Ubuntuのパッケージリポジトリのスナップショットを作成したり、
パッケージリポジトリの管理ツールである「aptly」
aptlyは
- 公式パッケージリポジトリのパッケージすべてもしくは一部のミラーリング
- パッケージリポジトリのスナップショットの作成
- ローカルパッケージリポジトリの作成
- リポジトリ間のマージ・
更新 - HTTP経由で作成したリポジトリを公開
- REST APIを使ったリポジトリの操作
フルミラーも可能ではありますが、apt-key
コマンドで取り込まなければならないことに注意が必要です。
リポジトリのスナップショット機能は、
ローカルパッケージリポジトリの作成は、dpkg
コマンドやapt-ftparchive
コマンドを使って構築することも可能ではありますが、
まだ実験的ではありますが、
単に公式パッケージのミラーサイトを作りたいだけであれば、apt-key
による鍵の追加は不要になるというメリットがあります。また、sources.
を変更する必要すらなく、
どちらのツールもaptlyほど柔軟な管理は行えませんが、
aptlyのインストール
aptlyのパッケージは公式リポジトリにも存在しますが、
$ wget -qO - https://www.aptly.info/pubkey.txt | sudo apt-key add - $ echo "deb http://repo.aptly.info/ squeeze main" | sudo tee /etc/apt/sources.list.d/aptly.list $ sudo apt update $ sudo apt install aptly
DebianとUbuntuで同じパッケージなので、squeeze
」
aptlyを運用するためにはリポジトリ用のGPG鍵が必要になります。普段使っているGPG鍵でも実装上は問題ありませんが、
$ sudo adduser aptly ユーザー `aptly' を追加しています... 新しいグループ `aptly' (1001) を追加しています... 新しいユーザー `aptly' (1001) をグループ `aptly' に追加しています... ホームディレクトリ `/home/aptly' を作成しています... `/etc/skel' からファイルをコピーしています... 新しい UNIX パスワードを入力してください: 新しい UNIX パスワードを再入力してください: passwd: password updated successfully Changing the user information for aptly Enter the new value, or press ENTER for the default Full Name []: aptly Room Number []: Work Phone []: Home Phone []: Other []: 以上で正しいですか? [Y/n]
aptlyユーザーに切り替えて、
$ sudo -iu aptly $ gpg --gen-key gpg (GnuPG) 1.4.20; Copyright (C) 2015 Free Software Foundation, Inc. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. gpg: ディレクトリ「/home/aptly/.gnupg」ができました gpg: 新しい構成ファイル「/home/aptly/.gnupg/gpg.conf」ができました gpg: *警告*: 「/home/aptly/.gnupg/gpg.conf」のオプションは起動している間、有効になりません gpg: 鍵リング「/home/aptly/.gnupg/secring.gpg」ができました gpg: 鍵リング「/home/aptly/.gnupg/pubring.gpg」ができました ご希望の鍵の種類を選択してください: (1) RSA と RSA (デフォルト) (2) DSA と Elgamal (3) DSA (署名のみ) (4) RSA (署名のみ) 選択は? RSA 鍵は 1024 から 4096 ビットの長さで可能です。 鍵長は? (2048) 要求された鍵長は2048ビット 鍵の有効期限を指定してください。 0 = 鍵は無期限 <n> = 鍵は n 日間で期限切れ <n>w = 鍵は n 週間で期限切れ <n>m = 鍵は n か月間で期限切れ <n>y = 鍵は n 年間で期限切れ 鍵の有効期間は? (0) (null)は無期限です これで正しいですか? (y/N) y あなたの鍵を同定するためにユーザIDが必要です。 このソフトは本名、コメント、電子メール・アドレスから 次の書式でユーザIDを構成します: "Heinrich Heine (Der Dichter) <[email protected]>" 本名: aptly 電子メール・アドレス: [email protected] コメント: 次のユーザIDを選択しました: "aptly <[email protected]>" 名前(N)、コメント(C)、電子メール(E)の変更、またはOK(O)か終了(Q)? O 秘密鍵を保護するためにパスフレーズがいります。 (中略) gpg: /home/aptly/.gnupg/trustdb.gpg: 信用データベースができました gpg: 鍵C6D7028Bを究極的に信用するよう記録しました 公開鍵と秘密鍵を作成し、署名しました。 gpg: 信用データベースの検査 gpg: 最小の「ある程度の信用」3、最小の「全面的信用」1、PGP信用モデル gpg: 深さ: 0 有効性: 1 署名: 0 信用: 0-, 0q, 0n, 0m, 0f, 1u pub 2048R/C6D7028B 2017-08-17 フィンガー・プリント = A6D2 FEF3 B835 CA7E 809F 35A9 2F19 39DF C6D7 028B uid aptly <[email protected]> sub 2048R/B36DF2F0 2017-08-17
これでaptlyを使う準備が整いました。
特定パッケージのミラーリポジトリを作る
例としてUbuntu 16.
そこであらかじめUbuntu公式リポジトリの公開鍵を信頼する鍵として取り込んでおきます。公式リポジトリの公開鍵リストはubuntu-keyringパッケージとして提供されています。一般的なインストール方法なら最初からインストールされているはずです。Debianのリポジトリの公開鍵が必要なら、
$ sudo apt install ubuntu-keyring $ gpg --no-default-keyring \ --keyring /usr/share/keyrings/ubuntu-archive-keyring.gpg \ --export | gpg --no-default-keyring --keyring trustedkeys.gpg --import gpg: 鍵437D05B5: 公開鍵"Ubuntu Archive Automatic Signing Key <[email protected]>"をインポートしました gpg: 鍵FBB75451: 公開鍵"Ubuntu CD Image Automatic Signing Key <[email protected]>"をインポートしました gpg: 鍵C0B21F32: 公開鍵"Ubuntu Archive Automatic Signing Key (2012) <[email protected]>"をインポートしました gpg: 鍵EFE21092: 公開鍵"Ubuntu CD Image Automatic Signing Key (2012) <[email protected]>"をインポートしました gpg: 処理数の合計: 4 gpg: インポート: 4 (RSA: 2) gpg: 究極的に信用する鍵C6D7028Bの公開鍵が見つかりません gpg: 最小の「ある程度の信用」3、最小の「全面的信用」1、PGP信用モデル gpg: 深さ: 0 有効性: 1 署名: 0 信用: 0-, 0q, 0n, 0m, 0f, 1u
では適当なミラーリポジトリを作成してみましょう。-architecutres
」-filter
」-filter
」$Source (foo)
」
「-filter-with-deps
」/etc/
に記載している内容)
$ aptly mirror create -architectures=amd64 -filter='fcitx | Name (~ mozc-*)' \ -filter-with-deps ange http://jp.archive.ubuntu.com/ubuntu/ \ xenial main restricted universe multiverse Config file not found, creating default config at /home/aptly/.aptly.conf Downloading http://jp.archive.ubuntu.com/ubuntu/dists/xenial/InRelease... gpgv: 2016年04月22日 08時25分09秒 JSTにDSA鍵ID 437D05B5で施された署名 gpgv: "Ubuntu Archive Automatic Signing Key <[email protected]>"からの正しい署名 gpgv: 2016年04月22日 08時25分09秒 JSTにRSA鍵ID C0B21F32で施された署名 gpgv: "Ubuntu Archive Automatic Signing Key (2012) <[email protected]>"からの正しい署名 Mirror [ange]: http://jp.archive.ubuntu.com/ubuntu/ xenial successfully added. You can run 'aptly mirror update ange' to download repository contents.
ミラーリポジトリを作成したら、aptly mirror update
」
$ aptly mirror update ange gpgv: 2016年04月22日 08時25分09秒 JSTにDSA鍵ID 437D05B5で施された署名 gpgv: "Ubuntu Archive Automatic Signing Key <[email protected]>"からの正しい署名 gpgv: 2016年04月22日 08時25分09秒 JSTにRSA鍵ID C0B21F32で施された署名 gpgv: "Ubuntu Archive Automatic Signing Key (2012) <[email protected]>"からの正しい署名 Downloading & parsing package files... Downloading http://jp.archive.ubuntu.com/ubuntu/dists/xenial/main/binary-amd64/Packages.gz... Downloading http://jp.archive.ubuntu.com/ubuntu/dists/xenial/restricted/binary-amd64/Packages.gz... Downloading http://jp.archive.ubuntu.com/ubuntu/dists/xenial/universe/binary-amd64/Packages.gz... Downloading http://jp.archive.ubuntu.com/ubuntu/dists/xenial/multiverse/binary-amd64/Packages.gz... Applying filter... Packages filtered: 53837 -> 271. Building download queue... Download queue: 271 items (149.93 MiB) Downloading http://jp.archive.ubuntu.com/ubuntu/pool/main/libd/libdrm/libdrm2_2.4.67-1_amd64.deb... Downloading http://jp.archive.ubuntu.com/ubuntu/pool/main/u/ucf/ucf_3.0036_all.deb... (中略) Downloading http://jp.archive.ubuntu.com/ubuntu/pool/universe/m/mozc/emacs-mozc_2.17.2116.102+gitfd0f5b34+dfsg-1ubuntu1_amd64.deb... Downloading http://jp.archive.ubuntu.com/ubuntu/pool/main/libx/libxcb/libxcb-render0_1.11.1-1ubuntu1_amd64.deb... Mirror `ange` has been successfully updated.
xenial以外にもリリース後のアップデートパッケージが格納されるxenial-updatesや、aptly mirror create
」
$ aptly mirror create -architectures=amd64 -filter='fcitx | Name (~ mozc-*)' \ -filter-with-deps ange-updates http://jp.archive.ubuntu.com/ubuntu/ \ xenial-updates main restricted universe multiverse $ aptly mirror update ange-updates
取得したパッケージは~/.aptly/
」
リポジトリの状態を確認する
リポジトリの状態はaptly mirror show
」
$ aptly mirror show ange Name: ange Archive Root URL: http://jp.archive.ubuntu.com/ubuntu/ Distribution: xenial Components: main, restricted, universe, multiverse Architectures: amd64 Download Sources: no Download .udebs: no Filter: fcitx | Name (~ mozc-*) Filter With Deps: yes Last update: 2017-08-17 20:44:26 JST Number of packages: 271 Information from release file: Acquire-By-Hash: yes Architectures: amd64 arm64 armhf i386 powerpc ppc64el s390x Codename: xenial Components: main restricted universe multiverse Date: Thu, 21 Apr 2016 23:23:46 UTC Description: Ubuntu Xenial 16.04 Label: Ubuntu Origin: Ubuntu Suite: xenial Version: 16.04
また各リポジトリに格納されているパッケージはaptly mirror search
」aptly package search
」
$ aptly mirror search ange fcitx fcitx_1:4.2.9.1-1ubuntu1_all $ aptly package search fcitx fcitx_1:4.2.9.1-1ubuntu1.16.04.2_all fcitx_1:4.2.9.1-1ubuntu1_all
「aptly package show
」
$ aptly package show fcitx Package: fcitx Priority: optional Section: utils Installed-Size: 36 Maintainer: Ubuntu Developers <[email protected]> Original-Maintainer: IME Packaging Team <[email protected]> Architecture: all Version: 1:4.2.9.1-1ubuntu1 Depends: fcitx-bin, fcitx-data, fcitx-modules Recommends: fcitx-config-gtk | kde-config-fcitx, fcitx-frontend-all | fcitx-frontend-fbterm, fcitx-ui-classic | fcitx-ui-light, im-config (>= 0.5) | im-switch Suggests: fcitx-m17n, fcitx-tools Filename: fcitx_4.2.9.1-1ubuntu1_all.deb Size: 5564 MD5sum: bcb1e9863263b3278aeb5d118f01f478 SHA1: 1ffac1fa939bb95e6a8cb6d61ebdbcafc0eba851 SHA256: 207e18c52efe00471c62923e9ad7e4e5e0421a25321ff27298f373e965f773a7 SHA512: 4a87c92492c42e3181faf21f724d94b8433281d970b6b4645f38b694096432a77ea2c561505c9b23a9138c5899420f2ba0f937aa982c24158c0d5d883e0ff19d Description: Flexible Input Method Framework Homepage: https://github.com/fcitx/fcitx Supported: 5y Description-Md5: bb21ec6d5296fba56418f43e299b26e5 Task: ubuntu-live, kubuntu-live, lubuntu-desktop, ubuntukylin-desktop Bugs: https://bugs.launchpad.net/ubuntu/+filebug Origin: Ubuntu
リポジトリのスナップショットを作成する
「aptly mirror update
」
先ほど作ったangeとange-updatesのスナップショット
$ aptly snapshot create ange-20170817 from mirror ange Snapshot ange-20170817 successfully created. You can run 'aptly publish snapshot ange-20170817' to publish snapshot as Debian repository. $ aptly snapshot create ange-updates-20170817 from mirror ange-updates Snapshot ange-updates-20170817 successfully created. You can run 'aptly publish snapshot ange-updates-20170817' to publish snapshot as Debian repository.
これでangeやange-updatesが更新されたとしても、
複数のスナップショットをマージして、-latest
」
$ aptly snapshot merge -latest princess-20170817 ange-20170817 ange-updates-20170817 Snapshot princess-20170817 successfully created. You can run 'aptly publish snapshot princess-20170817' to publish snapshot as Debian repository.
ちなみにスナップショット間での差分も表示できます。
$ aptly snapshot diff ange-20170817 princess-20170817 Arch | Package | Version in A | Version in B ! all | fcitx | 1:4.2.9.1-1ubuntu1 | 1:4.2.9.1-1ubuntu1.16.04.2 ! all | fcitx-data | 1:4.2.9.1-1ubuntu1 | 1:4.2.9.1-1ubuntu1.16.04.2 ! all | fontconfig-config | 2.11.94-0ubuntu1 | 2.11.94-0ubuntu1.1 ! all | libgdk-pixbuf2.0-common | 2.32.2-1ubuntu1 | 2.32.2-1ubuntu1.2 ! all | libgtk2.0-common | 2.24.30-1ubuntu1 | 2.24.30-1ubuntu1.16.04.2 ! all | mozc-data | 2.17.2116.102+gitfd0f5b34+dfsg-1ubuntu1 | 2.17.2116.102+gitfd0f5b34+dfsg-1ubuntu1.1 ! amd64 | emacs-mozc | 2.17.2116.102+gitfd0f5b34+dfsg-1ubuntu1 | 2.17.2116.102+gitfd0f5b34+dfsg-1ubuntu1.1 (以下略)
リポジトリを公開する
作成したスナップショットはパッケージリポジトリとして公開できます。
$ aptly publish snapshot -distribution=princess princess-20170817 Loading packages... Generating metadata files and linking package files... Finalizing metadata files... Signing file 'Release' with gpg, please enter your passphrase when prompted: 次のユーザの秘密鍵のロックを解除するには パスフレーズがいります:"aptly <[email protected]>" 2048ビットRSA鍵, ID C6D7028B作成日付は2017-08-17 Clearsigning file 'Release' with gpg, please enter your passphrase when prompted: 次のユーザの秘密鍵のロックを解除するには パスフレーズがいります:"aptly <[email protected]>" 2048ビットRSA鍵, ID C6D7028B作成日付は2017-08-17 Snapshot princess-20170817 has been successfully published. Please setup your webserver to serve directory '/home/aptly/.aptly/public' with autoindexing. Now you can add following line to apt sources: deb http://your-server/ princess main Don't forget to add your GPG key to apt with apt-key. You can also use `aptly serve` to publish your repositories over HTTP quickly.
リポジトリのメタデータに署名を行うため、
「-distribution
」
パッケージリポジトリは~/.aptly/
」~/.aptly.
」
「aptly publish
」~/.aptly/
」
実験的にHTTPサーバーを立てたければ、aptly serve
」
$ aptly serve Serving published repositories, recommended apt sources list: # ./princess [amd64] publishes {main: [princess-20170817]: Merged from sources: 'ange-20170817', 'ange-updates-20170817'} deb http://aptly:8080/ princess main Starting web server at: :8080 (press Ctrl+C to quit)...
「aptly serve
」
クライアント側の操作に移る前に、
$ gpg --export --armor > princess.pub
あとはこのリポジトリ鍵を登録し、sources.
を設定します。ここでaptlyが動いているマシンのアドレスをaptly.
」
$ sudo apt-key add princess.pub $ echo "deb http://aptly.example.com:8080/ princess main" | sudo tee /etc/apt/sources.list.d/princess.list $ sudo apt update $ sudo apt policy fcitx
最後のコマンドでfcitxの候補としてaptlyで作ったリポジトリのパッケージが表示されたら成功です。
もちろんaptly serve
」
ローカルパッケージのリポジトリを作る
ここまではすでに存在するリポジトリからパッケージを取得していました。aptlyでは単なるミラーだけでなく、
$ aptly repo create -distribution=dorothy -component=main chise-repo Local repo [chise-repo] successfully added. You can run 'aptly repo add chise-repo ...' to add packages to repository.
「-distribution
」-component
」
さて、
$ aptly repo add chise-repo beatrice/ Loading packages... [+] libkkc-common_0.3.5-1ubuntu1~1.gbp99dbf9_all added [+] libkkc-dev_0.3.5-1ubuntu1~1.gbp99dbf9_amd64 added [+] libkkc-utils-dbg_0.3.5-1ubuntu1~1.gbp99dbf9_amd64 added [+] libkkc-utils_0.3.5-1ubuntu1~1.gbp99dbf9_amd64 added [+] libkkc2-dbg_0.3.5-1ubuntu1~1.gbp99dbf9_amd64 added [+] libkkc2_0.3.5-1ubuntu1~1.gbp99dbf9_amd64 added [+] libkkc_0.3.5-1ubuntu1~1.gbp99dbf9_source added $ aptly repo show chise-repo Name: chise-repo Comment: Default Distribution: dorothy Default Component: main Number of packages: 7 $ aptly repo search chise-repo libkkc libkkc_0.3.5-1ubuntu1~1.gbp99dbf9_source
「beatrice/
」.deb
」.udeb
」.dsc
」.dsc
」.deb
」.udeb
」.dsc
」-remove-files
」
dput
コマンドのように.changes
」aptly repo include
」
「aptly repo copy
」aptly repo move
」aptly repo import
」
ローカルリポジトリはミラーリポジトリと異なり、aptly repo publich
」
社内開発リポジトリにaptlyはいかが?
ここまで紹介したように、
社内開発用にパッケージリポジトリが欲しいと考えているのであれば、