Ubuntu(Debian)向けに独自のパッケージリポジトリを作成する

いずれかの開発プロジェクトの人生の遅かれ早かれ(そしてより早く)、オペレーションが開発を有意義に見て、関係を形式化することを提案する瞬間が来ます。 イベントのさらなる発展は、いつものように、双方に依存しています。 今日は悪いことについては話しません。開発がその操作のために準備されたシンプルなパッケージ構築ツール(debian /ルールおよびdebian /コントロールテンプレート、fakeroot、debuildコマンドなど)を使用する準備ができた場合をすぐに検討します。 少しだけ残った:収集されたパッケージの独自のリポジトリを上げるため。







インターネットの研究により、このトピックはカバーれていましたHabrでさえも明らかに開示されているとは考えられないことが突然示されたため、このギャップを埋めようとします。







まず、リポジトリに署名するために使用されるキーが必要です。 この例では、4096ビットの長さのRSAキーを作成しますが、制限の規定はありません。







$ sudo apt install gpg $ gpg --gen-key Please select what kind of key you want: (1) RSA and RSA (default) (2) DSA and Elgamal (3) DSA (sign only) (4) RSA (sign only) Your selection? 4 RSA keys may be between 1024 and 4096 bits long. What keysize do you want? (2048) 4096 Requested keysize is 4096 bits Please specify how long the key should be valid. 0 = key does not expire <n> = key expires in n days <n>w = key expires in n weeks <n>m = key expires in n months <n>y = key expires in n years Key is valid for? (0) 0 Key does not expire at all Is this correct? (y/N) y You need a user ID to identify your key; the software constructs the user ID from the Real Name, Comment and Email Address in this form: "Zaphod Beeblebrox (Galactic President) <zbeeblebrox@pres.galaxy.com>" Real name: SnakeOil Admin Email address: admin@snakeoil.org Comment: You selected this USER-ID: "SnakeOil Admin <admin@snakeoil.org>" Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
      
      





変更時にリポジトリに署名することになっているため、キーパスワードは空のままにしておくことをお勧めします。そうしないと、スクリプトでリポジトリを更新できませんが、完全な制御が必要な場合は、設定することもできます。 次に、キーをファイルにエクスポートし、さらにクライアントにインポートするためにリポジトリのルートに配置する必要があります。







 $ export PUBKEY_ID=`gpg --list-keys | awk '( $1 == "pub" ) { print $2 ; exit }' | cut -f 2 -d /` $ gpg --output keyFile --armor --export $PUBKEY_ID
      
      





リポジトリツリーを準備します。 Ubuntuディストリビューションは1つのみで、Intel x86_64のみがあり、ソースコードを含むパッケージはありません。そのため、ツリーの他の要素を作成することについては心配していません。 パッケージが異なるディストリビューション向けにアセンブルされ、異なる依存関係を持つ場合、ツリーはより分岐しやすくなり、以下で説明するアセンブリルールはより複雑になります。







 $ sudo mkdir -p /var/www/repo $ sudo mv keyFile !$ $ cd !$ $ sudo mkdir -p conf contrib/binary-amd64 dists/xenial
      
      





リポジトリー構成ファイルを作成します。







 $ sudo cat > /var/www/repo/conf/distributions <<EOF Origin: SnakeOil Label: SnakeOil private Ubuntu repo Codename: xenial Architectures: amd64 Components: contrib Description: Our own and 3rd party software packaged internally EOF $ sudo echo SignWith: $PUBKEY_ID >> /var/www/repo/conf/distributions
      
      





新しいパッケージが表示されたら、自動リポジトリ更新を設定します。 署名が組み込まれたInReleaseファイルは新しいパッケージマネージャーによって要求され、古いファイルにはReleaseとRelease.gpgの2つのファイルが必要です。 サポートする予定のすべてのディストリビューションについて、依存関係を複製する必要があります。







 $ sudo cat > /var/www/repo/Makefile <<EOF #!/usr/bin/make # # Update the repository every time when a new package arrives all: repo repo: dists/xenial/InRelease dists/xenial/Release.gpg dists/xenial/InRelease: dists/xenial/Release gpg --clearsign --digest-algo SHA512 -o dists/xenial/InRelease.new dists/xenial/Release mv dists/xenial/InRelease.new dists/xenial/InRelease dists/xenial/Release.gpg: dists/xenial/Release gpg -abs -o dists/xenial/Release.gpg-new dists/xenial/Release mv dists/xenial/Release.gpg-new dists/xenial/Release.gpg dists/xenial/Release: conf/distributions contrib/binary-amd64/Packages.gz cat conf/distributions > dists/xenial/Release apt-ftparchive release . >> dists/xenial/Release contrib/binary-amd64/Packages.gz: contrib/binary-amd64/Packages gzip --keep --force -9 ../../contrib/binary-amd64/Packages contrib/binary-amd64/Packages: contrib/binary-amd64/*.deb dpkg-scanpackages contrib/binary-amd64 > contrib/binary-amd64/Packages.new mv contrib/binary-amd64/Packages.new contrib/binary-amd64/Packages EOF
      
      





リポジトリは準備ができており、/ var / www / repo / dists / xenial / contrib / binary-amd64に新しく作成されたすべてのパッケージのエントリを構成します(この記事の範囲を超えています)。 しかし、純粋にローカルである場合、リポジトリからどのくらい使用されますか? HTTP経由で可用性を確保する必要があります。







 $ sudo apt install nginx $ sudo cat > /etc/nginx/sites-available/repo.conf <<EOF server { listen 80; server_name repo repo.snakeoil.org; location ~ /(.*)/conf { deny all; } root /var/www/repo; } EOF $ sudo ln -s /etc/nginx/sites-available/repo.conf /etc/nginx/sites-enabled/ $ sudo service nginx restart
      
      





最後に、クライアントでリポジトリを処方します。







 $ wget -O - http://repo/keyFile | sudo apt-key add - $ sudo echo 'deb [arch=amd64] http://repo/ xenial contrib' > /etc/apt/sources.list.d/mylovelyrepo.list $ sudo apt update
      
      





ブラックマジックの公開セッションは終了しました。ご清聴ありがとうございました。








All Articles