X-Git-Url: https://ruderich.org/simon/gitweb/?p=config%2Fdotfiles.git;a=blobdiff_plain;f=os%2Fdebian%2Fbin%2Finit-reprepro.sh;fp=os%2Fdebian%2Fbin%2Finit-reprepro.sh;h=4014dc4b3a708b2efc6f3c1a8771ed6e622b7b2c;hp=0000000000000000000000000000000000000000;hb=ae5f25d9ebf147d2c5d724a0902d91beff577ca3;hpb=0e1f3846c77e6b0ca5d9215b07f6e587cedd19d9 diff --git a/os/debian/bin/init-reprepro.sh b/os/debian/bin/init-reprepro.sh new file mode 100755 index 0000000..4014dc4 --- /dev/null +++ b/os/debian/bin/init-reprepro.sh @@ -0,0 +1,90 @@ +# Setup a reprepro repository in /root/apt and add it to +# /etc/apt/sources.list. + +# Copyright (C) 2013 Simon Ruderich +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +set -eu + +sources=/etc/apt/sources.list +repo=/root/apt + +# Don't look for exact "file://$repo" match to allow modifications on the +# system. +if grep -E '^deb file:///' "$sources" >/dev/null 2>&1; then + echo "file:/// already present in '$sources'!" >&2 + exit 1 +fi + +# Create signing key for the repository if necessary. +email="apt@`hostname`" +if ! gpg --list-keys "$email" >/dev/null 2>&1; then + # See doc/DETAILS in the gpg source tree for documentation. + gpg --gen-key --batch </dev/null \ + || grep -E '^deb' "$sources" | head -n1 | awk '{ print $3 }'` + +# Create reprepro repository. +if test ! -d "$repo"; then + echo "creating reprepro repository in '$repo'" >&2 + mkdir -p "$repo/conf" + mkdir -p "$repo/morgue" + + arch="`dpkg --print-architecture` `dpkg --print-foreign-architectures`" + cat >"$repo/conf/distributions" <"$repo/conf/options" <&2 + ( cd "$repo" && reprepro export ) || true + + # Does nothing if the same key is imported multiple times. + echo 'Adding key with apt-key.' >&2 + gpg --export "$keyid" | apt-key add - +fi + +echo "deb file://$repo $codename main" >>"$sources" + +echo 'Finished successfully'. >&2