Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 80148 | Differences between
and this patch

Collapse All | Expand All

(-)/usr/sbin/emerge-webrsync (-51 / +130 lines)
Lines 4-9 Link Here
4
# $Header: /var/cvsroot/gentoo-src/portage/bin/Attic/emerge-webrsync,v 1.8.2.3 2005/01/17 16:38:22 jstubbs Exp $
4
# $Header: /var/cvsroot/gentoo-src/portage/bin/Attic/emerge-webrsync,v 1.8.2.3 2005/01/17 16:38:22 jstubbs Exp $
5
# Author: Karl Trygve Kalleberg <karltk@gentoo.org>
5
# Author: Karl Trygve Kalleberg <karltk@gentoo.org>
6
# Rewritten from the old, Perl-based emerge-webrsync script
6
# Rewritten from the old, Perl-based emerge-webrsync script
7
# Snapshot date verification etc added by James Roberts-Thomson
8
9
showhelp() {
10
	echo "Usage: $0 [-v] [-n|-N], where:"
11
	echo "          -v indicates verbose wgets"
12
	echo "          -n prevents downloading, just looks for previously downloaded snapshot"
13
	exit 1
14
}
15
16
invalid_parameter() {
17
	echo "Error: \"${_cmd_options}\" is not a valid parameter."
18
	echo ""
19
	showhelp
20
}
21
22
store_date() {
23
	if [ ! -d "/var/lib/portage" ]; then mkdir -p /var/lib/portage; fi
24
	echo $1 > /var/lib/portage/webrsync-date
25
}
26
27
check_date() {
28
	if [ -f "/var/lib/portage/webrsync-date" ]; then
29
		if [ "$1" == "`cat /var/lib/portage/webrsync-date`" ]; then
30
			exit 1
31
		else
32
			exit 0
33
		fi
34
	else
35
		exit 0
36
	fi 
37
}
38
39
found=0
40
attempts=0
41
download=1
42
_optv=0
43
_optn=0
44
45
# Iterate through any command-line options (if supplied), and set appropriate variables
46
for _cmd_options do
47
	case "${_cmd_options}" in
48
	-v) _optv=1 ;;
49
	-n) _optn=1 ;;
50
	-\?|-h|-H) showhelp;;
51
	*) invalid_parameter;;
52
	esac
53
done
7
54
8
GENTOO_MIRRORS="${GENTOO_MIRRORS} $(/usr/lib/portage/bin/portageq gentoo_mirrors)"
55
GENTOO_MIRRORS="${GENTOO_MIRRORS} $(/usr/lib/portage/bin/portageq gentoo_mirrors)"
9
PORTDIR="$(/usr/lib/portage/bin/portageq portdir)"
56
PORTDIR="$(/usr/lib/portage/bin/portageq portdir)"
Lines 17-24 fi Link Here
17
64
18
cd "$DISTDIR"
65
cd "$DISTDIR"
19
66
20
found=0
67
if [ "${_optv}" = "1" ] ; then
21
if [ "$1" == "-v" ] ; then
22
	wgetops=
68
	wgetops=
23
else	
69
else	
24
	#this sucks.  probably better to do 1> /dev/null
70
	#this sucks.  probably better to do 1> /dev/null
Lines 30-35 else Link Here
30
	fi
76
	fi
31
fi
77
fi
32
78
79
if [ "${_optn}" = "1" ] ; then
80
	download=0
81
fi
82
33
if type -p md5sum > /dev/null; then
83
if type -p md5sum > /dev/null; then
34
	md5_com='md5sum -c "${FILE}.md5sum"'
84
	md5_com='md5sum -c "${FILE}.md5sum"'
35
elif type -p md5 > /dev/null; then
85
elif type -p md5 > /dev/null; then
Lines 48-53 sync_local() { Link Here
48
		exit 1
98
		exit 1
49
	fi
99
	fi
50
	rm -f $FILE
100
	rm -f $FILE
101
	rm -f ${FILE}.md5sum
51
	# Make sure user and group file ownership is root
102
	# Make sure user and group file ownership is root
52
	chown -R 0:0 portage
103
	chown -R 0:0 portage
53
	cd portage
104
	cd portage
Lines 61-67 sync_local() { Link Here
61
	emerge metadata
112
	emerge metadata
62
}
113
}
63
114
64
echo "Fetching most recent snapshot"
115
get_md5file() {
116
	if [  ! -s "${FILE_ORIG}.md5sum" ]; then
117
		FILE_ORIG="${FILE}"
118
		FILE="${FILE}.md5sum"
119
		for i in $GENTOO_MIRRORS ; do 
120
			URI="${i}/snapshots/${FILE}"
121
			if (eval "$FETCHCOMMAND $wgetops") && [ -s "${FILE}" ]; then
122
				got_md5=1
123
				break
124
			fi
125
		done
126
	else
127
		got_md5=1
128
	fi
129
	FILE="${FILE_ORIG}"
130
}
131
132
if [ $download == 1 ]; then
133
	echo "Fetching most recent snapshot"
