source: scripts/funcs/tarball-funcs.sh@ 0ee931e

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 0ee931e was 617118d, checked in by Jim Gifford <clfs@…>, 19 years ago

r561@server (orig r559): root | 2005-06-05 02:38:49 -0700
Fixed Directory Structure

  • Property mode set to 100755
File size: 7.0 KB
RevLine 
[617118d]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 bleh; do
67 fetch ${1}.${type}
68 if [ "${?}" = "0" ]; then return 0 ; fi
69 # if the following is true, we failed in our mission
70 if [ "${type}" = "bleh" ]; then return 1 ; fi
71 done
72}
73
74unpack_tarball() { # ${1}=<package-${PACKAGE_VER}> ${2}
75 local pkgname=${1}
76 shift
77 local filelist="${@}"
78 # Easier add of .tgz
79
80 # if PACKAGE_VER was not set for this package, warn but exit with no error.
81 # this is so we can disable the build of a package by not exporting its
82 # PACKAGE_VER variable in plfs-packages
83 echo "${pkgname}" | ${GREP} -E \\-$ > /dev/null 2>&1
84 if [ "${?}" = 0 ]; then
85 echo "unpack_tarball: skipping script ${0}, package version not set"
86 exit 0
87 fi
88
89 local archive=`ls -t ${TARBALLS}/${pkgname}* 2> /dev/null | \
90 ${GREP} -E ${pkgname}.\(tgz\|tar.gz\|tar.bz2\|tar\)$ | head -n 1`
91
92 if [ -z ${archive} ]; then
93 echo "unpack_tarball: unable to locate tarball for '${pkgname}' in ${TARBALLS} ... exiting"
94 exit 1
95 fi
96
97 case ${archive} in
98 *.gz | *.tgz ) local CAT="gzip -dc" ;;
99 *.bz2 ) local CAT="bzcat" ;;
100 *.tar ) local CAT="cat" ;;
101 * ) echo "unpack_tarball: unable to determine tarball type... exiting"
102 exit 1 ;;
103 esac
104
105 # May as well provide a method for passing back the directory the tarball
106 # unpacks to.
107 # Should save some trauma when a tarball doesn't extract to where is expected
108 # ( usually package-${PACKAGE_VER} but not always... )
109 # store in environment as PKGDIR.
110
111 echo -e "\n${BRKLN}"
112 echo -n "Checking tarball install directory... "
113 export PKGDIR=`${CAT} ${archive} | tar -tf - | \
114 head -n 1 | sed -e 's@^\./@@g' -e 's@/.*$@@g'`
115
116 if [ -z ${PKGDIR} ]; then
117 echo "Error: unable to determine tarball contents, exiting"
118 exit 1
119 else
120 echo "${PKGDIR}"
121 fi
122
123 # If we are not doing a full unpack of the tarball, don't delete ${PKGDIR}
124 if [ ! -z "${filelist}" ]; then
125 # prepend ${PKGDIR} to each required file
126 filelist=`echo ${filelist} | \
127 sed "s@\([-+_a-zA-Z0-9/.]* \?\)@${PKGDIR}/\1@g"`
128 elif [ -d ${PKGDIR} ]; then
129 echo -n "Removing existing ${PKGDIR} directory... "
130 rm -rf ${PKGDIR} && echo "DONE" ||
131 echo "Error removing ${PKGDIR}... "; #return 1
132 fi
133
134
135 echo "Unpacking ${archive}"
136 ${CAT} ${archive} | tar -xf - ${filelist} 2> /dev/null &&
137 echo " o ${1} unpacked successfully" ||
138 {
139 echo "unpack_tarball: unable to unpack tarball ${archive}... exiting"
140 exit 1
141 }
142
143 return 0
144}
145
146check_tarballs () {
147 # ${GREP}s through the either the calling script or the script(s)
148 # passed as args for calls to unpack_tarball.
149 # This function expects the scripts to be stored in ${SCRIPTS}.
150 #
151 # It will store the list of packages required in the list PKGS
152 # All will have their variable components unexpanded.
153
154 LIST=""
155 ARGS="${@}"
156 if [ ! -z "${ARGS}" ]; then
157 for script in ${ARGS}; do
158 if [ -f ${SCRIPTS}/${script} ]; then
159 LIST="${LIST} ${SCRIPTS}/${script}"
160 else
161 echo "check_tarballs: build script ${SCRIPTS}/${script} not found... skipping" 1>&2
162 fi
163 done
164 elif [ ! -z ${SELF} -a -f ${SCRIPTS}/${SELF} ]; then
165 LIST=${SCRIPTS}/${SELF}
166 fi
167
168 test -z "${LIST}" &&
169 {
170 echo "check_tarballs: no build scripts found... exiting"
171 exit 1
172 }
173
174 # Retrieve package defs from unpack_tarball calls into a list
175 local PKGS="$( cat ${LIST} | \
176 ${GREP} -E '^[[:blank:]]*unpack_tarball (\w|-)*\${\w*}' | \
177 awk '{print $2}' | sort -u )"
178
179 echo -e "\nChecking for required tarballs in ${TARBALLS}\n${BRKLN}"
180
181 # loop through list
182 for pkg in ${PKGS} ; do
183
184 # check if the ${PKG_VER} variable is set in plfs-config
185 # If not ignore the package
186 ver_var=`echo ${pkg} | sed 's@.*\(${.*}\).*@\1@g'`
187 eval ver=${ver_var}
188 if [ -z ${ver} ]; then continue ; fi
189
190 # do variable expansion on ${pkg}
191 eval pkgname=${pkg}
192 # check if this package is used
193 check_pkg_used ${pkgname} || continue
194 echo -n " o Looking for ${pkgname}... "
195 # check for the existence of the tarball
196 #local archive=`ls -t ${TARBALLS}/${pkgname}.@(tgz|tar.gz|tar.bz2) \
197 # 2> /dev/null | head -n 1`
198 local archive=`ls -t ${TARBALLS}/${pkgname}* 2> /dev/null | \
199 ${GREP} -E ${pkgname}.\(tgz\|tar.gz\|tar.bz2\|tar\)$ | head -n 1`
200
201 if [ -z "${archive}" ]; then
202 echo "not found"
203
204 # Attempt to download it from the net
205 cd ${TARBALLS}
206 fetch_tarball ${pkgname} || {
207 echo -e "XXXXXX NOT FOUND: Unable to locate tarball for '${pkgname}' XXXXXX"
208 exit 1
209 }
210 else
211 echo -e "OK\n Found: ${archive}"
212 fi
213
214 done
215 echo -e " o ALL OK\n${BRKLN}\n"
216}
217
218# Following two functions are interim hacks for check_patches and
219# check_tarballs to get around conditional packages/patches
220# these will be revisited
221
222check_pkg_used () {
223 case ${1} in
224 glibc-linuxthreads* )
225 #test Y = "${USE_NPTL}" && return 1
226 return 1
227 ;;
228 nptl-* )
229 test Y = "${USE_NPTL}" || return 1
230 ;;
231 udev-* )
232 test Y = "${UDEV}" || return 1
233 ;;
234 esac
235 return 0
236}
237
238# Export functions
239export -f check_tarballs
240export -f fetch
241export -f fetch_tarball
242export -f unpack_tarball
243export -f check_pkg_used
244
Note: See TracBrowser for help on using the repository browser.