Kindle 8

Kobo Touchをしばらく使っていて、どうもバッテリーの持ちが良くないようで、1日30分の読書で約15%ほどバッテリーを消耗してました。バッテリーを取り替えるのもお金がかかるし、使えないこともないので悩んでいたら、kindle 8の中古を見つけたので買ってみました。予備としてもう1台あった方が安心という意味もあるので、持っていても損はないと思います。ただ、Kobo Touchより新しいので値段が倍ぐらいしましたが、バッテリーを交換することを考えたら、仕方ないのかなと考えました。基本的に2週間に1回充電すると考えて9年前のデバイスなら、1年で約25回充電すると大体225回の充電回数なので、まだまだいける、という考え方です。

kindle 8のFWはv5.16.2.1.1なのでWinterBreakという手法でjailbreakできます。手順はサイトの通りです。ただし、KUALのインストールがうまくいかなかったので、別な方法の手動でインストールしました。

Kindle 8以後の新しいKindleはFWも新しくなり、詳しいことは知りませんが、jailbreakする手段を失うという困った問題が起きてきます。それなので、Kindle 8でよかったのだと思います。

jailbreakが済んだらKoreaderをインストールします。epub形式のe-bookが読めるので、Koboと同じ本を入れました。それと辞書もインストールしました。

同じE Ink PearlですがKIndle 8の方がコントラスト、色合いとも綺麗です。理由は分かりません。

K2pdfopt

以前、インドの旅先でもらったLPのPDFがあるのですが、これをkindleやKoboで見るのはつらかったので便利なツールを探したところ、K2pdfoptというものがありました。何通りかのやり方はあるのですが、Calibreのプラグインとして使うのが良さそうだったのでセットアップしました。実行バイナリは別途ダウンロードして実行パーミッションをつけておきます。

このツールでPDFをカスタマイズされたものを表示させてみました。行き先が決まっていれば、プリントアウトして持って行くのですが、決まっていないと分厚い本を持っていく羽目になります。

PDFの最適化までできましたが最後に一つ問題があってmetadataがunknownになっており非常に不便です。そこでmetadetaを付けるためにGoogle AIに聞いたらPythonモジュールを紹介してくれました。それを使って編集しました。ただし非常に手間がかかりますが、その作業がないとe-bookが使い物になりません。

まずCalibreでK2optpdfを稼働させて変換します。

Pythonで一括変換用のスクリプトを作りました。ExcelでCSVファイルを作り、それで変換します。

#!/usr/bin/env python3

import pikepdf
from pathlib import Path
import sys

pathname = './output'
folder_path = Path(pathname)
folder_path.mkdir(parents=True, exist_ok=True)

def edit():
    while True:
        print("Filename: ", end="")
        file = str(input())
        print("Title: ", end="")
        title = str(input())
        print("Creator: ", end="")
        creator = str(input())

        with pikepdf.open(file) as pdf:
            with pdf.open_metadata() as meta:
                meta['dc:title'] = title
                meta['dc:creator'] = ['LP']

            pdf.save(pathname + '/' + file)

        print()

def csv_edit():
    import csv
    print("CSV filename: ", end="")
    _ = str(input())

    with open(_, newline='') as csvfile:
        spamreader = csv.reader(csvfile, delimiter=',')
        iterator = iter(spamreader)
        next(iterator, None)

        for row in iterator:
            file, title, creator = row

            with pikepdf.open(file) as pdf:
                with pdf.open_metadata() as meta:
                    meta['dc:title'] = title
                    meta['dc:creator'] = ['LP']

                pdf.save(pathname + '/' + file)

    print ("done.")

if len(sys.argv) > 1 and sys.argv[1] == 'csv':
    csv_edit()
else:
    edit()

Nepal版のガイドブックももらったのですが、こちらは2ページで1画面となっていて、うまく変換できません、そこでPDFを分割するツールがあるのでそれを使います。

brew install mupdf-tools
mkdir output
ls *.pdf | while read n; do mutool poster -x 2 "$n" ./output/"$n" ; done

先頭に白紙が出る場合は次のコマンドで取り除きます。

mutool clean input.pdf output.pdf 2-N
  • https://askubuntu.com/questions/56853/splitting-a-pdf-page-in-two

Screensaver

必須ではありませんがお気に入りのスクリーンサイバーを設定しました。Koboの場合は.koboのディレクトリの中にscreensaverを作りその中にイメージファイルを入れます。複数あるとランダムに表示してくれます。Kindleの場合は、linkssというプログラムをインストールします。イメージがPNGのみとのことなのでイメージアプリで変換します。

gm convert -size 600x800 -background white -depth 8 -resize 600x800 -colorspace gray -type palette -geometry 600x800 Homebody-Club.jpg Homebody-Club.png

Koboの方がいろんな画像フォーマットに対応しているので見栄えは良いです。

