Sipeed Lichee Nanoでhello world

2020-07-23低レベル勉強会に参加しました.Zoom.usでの開催でした.

内容はLinux名刺的なものを開発しようという内容で,リファレンスとしてSDカードサイズの小さなLinuxの動作するarmコンピュータのSipeed Lichee Nanoを使いました.

欲しい場合は1000円ちょいくらいからで入手できそうです.

Lichee Nanoを持っていない人はリモートで触れるようにしてあったので持っていない私も楽しめました.

このリモート開発の仕組みはLichee NanoとRaspberry PiをUSB経由のUARTで接続し,Raspberry PiでGNU screenを起動,ssh経由でGNU screenに繋いで操作という感じです.
GNU screenをGotty等にするとウェブブラウザで参加できてちょっと便利かもと思ったりも.(GoTTYは開発止まってるように見えるから別のもののほうがいいかもしれない)

Lichee Nanoで何かを動かしたい.armだけどarmhf動くのかな?とりあえずなにか転送して動かしてみようと.

とりあえずDebianのarmhfバイナリをuuencodeしてコピペで転送してみます.これが動けばDebianのパッケージ群が利用できるかもだけど…….

まずは簡単そうなfortuneを試します.

Debian sidでfortune-modパッケージのarmhfバイナリパッケージをダウンロードして展開(add archtecture armhfしてある環境)
$ apt download -t armhf fortune-mod
$ unar fortune-mod_1.99.1-7+b1_armhf.deb
$ cd fortune-mod_1.99.1-7+b1_armhf
$ tar xf data.tar.xz
$ cd usr/games

Lichee Nanoはserialで接続されていて,Internetには繋がっていないのでバイナリファイルの転送にはuudecode/uuencodeを使いました.久々です.
手元のGNU sharutils 4.15.2のuudecodeにはbase64を使う -m, --base64 があるので良さそう.と思ったけどLichee Nanoの方はbusyboxのもので非対応でした.

ローカル端末で圧縮してuuencodeしてクリップボードへ
$ gzip -c fortune | uuencode fortune.gz > fortune.gz.uu
$ cat fortune.gz.uu | xclip
リモートで伸張して解凍
# cat | uudecode    #ここでクリップボードから貼り付け
# zcat fortune.gz > fortune
# rm fortune.gz

そして…​…​

# ./fortune
-sh: ./fortune: not found
# ldd ./fortune
checking sub-depends for 'not found'
checking sub-depends for '/lib/libc.so.6'
/lib/ld-linux.so.3 (0xb6fa0000)
librecode.so.0 => not found (0x00000000)
libc.so.6 => /lib/libc.so.6 (0x00000000)
/lib/ld-linux.so.3 => /lib/ld-linux.so.3 (0x00000000)

これを動かすのはダイナミックリンクされているものを用意してあげないといけないのでストレージの容量的に難しいですね.

ここではgzipで圧縮しましたが,Lichee Nanoのbusyboxにxzがありました.gzipよりxzにしたほうが小さくなりますね.試してみるとこんな感じでした.$ xz -c fortune | uuencode fortune.xz > fortune.xz.uu

サイズ比較
-rw-r--r-- 1 matoken matoken 22368 Jul 23 15:11 fortune #元ファイル
-rw-r--r-- 1 matoken matoken 30844 Jul 23 14:58 fortune.uu #uudecode
-rw-r--r-- 1 matoken matoken 14975 Jul 23 15:08 fortune.gz.uu #zip + uudecode
-rw-r--r-- 1 matoken matoken 13047 Jul 23 15:47 fortune.xz.uu #xz + uudecode

そういえばあまり有名ではないですがbasE91なんてものもあります.base64よりサイズが小さくなりますが導入からやらないといけないのでちょっと面倒.

Hello worldを試してみます.適当にプログラムを用意してスタティックリンクでコンパイルしてみます.

$ cat hello.c
#include <stdio.h>
int
main(void)
{
    printf("Hello, world!\n");
    return 0;
}
$ gcc -static ./hello.c
$ ./a.out
Hello, world!
$ ls -l a.out
-rwxr-xr-x 1 pi pi 571120 7月 23 16:18 a.out

でかい…​…​

とりあえずでかいのはおいといてこれだとarm64なので動くはずがない.ということでクロスコンパイル環境を用意します.

今回試したホストはDebian sid amd64/Ubuntu 20.04 LTS arm64/Raspberry Pi OS arm64です.いずれも同じ手順でOKでした.

crossbuild-essential-<arch> パッケージで各種アーキテクチャの環境が導入できるようです.

$ apt-cache search crossbuild-essential-
crossbuild-essential-amd64 - Informational list of cross-build-essential packages
crossbuild-essential-arm64 - Informational list of cross-build-essential packages
crossbuild-essential-armel - Informational list of cross-build-essential packages
crossbuild-essential-armhf - Informational list of cross-build-essential packages
crossbuild-essential-i386 - Informational list of cross-build-essential packages
crossbuild-essential-powerpc - Informational list of cross-build-essential packages
crossbuild-essential-ppc64el - Informational list of cross-build-essential packages
crossbuild-essential-s390x - Informational list of cross-build-essential packages
crossbuild-essential-mips - Informational list of cross-build-essential packages
crossbuild-essential-mips64 - Informational list of cross-build-essential packages
crossbuild-essential-mips64el - Informational list of cross-build-essential packages
crossbuild-essential-mips64r6 - Informational list of cross-build-essential packages
crossbuild-essential-mips64r6el - Informational list of cross-build-essential packages
crossbuild-essential-mipsel - Informational list of cross-build-essential packages
crossbuild-essential-mipsr6 - Informational list of cross-build-essential packages
crossbuild-essential-mipsr6el - Informational list of cross-build-essential packages

沢山あります.今回はarmlf/armhfの crossbuild-essential-armel, crossbuild-essential-armhf を導入しました.

$ sudo apt install crossbuild-essential-armel crossbuild-essential-armhf

gccだけでいい場合はarmlfは gcc-arm-linux-gnueabi,armhfは gcc-arm-linux-gnueabihf だけでOKです.

まずは arm-linux-gnueabihf-gcc を使ってarmhfのバイナリを作ります.

$ /usr/bin/arm-linux-gnueabihf-gcc -static ./hello.c
$ strip a.out
$ xz -c a.out | uuencode a.out.xz > a.out.xz.uu

armhfは駄目そうです.

# cat | uudecode
^d
# xzcat ./a.out.xz > ./a.out
# chmod +x ./a.out
# ./a.out
Segmentation fault

次は gcc-arm-linux-gnueabi でarmlfのバイナリを作って試すと動きました.

$ /usr/bin/arm-linux-gnueabi-gcc -static ./hello.c
$ strip a.out
$ xz -c a.out | uuencode a.out.xz > a.out.xz.uu
# cat | uudecode
^d
# xzcat ./a.out.xz > ./a.out
# chmod +x ./a.out
# ./a.out
Hello, world!
# /usr/bin/time -f "%M KB" ./a.out
Hello, world!
2144 KB

この辺りで今回は時間切れ.次回の同じような感じになりそうです.興味のある方は以下のページから.

とりあえずarmelのバイナリが動くようなのがわかったので面白そうな小さなプログラムを試そうかなと思っています.cowsayとか好きなんだけどこれはPerlなので容量的に難しそう.とりあえずfortuneあたりかな?

以前PQI Air PenでやったようにSD cardを用意してそこにDebian armlf環境を展開してchrootとかもできそうです.

rsync 3.2.0の新機能を少し試す

ファイル同期にとても便利なrsyncの3.2.0がリリースされました.

バグフィクスや,いくつかの新機能が入ったようなので少し試してみました.

※1. この記事投稿時には 3.2.2 が出ています.
※2. 鹿児島Linux勉強会 2020.06で発表したものと同じ内容です.

導入例

Debian sid amd64 & Ubuntu 20.04 LTS amd64

$ sudo apt build-dep rsync
$ sudo apt install libxxhash-dev libzstd-dev liblz4-dev
$ wget -c \
https://download.samba.org/pub/rsync/rsync-3.2.0.tar.gz \
https://download.samba.org/pub/rsync/rsync-3.2.0.tar.gz.asc \
https://opencoder.net/WayneDavison.key
$ gpg2 --import ./WayneDavison.key
$ gpg2 --verify ./rsync-3.2.0.tar.gz.asc
$ tar tvzf ./rsync-3.2.0.tar.gz
$ tar xzf ./rsync-3.2.0.tar.gz
$ cd rsync-3.2.0
$ ./configure --help
$ ./configure
$ make
$ ./rsync --version
rsync  version 3.2.0  protocol version 31
Copyright (C) 1996-2020 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace, append,
    ACLs, xattrs, iconv, symtimes, prealloc, SIMD
