annotate sources/download_functions.sh @ 1253:d4b251e78fc0

Break out download_functions.sh into their own file.
author Rob Landley <rob@landley.net>
date Sat, 25 Sep 2010 14:10:23 -0500
parents
children 1461d20bb6a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1253
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 #!/bin/echo "This file is sourced, not run"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
2
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 # Give filename.tar.ext minus the version number.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
4
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 noversion()
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 {
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
7 echo "$1" | sed -e 's/-*\(\([0-9\.]\)*\([_-]rc\)*\(-pre\)*\([0-9][a-zA-Z]\)*\)*\(\.tar\..z2*\)$/'"$2"'\6/'
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
8 }
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
9
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
10 # Apply any patches to this package
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 patch_package()
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 {
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 ls "$PATCHDIR/${PACKAGE}"-* 2> /dev/null | sort | while read i
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
14 do
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
15 if [ -f "$i" ]
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
16 then
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
17 echo "Applying $i"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 (cd "${SRCTREE}/${PACKAGE}" &&
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
19 patch -p1 -i "$i" &&
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 sha1file "$i" >> "$SHA1FILE") ||
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
21 ([ -z "$ALLOW_PATCH_FAILURE" ] && dienow)
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 fi
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 done
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
24 }
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
25
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
26 # Extract tarball named in $1 and apply all relevant patches into
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
27 # "$BUILD/packages/$1". Record sha1sum of tarball and patch files in
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
28 # sha1-for-source.txt. Re-extract if tarball or patches change.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
29
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
30 extract_package()
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
31 {
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
32 mkdir -p "$SRCTREE" || dienow
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
33
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
34 # Figure out whether we're using an unstable package.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
35
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
36 PACKAGE="$1"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
37 is_in_list "$PACKAGE" $USE_UNSTABLE && PACKAGE=alt-"$PACKAGE"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
38
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
39 # Announce to the world that we're cracking open a new package
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
40
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
41 echo "=== $PACKAGE ($ARCH_NAME $STAGE_NAME)"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
42 set_titlebar "$ARCH_NAME $STAGE_NAME $PACKAGE"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
43
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
44 # Find tarball, and determine type
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
45
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
46 FILENAME="$(ls -tc "$SRCDIR/${PACKAGE}-"*.tar* 2>/dev/null | head -n 1)"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
47 DECOMPRESS=""
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
48 [ "$FILENAME" != "${FILENAME/%\.tar\.bz2/}" ] && DECOMPRESS="j"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
49 [ "$FILENAME" != "${FILENAME/%\.tar\.gz/}" ] && DECOMPRESS="z"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
50
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
51 # If the source tarball doesn't exist, but the extracted directory is there,
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
52 # assume everything's ok.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
53
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
54 SHA1FILE="$SRCTREE/$PACKAGE/sha1-for-source.txt"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
55 if [ -z "$FILENAME" ]
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
56 then
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
57 [ ! -e "$SRCTREE/$PACKAGE" ] && dienow "No tarball for $PACKAGE"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
58
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
59 # If the sha1sum file isn't there, re-patch the package.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
60 [ ! -e "$SHA1FILE" ] && patch_package
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
61 return 0
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
62 fi
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
63
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
64 # Check the sha1 list from the previous extract. If the source is already
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
65 # up to date (including patches), keep it.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
66
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
67 SHA1TAR="$(sha1file "$FILENAME")"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
68 SHALIST=$(cat "$SHA1FILE" 2> /dev/null)
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
69 if [ ! -z "$SHALIST" ]
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
70 then
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
71 for i in "$SHA1TAR" $(sha1file "$PATCHDIR/$PACKAGE"-* 2>/dev/null)
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
72 do
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
73 # Is this sha1 in the file?
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
74 if [ -z "$(echo "$SHALIST" | sed -n "s/$i/$i/p" )" ]
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
75 then
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
76 SHALIST=missing
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
77 break
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
78 fi
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
79 # Remove it
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
80 SHALIST="$(echo "$SHALIST" | sed "s/$i//" )"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
81 done
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
82 # If we matched all the sha1sums, nothing more to do.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
83 [ -z "$SHALIST" ] && return 0
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
84 fi
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
85
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
86 # Re-extract the package, deleting the old one (if any)..
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
87
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
88 echo -n "Extracting '$PACKAGE'"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
89 (
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
90 UNIQUE=$(readlink /proc/self)
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
91 trap 'rm -rf "$BUILD/temp-'$UNIQUE'"' EXIT
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
92 rm -rf "$SRCTREE/$PACKAGE" 2>/dev/null
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
93 mkdir -p "$BUILD"/{temp-$UNIQUE,packages} || dienow
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
94
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
95 { tar -xv${DECOMPRESS} -f "$FILENAME" -C "$BUILD/temp-$UNIQUE" || dienow
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
96 } | dotprogress
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
97
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
98 mv "$BUILD/temp-$UNIQUE/"* "$SRCTREE/$PACKAGE" &&
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
99 echo "$SHA1TAR" > "$SHA1FILE"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
100 )
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
101
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
102 [ $? -ne 0 ] && dienow
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
103
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
104 patch_package
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
105 }
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
106
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
107 # Confirm that a file has the appropriate checksum (or exists but SHA1 is blank)
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
108 # Delete invalid file.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
109
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
110 confirm_checksum()
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
111 {
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
112 SUM="$(sha1file "$SRCDIR/$FILENAME" 2>/dev/null)"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
113 if [ x"$SUM" == x"$SHA1" ] || [ -z "$SHA1" ] && [ -f "$SRCDIR/$FILENAME" ]
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
114 then
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
115 if [ -z "$SHA1" ]
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
116 then
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
117 echo "No SHA1 for $FILENAME ($SUM)"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
118 else
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
119 echo "Confirmed $FILENAME"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
120 fi
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
121
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
122 # Preemptively extract source packages?
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
123
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
124 [ -z "$EXTRACT_ALL" ] && return 0
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
125 extract_package "$BASENAME"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
126 return $?
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
127 fi
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
128
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
129 # If there's a corrupted file, delete it. In theory it would be nice
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
130 # to resume downloads, but wget creates "*.1" files instead.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
131
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
132 rm "$SRCDIR/$FILENAME" 2> /dev/null
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
133
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
134 return 1
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
135 }
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
136
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
137 # Attempt to obtain file from a specific location
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
138
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
139 download_from()
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
140 {
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
141 # Return success if we already have a valid copy of the file
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
142
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
143 confirm_checksum && return 0
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
144
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
145 # If we have another source, try to download file from there.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
146
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
147 [ -z "$1" ] && return 1
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
148 wget -t 2 -T 20 -O "$SRCDIR/$FILENAME" "$1" ||
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
149 (rm "$SRCDIR/$FILENAME"; return 2)
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
150 touch -c "$SRCDIR/$FILENAME"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
151
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
152 confirm_checksum
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
153 }
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
154
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
155 # Confirm a file matches sha1sum, else try to download it from mirror list.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
156
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
157 download()
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
158 {
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
159 FILENAME=`echo "$URL" | sed 's .*/ '`
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
160 [ -z "$RENAME" ] || FILENAME="$(echo "$FILENAME" | sed -r "$RENAME")"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
161 ALTFILENAME=alt-"$(noversion "$FILENAME" -0)"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
162
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
163 echo -ne "checking $FILENAME\r"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
164
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
165 # Update timestamps on both stable and unstable tarballs (if any)
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
166 # so cleanup_oldfiles doesn't delete stable when we're building unstable
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
167 # or vice versa
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
168
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
169 touch -c "$SRCDIR"/{"$FILENAME","$ALTFILENAME"} 2>/dev/null
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
170
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
171 # Give package name, minus file's version number and archive extension.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
172 BASENAME="$(noversion "$FILENAME" | sed 's/\.tar\..z2*$//')"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
173
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
174 # If unstable version selected, try from listed location, and fall back
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
175 # to PREFERRED_MIRROR. Do not try normal mirror locations for unstable.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
176
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
177 if is_in_list "$BASENAME" $USE_UNSTABLE
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
178 then
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
179 # If extracted source directory exists, don't download alt-tarball.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
180 [ -e "$SRCTREE/alt-$BASENAME" ] && return 0
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
181
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
182 # Download new one as alt-packagename.tar.ext
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
183 FILENAME="$ALTFILENAME"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
184 SHA1=
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
185
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
186 ([ ! -z "$PREFERRED_MIRROR" ] &&
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
187 download_from "$PREFERRED_MIRROR/$ALTFILENAME") ||
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
188 download_from "$UNSTABLE"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
189 return $?
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
190 fi
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
191
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
192 # If environment variable specifies a preferred mirror, try that first.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
193
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
194 if [ ! -z "$PREFERRED_MIRROR" ]
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
195 then
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
196 download_from "$PREFERRED_MIRROR/$FILENAME" && return 0
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
197 fi
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
198
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
199 # Try original location, then mirrors.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
200 # Note: the URLs in mirror list cannot contain whitespace.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
201
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
202 download_from "$URL" && return 0
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
203 for i in $MIRROR_LIST
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
204 do
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
205 download_from "$i/$FILENAME" && return 0
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
206 done
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
207
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
208 # Return failure.
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
209
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
210 echo "Could not download $FILENAME"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
211 echo -en "\e[0m"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
212 return 1
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
213 }
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
214
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
215 # Clean obsolete files out of the source directory
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
216
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
217 START_TIME=`date +%s`
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
218
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
219 cleanup_oldfiles()
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
220 {
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
221 # wait for asynchronous downloads to complete
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
222
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
223 wait
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
224
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
225 for i in "${SRCDIR}"/*
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
226 do
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
227 if [ -f "$i" ] && [ "$(date +%s -r "$i")" -lt "${START_TIME}" ]
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
228 then
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
229 echo Removing old file "$i"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
230 rm -rf "$i"
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
231 fi
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
232 done
d4b251e78fc0 Break out download_functions.sh into their own file.
Rob Landley <rob@landley.net>
parents:
diff changeset
233 }