QNAP:DockerにWPをインストール

うっかり消したポストを復活させるためQNAPのDockerにWPを立ち上げました。

Docker images

  • wordpress:php8.4-apache
  • etaylashev/mariadb:armv7-latest

WordPressはポートを8000->80に割り当てしました。

docker run -p 3306:3306/tcp --name my-mariadb -e MYSQL_ROOT_PASSWORD=password -d etaylashev/mariadb:armv7-latest
docker exec -it my-mariadb mariadb --user root -ppassword

> SHOW DATABASES;

> CREATE DATABASE wordpress_db;

> SHOW DATABASES;

> SELECT user, host FROM mysql.user ORDER BY user;

> GRANT ALL ON wordpress_db.* TO 'wordpress_db'@'%' IDENTIFIED BY 'password123';

> FLUSH PRIVILEGES;

IPアドレスは固定していないので全てからアクセスできるようにしました。

wordpressのコンテナ横の矢印のある四角いボックスをクリックするとWPのセットアップ画面に入ります。サイト名、データーベースとユーザーの設定をすると完成です。

最後の問題はバックアップをリストアしてアクセスするにはFQDNが必要です。なのでLinuxの/etc/hostsを一時的に変更しました。macOSは書き込み不可のためできません。

Posted in Docker, QNAP | Comments Off on QNAP:DockerにWPをインストール

Thinkpad x260: macOS Big Surのセットアップ(再)

うっかりポストを消してしまったので、バックアップから復活させました。

Screenshot

OpenCore Legacy Patcherを使ってmacOS Big SurをダウンロードしUSBインストールを作成します。

EFIをマウントしてx260用のEFIをコピーします。

vagrant

% brew install --cask virtualbox
% brew install vagrant
% brew install libiconv gcc
% brew install libvirt --build-from-source
% /opt/vagrant/embedded/bin/ruby --version
ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [x86_64-darwin]
% brew info libvirt
==> libvirt: stable 9.5.0 (bottled), HEAD
% CONFIGURE_ARGS='with-ldflags=-L/opt/vagrant/embedded/lib with-libvirt-include=/usr/local/Cellar/libvirt/9.5.0/include with-libvirt-lib=/usr/local/lib' \
GEM_HOME=~/.vagrant.d/gems/3.1.4 \
GEM_PATH=$GEM_HOME:/opt/vagrant/embedded/gems \
PATH=/opt/vagrant/embedded/bin:$PATH \
vagrant plugin install vagrant-libvirt
% CONFIGURE_ARGS='with-ldflags=-L/opt/vagrant/embedded/lib with-libvirt-include=/usr/local/Cellar/libvirt/9.5.0/include with-libvirt-lib=/usr/local/lib' \
GEM_HOME=~/.vagrant.d/gems/3.1.4 \
GEM_PATH=$GEM_HOME:/opt/vagrant/embedded/gems \
vagrant plugin install vagrant-disksize
% CONFIGURE_ARGS='with-ldflags=-L/opt/vagrant/embedded/lib with-libvirt-include=/usr/local/Cellar/libvirt/9.5.0/include with-libvirt-lib=/usr/local/lib' \
GEM_HOME=~/.vagrant.d/gems/3.1.4 \
GEM_PATH=$GEM_HOME:/opt/vagrant/embedded/gems \
vagrant plugin install vagrant-vbguest
% vagrant destroy
% vagrant init
% vagrant box add generic/ubuntu2204
% vagrant box update
% vagrant box list
% vagrant status
% vagrant up
% vagrant ssh
% vagrant halt

(参考)Vagrant plugins インストール簡易スクリプト

#!/bin/sh

ruby_ver=$(/opt/vagrant/embedded/bin/ruby --version | awk '{print $2}')
libvert_ver=$(brew info libvirt | grep 'libvirt:' | awk '{print $4}')

function install_plugin {
    CONFIGURE_ARGS='with-ldflags=-L/opt/vagrant/embedded/lib with-libvirt-include=/usr/local/Cellar/libvirt/$libvert_ver/include with-libvirt-lib=/usr/local/lib' \
    GEM_HOME=~/.vagrant.d/gems/$ruby_ver \
    GEM_PATH=$GEM_HOME:/opt/vagrant/embedded/gems \
    PATH=/opt/vagrant/embedded/bin:$PATH \
    vagrant plugin install $vagrant_plugin

    if [ $? -eq 0 ]; then
        echo "$vagrant_plugin installation succeeded"
    else
        echo "$vagrant_plugin installation failed"
    fi
}

# install plugins

for vagrant_plugin in vagrant-libvirt vagrant-disksize vagrant-vbguest
do
    install_plugin
done
Vagrant.configure("2") do |config|
  config.vm.box = "generic/ubuntu2204"
end

(参考)vagrant basic command

  • https://www.drupal.org/node/2008794
  • https://qiita.com/0ta2/items/69c2378600bf8adaac5c

Libvritを使った接続はネットワークのみになります。

 virsh -V
Virsh command line tool of libvirt 9.1.0
See web site at https://libvirt.org/

Compiled with support for:
 Hypervisors: QEMU/KVM VMware VirtualBox ESX Test
 Networking: Remote Network Bridging
 Storage: Dir iSCSI-direct ZFS
 Miscellaneous: Daemon Secrets Debug Readline
Vagrant.configure("2") do |config|
  config.vm.box = "generic/debian10"
  config.vm.provider :libvirt do |libvirt|
    libvirt.host = "USER@IP_ADDRESS"
    libvirt.connect_via_ssh = true
  end
end

wine

% brew install --cask --no-quarantine gcenx/wine/wine-crossover
% brew install winetricks
% wineboot --init
% winetricks winxp
% winetricks corefonts # または allfonts
% wget 'https://download.microsoft.com/download/E/4/1/E4173890-A24A-4936-9FC9-AF930FE3FA40/NDP461-KB3102436-x86-x64-AllOS-ENU.exe'
% wine ./NDP461-KB3102436-x86-x64-AllOS-ENU.exe /q
#% brew install --cask xquartz # Optional

