Mercurial > hg > aboriginal
comparison include.sh @ 236:9c48cf5b65f6
Teach extract to check patch files for changes, not just tarballs.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 30 Oct 2007 03:49:48 -0500 |
parents | 8b0d2080707c |
children | 735ee8a5ca35 |
comparison
equal
deleted
inserted
replaced
235:c0d9e91f528b | 236:9c48cf5b65f6 |
---|---|
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Strip the version number off a tarball | |
4 | |
3 function noversion() | 5 function noversion() |
4 { | 6 { |
5 echo "$1" | sed -r -e 's/-*([0-9\.]|[_-]rc|-pre|[0-9][a-zA-Z])*(\.tar\..z2*)$/\2/' | 7 echo "$1" | sed -r -e 's/-*([0-9\.]|[_-]rc|-pre|[0-9][a-zA-Z])*(\.tar\..z2*)$/\2/' |
6 } | 8 } |
9 | |
10 # output the sha1sum of a file | |
11 function sha1file() | |
12 { | |
13 sha1sum "$1" | awk '{print $1}' | |
14 } | |
15 | |
16 # Extract tarball named in $1 and apply all relevant patches into | |
17 # "$BUILD/sources/$1". Record sha1sum of tarball and patch files in | |
18 # sha1-for-source.txt. Re-extract if tarball or patches change. | |
7 | 19 |
8 function extract() | 20 function extract() |
9 { | 21 { |
10 SRCTREE="${BUILD}/sources" | 22 SRCTREE="${BUILD}/sources" |
11 BASENAME=`noversion "$1"` | 23 BASENAME=`noversion "$1"` |
12 BASENAME="${BASENAME/%\.tar\.*/}" | 24 BASENAME="${BASENAME/%\.tar\.*/}" |
25 SHA1FILE="$(echo "${SRCTREE}/${BASENAME}/sha1-for-source.txt")" | |
26 SHA1TAR="$(sha1file "$1")" | |
13 | 27 |
14 # Sanity check: don't ever "rm -rf /". Just don't. | 28 # Sanity check: don't ever "rm -rf /". Just don't. |
15 | 29 |
16 if [ -z "$BASENAME" ] || [ -z "$SRCTREE" ] | 30 if [ -z "$BASENAME" ] || [ -z "$SRCTREE" ] |
17 then | 31 then |
18 dienow | 32 dienow |
19 fi | 33 fi |
20 | 34 |
21 # If it's already extracted, do nothing. | 35 # If it's already extracted and up to date (including patches), do nothing. |
22 if [ -f "${SRCTREE}/${BASENAME}/sha1-for-source.txt" ] | 36 SHALIST=$(cat "$SHA1FILE" 2> /dev/null) |
23 then | 37 if [ ! -z "$SHALIST" ] |
24 SHA2="$(cat "${SRCTREE}/${BASENAME}/sha1-for-source.txt" 2>/dev/null)" | 38 then |
25 if [ -z "$2" ] || [ "$2" == "$SHA2" ] | 39 for i in "$SHA1TAR" $(sha1sum "${SOURCES}/patches/$BASENAME"* 2>/dev/null | awk '{print $1}') |
26 then | 40 do |
27 return 0 | 41 # Is this sha1 in the file? |
28 fi | 42 [ -z "$(echo "$SHALIST" | sed -n "s/$i/$i/p" )" ] && break |
29 fi | 43 # Remove it |
30 | 44 SHALIST="$(echo "$SHALIST" | sed "s/$i//" )" |
45 done | |
46 # If we matched all the sha1sums, nothing more to do. | |
47 [ -z "$SHALIST" ] && return 0 | |
48 fi | |
49 | |
50 echo -n "Extracting '${BASENAME}'" | |
51 # Delete the old tree (if any). Create new empty working directories. | |
31 rm -rf "${BUILD}/temp" "${SRCTREE}/${BASENAME}" 2>/dev/null | 52 rm -rf "${BUILD}/temp" "${SRCTREE}/${BASENAME}" 2>/dev/null |
32 mkdir -p "${BUILD}"/{temp,sources} || dienow | 53 mkdir -p "${BUILD}"/{temp,sources} || dienow |
33 | 54 |
34 # Is it a bzip2 or gzip tarball? | 55 # Is it a bzip2 or gzip tarball? |
35 DECOMPRESS="" | 56 DECOMPRESS="" |
36 [ "$1" != "${1/%\.tar\.bz2/}" ] && DECOMPRESS="j" | 57 [ "$1" != "${1/%\.tar\.bz2/}" ] && DECOMPRESS="j" |
37 [ "$1" != "${1/%\.tar\.gz/}" ] && DECOMPRESS="z" | 58 [ "$1" != "${1/%\.tar\.gz/}" ] && DECOMPRESS="z" |
38 | 59 |
39 echo -n "Extracting '${BASENAME}'" && | |
40 cd "${WORK}" && | 60 cd "${WORK}" && |
41 { tar xv${DECOMPRESS}fC "${SRCDIR}/$1" "${BUILD}/temp" || dienow | 61 { tar xv${DECOMPRESS}fC "${SRCDIR}/$1" "${BUILD}/temp" || dienow |
42 } | dotprogress | 62 } | dotprogress |
43 | 63 |
44 mv "${BUILD}/temp/"* "${SRCTREE}/${BASENAME}" && | 64 mv "${BUILD}/temp/"* "${SRCTREE}/${BASENAME}" && |
45 rmdir "${BUILD}/temp" && | 65 rmdir "${BUILD}/temp" && |
46 echo "$2" > "${SRCTREE}/${BASENAME}/sha1-for-source.txt" | 66 echo "$SHA1TAR" > "$SHA1FILE" |
47 | 67 |
48 [ $? -ne 0 ] && dienow | 68 [ $? -ne 0 ] && dienow |
49 | 69 |
50 # Apply any patches to this package | 70 # Apply any patches to this package |
51 | 71 |
53 do | 73 do |
54 if [ -f "$i" ] | 74 if [ -f "$i" ] |
55 then | 75 then |
56 echo "Applying $i" | 76 echo "Applying $i" |
57 (cd "${SRCTREE}/${BASENAME}" && patch -p1 -i "$i") || dienow | 77 (cd "${SRCTREE}/${BASENAME}" && patch -p1 -i "$i") || dienow |
78 sha1sum "$i" | awk '{print $1}' >> "$SHA1FILE" | |
58 fi | 79 fi |
59 done | 80 done |
60 } | 81 } |
61 | 82 |
62 function download() | 83 function download() |
82 else | 103 else |
83 echo "Confirmed $FILENAME" | 104 echo "Confirmed $FILENAME" |
84 fi | 105 fi |
85 if [ ! -z "$EXTRACT_ALL" ] | 106 if [ ! -z "$EXTRACT_ALL" ] |
86 then | 107 then |
87 extract "$FILENAME" "$SUM" | 108 extract "$FILENAME" |
88 fi | 109 fi |
89 return 0 | 110 return 0 |
90 fi | 111 fi |
91 | 112 |
92 # If there's a corrupted file, delete it. In theory it would be nice | 113 # If there's a corrupted file, delete it. In theory it would be nice |
149 # Extract package $1, use out-of-tree build directory $2 (or $1 if no $2) | 170 # Extract package $1, use out-of-tree build directory $2 (or $1 if no $2) |
150 # Use symlink directory $3 (or $1 if no $3) | 171 # Use symlink directory $3 (or $1 if no $3) |
151 | 172 |
152 function setupfor() | 173 function setupfor() |
153 { | 174 { |
154 # Make sure the | 175 # Make sure the source is already extracted and up-to-date. |
155 cd "${SRCDIR}" && | 176 cd "${SRCDIR}" && |
156 extract "${1}-"*.tar* "" | 177 extract "${1}-"*.tar* |
157 | 178 |
158 # Set CURSRC | 179 # Set CURSRC |
159 | 180 |
160 export CURSRC="$1" | 181 export CURSRC="$1" |
161 [ ! -z "$3" ] && CURSRC="$3" | 182 [ ! -z "$3" ] && CURSRC="$3" |