Ubuntu – matoken's blog https://matoken.org/blog Is there no plan B? Wed, 01 Mar 2023 13:42:34 +0000 ja hourly 1 https://wordpress.org/?v=6.9 https://matoken.org/blog/wp-content/uploads/2025/03/cropped-1865f695c4eecc844385acef2f078255036adccd42c254580ea3844543ab56d9-32x32.jpeg Ubuntu – matoken's blog https://matoken.org/blog 32 32 Nostr の Vanity address を掘る https://matoken.org/blog/2023/03/01/nostr-vanity-adress/ https://matoken.org/blog/2023/03/01/nostr-vanity-adress/#comments Wed, 01 Mar 2023 13:42:34 +0000 https://matoken.org/blog/?p=3864

Nostr という分散型SNSのプロトコルがあって最近良く見かけます.

このSNSの個人認識に秘密鍵と公開鍵のペアを作成してそれを利用します.鍵ペアは初回に自動生成されるのですが,公開鍵の文字列をたくさん計算して好みのアドレスが含まれたアドレスを掘るプログラムがあったので試してみました.

このプログラムはbech32で表現される公開鍵の npub1 の後ろの文字列を任意の文字列から始まるものにしたいというvanity アドレスを彫りたい人向けのものです.

導入

cargo insrtall で導入できるはずですが,手元のDebian bookworm testing amd64 環境ではrustc が 1.63 に対してrana は 1.64.0 以上が必要だということで古くて失敗しました.

$ cargo install rana
    Updating crates.io index
  Installing rana v0.5.1
  Downloaded is-terminal v0.4.4
  Downloaded clap_lex v0.3.2
  Downloaded syn v1.0.109
  Downloaded bip39 v1.2.0
  Downloaded 4 crates (346.5 KB) in 2.86s
error: failed to compile `rana v0.5.1`, intermediate artifacts can be found at `/tmp/cargo-installvCF9z2`

Caused by:
  package `clap_derive v4.1.0` cannot be built because it requires rustc 1.64.0 or newer, while the currently active rustc version is 1.63.0
  Try re-running cargo install with `--locked`
$ dpkg-query -W rustc
rustc   1.63.0+dfsg1-2

Rust Forge で新しいStable(1.67.1)を貰ってきて使おうかとも思いましたが,インストーラーを叩く形で環境が汚れそうで少し面倒そう.

Docker を使うことにします.

公式イメージだけあって最新の 1.67.1 です.rana もさくっと動きました.

$ script ./nostr_vanity.log
$ docker run --rm -it rust
# rustc --version
rustc 1.67.1 (d5a82bbd2 2023-02-07)
# adduser matoken
# su - matoken
$ export PATH=/usr/local/cargo/bin:$PATH
$ rustup default stable
$ cargo install rana
$ rana --help
Rana 🐸

      o  o
     ( -- )
  /\( ,   ,)/\
^^   ^^  ^^   ^^

A simple CLI to generate nostr vanity addresses

Francisco Calderón <negrunch@grunch.dev>

Usage: rana [OPTIONS]

Options:
  -d, --difficulty <DIFFICULTY>
          Enter the number of starting bits that should be 0. [default: 0]
  -v, --vanity <VANITY_PREFIX>
          Enter the prefix your public key should have when expressed
          as hexadecimal. [default: ]
  -n, --vanity-n-prefix <VANITY_NPUB_PREFIXES_RAW_INPUT>
          Enter the prefix your public key should have when expressed
          in npub format (Bech32 encoding). Specify multiple vanity
          targets as a comma-separated list. [default: ]
  -s, --vanity-n-suffix <VANITY_NPUB_SUFFIXES_RAW_INPUT>
          Enter the suffix your public key should have when expressed
          in npub format (Bech32 encoding). Specify multiple vanity
          targets as a comma-separated list. [default: ]
  -c, --cores <NUM_CORES>
          Number of processor cores to use [default: 4]
  -r, --restore <MNEMONIC>
          Restore from mnemonic to public private key [default: ]
  -g, --generate <WORD_COUNT>
          Generate mnemonic using wordcount. Should be 12,18 or 24 [default: 0]
  -p, --passphrase <MNEMONIC_PASSPHRASE>
          Passphrase used for restoring mnemonic to keypair [default: ]
  -q, --qr
          Print QR code of the private key
  -h, --help
          Print help
  -V, --version
          Print version

why can’t we use characters b, i, o, or 1?
the characters have to be in the bech32 character set.

— nostrogen
https://github.com/tonyinit/nostrogen#why-cant-we-use-characters-b-i-o-or-1

公開鍵は Bech32 形式で 023456789acdefghjklmnpqrstuvwxyz が利用できます.以下は Bech32 で使えない o を使って怒られた例です.

$ rana --vanity-n-prefix matok
thread 'main' panicked at 'The vanity npub prefix can only contain characters supported by Bech32: 023456789acdefghjklmnpqrstuvwxyz', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/rana-0.5.1/src/cli.rs:146:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

oを0に置き換えて動かしてみます.

$ rana --vanity-n-prefix mat0k | tee rana.log
Started mining process for vanity bech32 prefix[es]: 'npub1["mat0k"]' (estimated pow: 20)
Benchmarking of cores disabled for vanity npub key upon proper calculation.
Mining using 4 cores...

さて,これで待っていれば鍵が掘れるのですが,以下のように新しいラップトップで以下のような速度で掘れるとのことです.あまり長くするとなかなか掘れないので気をつけましょう.

how fast will nostrogen find my addresses?
this depends entirely upon how fast your machine is, but here are some rough estimates for a modern laptop or mobile phone:

1 character = usually less than a 0.1 seconds
2 characters = usually less than a 1 second
3 characters = usually less than a 30 seconds
4 characters = usually less than a 10 minutes
5 characters = usually less than a 1 hour
6+ characters = keep fire extinguisher handy

— nostrogen
https://github.com/tonyinit/nostrogen#how-fast-will-nostrogen-find-my-addresses

以下のような感じで結果が表示されます.Npub public key の npub1の後ろが指定したmat0kから始まっています.

$ rana --vanity-n-prefix mat0k | tee rana.log
Started mining process for vanity bech32 prefix[es]: 'npub1["mat0k"]' (estimated pow: 20)
Benchmarking of cores disabled for vanity npub key upon proper calculation.
Mining using 4 cores...
<<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>>
Vanity npub found:         mat0k
Found matching Nostr public key:
Hex public key:   df56fb6cce5a60eac0a55b09ff6d5fbb565b07da6f64a2578ae827d70a21873b
Hex private key:  7a1a088022c3110fabc445af28681c0d2c349a2123f38fe83fbc809d7c8ed6bb
Npub public key:  npub1mat0kmxwtfsw4s99tvyl7m2lhdt9kp76daj2y4u2aqnawz3psuass9qwnz
Nsec private key: nsec10gdq3qpzcvgsl27ygkhjs6qup5krfx3py0ecl6plhjqf6lyw66as4gyfat
26169409 iterations (about 2x10^7 hashes) in 3199 seconds. Avg rate 8180 hashes/second
Warning
公開されているこの鍵は利用しないでください

手元の,NotePCの Intel® Core™ i5-7300U CPU @ 2.60GHz と Oeracle Free Tier VPS Arm Ampere A1 共に8000〜8200 hashes/secod という感じでした.

3日ほど走らせて mak0 から始まるものたくさん,mat0ke から始まるものが2つ出てきました. cpu fan うるさいしmat0ken は諦めてこの辺にしとこうかな?

Npub public key: npub1mat0kejpylctwszs3h0jcaw24vsmzvx0h44hl2qf3ghuz2ggekjqkwyeq5

そういえば以前はTor の Vanity address も掘っていました…….

]]>
https://matoken.org/blog/2023/03/01/nostr-vanity-adress/feed/ 1
Ubuntu22.10のFirefoxをPPAのものに変更 https://matoken.org/blog/2022/06/30/firefox-changed-to-ppa-at-ubuntu/ https://matoken.org/blog/2022/06/30/firefox-changed-to-ppa-at-ubuntu/#comments Thu, 30 Jun 2022 13:48:04 +0000 http://matoken.org/blog/?p=3700

先日snap版Firefoxのアップデートに悩んだり,KeepassXCのブラウザ統合がsnap版に非対応だったりしてsnap版のFirefoxが使いづらいなと感じています.
Ubuntu Mozilla TeamのPPA版Firefox ESRに入れ替えてみました.

まず,既存のFirefoxを削除します.

$ sudo snap remove firefox
$ sudo apt purge firefox
Note

snapパッケージだけでなく,Ubuntuのfirefoxパッケージがありました,snap版がない状態で実行するとsnap版を導入するよう言われました.

$ firefox

Command '/usr/bin/firefox' requires the firefox snap to be installed.
Please install it with:

snap install firefox

PPAの登録を行いパッケージの更新を行います.

$ sudo add-apt-repository ppa:mozillateam/ppa
$ sudo apt update

firefox パッケージはsnapですが, firefox-esr はさっき登録したPPA版に向いています.

$ apt show firefox
Package: firefox
Version: 1:1snap1-0ubuntu2
Priority: optional
Section: web
Origin: Ubuntu
Maintainer: Ubuntu Mozilla Team <ubuntu-mozillateam@lists.ubuntu.com>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 261 kB
Provides: gnome-www-browser, iceweasel, www-browser, x-www-browser
Pre-Depends: debconf, snapd
Depends: debconf (>= 0.5) | debconf-2.0
Breaks: firefox-dbg (<< 1:1snap1), firefox-dev (<< 1:1snap1), firefox-geckodriver (<< 1:1snap1), firefox-mozsymbols (<< 1:1snap1)
Replaces: firefox-dbg (<< 1:1snap1), firefox-dev (<< 1:1snap1), firefox-geckodriver (<< 1:1snap1), firefox-mozsymbols (<< 1:1snap1)
Task: xubuntu-live, ubuntukylin-desktop
Download-Size: 72.3 kB
APT-Manual-Installed: yes
APT-Sources: http://jp.archive.ubuntu.com/ubuntu kinetic/main amd64 Packages
Description: Transitional package - firefox -> firefox snap
 This is a transitional dummy package. It can safely be removed.
 .
 firefox is now replaced by the firefox snap.

N: 追加レコードが 1 件あります。表示するには '-a' スイッチを付けてください。
$ apt show firefox-esr
Package: firefox-esr
Version: 91.11.0esr+build2-0ubuntu0.22.04.1
Priority: optional
Section: web
Maintainer: Ubuntu Mozilla Team <ubuntu-mozillateam@lists.ubuntu.com>
Installed-Size: 225 MB
Provides: gnome-www-browser, iceweasel, www-browser
Depends: lsb-release, libatk1.0-0 (>= 1.12.4), libc6 (>= 2.35), libcairo-gobject2 (>= 1.10.0), libcairo2 (>= 1.10.0), libdbus-1-3 (>= 1.9.14), libdbus-glib-1-2 (>= 0.78), libfontconfig1 (>= 2.12.6), libfreetype6 (>= 2.10.1), libgcc-s1 (>= 4.0), libgdk-pixbuf-2.0-0 (>= 2.22.0), libglib2.0-0 (>= 2.42), libgtk-3-0 (>= 3.14), libharfbuzz0b (>= 0.6.0), libpango-1.0-0 (>= 1.14.0), libpangocairo-1.0-0 (>= 1.14.0), libpangoft2-1.0-0 (>= 1.14.0), libstdc++6 (>= 12), libx11-6, libx11-xcb1 (>= 2:1.7.5), libxcb-shm0, libxcb1, libxcomposite1 (>= 1:0.4.5), libxcursor1 (>> 1.1.2), libxdamage1 (>= 1:1.1), libxext6, libxfixes3, libxi6, libxrender1, libxt6
Recommends: xul-ext-ubufox, libcanberra0, libdbusmenu-glib4, libdbusmenu-gtk3-4
Suggests: fonts-lyx
Xul-Appid: {ec8030f7-c20a-464f-9b0e-13a3a9e97384}
Download-Size: 61.8 MB
APT-Manual-Installed: yes
APT-Sources: https://ppa.launchpadcontent.net/mozillateam/ppa/ubuntu kinetic/main amd64 Packages
Description: Safe and easy web browser from Mozilla
 Firefox delivers safe, easy web browsing. A familiar user interface,
 enhanced security features including protection from online identity theft,
 and integrated search let you get the most out of the web.

firefox-serと日本語言語パッケージを導入します.

$ sudo apt install firefox-esr firefox-esr-locale-ja
$ firefox-esr --version
Mozilla Firefox 91.11.0esr

最新版が使いたい場合は使えない手ですが…….

環境
$ dpkg-query -W firefox-esr* keepassxc
firefox-esr     91.11.0esr+build2-0ubuntu0.22.04.1
firefox-esr-locale-ja   91.11.0esr+build2-0ubuntu0.22.04.1
keepassxc       2.6.6+dfsg.1-1
$ lsb_release -dr
Description:    Ubuntu Kinetic Kudu (development branch)
Release:        22.10
$ arch
x86_64
]]>
https://matoken.org/blog/2022/06/30/firefox-changed-to-ppa-at-ubuntu/feed/ 1
snapのアプリケーションが更新されない? https://matoken.org/blog/2022/06/30/snap-application-not-updated/ https://matoken.org/blog/2022/06/30/snap-application-not-updated/#respond Thu, 30 Jun 2022 13:15:08 +0000 http://matoken.org/blog/?p=3697

先日snapパッケージの更新を手動で行ってうまく行かなかったのでメモしておきます.該当アプリケーションを終了してから更新すればうまく行きました.

snap版のFirefoxパッケージが少し古いです.
101.0.1-1 に対して 101.0-2 が入っています.

$ sudo snap refresh
All snaps up to date.
$ snap find firefox | grep \*
firefox               101.0.1-1      mozilla**     -      Mozilla Firefox web browser
$ snap info firefox
name:      firefox
summary:   Mozilla Firefox web browser
publisher: Mozilla✓
store-url: https://snapcraft.io/firefox
contact:   https://support.mozilla.org/kb/file-bug-report-or-feature-request-mozilla
license:   unset
description: |
  Firefox is a powerful, extensible web browser with support for modern web application
  technologies.
commands:
  - firefox
  - firefox.geckodriver
snap-id:      3wdHCAVyZEmYsCMFDE9qt92UV8rC8Wdk
tracking:     latest/stable/ubuntu-21.10
refresh-date: 6 days ago, at 15:52 JST
channels:
  latest/stable:    101.0.1-1    2022-06-09 (1443) 170MB -
  latest/candidate: 101.0.1-1    2022-06-09 (1443) 170MB -
  latest/beta:      102.0b5-2    2022-06-09 (1439) 170MB -
  latest/edge:      103.0a1      2022-06-09 (1442) 180MB -
  esr/stable:       91.10.0esr-1 2022-05-31 (1391) 161MB -
  esr/candidate:    91.10.0esr-1 2022-05-23 (1391) 161MB -
  esr/beta:         ↑
  esr/edge:         ↑
installed:          101.0-2                 (1406) 170MB -

手動で更新しても最新だと言われて更新されません.

$ sudo snap refresh
All snaps up to date.
$ snap find firefox | grep \*
firefox               101.0.1-1      mozilla**     -      Mozilla Firefox web browser

snapの更新時間を制限しているのでこれのせいかと思って解除してもだめです.

$ snap refresh --time (1)
timer: 01:00-05:59
last: today at 01:00 JST
next: tomorrow at 01:00 JST
$ sudo snap unset system refresh.timer (2)
$ snap refresh --time (3)
timer: 00:00~24:00/4
last: today at 01:00 JST
next: today at 22:48 JST
$ sudo snap get system (4)
Key      Value
refresh  {...}
seed     {...}
system   {...}
$ sudo snap refresh
All snaps up to date.
$ snap find firefox | grep \*
firefox               101.0.1-1      mozilla**     -      Mozilla Firefox web browser
  1. 01:00〜05:59 に更新するようになっている
  2. 更新時間を解除して既定値に
  3. 24時間更新可能になっている
  4. 後の設定は既定値