MS Officeのインストールは別途に環境設定をします。

% WINEPREFIX=$HOME/msoffice wineboot --init
% WINEPREFIX=$HOME/msoffice winecfg # xp
% WINEPREFIX=$HOME/msoffice wine setup.exe
% WINEPREFIX=$HOME/msoffice wine office2007{sp1..sp3}-kb******-fullfile-en-us.exe /passive
% WINEPREFIX=$HOME/msoffice winetricks msxml3
% WINEPREFIX=$HOME/msoffice winetricks allfonts

winecfgでライブラリの設定をします。

[Libraries]
msxml3 -> native
gdiplus -> native
riched20 -> native

Script Editorで起動スクリプトを作ります。

on run
	
	--edit this to be the correct location and file to run (typically only edit after the "drive_c")
	-- WINEPREFIX=$HOME/msoffice wine  $HOME/msoffice/drive_c/Program\ Files\ \(x86\)/Microsoft\ Office/Office12/EXCEL.EXE 
	set toRun to "$WINEPREFIX/drive_c/Program Files (x86)/Microsoft Office/Office12/EXCEL.EXE"
	
	--edit winePrefix if you are not using the default prefix
	set winePrefix to "$HOME/msoffice"
	
	--edit wineLocation if your wine install is not the default location
	set wineLocation to "/usr/local/bin"
	
	-- With workaround for broken FreeType 2.7 rendering by switching to renderer from FreeType 2.6
	-- export FREETYPE_PROPERTIES="truetype:interpreter-version=35"
	-- See comment from Lucian Poston here: https://bugs.winehq.org/show_bug.cgi?id=41639 
	
	-------------------------------------------------------
	--DO NOT EDIT ANYTHING BELOW THIS LINE
	-------------------------------------------------------
	set toRunPath to do shell script "WINEPREFIX=\"" & winePrefix & "\"; TEMPVAR=\"" & toRun & "\"; echo \"${TEMPVAR%/*}\""
	set toRunFile to do shell script "WINEPREFIX=\"" & winePrefix & "\"; TEMPVAR=\"" & toRun & "\"; TEMPVAR2=\"" & toRunPath & "\"; echo \"${TEMPVAR#$TEMPVAR2/}\""
	do shell script "PATH=\"" & wineLocation & ":$PATH\"; export FREETYPE_PROPERTIES=\"truetype:interpreter-version=35\"; export WINEPREFIX=\"" & winePrefix & "\"; cd \"" & toRunPath & "\"; wine \"" & toRunFile & "\" > /dev/null 2>&1 &"
	
end run

File formatをApplicationで保存します。アイコンを登録するとこんな感じになります。

Screenshot

cups

MS Office 2007でも印刷もできます。

ネットワークプリンター(p910nd)に接続する設定です。

まずWebインターフェースを有効にします。

% sudo cupsctl WebInterface=yes

または、

WebInterface Yes

ghostscriptをインストールします。

% gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=rpdl -r600x600 -sPAPERSIZE=a4 \
     -sOutputFile=test.bin ThinkPad_X260_Spec.pdf
% cat test.bin | nc  [ネットワークプリンタのIP] 9100

次にfoomatic-ripをインストールします。Big Surの場合はインストーラーのエラーで直接インストールができないのでアーカイブを解凍してインストールします。

wget https://www.openprinting.org/download/printdriver/macosx/foomatic-rip-4.0.6.230.dmg
sudo -s
7z x foomatic-rip-4.0.6.230.dmg
cd Foomatic-RIP\ 4.0.6/Foomatic-RIP.pkg/Contents
gunzip -dc Archive.pax.gz > Archive.pax
cpio -i <Archive.pax
cp -a ./usr/libexec/cups/backend/beh /usr/libexec/cups/backend
cp -a ./usr/libexec/cups/filter/foomatic-rip /usr/libexec/cups/filter/
cp -a ./usr/local/bin/foomatic-rip /usr/local/bin/
cp -a ./usr/local/bin/foomatic-rip-PanTig /usr/local/bin/
cp -a ./usr/local/etc/foomatic /usr/local/etc/
cp -a ./usr/local/share/man/man1/foomatic-rip.1 /usr/local/share/man/man1/

Foomatic-RIPをCUPSで使えるようにします。

sudo sh -c 'echo "Sandboxing Relaxed" >> /etc/cups/cups-files.conf'

cupsを再起動します。

sudo launchctl stop org.cups.cupsd
sudo launchctl start org.cups.cupsd

ブラウザからアクセスしてプリンターを追加します。

  • Access: http://localhost:631
  • Add Printer: Internet Printing Protocol (http), Connection: socket://[remote PC]:9100
  • Select PPD File: (example)Ricoh-RPDL_IV_Laser_Printer-rpdl.ppd

サードパーティーのKextの再インストール

HoRNDISをインストールしようとして操作を間違えて起動できない状態になりました。そこでサイトを参考にして手直ししたのですがうまくいきませんでした。

  • https://github.com/jwise/HoRNDIS/issues/132

Extension with identifiers com.joshuawise.kexts.HoRNDIS not approved to load. Please approve using System Preferences.

Big Surの場合は次のやり方が正解でした。

kmutil trigger-panic-medic --volume-root /Volumes/<YourVolumeName> in recovery mode
  • https://developer.apple.com/forums/thread/661240

参考

  • https://github.com/SuhailSherief/ThinkPad-x260-macOS-OpenCore
  • https://developer.hashicorp.com/vagrant/downloads
  • https://appdb.winehq.org/objectManager.php?sClass=version&iId=17886
  • https://lunar.computer/posts/vagrant-libvirt-macos/
  • https://github.com/SuhailSherief/ThinkPad-x260-macOS-OpenCore/issues/3
Posted in macOS | Comments Off on Thinkpad x260: macOS Big Surのセットアップ(再)

QNAPから印刷する

