ラベル Debian の投稿を表示しています。 すべての投稿を表示
ラベル Debian の投稿を表示しています。 すべての投稿を表示

2024年10月7日月曜日

Debian 12 上に Gleam 言語の環境を構築する

この記事はなに?

何か理由があって Gleam を試そうと思って環境構築を行った。

理由を忘れてしまったのでブログにだけはしておこうと思った。

前提

Debian on Docker on Ubuntu on WSL2 on Windows 環境で実施している。

  • OS: Windows 11 Pro 23H2 ビルド 22631.4169
  • Docker: Docker version 27.3.1, build ce12230
  • コンテナイメージ: debian:12-slim

Gleam のインストールに必要なパッケージのインストール

apt update
apt install -y \
    curl \
    gnupg2

Gleam のインストール

GLEAM_VERSION=v1.5.1

curl -LO https://github.com/gleam-lang/gleam/releases/download/${GLEAM_VERSION}/gleam-${GLEAM_VERSION}-x86_64-unknown-linux-musl.tar.gz
mkdir -p /opt/gleam/bin
tar xfv gleam-${GLEAM_VERSION}-x86_64-unknown-linux-musl.tar.gz -C /opt/gleam/bin
PATH=$PATH:/opt/gleam/bin
rm gleam-${GLEAM_VERSION}-x86_64-unknown-linux-musl.tar.gz

Erlang のインストール

curl https://binaries2.erlang-solutions.com/GPG-KEY-pmanager.asc -o /usr/share/keyrings/pmanager.gpg
apt-key add /usr/share/keyrings/pmanager.gpg

cat << EOF > /etc/apt/sources.list.d/erlang.sources
Types: deb
URIs: http://binaries2.erlang-solutions.com/ubuntu/
Suites: jammy-esl-erlang-25
Components: contrib

Types: deb
URIs: http://binaries2.erlang-solutions.com/debian/
Suites: bullseye-elixir-1.15
Components: contrib

Types: deb
URIs: http://binaries2.erlang-solutions.com/ubuntu/
Suites: bionic-mongooseim-6
Components: contrib
EOF

apt update
apt install -y esl-erlang

Gleam プロジェクトの作成・動作確認

gleam new helloworld
cd helloworld
gleam run

OK.

参考資料

2022年5月1日日曜日

Debian bullseye に SATySFi をインストールする

後々 Dockerfile に落とし込んで Che で実行するのを見越して、 /opt 下にインストールする。

コンテナ起動

docker run -it --rm --name satysfi debian:bullseye-slim

必須パッケージのインストール

apt update
apt install -y \
    bzip2 \
    curl \
    gcc \
    git \
    make \
    patch \
    rsync \
    unzip \
    wget

OPAM インストール

mkdir -p /opt/opam/bin
curl -L "https://github.com/ocaml/opam/releases/download/2.1.2/opam-2.1.2-$(uname -m)-linux" -o /opt/opam/bin/opam
chmod +x /opt/opam/bin/opam
export PATH=$PATH:/opt/opam/bin

ユーザー作成

useradd -m -s /bin/bash satysfi
su - satysfi
export PATH=$PATH:/opt/opam/bin

OPAM 設定

opam init -y --disable-sandboxing --comp 4.10.0

eval $(opam env)

opam repository add satysfi-external https://github.com/gfngfn/satysfi-external-repo.git
opam update

SATySFi ビルド

# ソース取得
git clone https://github.com/gfngfn/SATySFi.git
cd SATySFi

# ビルド
opam pin add -y satysfi .
opam install -y satysfi

# フォントのダウンロード・配置
bash ./download-fonts.sh
bash ./install-libs.sh

cd ..
rm -rf SATySFi

参考資料

2021年11月7日日曜日

WSL2 で Debian 11 (Bullseye) を使う

/etc/apt/sources.list を修正して、 apt update, apt full-upgrade するのが楽かもしれない。

しかし、WSL2 のルートファイルシステムも Docker と同じ感じて作れるようなので、 Bullseye のルートファイルシステムを作って WSL2 へインポートしてみる。

前提

  • ゲスト OS: Ubuntu 20.04(WSL2)
  • Docker: Docker version 20.10.8, build 3967b7d

Debian 11 のルートファイルシステム作成

Docker コンテナ起動

debootstrap して作成したルートファイルシステムを Windows に持っていけるように、ボリュームをマウントしつつ Debian コンテナを起動。

PowerShell 上で、以下コマンドを実行。

docker run -it --rm -v "$(pwd):/work" --workdir "/work" -name debian debian:buster-slim

以降、起動した Debian コンテナ上でルートファイルシステムを作成していく。

必要パッケージのインストール

apt-get update
apt-get install -y debootstrap

debootstrap 実行

debootstrap で Debian 11 のルートファイルシステムを作成し、 tar で固める -> Windows へ渡すため、マウントしたフォルダへコピー。