Checksum list:
    xxh64 (xxhash) md5 md4 none
Compress list:
    zstd lz4 zlibx zlib none

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.
Note
gpg鍵は次から入手できます.rsync download

Raspberri Pi OS amd64

Raspberry Pi OS arm64の場合 libzstd-dev のバージョンが 1.3.8+dfsg-3 と少し古くbuildに失敗します. ./configure --disable-zstd としてzstdを無効にするか,sourceから zstd 1.4.5 を導入することでbuild出来ました.

$ make
  :
token.c: In function ‘init_compression_level’:
token.c:73:40: warning: implicit declaration of function ‘ZSTD_minCLevel’; did you mean ‘ZSTD_maxCLevel’? [-Wimplicit-function-declaration]
   min_level = skip_compression_level = ZSTD_minCLevel();
                                        ^~~~~~~~~~~~~~
                                        ZSTD_maxCLevel
token.c: In function ‘send_zstd_token’:
token.c:685:2: error: unknown type name ‘ZSTD_EndDirective’; did you mean ‘ZSTD_DDict’?
  ZSTD_EndDirective flush = ZSTD_e_continue;
  ^~~~~~~~~~~~~~~~~
  ZSTD_DDict
token.c:685:28: error: ‘ZSTD_e_continue’ undeclared (first use in this function)
  ZSTD_EndDirective flush = ZSTD_e_continue;
                            ^~~~~~~~~~~~~~~
token.c:685:28: note: each undeclared identifier is reported only once for each function it appears in
token.c:701:3: warning: implicit declaration of function ‘ZSTD_CCtx_setParameter’ [-Wimplicit-function-declaration]
   ZSTD_CCtx_setParameter(zstd_cctx, ZSTD_c_compressionLevel, do_compression_level);
   ^~~~~~~~~~~~~~~~~~~~~~
token.c:701:37: error: ‘ZSTD_c_compressionLevel’ undeclared (first use in this function); did you mean ‘skip_compression_level’?
   ZSTD_CCtx_setParameter(zstd_cctx, ZSTD_c_compressionLevel, do_compression_level);
                                     ^~~~~~~~~~~~~~~~~~~~~~~
                                     skip_compression_level
token.c:751:13: error: ‘ZSTD_e_flush’ undeclared (first use in this function); did you mean ‘ZSTD_DCtx_s’?
     flush = ZSTD_e_flush;
             ^~~~~~~~~~~~
             ZSTD_DCtx_s
token.c:753:8: warning: implicit declaration of function ‘ZSTD_compressStream2’; did you mean ‘ZSTD_compressStream’? [-Wimplicit-function-declaration]
    r = ZSTD_compressStream2(zstd_cctx, &zstd_out_buff, &zstd_in_buff, flush);
        ^~~~~~~~~~~~~~~~~~~~
        ZSTD_compressStream
$ cd ..
$ sudo apt remove libzstd-dev
$ wget https://github.com/facebook/zstd/releases/download/v1.4.5/zstd-1.4.5.tar.gz \
https://github.com/facebook/zstd/releases/download/v1.4.5/zstd-1.4.5.tar.gz.sha256
$ sha256sum -c ./zstd-1.4.5.tar.gz.sha256
$ tar tvf ./zstd-1.4.5.tar.gz | lv
$ tar xf ./zstd-1.4.5.tar.gz
$ cd zstd-1.4.5
$ make
$ sudo make install
$ cd ../rsync-3.2.0
$ ./configure && make

Debian sid amd64

Debian sid amd64 環境にはすでに降ってきているのでパッケージから導入するだけでOKです.

$ sudo apt install rsync
$ rsync --version
rsync  version 3.2.0  protocol version 31
Copyright (C) 1996-2020 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace, append,
    ACLs, xattrs, iconv, symtimes, prealloc, SIMD
Checksum list:
    xxh64 (xxhash) md5 md4 none
Compress list:
    zstd lz4 zlibx zlib none

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.
$ dpkg-query -W rsync
rsync   3.2.0-1

ってことで試せるようになりました.NEWSを見てみます.

BUG FIX

Avoid a hang when an overabundance of messages clogs up all the I/O buffers.

このバグ修正がちょっと気になります.fat32の制限に引っかかったときに帰ってこない問題もこれで解決してるかも?未確認.

ENHANCEMENTS

–checksum-choice=STR, –cc=STR

チェックサム形式を選べるようになったようです.現在選択できるのは xxh64/md5/md4 の3種類 or none or auto(既定値)

man(1)より
              o      auto (the default)
              o      xxh64 (aka xxhash)
              o      md5
              o      md4
              o      none

--version にも出力されます.

$ rsync --version | grep Checksum -A1
Checksum list:
    xxh64 (xxhash) md5 md4 none

configure option に --disable-xxhash がありました.

  --disable-xxhash        disable xxhash checksums

環境変数 RSYNC_CHECKSUM_LIST でも指定できます.オプション --checksum-choice がある場合はオプションのほうが優先なようです.

ちなみに --checksum-choice オプションに対応していない 3.1.3 に対して xxh64 を向けて叩いてみると以下のようなエラーになりました.(md4, md5 はok)