NASをNetgearからQNAPに変更した際に、プリンタの設定がネックになりました。Netgearの時はOSがDebianだったのでp910ndプリンターサーバをインストールできましたが、QNAPの場合は独自のファームウェアなのでそれができません。その代わりにDockerが使えます。Dockerは仮想化環境なので、ホストのポートマップとでデバイスのマップが必要になります。

DockerのイメージはDebian trixieとOpenWrtをダウンロードしました。プリンターサーバにはOpenWrtで十分なのでOpenWrtを使いました。

DockerのOpenWrtはv22.03.6で最新バージョンではありませんが、プリンターサーバとしては問題ありません。

Dockerの設定

NASのUIからは設定できないのでコマンドから登録しました。

docker run -it --device=/dev/usb/lp0:/dev/usb/lp0 -p \
   631:631/tcp -p 9100-9109:9100-9109/tcp -p 81:80/tcp \
   -p 1122:22/tcp \
   --name openwrt_printer bingsin/openwrt-armhf /sbin/init

ポートはcupsサーバを使い場合、p910ndは9100から9109まで割り当てました。OpenWrtではその値を推奨していました。あとはOpenWrtのUIとssh接続用のポートを割り当てました。QNAPのUIからターミナルの設定が分からなかったのでその保険のためです。コマンドからも入れます。

docker exec -it <コンテナID> /bin/sh

OpneWrtの設定

  • https://openwrt.org/docs/guide-user/services/print_server/p910ndprinterserver

サイトの手順通りです。

opkg update
opkg install kmod-usb-printer
opkg install p910nd luci-app-p910nd

カーネルを調べるとLinux 92c8eb6f326e 4.2.8 #2 SMP Thu Dec 25 03:27:17 CST 2025 armv7l GNU/Linuxなのでホストのカーネルです。なのでkmodはインストールする必要はないと思われます。

# ls -l /dev/usb/lp0
crw-rw----    1 root     lp        180,   0 Mar  3 19:06 /dev/usb/lp0

ただパーミッションの問題があるので、OpenWrtのUIからRun as rootにチェックを入れてrootで起動できるようにします。

Posted in OpenWrt, QNAP | Comments Off on QNAPから印刷する

OpenWrt on Amlogic

今回はTV BoxにOpenwrtを入れるという話です。古いTV Boxが転がっているので、わざわざSBCの評価ボードを買わなくてもTV Boxを転用することで使えますが、ほとんど全てAmlogicのCPUなので気が乗りませんでした。Amlogicはサポートが良くないので必ず不具合にぶつかります。一方、RockchipやAllwinnerはサポートがよくすんなりと稼働してくれます。

これらのTV BoxにはCoreLELCをいうKodiをベースとしたメディアセンターアプリがインストールしてあります。Amlogicは他社製と違いシステムがeMMCに600MBほど入れられており、それをCoreELECをeMMCにインストールすると改変するため、TFカードやUSBメモリから起動できないという問題があり、一旦、Stock Firmwareを入れなければいけないという作業が必要です。

Stock Firmwareのインストール

Firmwareを戻すのは、これが非常に困難な作業です。まずはFirmwareをネットから探して拾ってこなければならないのですが、これがなかなか見つからない。それなのでスペックを調べて、CPUのタイプ、メモリ、ネットワークデバイス(wifiとethernet)に合致した自分の持っている機種に近いFirmwareを探します。私の手元にあるのは、s912のZEN BOX 2/16 1G-LANとs905xのNex Box x95A 1/8 100M-LANです。他にもあるのですがeMMCが破損しているので普通では使えないので、無理やりStock FirmwareをTFカードに入れてその上にCoreELECをインストールしてあります。

Stock Firmwareも中にはカスタムROMというのがあって、非常にややっこしいことにTFカードやUSBメモリから起動できない仕様になっているので注意が必要です。

やり方は次のサイトの手順で行います。

  • https://androidpctv.com/amlogic-firmware-update-guide-tvbox/

s905xとs912は古いCPUなのでAMLogic USB Burning Tool v2.2.4というツールをダウンロードします。ツールのバージョンが違うとCPUに対応していないということらしいです。Windows10の場合はUSBドライバーとWindowsのランタイムライブラリの問題があって、32bitのランタイムライブラリをMSサイトからダウンロードしてインストールします。非認証のUSBドライバーの問題は、サイトにあるやり方で、Settings>Updates&Security>Recovery> Advanced Setup>Troubleshoot>Advanced options>Startup Settings>Restart>F7 Keyという操作になります。このリカバリーアプリはXPでも動くので、あればそちらの方がストレスがないと思います。なおTV Boxに接続するにはA-AタイプのUSBケーブルが必要になります。

OpenWrtのインストール

次のサイトからOpenWrtのFirmwareをダウンロードします。

  • https://github.com/ophub/amlogic-s9xxx-openwrt

結論から言うとs905xは起動できませんでしたがs912は動きました。いくつか問題があって、まずは大事なネットワークですが、k6.18だと動きません。k6.12は動くのでそちらを選択します。拡張u-bootの設定が必要でu-boot-s905x-s912.binをu-boot.extにコピーまたはリネームします。なお、TFカードでは起動できませんでした。そしてuENV.txtでFDT=/dtb/amlogic/meson-gxm*を編集します。meson-gxm以下のD TBなら動くと思いますが、ネットワークなど微妙に違うかもしれないので何度かテストして最適なDTBを設定ます。

そのほかの問題はHDMI接続してキーボードの入力があまりうまくできないので、できなくはないのですが、思ったように動いてくれないので、ネットワークが使えるようになればsshかWeb UIにデフォルトの192.168.1.1にアクセスした方が良いです。

LibreELEC

LibreELECはサポートがとても良く、どちらの機種ともTFカードとUSBメモリから動きました。ただCoreELECとは違いWIFIは使えませんでした。LibreELECの方が最新のKodiが使えるので好みで選べます。

OpenWrtの起動

起動するとこのような画面になります。ファイルシステムはbtrfsです。メモリにやさしいファイルシステムでext4より格段に寿命が伸びるそうです。