以下のページを見るとsnapアプリケーション起動中にはアップデート行わないオプションを実験中というのを見かけました.記事は2年以上前のものです.もう実装されているのかも?

書いてある設定は見当たりません.

$ sudo snap get core experimental.refresh-app-awareness
error: snap "core" has no "experimental" configuration option

Firefoxをkillしてから snap refresh を試すとアップデートがうまく行きました.

$ pgrep firefox
302750
$ pkill firefox
$ pgrep firefox
$ sudo snap refresh
firefox 101.0.1-1 from Mozilla✓ refreshed
$ snap find firefox | grep \*
firefox               101.0.1-1      mozilla**     -      Mozilla Firefox web browser

この辺りの設定はいじった覚えがないので,既定値がsnapアプリ起動中には更新を行わないようになっているようです.とりあえずはアプリケーションを終了してからrefreshでしょうか.

環境
$ dpkg-query -W snapd
snapd   2.55.3+22.04ubuntu1
$ snap find firefox | grep \*
firefox               101.0.1-1      mozilla**     -      Mozilla Firefox web browser
$ lsb_release -dr
Description:    Ubuntu Kinetic Kudu (development branch)
Release:        22.10
$ arch
x86_64
]]>
https://matoken.org/blog/2022/06/30/snap-application-not-updated/feed/ 0
OracleCloud VPSにブロックストレージを追加 https://matoken.org/blog/2022/06/28/add-block-storage-to-oracle-cloud-vps/ https://matoken.org/blog/2022/06/28/add-block-storage-to-oracle-cloud-vps/#respond Tue, 28 Jun 2022 14:13:26 +0000 http://matoken.org/blog/?p=3691

Matrixの文章を見ていたらOracleのサービスで200GBまでストレージが使えそうなのに気づきました.

表 1. Free Matrix Server using Oracle Cloud | Matrix.org
Vendor Time-limit Count RAM (GB) Storage (GB) Transfer (GB)

AWS

12 months

1 t2.micro

1

30

15

Azure

12 months

1 B1S

1

2x 64

15

GCP

no limit

1 e2-micro

1

30

1

Oracle

no limit

1-4 VM.Standard.A1.Flex

24

200

10000

公式ページを見ても200GB使えそうです.

2つのBlock Volumeストレージ、合計200 GB。

現在は50GB程x2利用しているのであと100GB使えそうです.試してみました.


https://cloud.oracle.com/ からログインして,「ストレージ」→「ブロック・ボリューム」から,「ブロック・ボリュームの作成」を行います.

そこで「名前」に「任意の名前」,ボリューム・サイズとパフォーマンス → カスタム,ボリューム・サイズ(GB)に「100GB」を設定.

左下の「リソース」,「メトリック」→「アタッチされたインスタンス」から「ブロック・ボリュームのアタッチ」で既存のインスタンスニアタッチします.
ここでは「ボリュームの選択」→「上で作成したボリューム」,「アタッチメント・タイプ」→「準仮想化」,「アクセス」→「読取り/書込み」,「デバイス・パス」→「/dev/oracleoci/oraclevdb」
という感じで設定しました.

(スクリーンショットを取得してなかったので大雑把です……)

この状態でインスタンを確認するとデバイス( /dev/oracleoci/oraclevdb )が出来ていました. /dev/sdb にシンボリックリンクがはられています.

$ ls /dev/oracleoci/oraclevdb
/dev/oracleoci/oraclevdb
$ ls -l /dev/sdb /dev/oracleoci/oraclevdb
lrwxrwxrwx 1 root root     6 Jun 28 12:57 /dev/oracleoci/oraclevdb -> ../sdb
brw-rw---- 1 root disk 8, 16 Jun 28 12:57 /dev/sdb

後は普通のLinuxなのでパーティションを切って,フォーマットしてマウントします.

$ sudo fdisk -l /dev/oracleoci/oraclevdb (1)
Disk /dev/oracleoci/oraclevdb: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: BlockVolume
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
$ sudo fdisk /dev/oracleoci/oraclevdb (2)

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x130d310a.

Command (m for help): n (3)
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p (4)
Partition number (1-4, default 1): (5)
First sector (2048-209715199, default 2048): (6)
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-209715199, default 209715199): (7)

Created a new partition 1 of type 'Linux' and of size 100 GiB.

Command (m for help): p (8)
Disk /dev/oracleoci/oraclevdb: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: BlockVolume
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: dos
Disk identifier: 0x130d310a

Device                    Boot Start       End   Sectors  Size Id Type
/dev/oracleoci/oraclevdb1       2048 209715199 209713152  100G 83 Linux

Command (m for help): w (9)
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

$ sudo mkfs.ext4 /dev/oracleoci/oraclevdb1 (10)
mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 26214144 4k blocks and 6553600 inodes
Filesystem UUID: dbc5f8b5-5f38-4246-9f41-6003e1f5d1fb
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done
Writing inode tables: done
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information: done

$ sudo mkdir /export (11)
$ sudo mount /dev/oracleoci/oraclevdb1 /export (12)
$ df -H | grep -vE "loop|tmpfs|udev" (13)
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        49G   29G   20G  60% /
/dev/sda15      103M  297k  102M   1% /boot/efi
/dev/sdb1       106G   63M  100G   1% /export
$ sudo umount /export (14)
$ echo "/dev/sdb1        /export ext4    defaults        0 1" | sudo tee -a /etc/fstab (15)
/dev/sdb1       /export ext4    defaults        0 1
$ sudo mount -a (16)
$ df -H | grep -vE "loop|tmpfs|udev" (17)
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        49G   29G   20G  60% /
/dev/sda15      103M  297k  102M   1% /boot/efi
/dev/sdb1       106G   63M  100G   1% /export
  1. diskの確認
  2. パーティションの設定
  3. n で新しいパーティション作成
  4. p でプライマリパーティション作成
  5. パーティション番号を Enter で規定値の 1
  6. 先頭セクタを Enter で規定値の 2048
  7. 終了セクタを Enter で規定値の 209715199 (全領域)
  8. p でパーティション設定確認
  9. w でパーティション書き込み
  10. ext4の既定値でフォーマット
  11. マウントポイント作成
  12. マウント
  13. 容量確認
  14. アンマウント
  15. /etc/fatab を設定
  16. fstab を使ってマウント
  17. マウント確認

後は普通に使えるはずです.

ということでarm64 4core, 24GB RAN, Disk 150GBな無料VPSができました.amd64のインスタンスを削除すればDisk 200GBにもできるはずです.
これが無料で使えるのすごいですね.(いつ使えなくなってもおかしくはないだろうけど)

]]>
https://matoken.org/blog/2022/06/28/add-block-storage-to-oracle-cloud-vps/feed/ 0
argosをGnome42(Ubuntu 22.04)でも使う https://matoken.org/blog/2022/05/21/use-argos-with-gnome42-ubuntu-22-04/ https://matoken.org/blog/2022/05/21/use-argos-with-gnome42-ubuntu-22-04/#respond Sat, 21 May 2022 13:58:36 +0000 http://matoken.org/blog/?p=3640

久々にGnome Shellを起動したところ拡張機能のargosが起動しなくなっていました.

argos gnome42 ng

リポジトリを見るGnome42対応をしている人がいたので,以下のリポジトリの gnome-42 ブランチを利用させてもらうことで動くようになりました :)

$ trash ~/.local/share/gnome-shell/extensions/argos\@pew.worldwidemann.com (1)
$ git clone https://github.com/Coda-Coda/argos (2)
$ cd argos
$ git branch (3)
* gnome-42
$ cp -a argos\@pew.worldwidemann.com ~/.local/share/gnome-shell/extensions/ (4)
  1. 古いargosをゴミ箱に
  2. Gnome42対応argosのリポジトリをクローン
  3. ブランチが gnome-42 になっているのを確認
  4. argos をGnomeShell拡張機能ディレクトリにコピー

このあと, Alt + F2 r Enter で反映します.

argos gnome42

動作するようになりました :)

詳細は以前の記事を.

環境
$ dpkg-query -W gnome-shell gnome-shell-extensions
gnome-shell     42.0-2ubuntu1
gnome-shell-extensions  42.0-1
$ lsb_release -dr
Description:    Ubuntu 22.04 LTS
Release:        22.04
$ arch
x86_64
]]>
https://matoken.org/blog/2022/05/21/use-argos-with-gnome42-ubuntu-22-04/feed/ 0
導入済みのLinuxにスワップを設定する(Oracle Cloud VPS) https://matoken.org/blog/2022/04/23/set-up-swap-on-installed-linuxoracle-cloud-vps/ https://matoken.org/blog/2022/04/23/set-up-swap-on-installed-linuxoracle-cloud-vps/#respond Fri, 22 Apr 2022 22:49:44 +0000 http://matoken.org/blog/?p=3624

最近Oracle Cloud VPSのFree Tier Always Free枠で遊んでいます.
今日はなんだかとても重くなりましたRAMが1GBあるのですが,9割以上利用していました.swapは未設定.swapを設定してみました.
Oracle Cloudですが大抵の環境でも同じように出来るはずです.

アドホックなswapファイル設定

まずは急場しのぎによく使う方法でスワップファイルを作成して利用する方法.

適当な場所に空ファイルを作成します. ここでは2GB分作成しました.

$ sudo dd if=/dev/zero of=/var/tmp/swap bs=1M count=2048

swapを設定します.

$ sudo chmod 600 /var/tmp/swap (1)
$ sudo mkswap /var/tmp/swap (2)
$ sudo swapon /var/tmp/swap (3)
$ free -h (4)
              total        used        free      shared  buff/cache   available
Mem:          966Mi       303Mi        62Mi        12Mi       600Mi       501Mi
Swap:         2.0Gi       0.0Ki       2.0Gi
$ sudo swapoff /var/tmp/swap (5)
$ sudo rm /var/tmp/swap (6)
  1. rootのみ読み書きに設定
  2. swapファイルを初期化
  3. swapに割当
  4. swapが設定されたのを確認
  5. 必要なくなったらswapから取り外し
  6. 必要なくなったswapファイルを削除

使い続けたい場合は/etx/fstabに設定することで永続化して再起動後も利用することができます.(下のswapパーティションを作る方法のほうが少し速いはず)

$ sudo vi /etc/fstab (1)
$ sudo git -C /etc diff HEAD~ /etc/fstab (2)
diff --git a/fstab b/fstab
index d1ac1c3..01c9c0e 100644
--- a/fstab
+++ b/fstab
@@ -1,5 +1,6 @@
 LABEL=cloudimg-rootfs  /        ext4   defaults        0 1
 LABEL=UEFI     /boot/efi       vfat    umask=0077      0 1
+/var/tmp/swap  none    swap    pri=-1  0 0

 # CLOUD_IMG: This file was created/modified by the Cloud Image build process
 ######################################
$ sudo swapon -av (3)
swapon: /var/tmp/swap: found signature [pagesize=4096, signature=swap]
swapon: /var/tmp/swap: pagesize=4096, swapsize=2147483648, devsize=2147483648
swapon /var/tmp/swap
$ free (4)
              total        used        free      shared  buff/cache   available
Mem:         989340      308556       71368       12880      609416      517280
Swap:       2097148           0     2097148
  1. /etc/fatab 修正
  2. /etc/fstab 修正内容
  3. swapを手動で反映(次回起動時からは自動的に反映される)
  4. swapが設定されたのを確認

ディスクを縮小してswapパーティションを作成

swapファイルを使う方法はお手軽ですが,レイヤーが増えるので少し遅くなるはずです.割当済のディスクを縮小してswapパーティションを作成してマウントします.

Warning

設定をミスするとシステムが壊れるので注意して操作してください.操作に不安がある場合は上のswapファイルを利用したほうが安全です.

Partedで処理を行います.GUIの場合はgPartedが解りやすくて便利です.
現在の状態を確認してみます.空きディスクはほとんどありませんが,パーティション1の /dev/dsa1 を縮小してswap用に貰うことにします.

$ sudo parted /dev/sda
  :
(parted) print free
Model: ORACLE BlockVolume (scsi)
Disk /dev/sda: 50.0GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
        17.4kB  1049kB  1031kB  Free Space
14      1049kB  5243kB  4194kB                     bios_grub
15      5243kB  116MB   111MB   fat32              boot, esp
 1      116MB   50.0GB  49.9GB  ext4

パーティション1を50GBから48GBにリサイズします.

(parted) resizepart
Partition number? 1
Warning: Partition /dev/sda1 is being used. Are you sure you want to continue?
Yes/No? yes
End?  [50.0GB]? 48GB
Warning: Shrinking a partition can cause data loss, are you sure you want to continue?
Yes/No? yes

パーティション1が小さくなりました.

(parted) print
Model: ORACLE BlockVolume (scsi)
Disk /dev/sda: 50.0GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
14      1049kB  5243kB  4194kB                     bios_grub
15      5243kB  116MB   111MB   fat32              boot, esp
 1      116MB   48.0GB  47.9GB  ext4

できた空き領域からswap用のパーティーションを作成します.

(parted) mkpart
Partition name?  []?
File system type?  [ext2]? linux-swap
Start? 48.0GB
End? 50GB
(parted) print
Model: ORACLE BlockVolume (scsi)
Disk /dev/sda: 50.0GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system     Name  Flags
14      1049kB  5243kB  4194kB                        bios_grub
15      5243kB  116MB   111MB   fat32                 boot, esp
 1      116MB   48.0GB  47.9GB  ext4
 2      48.0GB  50.0GB  2009MB  linux-swap(v1)

(parted) quit
Information: You may need to update /etc/fstab.

swapパーティションを初期化します.

$ sudo mkswap /dev/sda2
Setting up swapspace version 1, size = 1.9 GiB (2009067520 bytes)
no label, UUID=4e27ed83-3d75-4c3d-87ac-f16e618bba4a

アドホックに手動でswapを有効化してみます.

$ sudo swapon -v UUID=4e27ed83-3d75-4c3d-87ac-f16e618bba4a
swapon: /dev/sda2: found signature [pagesize=4096, signature=swap]
swapon: /dev/sda2: pagesize=4096, swapsize=2009071616, devsize=2009071616
swapon /dev/sda2
$ free
              total        used        free      shared  buff/cache   available
Mem:         989340      311428       83696       12884      594216      513164
Swap:       1961980           0     1961980

一旦swapをoffにして永続化のために/etc/fstabに登録してswaponしてみます.

$ sudo swapoff UUID=4e27ed83-3d75-4c3d-87ac-f16e618bba4a
$ sudo vi /etc/fstab
$ sudo git -C /etc diff /etc/fstab
diff --git a/fstab b/fstab
index e22bda5..72d64af 100644
--- a/fstab
+++ b/fstab
@@ -1,6 +1,6 @@
 LABEL=cloudimg-rootfs  /        ext4   defaults        0 1
 LABEL=UEFI     /boot/efi       vfat    umask=0077      0 1
-/var/tmp/swap  none    swap    pri=20  0 0
+UUID=4e27ed83-3d75-4c3d-87ac-f16e618bba4a      none    swap    pri=-1  0 0

 # CLOUD_IMG: This file was created/modified by the Cloud Image build process
 ######################################
ubuntu@instance-20220327-0134:~$ sudo swapon -a
ubuntu@instance-20220327-0134:~$ free
              total        used        free      shared  buff/cache   available
Mem:         989340      312360       80884       12884      596096      512232
Swap:       1961980           0     1961980

次回起動時から自動的に有効になるはずです.

環境

