#!/bin/sh -e . /usr/share/debconf/confmodule NAME=apt-cacher-ng CONFIGFILE=/etc/$NAME/zz_debconf.conf LDIR=/var/log/$NAME SLIST=/etc/apt/sources.list CFG=/etc/apt-cacher-ng DDIR=/usr/lib/apt-cacher-ng VDIR=/var/lib/apt-cacher-ng udefault=$VDIR/backends_ubuntu.default ddefault=$VDIR/backends_debian.default BINPATH=/usr/sbin/$NAME TOOL=$DDIR/acngtool gen_mirror_list_from_sources_list() { tmpfile="$1.dpkg-new" case "$2" in *gz) pickcmd=zgrep ;; *) pickcmd=grep ;; esac; ( grep -h '^deb' $SLIST.d/* $SLIST 2>/dev/null | sed -e "s,ftp:/,http:/," | \ ( while read a b c ; do case "$b" in http*) $pickcmd "$b" "$2" || true ;; esac done ) # but don't add duplicates ) | ( while read a ; do grep -q "$a" "$tmpfile" 2>/dev/null || echo "$a" >> "$tmpfile" ; done) # replace only if it got contents if test -s "$tmpfile" ; then cat "$tmpfile" > "$1" fi rm -f "$tmpfile" } sig='#09f369bf9c82a2210934e82213360226' def_file_header="# This is a configuration file. All lines starting with # will be ignored. # # WARNING: this file is maintained by configuration scripts of the apt-cacher-ng # package. All manual changes WILL BE LOST after the next package upgrade as # long as a line looking exactly like $sig # is found inside. Remove or modify that line to stop auto-updates of this file. $sig " # .default files specify a set of fallback configuration for the cases where # it's not possible to construct something useful in the regular backends files set_def_files() { # if not readable or still has the signature if ! test -r $ddefault || grep -q "^[[:space:]]*$sig[[:space:]]*$" $ddefault ; then echo "$def_file_header" > $ddefault # ftp.debian.org is a geodns mapped location, should be good as-is echo http://ftp.debian.org/debian/ >> $ddefault fi if ! test -r $udefault || grep -q "^[[:space:]]*$sig[[:space:]]*$" $udefault ; then guess_ubuntu_mirrors # silent fix of the broken file generated by the first versions of the mirror picking code if grep -q "^http://archive.ubuntu.com/?$" $udefault ; then sed "s,http://archive.ubuntu.com,http://archive.ubuntu.com/ubuntu," -i $udefault fi fi } get_umirrors_txt() { # mirror suggestions from Ubuntu's service might be a good candidate if ! $check_sane_data ; then mirurl=http://mirrors.ubuntu.com/mirrors.txt if which wget > /dev/null 2>&1 ; then timeout 15 wget --timeout=10 -q -O- $mirurl >> $tmpfile 2>/dev/null || true elif which curl > /dev/null 2>&1 ; then timeout 15 curl -m 10 --fail -s $mirurl >> $tmpfile 2>/dev/null || true else timeout 15 $TOOL NetworkTimeout=10 curl $mirurl $BINPATH >> $tmpfile 2>/dev/null || true fi fi } guess_ubuntu_mirrors() { tmpfile="`mktemp`" if [ ! "$http_proxy" ] ; then prx=$(apt-config dump | grep Acquire::http::Proxy | cut -f2 -d'"') || true if [ "$prx" ] ; then http_proxy="$prx" export http_proxy fi fi check_sane_data="grep -q http:// $tmpfile" # may hit a local mirror which also hosts Debian, use it then sed -e 's,\([a-z]\)/.*,\1,' < $CFG/backends_debian | xargs -I{} grep "{}" $DDIR/ubuntu_mirrors > $tmpfile || true get_umirrors_txt # maybe try without a proxy too, in case the proxy entry points at a broken apt-cacher-ng if ! $check_sane_data && test "$http_proxy" ; then unset http_proxy get_umirrors_txt fi # still nothing. Sneak more information from Debian backend configuration? if ! $check_sane_data ; then # ok, go by Debian TLD grep debian.org/ /etc/apt-cacher-ng/backends_debian | \ sed -e 's,^http://ftp[2-3]\?\.\([a-z][a-z]\).*,http://\1.archive.ubuntu.com/,' | \ sort -u | xargs -I{} grep "{}" $DDIR/ubuntu_mirrors > $tmpfile || true fi if ! $check_sane_data ; then # ok, then try just any TLD sed -e 's,^http://\([^\/]\+\).*,\1,;s,.*\.\(.*\),http://\1.archive.ubuntu.com/,' < $CFG/backends_debian | \ sort -u | xargs -I{} grep "{}" $DDIR/ubuntu_mirrors > $tmpfile || true fi if ! $check_sane_data ; then echo http://archive.ubuntu.com/ubuntu/ > $tmpfile || true fi if $check_sane_data ; then echo "$def_file_header" > $udefault cat $tmpfile >> $udefault fi rm -f "$tmpfile" 2>/dev/null } gen_lists() { gen_mirror_list_from_sources_list $CFG/backends_debian $DDIR/deb_mirrors.gz gen_mirror_list_from_sources_list $CFG/backends_ubuntu $DDIR/ubuntu_mirrors gen_mirror_list_from_sources_list $CFG/backends_debvol $DDIR/debvol_mirrors.gz } if [ "$1" = "configure" ]; then db_get $NAME/cachedir case "$RET" in keep|"") # maybe never displayed to user CDIRCONF='# CacheDir set to "keep", not overriding here' ;; *) # ok, configured by debconf, will be created as needed CDIR="$RET" CDIRCONF="CacheDir: $RET" ;; esac if test -z "$CDIR" ; then CDIR=$($TOOL printvar CacheDir -c $CFG 2>/dev/null) if test -z "$CDIR" ; then # unlikely... but even if PEBCAK, prepare the correct folder now CDIR=/var/cache/$NAME fi fi # user should exist. adduser sometimes fails (system range issue) but that's ok adduser --quiet --system --group --no-create-home --home "$CDIR" $NAME || id $NAME # also setup permissions ASAP if [ -z "$(dpkg-statoverride --list $CFG/security.conf)" ] ; then dpkg-statoverride --update --add root $NAME 640 $CFG/security.conf fi for x in "$CDIR" $LDIR ; do if [ ! -d "$x" ]; then install -d -g $NAME -o $NAME -m2755 "$x" fi done # creating some stubs # least invasive cooperation with the old style behavior for now for cfn in backends_debvol backends_ubuntu backends_debian ; do if ! test -e $CFG/$cfn ; then if test -e $CFG/oldconffiles/$cfn ; then mv -f $CFG/oldconffiles/$cfn $CFG/$cfn else install -m644 /dev/null $CFG/$cfn fi fi done rm -rf $CFG/oldconffiles db_get apt-cacher-ng/gentargetmode || true case "$RET" in "Create once"|"Set up once") gen_lists db_set apt-cacher-ng/gentargetmode "No automated setup" db_go ;; "Create now and update later"|"Set up now and update later") gen_lists ;; "No automated setup") ;; esac db_get $NAME/bindaddress BINDADDRESS="$RET" if [ x"$BINDADDRESS" = x"all" ] ; then # just for backwards compatibility BINDADDRESS='BindAddress: ' elif [ x"$BINDADDRESS" = x"keep" ] ; then BINDADDRESS='# BindAddress set to "keep", not overriding here' else BINDADDRESS="BindAddress: $BINDADDRESS" fi db_get $NAME/port PORT="$RET" if [ x"$PORT" = x"keep" ] || [ x"$PORT" = x ] ; then PORT='# Port set to "keep", not overriding here' else PORT="Port: $PORT" fi db_get $NAME/proxy PROXY="$RET" if [ x"$PROXY" = x ] ; then PROXY='Proxy:' elif [ x"$PROXY" = x"keep" ] ; then PROXY='# Proxy set to "keep", not overriding here' else if echo "$PROXY" |grep -q '@' ; then # well, there are credentials which is bad. This better goes into a file with restricted permissions. install -m 640 -o root -g $NAME /dev/null $CFG/zz_debconf_security.conf cat << HERESEC >$CFG/zz_debconf_security.conf # This file is created if the proxy contains user/password data # and is removed otherwise. Proxy: $PROXY HERESEC PROXY= else PROXY="Proxy: $PROXY" rm -rf $CFG/zz_debconf_security.conf fi fi PTENABLE='# PassThroughPattern: setting is not configured by debconf' db_get $NAME/tunnelenable if [ x"$RET" = x"true" ] ; then PTENABLE='PassThroughPattern: .*' fi cat << HERE > $CONFIGFILE # This is a configuration generated file managed by the package configuration # scripts of apt-cacher-ng. All manual changes here will be overriden. # To reconfigure particular settings, please run: # dpkg-reconfigure apt-cacher-ng -plow # See acng.conf and apt-cacher-ng documentation for more details. # To override this values permanently, put the assignments into a file # like /etc/apt-cacher-ng/zzz_override.conf . $PROXY $PORT $BINDADDRESS $CDIRCONF $PTENABLE HERE db_stop || true rm -f $CFG/in.acng $CFG/mount.acng set_def_files fi # Automatically added by dh_systemd_enable/13.7.1 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then # This will only remove masks created by d-s-h on package removal. deb-systemd-helper unmask 'apt-cacher-ng.service' >/dev/null || true # was-enabled defaults to true, so new installations run enable. if deb-systemd-helper --quiet was-enabled 'apt-cacher-ng.service'; then # Enables the unit on first installation, creates new # symlinks on upgrades if the unit file has changed. deb-systemd-helper enable 'apt-cacher-ng.service' >/dev/null || true else # Update the statefile to add new symlinks (if any), which need to be # cleaned up on purge. Also remove old symlinks. deb-systemd-helper update-state 'apt-cacher-ng.service' >/dev/null || true fi fi # End automatically added section # Automatically added by dh_installinit/13.7.1 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then # In case this system is running systemd, we need to ensure that all # necessary tmpfiles (if any) are created before starting. if [ -z "${DPKG_ROOT:-}" ] && [ -d /run/systemd/system ] ; then systemd-tmpfiles --create apt-cacher-ng.conf >/dev/null || true fi fi # End automatically added section # Automatically added by dh_installinit/13.7.1 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -z "${DPKG_ROOT:-}" ] && [ -x "/etc/init.d/apt-cacher-ng" ]; then update-rc.d apt-cacher-ng defaults 18 >/dev/null if [ -n "$2" ]; then _dh_action=restart else _dh_action=start fi invoke-rc.d apt-cacher-ng $_dh_action || exit 1 fi fi # End automatically added section