]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - os/debian/bin/init-reprepro.sh
4014dc4b3a708b2efc6f3c1a8771ed6e622b7b2c
[config/dotfiles.git] / os / debian / bin / init-reprepro.sh
1 # Setup a reprepro repository in /root/apt and add it to
2 # /etc/apt/sources.list.
3
4 # Copyright (C) 2013  Simon Ruderich
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
20 set -eu
21
22 sources=/etc/apt/sources.list
23 repo=/root/apt
24
25 # Don't look for exact "file://$repo" match to allow modifications on the
26 # system.
27 if grep -E '^deb file:///' "$sources" >/dev/null 2>&1; then
28     echo "file:/// already present in '$sources'!" >&2
29     exit 1
30 fi
31
32 # Create signing key for the repository if necessary.
33 email="apt@`hostname`"
34 if ! gpg --list-keys "$email" >/dev/null 2>&1; then
35     # See doc/DETAILS in the gpg source tree for documentation.
36     gpg --gen-key --batch <<EOF
37 %echo generating signing key $email for APT, this may take a while ...
38 Key-Type: RSA
39 Key-Length: 4096
40 # "cert" is automatically used for primary key.
41 Key-Usage: sign
42 Subkey-Type: RSA
43 Subkey-Length: 4096
44 Subkey-Usage: encrypt
45 Name-Real: Apt signing key
46 Name-Email: $email
47 Preferences: SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 BZIP2 ZLIB ZIP Uncompressed
48 %commit
49 EOF
50 fi
51
52 keyid=`gpg --list-keys --with-colons --fixed-list-mode "$email" \
53        | grep -E '^pub:' \
54        | tail -n1 \
55        | awk -F: '{ print $5 }'`
56 # Copied from simon-config and modified (uses "$sources"), keep in sync.
57 codename=`lsb_release -s -c 2>/dev/null \
58           || grep -E '^deb' "$sources" | head -n1 | awk '{ print $3 }'`
59
60 # Create reprepro repository.
61 if test ! -d "$repo"; then
62     echo "creating reprepro repository in '$repo'" >&2
63     mkdir -p "$repo/conf"
64     mkdir -p "$repo/morgue"
65
66     arch="`dpkg --print-architecture` `dpkg --print-foreign-architectures`"
67     cat >"$repo/conf/distributions" <<EOF
68 Codename: $codename
69 Components: main
70 Architectures: $arch source
71 SignWith: $keyid
72 EOF
73         cat >"$repo/conf/options" <<EOF
74 morguedir ./morgue
75 EOF
76
77     # Initialize repository and check configuration files. Ignore errors if
78     # reprepro is not installed, it's not necessary for a correct
79     # installation.
80     echo 'Initializing repository, errors are ignored.' >&2
81     ( cd "$repo" && reprepro export ) || true
82
83     # Does nothing if the same key is imported multiple times.
84     echo 'Adding key with apt-key.' >&2
85     gpg --export "$keyid" | apt-key add -
86 fi
87
88 echo "deb file://$repo $codename main" >>"$sources"
89
90 echo 'Finished successfully'. >&2