Oracle Cloud コンピュートインスタンス
イメージ
Canonical-Ubuntu-20.04-Minimal-2022.03.04-0
$ dpkg-query -W parted mount
mount   2.34-0.1ubuntu9.3
parted  3.3-4ubuntu0.20.04.1
$ lsb_release -dr
Description:    Ubuntu 20.04.4 LTS
Release:        20.04
$ uname -a
Linux instance-20220327-0134 5.13.0-1027-oracle #32~20.04.1-Ubuntu SMP Fri Apr 15 05:59:34 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
]]>
https://matoken.org/blog/2022/04/23/set-up-swap-on-installed-linuxoracle-cloud-vps/feed/ 0
Ubuntu 21.10 -> 22.04のアップグレードに失敗 https://matoken.org/blog/2022/04/14/ubuntu-21-10-22-04-upgrade-failed/ https://matoken.org/blog/2022/04/14/ubuntu-21-10-22-04-upgrade-failed/#respond Wed, 13 Apr 2022 22:29:33 +0000 http://matoken.org/blog/?p=3600

Ubuntu 21.10 amd64 から 22.04(development branch) へのアップグレード時に以下のようなエラーで失敗してしまいました.

unable to open '/usr/share/themes/Yaru/gnome-shell/calendar-today-light.svg.dpkg-new': No such file or directory

Preparing to unpack .../yaru-theme-gnome-shell_22.04.3.1_all.deb ...
Unpacking yaru-theme-gnome-shell (22.04.3.1) over (21.10.2) ...
dpkg: error processing archive /var/cache/apt/archives/yaru-theme-gnome-shell_22.04.3.1_all.deb (--unpack):
 unable to open '/usr/share/themes/Yaru/gnome-shell/calendar-today-light.svg.dpkg-new': No such file or directory
No apport report written because the error message indicates an issue on the local system
       Errors were encountered while processing:
 /var/cache/apt/archives/yaru-theme-gnome-shell_22.04.3.1_all.deb
.../yaru-theme-gnome-shell_22.04.3.1_all.deb を転換する準備をしています ...
yaru-theme-gnome-shell (22.04.3.1) で (21.10.2 に) 上書き展開しています ...
dpkg: アーカイブ /var/cache/apt/archives/yaru-theme-gnome-shell_22.04.3.1_all.deb の処理中にエラーが発生しました (--install):
 '/usr/share/themes/Yaru/gnome-shell/calendar-today-light.svg.dpkg-new' をオープンできません: そのようなファイルやディレクトリはありません
処理中にエラーが発生しました:
/var/cache/apt/archives/yaru-theme-gnome-shell_22.04.3.1_all.deb

エラーメッセージで検索すると以下のBugが見つかりました.

とりあえず添付された.debをダウンロードしてdpkgで導入すれば良さそうです.

$ wget https://bugs.launchpad.net/ubuntu/+source/yaru-theme/+bug/1968405/+attachment/5580229/+files/yaru-theme-gnome-shell_22.04.3.1+git2ff06a41_all.deb
$ sudo dpkg -i ./yaru-theme-gnome-shell_22.04.3.1+git2ff06a41_all.deb
$ sudo apt --fix-broken install
  :
$ sudo apt dist-upgrade
  :

若しくは少し待ってリポジトリに反映されるのを待ちましょう.

環境
$ lsb_release -dr
Description:    Ubuntu 21.10
Release:        21.10
$ arch
x86_64
]]>
https://matoken.org/blog/2022/04/14/ubuntu-21-10-22-04-upgrade-failed/feed/ 0
Debian/Ubuntuでawkを切り替える https://matoken.org/blog/2021/06/10/swatch-awk/ https://matoken.org/blog/2021/06/10/swatch-awk/#comments Wed, 09 Jun 2021 22:18:56 +0000 http://matoken.org/blog/?p=3259

Debian等でのインストール直後のawkは mawk が導入されます.
Debianのパッケージでは他にGNU awk(パッケージ名 gawk ), The One True Awk(パッケージ名 original-awk )というものもあります.*BSDなどでよく見る nawk もあるように見えますが,シンボリックリンクだけのようです.
(他にもあるかもしれない?)

mawk は初期状態で入っていて軽量.GNU awk はmawkに比べて多機能で既定値では導入されませんが, byobu などが依存を求めるので入っている人も多いと思います.

複数のawkパッケージが導入されているときに awk と実行したときは update-alternatives で管理されたシンボリックリンク先のいずれかのawkが実行されます.これを切り替えてみます.

切り替え前の状態です. awk , nawkgawk(GNU awk) に向いています.