OpenWrt on s905xを無理やり起動してみる

LibreELECでTFカードから起動できることから、おそらくu-bootがよくできていると推測できるので、LibreELECのシステムに無理やりOpenWrtを埋め込んでみました。やり方としてLibreELECのイメージにamlogicの起動スクリプト、linux関係のdtb、uENV.txt、カーネル等をコピーします。fdiskコマンドでLibreELECの2番目のパーティションを削り、新たにOpenWrtと同じサイズのパティションを作ります。そしてOpenWrtのrootfsパーティションをddでコピーします。

無事起動できました😊

追記:私のGithubのスクリプトでも動きますが、u-bootのインストールアドレスがわかれば、その部分だけを書き換えれば面倒なことをしなくても動くと思われます。

その他

パッケージシステムがopkgからapkに変更になっており、使い方がやや煩雑になっています。

チートシートがサイトにありました。

  • https://openwrt.org/docs/guide-user/additional-software/opkg-to-apk-cheatsheet

大体これで行けるのですが、たまにないパッケージがあってこれが厄介です。依存関係が強力なので強制的に入れる手段がありません。例えばカーネルモジュールですが、すでに全部あるので入れる必要がないのですが、まれにパッケージ登録されてないために依存関係の問題でインストールができないことがあります。その場合、パッケージを解凍してインストールするしかありません。やり方は次の通りです。

apk extract --allow-untrusted <package_file.apk>

Posted in OpenWrt, tvbox | Comments Off on OpenWrt on Amlogic

Silverdict

前回はGoldendictのインストールをしましたが今回はSilverdictについてです。Silverdictはサーバー形式でブラウザで表示することができます。それなのでネットワークにサーバを置いてあげればどのIT機器でもアクセスできます。macOSは標準で辞書を持っているので特別他の辞書が必要ではないのですがLinuxはないのであると便利です。Linux機はストレージを最小限にしてあるのであまり余計な辞書を入れても意味がないので、最小限にとどめておきます。それでサーバから必要に応じでアクセスできれば合理的です。

  • https://github.com/Crissium/SilverDict

手元にあるのがOrangePi zeroだったのでそれにインストールすることしました。OrangePiにはOpenWrtが入っていて、普段は簡易サーバ用途で使っていたのですが、SilverDictでPythonセットアップでは開発環境が必要で、lxcをセットアップしてそれにDevuan excaliburを立ち上げました。手順通りにSilverDictをセットアップして無事立ち上がりました。次の段階でNginxを使った方法でやりたかったのですが、メモリ不足でNode.jsがうまく動作せず中断しました。

NanoPi R3Sなら問題なく行けそうですが、値段見るとTFカードや電源など合計すると1万円はかかるので、趣味にあまりお金をかけたくないということでやめました。手持ちのamlogicのTVBOXが転がっているので、新しいTFカードを使ってOpenWrtを入れて、OpranPiのコンテナを移植するのもありかなと考えています。

このように結構綺麗に表示できました。

辞書形式は色々ありましが、StarDictとMdictを使っています。ただStarDictはSliverDictでうまくレイアウトができないものもあり、Mdictで統一しています。辞書もいくらでも追加できて面白いです。

Nginxのセットアップ

当初、サイトの通りにやってみ他のですがうまく動きませんでした。それでシステムをよく見直してみました。

Net === Openwrt - lxc container(Silverdict) 

サイトではReverseProxyでSiverdictを動かしているので、OpenwrtにNginxを入れても問題ありません。

worker_processes  1;

#error_log  /var/log/nginx/error.log;

events {
    worker_connections  1024;
    use epoll;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  1000;

    server {
        #listen       8080 reuseport fastopen=10;
        listen       8080;
        server_name  localhost;

        charset utf-8;

        #location / {
        #    root   /srv/www/htdocs/;
        #    index  index.html index.htm;
        #}

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /srv/www/htdocs/;
        }

        # Proxy /api/* requests to the server listening on 2628
#        location /api/ {
        location / {
            proxy_pass http://192.168.2.2:2628;

            proxy_redirect     default;
            proxy_http_version 1.1;
            proxy_set_header   Host              $http_host;
            proxy_set_header   X-Real-IP         $remote_addr;
            proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_max_temp_file_size 0;

            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;
            proxy_request_buffering    off; # Required for HTTP CLI commands
        }
    }
}

コンテナはでは次のようにSilverDicrを起動します。

python3 server.py 0.0.0.0:2628

またコンテナの設定でマスカレードそして2628/tcpのポートフォワーディングも設定しておきます。

Posted in e-book | Comments Off on Silverdict

GoldenDict-ng

この間のKoboのKoreaderの辞書を設定したときにLong バージョンの辞書があったのでそれをデスクトップ用に使えたら良いなと思いついたので早速やってみました。StardictはGouldendictで表示できるということで、現在はGoldenDict-ngというのが使えました。LinuxとmacOSの両方で対応しているので重宝できそうです。

オックスフォードのペーパーバックは、中古ですが手元にあるのですが、最大の問題は簡易製本なので使い古すと背の糊が割れてきて、そこからページが剥がれてくるということです。結局、製本用の糊を買う羽目になって、手間とお金がかかってきます。電子化した辞書を手軽にアクセスできればそちらの方が断然良いです。

アクセスする手段としてはアプリからとサーバからWebアクセスを2通りを考えています。まずはGoldenDictからです。GoldenDictから派生したGoldenDict-ngにmacOS用のインストーラーがあったのでそちらをインストールしました。

  • https://xiaoyifang.github.io/goldendict-ng
Posted in e-book | Comments Off on GoldenDict-ng

Kobo Touch (N905B)

紙の本は痛むのでe-readerのキンドルの中古を調べてみたら、どれも高く迷っていたところ、Kobo Touchが1800円弱であったので注文しました。2012年の製品で初期のe-readerですが、3世代目のE Ink Pearlを搭載して割と綺麗な上タッチパネルという仕様になっていて、遅いこととバックライトがない以外に特に欠点は思いつきません。とはいうものの、ビルトインのビューワーよりKoreaderというビューワーの方がよいと評判なのでインストールしました。

