Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /config/trunk/unpack
ViewVC logotype

Annotation of /config/trunk/unpack

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2159 - (view) (download)

1 : mblume 1355 #!/bin/sh
2 :     #
3 :     # This script was extracted from install.sh and deals with the fetching
4 :     # and unpacking of source/bootfile trees. The first argument must be
5 :     # the installation root directory. Subsequent arguments are the names
6 :     # of modules whose source trees are required.
7 :     #
8 :     # (C) 2003 The Fellowship of SML/NJ
9 :     #
10 :     # Author: Matthias Blume (blume@tti-c.org)
11 :     #
12 :    
13 :     this=$0
14 :     ROOT=$1
15 :     shift
16 :    
17 :     CONFIGDIR=$ROOT/config
18 :    
19 : mblume 1725 VERSION=`cat "$CONFIGDIR"/version`
20 :     . "$CONFIGDIR"/srcarchiveurl
21 : mblume 1355
22 :     vsay() {
23 :     if [ x${INSTALL_DEBUG} = xtrue ] ; then
24 :     echo "$@"
25 :     elif [ x${INSTALL_QUIETLY} = xtrue ] ; then
26 :     :
27 :     else
28 :     echo "$@"
29 :     fi
30 :     }
31 :    
32 :     #
33 :     # Function for asking user to fetch source archive.
34 :     # $1 - descriptive name
35 :     # $2 - base name without extension, without version, and without dir
36 :     # $3 - remote directory
37 :     #
38 :     askurl() {
39 : mblume 1385 echo "$this: Please, fetch $1 archive"
40 : mblume 1355 echo ' ('$2.'*' or $VERSION-$2.'*)'
41 :     echo " from $3"
42 :     echo " and then re-run this script!"
43 :     exit 1
44 :     }
45 :    
46 :     #
47 :     # Function for fetching source archives automatically using wget or lynx.
48 :     # $1 - command to actually get the stuff
49 :     # $2 - descriptive name
50 :     # $3 - base name without extension and without dir
51 :     # $4 - remote directory
52 :     #
53 :     fetchurl() {
54 :     getter=$1 ; shift
55 :     vsay $this: Fetching $1 from $3. Please stand by...
56 :     fetched=no
57 :     for base in $2 $VERSION-$2 ; do
58 :     for ext in tgz tar.gz tar.Z tz tar tar.bz2 ; do
59 :     try=$base.$ext
60 :     vsay $this: Trying $try ...
61 : mblume 1725 if "$getter" "$3"/"$try" "$ROOT"/"$try" ; then
62 : mblume 1355 fetched=yes
63 :     vsay $this: Fetching $try was a success.
64 :     break 2 # get out of both for-loops
65 :     else
66 : mblume 1725 rm -f "$ROOT"/"$try"
67 : mblume 1355 fi
68 :     done
69 :     done
70 :     if [ $fetched = no ] ; then
71 :     echo $this: Fetching $try was no success.
72 :     echo ' ' You should try to do it manually now.
73 :     askurl "$1" "$2" "$3"
74 :     fi
75 :     }
76 :    
77 :     # wrapper for wget
78 :     usewget() {
79 : mblume 1725 wget -nv -O "$2" "$1"
80 : mblume 1355 }
81 :    
82 :     # wrapper for lynx
83 :     uselynx() {
84 : mblume 1725 lynx -source "$1" >"$2"
85 : mblume 1355 }
86 :    
87 :     # wrapper for curl
88 :     usecurl() {
89 : mblume 1725 curl -s "$1" >"$2"
90 : mblume 1355 }
91 :    
92 :     testurlgetter() {
93 :     (exec >/dev/null 2>&1 ; exec $*)
94 :     }
95 :    
96 :     #
97 :     # Function to check whether wget or lynx is available.
98 :     # Set URLGETTER accordingly. URLGETTER can be set externally
99 :     # to either 'wget' or 'curl' or 'lynx' -- in which case the
100 :     # corresponding command will be used (properly wrapped). Any
101 :     # other external setting will be passed directly to fetchurl (without
102 :     # wrapping -- meaning it must take precisely two argumets: source and
103 :     # destination, in that order).
104 :     #
105 :     urlgetter() {
106 :     case ${URLGETTER:-unknown} in
107 :     fetchurl*)
108 :     ;;
109 :     unknown)
110 :     # automatically figure out which wrapper to use
111 :     if testurlgetter wget --help ; then
112 :     URLGETTER="fetchurl usewget"
113 :     elif testurlgetter curl -s -O file:///dev/null -o /dev/null ; then
114 :     URLGETTER="fetchurl usecurl"
115 :     elif testurlgetter lynx -help ; then
116 :     URLGETTER="fetchurl uselynx"
117 :     else
118 :     URLGETTER="askurl"
119 :     fi
120 :     ;;
121 :     wget|curl|lynx)
122 :     # special getters we know how to wrap
123 :     URLGETTER="fetchurl use${URLGETTER}"
124 :     ;;
125 :     *)
126 :     # other -- must be able to work without wrapper
127 :     URLGETTER="fetchurl ${URLGETTER}"
128 :     ;;
129 :     esac
130 :     }
131 :    
132 :     # wrapper for tar
133 :     un_tar() {
134 :     vsay "$this: Un-TAR-ing $1 archive."
135 : mblume 1725 tar -xf "$2"
136 : mblume 1355 }
137 :    
138 :     # wrapper for zcat followed by tar
139 :     un_tar_Z() {
140 :     vsay "$this: Un-COMPRESS-ing and un-TAR-ing $1 archive."
141 : mblume 1725 zcat "$2" | tar -xf -
142 : mblume 1355 }
143 :    
144 :     # wrapper for gunzip followed by tar
145 :     un_tar_gz() {
146 :     vsay "$this: Un-GZIP-ing and un-TAR-ing $1 archive."
147 : mblume 1725 gunzip -c "$2" | tar -xf -
148 : mblume 1355 }
149 :    
150 :     # wrapper for bunzip2 followed by tar
151 :     un_tar_bz2() {
152 :     vsay "$this: Un-BZIP2-ing and un-TAR-ing $1 archive."
153 : mblume 1725 bunzip2 -c "$2" | tar -xf -
154 : mblume 1355 }
155 :    
156 :     # unarchive archive without and with version number attached
157 :     unarchive() {
158 :     # $1: descriptive string, $2: archive, $3: unpacker
159 : mblume 1725 if [ -r "$ROOT"/"$2" ] ; then
160 :     "$3" "$1" "$ROOT"/"$2"
161 :     elif [ -r "$ROOT"/"$VERSION"-"$2" ]; then
162 :     $3 "$1" "$ROOT"/"$VERSION"-"$2"
163 : mblume 1355 else
164 :     return 1
165 :     fi
166 :     }
167 :    
168 :     #
169 :     # Function to unpack a source archive.
170 :     #
171 :     # $1: descriptive name of the sources to be unpacked
172 :     # $2: the directory into which to unpack the sources
173 :     # $3: the sub-directory of $2 that is going to be created by unpacking
174 :     # $4: the basename of the source archive (the script will check several
175 :     # different suffixes to determine what kind of de-compression is to
176 :     # be used)
177 :     #
178 :     # fetch_n_unpack is the helper function that does the real work. If
179 :     # no archive is found locally, it invokes $URLGETTER and tries again.
180 :     # The variable $tryfetch is used to make sure this happens only once.
181 :     fetch_n_unpack() {
182 : mblume 1725 cd "$2"
183 :     if unarchive "$1" "$4".tgz un_tar_gz ||
184 :     unarchive "$1" "$4".tar.gz un_tar_gz ||
185 :     unarchive "$1" "$4".tar.Z un_tar_Z ||
186 :     unarchive "$1" "$4".tar un_tar ||
187 :     unarchive "$1" "$4".tar.bz2 un_tar_bz2 ||
188 :     unarchive "$1" "$4".tz un_tar_Z
189 : mblume 1355 then
190 :     : we are done
191 :     elif [ $tryfetch = yes ] ; then
192 :     urlgetter
193 : mblume 1725 $URLGETTER "$1" "$4" "$SRCARCHIVEURL"
194 : mblume 1355 tryfetch=no
195 :     fetch_n_unpack "$1" "$2" "$3" "$4"
196 :     fi
197 :     }
198 :    
199 :     #
200 :     # The main "unpack" driver function that invokes the above helper.
201 :     #
202 :     unpack() {
203 :     tryfetch=yes
204 : mblume 1725 if [ -d "$2"/"$3" ]; then
205 : mblume 1355 vsay "$this: The $1 tree already exists."
206 :     else
207 :     fetch_n_unpack "$1" "$2" "$3" "$4"
208 :     fi
209 : mblume 1725 if [ ! -d "$2"/"$3" ]; then
210 : mblume 1485 echo "$this: !!! Unable to unpack $1 archive."
211 :     exit 1
212 : mblume 1355 fi
213 :     }
214 :    
215 :     #
216 :     # Now do it:
217 :     #
218 :    
219 : mblume 1368 for i
220 :     do
221 : mblume 1725 case "$i" in
222 : mblume 1355 runtime)
223 : blume 2150 unpack run-time "$ROOT"/base/src runtime runtime
224 : mblume 1355 ;;
225 :     boot.*)
226 : mblume 1725 unpack bootfiles "$ROOT" sml.$i $i
227 : mblume 1355 ;;
228 : mblume 1485 compiler)
229 : blume 2150 unpack compiler "$ROOT"/base/src compiler compiler
230 : mblume 1355 ;;
231 : mblume 1485 cm)
232 : blume 2150 unpack compiler "$ROOT"/base/src cm cm
233 : mblume 1485 ;;
234 :     system)
235 : blume 2150 unpack compiler "$ROOT"/base/src system system
236 : mblume 1485 ;;
237 : mblume 1355 ml-yacc)
238 : blume 2150 unpack ML-Yacc "$ROOT" ml-yacc ml-yacc
239 : mblume 1355 ;;
240 :     ml-lex)
241 : blume 2150 unpack ML-Lex "$ROOT" ml-lex ml-lex
242 : mblume 1355 ;;
243 : mblume 1902 lexgen)
244 : blume 2150 unpack LexGen "$ROOT" lexgen lexgen
245 : mblume 1895 ;;
246 : mblume 1355 ml-burg)
247 : blume 2150 unpack ML-Burg "$ROOT" ml-burg ml-burg
248 : mblume 1355 ;;
249 :     ml-nlffigen)
250 : blume 2150 unpack ML-NLFFI-Gen "$ROOT" nlffi nlffi
251 : mblume 1355 ;;
252 :     nowhere)
253 : blume 2150 unpack "MLRISC Tools Library" "$ROOT" MLRISC MLRISC
254 : mblume 1355 ;;
255 :     smlnj-lib)
256 : blume 2150 unpack "SML/NJ Library" "$ROOT" smlnj-lib smlnj-lib
257 : mblume 1355 ;;
258 :     cml)
259 : blume 2150 unpack CML "$ROOT" cml cml
260 : mblume 1355 ;;
261 :     cml-lib)
262 : blume 2150 unpack CML "$ROOT" cml cml
263 : mblume 1355 ;;
264 :     eXene)
265 : blume 2150 unpack EXene "$ROOT" eXene eXene
266 : mblume 1355 ;;
267 :     ckit)
268 : mblume 1725 unpack "C-Kit" "$ROOT" ckit ckit
269 : mblume 1355 ;;
270 :     ml-nlffi-lib)
271 : blume 2150 unpack "NLFFI Library" "$ROOT" nlffi nlffi
272 : mblume 1355 ;;
273 :     pgraph-util)
274 : blume 2150 unpack "CM source code" "$ROOT"/base/src cm cm
275 : mblume 1355 ;;
276 :     mlrisc)
277 : blume 2150 unpack "MLRISC Library" "$ROOT" MLRISC MLRISC
278 : mblume 1355 ;;
279 :     mlrisc-tools)
280 : blume 2150 unpack "MLRISC Tools Library" "$ROOT" MLRISC MLRISC
281 : mblume 1355 ;;
282 : mblume 1485 smlnj-c)
283 : blume 2150 unpack "SML/NJ-C FFI" "$ROOT" smlnj-c smlnj-c
284 : mblume 1485 ;;
285 : mblume 1747 heap2asm)
286 : blume 2150 unpack "Heap->ASM tool" "$ROOT" heap2asm heap2asm
287 : mblume 1747 ;;
288 : mblume 1923 tools)
289 : blume 2150 unpack "debugging tools" "$ROOT"/base/src tools tools
290 : mblume 1923 ;;
291 : mblume 1355 doc)
292 :     echo Package doc is currently unavailable.
293 :     # unpack Doc $ROOT doc doc
294 :     # cd $ROOT/doc
295 :     # build $ROOT
296 :     ;;
297 :     *)
298 : mblume 1485 echo Unknown package: ${i}.
299 : blume 2159 echo Trying default method...
300 :     unpack ${i} "$ROOT" ${i} ${i}
301 : mblume 1355 ;;
302 :     esac
303 :     done
304 : mblume 1368
305 :     exit 0

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0