postinst is in apt-cacher-ng 3.1-1build1.
This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316  | #!/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
}
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 -n1 -i grep "{}" $DDIR/ubuntu_mirrors > $tmpfile || true
   # 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
         wget --timeout=15 -q -O- $mirurl >> $tmpfile 2>/dev/null || true
      elif which curl > /dev/null 2>&1 ; then
         curl -m 15 --fail -s $mirurl >> $tmpfile 2>/dev/null || true
      else
         $TOOL NetworkTimeout:15 curl $mirurl $BINPATH >> $tmpfile 2>/dev/null || true
      fi
   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 -n1 -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 -n1 -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
         ;;
      *)
         # 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/11.1.4ubuntu1
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/11.1.4ubuntu1
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 [ -d /run/systemd/system ] ; then
		systemd-tmpfiles --create /usr/lib/tmpfiles.d/apt-cacher-ng.conf >/dev/null || true
	fi
fi
# End automatically added section
# Automatically added by dh_installinit/11.1.4ubuntu1
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
	if [ -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
 |