実際は思ったほど簡単ではなくタッチスクリーンの不具合という致命的な問題があります。Google AIですぐズバリ回答できるようになって、すぐ修正方法がわかったのはありがたいことです。問題は最新のファームウェアにありました。問題を解決するにはファームウェアのダウングレード、そして楽天のKobo Desktopアプリに接続させないことです。アプリに接続するとすぐさまアップグレードするので、それは回避させないといけません。

ファームウェアのバージョンはv4.34が安定しているということでこちらのサイトからダウンロードしました。

  • https://pgaskin.net/KoboStuff/kobofirmware.html

まず、Settings > Device Information > Factory Resetで初期化します。リブートしてPC
にUSB接続してKoboのファイルシステムにアクセスします。解凍したファームウェアを隠しファイルもろとも全て.koboフォルダーにコピーします。コピーを終えたらアンマウントしUSBケーブルを外します。そうすると自動的にKoboがアップデートを開始します。

ダウングレードが完了したら次に自動アップグレードを回避する作業を行います。USBケーブルでKoboとPCを繋ぎます。.koboのディレクトリのKobo/KoboReader.configをエディターで編集します。[ApplicationPreferences]セクションの下にSideloadedMode=trueを追加します。リブートするとKoboの標準画面に入れます。

そしてようやく、Koreaderをインストールに取りかかれます。手順はmobilereadに書かれている通りです。流れとしては、まずKFMon &とNickelMenuをインストールします。そのあとKoreaderをインストールします。

  • https://www.mobileread.com/forums/showthread.php?t=314220

辞書はオンラインよりインストールできますが、wifiに接続してインストールするとファームウェアも同時にアップデートされるので注意が必要です。Koreaaderの辞書はStarDict形式になっていて、Koboの辞書は使えません。それでSOEDrich StarDict 2022-11-11 (e-Ink)というオックスフォード辞書があるのでそれをインストールしました。

E-book

古典しか読まないのでパブリックドメインの良書をインストールしました。

  • https://standardebooks.org/

Posted in e-book | Comments Off on Kobo Touch (N905B)

macOS: Apple ConfiguratorのCertificate(PKCS12)のインストール

macOSでStrongSwanのIKEv2を使う場合、Apple Configuratorの設定が必要になります。証明書がインストールできなかったので、色々調べたところ、どうもmacOSのSSLプログラムがおかしいということに気が付きました。macOSではLibreSSLを使っていて、フロントエンドのXCAはOpenSSLを使っています。XCAからPKCS12を作るとApple Configuratorで登録できない。そこでコマンドラインからPKCS12を作りました。重要な点はコマンドオプションに-legacyをつけてあげることでした。

openssl pkcs12 -legacy -export -in USER_CERT.crt \
-inkey USER_KEY.pem \
-chain -CAfile SITE_CA.crt \
-out USER.pfx
Posted in macOS, strongSwan | Comments Off on macOS: Apple ConfiguratorのCertificate(PKCS12)のインストール

Linux: dovecot 2.4 アップデート

Debian trixieにアップデートしたときにdovecotも2.4.1にアップグレードされたのですが、設定が2.3から大幅にかわり、そのままでは動かないので再設定が必要になりました。その時の設定メモです。

旧設定はこちら

Dovecot