$ rsync --checksum-choice=xxh64 -avc ./* user@remote:/tmp/
unknown checksum name: xxh64
rsync error: requested action not supported (code 4) at checksum.c(73) [server=3.1.3]
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(235) [sender=3.2.0]

時間がどのくらい変わるかちょうど転がっていたkernel source(小さいファイルが沢山)で試してみました.はじめ普通に同期した後,キャッシュクリアして md4, md5, xxh64 で試してみました.思ったより差が出ない感じ?

md4
$ find ./linux-5.6 | wc -l
82114
$ du -ms ./linux-5.6
1310    ./linux-5.6
$ rsync --checksum-choice=auto -ac ./linux-5.6 /tmp/
$ sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches ; time rsync --checksum-choice=md4 -ac ./linux-5.6 /tmp/
3

real    0m52.393s
user    0m5.051s
sys     0m12.246s
md5
$ sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches ; time rsync --checksum-choice=md5 -ac ./linux-5.6 /tmp/
3

real    0m57.716s
user    0m6.976s
sys     0m13.486s
xxh64
$ sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches ; time rsync --checksum-choice=xxh64 -ac ./linux-5.6 /tmp/
3

real    1m5.520s
user    0m2.507s
sys     0m13.625s

大きめのファイルでも試してみました.4GB程のisoファイル1つです.md4, md5 はあまり代わりませんが,xxh64 はかなり高速ですね.

md4
$ ls -s ./Parrot-security-4.9.1_x64.iso*
3909164 ./Parrot-security-4.9.1_x64.iso  3909164 ./Parrot-security-4.9.1_x64.iso2
$ sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches ; time rsync --checksum-choice=md4 -ac ./Parrot-security-4.9.1_x64.iso ./Parrot-security-4.9.1_x
64.iso2
3

real    0m23.276s
user    0m10.601s
sys     0m4.387s
md5
$ sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches ; time rsync --checksum-choice=md5 -ac ./Parrot-security-4.9.1_x64.iso ./Parrot-security-4.9.1_x64.iso2
3

real    0m28.150s
user    0m16.945s
sys     0m4.399s
xxh64
$ sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches ; time rsync --checksum-choice=xxh64 -ac ./Parrot-security-4.9.1_x64.iso ./Parrot-security-4.9.1_x64.iso2
3

real    0m12.767s
user    0m1.375s
sys     0m4.060s

この辺の速度は環境により大分変わると思うので参考程度に.

–compress-choice=STR, –zc=STR

--compress オプション利用時の圧縮形式を指定できるようです.

圧縮形式はrsync 3.2.0 同士では zlibx 形式が zlib 形式よりも優先されるようです.
選択できるオプションは zstd, lz4, zlibx, zlib, none のようです.

man(1)より
              o      zstd
              o      lz4
              o      zlibx
              o      zlib
              o      none

rsync --version でも確認できます.

$ rsync --version | grep Compress -A1
Compress list:
    zstd lz4 zlibx zlib none

configure oprion に --disable-zstd, --disable-lz4 があります.

  --disable-zstd          disable zstd compression
  --disable-lz4           disable LZ4 compression

環境変数 RSYNC_COMPRESS_LIST でも指定できるようです.

未対応の 3.1.3 に対して指定すると unknown option と言われます.

$ time rsync --compress-choice=zstd --compress -a ./hoge mk@x201i.local:/tmp/
rsync: on remote machine: --compress-choice=zstd: unknown option
rsync error: syntax or usage error (code 1) at main.c(1596) [server=3.1.3]
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(235) [sender=3.2.0]

こちらも簡単にベンチを.でもWi-Fi環境だし参考程度に.

zstd
$ ssh user@remote rm -rf ~/tmp/linux-5.6; echo 3 | sudo tee /proc/sys/vm/drop_caches; time rsync --compress-choice=zstd --compress -a --rsync-path=~/src/rsync-3.2.0/rsync ~/src/linux-5.6 user@remote:~/tmp/
3

real    4m38.921s
user    0m24.463s
sys     0m7.182s
lz4
$ ssh user@remote rm -rf ~user/tmp/linux-5.6; echo 3 | sudo tee /proc/sys/vm/drop_caches; time rsync --compress-choice=lz4 --compress -a --rsync-path=~/src/rsync-3.2.0/rsync ~/src/linux-5.6 user@remote:~/tmp/
3

real    9m28.829s
user    0m4.878s
sys     0m6.177s
zlibx
$ ssh user@remote rm -rf ~user/tmp/linux-5.6; echo 3 | sudo tee /proc/sys/vm/drop_caches; time rsync --compress-choice=zlibx --compress -a --rsync-path=~/src/rsync-3.2.0/rsync ~/src/linux-5.6 user@remote:~/tmp/
3

real    5m21.702s
user    0m46.740s
sys     0m6.541s
zlib
$ ssh user@remote rm -rf ~user/tmp/linux-5.6; echo 3 | sudo tee /proc/sys/vm/drop_caches; time rsync --compress-choice=zlib --compress -a --rsync-path=~/src/rsync-3.2.0/rsync ~/src/linux-5.6 user@remote:~/tmp/
3

real    5m28.722s
user    0m45.861s
sys     0m6.381s
none
$ ssh user@remote rm -rf ~user/tmp/linux-5.6; echo 3 | sudo tee /proc/sys/vm/drop_caches; time rsync --compress-choice=none -a --rsync-path=~/src/rsync-3.2.0/rsync ~/src/linux-5.6 user@remote:~/tmp/
3

real    22m56.712s
user    0m1.848s
sys     0m7.323s

–debug=NSTR

チェックサムと圧縮の詳細を表示するオプションのようです.どのアルゴリズムを利用しているのかが確認できます.

–debug=NSTR を付けたときのの実行結果例
Client negotiated checksum: xxh64
Client compress: zstd (level 3)

–debug=OPTS, -M—​debug=OPTS

--debug=OPTS を使うとリモートのrsyncにデバッグオプションを送らなくなるようです.これによりクライアント側とサーバ側で異なるデバッグレベルを指定できるようになったそうです.
リモート側にオプションを送る場合には -M—​debug=OPTS

SIGINFO & SIGVTALRM

rsyncプロセスに SIGINFO & SIGVTALRM シグナルを送信することでステータスを表示できるようになったようです.Linuxは SIGINFO に対応していないので, SIGVTALRM を試しました.

rsyncを実行している状態で SIGVTALRM を送信
$ pkill -SIGVTALRM rsync
rsyncがステータスを表示
linux-5.6/arch/sparc/lib/lshrdi3.S
    114,384,392  81%  931.12kB/s    0:01:59 (xfr#21058, ir-chk=1030/23451)

–copy-as=USER[:GROUP]

指定ユーザ/グループ権限でファイルをコピーするようです.

コピー元に3ユーザのファイル
$ ls -Al /tmp/rsync-test/
total 0
-rw-r--r-- 1 matoken  matoken  0 Jun 25 18:50 matokenfile
-rw-r--r-- 1 root     root     0 Jun 25 18:51 root
-rw-r--r-- 1 www-data www-data 0 Jun 25 18:51 www-data
普通にコピーするとユーザが引き継がれる
$ sudo ./rsync -a /tmp/rsync-test/ /tmp/rsync-test2
$ ls -lA /tmp/rsync-test2
total 0
-rw-r--r-- 1 matoken  matoken  0 Jun 25 18:50 matokenfile
-rw-r--r-- 1 root     root     0 Jun 25 18:51 root
-rw-r--r-- 1 www-data www-data 0 Jun 25 18:51 www-data
--copy-as=matoken を指定するとすべてmatokenになる
$ sudo \rm -rf /tmp/rsync-test2
$ sudo ./rsync --copy-as=matoken -a /tmp/rsync-test/ /tmp/rsync-test2
$ ls -lA /tmp/rsync-test2
total 0
-rw-r--r-- 1 matoken matoken 0 Jun 25 18:50 matokenfile
-rw-r--r-- 1 matoken matoken 0 Jun 25 18:51 root
-rw-r--r-- 1 matoken matoken 0 Jun 25 18:51 www-data

-V

--version の短いオプションとして -V が入りました.

$ ./rsync --help|grep -- -V
--version, -V            print the version + other info and exit
$ ./rsync --help|grep \-V
grep (GNU grep) 3.4
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others; see
<https://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

–ipv4, -4 / –ipv6, -6

ipv4, ipv6 を指定したいときに rsh='ssh -4' とするより便利な --ipv4, -4, --ipv6, -6 オプションが入りました.

ipv4しかない環境で -6 を指定して失敗する
$ rsync -avc6 ./ user@remote:/tmp/
ssh: Could not resolve hostname remote: Name or service not known
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.2.1]

awesome wmでの壁紙変更設定を変更(crontabからDISPLAY番号取得)

awesome wm環境での壁紙自動変更にcrontab経由で feh コマンドを利用しています.

30分ごとに~/Pictures/wp/以下のファイルをダンダムに設定
*/30 * * * *    DISPLAY=:0 feh --bg-scale "$(find ~/Pictures/wp/ -type f | shuf -n 1)"

このときXのディスプレイ番号を固定で書いているのですがディスプレイ番号が変わることもあってその時エラーになってしまいます.
ウィンドウマネージャを変更したときもよくなさそう.

ということでcronからユーザのawesome wmのディスプレイ番号を探すようにしてみました.

まずは対象ユーザのawesome wmのプロセス番号を調べます.

$ pgrep -u $(id -u) awesome
2932

/proc/$PID/environ からDISPLAYを探します.

$ cat /proc/2932/environ 2> /dev/null | tr '
$ cat /proc/2932/environ 2> /dev/null | tr '\0' '\n' | grep ^DISPLAY=:
DISPLAY=:1
' '\n' | grep ^DISPLAY=: DISPLAY=:1

カレントユーザのawesome wmのディスプレイ番号が :1 なのが解りました :)

これを組み合わせてこのようにしてみました.これでディスプレイ番号が変わっても大丈夫で,awesome以外のウィンドウマネージャを使ったときには何もしないはず( xargs --no-run-if-empty )です.
同じユーザでawesomeを複数起動した場合は先に起動した方しか反映されないはずですが,あまりそういったことはしないと思うので大丈夫かなと.

*/30 * * * *    cat /proc/$(pgrep -u $(id -u) awesome)/environ 2> /dev/null | tr '
*/30 * * * *    cat /proc/$(pgrep -u $(id -u) awesome)/environ 2> /dev/null | tr '\0' '\n' | grep ^DISPLAY=: | xargs --no-run-if-empty -I{} sh -c '{} feh --bg-scale "$(find ~/Pictures/wp/ -type f | shuf -n 1)"'
' '\n' | grep ^DISPLAY=: | xargs --no-run-if-empty -I{} sh -c '{} feh --bg-scale "$(find ~/Pictures/wp/ -type f | shuf -n 1)"'

2020-07-17 ADD
fehに -z, --randomize と言うオプションがありました.これを使うとコマンドが2つ減って少しわかりやすく……あまり変わらないか.

*/30 * * * *    cat /proc/$(pgrep -u $(id -u) awesome)/environ 2> /dev/null | tr '
*/30 * * * *    cat /proc/$(pgrep -u $(id -u) awesome)/environ 2> /dev/null | tr '\0' '\n' | grep ^DISPLAY=: | xargs --no-run-if-empty -I{} {} feh --bg-scale -z ~/Pictures/wp/
' '\n' | grep ^DISPLAY=: | xargs --no-run-if-empty -I{} {} feh --bg-scale -z ~/Pictures/wp/
環境
$ dpkg-query -W awesome feh procps findutils grep
awesome 4.3-4
feh     3.4.1-1
findutils       4.7.0-1
grep    3.4-1
procps  2:3.3.16-5
$ lsb_release -dr
Description:    Debian GNU/Linux bullseye/sid
Release:        unstable
$ uname -m
x86_64

