1 # Setup a reprepro repository in /root/apt and add it to
2 # /etc/apt/sources.list.
4 # Copyright (C) 2013 Simon Ruderich
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.
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.
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/>.
22 sources=/etc/apt/sources.list
25 # Don't look for exact "file://$repo" match to allow modifications on the
27 if grep -E '^deb file:///' "$sources" >/dev/null 2>&1; then
28 echo "file:/// already present in '$sources'!" >&2
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 ...
40 # "cert" is automatically used for primary key.
45 Name-Real: Apt signing key
47 Preferences: SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 BZIP2 ZLIB ZIP Uncompressed
52 keyid=`gpg --list-keys --with-colons --fixed-list-mode "$email" \
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 }'`
60 # Create reprepro repository.
61 if test ! -d "$repo"; then
62 echo "creating reprepro repository in '$repo'" >&2
64 mkdir -p "$repo/morgue"
66 arch="`dpkg --print-architecture` `dpkg --print-foreign-architectures`"
67 cat >"$repo/conf/distributions" <<EOF
70 Architectures: $arch source
73 cat >"$repo/conf/options" <<EOF
77 # Initialize repository and check configuration files. Ignore errors if
78 # reprepro is not installed, it's not necessary for a correct
80 echo 'Initializing repository, errors are ignored.' >&2
81 ( cd "$repo" && reprepro export ) || true
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 -
88 echo "deb file://$repo $codename main" >>"$sources"
90 echo 'Finished successfully'. >&2