$ ls -l /usr/bin/*awk
lrwxrwxrwx 1 root root     21 May 16 00:33 /usr/bin/awk -> /etc/alternatives/awk
-rwxr-xr-x 1 root root 694624 Feb 10 17:42 /usr/bin/gawk
-rwxr-xr-x 1 root root 158296 Feb 17  2020 /usr/bin/mawk
lrwxrwxrwx 1 root root     22 May 16 00:33 /usr/bin/nawk -> /etc/alternatives/nawk
-rwxr-xr-x 1 root root 135848 Dec 22 06:24 /usr/bin/original-awk
$ ls -l /etc/alternatives/*awk
lrwxrwxrwx 1 root root 13 May 16 04:27 /etc/alternatives/awk -> /usr/bin/gawk
lrwxrwxrwx 1 root root 13 May 16 04:27 /etc/alternatives/nawk -> /usr/bin/gawk

awk コマンドを切り替えてみます.ここでは gawk から mawk にしました.

$ sudo update-alternatives --display awk (1)
awk - auto mode
  link best version is /usr/bin/gawk
  link currently points to /usr/bin/gawk
  link awk is /usr/bin/awk
  slave awk.1.gz is /usr/share/man/man1/awk.1.gz
  slave nawk is /usr/bin/nawk
  slave nawk.1.gz is /usr/share/man/man1/nawk.1.gz
/usr/bin/gawk - priority 10
  slave awk.1.gz: /usr/share/man/man1/gawk.1.gz
  slave nawk: /usr/bin/gawk
  slave nawk.1.gz: /usr/share/man/man1/gawk.1.gz
/usr/bin/mawk - priority 5
  slave awk.1.gz: /usr/share/man/man1/mawk.1.gz
  slave nawk: /usr/bin/mawk
  slave nawk.1.gz: /usr/share/man/man1/mawk.1.gz
/usr/bin/original-awk - priority 0
  slave awk.1.gz: /usr/share/man/man1/original-awk.1.gz
$ sudo update-alternatives --config awk (2)
There are 3 choices for the alternative awk (providing /usr/bin/awk).

  Selection    Path                   Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gawk           10        auto mode
  1            /usr/bin/gawk           10        manual mode
  2            /usr/bin/mawk           5         manual mode
  3            /usr/bin/original-awk   0         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/mawk to provide /usr/bin/awk (awk) in manual mode
$ sudo update-alternatives --set awk /usr/bin/mawk (3)
update-alternatives: using /usr/bin/mawk to provide /usr/bin/awk (awk) in manual mode
$ ls -l /etc/alternatives/*awk (4)
lrwxrwxrwx 1 root root 13 Jun  7 08:27 /etc/alternatives/awk -> /usr/bin/mawk
lrwxrwxrwx 1 root root 13 Jun  7 08:27 /etc/alternatives/nawk -> /usr/bin/mawk
  1. 現在の awk の設定を確認. gawk に向いている
  2. 対話モードで update-alternatives コマンドを起動して 2mawk に設定
  3. コマンドモードの場合
  4. awk , nawkmawk に向いたのを確認.

切り替えできました. :)

ちなみに update-alternatives で管理されているコマンドの一覧は以下のコマンドで表示できます.

$ update-alternatives --get-selections
環境1(Debian sid amd64)
$ dpkg-query -W mawk gawk original-awk dpkg
dpkg    1.20.9
gawk    1:5.1.0-1
mawk    1.3.4.20200120-2
original-awk    2018-08-27-1
$ lsb_release -dr
Description:    Debian GNU/Linux 11 (bullseye) (1)
Release:        11
$ arch
x86_64
  1. 実際はsid
環境2(Ubuntu 21.04 amd64)
$ dpkg-query -W mawk gawk dpkg
dpkg	1.20.9ubuntu1
gawk	1:5.1.0-1build1
mawk	1.3.4.20200120-2
$ lsb_release -dr
Description:	Ubuntu 21.04
Release:	21.04
$ arch
x86_64
環境3(Raspberry Pi OS buster armhf)
$ dpkg-query -W mawk gawk dpkg
dpkg    1.19.7
gawk    1:4.2.1+dfsg-1
mawk    1.3.3-17
$ lsb_release -dr
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
$ arch
armv7l

]]>
https://matoken.org/blog/2021/06/10/swatch-awk/feed/ 1
vnStatでネットワークトラフィックを集計する https://matoken.org/blog/2021/05/28/vnstat/ https://matoken.org/blog/2021/05/28/vnstat/#respond Fri, 28 May 2021 14:17:09 +0000 http://matoken.org/blog/?p=3243

以下のエントリでipコマンドでネットワーク通信量が確認できました.

端末を起動してからの通信量は確認できますが,再起動したりするとデータ量はクリアされてしまいます.MRTGやZabbixなどを使うのは大げさな感じがします.
もう少しお手軽なものがないかなと少し探してvnStatというものを見つけたので今回試してみました.

Debianでは vnstatvnstati というパッケージが提供されています.vnstat が本体で, vnstati はイメージ出力のコマンドです.

まずは本体の vnstat を導入します.

$ sudo apt install vnstat

導入するとvnStatのデーモンが起動します.

$ sudo service vnstat status
● vnstat.service - vnStat network traffic monitor
     Loaded: loaded (/lib/systemd/system/vnstat.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-04-30 00:46:09 JST; 5min ago
       Docs: man:vnstatd(8)
             man:vnstat(1)
             man:vnstat.conf(5)
   Main PID: 2045411 (vnstatd)
      Tasks: 1 (limit: 18935)
     Memory: 808.0K
        CPU: 184ms
     CGroup: /system.slice/vnstat.service
             └─2045411 /usr/sbin/vnstatd -n

Apr 30 00:46:10 t430s vnstatd[2045411]: Interface "virbr0" added with 1000 Mbit bandwidth limit.
Apr 30 00:46:10 t430s vnstatd[2045411]: Interface "nm-br1" added with 1000 Mbit bandwidth limit.
Apr 30 00:46:10 t430s vnstatd[2045411]: Interface "anbox0" added with 1000 Mbit bandwidth limit.
Apr 30 00:46:10 t430s vnstatd[2045411]: Interface "lxcbr0" added with 1000 Mbit bandwidth limit.
Apr 30 00:46:10 t430s vnstatd[2045411]: Interface "docker0" added with 1000 Mbit bandwidth limit.
Apr 30 00:46:10 t430s vnstatd[2045411]: -> 7 new interfaces found.
Apr 30 00:46:10 t430s vnstatd[2045411]: Limits can be modified using the configuration file. See "man vnstat.conf".
Apr 30 00:46:10 t430s vnstatd[2045411]: Unwanted interfaces can be removed from monitoring with "vnstat --remove".
Apr 30 00:46:10 t430s vnstatd[2045411]: Info: vnStat daemon 2.6 started. (pid:2045411 uid:149 gid:165 64-bit)
Apr 30 00:46:10 t430s vnstatd[2045411]: Info: Monitoring (7): wlp3s0 (1000 Mbit) virbr0 (1000 Mbit) nm-br1 (1000 Mbit) lxcbr0 (1000 Mbit) enp0s2>

はじめはデータがないのでこんな感じの寂しい表示です.

$ vnstat                                                                                                            [169/1082]

                      rx      /      tx      /     total    /   estimated
 anbox0: Not enough data available yet.
 docker0: Not enough data available yet.
 enp0s25: Not enough data available yet.
 lxcbr0: Not enough data available yet.
 nm-br1: Not enough data available yet.
 virbr0: Not enough data available yet.
 wlp3s0: Not enough data available yet.

数分経ってから実行するとデータが記録されてログが出てきます.

$ vnstat

                      rx      /      tx      /     total    /   estimated
 anbox0: Not enough data available yet.
 docker0: Not enough data available yet.
 enp0s25: Not enough data available yet.
 lxcbr0: Not enough data available yet.
 nm-br1: Not enough data available yet.
 virbr0: Not enough data available yet.
 wlp3s0:
       2021-04     21.10 MiB  /    3.70 MiB  /   24.80 MiB  /   22.25 MiB
         today     21.10 MiB  /    3.70 MiB  /   24.80 MiB  /  673.77 MiB

ネットワークインターフェイスが複数あって,特定のインターフェイスの情報だけを確認したい場合は -i オプションでインターフェイスが指定できます.

$ vnstat -i wlp3s0
Database updated: 2021-04-30 00:53:40

   wlp3s0 since 2021-04-30

          rx:  21.10 MiB      tx:  3.70 MiB      total:  24.80 MiB

   monthly
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       2021-04     21.10 MiB |    3.70 MiB |   24.80 MiB |       82 bit/s
     ------------------------+-------------+-------------+---------------
     estimated     19.78 MiB |    2.47 MiB |   22.25 MiB |

   daily
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
         today     21.10 MiB |    3.70 MiB |   24.80 MiB |   64.60 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated    573.38 MiB |  100.39 MiB |  673.77 MiB |

複数のインターフェイスの合計を指定する場合は, + でインターフェイスをつなげて指定します.

$ vnstat -i usb0+wlp3s0

vnStatインストール時に存在しなかったインターフェイスは監視されません.

$ vnstat -i usb0
Error: Interface "usb0" not found in database.

新しいネットワークインターフェイスを追加します.ここでは usb0 を登録しました.

$ sudo vnstat --add -i usb0 (1)
Adding interface "usb0" for monitoring to database...

Restart the vnStat daemon if it is currently running in order to start monitoring "usb0".
$ sudo service vnstat restart   (2)
$ vnstat -i usb0 -d (3)

 usb0  /  daily

          day        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     2021-04-30     2.03 MiB |    8.18 MiB |   10.21 MiB |   12.90 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated     26.57 MiB |  107.12 MiB |  133.70 MiB |
  1. usb0 インターフェイスを登録
  2. 反映のためにvNstatを再起動する.
  3. 暫く待ってからカウントされているのを確認.

インターフェイスが切断されているときは disabled の表示になりますが,再接続されるとまたカウントされます.

$ vnstat | grep :
 usb0 [disabled]:
 wlp4s0:

情報の確認はいくつかの表示ができます.サマリー,5分毎,1時間毎,日毎,月毎,年毎,トップなど.
既定値がサマリーのようです.

-5 で5分毎(ここではwlp3s0を5分x6表示)
$ vnstat -i wlp3s0 -5 6

 wlp3s0  /  5 minute

         time        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     2021-05-24
         14:35      1.43 MiB |    1.27 MiB |    2.70 MiB |   75.52 kbit/s
         14:40      7.11 MiB |    1.44 MiB |    8.55 MiB |  238.96 kbit/s
         14:45      1.60 MiB |    1.28 MiB |    2.87 MiB |   80.34 kbit/s
         14:50      1.12 MiB |    1.17 MiB |    2.29 MiB |   63.94 kbit/s
         14:55      1.49 MiB |    1.50 MiB |    2.99 MiB |   83.47 kbit/s
         15:00    748.04 KiB |    1.18 MiB |    1.91 MiB |   53.41 kbit/s
     ------------------------+-------------+-------------+---------------
-h で1時間毎(ここでは1時間x3表示)
$ vnstat -h 3

 wlp4s0  /  hourly

         hour        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     2021-05-24
         05:00      3.28 MiB |  623.99 KiB |    3.88 MiB |    9.05 kbit/s
         17:00    510.09 MiB |    7.29 MiB |  517.38 MiB |    1.21 Mbit/s
         18:00    286.84 MiB |    8.32 MiB |  295.16 MiB |    1.65 Mbit/s
     ------------------------+-------------+-------------+---------------
-d で日毎(ここでは1日x3表示)
$ vnstat -d 3

 wlp3s0+enp0s25+usb0  /  daily

          day        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     2021-05-23   936.47 MiB |  820.25 MiB |    1.72 GiB |  170.56 kbit/s
     2021-05-24     1.56 GiB |  300.01 MiB |    1.85 GiB |  183.94 kbit/s
     2021-05-28   483.40 MiB |  372.19 MiB |  855.60 MiB |   83.07 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated    642.75 MiB |  494.88 MiB |    1.11 GiB |

estimated も表示されます.これはこの調子で使い続けるとこのくらいという推測のようで利用時間や利用量が少なかったり,利用状況が変わる場合信頼できない値になります.

-m で月毎
$ vnstat -m

 wlp3s0+enp0s25+usb0  /  monthly

        month        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       2021-04      1.54 GiB |  571.46 MiB |    2.09 GiB |    6.94 kbit/s
       2021-05     19.13 GiB |    4.53 GiB |   23.66 GiB |  303.40 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated     76.48 GiB |   18.12 GiB |   94.60 GiB |
-y で年毎
$ vnstat -y

 wlp4s0  /  yearly

         year        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
          2021     47.48 GiB |    3.16 GiB |   50.64 GiB |   34.07 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated    117.29 GiB |    7.81 GiB |  125.09 GiB |
-t でtop(ここではTop3)
$ vnstat -t 3

 wlp4s0  /  top 3

    #      day          rx      |     tx      |    total    |   avg. rate
   -----------------------------+-------------+-------------+---------------
    1   2021-05-19     7.76 GiB |    1.52 GiB |    9.29 GiB |  923.28 kbit/s
    2   2021-05-27     8.01 GiB |  373.46 MiB |    8.37 GiB |  832.45 kbit/s
    3   2021-05-18     5.66 GiB |  165.91 MiB |    5.83 GiB |  579.24 kbit/s
   -----------------------------+-------------+-------------+---------------
開始( -b ),終了( -e )期間指定(ここでは2021-05-18〜2021-05-25を指定)
$ vnstat -i usb0 -b 2021-05-18 -e 2021-05-25
Database updated: 2021-05-24 05:09:40

   usb0 [disabled] since 2021-05-17

          rx:  5.84 GiB      tx:  1.03 GiB      total:  6.87 GiB

   monthly
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       2021-05      5.84 GiB |    1.03 GiB |    6.87 GiB |   29.41 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated      7.80 GiB |    1.37 GiB |    9.17 GiB |

   daily
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     2021-05-23     3.24 GiB |  756.16 MiB |    3.98 GiB |  395.74 kbit/s
     2021-05-24    45.06 MiB |   10.71 MiB |   55.78 MiB |   25.18 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated    210.01 MiB |   49.92 MiB |  259.93 MiB |
-hg, --hoursgraph で1時間ごとのグラフ
$ vnstat -hg
 eth0                                                                     22:15
  ^                                                                     t
  |                                                                     t
  |                                                                     t
  |                                                                     t
  |                                                                     t
  |                                                                     t
  |                                                                     t
  |                                                                     t
  |                                                                    rt  t
  |                                                              rt r  rt rt
 -+--------------------------------------------------------------------------->
  |  23 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22

 h  rx (MiB)   tx (MiB)  ][  h  rx (MiB)   tx (MiB)  ][  h  rx (MiB)   tx (MiB)
23        0.0        0.0 ][ 07        0.0        0.0 ][ 15        0.0        0.0
00        0.0        0.0 ][ 08        0.0        0.0 ][ 16        0.0        0.0
01        0.0        0.0 ][ 09        0.0        0.0 ][ 17        0.0        0.0
02        0.0        0.0 ][ 10        0.0        0.0 ][ 18        3.3        9.1
03        0.0        0.0 ][ 11        0.0        0.0 ][ 19       27.0       19.4
04        0.0        0.0 ][ 12        0.0        0.0 ][ 20       25.0       14.6
05        0.0        0.0 ][ 13        0.0        0.0 ][ 21       31.0      150.8
06        0.0        0.0 ][ 14        0.0        0.0 ][ 22       20.3       37.2
-l でリアルタイム(^cで終了,統計が表示される)
$ vnstat -l
Monitoring wlp4s0...    (press CTRL-C to stop)

   rx:     7.39 Mbit/s   632 p/s          tx:   234.20 kbit/s   306 p/s^C


 wlp4s0  /  traffic statistics

                           rx         |       tx
--------------------------------------+------------------
  bytes                   241.31 MiB  |       10.07 MiB
--------------------------------------+------------------
          max            8.33 Mbit/s  |   322.19 kbit/s
      average          322.69 kbit/s  |    13.47 kbit/s
          min                0 bit/s  |         0 bit/s
--------------------------------------+------------------
  packets                     187533  |           92295
--------------------------------------+------------------
          max                716 p/s  |         382 p/s
      average                 29 p/s  |          14 p/s
          min                  0 p/s  |           0 p/s
--------------------------------------+------------------
  time                104.55 minutes

機関の指定もできるようですが,使い方が悪いのか機関によってはうまく使えません.ここではサマリ表示で指定していない期間の2021-05-24も表示されていて, -h 表示でデータが出てこない.

$ vnstat -i usb0 --begin "2021-05-23 13:00" --end "2021-05-23 20:00"
Database updated: 2021-05-24 05:09:40

   usb0 [disabled] since 2021-05-17

          rx:  5.84 GiB      tx:  1.03 GiB      total:  6.87 GiB

   monthly
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       2021-05      5.84 GiB |    1.03 GiB |    6.87 GiB |   29.41 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated      7.80 GiB |    1.37 GiB |    9.17 GiB |

   daily
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     2021-05-23     3.24 GiB |  756.16 MiB |    3.98 GiB |  395.74 kbit/s
     2021-05-24    45.06 MiB |   10.71 MiB |   55.78 MiB |   25.18 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated    210.01 MiB |   49.92 MiB |  259.93 MiB |
$ vnstat -i usb0 --begin "2021-05-23 13:00" --end "2021-05-23 20:00" --hours

 usb0 [disabled]  /  hourly

         hour        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
                            no data available
     ------------------------+-------------+-------------+---------------

vnstati も試してみます.
これは vNstat の画像出力コマンドです.Debianではvnstatとは別パッケージの vnstati に分かれているのでこれを導入します.

$ sudo apt install vnstati

範囲などのオプションは vnstat と共通です.

$ vnstati -i usb0 -h 7 -o /tmp/today.png

vnstati

環境1
$ dpkg-query -W vnstat vnstati
vnstat  2.6-3
vnstati 2.6-3
$ lsb_release -dr
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
$ arch
x86_64
環境2
$ dpkg-query -W vnstat vnstati
vnstat  2.6-3
vnstati 2.6-3
$ lsb_release -dr
Description:    Debian GNU/Linux 11 (bullseye)
Release:        11
$ arch
x86_64
環境3
$ dpkg-query -W vnstat
vnstat  2.6-1
$ lsb_release -dr
Description:    Ubuntu 20.04.2 LTS
Release:        20.04
$ arch
x86_64
]]>
https://matoken.org/blog/2021/05/28/vnstat/feed/ 0
cpu情報を表示するcpufetch https://matoken.org/blog/2021/04/07/cpufetch/ https://matoken.org/blog/2021/04/07/cpufetch/#respond Wed, 07 Apr 2021 12:25:17 +0000 http://matoken.org/blog/?p=3199

cpufetchというscreenfetchインスパイアな感じのcpu情報表示ツールを見かけたので試してみました.

$ git clone https://github.com/Dr-Noob/cpufetch
$ cd cpufetch
$ make
$ ./cpufetch -s retro

                               ################
                       #######                #######
                  ####                              ####
              ###                                     ####    Name:              Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz
         ###                                             ###  Microarchitecture: Ivy Bridge
         ###                                             ###  Technology:        22nm
      #                    ###                ###        ###  Max Frequency:     3.300 GHz
    ##   ###   #########   ######   ######    ###        ###  Cores:             2 cores (4 threads)
   ##    ###   ###    ###  ###    ####  ####  ###        ###  AVX:               AVX
  ##     ###   ###    ###  ###    ###    ###  ###       ###   FMA:               No
 ##      ###   ###    ###  ###    ##########  ###     ####    L1i Size:          32KB (64KB Total)
 ##      ###   ###    ###  ###    ###         ###   #####     L1d Size:          32KB (64KB Total)
 ##       ##   ###    ###   #####  #########   ##  ###        L2 Size:           256KB (512KB Total)
 ###                                                          L3 Size:           3MB
  ###                                                         Peak Performance:  52.80 GFLOP/s
  ####                                        ####
    #####                               ##########
      ##########               ################
          ###############################

標準のスタイルでテキストで貼り付けると真っ白になるので retro です.通常の実行結果は以下に.

Linux以外でもWindows/macOS/Android(termux)でも動作するようです.

cpufetch intel
cpufetch amd
cpufetch arm
cpufetch snapdragon

neofetch/screenfetch等はシステムの情報を表示しますがcpufetchはcpu情報に特化しています.未だサポートcpuは多くないようです.
/proc/cpuinfo, lscpu, lshw -class cpu とかのほうが実用的だと思いますが,楽しいので.

環境1
$ dpkg-query -W gcc make git
gcc     4:10.2.1-1
git     1:2.31.0-1
make    4.3-4
$ lsb_release -dr
Description:    Debian GNU/Linux bullseye/sid
Release:        unstable
$ arch
x86_64
環境2
$ pkg list-installed 2>&1 | grep -E 'clang|git|make'
clang/stable,now 11.1.0 aarch64 [installed]
git/stable,now 2.31.1 aarch64 [installed]
make/stable,now 4.3-1 aarch64 [installed]
$ termux-info
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://termux.org/packages/ stable main
# game-repo (sources.list.d/game.list)
deb https://grimler.se/game-packages-24 games stable
# science-repo (sources.list.d/science.list)
deb https://grimler.se/science-packages-24 science stable
Updatable packages:
apt/stable 2.2.2 aarch64 [upgradable from: 2.1.18]
dialog/stable 1.3-20210324-0 aarch64 [upgradable from: 1.3-20210117-0]
nano/stable 5.6.1 aarch64 [upgradable from: 5.5]
termux-exec/stable 1:0.9 aarch64 [upgradable from: 1:0.8]
termux-tools/stable 0.115 all [upgradable from: 0.111]
Android version:
9
Kernel build information:
Linux localhost 4.9.112-perf #1 SMP PREEMPT Thu Feb 25 22:16:13 CST 2021 aarch64 Android
Device manufacturer:
TINNO
Device model:
C330
]]>
https://matoken.org/blog/2021/04/07/cpufetch/feed/ 0
Nextcloud 18 -> 19 アップグレード時のセキュリティ&セットアップ警告を解決 https://matoken.org/blog/2021/02/15/nextcloud-18-19-resolved-security-setup-warning-when-upgrading/ https://matoken.org/blog/2021/02/15/nextcloud-18-19-resolved-security-setup-warning-when-upgrading/#respond Sun, 14 Feb 2021 23:30:00 +0000 http://matoken.org/blog/?p=2991

Nextcloud 18 がEoL になっていたので,Nextcloud 18.0.14 から Nextcloud 19.0.7 にアップグレードしました.

表 1. Maintenance and Release Schedule · nextcloud/server Wiki
release date end of life current version next version

20

2020-10-03

2021-10

20.0.7 (2021-02-02)

20.0.8 (2021-02-25)

19

2020-06-03

2021-06

19.0.8 (2021-01-27)

19.0.9 (2021-02-25)

18

2020-01-16

2021-01

18.0.14 (2021-01-27)

End of Life

$ sudo -u www-data php $NEXTCLOUDPATH/occ app:update --all
$ sudo -u www-data php $NEXTCLOUDPATH/updater/updater.phar
$ sudo -u www-data php $NEXTCLOUDPATH/occ app:update --all

以前実行したときと比べて「セキュリティ&セットアップ警告」の内容が違っていたのでメモしておきます.

警告を解決

警告メッセージ全体
セキュリティ&セットアップ警告
サーバーのセキュリティとパフォーマンスにとって重要なことは、すべてが正確に設定されていることです。あなたの助けとなるよう、Nextcloudでは一部の自動チェックを行っています。詳細な情報は、リンク先のドキュメントを参照してください。

セットアップに関して警告がいくつかあります。
PHPのメモリ制限が推奨値の512MB以下です。
"Strict-Transport-Security" HTTPヘッダが最低でも "15552000" 秒に設定されていません。セキュリティを強化するには、セキュリティTips ↗で解説しているHSTSを有効にすることを推奨します。
Webサーバーは適切にホスト名 "/.well-known/caldav" が引けるように設定されていません。より詳しい情報については、ドキュメントを参照ください。
Webサーバーは適切にホスト名 "/.well-known/carddav" が引けるように設定されていません。より詳しい情報については、ドキュメントを参照ください。
メモリキャッシュが設定されていません。可能であれば、パフォーマンスを向上するため、memcacheを設定してください。より詳しい情報はドキュメントで参照できます。
データベースにいくつかのインデックスがありません。 大きなテーブルにインデックスを追加すると、自動的に追加されないまでに時間がかかる可能性があるためです。 "occ db:add-missing-indices"を実行することによって、インスタンスが実行し続けている間にそれらの欠けているインデックスを手動で追加することができます。 インデックスが追加されると、それらのテーブルへのクエリは通常はるかに速くなります。
テーブル "oc_calendarobjects_props"のインデックス "calendarobject_calid_index"が見つかりません。
テーブル "oc_schedulingobjects"のインデックス "schedulobj_principuri_index"が見つかりません。
テーブル "oc_properties"のインデックス "properties_path_index"が見つかりません。
データベースにはオプションのカラムがいくつかありません。大きなテーブルにカラムを追加するには時間がかかるため、オプションのカラムは自動的に追加されませんでした。"occ db:add-missing-columns"を実行することで、不足しているカラムはインスタンスの実行中に手動で追加することができます。カラムが追加されると、応答性や使い勝手が改善される可能性があります。
テーブル "oc_comments" にオプションのカラム "reference_id" が存在しません。
このインスタンスには推奨されるPHPモジュールがいくつかありません。 パフォーマンスの向上と互換性の向上のために、それらをインストールすることを強くお勧めします。
intl
bcmath
gmp
データベース内のいくつかの列で、big intへの変換が行われていません。 大きなテーブルでカラムタイプを変更すると時間がかかることがあるため、自動的には変更されませんでした。 'occ db:convert-filecache-bigint'を実行することによって、それらの保留中の変更は手動で適用できます。 この操作は、インスタンスがオフラインの間に行う必要があります。 詳細についてはこれに関するドキュメントページを読んでください。
filecache_extended.fileid
mounts.storage_id
mounts.root_id
mounts.mount_id
インストールガイド ↗を再確認して、 ログ にあるすべてのエラーや警告を確認してください。

「このインスタンスには推奨されるPHPモジュールがいくつかありません。」

php

このインスタンスには推奨されるPHPモジュールがいくつかありません。 パフォーマンスの向上と互換性の向上のために、それらをインストールすることを強くお勧めします。
intl
bcmath
gmp

該当パッケージを導入してhttpdを再読込します.

$ sudo apt install php-intl php-bcmath php-gmp (1)
$ sudo service apache2 reload (2)
  1. 対応パッケージの導入
  2. apache httpd 再読込

「セキュリティ&セットアップ警告」ページを再読込して警告が消えるのを確認します.

データベースにいくつかのインデックスがありません。

db index

データベースにいくつかのインデックスがありません。 大きなテーブルにインデックスを追加すると、自動的に追加されないまでに時間がかかる可能性があるためです。 "occ db:add-missing-indices"を実行することによって、インスタンスが実行し続けている間にそれらの欠けているインデックスを手動で追加することができます。 インデックスが追加されると、それらのテーブルへのクエリは通常はるかに速くなります。
テーブル "oc_calendarobjects_props"のインデックス "calendarobject_calid_index"が見つかりません。
テーブル "oc_schedulingobjects"のインデックス "schedulobj_principuri_index"が見つかりません。
テーブル "oc_properties"のインデックス "properties_path_index"が見つかりません。

メッセージの通りoccコマンドでインデックスを作成します.メッセージそのままコピーすると:がマルチバイト文字になっているので注意しましょう.

$ sudo -u www-data php $NEXTCLOUDPATH/occ db:add-missing-indices
Check indices of the share table.
Check indices of the filecache table.
Check indices of the twofactor_providers table.
Check indices of the login_flow_v2 table.
Check indices of the whats_new table.
Check indices of the cards table.
Check indices of the cards_properties table.
Check indices of the calendarobjects_props table.
Adding calendarobject_calid_index index to the calendarobjects_props table, this can take some time...
calendarobjects_props table updated successfully.
Check indices of the schedulingobjects table.
Adding schedulobj_principuri_index index to the schedulingobjects table, this can take some time...
schedulingobjects table updated successfully.
Check indices of the oc_properties table.
Adding properties_path_index index to the oc_properties table, this can take some time...
oc_properties table updated successfully.

「セキュリティ&セットアップ警告」ページを再読込して警告が消えるのを確認します.

「データベースにはオプションのカラムがいくつかありません。」

db collum

データベースにはオプションのカラムがいくつかありません。大きなテーブルにカラムを追加するには時間がかかるため、オプションのカラムは自動的に追加されませんでした。"occ db:add-missing-columns"を実行することで、不足しているカラムはインスタンスの実行中に手動で追加することができます。カラムが追加されると、応答性や使い勝手が改善される可能性があります。
テーブル "oc_comments" にオプションのカラム "reference_id" が存在しません。

メッセージの通りoccコマンドでカラムを追加します.メッセージそのままコピーすると:がマルチバイト文字になっているので注意しましょう.

$ sudo -u www-data php $NEXTCLOUDPATH/occ db:add-missing-columns
Check columns of the comments table.
Adding additional reference_id column to the comments table, this can take some time...
Comments table updated successfully.

「セキュリティ&セットアップ警告」ページを再読込して警告が消えるのを確認します.

「データベース内のいくつかの列で、big intへの変換が行われていません。」

db big init

データベース内のいくつかの列で、big intへの変換が行われていません。 大きなテーブルでカラムタイプを変更すると時間がかかることがあるため、自動的には変更されませんでした。 'occ db:convert-filecache-bigint'を実行することによって、それらの保留中の変更は手動で適用できます。 この操作は、インスタンスがオフラインの間に行う必要があります。 詳細についてはこれに関するドキュメントページを読んでください。
filecache_extended.fileid
mounts.storage_id
mounts.root_id
mounts.mount_id

メッセージの通りoccコマンドでbig intへの変換をします.メッセージそのままコピーすると:がマルチバイト文字になっているので注意しましょう.
途中時間がかかる旨のメッセージが表示されます.y を指定することで処理を続行します.siteの規模や利用状況によって実行時間を考えましょう.

$ sudo -u www-data php $NEXTCLOUDPATH/occ db:convert-filecache-bigint
Following columns will be updated:

* filecache_extended.fileid
* mounts.storage_id
* mounts.root_id
* mounts.mount_id

This can take up to hours, depending on the number of files in your instance!
Continue with the conversion (y/n)? [n] y

「セキュリティ&セットアップ警告」ページを再読込して警告が消えるのを確認します.

「PHPのメモリ制限が推奨値の512MB以下です。」

php memory

PHPのメモリ制限が推奨値の512MB以下です。

phpの memory_limit の値を /etc/php/7.4/apache2/php.ini を編集して修正します.その後httpdの再読込を行います.

$ sudo vim /etc/php/7.4/apache2/php.ini (1)
$ sudo git -C /etc diff /etc/php/7.4/apache2/php.ini (2)
diff --git a/php/7.4/apache2/php.ini b/php/7.4/apache2/php.ini
index ef89b713..407ee04d 100644
--- a/php/7.4/apache2/php.ini
+++ b/php/7.4/apache2/php.ini
@@ -406,7 +406,7 @@ max_input_time = 60

 ; Maximum amount of memory a script may consume (128MB)
 ; http://php.net/memory-limit
-memory_limit = 128M
+memory_limit = 512M

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Error handling and logging ;
$ php --php-ini /etc/php/7.4/apache2/php.ini -i | grep memory_limit (3)
memory_limit => 512M => 512M
$ sudo service apache2 reload (4)
  1. vimで設定ファイルを修正
  2. 編集内容確認
  3. 設定確認
  4. apache httpd を再読込

「セキュリティ&セットアップ警告」ページを再読込して警告が消えるのを確認します.

「”Strict-Transport-Security” HTTPヘッダが最低でも “15552000” 秒に設定されていません。」

hsts

"Strict-Transport-Security" HTTPヘッダが最低でも "15552000" 秒に設定されていません。セキュリティを強化するには、セキュリティTips ↗で解説しているHSTSを有効にすることを推奨します。
$ sudo vi /etc/apache2/sites-available/nextcloud.conf (1)
$ sudo git -C /etc diff /etc/apache2/sites-available/nextcloud.conf (2)
diff --git a/apache2/sites-available/nextcloud.conf b/apache2/sites-available/nextcloud.conf
index 2844232c..4a064d52 100644
--- a/apache2/sites-available/nextcloud.conf
+++ b/apache2/sites-available/nextcloud.conf
@@ -135,6 +135,10 @@
                #               nokeepalive ssl-unclean-shutdown \
                #               downgrade-1.0 force-response-1.0

+               <IfModule mod_headers.c>
+                       Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
+               </IfModule>
+
        </VirtualHost>
 </IfModule>

$ sudo apache2ctl configtest (3)
Syntax OK
$ sudo service apache2 reload (4)
  1. apacheの該当のサイト設定修正
  2. 設定確認
  3. 文法チェック
  4. apache httpd再読込

「セキュリティ&セットアップ警告」ページを再読込して警告が消えるのを確認します.

「Webサーバーは適切にホスト名が引けるように設定されていません。」

well known

Webサーバーは適切にホスト名 "/.well-known/caldav" が引けるように設定されていません。より詳しい情報については、ドキュメントを参照ください。
Webサーバーは適切にホスト名 "/.well-known/carddav" が引けるように設定されていません。より詳しい情報については、ドキュメントを参照ください。

専用のドメインではなくサブディレクトリ( nextcloud )で運用しているNextcloud なので,ドメインのドキュメントルートに以下のような .htaccess ファイルを用意します.caldav/carddavだけでなく一緒に他のものも設定しました.専用の(サブ)ドメインならこの問題は出ないと思います.

$ sudo -u www-data vi $HTTPROOTPATH/.htaccess (1)
$ cat $HTTPROOTPATH/.htaccess (2)
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^\.well-known/host-meta /nextcloud/public.php?service=host-meta [QSA,L]
  RewriteRule ^\.well-known/host-meta\.json /nextcloud/public.php?service=host-meta-json [QSA,L]
  RewriteRule ^\.well-known/webfinger /nextcloud/public.php?service=webfinger [QSA,L]
  RewriteRule ^\.well-known/carddav /nextcloud/remote.php/dav/ [R=301,L]
  RewriteRule ^\.well-known/caldav /nextcloud/remote.php/dav/ [R=301,L]
</IfModule>
  1. NextcloudのhttpdのROOT直下の .htaccess ファイルを編集
  2. 編集内容を確認.

「セキュリティ&セットアップ警告」ページを再読込して警告が消えるのを確認します.

「メモリキャッシュが設定されていません。」

memcache

メモリキャッシュが設定されていません。可能であれば、パフォーマンスを向上するため、memcacheを設定してください。より詳しい情報はドキュメントで参照できます。
A memcache is not required and you may safely ignore the warning if you prefer.

この設定は必須ではなさそうですが,RAMは余っているので設定します.

いくつか種類があるようですが,今回はAPCuを設定しました.

$ sudo apt install php-apcu (1)
$ sudo -u www-data vim $NEXTCLOUDPATH/config/config.php (2)
$ sudo git --git-dir=/var/git/nextcloud --work-tree=. diff config/config.php (3)
diff --git a/config/config.php b/config/config.php
index f62133e..62d137d 100644
--- a/config/config.php
+++ b/config/config.php
@@ -41,4 +41,5 @@ $CONFIG = array (
   array (
   ),
   'mail_sendmailmode' => 'smtp',
+  'memcache.local' => '\OC\Memcache\APCu',
 );
  1. APCuのパッケージを導入
  2. Nextcloudの設定ファイルを編集して設定を追加
  3. 設定確認

「セキュリティ&セットアップ警告」ページを再読込して警告が消えるのを確認します.

「すべてのチェックに合格しました。」

ok

:)

環境

今回のホストの環境はUbuntu 20.04 LTS amd64のapache httpd 2.4, mysql server 8, php 7.4です.

$ dpkg-query -W php7.4-common php7.4-apcu apache2 mysql-server
apache2 2.4.41-4ubuntu3.2
mysql-server    8.0.23-0ubuntu0.20.04.1
php7.4-apcu
php7.4-common   7.4.3-4ubuntu2.4
$ lsb_release -dr
Description:    Ubuntu 20.04.2 LTS
Release:        20.04
$ uname -m
x86_64

]]>
https://matoken.org/blog/2021/02/15/nextcloud-18-19-resolved-security-setup-warning-when-upgrading/feed/ 0
The Great SuspenderでサスペンドしていたURLをjsonで出力する https://matoken.org/blog/2021/02/05/output-the-url-suspended-by-the-great-suspender-with-json/ https://matoken.org/blog/2021/02/05/output-the-url-suspended-by-the-great-suspender-with-json/#respond Fri, 05 Feb 2021 09:15:16 +0000 http://matoken.org/blog/?p=2969

ということで削除されちゃったんですね.
自分は先月怪しいという話を聞いて削除していました.その時タブが消えてしまい悲しかったのですがこんな感じで復旧させました.
タイムスタンプとタイトル,URLをjsonで出力します.

$ sqlite3 ~/.config/google-chrome/Default/History "SELECT \"[\" || group_concat(json_object('timestamp', last_visit_time, title, url)) || \"]\" FROM urls WHERE url LIKE '%bkeccnjlkjkiokjodocebajanakg%';" | jq . | sed -e 's/chrome-extension:\/\/klbibkeccnjlkjkiokjodocebajanakg\/suspended.html.*&uri=//'

何をやっているかというと, ~/.config/google-chrome/Default/History がGoogle Chromeのsqlite3形式の履歴ファイルなので,この中からThe Great Suspenderのurlの含まれているurlを引っ張り出して整形しています.

Chromiumの場合は ~/.config/chromium/Default/History
Braveは ~/.config/BraveSoftware/Brave-Browser/Default/History でした.

Default以外のprofileは名前いろいろなのでfindとかで探すといいでしょう.

$ find ~/.config/chromium/ ~/.config/google-chrome/ ~/.config/BraveSoftware/Brave-Browser -name History

ここで紹介したのはLinuxでの場合ですが,パスを変えると他のOSでもいけるはずです.

環境1
$ dpkg-query -W jq sqlite3 chromium google-chrome-stable
chromium
google-chrome-stable    69.0.3497.100-1
jq      1.6-2.1ubuntu1
sqlite3 3.34.0-1
$ lsb_release -dr
Description:    Ubuntu Hirsute Hippo (development branch)
Release:        21.04
$ uname -m
x86_64
環境2
$ dpkg-query -W jq sqlite3 chrome brave-browser google-chrome-stable
brave-browser   1.19.90
google-chrome-stable    88.0.4324.146-1
jq      1.6-2.1
sqlite3 3.34.1-1
$ lsb_release -dr
Description:    Debian GNU/Linux bullseye/sid
Release:        unstable
$ uname -m
x86_64

]]>
https://matoken.org/blog/2021/02/05/output-the-url-suspended-by-the-great-suspender-with-json/feed/ 0
Gnome ShellでBitbar, SwiftBar代替のArgosを使う https://matoken.org/blog/2021/01/23/use-argos-instead-of-bitbar-swiftbar-in-gnome-shell/ https://matoken.org/blog/2021/01/23/use-argos-instead-of-bitbar-swiftbar-in-gnome-shell/#comments Sat, 23 Jan 2021 13:37:47 +0000 http://matoken.org/blog/?p=2939

PodcastのRebuild.fm 292回でBitBar, SwiftBar というツールバーに任意のコマンドの結果を表示できるツールを知って

Linuxで動作するBitBar/SwiftBar Alternativeが無いかなと探して,Argos, Kargos, Margosというものを見つけました.

そして先日Margosを試してみたけどウィンドウ表示できなかったりと機能が少なかったです.

ということで今回はGnome Shell環境を用意してBitBarと互換性があるというArgosを試してみました.

ArgosはGnome shellの拡張機能として提供されています.
以下のページから入手できます.ブラウザから導入もしくは手動でダウンロードして展開します.

手動ダウンロード時はGnome shellのバージョンを求められるのでバージョンがわからない場合は以下のようなコマンドで確認できます.

Gnome Shellバージョン確認
$ gnome-shell --version
GNOME Shell 3.38.3

手動での導入の場合拡張機能ダウンロード後以下のような感じで展開します.

$ mkdir -p ~/.local/share/gnome-shell/extensions
$ unzip ./argospew.worldwidemann.com.v3.shell-extension.zip \
-d ~/.local/share/gnome-shell/extensions/argos@pew.worldwidemann.com/

このあとGnome Shell を Alt+F2 r↲ と操作して再起動して反映します.

ステータスバーにArgosは現れましたが,クリックしてもウィンドウが開きません.Gnome Shellが新しい(3.36以降?)とArgosはうまく動かないようです.

Gitリポジトリのmasterと以下のPRのpatchを利用して動作しました.

一旦Argosを削除して導入し直します.

旧バージョンを削除
$ gnome-extensions disable argos@pew.worldwidemann.com (1)
$ gnome-extensions uninstall argos@pew.worldwidemann.com (2)
  1. 拡張機能無効化
  2. アンインストール

続いてGit版ArgosのmasterとPRのファイルを適用します.

$ git clone https://github.com/p-e-w/argos (1)
$ cd argos
$ cp -r ./argos@pew.worldwidemann.com \
~/.local/share/gnome-shell/extensions/ (2)
$ wget https://raw.githubusercontent.com/p-e-w/argos/c4663d9d3e29ef33b7e9123ef0c095811c91cf5b/argos%40pew.worldwidemann.com/menuitem.js \
-O ~/.local/share/gnome-shell/extensions/argos@pew.worldwidemann.com/menuitem.js (3)
  1. リポジトリclone
  2. 拡張機能コピー
  3. Gnome Shell 3.36+向けの修正を適用

Alt+F2 r↲ でGnome Shellを再起動して反映してGnome Shell 3.38.3でも動作するようになりました.

Argosのデフォルトプラグインを確認してみます.

ステータスバーにArgosが現れているはずです.文字列をクリックでウィンドウが表示されます.最下部の argos.sh をクリックすると規定値のテキストエディタで開かれてそのまま編集できて便利です.

argos argos

Argos Pluginは結構簡単に書けます.

~/.config/argos/実行可能プラグラムやスクリプトを置くと即実行されます.プログラムの出力結果1行目がバーに表示され,--- の後がウィンドウ内に表示されます.インターバルはファイル名で制御します.
例えば hoge.3s+.sh の場合は3秒毎に実行され, fuga.10m+.py は10分毎に実行されます.
その他色を付けたりアイコンを設定したり色々できるようです.詳しくはBitBar, Argosのドキュメントを参照してください.

試しに簡単なPluginを作ってみます.

まずは定番の天気表示をwegoコマンドで試します.
天気をバーに表示してクリックすると2日分の天気予報を表示されるようにしてみました.罫線は崩れちゃいました.

argos wego

~/.config/argos/wego.1h+.sh
#!/bin/bash

STR=`wego -d 2 -f emoji`
echo "`echo "${STR}" | head -4 | tail -1`"
echo "---"
echo "${STR}" | awk 1 ORS="\\\\n"
echo " | font=monospace"

次にCPUの温度とtopを表示するものを書いてみました.1分毎にCPUの温度をバーに表示して,クリックするとtopコマンドの上の方をを表示します.手元のPCはよくCPU温度が上がってサーマルスロットリングされてしまうのでこれは結構実用的です.

argos cputhermal

~/.config/argos/cputhermal.1m+.sh
#!/bin/bash

THERMAL=`acpi -t | awk '{print $4}'`
COLOR="white"

if [ `echo "${THERMAL} >= 80" | bc` == 1 ] ; then
        COLOR="red"
fi

#echo "<span color='${COLOR}' weight='normal'><tt>🌡${THERMAL}℃ </tt></span>"
echo "🌡${THERMAL}℃  | color=${COLOR}"
echo "---"
if [ "${ARGOS_MENU_OPEN}" == "true" ]; then
        TOP_OUTPUT=$(top -b -n 1 | head -n 20 | awk 1 ORS="\\\\n")
        echo "${TOP_OUTPUT} | font=monospace bash=top"
else
        echo "Loading..."
fi

本当は80度を超えていたらバーの文字列を赤くしたいのですがうまく行っていません.Argosのバグらしく,ワークアラウンドとして絵文字を表示すればOKというのを見かけましたがこれもうまく動いていません.(ちなみにエスケープシーケンスでの色変更は効くようです.)

次にArgosはBitBarと互換性があるということでBitBar Pluginを利用できるか試してみます.

ただし,PluginによりAPI keyや座標を記述したりと行った少しの修正は必要(これはBitBarでも),更にBitBarはmacOS用なのでシステム周りのPluginは動かなかったりPATHが違ったりするので修正しなうと動かなかったりします.

そのまま動きそうなものとしてHackserNewsを表示するプラグインを試してみました.リポジトリをcloneしてシンボリックリンクを貼ると動作しました :)

$ git clone https://github.com/matryer/bitbar-plugins
$ cd bitbar-plugins
$ ln -s `pwd`/Web/HackerNews/hacker_news.1m.rb ~/.config/argos/

argos hackernews

という感じでArgosはBitBarと互換性があるしShell Scriptなどをちょっと書くだけでステータスバーにいろいろな情報を表示来てとても便利です.Gnome Shell環境の方はぜひためしてみてください.

しかし,解像度が低いと表示領域が狭く一部しか表示されなくて視認性が悪くなるので大画面のモニタがほしいところです…….

ということでMargos, Argosを試して残りはKDE Plasma向けのKargosですが,WebのREADMEを見るとちょっと古そうなので試すのをためらっています.

A Plasma port of Argos and BitBar plugins to fast create custom plasmoids.

Note: This is an alpha project. By now, it only was tested on Kubuntu 16.04 LTS.

環境1
$ git -C ~/src/argos log | head -1
commit fcb475140bd9d0b4b95279ce56c4c28f36fb29d6
$ dpkg-query -W gnome-shell gnome-shell-extensions
gnome-shell     3.38.3-1
gnome-shell-extensions  3.38.2-1
$ lsb_release -dr
Description:    Debian GNU/Linux bullseye/sid
Release:        unstable
$ uname -m
x86_64
環境2
$ git -C ~/src/argos log | head -1
commit fcb475140bd9d0b4b95279ce56c4c28f36fb29d6
$ dpkg-query -W gnome-shell gnome-shell-extensions
gnome-shell     3.38.2-1ubuntu1
gnome-shell-extensions  3.38.2-1
$ lsb_release -dr
Description:    Ubuntu Hirsute Hippo (development branch)
Release:        21.04
$ uname -m
x86_64

]]>
https://matoken.org/blog/2021/01/23/use-argos-instead-of-bitbar-swiftbar-in-gnome-shell/feed/ 1
センサーのログをNextcloudのSensorloggerで記録してみる https://matoken.org/blog/2020/12/20/try-to-record-the-sensor-log-with-nextclouds-sensorlogger/ https://matoken.org/blog/2020/12/20/try-to-record-the-sensor-log-with-nextclouds-sensorlogger/#respond Sat, 19 Dec 2020 15:00:17 +0000 http://matoken.org/blog/?p=2897

この記事は 日本Androidの会秋葉原支部ロボット部 Advent Calendar 2020 の20日分の記事です.
日本Androidの会秋葉原支部ロボット部は現在月に一回勉強会を行い様々な話題で盛り上がっています.
次の勉強会はちょうど今日(20日)です.興味のある方は覗いてみてください.

センサーのログなどをアップロードするのに色々なwebサービスを使ったり,Googleスプレッドシートに書いたりしています.
便利なんだけどロックインになるのは嫌だなって思ったりします.

Nextcloudというファイル共有サービス+αなOSSがあります.アプリケーションを追加して機能を増やすことが出来ます.例えばテレビ電話や,オンラインオフィスとか,マップサービスとか様々なアプリがあります.
これを個人的に立てて便利に使っています

この中のアプリを眺めているとSensorloggerというセンサーのログを保存できそうなものを見つけたので試してみました.

まずNextcloudですが,とりあえず試すだけならsnapを利用するのがお手軽です.Raspberry Pi + Raspberry Pi OSなどでもOKです.

Debian sid amd64/Ubuntu 20.04 LTS/Raspberry Pi OS armhfでは以下の手順でOKでした.

$ sudo apt update && sudo apt upgrade   (1)
$ sudo apt install snapd    (2)
$ sudo snap install nextcloud   (3)
  1. システムのパッケージを最新にする
  2. snapを使えるように snapd パッケージを導入
  3. snapでnextcloudを導入

10分位待つと導入が終わります.ウェブブラウザにIPアドレスを入力するとセットアップ画面が表示されるので管理者ID/PASSWORDを設定します.

これでとりあえず使えるようになったと思います.

この後Sensorloggerを導入します.
管理者権限のアカウントでNextcloudの右上のメニューから「アプリ」を開きます.

20201219 20:12:45 2014278

次に上の検索バーに「Sensorlogger」とかの文字列で検索して「有効」ボタンを押して導入します.

20201219 20:12:42 2017785

Tip
Nextcloudのアプリケーションはコマンドラインから導入することも出来ます.
$ sudo -u www-data occ app:install sensorlogger #通常導入した場合
$ sudo /snap/bin/nextcloud.occ app:install sensorlogger #snapで導入した場合

ここからは一般ユーザでOKです.

Nextcloudの上部から「Sensorlogger」のアイコンをクリックするとSensorloggerの画面が表示されます.

20201219 20:12:03 2021911

はじめはデータがないのでまっさらです.「Device」辺りでデバイスの登録をするのかな?と思いましたが出来ません.
「Read SensorLogger Wiki Devices」と書かれているのでWikiを参照してみます.

データを送ると自動的にデバイスが出来るようです.Simple, Complexの2種類のデータタイプがあるようです.Simpleは温度,湿度のようでとりあえずこれを試してみます.

以下の辺りから post.php を持ってきて使います.このscriptはダミーのランダムな温度と湿度データを作ってSensourloggerにデータを投げます.

何箇所か書き換えます.
* $url = ` を自分のNextcloudのURLに変更します.
* `$array = array("deviceId" ⇒
uuidgen コマンドなどで生成したUUIDに変更します.
* $username = をNextcloudの自分のユーザーに変更します.
* $token = に「設定」「セキュリティ」ページの「デバイスとセッション」の一番下の「新しいアプリパスワードを作成」で作成したトークンに修正します.

そしてphpとphp-curlが必要なので導入します.

Debian sid amd64/Ubuntu 20.04 LTS/Raspberry Pi OS armhfでの例
$ sudo apt install php-cli php-curl

この状態で post.php を実行して成功すると以下のようなメッセージが帰ってきます.

$ php ./post.php
{"success":true,"message":"Sensor Log successfully stored","data":null}

Sensorloggerのページの List を見るとエータがアップロードされているのが解ります :)

手動で実行するのは大変なのでcrontabにこんな感じで登録してみます.5分に一回データを送信します.

$ crontab -e (1)
$ crontab -l | grep post.php (2)
*/5 * * * *     php ~/tmp/post.php 2&>1 > ~/tmp/post.php.log
  1. crontabの編集
  2. crontabに登録されたか確認