Speaker Deckのスライドが全て非公開になって困る

Speaker Deckというスライド共有サービスがあります.日本ではSlideShareの次くらいによく使われていそうなサービスです.ここでトラブルがあったので健忘録としてメモしておきます.

このサービスにスライドを登録しようとアップロードしたところ変換に失敗してしまいます.スライドのデータが悪いのかな?と他のものも試すとやはり駄目です.
よく見ると5月以降に登録したスライドはアクセスが0です.なにかおかしい.

ログアウトした状態で見るとスライドが1つも見えなくなってしまっています.

speakerdeck 20200625 07:06:04 766282.resized

既存のスライドを公開(publish)し直しても公開されません.

全てのスライドが非公開になっている,ログインしたら見えるけど公開できない,新しいスライドの登録は失敗する……という状態です.

DMCAとか著作権違反とかが報告されてロックされていそうな感じがします(心当たりはないけど他のサービスもそれでBANされた前科あり).メールを探しますが特にそれらしいものは見当たりません.

ちょっと自分ではどうしようもなさそうだとSpeaker Deckの「Feedback」リンクからメールで問い合わせてみました.しかし反応がありません.
ダメ元でTwitterのSpeaker Deckアカウントである@speakerdeckにmentionを投げてみると数時間で復旧していました.

スライドはちゃんと公開され,新しいスライドのアップロードも出来ました.ということでよくわかりませんがシステムの不具合だったのかな?

やっぱり人任せにするのは怖いですね.自分でコントロールできるところでもまとめておこうと思います.

鹿児島らぐの「鹿児島Linux勉強会 2020.06」に参加

2020-06-28(sun)に開催された「鹿児島Linux勉強会 2020.06」に参加しました.

今回もDiscordで開催.主に音声チャットでやり取りで発表は画面共有で行う感じです.参加者は6名(申し込み7人欠席2人飛び入り1人)でした.

以下のような話がありました.

私は先月の「YoutubeLiveを細い回線で「聴く」」の続きをと思ったのですが,スライドのアクセスがとても少なく(たぶん自分を除くと一桁)反応良くなさそうだったのと,Twitterでrsyncの新機能への反応が良かったように見えたので「rsync 3.2.0の新機能を試してみた」と,参加者少なさそうだったので急遽「cowsayのcowを増やそう」を用意しました.
まあどちらもいまいち刺さらなかったかな…….

次回は07/26(日)でオンライン開催の予定です.

小江戸らぐ 6月のオフな集まり(第215回) オンライン開催に参加

06/13(Sat) 14:00〜20:00

カンファレンスツールにはZoom.us を利用して,14:00〜18:00 が勉強会.その後は懇親会な感じです.実際は00:00過ぎまでやっていました.

参加者はだいたい20人前後な感じでした.

以下のような発表がありました.

私の発表は「Linux環境で(低解像度の)画面共有を行うTips」でした.
しかし,今発表腕紹介したXephyrを使って発表しようとしたら今回のツールのZoom.us Linux版 clientでは画面共有の一覧に出てこず利用できませんでした(あとでChromiumでZoom.usを利用したら共有できるのを確認).スライドのまま共有してもほとんどアクセスはないのでそのうちblogにでもまとめなおそうと思います.

次回は恐らく07/11(Sat)にオンライン開催です.

torのhidden serviceで使うアドレスを計算する(Vanity Addresses)

最近このような記事を読みました.

今のインターネットはドメイン頼りな割に単一障害点となってしまってあまりよろしくない.でも逃げ道があまりないのですよね…….
とりあえず以前からそのうちやろうと思って放置していたtorのhidden serviceでミラーを立てるのをやってみようかなと思い立ちました.

とりあえず /etc/tor/torrc で以下のあたりを有効にしてtorを再起動してhttpdの設定をするだけで動きます.

HiddenServiceDir /var/lib/tor/hidden_service/
HiddenServicePort 80 127.0.0.1:80

このときのアドレスはtor再起動後に HiddenServiceDir 以下に作られる hostname ファイルの中の名前になります.

$ sudo cat /var/lib/tor/hidden_service/hostname
tbiettfnprnqpoccrz3ll7hioprbyjoam2n6okihpadf5ukaa4hwrwad.onion

このアドレスは[a-z|3-7]の32文字(BASE32)からなる16文字の onion v2 アドレスと,56文字の onion v3 アドレスがあって,最近は後者のv3アドレスが規定値になっているようです.鍵は RSA から ed25519 になっています.

Onion v2 はホストネームから秘密鍵を求めるのに現実的な時間で済むのが近づいてきているようなのでとても長くて使いづらいですがこれからはOnion v3 アドレスにしたほうが良さそうです.
今はv2,v3 を併用しているところも多いようです.

Onion v2 Onion v3

hostname文字長

16

56

鍵形式

RSA

ed25519

鍵ファイル名

private_key

hs_ed25519_secret_key hs_ed25519_public_key

(無駄に)アドレスを計算して好みの単語にマッチしたものを探す(例えばmatokenから始まるアドレスを探すとか)ことが可能です.
こういったアドレスはVanity Addresses というようです.

他にもアドレスを売っているところもありますが,相手は秘密鍵を持っているわけであまりよくないと思います.

Onion v2 アドレスを eschalot で探す

add 2020-07-28)

Onion v2 アドレスは2021年11月あたりで使えなくなるようです.

Onion v2 アドレスを eschalot というツールを使ってみます.

導入
$ sudo apt install libssl-dev
$ git clone https://github.com/ReclaimYourPrivacy/eschalot
$ cd eschalot
$ make
$ ./eschalot
Version: 1.2.0

usage:
eschalot [-c] [-v] [-t count] ([-n] [-l min-max] -f filename) | (-r regex) | (-p prefix)
  -v         : verbose mode - print extra information to STDERR
  -c         : continue searching after the hash is found
  -t count   : number of threads to spawn default is one)
  -l min-max : look for prefixes that are from 'min' to 'max' characters long
  -n         : Allow digits to be part of the prefix (affects wordlist mode only)
  -f filename: name of the text file with a list of prefixes
  -p prefix  : single prefix to look for (1-16 characters long)
  -r regex   : search for a POSIX-style regular expression

Examples:
  eschalot -cvt4 -l8-12 -f wordlist.txt >> results.txt
  eschalot -v -r '^test|^exam'
  eschalot -ct5 -p test

  base32 alphabet allows letters [a-z] and digits [2-7]
  Regex pattern examples:
    xxx           must contain 'xxx'
    ^foo          must begin with 'foo'
    bar$          must end with 'bar'
    b[aoeiu]r     must have a vowel between 'b' and 'r'
    '^ab|^cd'     must begin with 'ab' or 'cd'
    [a-z]{16}     must contain letters only, no digits
    ^dusk.*dawn$  must begin with 'dusk' and end with 'dawn'
    [a-z2-7]{16}  any name - will succeed after one iteration

以下は -t でスレッド数を指定,-v で冗長出力,-pabc 方始まるホスト名を探しています.
見つかると標準出力にホスト名と秘密鍵が出力されます.

$ time ./eschalot -t`nproc` -v -p abc
Verbose, single result, no digits, 4 threads, prefixes 3-3 characters long.
Thread #1 started.
Thread #2 started.
Thread #3 started.
Thread #4 started.
Running, collecting performance data...
Found a key for abc (3) - abcamzmribeujuzw.onion
----------------------------------------------------------------
abcamzmribeujuzw.onion
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDIHD5uCynAW/Y1Vmyef8KrKuyFMzavij5Gl6aHYoiaGWNkJOZ7
P/Xc1Z78YTZ7LtzpWCAWLax4PmIhQiwPhldsD/kVWKAi0fODxaP/Z0XoJjqIfx8f
CmVWIQ1L9TVp9kfp8nLtXm9CnawCT98g0VE/jvZEddBV2oaVCuq88BTsoQIEAQBz
4QKBgBHzMeQAOOkyB3yCc51oYOh92jYLyXJuc511HR9yki7b/CxIhjL7miA+GVmJ
n4DD9nKubE5/xE6KrNnm3YZ1kmar2Yl/8fLJxBUrVoDUeGAc7i77i+tqM4d1LCr3
X1Ead8S7WpnnTVSmRHiLjuebaF78BWiMII4+3v9d1e6PQXbRAkEA9IJknhUNSO5b
1bzEIOmybg94r3fvBdWsc9xiwm6ONMBI2WyAVwmxDZ63Spwb/AyKCEblwekcaw6h
NMmhBQeUmQJBANGDs597RqBQUsFqtb5BoBkQgELIVeS4xKgZXrDI9SKfnnpTxv8Z
ypah+g335EN3/bBgfbqy8C7zFZhjHclzFUkCQQDcoP4aDG1zPO4TFcnguwvnGv/j
kOBS3h0CJOVY+rLTlUaekvjD6ugVLQ0olFItL1wyyZ3IifKcDHoDWJo/OOZZAkAQ
82dcvUGLOUpZObyFTdyUkU/eytiXaQZM0UdTDPnGYmrH/CBEaoSSjgRG7MEdFf2k
r+VVLqSnp+g6tFwp9It5AkBI4fJxCrrANt3E/CCrFW4iZXIqP3aPXHHZK5SqtQzJ
gBKUN8HSRxo/dURQPOLKKX0ynVJaMhg5UO4tQ3rHiJwa
-----END RSA PRIVATE KEY-----

