source: scripts/funcs/tarball-funcs.sh@ 8a3554d

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 8a3554d was 61c0e64, checked in by Jim Gifford <clfs@…>, 19 years ago

r568@server (orig r566): ryan | 2005-06-09 08:36:17 -0700
Several changes

  • Handle tar.Z files (use zcat)
  • add a -no-remove option to unpack_tarball and fix the OK message to display the tarball name, not ${1}



  • Property mode set to 100755
File size: 7.3 KB
Line 
1#!/bin/bash
2#
3# Tarball handling functions for cross-lfs build
4# -----------------------------------------------
5# $LastChangedBy$
6# $LastChangedDate$
7# $LastChangedRevision$
8# $HeadURL$
9#
10
11# Check for stuff
12#----------------
13
14# Check for a grep which takes -E
15for dir in "" /bin/ /usr/bin/ /usr/xpg4/bin/ /usr/local/bin/ ; do
16 echo X | ${dir}grep -E X > /dev/null 2>&1 &&
17 {
18 export GREP="${dir}grep"
19 break
20 }
21done
22
23if [ "${GREP}" = "" ]; then
24 echo "install a grep on the system that handles -E"
25 exit 1
26fi
27
28fetch() {
29
30 # find and fetch files with wget by using the google "I'm feeling lucky" search
31 #------------------------------------------------------------------------------
32 # Many, many thanks to Glenn Sommer <glemsom_at_hotpop.com> for this damn cool
33 # bit of scriptage ;-)
34 #
35 # Probably a bit more sanity checking wouldn't go astray... but hey ;-)
36
37 if [ -z "${1}" ]; then
38 echo "fetch: error, no file specified" 2>&1
39 return 1
40 fi
41
42 echo -n " o searching for ${1} tarball ... "
43
44 # We search for "Index of" - hoping to catch some ftp server
45 # And then we search for the filename
46 google_lucky_search="http://www.google.com/search?hl=en&q=%22Index+of%22+${1}&btnI=I%27m+Feeling+Lucky&meta="
47
48 location=`wget -c -U Mozilla ${google_lucky_search} 2>&1 |
49 grep Location | \
50 head -n 1 | \
51 sed -e 's/Location: \(.*\) \[following\].*$/\1/'`
52 rm -f index.html
53
54 if [ -z "${location}" ]; then
55 echo "failed"
56 return 1
57 fi
58
59 echo -e "found"
60 echo " o retrieving ${location}${1}"
61 wget -c ${location}${1} 2>&1
62
63}
64
65fetch_tarball() { # ${1} should be a package name w version
66 for type in tar.bz2 tar.gz tgz tar.Z tar bleh; do
67 # if the following is true, we failed in our mission
68 if [ "${type}" = "bleh" ]; then return 1 ; fi
69 fetch ${1}.${type}
70 if [ "${?}" = "0" ]; then return 0 ; fi
71 done
72}
73
74unpack_tarball() { # ${1}=<package-${PACKAGE_VER}> ${2}
75 local pkgname=${1}
76 shift
77 local filelist="${@}"
78
79 # Check if -no-remove option is set
80 echo ${filelist} | grep \\-no-remove > /dev/null 2>&1 &&
81 {
82 local no_remove=Y
83 filelist=`echo ${filelist} | sed 's@-no-remove@@g'`
84 }
85
86 # Easier add of .tgz
87
88 # if PACKAGE_VER was not set for this package, warn but exit with no error.
89 # this is so we can disable the build of a package by not exporting its
90 # PACKAGE_VER variable in plfs-packages
91 echo "${pkgname}" | ${GREP} -E \\-$ > /dev/null 2>&1
92 if [ "${?}" = 0 ]; then
93 echo "unpack_tarball: skipping script ${0}, package version not set"
94 exit 0
95 fi
96
97 local archive=`ls -t ${TARBALLS}/${pkgname}* 2> /dev/null | \
98 ${GREP} -E ${pkgname}.\(tgz\|tar.gz\|tar.bz2\|tar.Z\|tar\)$ | head -n 1`
99
100 if [ -z ${archive} ]; then
101 echo "unpack_tarball: unable to locate tarball for '${pkgname}' in ${TARBALLS} ... exiting"
102 exit 1
103 fi
104
105 case ${archive} in
106 *.gz | *.tgz ) local CAT="gzip -dc" ;;
107 *.bz2 ) local CAT="bzcat" ;;
108 *.Z ) local CAT="zcat" ;;
109 *.tar ) local CAT="cat" ;;
110 * ) echo "unpack_tarball: unable to determine tarball type... exiting"
111 exit 1 ;;
112 esac
113
114 # May as well provide a method for passing back the directory the tarball
115 # unpacks to.
116 # Should save some trauma when a tarball doesn't extract to where is expected
117 # ( usually package-${PACKAGE_VER} but not always... )
118 # store in environment as PKGDIR.
119
120 echo -e "\n${BRKLN}"
121 echo -n "Checking tarball install directory... "
122 export PKGDIR=`${CAT} ${archive} | tar -tf - | \
123 head -n 1 | sed -e 's@^\./@@g' -e 's@/.*$@@g'`
124
125 if [ -z ${PKGDIR} ]; then
126 echo "Error: unable to determine tarball contents, exiting"
127 exit 1
128 else
129 echo "${PKGDIR}"
130 fi
131
132 # If we are not doing a full unpack of the tarball, don't delete ${PKGDIR}
133 if [ ! -z "${filelist}" ]; then
134 # prepend ${PKGDIR} to each required file
135 filelist=`echo ${filelist} | \
136 sed "s@\([-+_a-zA-Z0-9/.]* \?\)@${PKGDIR}/\1@g"`
137 elif [ -d ${PKGDIR} -a ! "${no_remove}" = "Y" ]; then
138 echo -n "Removing existing ${PKGDIR} directory... "
139 rm -rf ${PKGDIR} && echo "DONE" ||
140 echo "Error removing ${PKGDIR}... "; #return 1
141 fi
142
143
144 echo "Unpacking ${archive}"
145 ${CAT} ${archive} | tar -xf - ${filelist} 2> /dev/null &&
146 echo " o ${archive} unpacked successfully" ||
147 {
148 echo "unpack_tarball: unable to unpack tarball ${archive}... exiting"
149 exit 1
150 }
151
152 return 0
153}
154
155check_tarballs () {
156 # ${GREP}s through the either the calling script or the script(s)
157 # passed as args for calls to unpack_tarball.
158 # This function expects the scripts to be stored in ${SCRIPTS}.
159 #
160 # It will store the list of packages required in the list PKGS
161 # All will have their variable components unexpanded.
162
163 LIST=""
164 ARGS="${@}"
165 if [ ! -z "${ARGS}" ]; then
166 for script in ${ARGS}; do
167 if [ -f ${SCRIPTS}/${script} ]; then
168 LIST="${LIST} ${SCRIPTS}/${script}"
169 else
170 echo "check_tarballs: build script ${SCRIPTS}/${script} not found... skipping" 1>&2
171 fi
172 done
173 elif [ ! -z ${SELF} -a -f ${SCRIPTS}/${SELF} ]; then
174 LIST=${SCRIPTS}/${SELF}
175 fi
176
177 test -z "${LIST}" &&
178 {
179 echo "check_tarballs: no build scripts found... exiting"
180 exit 1
181 }
182
183 # Retrieve package defs from unpack_tarball calls into a list
184 local PKGS="$( cat ${LIST} | \
185 ${GREP} -E '^[[:blank:]]*unpack_tarball (\w|-)*\${\w*}' | \
186 awk '{print $2}' | sort -u )"
187
188 echo -e "\nChecking for required tarballs in ${TARBALLS}\n${BRKLN}"
189
190 # loop through list
191 for pkg in ${PKGS} ; do
192
193 # check if the ${PKG_VER} variable is set in plfs-config
194 # If not ignore the package
195 ver_var=`echo ${pkg} | sed 's@.*\(${.*}\).*@\1@g'`
196 eval ver=${ver_var}
197 if [ -z ${ver} ]; then continue ; fi
198
199 # do variable expansion on ${pkg}
200 eval pkgname=${pkg}
201 # check if this package is used
202 check_pkg_used ${pkgname} || continue
203 echo -n " o Looking for ${pkgname}... "
204 # check for the existence of the tarball
205 #local archive=`ls -t ${TARBALLS}/${pkgname}.@(tgz|tar.gz|tar.bz2) \
206 # 2> /dev/null | head -n 1`
207 local archive=`ls -t ${TARBALLS}/${pkgname}* 2> /dev/null | \
208 ${GREP} -E ${pkgname}.\(tgz\|tar.gz\|tar.bz2\|tar.Z\|tar\)$ | head -n 1`
209
210 if [ -z "${archive}" ]; then
211 echo "not found"
212
213 # Attempt to download it from the net
214 cd ${TARBALLS}
215 fetch_tarball ${pkgname} || {
216 echo -e "XXXXXX NOT FOUND: Unable to locate tarball for '${pkgname}' XXXXXX"
217 exit 1
218 }
219 else
220 echo -e "OK\n Found: ${archive}"
221 fi
222
223 done
224 echo -e " o ALL OK\n${BRKLN}\n"
225}
226
227# Following two functions are interim hacks for check_patches and
228# check_tarballs to get around conditional packages/patches
229# these will be revisited
230
231check_pkg_used () {
232 case ${1} in
233 glibc-linuxthreads* )
234 #test Y = "${USE_NPTL}" && return 1
235 return 1
236 ;;
237 nptl-* )
238 test Y = "${USE_NPTL}" || return 1
239 ;;
240 udev-* )
241 test Y = "${UDEV}" || return 1
242 ;;
243 esac
244 return 0
245}
246
247# Export functions
248export -f check_tarballs
249export -f fetch
250export -f fetch_tarball
251export -f unpack_tarball
252export -f check_pkg_used
253
Note: See TracBrowser for help on using the repository browser.