同様にRaspberry Piの温度も送ってみます.温度の $temperature を以下のような感じで書き換えて,UUIDも書き換えるとOK.これもcrontabに登録します.

    $temperature = system( '/opt/vc/bin/vcgencmd measure_temp | awk -F "[=\']" \'{print $2 }\' | tr -d \'\n\'' );

しばらく動かしてからダッシュボードを設定するとこんな感じのチャートが表示できました.

20201219 20:12:13 2035392

密集してよくわからない部分はマウスドラッグで矩形選択するとその部分がズームされます.

20201219 22:12:30 2180945

という感じでとりあえず動きました.ドキュメントが未だ充実していな買ったり使い勝手も悪いですが最低限の機能はあるかなという感じです.
興味があったら試してみてください.
若しくはおすすめのアプリやサービスを教えてください.

]]>
https://matoken.org/blog/2020/12/20/try-to-record-the-sensor-log-with-nextclouds-sensorlogger/feed/ 0
GNU Bashのbracketed pasteの設定 https://matoken.org/blog/2020/11/12/gnu-bash-bracketed-paste-settings/ https://matoken.org/blog/2020/11/12/gnu-bash-bracketed-paste-settings/#comments Thu, 12 Nov 2020 11:52:46 +0000 http://matoken.org/blog/?p=2873