Segmentation fault

real    0m0.126s
user    0m0.399s
sys     0m0.015s

-r オプションで正規表現が利用できます.以下の例は abc から始まり bca で終わるホスト名か,deadbeef で始まるアドレスを探しています.

$ ./eschalot -t`nproc` -v -r "^abc.*bca^|^deadbeef"

-c オプションで1つ見つかっても中断するまで探し続けます.
ファイルにリダイレクトしておくと便利です.

$ ./eschalot -cvt`nproc` -r "^abc.bca^|^deadbeef" >> result.log

探したいワードが多い場合は1ワード1行の辞書ファイルを作成して -f オプションで指定すると便利です.ただし,辞書ファイル指定時は7文字以下のワードは無視されるようです.-l オプションで 7-16 のように最小文字数を7以下にすればと思ったのですが,このオプションは7以下だとエラーで終了してしまいます.

$ ./eschalot -cvt`nproc` -f ./wordlist.dic >> result.log

GPUを使うツールも複数あります.例えば Scallion こっちのほうがずっと速いでしょう.(ASICとかもあるのかな?)

Onion v3 アドレスを mkp224o で探す

Onion v3 アドレスは mkp224o というツールを使ってみました.

configure optionに --enable-amd64-51-30k , --enable-amd64-64-24k というものがあるので試してみましたが,なし,--enable-amd64-51-30k , --enable-amd64-64-24k のいずれでも有意な速度差は見られませんでした.(Intel® Core™ i5-3320M)

導入
$ sudo apt install libsodium-dev autoconf
$ git clone https://github.com/cathugger/mkp224o
$ cd mkp224o
$ ./autogen.sh
$ ./configure
$ make
$ ./mkp224o
Usage: ./mkp224o filter [filter...] [options]
       ./mkp224o -f filterfile [options]
Options:
        -h  - print help to stdout and quit
        -f  - specify filter file which contains filters separated by newlines
        -D  - deduplicate filters
        -q  - do not print diagnostic output to stderr
        -x  - do not print onion names
        -v  - print more diagnostic data
        -o filename  - output onion names to specified file (append)
        -O filename  - output onion names to specified file (overwrite)
        -F  - include directory names in onion names output
        -d dirname  - output directory
        -t numthreads  - specify number of threads to utilise (default - CPU core count or 1)
        -j numthreads  - same as -t
        -n numkeys  - specify number of keys (default - 0 - unlimited)
        -N numwords  - specify number of words per key (default - 1)
        -z  - use faster key generation method; this is now default
        -Z  - use slower key generation method
        -B  - use batching key generation method (>10x faster than -z, experimental)
        -s  - print statistics each 10 seconds
        -S t  - print statistics every specified ammount of seconds
        -T  - do not reset statistics counters when printing
        -y  - output generated keys in YAML format instead of dumping them to filesystem
        -Y [filename [host.onion]]  - parse YAML encoded input and extract key(s) to filesystem
        --rawyaml  - raw (unprefixed) public/secret keys for -y/-Y (may be useful for tor controller API)
        -p passphrase  - use passphrase to initialize the random seed with
        -P  - same as -p, but takes passphrase from PASSPHRASE environment variable

探したいワードを引数に与えて実行するだけで利用できます.結果はホスト名のディレクトリ以下にファイルとして出力されます.

$ time ./mkp224o abcd
sorting filters... done.
filters:
        abcd
in total, 1 filter
using 4 threads
abcdpr2quwoxranttf2ywckm7g5giysscy62kmhyqmnq2ycvooxbtryd.onion
^Cwaiting for threads to finish... done.

real    0m8.982s
user    0m21.740s
sys     0m0.167s
$ ls -A abcdpr2quwoxranttf2ywckm7g5giysscy62kmhyqmnq2ycvooxbtryd.onion
hostname  hs_ed25519_public_key  hs_ed25519_secret_key

結果を onion ディレクトリに格納するようにしました.

$ time ./mkp224o -d ./onion abcd

フィルタは複数書けます.

$ time ./mkp224o -d ./onion abcd efgh ijkl

-S オプションで指定した秒数ごとに統計上を鵜を出力します.フィルタに辞書ファイルを使います.

$ ./mkp224o -S 300 -d ./onion -f ./wordlist.dic

以下は手元のNotePCとRaspberry Pi 3 model Bでの速度です.PCの方は熱でスロットリングが効いているのもありますが,案外Raspberry Pi が悪くない数字に見えます.自分の環境の場合電気代等を考えるとRaspberry Pi を並列で動かしておくほうが良さそうです.

Intel® Core™ i5-3320M
>calc/sec:202602.624226, succ/sec:0.000000, rest/sec:0.000000, elapsed:300.129147sec
>calc/sec:177378.183948, succ/sec:0.006667, rest/sec:0.006667, elapsed:600.131277sec
>calc/sec:155232.657607, succ/sec:0.006667, rest/sec:0.006667, elapsed:900.106274sec
>calc/sec:111928.180486, succ/sec:0.000000, rest/sec:0.000000, elapsed:1200.166338sec
Raspberry Pi 3 model B(aarch64 kernel)
>calc/sec:103867.893552, succ/sec:0.003333, rest/sec:0.003333, elapsed:300.130969sec
>calc/sec:100761.039921, succ/sec:0.003333, rest/sec:0.003333, elapsed:600.155046sec
>calc/sec:94511.877034, succ/sec:0.009999, rest/sec:0.009999, elapsed:900.194934sec
>calc/sec:91854.274354, succ/sec:0.003334, rest/sec:0.003334, elapsed:1200.130938sec

Vanity Addresses の設定

Onion v2

torrc の HiddenServiceDir 以下の hostname, hs_ed25519_public_key, hs_ed25519_secret_key を退避します.
次に private_key ファイルをtorの権限で作成し,見つけたRSA鍵を保存します.

その後torのサービスを再起動すると反映されて hostname ファイルも作成されます.

$ grep ^HiddenServiceDir /etc/tor/torrc
HiddenServiceDir /var/lib/tor/other_hidden_service/
$ sudo ls -A /var/lib/tor/other_hidden_service/
authorized_clients  hostname  hs_ed25519_public_key  hs_ed25519_secret_key  private_key
$ sudo rm /var/lib/tor/other_hidden_service/hostname /var/lib/tor/other_hidden_service/hs_ed25519_public_key /var/lib/tor/other_hidden_service/hs_ed25519_secret_key
$ sudo install -o debian-tor -g debian-tor -m 400 /dev/null /var/lib/tor/other_hidden_service/private_key
$ echo '-----BEGIN RSA PRIVATE KEY-----
> MIICXQIBAAKBgQDIHD5uCynAW/Y1Vmyef8KrKuyFMzavij5Gl6aHYoiaGWNkJOZ7
> P/Xc1Z78YTZ7LtzpWCAWLax4PmIhQiwPhldsD/kVWKAi0fODxaP/Z0XoJjqIfx8f
> CmVWIQ1L9TVp9kfp8nLtXm9CnawCT98g0VE/jvZEddBV2oaVCuq88BTsoQIEAQBz
> 4QKBgBHzMeQAOOkyB3yCc51oYOh92jYLyXJuc511HR9yki7b/CxIhjL7miA+GVmJ
> n4DD9nKubE5/xE6KrNnm3YZ1kmar2Yl/8fLJxBUrVoDUeGAc7i77i+tqM4d1LCr3
> X1Ead8S7WpnnTVSmRHiLjuebaF78BWiMII4+3v9d1e6PQXbRAkEA9IJknhUNSO5b
> 1bzEIOmybg94r3fvBdWsc9xiwm6ONMBI2WyAVwmxDZ63Spwb/AyKCEblwekcaw6h
> NMmhBQeUmQJBANGDs597RqBQUsFqtb5BoBkQgELIVeS4xKgZXrDI9SKfnnpTxv8Z
> ypah+g335EN3/bBgfbqy8C7zFZhjHclzFUkCQQDcoP4aDG1zPO4TFcnguwvnGv/j
> kOBS3h0CJOVY+rLTlUaekvjD6ugVLQ0olFItL1wyyZ3IifKcDHoDWJo/OOZZAkAQ
> 82dcvUGLOUpZObyFTdyUkU/eytiXaQZM0UdTDPnGYmrH/CBEaoSSjgRG7MEdFf2k
> r+VVLqSnp+g6tFwp9It5AkBI4fJxCrrANt3E/CCrFW4iZXIqP3aPXHHZK5SqtQzJ
> gBKUN8HSRxo/dURQPOLKKX0ynVJaMhg5UO4tQ3rHiJwa
> -----END RSA PRIVATE KEY-----' | sudo -u debian-tor tee /var/lib/tor/other_hidden_service/private_key
$ sudo service tor restart
$ torsocks w3m `sudo -u debian-tor cat /var/lib/tor/other_hidden_service/hostname`