134
else
135
	echo "Using most recently downloaded snapshot"
136
fi
65
137
66
declare -i attempts=-1
138
declare -i attempts=-1
67
while (( $attempts <  40 )) ; do
139
while (( $attempts <  40 )) ; do
Lines 79-139 while (( $attempts < 40 )) ; do Link Here
79
		year=$(date -d "-$attempts day" +"%Y")
151
		year=$(date -d "-$attempts day" +"%Y")
80
	fi
152
	fi
81
153
82
	FILE_ORIG="portage-${year}${month}${day}.tar.bz2"
154
	if (check_date ${year}${month}${day})
155
	then
156
		FILE="portage-${year}${month}${day}.tar.bz2"
83
157
84
	echo "Attempting to fetch file dated: ${year}${month}${day}"
158
		[ "$_optn" == "0" ] && echo "Attempting to fetch file dated: ${year}${month}${day}"
85
		
86
	got_md5=0
87
159
88
	if [  ! -e "${FILE_ORIG}.md5sum" ]; then
160
		got_md5=0
89
		FILE="${FILE_ORIG}.md5sum"
161
90
		for i in $GENTOO_MIRRORS ; do 
162
		if [ "$download" = "1" ]
91
			URI="${i}/snapshots/${FILE}"
163
		then
92
			if (eval "$FETCHCOMMAND $wgetops") && [ -s "${FILE}" ]; then
164
			get_md5file
93
				got_md5=1
165
94
				break
166
			if (($got_md5 == 0 )); then
167
				echo " --- No md5sum present on the mirror. (Not yet available.)"
168
				continue
95
			fi
169
			fi
96
		done
97
	else
98
		got_md5=1
99
	fi
100
	FILE="${FILE_ORIG}"
101
170
102
	if (($got_md5 == 0 )); then
171
			for i in $GENTOO_MIRRORS ; do
103
		echo " --- No md5sum present on the mirror. (Not yet available.)"
172
				URI="${i}/snapshots/$FILE"
104
		continue
173
				rm -f "$FILE"
105
	elif [ -s "${FILE}" ]; then
174
				if (eval "$FETCHCOMMAND $wgetops") && [ -s "$FILE" ]; then
106
		if eval "$md5_com"; then
175
					if ! eval "$md5_com"; then
107
			echo " === snapshot $FILE is correct, using it"
176
						echo "md5 failed on $FILE"
108
			sync_local
177
						rm ${FILE}
109
			echo
178
						rm ${FILE}.md5sum
110
			echo " === Snapshot has beed sync'd"
179
						continue
111
			echo
180
					else
112
			exit 0
181
						sync_local
182
						echo
183
						echo " *** Completed websync, please now perform a normal rsync if possible."
184
						echo "     Update is current as of the of YYYYMMDD: ${year}${month}${day}"
185
						echo
186
						exit 0
187
					fi
188
				fi
189
			done
113
		else
190
		else
114
			rm $FILE
191
			if [ -s "${FILE}" ]
115
		fi
192
			then
116
	fi
193
				echo " === found snapshot $FILE"
117
	
194
				if [ ! -s "${FILE}.md5sum" ]; then
118
	for i in $GENTOO_MIRRORS ; do
195
					echo " === no MD5 checksum, trying to fetch one"
119
		URI="${i}/snapshots/$FILE"
196
					get_md5file
120
		rm -f "$FILE"
197
				fi
121
		if (eval "$FETCHCOMMAND $wgetops") && [ -s "$FILE" ]; then
198
				if eval "$md5_com"; then
122
			if ! eval "$md5_com"; then
199
					echo " === snapshot $FILE is correct, using it"
123
				echo "md5 failed on $FILE"
200
					sync_local
124
				rm ${FILE}
201
					echo
125
				continue
202
					echo " === Snapshot has beed sync'd"
126
			else
203
					echo
127
				sync_local
204
					exit 0
128
				echo
205
				else
129
				echo " *** Completed websync, please now perform a normal rsync if possible."
206
					echo " === unable to verify snapshot $FILE, removing it"
130
				echo "     Update is current as of the of YYYYMMDD: ${year}${month}${day}"
207
					rm $FILE
131
				echo
208
					rm -f ${FILE}.md5sum
132
				exit 0
209
				fi
133
			fi
210
			fi
134
		fi
211
		fi
135
212
	else
136
	done
213
		echo "Earlier snapshot date reached - aborting"
214
		attempts=999
215
	fi
137
done
216
done
138
217
139
rm -rf portage
218
rm -rf portage

Return to bug 80148