cd
debootstrap bullseye ./bullseye http://deb.debian.org/debian
cd bullseye/
tar cfv ../debian-bullseye.tar .
cp ../debian-bullseye.tar /work

作成したら Debian コンテナはもう使わないので、停止。

WSL2 に Debian 11 をインポート

WSL2 ディストリビューションのディスク格納フォルダを作って、そこにインポートする。

PowerShell 上で以下コマンドを実行。

New-Item -ItemType Directory -p $HOME\wsl\debian\bullseye
wsl --import Debian-11 $HOME\wsl\debian\bullseye\ .\debian-bullseye.tar

Debian 11 の環境構築

Debian 11 のディストリビューション起動

PowerShell 上で以下コマンドを実行。

wsl -d Debian-11

Debian のアップグレードと必須パッケージインストール

アップグレードして sudo をインストールする。

起動した WSL 上で以下コマンドを実行。

apt-get update
apt-get upgrade -y
apt-get install -y sudo

一般ユーザー追加・設定

一般ユーザーを追加し、パスワード設定と sudo グループへの追加を行う。

useradd -m -s /bin/bash mikoto
passwd mikoto
gpasswd -a mikoto sudo

apt ソースリストの更新

適当に更新。

cat << EOF > /etc/apt/sources.list
deb http://ftp.jp.debian.org/debian/ bullseye main contrib non-free
deb-src http://ftp.jp.debian.org/debian/ bullseye main contrib non-free

deb http://ftp.jp.debian.org/debian/ bullseye-updates main contrib non-free
deb-src http://ftp.jp.debian.org/debian/ bullseye-updates main contrib non-free

deb http://security.debian.org/ bullseye-security main
deb-src http://security.debian.org/ bullseye-security main
EOF

デフォルトユーザー設定

/etc/wsl.conf を更新し、WSL2 起動時に追加した一般ユーザーでログインする設定を行う。

cat << EOF > /etc/wsl.conf
[user]
default=mikoto
EOF

WSL2 再起動

これで、追加したユーザー(今回は mikoto) でログインした状態で Debian 11 が起動する。

Debian をログアウトして、 PowerShell 上で以下コマンドを実行する。

wsl -t Debian-11
wsl -d Debian-11

バージョン確認

/etc/os-release で、 Debian 11 がインストールされていることを確認する。

再起動後の Debian 上で、以下コマンドを実行・確認する。

mikoto@DESKTOP-CO13JB2:~$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

以上、あとはよしなに。

参考資料

更新履歴

日付 更新内容
2021/11/7 新規作成
2021/11/10 sources.list の内容が適当すぎたので修正。
あわせて参考資料を追加。

2021年5月14日金曜日

deb パッケージを更新する

前回 Athrill2 の deb パッケージを作成した。

今回はそれの更新手順をメモ。

コンテナ起動

cd /PATH/TO/athrill-deb
docker run -it --rm --workdir "/work" ubuntu:20.04

必要なパッケージインストールと設定

# deb パッケージビルドに必要な環境変数を設定
export DEBFULLNAME="mikoto2000"
export DEBMAIL=mikoto2000@gmail.com
export LONGNAME="mikoto2000"
export USER="mikoto2000"

# tzdata の configuration が走るので、 Azia/Tokyo を選択して(Geographic area: 6, Time zone: 79)
export TZ=Asia/Tokyo
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 必要なパッケージのインストール
apt-get update
apt-get install -y gcc make git-buildpackage cdbs vim

git config --global user.name "mikoto2000"
git config --global user.email "mikoto2000@gmail.com"

リポジトリクローン

git clone --depth 1 --recurse-submodule https://github.com/mikoto2000/athrill-target-rh850f1x-deb.git

ビルド

cd athrill-target-rh850f1x-deb
BUILD_TIME=$(date "+%Y%m%e%H%M%S")
git checkout -b ${BUILD_TIME}
gbp buildpackage -us -uc --git-pristine-tar --git-pristine-tar-commit --git-tag --git-ignore-new --git-upstream-tag=${BUILD_TIME} -b

以上。

2021年3月24日水曜日

Debian 11 で Rootless Podman を試す

Debian 11 だと apt でインストールできるようなので、それでサクッと試す。

前提条件

Podman のインストール

pull 時に TLS 通信が使われるので、 ca-certificates もインストールする。

sudo apt-get update
sudo apt-get install -y podman ca-certificates

とりあえず rootfull で podman が実行できることを確認。

mikoto@debian:~$ sudo podman run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

OK.

Rootless のための準備

一般ユーザーが名前空間を作成できるようにカーネルパラメーターを更新。

sudo bash -c 'echo "user.max_user_namespaces=28633" > /etc/sysctl.d/userns.conf'
sudo sysctl -p /etc/sysctl.d/userns.conf

この後作成するユーザーについては、rootless podman を実行するための設定が有効になる。

現在のログインユーザーが、名前空間を作成できるようにするためには、マシンの再起動が必要。 (他に方法があると思うが、今回再ログインでもダメだったので再起動した…)