Onion v3

torrc の HiddenServiceDir 以下の hostname, hs_ed25519_public_key, hs_ed25519_secret_key を退避します.
次に hs_ed25519_secret_key ファイルをtorの権限でコピーします.

その後torのサービスを再起動すると反映されて hostname, hs_ed25519_public_key ファイルも作成されます.

$ grep ^HiddenServiceDir /etc/tor/torrc
HiddenServiceDir /var/lib/tor/other_hidden_service/
$ sudo ls -A /var/lib/tor/other_hidden_service/
authorized_clients  hostname  hs_ed25519_public_key  hs_ed25519_secret_key  private_key
$ sudo rm /var/lib/tor/other_hidden_service/hostname /var/lib/tor/other_hidden_service/hs_ed25519_public_key /var/lib/tor/other_hidden_service/hs_ed25519_secret_key
$ sudo install -o debian-tor -g debian-tor -m 400 ./onion/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.onion/hs_ed25519_secret_key /var/lib/tor/other_hidden_service/hs_ed25519_secret_key
$ sudo service tor restart
$ torsocks w3m `sudo -u debian-tor cat /var/lib/tor/other_hidden_service/hostname`

まとめ

という感じで3日ほど動かしてみましたが matoken から始まるホスト名を3つほど掘り当てました.近いうちにミラーを設定してみようと思います.(v2, v3のアドレスを1つのtorサービスでホストする方法ってあるのかな?)
しかし設定してもアクセスはほぼ無いような気も…….

ちなみにtorはNAT越えもしてしまうのでsshdなどを許可する場合は注意しましょう.

$ torsocks w3m -dump http://matoken3inrzd4ks.onion/
 _     _   _             ____               _        _              _____
| |__ | |_| |_ _ __ _   / / / __ ___   __ _| |_ ___ | | _____ _ __ |___ /
| '_ \| __| __| '_ (_) / / / '_ ` _ \ / _` | __/ _ \| |/ / _ \ '_ \  |_ \
| | | | |_| |_| |_) | / / /| | | | | | (_| | || (_) |   <  __/ | | |___) |
|_| |_|\__|\__| .__(_)_/_/ |_| |_| |_|\__,_|\__\___/|_|\_\___|_| |_|____/
              |_|
 _                   _ _  _   _                     _                __