Debian sid amd64環境で最近Bashにテキストを貼り付けると貼り付けた文字列が反転して即時反映されないようになっていました.
何らかの操作をすると反転は解除されて反映されます.改行の含まれた文字列を貼り付けて誤って実行されるというようなことが抑制できていい感じです.でも貼り付けただけで実行されたつもりになってしまうこともあったり.

便利だけどこれなんだろうと確認してみました.

Changelogを見てみます.
/usr/share/doc/bash/changelog.Debian.gz は殆どUpstreamへの追従.
/usr/share/doc/bash/changelog.gz を見るとそれらしいものが載っていました.

bash-4.4-alpha, bash-4.3-release.から Bracketed paste mode が入ったようです.
そしてbash-5.1-alpha, bash-5.0-releaseから既定値になたようです.(そして気づいた)

bash-4.4-alpha, bash-4.3-release.

b. There is a new bindable variable, `enable-bracketed-paste’, which enables
support for a terminal’s bracketed paste mode.

bash-5.1-alpha, bash-5.0-release.

h. Bracketed paste mode is enabled by default.

infoを見ると enable-bracketed-paste という項目で設定できるようです.

info bash
enable-bracketed-paste (On)
       When set to On, readline will configure the terminal in a way that will enable it to insert each paste into the editing buffer as a single string of characters, instead of treating
       each character as if it had been read from the keyboard.  This can prevent pasted characters from being interpreted as editing commands.
info bash
Readline Variables
    Readline has variables that can be used to further customize its behavior.  A variable may be set in the inputrc file with a statement of the form
       set variable-name value
or using the bind builtin command (see SHELL BUILTIN COMMANDS below).

実際に叩いてみます.こんな感じでoff/onできました.

$ bind 'set enable-bracketed-paste off'
$ bind 'set enable-bracketed-paste on'

~/.bashrc 辺りに書いておくと次回のbash起動時に反映されます.

その他
  • byobu-screenでは enable-bracketed-paste on しても利用できない?
  • tmuxでのCtrl+b Ctrl + ] での貼付け時には無視される?
  • Ubuntu 20.10 amd64の5.0-6ubuntu2では既定値で無効になっているけど enable-bracketed-paste on で有効に出来る
環境
$ dpkg-query -W bash
bash    5.1~rc2-1
$ lsb_release -dr
Description:    Debian GNU/Linux bullseye/sid
Release:        unstable
$ uname -m
x86_64
]]>
https://matoken.org/blog/2020/11/12/gnu-bash-bracketed-paste-settings/feed/ 2
Raspberry Pi OS/Debian/Ubuntuでの既定のPython切り替え https://matoken.org/blog/2020/07/28/default-python-switching-on-raspberry-pi-os-debian-ubuntu/ https://matoken.org/blog/2020/07/28/default-python-switching-on-raspberry-pi-os-debian-ubuntu/#respond Tue, 28 Jul 2020 13:31:55 +0000 http://matoken.org/blog/?p=2843

最近使うPythonアプリはPython3が多くなっています.Python2のEoLが迫っているので正しいのですが,手元の環境では python コマンドは python2 に向いています.python3 コマンドを叩けばいいのですが,これを python3 に向けられないかなと試してみました.

Raspberry Pi OS arm64(busterベース)でのPython確認してみます.python コマンドは python2.7 を呼ぶようになっています.

$ python --version
Python 2.7.16
$ ls -l `which python`
lrwxrwxrwx 1 root root 7  3月  5  2019 /usr/bin/python -> python2
$ ls -l `which python2`
lrwxrwxrwx 1 root root 9  3月  5  2019 /usr/bin/python2 -> python2.7
$ ls -l `which python3`
lrwxrwxrwx 1 root root 9  3月 26  2019 /usr/bin/python3 -> python3.7

update-alternatives で管理されてるのかな?と思いましたが設定がなさそうです.

$ update-alternatives --get-selections|grep -i ^python

update-alternatives を手動で設定してみます.
これで python コマンドが python3.7 を呼ぶようになりました.

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives: /usr/bin/python (python) を提供するために自動モードで /usr/bin/python2.7 を使います
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2
update-alternatives: /usr/bin/python (python) を提供するために自動モードで /usr/bin/python3.7 を使います
$ ls -l `which python`
lrwxrwxrwx 1 root root 24  7月 28 08:47 /usr/bin/python -> /etc/alternatives/python
$ python --version
Python 3.7.3
$ update-alternatives --query python
Name: python
Link: /usr/bin/python
Status: auto
Best: /usr/bin/python3.7
Value: /usr/bin/python3.7

Alternative: /usr/bin/python2.7
Priority: 1

Alternative: /usr/bin/python3.7
Priority: 2

切り替えたいときはこんな感じで選択肢なおせばok.

$ sudo update-alternatives --config python
alternative python (/usr/bin/python を提供) には 2 個の選択肢があります。

  選択肢    パス              優先度  状態
------------------------------------------------------------
* 0            /usr/bin/python3.7   2         自動モード
  1            /usr/bin/python2.7   1         手動モード
  2            /usr/bin/python3.7   2         手動モード

現在の選択 [*] を保持するには <Enter>、さもなければ選択肢の番号のキーを押してください:

Debian asid amd64, Ubuntu 20.04 LTS amd64 でも設定してみました.

Debian sid amd64
$ update-alternatives --query python
Name: python
Link: /usr/bin/python
Status: auto
Best: /usr/bin/python3.8
Value: /usr/bin/python3.8

Alternative: /usr/bin/python2.7
Priority: 1

Alternative: /usr/bin/python3.7
Priority: 2

Alternative: /usr/bin/python3.8
Priority: 3
Ubuntu 20,04 LTS amd64
$ update-alternatives --query python
Name: python
Link: /usr/bin/python
Status: auto
Best: /usr/bin/python3.8
Value: /usr/bin/python3.8

Alternative: /usr/bin/python2.7
Priority: 1

Alternative: /usr/bin/python3.5
Priority: 2

Alternative: /usr/bin/python3.8
Priority: 3

てことで python コマンドが python3 になりました.しかしシステムワイドな設定なのでシステムのプログラムなどで問題が出るかもしれないですね.
問題が起こったらpython2に戻しましょう.

Rasoberry Pi OS amd64
$ dpkg-query -W python python3
python  2.7.16-1
python3 3.7.3-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
Debian sid amd64
$ dpkg-query -W python python3 python3.7
python  2.7.17-2
python3 3.8.2-3
python3.7       3.7.7-1+b1
$ lsb_release -dr
Description:    Debian GNU/Linux bullseye/sid
Release:        unstable
$ uname -m
x86_64
Ubuntu 20.04 LTS amd64
$ dpkg-query -W python python3 python3.7
python  2.7.17-1
python3 3.8.2-0ubuntu2
python3.7
$ lsb_release -dr
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
$ uname -m
x86_64
]]>
https://matoken.org/blog/2020/07/28/default-python-switching-on-raspberry-pi-os-debian-ubuntu/feed/ 0
Sipeed Lichee Nanoでhello world https://matoken.org/blog/2020/07/24/hello-world-in-sipeed-lichee-nano/ https://matoken.org/blog/2020/07/24/hello-world-in-sipeed-lichee-nano/#comments Fri, 24 Jul 2020 14:46:32 +0000 http://matoken.org/blog/?p=2840

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とかもできそうです.

]]>
https://matoken.org/blog/2020/07/24/hello-world-in-sipeed-lichee-nano/feed/ 1
rsync 3.2.0の新機能を少し試す https://matoken.org/blog/2020/07/17/a-little-experiment-with-the-new-features-of-rsync-3-2-0/ https://matoken.org/blog/2020/07/17/a-little-experiment-with-the-new-features-of-rsync-3-2-0/#respond Thu, 16 Jul 2020 21:40:12 +0000 http://matoken.org/blog/?p=2834

ファイル同期にとても便利な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]
]]>
https://matoken.org/blog/2020/07/17/a-little-experiment-with-the-new-features-of-rsync-3-2-0/feed/ 0
snapでNextcloudを導入して手軽にGoogleDocぽく使う(snap版Nextcloud + OnlyOffice) https://matoken.org/blog/2020/06/10/install-nextcloud-in-a-snap-and-easily-use-it-like-google-doc-nextcloud-for-snap-version-onlyoffice/ https://matoken.org/blog/2020/06/10/install-nextcloud-in-a-snap-and-easily-use-it-like-google-doc-nextcloud-for-snap-version-onlyoffice/#respond Wed, 10 Jun 2020 13:39:13 +0000 http://matoken.org/blog/?p=2792

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から導入できるのでおすすめです.

]]>
https://matoken.org/blog/2020/06/10/install-nextcloud-in-a-snap-and-easily-use-it-like-google-doc-nextcloud-for-snap-version-onlyoffice/feed/ 0
LibreOffice Impress の HTML WebCast 書き出しで遠隔プレゼン機能を試す https://matoken.org/blog/2020/06/03/try-remote-presentation-with-html-webcast-export-in-libreoffice-impress/ https://matoken.org/blog/2020/06/03/try-remote-presentation-with-html-webcast-export-in-libreoffice-impress/#respond Wed, 03 Jun 2020 14:29:26 +0000 http://matoken.org/blog/?p=2771
add 2020-06-05

該当しそうなBug

オンラインでプレゼンテーションをするとき一般的には画面共有すると思いますが,スライドファイルを前もって配布しておいてお互いそれを見ながらプレゼンも出来ます.
その間くらいの機能でスライドのページめくりをプレゼンターと視聴者で同期するサービスが欲しいなと思っています.
以下のようなサービスがあるようですが自分が何度か試した限りでは「ログイン/新規登録」が出来ず使えていません.

LibreOffice Impress のHTML 書き出し機能にWebCast 機能を見つけたので試してみました.
しかし紹介しておいてなんですがこの機能は長らくメンテされていないようなのであまり使わないほうがいいかもしれません.(Perl cgi環境も用意しにくいだろうし)

ヘルプもざっくりとした説明しかありません.

HTML 形式で保存するプレゼンテーションを開きます。

ファイル → エクスポート を行ないます。

ファイル書式 を HTML ドキュメント (LibreOffice Impress) (.html;.htm) に設定します。

ファイル名 を入力して、エクスポート をクリックします。

HTML エクスポート ウィザードの指示に従います。

てことでメモがてら.

LibreOffice Impress で書き出したいスライドを開きます.

「ファイル」→「エクスポート」でエクスポートウィドウが開きます.

LibreOffice WebCast01

書き出し先のディレクトリ(複数のファイルが書き出されるので新しいディレクトリを用意したほうが良い)を指定し,任意のファイル名を指定します.
「ファイル形式」に「HTML ドキュメント (Impress) (.html;.htm)」を選択して「エクスポート」ボタンを押します.

LibreOffice WebCast02

「デザインの割り当て」は初回は「新規デザイン」しか選べません.「次へ」ボタンを押します.

LibreOffice WebCast03

「発表方法」に「WebCast」を選択し,右側の「WebCast」では「Perl」を選択します(ASPは未検証).テキストボックスは規定値のままで構いません.「次へ」ボタンを押します.

LibreOffice WebCast04

「名前を付けて画像を保存」(原文は Save Image As なので訳が間違っていそう)で画像形式を,「モニターの解像度」でスライドの解像度を指定します.「作成」ボタンで書き出されます.
書き出し時にHTMLデザインの保存ウィンドウが表示されますがキャンセルも出来ます.

LibreOffice WebCast05

書き出したディレクトリを見ると,スライドの画像といくつかの.htmlファイルや.plなども出力されています.これらのファイルをcgiの動くsiteにコピーします.
今はcgiの動く場所がとても限られているのでこれが一番難しいかもしれないですね.

$ ls -w 80 ./slide_dir
common.pl    img15.png  img24.png  img33.png  img42.png  img51.png  img7.png
currpic.txt  img16.png  img25.png  img34.png  img43.png  img52.png  img8.png
editpic.pl   img17.png  img26.png  img35.png  img44.png  img53.png  img9.png
img0.png     img18.png  img27.png  img36.png  img45.png  img54.png  index.html
img1.png     img19.png  img28.png  img37.png  img46.png  img55.png  picture.txt
img10.png    img2.png   img29.png  img38.png  img47.png  img56.png  poll.pl
img11.png    img20.png  img3.png   img39.png  img48.png  img57.png  savepic.pl
img12.png    img21.png  img30.png  img4.png   img49.png  img58.png  show.pl
img13.png    img22.png  img31.png  img40.png  img5.png   img59.png  slide.html
img14.png    img23.png  img32.png  img41.png  img50.png  img6.png   webcast.pl

今回は自宅の適当なApache httpdの動いている環境にコピーしました.

$ scp -r ./slide_dir user@host:~/public_html/cgi-bin/

この環境は .cgi しかcgiとして動かないので,.htaccess を作成して .pl もcgiとして動くようにしました.

$ echo 'AddHandler cgi-script .pl' > ./.htaccess
$ cat ./.htaccess
AddHandler cgi-script .pl

次に *.pl ファイルに実行権を付与します.httpdのユーザが実行できる権限にします.

$ chmod o+x ./*.pl

次にページ管理ファイルの currpic.txt に読み書き権を付与します.httpdのユーザが読み書きできる権限にします.

$ chmod o+rw ./currpic.txt

これは恐らくサーバの環境依存でやらなくても動く環境のほうが多いと思うので一旦スキップして動かなかったら設定してください.editpic.pl, editpic.pl, savepic.pl, show.pl ファイルの require "common.pl"; 行を require "./common.pl"; に書き換えます.

- require "common.pl";
+ require "./common.pl";

この状態でウェブブラウザで視聴者は index.html を,プレゼンターは slide.html (html書き出し時のファイル名)を開けばOKなはずです.

以下今回試したサンプルです.多分すぐに消します.

仕組みとしてはプレゼンターがページめくり操作をすると,ページ番号の保存されている currpic.txt ファイルにページ番号を格納.
視聴者側のブラウザでは1秒毎に cgi を呼び出していて,呼び出された cgi 側では現在のページ番号が保存されている currpic.txt の内容から該当のページを表示する.といったことをしているようです.
そのためプレゼンターが操作してから実際に視聴者のページが更新されるまで数秒掛かる感じです.

中を見ると解りますがライブラリも同梱の小さな独自ライブラリ1つだけで行数も少なくとてもプリミティブです.これは誰も使わず埋もれて何年も放置されていそうです.
出来ることなら最近のギジュとで書き直されてほしいけどこれまでの放置っぷりから難しそうですね.

とりあえずはWebに公開して口頭でページめくりを指示するのが現実的そうです.
(それか普通に画面共有)

LibreOffice環境
$ dpkg-query -W libreoffice
libreoffice     1:6.4.4-1
$ lsb_release -dr
Description:    Debian GNU/Linux bullseye/sid
Release:        unstable
$ uname -m
x86_64
WebServer環境
$ dpkg-query -W apache2 perl
apache2 2.4.41-4ubuntu3
perl    5.30.0-9build1
$ lsb_release -dr
Description:    Ubuntu 20.04 LTS
Release:        20.04
$ uname -m
x86_64

]]>
https://matoken.org/blog/2020/06/03/try-remote-presentation-with-html-webcast-export-in-libreoffice-impress/feed/ 0
Bluetooth ヘッドセットが A2DP に切り替えられなくて困る https://matoken.org/blog/2020/04/10/im-having-trouble-switching-my-bluetooth-headset-to-a2dp/ https://matoken.org/blog/2020/04/10/im-having-trouble-switching-my-bluetooth-headset-to-a2dp/#comments Fri, 10 Apr 2020 13:02:31 +0000 http://matoken.org/blog/?p=2716

最近Bluetooth ヘッドセットで A2DP に切り替えが出来なくなっていました.オーディオプロファイルを A2DP にしようとすると変更に失敗します.

20200410 03:04:39 1847144

20200410 03:04:39 1847144 2

有線のヘッドホン(セリア製100円!)で使っていたのですが頭に合わなかったり不自由なので調べることに.
以下のページを見つけました.

どうも PulseAudio の自動切り替えがうまく行っていないようでこれを無効にすることで直りました.

具体的な設定は, /etc/pulse/default.pa ファイルの load-module module-bluetooth-policyauto_switch=false というオプションを付けでデーモンの再起動です.

/etc/pulse/default.pa を修正.
$ sudo git -C /etc diff /etc/pulse/default.pa
diff --git a/pulse/default.pa b/pulse/default.pa
index f670be0..494c1ce 100644
--- a/pulse/default.pa
+++ b/pulse/default.pa
@@ -64,7 +64,7 @@ load-module module-jackdbus-detect channels=2

 ### Automatically load driver modules for Bluetooth hardware
 .ifexists module-bluetooth-policy.so
-load-module module-bluetooth-policy
+load-module module-bluetooth-policy auto_switch=false
 .endif

 .ifexists module-bluetooth-discover.so
daemonを再起動(Pulseaudioは自動復帰した)
$ pulseaudio -k
$ sudo service bluetooth restart

この後ヘッドセットを接続し直すことでA2DPが使えるようになりました.

今使っているヘッドセットは Aukey EP-B26 で長時間使えていたのが良かったのですが,バッテリーがへたってしまっています.今はUSBケーブルで給電しながら使っています.有線なんだけど細いケーブル(100円ショップの巻取りUSB microBの中の線だけにしたもの)で小さなモバイルバッテリーをポケットに入れて使うと結構自由度高い感じです.

でも出来れば新調したいところ.同じものはもう売ってないようなのでこのへんとかかな?

AfterShokz も気になってるけどちょっとお高いですね.

環境
$ dpkg-query -W pulseaudio* bluez* blueman
blueman 2.1.2-1
bluez   5.53-0ubuntu2
bluez-alsa
bluez-audio
bluez-cups      5.53-0ubuntu2
bluez-gnome
bluez-input
bluez-network
bluez-obexd     5.53-0ubuntu2
bluez-serial
bluez-utils
pulseaudio      1:13.99.1-1ubuntu1
pulseaudio-module-bluetooth     1:13.99.1-1ubuntu1
pulseaudio-utils        1:13.99.1-1ubuntu1
$ lsb_release -dr
Description:    Ubuntu Focal Fossa (development branch)
Release:        20.04
$ uname -m
x86_64
$ lsusb -d 0a5c:217f
Bus 001 Device 016: ID 0a5c:217f Broadcom Corp. BCM2045B (BDC-2.1)
$ lspci | grep -i audio
00:1b.0 Audio device: Intel Corporation 5 Series/3400 Series Chipset High Definition Audio (rev 06)
]]>
https://matoken.org/blog/2020/04/10/im-having-trouble-switching-my-bluetooth-headset-to-a2dp/feed/ 2
Raspberry Pi公式のOS書き込みソフトウェアの Raspberry Pi Imager を少し試す https://matoken.org/blog/2020/03/08/try-raspberry-pi-imager-the-official-os-writing-software-for-raspberry-pi/ https://matoken.org/blog/2020/03/08/try-raspberry-pi-imager-the-official-os-writing-software-for-raspberry-pi/#comments Sun, 08 Mar 2020 14:37:48 +0000 http://matoken.org/blog/?p=2704

Instagram の動画がわかりやすいですね.
Raspberry Pi公式のOSイメージ書き込みソフトウェアです.少し試してみました.

導入

ダウンロードページにはWindows/macOSの他 Ubuntu amd64 向けの.debへのリンクしか無いのですが, https://downloads.raspberrypi.org/imager/ にアクセスすると AppImage と .sig がありました.
どちらも amd64 なので他のArchtectureじゃ使えないようです.Raspbianのarmhf版くらいは欲しいですね.

とりあえず Ubuntu 20.04 amd64 では .deb を,Debian sid amd64 では AppImage を試してみました.

debの場合

ダウンロードして署名検証して dpkg -i で導入したのですがpkgが足りなくてエラーが出力されました.足りないパッケージは apt install -f で導入しました.足りなかったパッケージは qml-module-qt-labs-settingslibdleyna-core-1.0-5 でした.(環境により変わるはず)

$ wget https://downloads.raspberrypi.org/imager/imager_amd64.deb https://downloads.raspberrypi.org/imager/imager_amd64.deb.sig
$ gpg --verify ./imager_amd64.deb.sig
gpg: assuming signed data in './imager_amd64.deb'
gpg: Signature made Fri Mar  6 20:49:08 2020 JST
gpg:                using RSA key 54C3DD610D9D1B4AF82A37758738CD6B956F460C
gpg: Good signature from "Raspberry Pi Downloads Signing Key" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 54C3 DD61 0D9D 1B4A F82A  3775 8738 CD6B 956F 460C
$ sudo dpkg -i ./imager_amd64.deb
$ sudo apt install -f
$ sudo rpi-imager
AppImage の場合

ダウンロードして署名検証して実行権を付けるだけです.

$ wget https://downloads.raspberrypi.org/imager/imager_amd64.AppImage https://downloads.raspberrypi.org/imager/imager_amd64.AppImage.sig
$ gpg --verify ./imager_amd64.AppImage.sig
gpg: assuming signed data in './imager_amd64.AppImage'
gpg: Signature made Fri 06 Mar 2020 10:34:08 PM JST
gpg:                using RSA key 54C3DD610D9D1B4AF82A37758738CD6B956F460C
gpg: Good signature from "Raspberry Pi Downloads Signing Key" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 54C3 DD61 0D9D 1B4A F82A  3775 8738 CD6B 956F 460C
$ chmod +x ./imager_amd64.AppImage
$ sudo ./imager_amd64.AppImage
余録).debを展開してとりあえず実行
$ ar x ./imager_amd64.deb
$ tar xf data.tar.xz
$ sudo ./usr/bin/rpi-imager

起動

root権が必要です.一般ユーザでも起動できるのですが,書き込み時にSD cardにアクセスできないエラーが出てしまいます.

20200308 15:03:05 1211621

OS list 取得エラー(一時的なサーバ側の問題)

現在サーバ側でSSLの問題があり大抵以下のようなエラーになります.9回に1回の割合で成功するらしいですが,私は30回ほど試してやっとうまく行きました.数日待てば治るそうなのでしばらく待ってから試す方がいいかもしれません.

20200307 17:03:40 265752

Caleb says:5th Mar 2020 at 3:32 pm
Currently giving me a “Error downloading OS list from Internet” when running it on a raspberry pi 4b

Avatar Gordon Hollingworth says:5th Mar 2020 at 5:05 pm
Yes, that’s because downloads.raspberrypi.org needs its SSL stuff updated. It should happen in the next few days!

Otherwise keep loading it, there’s a 1 in 9 chance you’ll get through to the server that does work!

Gordon

ちなみにOS listが取得できなくても自分でダウンロードしたイメージの書き込みやSD cardの消去は出来ます.

20200307 17:03:24 252063

Imagerの起動

起動するとこんな画面です.「CHOOSE OS」でOSイメージの選択(Raspbian各種とLibreELEC),ユーティリティ,消去,カスタムが選択できます.
「CHOOSE SD CARD」でSD cardやUSBメモリなどが選択できます.

20200307 17:03:12 251909

OSイメージの選択

20200308 15:03:20 1209635
20200308 15:03:02 1210096

SD card等の選択「CHOOSE SD CARD」

この画面を表示してからSD cardやUSBメモリ等を挿入するとリアルタイムに表示さるのでわかりやすいです.内蔵diskは出てきませんが,マウント中のHDDなどは出てくるので間違えないように注意しましょう.
選択できるストレージは1度に1つだけのようです.複数のメディアに書き込む場合は複数回の実行が必要です.

20200308 15:03:27 1210403

OSイメージ書き込み

「WRITE」ボタンを押すことで書き込みが開始されます.SecureEraseを試みてイメージ書き込み,ベリファイを行います.終わるまでしばらく待ちましょう.

20200308 15:03:57 1211527
20200308 15:03:30 1211923
20200308 15:03:30 1215554

自動ダウンロードしたイメージ

deb版の方は ~root/.cache/Raspberry Pi/Imager/lastdownload.cache として 最後に利用したものだけ が残るようです.なので同じイメージであれば2回目はダウンロードせずに済みます.
別のイメージを利用すると上書きされてそのイメージになります.

AppImage は /tmp/runtime-root 以下のようなので再起動したら消えてしまいますね.

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to ‘/tmp/runtime-root’

rpi-imagerでLibreELEC RPi1を書き込んだ後出来たキャッシュファイルと LibreELEC からダウンロードしたファイルを比較
# sha256sum ./lastdownload.cache
80cd38e0a576f75caaecf511970ae563c5b605896074809643aecfdc91344bcf  ./lastdownload.cache
# wget http://releases.libreelec.tv/LibreELEC-RPi.arm-9.2.0.img.gz
# sha256sum LibreELEC-RPi.arm-9.2.0.img.gz
80cd38e0a576f75caaecf511970ae563c5b605896074809643aecfdc91344bcf  LibreELEC-RPi.arm-9.2.0.img.gz
# diff -as lastdownload.cache LibreELEC-RPi.arm-9.2.0.img.gz
Files lastdownload.cache and LibreELEC-RPi.arm-9.2.0.img.gz are identical

おわりに

てことで応用が聞かない感じなのでRaspberry Piを初めて使う人向けかなーと感じました.LibreELECなんかも同じようなツールを用意しているしOSイメージ書き込みで躓く人が多いのでツールが用意されているのかもしれないですね.
更に面倒だという人はOSイメージ入りのストレージを購入すると良さそうです.

個人的なおすすめは現在だとダウンロードは手動で書き込みには balenaEtcher がいいかなと思います.これもマルチプラットホーム対応で更に同時に複数のストレージに書き込みも可能です.

試した環境

deb版を試したUbuntu環境
$ dpkg-query -W rpi-imager qml-module-qt-labs-settings libdleyna-core-1.0-5
libdleyna-core-1.0-5:amd64
qml-module-qt-labs-settings:amd64       5.12.5-5
rpi-imager      1.0
$ lsb_release -dr
Description:    Ubuntu Focal Fossa (development branch)
Release:        20.04
$ uname -m
x86_64
AppImage版を試したDebian環境
$ lsb_release -dr
Description:    Debian GNU/Linux bullseye/sid
Release:        unstable
$ uname -m
x86_64
]]>
https://matoken.org/blog/2020/03/08/try-raspberry-pi-imager-the-official-os-writing-software-for-raspberry-pi/feed/ 1
smbgetのパスワード指定 https://matoken.org/blog/2019/12/14/smbget-password-specification/ https://matoken.org/blog/2019/12/14/smbget-password-specification/#respond Sat, 14 Dec 2019 14:07:17 +0000 http://matoken.org/blog/?p=2687

sambaの速度を測るのにsambaをwgetのように使える smbget を使おうとしたのですが以前使えていた気がする -p オプションが無くなっています.

$ bash -c "read -sp \"passwd: \" passwd; smbget smb://smbhost/share/data -U user -p $passwd -O > /dev/null"
passwd: -p: unknown option

usageを見ると確かにありません.

$ smbget --usage
Usage: smbget [-?aneruRODqv] [-?|--help] [--usage] [-w|--workgroup=STRING] [-U|--user=STRING] [-a|--guest] [-n|--nonprompt] [-d|--debuglevel=INT] [-e|--encrypt]
        [-r|--resume] [-u|--update] [-R|--recursive] [-b|--blocksize=INT] [-o|--outputfile=STRING] [-O|--stdout] [-D|--dots] [-q|--quiet] [-v|--verbose]
        [-f|--rcfile=STRING]

-pを無くせばプロンプトが出てきますが毎回入力するのは面倒なのでどうにか出来ないかなとmanを見てみます.

man smbget
       -U, --user=username[%password]
           Username (and password) to use

-U オプションに一緒に書けるようです.デミリタは要らないよう.

$ bash -c "read -sp \"passwd: \" passwd; smbget smb://smbhost/share/data -U user$passwd -O > /dev/null"

デミリタに : を指定しても動きました.

$ bash -c "read -sp \"passwd: \" passwd; smbget smb://smbhost/share/data -U user:$passwd -O > /dev/null"

他にもSMB URLにも書けるようです.

man smbget
SMB URLS
       SMB URL's should be specified in the following format:

           smb://[[[domain;]user[:password@]]server[/share[/path[/file]]]]

ただし,この書き方だとSMB URLが環境変数が展開されてSTDOUTに表示されるのでパスワードを隠したい場合は使えません.

$ bash -c "read -sp \"passwd: \" passwd; smbget smb://user:$passwd@smbhost/share/data -O > /dev/null"
smb://user:password@smbhost/share/data(100.00%) at 130.69MB/s ETA: 00:00:0008
Downloaded 2.17GB in 17 seconds

それを言うと -U の場合もプロセスにパスワードが表示されてしまうのであまりよろしくないですね.てことでとりあえずこんな感じならいいかな?

$ bash -c "read -sp \"passwd: \" passwd; echo $passwd | smbget smb://smbhost/share/data -U user -O > /dev/null"

このときのプロセス

$ ps -ef|grep smbget
mk       12626 14620  0 22:38 pts/6    00:00:00 bash -c read -sp "passwd: " passwd; echo $passwd | smbget smb://smbhost/share/data -U user -O > /dev/null
mk       13263 12626 49 22:39 pts/6    00:00:00 smbget smb://smbhost/share/data -U user -O

あれ?結局最初に戻って…….

余録(キャッシュクリア)

速度を測りたいけど2回目以降はキャッシュされてしまうのでキャッシュをクリアして測る.
以下はlocalhostで試してるので差が出ているが,ネットワーク経由だとネットワークがボトルネックになり差が出なかった.でも一応やっておく.

1回目
smb://smbhost/share/data(100.00%) at 28.12MB/s ETA: 00:00:00434
Downloaded 2.17GB in 79 seconds
2回目
smb://smbhost/share/data(100.00%) at 130.69MB/s ETA: 00:00:0008
Downloaded 2.17GB in 17 seconds
キャッシュをクリア
$ sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"
もう一回
smb://smbhost/share/data(100.00%) at 27.43MB/s ETA: 00:00:0044
Downloaded 2.17GB in 81 seconds

/proc/sys/vm/drop_caches についてはKernel Documentsの admin-guide/sysctl/vm.rst.gz あたりを参照のこと.

$ zgrep ^drop_caches -A42 /usr/share/doc/linux-doc-5.3/Documentation/admin-guide/sysctl/vm.rst.gz

環境

環境1
$ dpkg-query -W samba smbclient bash
bash    4.4.18-2ubuntu1.2
samba   2:4.7.6+dfsg~ubuntu-0ubuntu2.14
smbclient       2:4.7.6+dfsg~ubuntu-0ubuntu2.14
$ lsb_release -dr
Description:    Ubuntu 18.04.3 LTS
Release:        18.04
$ uname -rvm
4.15.0-72-generic #81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 2019 x86_64
環境2
$ dpkg-query -W samba smbclient bash
bash    5.0-5
samba   2:4.11.1+dfsg-3
smbclient       2:4.11.1+dfsg-3
$ lsb_release -dr
Description:    Debian GNU/Linux bullseye/sid
Release:        unstable
$ uname -rvm
5.3.0-3-amd64 #1 SMP Debian 5.3.15-1 (2019-12-07) x86_64
]]>
https://matoken.org/blog/2019/12/14/smbget-password-specification/feed/ 0
Nextcloudのデータディレクトリを移動するメモ https://matoken.org/blog/2019/12/03/move-nextcloud-data-directory/ https://matoken.org/blog/2019/12/03/move-nextcloud-data-directory/#respond Mon, 02 Dec 2019 16:51:48 +0000 http://matoken.org/blog/?p=2682

Nextcloudのデータディレクトリは既定値ではNextcloudのすぐ下の data ディレクトリになります.しかしここはウェブサーバのドキュメントルート以下になってしまい設定をミスするとデータディレクトリが一般公開されてしまう可能性があり少し怖いです.
そこでNextcloud導入時に設定ファイルの config/config.phpdatadirectory にウェブサーバドキュメントルートの外にNextcloudデータを設定します.

今回デフォルトのウェブサーバドキュメントルート内のまま運用されているNextcloudがあったのでそれをウェブサーバドキュメントルート外に移動してみました.
ディスクを増設してそちらにデータを移すなどの際にも同じ手順でデータ移行できると思います.

今回の例でのパスはこんな感じです.

  • Nextcloud導入ディレクトリ : /var/www/nextcloud
  • 旧Nextcloud データディレクトリ : /var/www/nextcloud/data
  • 新Nextcloud データディレクトリ : /var/data/nextcloud/data
Important
インストール後のデータディレクトリの移動は公式ではサポートされていません.

ファイルのコピー

同一のファイルシステム間であれば mv commandで一瞬ですが,今回はファイルシステムを跨いでいるので時間がかかります.
ダウンタイムを短くしたいのでNextcloud動作状態で一度データをコピーしてその後rsyncで差分のみコピーすることにします.

1度目のコピー

$ sudo cp -a /var/www/nextcloud/data /var/www/nextcloud/

rsyncでデータ同期

1度目のデータコピーに時間がかかったのでrsyncで同期

$ sudo rsync -avc /var/www/nextcloud/data /var/www/nextcloud/

バックグラウンドジョブを停止(恐らくこの手順は不要)

次の手順でメンテナンスモードに移行するので不要だと思うけど念の為バックグラウンドジョブをcrontabで設定しているのを停止(コメントアウト)しておく.(Webcronの場合も止めたほうがいいかも.AJAXの場合は恐らく不要)

$ sudo -u www-data crontab -e

メンテナンスモードに移行

ここからNextcloudは利用できなくなります.

$ sudo -u www-data php ./occ maintenance:mode --on

データ同期

-c オプションも付けたほうがいいけどデータが大きいと時間がかかるので今回はなしであとでチェックすることにする.

$ sudo rsync -av /var/www/nextcloud/data /var/www/nextcloud/

データベース書き換え

Nextcludのデータベース内のファイルディレクトリ情報を書き換えます.書き換え前に念の為データベースのバックアップも取っておきます.

バックアップ
$ sh -c "umask 266 ; mysqldump -uroot -p --opt --all-databases --events | xz > mysqlbackup-`date +\%F_\%T_\%s_$`.sql.xz"
db書き換え
$ mysql -unextcloud -p
mysql> use nextcloud;
mysql> update oc_storages set id='local::/var/data/nextcloud/data/' where id='local::/var/www/nextcloud/data/';
mysql> quit;

設定ファイル書き換え

Nextcloudの設定ファイルの config/config.php の中の datadirectory を新しいパスに書き換えます.

  'datadirectory' => '/var/data/nextcloud/data',

メンテナンスモードをoffにする

$ sudo -u www-data php ./occ maintenance:mode --off

動作確認

Nextcloudにログインしてファイルディレクトリが閲覧できることを確認する.

バックグラウンドジョブを設定

バックグラウンドジョブをcrontabで再設定

$ sudo -u www-data crontab -e

旧データの削除

しばらく運用して問題ないようなら旧データを削除する.

$ sudo rm -rf /var/www/nextcloud/data

生ディスクなんかだと secure-delete とか使うと少し安心.でも確実じゃないし時間かかるので暗号化fsを推奨.

$ sudo nice -20 ionice -c1 -n0 srm -r /var/www/nextcloud/data

環境

$ sudo -u www-data php ./occ -V
Nextcloud 17.0.1
$ dpkg-query -W php7.2-common mysql-server
mysql-server    5.7.28-0ubuntu0.18.04.4
php7.2-common   7.2.24-0ubuntu0.18.04.1
$ lsb_release -dr
Description:    Ubuntu 18.04.3 LTS
Release:        18.04
$ uname -m
x86_64
]]>
https://matoken.org/blog/2019/12/03/move-nextcloud-data-directory/feed/ 0
Nextcloud upgrade時に`Check for expected files The following extra files have been found: .rnd` と言われて失敗する(15.0.7→16.0.6) https://matoken.org/blog/2019/11/29/failed-to-say-check-for-expected-files-the-following-extra-files-have-been-found-rnd-during-nextcloud-upgrade-15-0-7-%e2%86%92-16-0-6/ https://matoken.org/blog/2019/11/29/failed-to-say-check-for-expected-files-the-following-extra-files-have-been-found-rnd-during-nextcloud-upgrade-15-0-7-%e2%86%92-16-0-6/#respond Fri, 29 Nov 2019 06:51:25 +0000 http://matoken.org/blog/?p=2677

Nextcloud 15.0.7からNextcloud 16.0.6へのアップグレードを行おうとしたところ,アップグレード画面で以下のようなメッセージが表示されて先に勧めません.

Nextcloud upgrade failed 20191125 13:11:17 12878

Check for expected files
The following extra files have been found:
.rnd

Nextcloud 以下を確認すると3つの .rnd ファイルが見つかりました.

$ cd /export/data/var/nextcloud-data
$ find ./ -name .rnd -ls
13495506336      0 drwxr-xr-x   3 www-data www-data       38 Jan 31  2018 ./data/matoken/files_encryption/keys/files/tmp/pizero/home/pi/.rnd
15757999341     12 -rw-r--r--   1 www-data www-data     9656 Jan 31  2018 ./data/matoken/files/tmp/pizero/home/pi/.rnd
11866753713      4 -rw-------   1 www-data www-data     1024 Nov 25 13:19 ./.rnd

以下のページを見ると,Nextcloud 直下の .rnd ファイルが悪さをしているようなのでこれを退避します.

$ sudo mv ./.rnd ~/tmp

この後もう一度アップグレードを試みるとうまく行きました.

This behavior continues up to version 15.0.7.

とのことでぎりぎり引っかかったようです😣

環境
$ sudo -u www-data php ./occ -V
Nextcloud 16.0.6
$ dpkg-query -W php7.2-common mysql-server
mysql-server    5.7.28-0ubuntu0.18.04.4
php7.2-common   7.2.24-0ubuntu0.18.04.1
$ lsb_release -dr
Description:    Ubuntu 18.04.3 LTS
Release:        18.04
$ uname -m
x86_64
]]>
https://matoken.org/blog/2019/11/29/failed-to-say-check-for-expected-files-the-following-extra-files-have-been-found-rnd-during-nextcloud-upgrade-15-0-7-%e2%86%92-16-0-6/feed/ 0