動作確認

mikoto@debian:~$ podman run hello-world
Resolved "hello-world" as an alias (/etc/containers/registries.conf.d/shortnames.conf)
Trying to pull docker.io/library/hello-world:latest...
Getting image source signatures
Copying blob b8dfde127a29 done
Copying config d1165f2212 done
Writing manifest to image destination
Storing signatures

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

以上。

参考資料

2021年1月31日日曜日

qemu-system-arm で Debian buster armhf を動かす

Debian installer を使って、 Debian buster armhf をインストールする。

前提

必要ファイルのダウンロード

インストーラー起動用の vmlinuz と initrd をダウンロード。

Invoke-WebRequest http://ftp.debian.org/debian/dists/buster/main/installer-armhf/current/images/netboot/initrd.gz -OutFile initrd.gz
Invoke-WebRequest http://ftp.debian.org/debian/dists/buster/main/installer-armhf/current/images/netboot/vmlinuz -OutFile vmlinuz

qemu-system-arm インストール済みのコンテナを起動

mount コマンドを利用するので、 --privileged オプション付きで起動する。

docker run -it --rm --privileged -v "$(pwd):/work" --workdir="/work" mikoto2000/qemu-system-arm

インストール

ディスクイメージ作成

qemu-img create -f qcow2 hda.qcow2 8G

インストーラー起動

qemu-system-arm -M virt -m 1024 \
  -kernel vmlinuz \
  -initrd initrd.gz \
  -drive if=none,file=hda.qcow2,format=qcow2,id=hd \
  -device virtio-blk-device,drive=hd \
  -netdev user,id=usernet \
  -device virtio-net-device,netdev=usernet \
  -nographic -no-reboot

Debian インストーラーに従ってインストールを行う。

起動用ファイルをディスクイメージから抜き出す

Debian をインストールした qcow2 を raw へ変換

qemu-img convert -O raw hda.qcow2 hda.img

イメージをマウントし、 vmlinuz と initrd をコピー

マウントオフセット確認

START=$(fdisk -l hda.img | grep "*" | grep "hda.img" | awk '{print $3}')
OFFSET=$(($START*512))

マウント

mkdir ./tmp
mount -o loop,offset=$OFFSET hda.img ./tmp

ファイルコピー

cp ./tmp/vmlinuz-4.19.0-13-armmp-lpae ./
cp ./tmp/initrd.img-4.19.0-13-armmp-lpae ./

マウント解除

umount ./tmp

インストールした Debian の起動

コピーした vmlinuz と initrd を使って Debian を起動する。

qemu-system-arm -M virt -m 1024 \
  -kernel vmlinuz-4.19.0-13-armmp-lpae \
  -initrd initrd.img-4.19.0-13-armmp-lpae \
  -drive if=none,file=hda.qcow2,format=qcow2,id=hd \
  -device virtio-blk-device,drive=hd \
  -netdev user,id=usernet \
  -device virtio-net-device,netdev=usernet \
  -append "root=/dev/vda2" \
  -nographic -no-reboot

以上。

参考資料

2020年12月1日火曜日

textlint と prh, RedPen で日本語文章をチェックする

前提

  • OS: Windows 10 Pro
  • Docker: Docker version 19.03.13, build 4484c46d9d
  • 使用する Docker イメージ
    • node:15
    • openjdk:8

チェック対象テキストは content.md。内容は以下。