(_)_ __  _ __ ______| | || | | | _____   ___  _ __ (_) ___  _ __    / /
| | '_ \| '__|_  / _` | || |_| |/ / __| / _ \| '_ \| |/ _ \| '_ \  / /
| | | | | |   / / (_| |__   _|   <\__ \| (_) | | | | | (_) | | | |/ /
|_|_| |_|_|  /___\__,_|  |_| |_|\_\___(_)___/|_| |_|_|\___/|_| |_/_/
環境
$ dpkg-query -W tor
tor     0.3.5.10-1
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
aarch64
$ cat /proc/device-tree/model ;echo
Raspberry Pi 3 Model B Rev 1.2

snapでNextcloudを導入して手軽にGoogleDocぽく使う(snap版Nextcloud + OnlyOffice)

Nextcloud導入が面倒?snapを使うとこれだけでGoogleDocみたいなことができます(Debian sid amd64/Ubuntu 20.04 LTSで確認済み).

$ sudo apt update && sudo apt upgrade
$ sudo apt install snapd
$ sudo snap install nextcloud
$ sudo /snap/bin/nextcloud.occ app:install documentserver_community
$ sudo /snap/bin/nextcloud.occ app:install onlyoffice

snap nextcloud 20200610 00:06:05 415116

簡単に説明していきます.

OSの状態を最新にしておきます.
$ sudo apt update && sudo apt upgrade
snapを使うためにsnapdを導入します(最近のUbuntuだと標準で入ってると思います).
$ sudo apt install snapd
snapでNextcloudを検索してみます.
$ snap find nextcloud
Name                       Version                    Publisher         Notes  Summary
nextcloud                  18.0.4snap3                nextcloud✓        -      Nextcloud Server - A safe home for all your data
spreedme                   0.29.5snap1                nextcloud✓        -      Spreed.ME audio/video calls and conferences feature for the Nextcloud Snap
onlyoffice-desktopeditors  5.5.1                      onlyoffice✓       -      A comprehensive office suite for editing documents, spreadsheets and presentations
qownnotes                  20.6.2                     pbek              -      Plain-text file markdown note taking with Nextcloud / ownCloud integration
nextcloud-port8080         1.01                       arcticslyfox      -      Nextcloud Server
nextcloud-snap-abacao      11.0.3snap4                abacao            -      Nextcloud Server
nextcloud-nextant          11.0.0snap3                rmescandon        -      Nextcloud Server + search support
nextcloud-abacao           11.0.3snap4                abacao            -      Nextcloud Server
cashbox-nextcloud          11.0.2snap2                cashbox           -      Nextcloud Server for www.cashBOX.plus
nextcloudsnap              12.0.4snap1                oscarbrolin       -      Nextcloud Server - A safe home for all your data
ghostcloud                 0.9.5                      beidl             -      A modern cross-platform client for Nextcloud, ownCloud, WebDav.
htxucloud                  12.0.3snap7                htxu              -      Nextcloud Server
carnet                     0.22.1                     alexandre-roux-m  -      Powerful note taking app with sync, online editor and android app
opentodolist               3.23.0                     mhoeher           -      Todo list and note taking application
solr                       0.1                        rmescandon        -      Starts up solr as forking daemon
mdns-hostname              0.0.1                      welike            -      mDNS mini-daemon to published hostname.local
nextcloud-stondino         15.0.10snap3+git1.ff25cb9  zmusselman        -      Nextcloud Server - A safe home for all your data
vmcloud-nextcloud          1.0.0                      victoriususm      -      Nextcloud 16.0.3 Optimized-Boosted
feedreader                 0+git.9ac478f7             ken-vandine       -      RSS client for various webservices
test003-nc                 13.0.4.snap1               reinism           -      Nextcloud Server - A safe home for all your data
$ snap info nextcloud
name:      nextcloud
summary:   Nextcloud Server - A safe home for all your data
publisher: Nextcloud*
store-url: https://snapcraft.io/nextcloud
contact:   https://github.com/nextcloud/nextcloud-snap
license:   unset
description: |
  Where are your photos and documents? With Nextcloud you pick a server of
  your choice, at home, in a data center or at a provider. And that is where
  your files will be. Nextcloud runs on that server, protecting your data and
  giving you access from your desktop or mobile devices. Through Nextcloud
  you also access, sync and share your existing data on that FTP drive at
  school, a Dropbox or a NAS you have at home.
commands:
  - nextcloud.disable-https
  - nextcloud.enable-https
  - nextcloud.export
  - nextcloud.import
  - nextcloud.manual-install
  - nextcloud.mysql-client
  - nextcloud.mysqldump
  - nextcloud.occ
services:
  nextcloud.apache:          simple, enabled, active
  nextcloud.mdns-publisher:  simple, enabled, active
  nextcloud.mysql:           simple, enabled, active
  nextcloud.nextcloud-cron:  simple, enabled, active
  nextcloud.nextcloud-fixer: simple, enabled, inactive
  nextcloud.php-fpm:         simple, enabled, active
  nextcloud.redis-server:    simple, enabled, active
  nextcloud.renew-certs:     simple, enabled, active
snap-id:      njObIbGQEaVx1H4nyWxchk1i8opy4h54
tracking:     latest/stable
refresh-date: yesterday at 21:53 JST
channels:
  latest/stable:    18.0.4snap4               2020-06-08 (21413) 264MB -
  latest/candidate: ^
  latest/beta:      18.0.4snap4+git5.31f0acd  2020-06-09 (21469) 264MB -
  latest/edge:      master-2020-06-10         2020-06-10 (21487) 267MB -
  18/stable:        18.0.4snap4               2020-06-08 (21413) 264MB -
  18/candidate:     ^
  18/beta:          ^
  18/edge:          18-2020-06-10             2020-06-10 (21482) 265MB -
  17/stable:        17.0.6snap1               2020-05-03 (20616) 229MB -
  17/candidate:     ^
  17/beta:          17.0.6snap1+git10.8f765f8 2020-06-09 (21474) 249MB -
  17/edge:          17-2020-06-10             2020-06-10 (21483) 250MB -
  16/stable:        16.0.11snap1              2020-06-08 (21459) 225MB -
  16/candidate:     ^
  16/beta:          ^
  16/edge:          ^
  15/stable:        15.0.14snap1              2020-01-20 (18374) 216MB -
  15/candidate:     ^
  15/beta:          ^
  15/edge:          ^
  14/stable:        14.0.10snap1              2019-05-04 (13208) 202MB -
  14/candidate:     ^
  14/beta:          ^
  14/edge:          ^
  13/stable:        13.0.12snap1              2019-05-03 (13155) 193MB -
  13/candidate:     ^
  13/beta:          ^
  13/edge:          ^
  12/stable:        12.0.13snap1              2019-01-07 (10632) 206MB -
  12/candidate:     ^
  12/beta:          ^
  12/edge:          ^
  11/stable:        11.0.8snap1               2018-05-10  (6942) 202MB -
  11/candidate:     ^
  11/beta:          ^
  11/edge:          ^

いくつかでてきますが,Publisherが nextcloud になっている公式のstableを使います.ちなみにこのコマンドを叩いた時点で19.0.0や18.0.5が出ていてこの記事執筆時点で18.0.6が出ています.ちょっと反映が遅いみたいですね.

snap版Nextcloudを導入
$ sudo snap install nextcloud

しばらく時間がかかりますが,これでNextcloudと関連のApache httpd/PHP/MySQL等が設定済みの状態で導入されます.

$ ps aux | grep -i nextcloud
root     17628  0.0  0.0   1872   196 ?        Ss   00:10   0:00 /bin/sh /snap/nextcloud/21169/bin/delay-on-failure mdns-publisher nextcloud
root     17615  0.0  0.1   1872  1168 ?        Ss   00:10   0:00 /bin/sh /snap/nextcloud/21169/bin/nextcloud-cron
root     17657  0.0  0.1   1872  1200 ?        Ss   00:10   0:00 /bin/sh /snap/nextcloud/21169/bin/renew-certs
root     17681  0.0  0.1   1872  1272 ?        Ss   00:10   0:00 /bin/sh /snap/nextcloud/21169/bin/start-php-fpm
root     17712  0.0  0.1   1872  1216 ?        Ss   00:10   0:00 /bin/sh /snap/nextcloud/21169/bin/start-redis-server
root     17765  0.0  0.6 258120  6008 ?        Sl   00:10   0:00 mdns-publisher nextcloud
root     17987  0.0  0.1   1872  1200 ?        Ss   00:10   0:00 /bin/sh /snap/nextcloud/21169/bin/run-httpd -k start -DFOREGROUND
root     18069  0.1  0.1   1872  1168 ?        Ss   00:10   0:01 /bin/sh /snap/nextcloud/21169/bin/start_mysql
root     18111  0.0  0.1   1872  1100 ?        S    00:10   0:00 /bin/sh /snap/nextcloud/21169/bin/mysqld_safe --datadir=/var/snap/nextcloud/21169/mysql --pid-file=/tmp/pids/mys
ql.pid --lc-messages-dir=/snap/nextcloud/21169/share --socket=/tmp/sockets/mysql.sock
root     18128  0.9 22.0 1815000 210060 ?      Sl   00:10   0:08 /snap/nextcloud/21169/bin/mysqld --basedir=/snap/nextcloud/21169 --datadir=/var/snap/nextcloud/21169/mysql --plu
gin-dir=/snap/nextcloud/21169/lib/plugin --lc-messages-dir=/snap/nextcloud/21169/share --log-error=error.log --pid-file=/tmp/pids/mysql.pid --socket=/tmp/sockets/mysql.sock
root     18196  0.0  2.1 200580 21712 ?        Ss   00:10   0:00 php-fpm: master process (/snap/nextcloud/21169/config/php/php-fpm.conf)
root     18980  0.0  0.1   1872  1276 ?        S    00:10   0:00 /bin/sh /snap/nextcloud/21169/bin/httpd-wrapper -k start -DFOREGROUND
root     19017  0.0  0.0   6168  0280 ?        S    00:10   0:00 httpd -d /snap/nextcloud/21169 -k start -DFOREGROUND
root     19018  0.0  0.1 1211772 1612 ?        Sl   00:10   0:00 httpd -d /snap/nextcloud/21169 -k start -DFOREGROUND
root     19019  0.0  0.1 880108  1668 ?        Sl   00:10   0:00 httpd -d /snap/nextcloud/21169 -k start -DFOREGROUND
root     19020  0.0  0.1 1080512 1656 ?        Sl   00:10   0:00 httpd -d /snap/nextcloud/21169 -k start -DFOREGROUND
root     19221  0.0  0.0 1716012 0292 ?        Sl   00:10   0:00 httpd -d /snap/nextcloud/21169 -k start -DFOREGROUND

これでもうデーモンも起動しているので対象マシンのホスト名やipアドレスをウェブブラウザに入力して任意の管理者ユーザのユーザ名とパスワードを入力して登録します.同じネットワークだと誰でも繋いで設定できてしまうので注意しましょう.

管理者ユーザ登録画面

snap nextcloud 20200609 22:06:09 329531

「推奨アプリをインストール」にチェックを入れておくと便利な推奨アプリが導入されます.時間がかかるので後でもいいかもしれません.

これでとりあえずNextcloudが利用できるようになりました.実はここまでは snapパッケージが amd64以外にも arm64. armhf, i386, ppc64el に対応しているので armhf/arm64 な Raspberry Pi などでも動作します.

続いて OnlyOffice, community edition の server版を導入します.

Nextcloudのウェブからも導入できるのですが,300MB程とサイズが大きく回線によってはタイムアウトしてしまいます.

snap nextcloud 20200606 19:06:50 477356

その場合は occ コマンドで導入します.(snapなので nextcloud.occ コマンドを使います)

$ sudo /snap/bin/nextcloud.occ app:install documentserver_community

これでも失敗することがあります.その場合は手動でGitHub からアーカイブを入手して手動で展開して有効化します.(この方法だとamd64以外でも導入はできちゃいますが動かないので注意)

$ COUNT=1; while :;do wget https://github.com/nextcloud/documentserver_community/releases/download/v0.1.6/documentserver_community.tar.gz && break; c=$(( $c + 1 )) ;sleep 10; done;echo $COUNT
$ sudo tar xvf ./documentserver_community.tar.gz -C /var/snap/nextcloud/current/nextcloud/extra-apps/
$ sudo chown -R root.root /var/snap/nextcloud/current/nextcloud/extra-apps/documentserver_community
$ sudo /snap/bin/nextcloud.occ app:enable documentserver_community

CollaboraはAppImageを使っていたのでファイル数は少なかったですがこちらは普通にディレクトリに展開されるようでたくさんあります.

$ sudo find /var/snap/nextcloud/current/nextcloud/extra-apps/documentserver_community | wc -l
12935

続いてOnlyOfficeアプリも導入します.

これはOnlyOffice Serverに繋いでやり取りするものです.Nextcloud のアプリ画面若しくは以下のコマンドで導入します.

$ sudo /snap/bin/nextcloud.occ app:install onlyoffice

これでNextcloudに戻って対応ドキュメントを開いたり新規作成するとOnlyOfficeが起動して編集できるはずです :)

snap nextcloud 20200609 23:06:12 405447
snap nextcloud 20200610 00:06:05 415116

アプリが導入されているけどうまく行かない場合はOnlyOfficeアプリを導入し直すとうまく行くかもしれません.(OnlyOfficeアプリがServerより先に導入されるとうまく行かない)

$ sudo /snap/bin/nextcloud.occ app:remove onlyoffice
$ sudo /snap/bin/nextcloud.occ app:install onlyoffice

とりあえずこれでお試しは出来る感じです.実際に運用するにはhttps化したりバックアップを定期的に取るようにしたりなど設定したほうがいいですがパスやコマンド以外は通常のNextcloudと同じだと思います.
主なパスやコマンドはこうなっています.

  • 設定ファイル /var/snap/nextcloud/current/nextcloud/config/config.php
  • Nextcloudデータ,ログ /var/snap/nextcloud/common/
  • 関連アプリ格納 /var/snap/nextcloud/current/
  • occ /snap/bin/nextcloud.occ
  • mysql-client /snap/bin/mysql-client
  • mysqldump /snap/bin/nextcloud.mysqldump

dbのアカウント情報は設定ファイルに載っています.

$ sudo grep db /var/snap/nextcloud/current/nextcloud/config/config.php
  'dbtype' => 'mysql',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost:/tmp/sockets/mysql.sock',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nextcloud',
  'dbpassword' => 'wdwYevflNhziZDUxxG2OXJs6el4zThtkmX20Bijih7Zh_4XU58OkZs3TAt7TCJjt',

設定ファイルを編集してデーモンを再起動したい場合はこんな感じで再起動できます.

$ sudo snap restart nextcloud

てことでsnap版Nextcloudはお試しにはおすすめです.
OnlyOfficeは今のところamd64環境しか提供されていませんがRaspberry Pi などでも動くようにしたいと言っているのでこれも期待です.

Nextcloud 19 だと先日紹介したCollaboraも同様にWebから導入できるのでおすすめです.

Lutrisを使ってLinuxでもEpic Gamesで遊ぶ

Epic Games というゲームプラットホームがあります.定期的にゲームを無料配布してくれるのでたまに貰っています.

しかしこのプラットホームは Stream や itch などと違い PC/Mac のみの対応で Linux には対応していません.

Epic Games Storeはどのプラットフォームに対応していますか?
Epic Games Storeは、現在PCとMacに対応しています。各タイトルのプラットフォームとの互換性については、製品ページの「ゲームについて」で確認することができます。

無料で貰っても遊ばないと意味がないです.
そういえば Lutris 経由で動かないかな?と思いつきました.Lutris はLinux 環境で各種プラットホームのゲーム環境を管理できて,複数のWine 環境を簡単に導入設定できたりして便利です.ここで貰ったゲームが出てきたらお手軽に遊べそうです.

Lutris についての詳細は以下のスライドもどうぞ.

ゲームの前に Lutris で Epic Games で検索すると Epic Games が出てきました.「Install」ボタンを押してウィザードに従うだけで簡単に導入できました.

lutris epic 20200606 03:06:59 18609

後は Epic Games でゲームをインストールしてみると起動しました :)

lutris epic 20200606 08:06:45 150593

lutris epic 20200606 08:06:24 148344
lutris epic 20200606 08:06:15 147780

思ったより手軽に遊べそうです.
しかし暖かくなって排熱が追いつかない感じでちょっと辛い今日この頃です.

//

環境
$ apt show lutris
Package: lutris
Version: 0.5.6
Priority: optional
Section: games
Maintainer: Mathieu Comandon <strider@strycore.com>
Installed-Size: 4,035 kB
Depends: python3-evdev, python3-gi, python3-requests, python3-yaml, python3:any, python3-pil, python3-setproctitle, python3-distro, gir1.2-gtk-3.0, gir1.2-gnomedesktop-3.0, gir1
.2-webkit2-4.0, gir1.2-notify-0.7, psmisc, cabextract, unzip, p7zip, curl, fluid-soundfont-gs, x11-xserver-utils, mesa-utils
Recommends: gvfs-backends, libwine-development, winetricks, libc6-i386, lib32gcc1
Suggests: gamemode
Homepage: https://lutris.net
Download-Size: 1,690 kB
APT-Manual-Installed: yes
APT-Sources: http://download.opensuse.org/repositories/home:/strycore/Debian_Unstable  Packages
Description: open source gaming platform
 Lutris goal is to make gaming on Linux as easy as possible by taking care of
 installing and setting up the game for the user. The only thing you have to do
 is play the game. It aims to support every game that is playable on Linux.

$ lsb_release -dr
Description:    Debian GNU/Linux bullseye/sid
Release:        unstable
$ uname -m
x86_64

Nextcloud 19からのNextcloudアプリ化したCollabora Online を試す

Nextcloud 19がリリースされました.

今回の新機能にCollabora Online がNextcloud Hub に含まれるようになり,簡単にすべてのユーザが利用できるようになったそうです.

Easy to install for every user
Collabora Online will be shipped out of the box with the new Nextcloud 19 Hub. A special community server has been developed, that can easily be installed with a single click by every user, and so avoiding web server and docker containers installation and configuration.

少し前にもデモサーバーを用意してくれてお手軽に試せるようにしてくれていましたが今回は自分の環境でとても簡単に動くようになったようです.

ということでNextcloud 19 にアップデートして試してみました.

Nextcloud 19環境管理者権限で https://$NEXTCLOUDURL/index.php/settings/admin/richdocuments にアクセスして設定を見てみます.

NC19 CODE 01

Use the built-in CODE という設定が増えています.がグレーアウトしています.

Use the built-in CODE – Collabora Online Development Edition
Easy to install, for personal use or for small teams. A bit slower than a standalone server and without the advanced scalability features.

てことで,以下のNextcloud アプリを導入します.

NC19 CODE 02

導入は本当に簡単で「ダウンロードして有効にする」を押すだけです.

コマンドラインではこんな感じで導入できます.

$ sudo -u www-data php ./occ app:install richdocumentscode
richdocumentscode installed
richdocumentscode enabled

導入されると Built-in CODE が選べるようになっているので選択します.後はファイルでオフィス文章を開いたり新規作成すれば自動的に起動して利用できます.

NC19 CODE 03

初回はちょっと時間がかかります.これはCODEが裏で起動する時間がかかるからみたいです.
後は普通に利用できます :)
Demoサーバと違って制限もないので普通に使えます.NextcloudでURL共有をするとGoogleDoc のようにみんなで同時にドキュメントを編集したりも出来ます.(Nextcloudの指定ユーザだけ編集可能とかURLを知ってる人は誰でも編集できるとかも出来ます.)

少し使っていて気になったのは以下のメッセージがたまに出ます.ディスク空き容量が 4GBで出るときと出ないときがありぎりぎり動いているのかなと思いましたが,空き容量を6GBに空けても出たり出なかったりします.もしかしたらバグかも?

NC19 CODE 04

そしてこちらの画面はセッションが数個(2個のつもり)でも出ます.セッションのカウントがおかしいのか他のバグなのか?

NC19 CODE 05

今回のCollabora Online はどんな仕組みなのかなとディレクトリを覗くと,Collabora Online がAppImage 化されてごろっと置かれているようです.

$ ls -l apps/richdocumentscode/collabora/
total 339320
-rwxr--r-- 1 www-data www-data 347455528 Jun  5 01:27 Collabora_Online.AppImage

これが文章を閉じてもずっと起動しているようです.RAMが少ないのでちょっと辛い.

$ ps aux | pee "head -1" "grep Collabora_OnlineAppImage"
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
mk       29361  0.0  0.0   2272   752 pts/2    S+   23:04   0:00 pee head -1 grep Collabora_OnlineAppImage

このマシンはリモートのサーバで日本語フォントがほとんど入っていないのでCollabora Online でもフォントがあまり選べません.システムにフォントを導入します.今回はNoto CJK を導入してみました.

$ sudo apt install fonts-noto-cjk

導入してもそのままではCollabora Online には反映されませんでした.文章を閉じて,AppImage のプロセスをkill して再度文章を開くとまた AppImage が起動して反映されました.

ということでとても簡単にWebだけでNextcloud からCollabora Online が導入できるようになりました.
とても便利なのでおすすめです.

環境
$ sudo -u www-data php ./occ app:list | grep richdocuments
  - richdocuments: 3.7.0
  - richdocumentscode: 4.2.403
$ sudo -u www-data php ./occ status
  - installed: true
  - version: 19.0.0.12
  - versionstring: 19.0.0
  - edition:
$ dpkg-query -W php apache2
apache2 2.4.38-3+deb10u3
php     2:7.3+69
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64