comparison sources/functions.sh @ 676:112dc7b787d3

Fix hg 665 so it actually works. (Make setupfor work when build/sources/package exists but there's no packages/package-*.tar* file.)
author Rob Landley <rob@landley.net>
date Mon, 30 Mar 2009 03:26:45 -0500
parents e7eb5123258c
children 3c09987974c8
comparison
equal deleted inserted replaced
675:4571f63c2298 676:112dc7b787d3
77 # "$BUILD/sources/$1". Record sha1sum of tarball and patch files in 77 # "$BUILD/sources/$1". Record sha1sum of tarball and patch files in
78 # sha1-for-source.txt. Re-extract if tarball or patches change. 78 # sha1-for-source.txt. Re-extract if tarball or patches change.
79 79
80 function extract() 80 function extract()
81 { 81 {
82 FILENAME="$1"
82 SRCTREE="${BUILD}/sources" 83 SRCTREE="${BUILD}/sources"
83 BASENAME="$(basename "$1")" 84 SHA1FILE="$(echo "${SRCTREE}/${PACKAGE}/sha1-for-source.txt")"
84 SHA1FILE="$(echo "${SRCTREE}/${BASENAME}/sha1-for-source.txt")"
85 SHA1TAR="$(sha1file "${SRCDIR}/$1")"
86 85
87 # Sanity check: don't ever "rm -rf /". Just don't. 86 # Sanity check: don't ever "rm -rf /". Just don't.
88 87
89 if [ -z "$BASENAME" ] || [ -z "$SRCTREE" ] 88 if [ -z "$PACKAGE" ] || [ -z "$SRCTREE" ]
90 then 89 then
91 dienow 90 dienow
92 fi 91 fi
93 92
94 # If the source tarball doesn't exist, but the extracted directory is there, 93 # If the source tarball doesn't exist, but the extracted directory is there,
95 # assume everything's ok. 94 # assume everything's ok.
96 95
97 [ ! -e "$1" ] && [ -e "$SHA1FILE" ] && return 0 96 [ ! -e "$FILENAME" ] && [ -e "$SHA1FILE" ] && return 0
97
98 SHA1TAR="$(sha1file "${SRCDIR}/${FILENAME}")"
98 99
99 # If it's already extracted and up to date (including patches), do nothing. 100 # If it's already extracted and up to date (including patches), do nothing.
100 SHALIST=$(cat "$SHA1FILE" 2> /dev/null) 101 SHALIST=$(cat "$SHA1FILE" 2> /dev/null)
101 if [ ! -z "$SHALIST" ] 102 if [ ! -z "$SHALIST" ]
102 then 103 then
103 for i in "$SHA1TAR" $(sha1file "${SOURCES}/patches/$BASENAME"-* 2>/dev/null) 104 for i in "$SHA1TAR" $(sha1file "${SOURCES}/patches/${PACKAGE}"-* 2>/dev/null)
104 do 105 do
105 # Is this sha1 in the file? 106 # Is this sha1 in the file?
106 if [ -z "$(echo "$SHALIST" | sed -n "s/$i/$i/p" )" ] 107 if [ -z "$(echo "$SHALIST" | sed -n "s/$i/$i/p" )" ]
107 then 108 then
108 SHALIST=missing 109 SHALIST=missing
113 done 114 done
114 # If we matched all the sha1sums, nothing more to do. 115 # If we matched all the sha1sums, nothing more to do.
115 [ -z "$SHALIST" ] && return 0 116 [ -z "$SHALIST" ] && return 0
116 fi 117 fi
117 118
118 echo -n "Extracting '${BASENAME}'" 119 echo -n "Extracting '${PACKAGE}'"
119 # Delete the old tree (if any). Create new empty working directories. 120 # Delete the old tree (if any). Create new empty working directories.
120 rm -rf "${BUILD}/temp" "${SRCTREE}/${BASENAME}" 2>/dev/null 121 rm -rf "${BUILD}/temp" "${SRCTREE}/${PACKAGE}" 2>/dev/null
121 mkdir -p "${BUILD}"/{temp,sources} || dienow 122 mkdir -p "${BUILD}"/{temp,sources} || dienow
122 123
123 # Is it a bzip2 or gzip tarball? 124 # Is it a bzip2 or gzip tarball?
124 DECOMPRESS="" 125 DECOMPRESS=""
125 [ "$1" != "${1/%\.tar\.bz2/}" ] && DECOMPRESS="j" 126 [ "$FILENAME" != "${FILENAME/%\.tar\.bz2/}" ] && DECOMPRESS="j"
126 [ "$1" != "${1/%\.tar\.gz/}" ] && DECOMPRESS="z" 127 [ "$FILENAME" != "${FILENAME/%\.tar\.gz/}" ] && DECOMPRESS="z"
127 128
128 cd "${WORK}" && 129 cd "${WORK}" &&
129 { tar -xv${DECOMPRESS} -f "${SRCDIR}/$1" -C "${BUILD}/temp" || dienow 130 { tar -xv${DECOMPRESS} -f "${SRCDIR}/${FILENAME}" -C "${BUILD}/temp" || dienow
130 } | dotprogress 131 } | dotprogress
131 132
132 mv "${BUILD}/temp/"* "${SRCTREE}/${BASENAME}" && 133 mv "${BUILD}/temp/"* "${SRCTREE}/${PACKAGE}" &&
133 rmdir "${BUILD}/temp" && 134 rmdir "${BUILD}/temp" &&
134 echo "$SHA1TAR" > "$SHA1FILE" 135 echo "$SHA1TAR" > "$SHA1FILE"
135 136
136 [ $? -ne 0 ] && dienow 137 [ $? -ne 0 ] && dienow
137 138
138 # Apply any patches to this package 139 # Apply any patches to this package
139 140
140 ls "${SOURCES}/patches/$BASENAME"-* 2> /dev/null | sort | while read i 141 ls "${SOURCES}/patches/${PACKAGE}"-* 2> /dev/null | sort | while read i
141 do 142 do
142 if [ -f "$i" ] 143 if [ -f "$i" ]
143 then 144 then
144 echo "Applying $i" 145 echo "Applying $i"
145 (cd "${SRCTREE}/${BASENAME}" && patch -p1 -i "$i") || dienow 146 (cd "${SRCTREE}/${PACKAGE}" && patch -p1 -i "$i") || dienow
146 sha1file "$i" >> "$SHA1FILE" 147 sha1file "$i" >> "$SHA1FILE"
147 fi 148 fi
148 done 149 done
149 } 150 }
150 151
160 else 161 else
161 echo "Confirmed $FILENAME" 162 echo "Confirmed $FILENAME"
162 fi 163 fi
163 164
164 [ -z "$EXTRACT_ALL" ] && return 0 165 [ -z "$EXTRACT_ALL" ] && return 0
165 extract "$FILENAME" 166 PACKAGE="$(basename "$FILENAME")" extract "$FILENAME"
166 return $? 167 return $?
167 fi 168 fi
168 169
169 return 1 170 return 1
170 } 171 }