# 2.4.1-4 (7d8c0e5759): /etc/dovecot/dovecot.conf
# Pigeonhole version 2.4.1-4 (0a86619f)
# OS: Linux 6.12.57+deb13-amd64 i686 Debian 13.2 overlay
# Hostname: debian-mailserver
# 4 default setting changes since version 2.4.0
dovecot_config_version = 2.4.0
auth_mechanisms = plain login
auth_verbose = yes
auth_verbose_passwords = yes
dovecot_storage_version = 2.4.0
listen = *, ::
log_debug = category=mail
mail_driver = maildir
mail_home = /var/vmail/${user|domain}/${user|username}
mail_inbox_path = /var/vmail/${user|domain}/${user|username}
mail_path = /var/vmail
protocols = imap lmtp
ssl = required
ssl_cipher_list = kEECDH:+kEECDH+SHA:kEDH:+kEDH+SHA:+kEDH+CAMELLIA:kECDH:+kECDH+SHA:kRSA:+kRSA+SHA:+kRSA+CAMELLIA:!aNULL:!eNULL:!SSLv2:!RC4:!MD5:!DES:!EXP:!SEED:!IDEA:!3DES
passdb passwd-file {
  default_password_scheme = SHA512-CRYPT
  passwd_file_path = /etc/dovecot/imap.passwd
}
userdb static {
  fields {
    gid:default = vmail
    home:default = /var/vmail/${user|domain}/${user|username}
    uid:default = vmail
  }
}
namespace inbox {
  inbox = yes
}
service imap-login {
  inet_listener imap {
    port = 0
  }
  inet_listener imaps {
    port = 993
    ssl = yes
  }
}
service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    mode = 0600
    user = postfix 
    group = postfix
  }
}
service imap {
}
service auth {
  user = $SET:default_internal_user
  unix_listener /var/spool/postfix/private/auth {
    mode = 0600
    user = postfix 
    group = postfix
  }
}
service auth-worker {
  user = $SET:default_internal_user
}
service dict {
  unix_listener dict {
  }
}
ssl_server {
  cert_file = /etc/acme/hottunalabs.net/fullchain.cer
  dh_file = /etc/acme/ssl-dhparams.pem
  key_file = /etc/acme/hottunalabs.net/hottunalabs.net.key
}
local_name hottunalabs.net {
  ssl_server {
    cert_file = /etc/acme/hottunalabs.net/fullchain.cer
    key_file = /etc/acme/hottunalabs.net/hottunalabs.net.key
  }
}
local_name hottunalabs.mydns.org {
  ssl_server {
    cert_file = /etc/acme/hottunalabs.net/fullchain.cer
    key_file = /etc/acme/hottunalabs.net/hottunalabs.net.key
  }
dovecot_config_version = 2.4.0
dovecot_storage_version = 2.4.0
protocols = imap lmtp
!include_try /usr/share/dovecot/protocols.d/*.protocol
listen = *, ::
!include conf.d/*.conf
!include_try local.conf
auth_mechanisms = plain login 
!include auth-passwdfile.conf.ext
mail_driver = maildir
mail_path = /var/vmail
mail_home = /var/vmail/${user|domain}/${user|username}
mail_inbox_path = /var/vmail/${user|domain}/${user|username}
namespace inbox {
  inbox = yes
}
protocol !indexer-worker {
}
service imap-login {
  inet_listener imap {
    port = 0
  }
  inet_listener imaps {
    port = 993
    ssl = yes
  }
}
service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {   
    mode = 0600
    user = postfix 
    group = postfix
  }
}
service imap {
}
service auth {
  unix_listener /var/spool/postfix/private/auth {
    mode = 0600
    user = postfix 
    group = postfix
  }
  user = $SET:default_internal_user
}
service auth-worker {
  user = $SET:default_internal_user
}
service dict {
  unix_listener dict {
  }
}
ssl = required
ssl_server_cert_file = /etc/acme/hottunalabs.net/fullchain.cer
ssl_server_key_file = /etc/acme/hottunalabs.net/hottunalabs.net.key
ssl_server_dh_file = /etc/acme/ssl-dhparams.pem
local_name hottunalabs.net {
    ssl_server_cert_file = /etc/acme/hottunalabs.net/fullchain.cer
    ssl_server_key_file = /etc/acme/hottunalabs.net/hottunalabs.net.key
}
local_name hottuna.server-on.net {
    ssl_server_cert_file = /etc/acme/hottunalabs.net/fullchain.cer
    ssl_server_key_file = /etc/acme/hottunalabs.net/hottunalabs.net.key
}
ssl_min_protocol = TLSv1.2
ssl_cipher_list = kEECDH:+kEECDH+SHA:kEDH:+kEDH+SHA:+kEDH+CAMELLIA:kECDH:+kECDH+SHA:kRSA:+kRSA+SHA:+kRSA+CAMELLIA:!aNULL:!eNULL:!SSLv2:!RC4:!MD5:!DES:!EXP:!SEED:!IDEA:!3DES
protocol lda {
}
protocol imap {
}
protocol lmtp {
}
passdb passwd-file {
  default_password_scheme = SHA512-CRYPT
  passwd_file_path = /etc/dovecot/imap.passwd
}
userdb static {
  fields {
    uid:default = vmail
    gid:default = vmail
    home:default = /var/vmail/${user|domain}/${user|username}
  }
}

opendkim

旧版ではinet socketでしたが今回はunix domain socketに変更します。

Syslog			yes
SyslogSuccess		yes
Canonicalization	relaxed/simple
OversignHeaders		From
Domain			hottunalabs.net
Selector                myselector
KeyFile			/etc/dkimkeys/myselector.private
UserID			opendkim
UMask			002
Socket			local:/var/spool/postfix/opendkim/opendkim.sock
PidFile			/run/opendkim/opendkim.pid
TrustAnchorFile		/usr/share/dns/root.key
sudo mkdir /etc/dkimkeys
sudo chown root: /etc/dkimkeys
sudo chmod 700 /etc/dkimkeys
cd /etc/dkimkeys 
sudo opendkim-genkey -r -s myselector -d <my domain name>
groupadd dkimsocket
usermod --append --groups dkimsocket postfix
usermod --gid dkimsocket opendkim
usermod --append --groups opendkim opendkim
usermod --append --groups opendkim postfix

myselector.txtができるのその内容をDNSサーバーに設定します。

myselector._domainkey   IN	 TXT	"v=DKIM1; p=...................."

openDMARC

PidFile /run/opendmarc/opendmarc.pid
PublicSuffixList /usr/share/publicsuffix/public_suffix_list.dat
Socket local:/var/spool/postfix/opendmarc/opendmarc.sock
Syslog true
UMask 0002
UserID opendmarc
sudo mkdir -p /var/spool/postfix/opendmarc
sudo chown opendmarc:opendmarc /var/spool/postfix/opendmarc -R
sudo chmod 750 /var/spool/postfix/opendmarc/ -R
sudo adduser postfix opendmarc

Postfix

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
append_dot_mydomain = no
compatibility_level = 3.6
sendmail_path = /usr/sbin/postfix
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
inet_interfaces = all
inet_protocols = ipv4
message_size_limit = 10485760
setgid_group = postdrop
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/lib/postfix/sbin
data_directory = /var/lib/postfix
myhostname = mx.hottunalabs.net
mydomain = hottunalabs.net
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = $myhostname, mail-debian, localhost.localdomain, localhost
relayhost = 
mynetworks = 127.0.0.0/8, 10.0.0.0/24
mailbox_size_limit = 0
recipient_delimiter = +
local_recipient_maps = unix:passwd.byname $alias_maps
unknown_local_recipient_reject_code = 550
debugger_command =
         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
         ddd $daemon_directory/$process_name $process_id & sleep 5
smtp_sender_dependent_authentication = yes
smtpd_tls_chain_files = /etc/acme/hottunalabs.net/hottunalabs.net.key, /etc/acme/hottunalabs.net/fullchain.cer
tls_server_sni_maps = hash:/etc/postfix/ssl_map
smtpd_tls_security_level=may
smtp_tls_security_level=may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_tls_mandatory_ciphers = high
smtpd_tls_mandatory_exclude_ciphers = aNULL, MD5
smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3
cyrus_sasl_config_path = /etc/postfix/sasl
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_tls_auth_only = yes
smtpd_sender_restrictions = reject_unknown_sender_domain, reject_non_fqdn_sender, hash:/etc/postfix/reject_sender
smtpd_recipient_restrictions = permit_sasl_authenticated,
        permit_mynetworks,
        reject_unauth_destination,
        reject_invalid_hostname,
        reject_unknown_recipient_domain,
        reject_unauth_destination,
smtpd_helo_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        reject_invalid_helo_hostname,
        reject_non_fqdn_helo_hostname,
        reject_unknown_helo_hostname
recipient_delimiter = +
virtual_transport = lmtp:unix:private/dovecot-lmtp
virtual_mailbox_domains = $mydomain
virtual_alias_domains = hottunalabs.mydns.org
virtual_alias_maps = hash:/etc/postfix/virtual_aliases
milter_default_action = accept
milter_protocol       = 6
smtpd_milters         = local:opendkim/opendkim.sock,local:opendmarc/opendmarc.sock
non_smtpd_milters     = $smtpd_milters
smtp      inet  n       -       y       -       -       smtpd
submission inet n       -       y       -       -       smtpd
  -o smtpd_sasl_auth_enable=yes
pickup    unix  n       -       y       60      1       pickup
cleanup   unix  n       -       y       -       0       cleanup
qmgr      unix  n       -       n       300     1       qmgr
tlsmgr    unix  -       -       y       1000?   1       tlsmgr
rewrite   unix  -       -       y       -       -       trivial-rewrite
bounce    unix  -       -       y       -       0       bounce
defer     unix  -       -       y       -       0       bounce
trace     unix  -       -       y       -       0       bounce
verify    unix  -       -       y       -       1       verify
flush     unix  n       -       y       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       y       -       -       smtp
relay     unix  -       -       y       -       -       smtp
        -o syslog_name=postfix/$service_name
showq     unix  n       -       y       -       -       showq
error     unix  -       -       y       -       -       error
retry     unix  -       -       y       -       -       error
discard   unix  -       -       y       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       y       -       -       lmtp
anvil     unix  -       -       y       -       1       anvil
scache    unix  -       -       y       -       1       scache
postlog   unix-dgram n  -       n       -       1       postlogd
maildrop  unix  -       n       n       -       -       pipe
  flags=DRXhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
uucp      unix  -       n       n       -       -       pipe
  flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
ifmail    unix  -       n       n       -       -       pipe
  flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp     unix  -       n       n       -       -       pipe
  flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix -       n       n       -       2       pipe
  flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman   unix  -       n       n       -       -       pipe
  flags=FRX user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py ${nexthop} ${user}
hottunalabs.net /etc/acme/hottunalabs.net/hottunalabs.net.key /etc/acme/hottunalabs.net/fullchain.cer
hottuna.server-on.net /etc/acme/hottunalabs.net/hottunalabs.net.key /etc/acme/hottunalabs.net/fullchain.cer
postmaster          root 
webmaster           root
 # Person who should get root's mail 
root                myname
info@hottunalabs.net     myname
myname@mydns.org	myname\@hottunalabs.net
myname@hottunalabs.net		myname\@hottunalabs.net
sudo touch reject_sender
sudo postmap reject_sender
sudo postmap ssl_map
sudo postmap virtual_aliases

参考

  • https://doc.dovecot.org/main/installation/upgrade/2.3-to-2.4.html
  • https://z-issue.com/wp/dovecot-2-3-to-2-4-update-problems/
  • https://wiki.archlinux.org/title/OpenDKIM
  • https://wiki.gentoo.org/wiki/OpenDKIM
Posted in Linux, Mail | Comments Off on Linux: dovecot 2.4 アップデート

Linux: Debian trixieのOpenRC化

VPSのDebianをbookwormからtrixieにアップグレードのついでにOpenRCも同時にすることにしました。方法はDebianのwikiを参照してそのとおりにしたのですが、結果はシステムが完全に破綻状態になりました。やはり無謀すぎたようです。それでクリーンインストールしてOpenRC化することにしました。OpenRC化する理由はsystemdはリソースを食いすぎて運用しているVPSにかなり負担になっているからです。

VPSに正規方法ではないインストール方法は手間がかかるのですが不要なパッケージ入れないようにするためにこの方法を使います。

やり方はまずVPSで用意されているCDを使ってブートし、レスキューモードのシェルを立ち上げます。そしてrootパーティションをchrootでマウントし、debootstrapコマンドでOSをインストールします。OSが復旧したら別途保存しておいた設定やデータをリストアします。

OpenRC化

initを置き換えるのはかなりトリッキーですが、Debianのwikiに方法があったのでその通りにやってみました。

apt –purge –allow-remove-essential install sysvinit-core libpam-elogind dbus-x11 systemd-sysv-

これはsysv-initなのでOpenRCの場合は次のようにします。

apt --purge --allow-remove-essential install openrc systemd-sysv-

OS復旧仕立て場合は一発で変更できました。経験としてパッケージを入れすぎると破綻してしまうということでした。そしてsystemdをインストールしないように予防線を張っておきます。

apt-mark hold systemd systemd-sysv

たいていのデーモンは/etc/init.dから起動できますがshorewallだけは起動できなかったので/etc/rc.localから起動するようにしました。

暗号化rootfsのネット経由のunlock

まずは必要なパッケージをインストールします。

apt install dropbear-initramfs

Client側でdropbear用のrsa鍵を作りid_rsa.pubをscp等でサーバに転送します。それを/etc/dropbear/initramfs/authorized_keysに書き込みます。次にinitramfs起動時に固定IPを設定します。

dropbearの設定を特にしなければsshポート22をを使いますが、設定した方が良いので変更します。

DROPBEAR_OPTIONS="-p 1234 -s -j -k -I 90"

各パラメータはmanpageを参照してください。

IP=192.168.1.128::192.168.1.1:255.255.255.0:vps-ablenet

シンタックスはip=<server-ip>::<gw-ip>:<netmask>:<hostname>です。

設定が完了したらinitramfsをアップデートします。

update-initramfs -u

リブートしてクライアント側からリモートログインしてrootfsをアンロックします。

ssh -p 1234 -o "UserKnownHostsFile=~/.ssh/known_hosts.ablenet" \
  -i "~/.ssh/id_rsa.ablenet_boot" root@192.168.1.128 \
 "echo -ne \"password_for_dm_crypt\" >/lib/cryptsetup/passfifo"

wireguard

google AIに尋ねてみると次のような回答でした。

https://www.google.com/search?q=wireguird+openrc+dsevuan&sca_esv=1fc1f57c86215af9&sxsrf=AE3TifNz7spmj-urtJ6wYPe7HeIimjQEeg%3A1767220613476&ei=haVVae3sHJ6k2roPqYuf8QY&ved=0ahUKEwitw5_n8eiRAxUeklYBHanFJ24Q4dUDCBM&uact=5&oq=wireguird+openrc+dsevuan&gs_lp=Egxnd3Mtd2l6LXNlcnAiGHdpcmVndWlyZCBvcGVucmMgZHNldnVhbjIHECEYoAEYCjIHECEYoAEYCjIHECEYoAEYCkjIGVDmBliJF3ABeACQAQGYAZICoAGbDKoBBTAuOC4xuAEDyAEA-AEBmAIIoALOCcICChAAGLADGNYEGEfCAgYQABgNGB7CAggQABgIGA0YHsICCxAAGIAEGIYDGIoFwgIFEAAY7wWYAwDiAwUSATEgQIgGAZAGCJIHBTEuNi4xoAfNJbIHBTAuNi4xuAfECcIHCTAuNS4yLjUtMcgHW4AIAA&sclient=gws-wiz-serp

#!/sbin/openrc-run
description="WireGuard Quick"
# Change 'wg0' to the name of your configuration file if different
name="wg0" 

depend() {
    need localmount
    need net
    # Might also need an explicit dependency on the physical interface if complex networking
}

start() {
    ebegin "Starting WireGuard interface ${name}"
    wg-quick up ${name}
    eend $?
}

stop() {
    ebegin "Stopping WireGuard interface ${name}"
    wg-quick down ${name}
    eend $?
}

dependファンクションのlocalmountとnetがdebianでは起動してないのでそのままだとエラーで起動できません。それなのでdbusならシステムの要であり割と遅く起動するので変更しました。

#!/sbin/openrc-run
description="WireGuard Quick"
# Change 'wg0' to the name of your configuration file if different
name="wg0"

depend() {
    #need localmount
    #need net
    need dbus
    # Might also need an explicit dependency on the physical interface if complex networking
}

start() {
    ebegin "Starting WireGuard interface ${name}"
    wg-quick up ${name}
    eend $?
}

stop() {
    ebegin "Stopping WireGuard interface ${name}"
    wg-quick down ${name}
    eend $?
}
cd /etc/init.d
ln -s wg-quick wg-quick@wg0
rc-update add wg-quick@wg0 default

shorewallもこの方法で起動した方が良いでしょう。

#!/sbin/openrc-run
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-firewall/shorewall/files/shorewall.initd,v 1.4 2013/07/13 14:09:09 constanze Exp $

command=/usr/sbin/shorewall
extra_commands="check clear"
extra_started_commands="refresh reset safe_restart"

depend() {
#	need net
	provide firewall
	after rsyslog
}

start() {
	checkpath -d -m 755 /var/lock/subsys
	ebegin "Starting shorewall"
	$command -f start 1>/dev/null
	eend $?
}

stop() {
	ebegin "Stopping shorewall"
	$command stop 1>/dev/null
	eend $?
}

safe_restart() {
	ebegin "Safely restarting shorewall"
	$command safe-restart 1>/dev/null
	eend $?
}

clear() {
	# clear will remove all the rules and bring the system to an unfirewalled
	# state. (21 Nov 2004 eldad)

	ebegin "Clearing all shorewall rules and setting policy to ACCEPT"
	$command clear
	eend $?
}

reset() {
	# reset the packet and byte counters in the firewall

	ebegin "Resetting the packet and byte counters in the shorewall"
	$command reset
	eend $?
}

refresh() {
	# refresh the rules involving the broadcast addresses of firewall
	# interfaces, the black list, traffic control rules and
	# ECN control rules

	ebegin "Refreshing shorewall rules"
	$command refresh
	eend $?
}

check() {
	# perform cursory validation of the zones, interfaces, hosts, rules
	# and policy files. CAUTION: does not parse and validate the generated
	# iptables commands.

	ebegin "Checking configuration files"
	$command check
	eend $?
}
ting system message bus: dbusdbus-daemon[1455]: Failed to start message bus: Could not get UID and GID for username "messagebus"
# groupadd -g 991 messagebus
# useradd -c 'System Message Bus' -u 991 -g messagebus -d '/nonexistent' -s /usr/sbin/nologin messagebus
useradd warning: dbus's uid 991 outside of the UID_MIN 1000 and UID_MAX 60000 range.

#!/sbin/openrc-run

description="Starts the rsyslogd enhanced system logging daemon"
command="/usr/sbin/rsyslogd"
command_args="-n"
supervisor=supervise-daemon

depend() {
	provide logger
	after bootmisc
}

LXC

ついでにコンテナのLXCでdebianとopenwrtもアップグレードしました。debianのi386のtrixieは最後のバージョンです。公式にはサポートが外れますがまだ使えるのでそのまま続行します。openwrtは安定版がv24.10.5です。サイトからrootfs.tar.gzをダウンロードして展開すればすぐ使えます。アップグレードは大きな問題はありませんが、dovecotの設定が大幅に変更になって再設定が必要です。詳しくは次のサイトにあります。

  • https://openwrt.org/docs/guide-user/virtualization/lxc
  • https://www.debian.org/releases/trixie/release-notes/issues.html

参考

  • https://www.debian.org/releases/forky/arm64/apds03.en.html
  • https://wiki.debian.org/Debootstrap
  • https://wiki.debian.org/OpenRC
  • https://wiki.debian.org/Init
  • https://www.cyberciti.biz/security/how-to-unlock-luks-using-dropbear-ssh-keys-remotely-in-linux/

Posted in Linux | Comments Off on Linux: Debian trixieのOpenRC化