LoginSignup
8
5

More than 5 years have passed since last update.

private な APT REPOSITORY を作成したい

Last updated at Posted at 2019-04-13

Google 検索すると…
必要労力が全く異なる複数の方法が出てきました。
そこで、自分用にまとめをします。

APT REPOSITORY がどのようなものであるかは、
Debian Repository Format が詳しいです。

(本文中で使用している pg_dummy は github へアップしています)

良いと思うものを先に挙げています。

mini-dinstall

See: オレオレ Debian アーカイブの作成

reprepro

See: https://www.codepool.biz/linux-debian-reporisory-reprepro.html

deb パッケージを追加

reprepro includedeb myrepo /build/*.deb

(reprepro includedeb では deb ファイルがそのまま REPOSITORY へ投入されるので… 署名したい場合は dpkg-sig --sign builder *.deb などで先に署名します)

そして、コマンド一発で REPOSITORY が出来上がるのは素晴らしい!

reprepro export

手書きしたファイルはつぎのファイルだけ

conf/distributions
Origin: me
Label: myrepo
Codename: myrepo
Architectures: amd64
Components: main
Description: myrepo
SignWith: 97EF4BE15A920E4E

実行前のツリー

root@015806d0655a:/apt# tree
.
├── conf
│   └── distributions
└── web.config

1 directory, 2 files

実行後

root@015806d0655a:/apt# tree
.
├── conf
│   └── distributions
├── db
│   ├── checksums.db
│   ├── contents.cache.db
│   ├── packages.db
│   ├── references.db
│   ├── release.caches.db
│   └── version
├── dists
│   └── myrepo
│       ├── InRelease
│       ├── main
│       │   └── binary-amd64
│       │       ├── Packages
│       │       ├── Packages.gz
│       │       └── Release
│       ├── Release
│       └── Release.gpg
├── pool
│   └── main
│       └── p
│           └── postgresql-10-pgdummy
│               └── postgresql-10-pgdummy_0.1.0_amd64.deb
└── web.config

10 directories, 15 files

レポジトリを公開する場合は、conf と db を外部からアクセスできないようにしましょう

apt-ftparchive generate

See: https://unix.stackexchange.com/a/403489

これでも結構大変でした。 reprepro を知らなかったがために… 理屈を理解するうえでは役に立ちましたが

build.sh
#!/bin/bash

(
  mkdir -p dists/myrepo/main/binary-amd64
) && (
  find . -name "Contents-amd64.*" -or -name "Packages" -or -name "Packages.*" -delete
) && (
  apt-ftparchive generate -c=aptftp.conf aptgenerate.conf
) && (
  apt-ftparchive release -c=aptftp.conf dists/myrepo >dists/myrepo/Release
) && (
  rm -f dists/myrepo/Release.gpg dists/myrepo/InRelease
) && (
  gpg --clearsign -o dists/myrepo/InRelease dists/myrepo/Release
) && (
  gpg -abs -o dists/myrepo/Release.gpg dists/myrepo/Release
) && (
  echo OK
)
aptftp.conf
APT::FTPArchive::Release {
    Origin "example.com";
    Label "A dummy Debian/Ubuntu repository";
    Suite "myrepo";
    Codename "myrepo";
    Architectures "amd64";
    Components "main";
};
aptgenerate.conf
Dir::ArchiveDir ".";
Dir::CacheDir ".";
TreeDefault::Directory "pool/";
Default::Packages::Extensions ".deb";
Default::Packages::Compress ". gzip bzip2";
Default::Sources::Compress ". gzip bzip2";
Default::Contents::Compress "gzip bzip2";

BinDirectory "dists/myrepo/main/binary-amd64" {
    Packages "dists/myrepo/main/binary-amd64/Packages";
    Contents "dists/myrepo/Contents-amd64";
};

Tree "dists/myrepo" {
    Sections "main";
    Architectures "amd64";
};

コマンド

./build.sh

実行前のツリー

root@015806d0655a:/apt# tree
.
├── aptftp.conf
├── aptgenerate.conf
├── build.sh
├── pool
│   └── postgresql-10-pgdummy_0.1.0-1_amd64.deb
└── web.config

1 directory, 5 files

実行後は

root@015806d0655a:/apt# tree
.
├── aptftp.conf
├── aptgenerate.conf
├── build.sh
├── dists
│   └── myrepo
│       ├── Contents-amd64.bz2
│       ├── Contents-amd64.gz
│       ├── InRelease
│       ├── main
│       │   ├── binary-amd64
│       │   │   ├── Packages
│       │   │   ├── Packages.bz2
│       │   │   └── Packages.gz
│       │   ├── Contents-amd64.bz2
│       │   └── Contents-amd64.gz
│       ├── Release
│       └── Release.gpg
├── packages-amd64.db
├── pool
│   └── postgresql-10-pgdummy_0.1.0-1_amd64.deb
└── web.config

5 directories, 16 files

apt-ftparchive

See: How To Create an Authenticated Repository

apt-ftparchive にはいくつかのコマンドがあります: packages, sources, contents, release, generate, clean

apt 1.4.9 (amd64)
Usage: apt-ftparchive [options] command
Commands: packages binarypath [overridefile [pathprefix]]
          sources srcpath [overridefile [pathprefix]]
          contents path
          release path
          generate config [groups]
          clean config

このあと紹介するのは packagesrelease

apt-ftparchive packages

apt-ftparchive packages では deb パッケージの情報と、deb ファイルへのパスと、ハッシュ値を出力するようです (複数のパッケージがある場合は空行を挟む模様)
dists/$DIST/$COMP/binary-$ARCH/Packages に出力されるような内容です。
apt updateRelease のつぎに Packages を探します

root@015806d0655a:/apt# apt-ftparchive packages pool
Package: postgresql-10-pgdummy
Architecture: amd64
Version: 0.1.0
Priority: optional
Section: database
Maintainer: kenjiuno <ku@digitaldolphins.jp>
Installed-Size: 33
Depends: postgresql-10
Filename: pool/postgresql-10-pgdummy_0.1.0-1_amd64.deb
Size: 5112
MD5sum: fb6b6c691ef409fe03d1ad626980cdf5
SHA1: a5a95a05826ab94fabb88b3be9812193e60739ef
SHA256: 169b48a5b1cbd189e99d5f3ec4cda3923f16641ded6e909e4fd44b27d45640ea
SHA512: 4906aa8c574f2f675ebbc7f1b2d617dd8e77dbbd501cec975a657db22518d9de960b7901b0e
bb6a7d93698f342e57b7f5344172d26963dba36a7e28d748c189e
Description: pg_dummy for PostgreSQL C libraries

apt-ftparchive release

apt-ftparchive release では、DISTRIBUTION ごとのファイル一覧、ハッシュ値をリスト化するようです。
$ARCHIVE_ROOT/dists/$DISTRIBUTION/Release に出力されるような内容です。
apt update が 1 番目に見に来るファイルです

※ 下記の情報だけでは不十分です。Codename, Component, Label, Origin, Suite のような情報がないと apt update が失敗し REPOSITORY として機能しません。

root@015806d0655a:/apt# apt-ftparchive release dists/myrepo/
Date: Sun, 14 Apr 2019 12:21:13 +0000
MD5Sum:
 7b9e8e0c6121cdfcea1065934febf7a1              114 Contents-amd64.bz2
 985feb384bc9a66c510ab8aad2be6e9e               97 Contents-amd64.gz
 a6118f08db732180049f5f452467f518             3637 Release
 7b9e8e0c6121cdfcea1065934febf7a1              114 main/Contents-amd64.bz2
 985feb384bc9a66c510ab8aad2be6e9e               97 main/Contents-amd64.gz
 5aed8b647fdeeecc323f06789a3c0527              604 main/binary-amd64/Packages
 63b52f842c60be2ff2ee998bdf640990              474 main/binary-amd64/Packages.bz2
 3b89cefdd91a4f77d15ffa5025a1616b              451 main/binary-amd64/Packages.gz
SHA1:
 5c6bc323cfe3cc495cab4620b9bfdb19ca7a49ea              114 Contents-amd64.bz2
 f6a9f7706f507c4f04d4ebf65b0ab2934a10671e               97 Contents-amd64.gz
 cc5adfc9a82ccc8502f74e9c5221f39093fbd902             3637 Release
 5c6bc323cfe3cc495cab4620b9bfdb19ca7a49ea              114 main/Contents-amd64.bz2
 f6a9f7706f507c4f04d4ebf65b0ab2934a10671e               97 main/Contents-amd64.gz
 a87f5146c6d9da25ceff04a9a16e2d243e37fd68              604 main/binary-amd64/Packages
 63c44c7078a917dd8e44cee5a3c694fec054116e              474 main/binary-amd64/Packages.bz2
 7194955fd93d957e22b5984cbf273654d87fb7c5              451 main/binary-amd64/Packages.gz
SHA256:
 3430b0e4646d6a9cd184cf2adb1d4ab39a1cfd2ff8dfec7168607caa81f19747              114 Contents-amd64.bz2
 5940ac16b990ff3742f11a35c294bb4662533480102ec06444983353460ebfbf               97 Contents-amd64.gz
 82c3ca8612759179b0f5571eb2d1eaea9fa183bd939bd93044cde648507b002d             3637 Release
 3430b0e4646d6a9cd184cf2adb1d4ab39a1cfd2ff8dfec7168607caa81f19747              114 main/Contents-amd64.bz2
 5940ac16b990ff3742f11a35c294bb4662533480102ec06444983353460ebfbf               97 main/Contents-amd64.gz
 ea2fe48ea7cff41b15ef2665c34abba2b8efb946f856c2079af4d8ec611a89e4              604 main/binary-amd64/Packages
 a6873b5c4dbbd594b32fbb144fb207fac1345e9d4e1dc025447e04efbf590084              474 main/binary-amd64/Packages.bz2
 3279d9c01f269f65e7cbdeba75287c6b26e0f83450ad97efea521f1828a2ce45              451 main/binary-amd64/Packages.gz
SHA512:
 c67d7d87d291c48694e8d9f5370bb60ca7b2b0f02ea84648ea80445fd4cb9a49f186ce78daf666419b9f3121baada889817e1c79646dc873f70dbcc01733f01c              114 Contents-amd64.bz2
 9cb30567e4756d542000c6294df40210edcd278848d491856bfe9ace76901ed64e4386b5a6550b464620ffd98d1e2655c4e16155f062329808056a5aa6892a4c               97 Contents-amd64.gz
 5179801a0429920f9a24aee2b15c3b8409188f91893843fa66993c786458a2b16d8e16906871a90bd8db6f10eced74b6aa6eef7e449674edfa5d9fe829cd330f             3637 Release
 c67d7d87d291c48694e8d9f5370bb60ca7b2b0f02ea84648ea80445fd4cb9a49f186ce78daf666419b9f3121baada889817e1c79646dc873f70dbcc01733f01c              114 main/Contents-amd64.bz2
 9cb30567e4756d542000c6294df40210edcd278848d491856bfe9ace76901ed64e4386b5a6550b464620ffd98d1e2655c4e16155f062329808056a5aa6892a4c               97 main/Contents-amd64.gz
 4ae9066c5aeabbd66278c84dc11d0f13387cebb84fcd01ab36895cb2795ffe9706f8aacc7602aac97d974a5eb628c43a6f1003f7857d22e83a40f3bf14927c7b              604 main/binary-amd64/Packages
 665dd26c9297535e2d2484bac7a5a9c339dc5387201e3ba2ce5cdd1ce5d29d9842ac25b6ed73444ae5db6cc425092505113682b4c22f5bb5df31e2f5fecc63c9              474 main/binary-amd64/Packages.bz2
 50cd9c7467bb330158134d6fb7a7588690e0893dd1521195ce9523d61859698b7f853d4420230be3982aabff3b4fe965df61d884e1b8d3e621eb00e8bc1fc002              451 main/binary-amd64/Packages.gz

dpkg-scanpackages など

See: https://askubuntu.com/a/772636

使用例です。

dpkg-scanpackages . で、孫フォルダーを含む子フォルダーにある deb ファイルを探し出し、パッケージごとの詳細を出力します。

root@015806d0655a:/apt# dpkg-scanpackages .
Package: postgresql-10-pgdummy
Version: 0.1.0
Architecture: amd64
Maintainer: kenjiuno <ku@digitaldolphins.jp>
Installed-Size: 33
Depends: postgresql-10
Filename: ./pool/postgresql-10-pgdummy_0.1.0-1_amd64.deb
Size: 5112
MD5sum: fb6b6c691ef409fe03d1ad626980cdf5
SHA1: a5a95a05826ab94fabb88b3be9812193e60739ef
SHA256: 169b48a5b1cbd189e99d5f3ec4cda3923f16641ded6e909e4fd44b27d45640ea
Section: database
Priority: optional
Description: pg_dummy for PostgreSQL C libraries
8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5