Eclipse  Che のワークスペースの生成・破棄は、Linux コンテナ技術によって実現されている。そのため、ワークスペースで使用するツールは、64bit Linux 環境で動作する必要がある。TOPPERS で公開されているコンフィギュレータ(https://toppers.jp/cfg.html)は、64bit Linux環境に対応していないため、今回はTOPPERS/cfg に64bit Linux 対応の修正を行い、それを利用した(mikoto2000/cfg-1v1.9.7.2)。

textlint で日本語チェック

以下のプラグインを使ってチェックを行う。

Docker コンテナ起動

docker run -it -v "$(pwd):/work" --workdir "/work" node:15 bash

環境構築

npm install -g textlint
npm install -g @textlint/textlint-plugin-markdown

npm install -g prh
npm install -g textlint-rule-prh
npm install -g textlint-rule-preset-ja-technical-writing
npm install -g textlint-rule-preset-jtf-style

設定ファイル作成

重複など気にせず、とにかく何でもかんでも指摘させる設定になっている(はず)なので、要調整。

設定内容の詳細は各プラグインのドキュメントを参照。

最低でも ./rules/media/techbooster.yml, ./rules/media/WEB+DB_PRESS.yml はどちらかひとつにするのが良いはず。

# prh のリファレンス(?)ルール取得
git clone --depth 1 https://github.com/prh/rules.git

# prh の設定
cat - << EOF > ./prh.yml
version: 1

imports:
  - ./rules/media/techbooster.yml
  - ./rules/media/WEB+DB_PRESS.yml
EOF

# textlint の設定
cat - << EOF > ./.textlintrc
{
    "plugins": {
        "@textlint/markdown": {
            "extensions": [".md"]
        }
    },
    "rules": {
        "prh": {
            "rulePaths" :["./prh.yml"]
        },
        "preset-ja-technical-writing": true
    }
}
EOF

textlint 実行

textlint --no-color "content.md" -o lint_results.txt

lint_results.txt に、指摘点が列挙される。


/work/content.md
  1:101  error    Line 1 sentence length(151) exceeds the maximum sentence length of 100.
Over 51 characters   ja-technical-writing/sentence-length
  1:225  ✓ error  (mikoto2000/cfg-1v1.9.7.2) => (mikoto2000/cfg-1v1.9.7.2)
半角カッコの代わりに全角カッコを使うこと。文字のバランスが崩れるためです  prh

✖ 2 problems (2 errors, 0 warnings)
✓ 1 fixable problem.
Try to run: $ textlint --fix [file]

RedPen

Docker コンテナ起動

docker run -it --rm -v "$(pwd):/work" --workdir "/work" openjdk:8 bash

環境構築

curl -L -O https://github.com/redpen-cc/redpen/releases/download/redpen-1.10.4/redpen-1.10.4.tar.gz
tar xf redpen-1.10.4.tar.gz
export PATH=$PATH:$(pwd)/redpen-distribution-1.10.4/bin/

redpen 実行

redpen -f markdown -L ja ./content.md > redpen_results.txt

redpen_results.txt に、指摘が列挙される。

./content.md:1: ValidationError[SentenceLength], 文長("151")が最大値 "100" を超えています。 at line: TOPPERS で公開されているコンフィギュレータ(https://toppers.jp/cfg.html)は、64bit Linux環境に対応していないため、今回はTOPPERS/cfg に64bit Linux 対応の修正を行い、それを利用した(mikoto2000/cfg-1v1.9.7.2)。
./content.md:1: ValidationError[JapaneseAmbiguousNounConjunction], 助詞「の」が連続しています: "〜Eclipseのワークスペースの生成〜" at line: Eclipse Che のワークスペースの生成・破棄は、Linux コンテナ技術によって実現されている。
./content.md:1: ValidationError[InvalidSymbol], 不正なシンボル "(" がみつかりました。 at line: TOPPERS で公開されているコンフィギュレータ(https://toppers.jp/cfg.html)は、64bit Linux環境に対応していないため、今回はTOPPERS/cfg に64bit Linux 対応の修正を行い、それを利用した(mikoto2000/cfg-1v1.9.7.2)。
./content.md:1: ValidationError[InvalidSymbol], 不正なシンボル ")" がみつかりました。 at line: TOPPERS で公開されているコンフィギュレータ(https://toppers.jp/cfg.html)は、64bit Linux環境に対応していないため、今回はTOPPERS/cfg に64bit Linux 対応の修正を行い、それを利用した(mikoto2000/cfg-1v1.9.7.2)。
./content.md:1: ValidationError[SpaceBetweenAlphabeticalWord], アルファベット単語の後にスペースが存在しません。 at line: TOPPERS で公開されているコンフィギュレータ(https://toppers.jp/cfg.html)は、64bit Linux環境に対応していないため、今回はTOPPERS/cfg に64bit Linux 対応の修正を行い、それを利用した(mikoto2000/cfg-1v1.9.7.2)。
./content.md:1: ValidationError[SpaceBetweenAlphabeticalWord], アルファベット単語の前にスペースが存在しません。 at line: TOPPERS で公開されているコンフィギュレータ(https://toppers.jp/cfg.html)は、64bit Linux環境に対応していないため、今回はTOPPERS/cfg に64bit Linux 対応の修正を行い、それを利用した(mikoto2000/cfg-1v1.9.7.2)。

後は、それぞれの Docker イメージを作ってサクッと実行できるようにしたうえで、設定を詰めていけばいい感じになりそう。

以上。

参考資料

2020年11月12日木曜日

Debian に H2 データベースをインストールして Web コンソールから SQL を発行する

前提

  • OS: Windows 10 Pro
  • Docker: Docker version 19.03.13, build 4484c46d9d
  • 使用イメージ: debian:buster-slim

Docker コンテナ起動

docker run -it --rm -p "8082:8082" debian:buster-slim

インストール

# 必要なツール群インストール
mkdir -p /usr/share/man/man1
apt-get update
apt-get install -y curl unzip openjdk-11-jdk-headless

# ファイル一式をダウンロードして /opt/h2 へ配置する
curl -l -O https://h2database.com/h2-2019-10-14.zip
unzip h2-2019-10-14.zip
mv h2 /opt/
chmod u+x /opt/h2/bin/h2.sh
rm -rf h2-2019-10-14.zip

# パスを通す
export PATH=$PATH:/opt/h2/bin

データベース作成

データベースファイルは org.h2.tools.Shell の初回接続時に自動生成されるので、とりあえず空の SQL を発行する。

java -cp /opt/h2/bin/h2-1.4.200.jar org.h2.tools.Shell -url jdbc:h2:~/h2db_data -driver org.h2.Driver -user sa -password "" -sql ""

サーバー起動

web コンソールを有効化してサーバーを起動する。

/opt/h2/bin/h2.sh -webAllowOthers

Web コンソールで接続

ここまで来たら、ホストのブラウザで http://localhost:8082 に接続する。

Web コンソールが開くので、各項目に以下の通り入力し、 接続 ボタンを押下。

  • ドライバクラス: org.h2.Driver
  • JDBC URL: jdbc:h2:~/h2db_data
  • ユーザ名: sa
  • パスワード: (空)

h2db_data は、 データベース作成 で作成したデータベース名。

あとはテキストエリアに SQL 入れて実行するだけ。

以上。

参考資料

2020年10月5日月曜日

Reprepro で APT リポジトリを構築する

前々回, 前回 と、deb パッケージを作ったので、これを公開する APT リポジトリを作っていく。

コンテナ起動

docker run -it --rm -v "$(pwd):/work" --workdir="/work" debian:buster-slim

APT リポジトリの構築

必須パッケージのインストール

apt-get update
apt-get install -y gnupg2 reprepro

署名用の鍵生成

鍵生成の設定ファイル作成

gpg --full-generate-key
  1. Please select what kind of key you want : `(1) RSA and RSA (default)`
  2. What keysize do you want? (3072) : 4096
  3. Please specify how long the key should be valid. : 0
  4. Is this correct? (y/N) : y
  5. Real name : mikoto2000
  6. Email address : mikoto2000@gmail.com
  7. Comment : Athrill apt repository key.
  8. Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? : O
  9. Passphrase : (空)

鍵の ID をメモしておく。

(今回は 6B5F3367A3F74C173E2E83612F6719AE3DEFC0C0 だった。)

リポジトリ設定

リポジトリ設定格納用ディレクトリの作成

mkdir -p /work/reprepro/conf

リポジトリ設定作成

/work/reprepro/conf/distributions

cat <<EOF> /work/reprepro/conf/distributions
Origin: TOPPERS/hakoniwa
Label: Athrill
Codename: bionic
Architectures: amd64
Components: main
Description: Apt repository for project Athrill
SignWith: 6B5F3367A3F74C173E2E83612F6719AE3DEFC0C0
EOF
  • Codename : ディストリビューションのコードネーム。bionic だったり buster だったり
  • SignWith : gpg コマンドで作成した公開鍵の ID

パッケージの取り込み

cd /work/reprepro
reprepro includedeb bionic /work/athrill-rh850f1x_0.A.0-1_amd64.deb

署名の設定

cd /work/reprepro
gpg --armor --output athrill.gpg.key --export 6B5F3367A3F74C173E2E83612F6719AE3DEFC0C0

動作確認

Web サーバーを立ててそこからインストールしてみる。

APT リポジトリとなる nginx 起動

新しく nginx のコンテナを立てる。

先ほど作成した reprepro ディレクトリを /usr/share/nginx/html にマウントする。

docker run -it --rm -v "$(pwd)/reprepro:/usr/share/nginx/html:ro" -p "80:80" --name nginx nginx

※ 実際は、 db/, conf/ は見えないようにするらしい

正しくインストールできるか確認

先ほど立ち上げた nginx から、正しく apt でインストールできるかを確認する。

新たに debian:buster-slim のコンテナを立ち上げて、 host.docker.internal の APT リポジトリを登録する。

インストールする debian の起動

docker run -it --rm ubuntu:18.04

必要パッケージインストール

apt-get update
apt-get install -y curl gnupg2 software-properties-common

APT リポジトリのキー登録

curl -fsSL http://host.docker.internal/athrill.gpg.key | apt-key add -

APT リポジトリ登録

add-apt-repository "deb http://host.docker.internal bionic main"
apt-get update

インストール

apt-get install -y athrill-rh850f1x

鍵の管理

このままだと、コンテナ終了時に秘密鍵も消えてしまうので、コンテナからエクスポートしてコピーすること。

鍵のエクスポート

cd /
gpg --list-secret-keys
gpg --export-secret-keys --output backup.sec.key mikoto2000@gmail.com
gpg --export --output backup.pub.key mikoto2000@gmail.com

鍵のインポート

gpg --import ./backup.sec.key
gpg --import ./backup.pub.key

参考資料

2020年10月4日日曜日

Athrill2 の deb パッケージ作成を git-buildpackage で管理する

前回、 Athrill の deb パッケージ作成手順を確立したので、今回はそれを git-buildpackage で管理するための手順を確認する。

作業用コンテナ立ち上げ

cowbuilder 実行の権限を渡すために --privileged オプションを付けてコンテナ起動。

docker run -it --rm -v "$(pwd):/work" --workdir="/work" --privileged ubuntu:18.04

deb パッケージの作成に必要な環境を構築

# deb パッケージビルドに必要な環境変数を設定
export DEBFULLNAME="mikoto2000"
export DEBMAIL=mikoto2000@gmail.com
export LONGNAME="mikoto2000"
export USER="mikoto2000"

# tzdata の configuration が走るので、 Azia/Tokyo を選択して(Geographic area: 6, Time zone: 79)
export TZ=Asia/Tokyo
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 必要なパッケージのインストール
apt-get update
apt-get install -y build-essential dh-make git-buildpackage fakeroot devscripts pbuilder cdbs git vim cowbuilder

git config --global user.name "mikoto2000"
git config --global user.email "mikoto2000@gmail.com"

deb パッケージビルドに必要なファイル群の取得・生成

# deb パッケージ用のディレクトリ作成
mkdir athrill-rh850f1x
cd athrill-rh850f1x
git init
git commit --allow-empty -m 'Initial commit.'

# オリジナルのソースコード取得
git submodule add https://github.com/toppers/athrill.git
git submodule add https://github.com/toppers/athrill-target-rh850f1x.git
git commit -m 'Added upstream sources.'

# 作業用ブランチ作成
git checkout -b add_debian_directory

# deb パッケージに必要なファイル群を生成
dh_make --createorig -s -e ${DEBMAIL} -p athrill-rh850f1x_0.A.0 -y
git add debian
git commit -m 'Added debian directory.'

# サンプルファイル類削除
rm -rf debian/*.ex
rm -rf debian/*.EX
rm -rf debian/README.*
rm -rf debian/athrill-rh850f1x-docs.docs

メタデータ編集

debian/control

Source: athrill-rh850f1x
Section: misc
Priority: optional
Maintainer: kanetugu2015 <kanetugu2015@gmail.com>
Bugs: https://github.com/toppers/athrill-target-rh850f1x
Build-Depends: cdbs, debhelper (>= 10)
Standards-Version: 4.1.2
Homepage: https://github.com/toppers/athrill-target-rh850f1x

Package: athrill-rh850f1x
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Athrill emulator for RH850F1x.
 Athrill core version: 1.1.1

コピーライト修正

debian/copyright

TOPPERS ライセンスに修正。

Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: athrill-terget-rh850f1x
Source: https://github.com/toppers/athrill-target-rh850f1x

Files: *
Copyright: 2019 by Center for Embedded Computing Systems
                     Graduate School of Informatics, Nagoya Univ., JAPAN
           2019 by ESM, Inc.
License: TOPPERS License
 上記著作権者は,以下の (1)〜(4) の条件を満たす場合に限り,本ソフトウェ
 ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改変・
 再配布(以下,利用と呼ぶ)することを無償で許諾する.
 (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作権
     表示,この利用条件および下記の無保証規定が,そのままの形でソース
     コード中に含まれていること.
 (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使用
     できる形で再配布する場合には,再配布に伴うドキュメント(利用者マ
     ニュアルなど)に,上記の著作権表示,この利用条件および下記の無保
     証規定を掲載すること.
 (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使用
     できない形で再配布する場合には,次のいずれかの条件を満たすこと.
   (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著作
       権表示,この利用条件および下記の無保証規定を掲載すること.
   (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに報
       告すること.
 (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損害
     からも,上記著作権者およびTOPPERSプロジェクトを免責すること.また,
     本ソフトウェアのユーザまたはエンドユーザからのいかなる理由に基づ
     く請求からも,上記著作権者およびTOPPERSプロジェクトを免責すること.

 本ソフトウェアは,無保証で提供されているものである.上記著作権者およ
 びTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的に対す
 る適合性も含めて,いかなる保証も行わない.また,本ソフトウェアの利用
 により直接的または間接的に生じたいかなる損害に関しても,その責任を負
 わない.

ビルドスクリプト修正

debian/rules

#!/usr/bin/make -f
include /usr/share/cdbs/1/rules/debhelper.mk

install/athrill-rh850f1x::
    install -pd $(DEB_DESTDIR)/usr/bin
    install -pm 755 athrill/bin/linux/athrill2 $(DEB_DESTDIR)/usr/bin/athrill2-rh850f1x
    install -pd athrill-target-rh850f1x/params/rh850f1k/* $(DEB_DESTDIR)/usr/share/doc/athrill/params/rh850f1k

build/athrill-rh850f1x::
    cd athrill-target-rh850f1x/build_linux; make

バイナリファイルのホワイトリスト作成

debian/source/include-binaries

athrill/bin/linux/athrill2

changelog を修正

debian/changelog

athrill-rh850f1x (0.A.0-1) unstable; urgency=medium

  * Initial release.

 -- mikoto2000 <mikoto2000@gmail.com>  Sun, 04 Oct 2020 10:14:22 +0900

メンテナースクリプトの作成

debian/postinst

インストール後に、 update-alternativesathrill2 コマンドを登録

update-alternatives --install /usr/bin/athrill2 athrill2 /usr/bin/athrill2-rh850f1x 10

debian/prerm

アンインストール前に、 update-alternatives で登録した athrill2 設定を削除

update-alternatives --install /usr/bin/athrill2 athrill2 /usr/bin/athrill2-rh850f1x 10

修正をコミット

git add .
git commit -m 'Update debian directory for athrill.'
dpkg-source --commit

ビルド

cowbuilder でクリーンなビルド環境を作って、その中でビルド。

# ビルド環境を作る
cowbuilder --create --basepath /var/cache/pbuilder/bionic.cow --distribution bionic

# ビルド
gbp buildpackage -us -uc --git-pristine-tar-commit --git-pbuilder --git-pbuilder-options=" --basepath /var/cache/pbuilder/bionic.cow --source-only-changes" --git-tag --git-ignore-new --git-upstream-tag=add_debian_directory
  • add_debian_directory: deb パッケージを作る際の元ネタに使うブランチを指定

ビルドが実行され、以下 3 つが生成される。

  • athrill_0.A.0-1_amd64.deb
  • タグ debian/0.A.0-1
  • ブランチ pristine-tar

マージ, push

  1. add_debian_directorymaster へマージ(GitHub なら Pull Request 出したり)
  2. リモートリポジトリがあるならタグ・ブランチを push
    • debian/0.A.0-1
    • pristine-tar

この作業で作ったリポジトリが以下。

mikoto2000/athrill-target-rh850f1x-deb: athrill-target-rh850f1x deb package.

おまけ

以上。

参考資料

2020年9月25日金曜日

Athrill2 の deb パッケージを作成する

deb パッケージの作成に必要な環境を構築

# deb パッケージビルドに必要な環境変数を設定
export DEBFULLNAME="mikoto2000"
export DEBMAIL=mikoto2000@gmail.com
export LONGNAME="mikoto2000"
export USER="mikoto2000"

# 必要なパッケージのインストール
apt-get update
apt-get install -y build-essential dh-make fakeroot devscripts pbuilder cdbs git vim

deb パッケージビルドに必要なファイル群の取得・生成

# deb パッケージ用のディレクトリ作成
mkdir athrill
cd athrill

# オリジナルのソースコード取得
git clone --recurse-submodules https://github.com/toppers/athrill.git
git clone --recurse-submodules https://github.com/toppers/athrill-target-rh850f1x.git

# deb パッケージに必要なファイル群を生成
dh_make --createorig -s -e ${DEBMAIL} -p athrill_2.0.0

# サンプルファイル類削除
rm -rf debian/*.ex
rm -rf debian/*.EX

メタデータ編集

debian/control

Source: athrill
Section: misc
Priority: optional
Maintainer: kanetugu2015 <kanetugu2015@gmail.com>
Bugs: https://github.com/toppers/athrill-target-rh850f1x
Build-Depends: debhelper (>= 10)
Standards-Version: 4.1.2
Homepage: https://github.com/toppers/athrill-target-rh850f1x

Package: athrill
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Athrill emulator for RH850F1x.

コピーライト修正

debian/copyright

TOPPERS ライセンスに修正。

Format:  http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: athrill
Source: https://github.com/toppers/athrill-target-rh850f1x

Files: *
Copyright: 2019 by Center for Embedded Computing Systems
                     Graduate School of Informatics, Nagoya Univ., JAPAN
           2019 by ESM, Inc.
License: TOPPERS License
 上記著作権者は,以下の (1)〜(4) の条件を満たす場合に限り,本ソフトウェ
 ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改変・
 再配布(以下,利用と呼ぶ)することを無償で許諾する.
 (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作権
     表示,この利用条件および下記の無保証規定が,そのままの形でソース
     コード中に含まれていること.
 (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使用
     できる形で再配布する場合には,再配布に伴うドキュメント(利用者マ
     ニュアルなど)に,上記の著作権表示,この利用条件および下記の無保
     証規定を掲載すること.
 (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使用
     できない形で再配布する場合には,次のいずれかの条件を満たすこと.
   (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著作
       権表示,この利用条件および下記の無保証規定を掲載すること.
   (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに報
       告すること.
 (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損害
     からも,上記著作権者およびTOPPERSプロジェクトを免責すること.また,
     本ソフトウェアのユーザまたはエンドユーザからのいかなる理由に基づ
     く請求からも,上記著作権者およびTOPPERSプロジェクトを免責すること.

 本ソフトウェアは,無保証で提供されているものである.上記著作権者およ
 びTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的に対す
 る適合性も含めて,いかなる保証も行わない.また,本ソフトウェアの利用
 により直接的または間接的に生じたいかなる損害に関しても,その責任を負
 わない.

ビルドスクリプト修正

debian/rules

#!/usr/bin/make -f
include /usr/share/cdbs/1/rules/debhelper.mk
 
install/athrill::
    install -pd $(DEB_DESTDIR)/usr/bin
    install -pm 755 athrill/bin/linux/* $(DEB_DESTDIR)/usr/bin

build/athrill::
    cd athrill-target-rh850f1x/build_linux; make

コミット・ビルド

# 初回は必要ない(`dpkg-source: info: there are no local changes to record` になるはず)
dpkg-source --commit

# ビルド・もろもろの成果物生成
debuild -rfakeroot -uc -us

ビルドが実行され、 athrill_2.0.0-1_amd64.deb が生成される。

成果物の確認

./
 +- athrill/                          : deb パッケージ用ディレクトリ
 |   +- athrill/                      : clone した athrill リポジトリ
 |   +- athrill-target-rh850f1x/      : clone した athrill-target-rh850f1x リポジトリ
 |   +- debian/                       : deb パッケージに必要な情報を入れたディレクトリ
 +- athrill_2.0.0-1.debian.tar.xz     : debian ディレクトリの中身を圧縮したもの
 +- athrill_2.0.0-1_amd64.build       : ビルドログ
 +- athrill_2.0.0-1_amd64.changes     : 変更履歴
 +- athrill_2.0.0.orig.tar.xz         : オリジナルソースコードを圧縮したもの
 +- athrill-dbgsym_2.0.0-1_amd64.ddeb : デバッグシンボルパッケージ
 +- athrill_2.0.0-1.dsc               : ソースコードの概要が記述されたファイル
 +- athrill_2.0.0-1_amd64.buildinfo   : ビルド時の環境情報
 +- athrill_2.0.0-1_amd64.deb         : apt, dpkg でインストールできるバイナリパッケージ

あとは、生成された athrill_2.0.0-1_amd64.deb を配布すれば OK。

一般的には、これを git-buildpackage で管理するらしいので、その方法を勉強しないと…

以上。

参考資料

2020年8月23日日曜日

Debian 10 で TOPPERS/ASP3 in Zig を動かす

前提

  • OS: Windoes 10 Pro 1909
  • Docker :Docker version 19.03.12, build 48a66213fe
  • Docker Image: debian:buster-slim
  • asp3_in_zig: 3d0d9f6bb7bdafaafb5a76529cc8af3ade577e77

docker run -it --rm debian:buster-slim してからの作業。

環境構築

apt-get update
apt-get install -y git curl bzip2 xz-utils make ruby qemu-system-arm gcc-arm-none-eabi

# zig 0.6.0+4e63cae36 を /opt/zig-linux-x86_64-0.6.0+4e63cae36 にインストール
curl -L https://ziglang.org/builds/zig-linux-x86_64-0.6.0+4e63cae36.tar.xz -O
tar xf zig-linux-x86_64-0.6.0+4e63cae36.tar.xz -C /opt
export PATH=$PATH:/opt/zig-linux-x86_64-0.6.0+4e63cae36

# tecsgen 1.7.0 のインストール
curl -L https://www.toppers.jp/download.cgi/tecsgen-1.7.0.tgz -O
tar xf tecsgen-1.7.0.tgz -C /opt

asp3_in_zig の取得とビルド

WORK_DIR=/work
ASP3_DIR=$WORK_DIR/asp3_in_zig

mkdir -p $WORK_DIR
cd $WORK_DIR
git clone https://github.com/toppers/asp3_in_zig.git

cd $ASP3_DIR
git checkout 3d0d9f6bb7bdafaafb5a76529cc8af3ade577e77

mkdir $ASP3_DIR/OBJ-ARM
cd $ASP3_DIR/OBJ-ARM
../configure.rb -G /opt/tecsgen-1.7.0/tecsgen/tecsgen.rb -T ct11mpcore_gcc -O "-DTOPPERS_USE_QEMU"
make

sample1 の実行

root@e5307855eb8c:/work/asp3_in_zig/OBJ-ARM# qemu-system-arm -M realview-eb-mpcore -semihosting -m 128M -nographic -kernel asp
pulseaudio: pa_context_connect() failed
pulseaudio: Reason: Connection refused
pulseaudio: Failed to initialize PA contextaudio: Could not init `pa' audio driver
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5047:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM default
alsa: Could not initialize DAC
alsa: Failed to open `default':
alsa: Reason: No such file or directory
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5047:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM default
alsa: Could not initialize DAC
alsa: Failed to open `default':
alsa: Reason: No such file or directory
audio: Failed to create voice `lm4549.out'

TOPPERS/ASP3 Kernel in Zig Release 3.6.0 for ARM CT11MPCore (Aug 23 2020, 12:34:09)
Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
                            Toyohashi Univ. of Technology, JAPAN
Copyright (C) 2004-2020 by Embedded and Real-Time Systems Laboratory
               Graduate School of Informatics, Nagoya Univ., JAPAN

no time event is processed in hrt interrupt.
System logging task is started.
Sample program starts (exinf = 0).
task1 is running (001).   |
task1 is running (002).   |
task1 is running (003).   |
...(snip)

以上。

参考資料