refocus_ok

滑り止め

Kindleの背面はプラスチックで滑ります。すでに何度か滑らせて落としているので滑り止めをつけてみました。当初養生テープにしようかと思っていたのですが、ダイソーでスキージーのフェルトが使えそうなので使ってみました。

Posted in e-book, kindle | Comments Off on Kindle 8

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>

LXC

OpenWrtのLXCのauto startが特殊でやり方は次のとおりです。

opkg install lxc-auto lxc-autostart
uci show lxc-auto
uci add lxc-auto container
uci set lxc-auto.@container[-1].name=myLMS
uci set lxc-auto.@container[-1].timeout=30
uci show lxc-auto
uci commit lxc-auto
  • https://openwrt.org/lxc_openwrt_host
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のセットアップ

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

user www-data;
worker_processes auto;
worker_cpu_affinity auto;
pid /run/nginx.pid;

#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       80 reuseport fastopen=10;
        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 / {

            proxy_pass http://0.0.0.0:2628;

            proxy_redirect     default;
            proxy_set_header Host $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_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
python3 server.py 0.0.0.0:2628
WARNING:app.langs:No spellchecking library found.
INFO:app.dictionaries:Dictionaries loaded.
INFO:waitress:Serving on http://0.0.0.0:2628
WARNING:waitress.queue:Task queue depth is 1
WARNING:waitress.queue:Task queue depth is 1
INFO:app.settings:Found dictionary 1911-and-1922-Encyclopedia-Britannica (/root/.silverdict/source/1911-and-1922-Encyclopedia-Britannica/1911-and-1922-Encyclopedia-Britannica.ifo) during re-scanning.
INFO:app.dicts.stardict_reader:Entries of dictionary __1911-and-1922-E added to database
INFO:app.dictionaries:Added dictionary __1911-and-1922-E
INFO:app.settings:Found dictionary CALD4 (/root/.silverdict/source/Cambridge/CALD_4th/CALD4.mdx) during re-scanning.
INFO:app.dicts.mdict_reader:Entries of dictionary __CALD4 added to database
INFO:app.dictionaries:Added dictionary __CALD4
INFO:app.settings:Found dictionary Oxford English Dictionary (/root/.silverdict/source/Oxford/Oxford English Dictionary.mdx) during re-scanning.
INFO:app.dicts.mdict_reader:Entries of dictionary __OxfordEnglish added to database
INFO:app.dictionaries:Added dictionary __OxfordEnglish
INFO:app.settings:Found dictionary New Oxford Dictionary of English (/root/.silverdict/source/Oxford/New Oxford Dictionary of English.mdx) during re-scanning.
INFO:app.dicts.mdict_reader:Entries of dictionary __NewOxfordDict added to database
INFO:app.dictionaries:Added dictionary __NewOxfordDict

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

音声の問題

CALD4は発音もできるのですがspeexという規格でGoldendictなどのアプリからは再生できますがWeb上ではできませんでした。調べてみるとhtml5の仕様ではSpeex(.spx)はサポートしてないため再生できないようです。そこでさらに調べたのですが,speex.jsを使って再生するというやり方だとfunctionを組み込まないとならず、結構ややっこしくなるので、speexをmp3に変換することになりました。

やり方はmdict-utilsをインストールしてmdictコマンドでアンパックし、sedで一発変換し、再パックするというやり方です。

  • https://pypi.org/project/mdict-utils/

こんな感じです。今度は音声がいきなり再生するので、微妙な感じになりました。

Google AIによると、

The snippet html href="sound:" is incomplete and not valid HTML for playing sound. In HTML, the href attribute is used for hyperlinks to link to other web pages or resources, not to directly embed and play audio in the current document using a special “sound:” protocol. 

To embed and play audio, you should use the HTML5 <audio> element with the src attribute or nested <source> elements.

正規のフォーマットじゃないのでということでお手上げです。

音声を再生させないようにするにはブラウザの設定でサウンドをオフにします。

OpneWrtの設定

autoスタートの方法を調べてみました。

lxc.start.auto = 1
lxc.group = onboot

lxc.groupは必要かどうかわかりませんが一応、設定しておきました。

apk update
apk add lxc-start lxc-stop lxc-create lxc-attach lxc-destroy lxc-config lxc-ls getopt
apk add luci-app-lxc
apk add lxc-auto lxc-autostart
uci add lxc-auto container
cfg01cd88
uci set lxc-auto.@container[-1].name=silverdict
uci set lxc-auto.@container[-1].timeout=30
uci show lxc-auto
lxc-auto.@container[0]=container
lxc-auto.@container[0].name='silverdict'
lxc-auto.@container[0].timeout='30'
uci commit lxc-auto
reboot

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に接続してインストールするとファームウェアも同時にアップデートされるので注意が必要です。Koreaderの辞書は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 アップデート