File: 50mirror

package info (click to toggle)
apt-setup 1%3A0.20etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 956 kB
  • ctags: 8
  • sloc: sh: 479; makefile: 26
file content (137 lines) | stat: -rwxr-xr-x 2,862 bytes parent folder | download
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
#!/bin/sh
set -e

. /usr/share/debconf/confmodule

file="$1"

log() {
	logger -t apt-setup "$@"
}
warning() {
	log "warning: $@"
}

# Ask if a mirror should be used if the base system can be installed from CD.
if [ -e /cdrom/.disk/base_installable ]; then
	if search-path choose-mirror; then
		db_input high apt-setup/use_mirror || [ $? -eq 30 ]
		db_go || exit 10
	else
		warning "choose-mirror is not available; cannot offer network mirror"
		exit 1
	fi

	db_get apt-setup/use_mirror
	if [ "$RET" = false ]; then
		exit 1
	fi

	# Default suite to codename; choose-mirror will determine actual suite
	if db_get cdrom/codename && [ "$RET" ]; then
		db_set mirror/suite $RET
	fi
	choose-mirror -n # no progress bar
fi

# Abort if no mirror is configured.
db_get mirror/protocol
protocol="$RET"
db_get mirror/codename
codename="$RET"
db_get mirror/$protocol/hostname
hostname="$RET"
db_get mirror/$protocol/directory
directory="/${RET#/}"
if [ -z "$hostname" ] || [ -z "$directory" ]; then
	exit 1
fi

STATE=1
while true; do
	case "$STATE" in
		1)
			db_input low apt-setup/non-free || true
		;;
		2)
			# If they chose not to use non-free, ask about
			# contrib, with a default of no. If they chose to
			# use non-free, they get contrib too..
			db_get apt-setup/non-free
			if [ "$RET" = false ]; then
				db_fget apt-setup/contrib seen
				if [ "$RET" = false ]; then
					db_set apt-setup/contrib false
				fi
				db_input low apt-setup/contrib || true
			else
				db_fget apt-setup/contrib seen
				if [ "$RET" = false ]; then
					db_set apt-setup/contrib true
				fi
			fi
		;;
		*)
			break
		;;
	esac

	if db_go; then
		STATE=$(($STATE + 1))
	else
		STATE=$(($STATE - 1))
	fi
done
if [ $STATE -eq 0 ]; then
	exit 10
fi

dists="main"
db_get apt-setup/non-free
if [ "$RET" = true ]; then
	dists="$dists non-free"
fi
db_get apt-setup/contrib
if [ "$RET" = true ]; then
	dists="$dists contrib"
fi

done=""
while [ ! "$done" ]; do
	db_get mirror/codename
	codename="$RET"
	db_get mirror/protocol
	protocol="$RET"
	db_get mirror/$protocol/hostname
	hostname="$RET"
	db_get mirror/$protocol/directory
	directory="/${RET#/}"

	if [ "$protocol" = http ]; then
		db_get mirror/$protocol/proxy
		proxy="$RET"
		if [ -n "$proxy" ]; then
			if ! grep -iq "Acquire::$protocol::Proxy" $ROOT/etc/apt/apt.conf.new; then
				echo "Acquire::$protocol::Proxy \"$proxy\";" >> $ROOT/etc/apt/apt.conf.new
			fi
		fi
	fi

	echo "deb $protocol://$hostname$directory $codename $dists" > $file
	
	if apt-setup-verify $file; then
		done=1
	else
		db_set apt-setup/mirror/error Retry
		db_input critical apt-setup/mirror/error || true
		db_go || exit 10
		db_get apt-setup/mirror/error
		if [ "$RET" = "Change mirror" ]; then
			choose-mirror || true
		elif [ "$RET" = Ignore ]; then
			exit 1
		fi
	fi
done

echo "deb-src $protocol://$hostname$directory $codename $dists" >> $file