~pi-rho/+junk/apt-cacher-ng-debian

« back to all changes in this revision

Viewing changes to debian/apt-cacher-ng.postinst

  • Committer: pi-rho
  • Date: 2013-11-03 01:37:10 UTC
  • Revision ID: ubuntu@tyr.cx-20131103013710-1efj7irlgact87hg
Tags: 0.7.19-1ubuntu1~ppa2~uuu
packaging updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
CFG=/etc/apt-cacher-ng
11
11
DDIR=/usr/lib/apt-cacher-ng
12
12
VDIR=/var/lib/apt-cacher-ng
 
13
udefault=$VDIR/backends_ubuntu.default
 
14
ddefault=$VDIR/backends_debian.default
13
15
 
14
 
gen_mirror_list() {
 
16
gen_mirror_list_from_sources_list() {
15
17
 
16
18
   tmpfile="$1.dpkg-new"
17
19
 
59
61
 
60
62
set_def_files() {
61
63
 
62
 
   # ftp.debian.org is a geodns location, should be good as-is
63
 
   if ! test -r $VDIR/backends_debian.default ; then
64
 
      echo "$def_file_header" > $VDIR/backends_debian.default
65
 
      # Debian mirrors are using geodns
66
 
      echo http://ftp.debian.org/debian/ >> $VDIR/backends_debian.default
67
 
   fi
68
 
 
69
 
   if ! test -r $VDIR/backends_ubuntu.default ; then
70
 
      echo "$def_file_header" > $VDIR/backends_ubuntu.default
71
 
      echo http://archive.ubuntu.com/ubuntu/ >> $VDIR/backends_ubuntu.default
72
 
   fi
73
 
 
74
 
   # try to find a more suitable fallback mirror
75
 
   if ! test -s $CFG/backends_ubuntu ; then
76
 
      pick_ubuntu_mirrors $VDIR/backends_ubuntu.default
77
 
   fi
78
 
 
79
 
   # silent fix of the broken file generated by the first versions of the mirror picking code
80
 
   if grep -q "^$sig$" $VDIR/backends_ubuntu.default && grep -q "^http://archive.ubuntu.com/?$" $VDIR/backends_ubuntu.default ; then
81
 
      sed "s,http://archive.ubuntu.com,http://archive.ubuntu.com/ubuntu," -i $VDIR/backends_ubuntu.default
 
64
   # if not readable or still has the signature
 
65
   if ! test -r $ddefault  || grep -q "^[[:space:]]*$sig[[:space:]]*$" $ddefault ; then
 
66
      echo "$def_file_header" > $ddefault
 
67
      # ftp.debian.org is a geodns mapped location, should be good as-is
 
68
      echo http://ftp.debian.org/debian/ >> $ddefault
 
69
   fi
 
70
 
 
71
   if ! test -r $udefault || grep -q "^[[:space:]]*$sig[[:space:]]*$" $udefault ; then
 
72
 
 
73
      guess_ubuntu_mirrors
 
74
 
 
75
      # silent fix of the broken file generated by the first versions of the mirror picking code
 
76
      if grep -q "^http://archive.ubuntu.com/?$" $udefault ; then
 
77
         sed "s,http://archive.ubuntu.com,http://archive.ubuntu.com/ubuntu," -i $udefault
 
78
      fi
82
79
   fi
83
80
}
84
81
 
85
 
pick_ubuntu_mirrors() {
86
 
 
87
 
   headlen=$(grep -n "^$sig$" "$1" 2>/dev/null | cut -f2 -d: | tail -n1)
88
 
 
89
 
   if ! test "$headlen" ; then
90
 
      return # not for us, changed or removed by user
91
 
   fi
 
82
guess_ubuntu_mirrors() {
92
83
   
93
84
   tmpfile="`mktemp`"
94
85
 
95
 
   # may hit a local mirror
 
86
   if [ ! "$http_proxy" ] ; then
 
87
      prx=$(apt-config dump | grep Acquire::http::Proxy | cut -f2 -d'"') || true
 
88
      if [ "$prx" ] ; then
 
89
         http_proxy="$prx"
 
90
         export http_proxy
 
91
      fi
 
92
   fi
 
93
 
 
94
   # may hit a local mirror which also hosts Debian, use it then
96
95
   sed -e 's,\([a-z]\)/.*,\1,' < $CFG/backends_debian | xargs -n1 -i grep "{}" $DDIR/ubuntu_mirrors > $tmpfile || true
97
96
 
 
97
   # mirror suggestions from Ubuntu's service might be a good candidate
 
98
   if ! test -s $tmpfile ; then
 
99
      mirurl=http://mirrors.ubuntu.com/mirrors.txt
 
100
      wget -q -O- $mirurl >> $tmpfile 2>/dev/null || curl -s $mirurl >> $tmpfile 2>/dev/null || true
 
101
   fi
 
102
 
 
103
   # still nothing. Sneak more information from Debian backend configuration?
98
104
   if ! test -s $tmpfile ; then # ok, go by Debian TLD
99
105
      grep debian.org/ /etc/apt-cacher-ng/backends_debian | \
100
106
         sed -e 's,^http://ftp[2-3]\?\.\([a-z][a-z]\).*,http://\1.archive.ubuntu.com/,' | \
101
107
         sort -u | xargs -n1 -i grep "{}" $DDIR/ubuntu_mirrors > $tmpfile || true
102
108
   fi
103
109
 
104
 
   if ! test -s $tmpfile ; then # ok, just any TLD
 
110
   if ! test -s $tmpfile ; then # ok, then try just any TLD
105
111
      sed -e 's,^http://\([^\/]\+\).*,\1,;s,.*\.\(.*\),http://\1.archive.ubuntu.com/,' < $CFG/backends_debian | \
106
112
         sort -u | xargs -n1 -i grep "{}" $DDIR/ubuntu_mirrors > $tmpfile || true
107
113
   fi
111
117
   fi
112
118
 
113
119
   if test -s $tmpfile ; then
114
 
      echo "$def_file_header" > $1
115
 
      cat $tmpfile >> $1
116
 
      # echo $- | grep x && cat $tmpfile || :
 
120
      echo "$def_file_header" > $udefault
 
121
      cat $tmpfile >> $udefault
117
122
   fi
118
123
 
119
124
   rm -f "$tmpfile" 2>/dev/null
121
126
}
122
127
 
123
128
gen_lists() {
124
 
   gen_mirror_list $CFG/backends_debian $DDIR/deb_mirrors.gz
125
 
   gen_mirror_list $CFG/backends_ubuntu $DDIR/ubuntu_mirrors
126
 
   gen_mirror_list $CFG/backends_debvol $DDIR/debvol_mirrors.gz
 
129
   gen_mirror_list_from_sources_list $CFG/backends_debian $DDIR/deb_mirrors.gz
 
130
   gen_mirror_list_from_sources_list $CFG/backends_ubuntu $DDIR/ubuntu_mirrors
 
131
   gen_mirror_list_from_sources_list $CFG/backends_debvol $DDIR/debvol_mirrors.gz
127
132
}
128
133
 
129
134
if [ "$1" = "configure" ]; then
130
135
 
131
 
   adduser --quiet --system --group --no-create-home --home $CDIR $NAME
132
 
 
133
 
   for x in $CDIR $LDIR ; do
 
136
   # least invasive cooperation with the old style behavior for now
 
137
   for cfn in backends_debvol backends_ubuntu backends_debian ; do
 
138
      test -e $CFG/$cfn || install -m644 /dev/null $CFG/$cfn
 
139
   done
 
140
 
 
141
   # user should exist. adduser sometimes fails (system range issue) but that's ok
 
142
   adduser --quiet --system --group --no-create-home --home $CDIR $NAME || id $NAME
 
143
 
 
144
   for x in $CDIR $LDIR ; do 
134
145
      if [ ! -d "$x" ]; then
135
146
         install -d -g $NAME -o $NAME -m2755 "$x"
136
147
      fi
154
165
 
155
166
   db_stop || true
156
167
 
 
168
   rm -f $CFG/in.acng $CFG/mount.acng
 
169
 
157
170
   if [ -z "$(dpkg-statoverride --list $CFG/security.conf)" ] ; then
158
171
      dpkg-statoverride --update --add apt-cacher-ng apt-cacher-ng 600 $CFG/security.conf
159
172
   fi