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
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
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
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
71
if ! test -r $udefault || grep -q "^[[:space:]]*$sig[[:space:]]*$" $udefault ; then
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
85
pick_ubuntu_mirrors() {
87
headlen=$(grep -n "^$sig$" "$1" 2>/dev/null | cut -f2 -d: | tail -n1)
89
if ! test "$headlen" ; then
90
return # not for us, changed or removed by user
82
guess_ubuntu_mirrors() {
95
# may hit a local mirror
86
if [ ! "$http_proxy" ] ; then
87
prx=$(apt-config dump | grep Acquire::http::Proxy | cut -f2 -d'"') || true
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
# 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
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
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
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
129
134
if [ "$1" = "configure" ]; then
131
adduser --quiet --system --group --no-create-home --home $CDIR $NAME
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
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
144
for x in $CDIR $LDIR ; do
134
145
if [ ! -d "$x" ]; then
135
146
install -d -g $NAME -o $NAME -m2755 "$x"