annotate sources/functions.sh @ 436:2ffa9dab13e5

Slightly improved display.
author Rob Landley <rob@landley.net>
date Fri, 31 Oct 2008 03:47:49 -0500
parents c88e25996320
children 59fe5a276991
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 # Lots of reusable functions. This file is sourced, not run.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
2
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 # Figure out if we're using the stable or unstable versions of a package.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
4
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 function unstable()
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 {
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
7 [ ! -z "$(echo ,"$USE_UNSTABLE", | grep ,"$1",)" ]
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
8 }
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
9
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
10 # Strip the version number off a tarball
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
11
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 function cleanup()
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 {
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
14
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
15 [ $? -ne 0 ] && dienow
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
16
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
17 for i in "$@"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
18 do
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
19 unstable "$i" && i="$PACKAGE"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 echo "cleanup $i"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
21 rm -rf "$i" || dienow
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 done
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 }
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
24
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 # Give filename.tar.ext minus the version number.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
26
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
27 function noversion()
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
28 {
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
29 echo "$1" | sed -e 's/-*\(\([0-9\.]\)*\([_-]rc\)*\(-pre\)*\([0-9][a-zA-Z]\)*\)*\(\.tar\..z2*\)$/'"$2"'\6/'
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
30 }
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
31
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
32 # Give package name, minus file's version number and archive extension.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
33
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
34 function basename()
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
35 {
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
36 noversion $1 | sed 's/\.tar\..z2*$//'
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
37 }
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
38
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
39 # output the sha1sum of a file
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
40 function sha1file()
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
41 {
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
42 sha1sum "$@" | awk '{print $1}'
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
43 }
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
44
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
45 # Extract tarball named in $1 and apply all relevant patches into
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
46 # "$BUILD/sources/$1". Record sha1sum of tarball and patch files in
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
47 # sha1-for-source.txt. Re-extract if tarball or patches change.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
48
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
49 function extract()
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
50 {
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
51 SRCTREE="${BUILD}/sources"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
52 BASENAME="$(basename "$1")"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
53 SHA1FILE="$(echo "${SRCTREE}/${BASENAME}/sha1-for-source.txt")"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
54 SHA1TAR="$(sha1file "${SRCDIR}/$1")"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
55
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
56 # Sanity check: don't ever "rm -rf /". Just don't.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
57
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
58 if [ -z "$BASENAME" ] || [ -z "$SRCTREE" ]
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
59 then
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
60 dienow
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
61 fi
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
62
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
63 # If it's already extracted and up to date (including patches), do nothing.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
64 SHALIST=$(cat "$SHA1FILE" 2> /dev/null)
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
65 if [ ! -z "$SHALIST" ]
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
66 then
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
67 for i in "$SHA1TAR" $(sha1file "${SOURCES}/patches/$BASENAME"* 2>/dev/null)
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
68 do
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
69 # Is this sha1 in the file?
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
70 if [ -z "$(echo "$SHALIST" | sed -n "s/$i/$i/p" )" ]
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
71 then
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
72 SHALIST=missing
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
73 break
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
74 fi
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
75 # Remove it
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
76 SHALIST="$(echo "$SHALIST" | sed "s/$i//" )"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
77 done
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
78 # If we matched all the sha1sums, nothing more to do.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
79 [ -z "$SHALIST" ] && return 0
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
80 fi
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
81
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
82 echo -n "Extracting '${BASENAME}'"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
83 # Delete the old tree (if any). Create new empty working directories.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
84 rm -rf "${BUILD}/temp" "${SRCTREE}/${BASENAME}" 2>/dev/null
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
85 mkdir -p "${BUILD}"/{temp,sources} || dienow
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
86
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
87 # Is it a bzip2 or gzip tarball?
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
88 DECOMPRESS=""
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
89 [ "$1" != "${1/%\.tar\.bz2/}" ] && DECOMPRESS="j"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
90 [ "$1" != "${1/%\.tar\.gz/}" ] && DECOMPRESS="z"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
91
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
92 cd "${WORK}" &&
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
93 { tar -xv${DECOMPRESS} -f "${SRCDIR}/$1" -C "${BUILD}/temp" || dienow
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
94 } | dotprogress
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
95
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
96 mv "${BUILD}/temp/"* "${SRCTREE}/${BASENAME}" &&
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
97 rmdir "${BUILD}/temp" &&
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
98 echo "$SHA1TAR" > "$SHA1FILE"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
99
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
100 [ $? -ne 0 ] && dienow
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
101
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
102 # Apply any patches to this package
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
103
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
104 ls "${SOURCES}/patches/$BASENAME"* 2> /dev/null | sort | while read i
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
105 do
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
106 if [ -f "$i" ]
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
107 then
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
108 echo "Applying $i"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
109 (cd "${SRCTREE}/${BASENAME}" && patch -p1 -i "$i") || dienow
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
110 sha1file "$i" >> "$SHA1FILE"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
111 fi
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
112 done
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
113 }
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
114
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
115 function try_checksum()
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
116 {
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
117 SUM="$(sha1file "$SRCDIR/$FILENAME" 2>/dev/null)"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
118 if [ x"$SUM" == x"$SHA1" ] || [ -z "$SHA1" ] && [ -f "$SRCDIR/$FILENAME" ]
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
119 then
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
120 touch "$SRCDIR/$FILENAME"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
121 if [ -z "$SHA1" ]
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
122 then
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
123 echo "No SHA1 for $FILENAME ($SUM)"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
124 else
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
125 echo "Confirmed $FILENAME"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
126 fi
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
127
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
128 [ -z "$EXTRACT_ALL" ] && return 0
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
129 extract "$FILENAME"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
130 return $?
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
131 fi
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
132
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
133 return 1
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
134 }
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
135
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
136
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
137 function try_download()
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
138 {
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
139 # Return success if we have a valid copy of the file
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
140
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
141 try_checksum && return 0
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
142
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
143 # If there's a corrupted file, delete it. In theory it would be nice
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
144 # to resume downloads, but wget creates "*.1" files instead.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
145
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
146 rm "$SRCDIR/$FILENAME" 2> /dev/null
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
147
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
148 # If we have another source, try to download file.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
149
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
150 if [ -n "$1" ]
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
151 then
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
152 wget -t 2 -T 20 -O "$SRCDIR/$FILENAME" "$1" || return 2
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
153 fi
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
154
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
155 try_checksum
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
156 }
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
157
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
158 # Confirm a file matches sha1sum, else try to download it from mirror list.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
159
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
160 function download()
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
161 {
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
162 FILENAME=`echo "$URL" | sed 's .*/ '`
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
163 ALTFILENAME=alt-"$(noversion "$FILENAME" -0)"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
164
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
165 # Is there an unstable version to download, and is it selected?
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
166 if [ ! -z "$UNSTABLE" ] && unstable "$(basename "$FILENAME")"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
167 then
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
168 # Keep old version around, if present.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
169 touch -c "$SRCDIR/$FILENAME" 2>/dev/null
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
170
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
171 # Download new one as alt-packagename.tar.ext
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
172 FILENAME="$ALTFILENAME" SHA1= try_download "$UNSTABLE"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
173 return $?
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
174 fi
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
175
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
176 # If environment variable specifies a preferred mirror, try that first.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
177
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
178 if [ ! -z "$PREFERRED_MIRROR" ]
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
179 then
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
180 try_download "$PREFERRED_MIRROR/$FILENAME" && return 0
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
181 fi
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
182
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
183 # Try standard locations
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
184
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
185 for i in "$URL" http://impactlinux.com/firmware/mirror/"$FILENAME" \
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
186 http://landley.net/code/firmware/mirror/"$FILENAME"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
187 do
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
188 try_download "$i" && return 0
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
189 done
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
190
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
191 # Return failure.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
192
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
193 echo "Could not download $FILENAME"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
194 echo -en "\e[0m"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
195 return 1
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
196 }
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
197
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
198 # Clean obsolete files out of the source directory
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
199
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
200 START_TIME=`date +%s`
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
201
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
202 function cleanup_oldfiles()
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
203 {
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
204 for i in "${SRCDIR}"/*
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
205 do
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
206 if [ -f "$i" ] && [ "$(date +%s -r "$i")" -lt "${START_TIME}" ]
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
207 then
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
208 echo Removing old file "$i"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
209 rm -rf "$i"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
210 fi
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
211 done
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
212 }
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
213
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
214 # An exit function that works properly even from a subshell.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
215
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
216 function actually_dienow()
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
217 {
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
218 echo -e "\e[31mExiting due to errors\e[0m"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
219 exit 1
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
220 }
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
221
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
222 trap actually_dienow SIGUSR1
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
223 TOPSHELL=$$
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
224
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
225 function dienow()
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
226 {
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
227 kill -USR1 $TOPSHELL
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
228 exit 1
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
229 }
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
230
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
231 # Turn a bunch of output lines into a much quieter series of periods.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
232
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
233 function dotprogress()
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
234 {
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
235 x=0
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
236 while read i
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
237 do
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
238 x=$[$x + 1]
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
239 if [[ "$x" -eq 25 ]]
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
240 then
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
241 x=0
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
242 echo -n .
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
243 fi
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
244 done
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
245 echo
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
246 }
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
247
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
248 # Extract package $1, use out-of-tree build directory $2 (or $1 if no $2)
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
249 # Use link directory $3 (or $1 if no $3)
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
250
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
251 function setupfor()
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
252 {
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
253 export WRAPPY_LOGPATH="$WRAPPY_LOGDIR/cmdlines.${STAGE_NAME}.setupfor"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
254
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
255 # Figure out whether we're using an unstable package.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
256
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
257 PACKAGE="$1"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
258 unstable "$PACKAGE" && PACKAGE=alt-"$PACKAGE"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
259
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
260 # Make sure the source is already extracted and up-to-date.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
261 cd "${SRCDIR}" &&
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
262 extract "${PACKAGE}-"*.tar* || exit 1
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
263
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
264 # Set CURSRC
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
265 CURSRC="$PACKAGE"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
266 if [ ! -z "$3" ]
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
267 then
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
268 CURSRC="$3"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
269 unstable "$CURSRC" && CURSRC=alt-"$CURSRC"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
270 fi
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
271 export CURSRC="${WORK}/${CURSRC}"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
272
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
273 # Announce package, with easy-to-grep-for "===" marker.
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
274
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
275 echo "=== Building $PACKAGE ($ARCH_NAME)"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
276 echo "Snapshot '$PACKAGE'..."
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
277 cd "${WORK}" || dienow
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
278 if [ $# -lt 3 ]
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
279 then
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
280 rm -rf "${CURSRC}" || dienow
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
281 fi
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
282 mkdir -p "${CURSRC}" &&
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
283 cp -lfR "${SRCTREE}/$PACKAGE/"* "${CURSRC}"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
284
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
285 [ $? -ne 0 ] && dienow
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
286
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
287 # Do we have a separate working directory?
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
288
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
289 if [ -z "$2" ]
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
290 then
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
291 cd "$PACKAGE"* || dienow
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
292 else
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
293 mkdir -p "$2" && cd "$2" || dienow
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
294 fi
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
295 export WRAPPY_LOGPATH="$WRAPPY_LOGDIR/cmdlines.${STAGE_NAME}.$1"
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
296
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
297 # Change window title bar to package now
436
2ffa9dab13e5 Slightly improved display.
Rob Landley <rob@landley.net>
parents: 428
diff changeset
298 echo -en "\033]2;Building $ARCH_NAME $STAGE_NAME $PACKAGE\007"
428
c88e25996320 Split function definitions out from include.sh.
Rob Landley <rob@landley.net>
parents:
diff changeset
299 }