Skip to content

Commit a605123

Browse files
committed
Make scripts a bit more safe
1 parent d621595 commit a605123

File tree

6 files changed

+68
-54
lines changed

6 files changed

+68
-54
lines changed

building/linux64x64/squeak.cog.spur/build/mvm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22
set -e
3+
set -o pipefail
34
# Spur VM with VM profiler and threaded heartbeat
45
INSTALLDIR=sqcogspur64linuxht
56
# Some gcc versions create a broken VM using -O2
@@ -46,7 +47,7 @@ test -f config.h || ../../../../platforms/unix/config/configure --without-npsque
4647
LIBS="$LIBS" \
4748
LDFLAGS="$LDFLAGS"
4849
rm -f vm/sqUnixMain.o # nuke version info
49-
rm -rf ../../../../products/$INSTALLDIR
50+
rm -rf "../../../../products/$INSTALLDIR"
5051
# prefer make install prefix=`readlink -f \`pwd\`/../../../../products/$INSTALLDIR`
5152
# but older linux readlinks lack the -f flag
52-
make install-squeak install-plugins prefix=`(cd ../../../../;pwd)`/products/$INSTALLDIR 2>&1 | tee LOG ; test ${PIPESTATUS[0]} -eq 0
53+
make install-squeak install-plugins prefix="$(cd ../../../../;pwd)/products/$INSTALLDIR" 2>&1 | tee LOG

image/envvars.sh

100755100644
Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,47 @@ BASESISTA64=trunk6-sista-64
77

88
# N.B. uname -r (OSREL) is not to be trusted on Mac OS X;
99

10-
if test -x /usr/bin/uname; then
11-
OS=`/usr/bin/uname -s`
12-
CPU=`/usr/bin/uname -m`
13-
OSREL=`/usr/bin/uname -r | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*$/\1.\2.\3/'`
14-
elif test -x /bin/uname; then
15-
OS=`/bin/uname -s`
16-
CPU=`/bin/uname -m`
17-
OSREL=`/bin/uname -r | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*$/\1.\2.\3/'`
10+
if test -x uname; then
11+
OS=$(uname -s)
12+
CPU=$(uname -m)
13+
OSREL=$(uname -r | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*$/\1.\2.\3/')
14+
elif test -x uname; then
15+
OS=$(uname -s)
16+
CPU=$(uname -m)
17+
OSREL=$(uname -r | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*$/\1.\2.\3/')
1818
else
19-
OS=`uname -s`
20-
CPU=`uname -m`
21-
OSREL=`uname -r | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*$/\1.\2.\3/'`
19+
OS=$(uname -s)
20+
CPU=$(uname -m)
21+
OSREL=$(uname -r | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*$/\1.\2.\3/')
2222
fi
2323

24-
test "$OS" = Darwin && function quietmd5 { /sbin/md5 -q "$1" 2>/dev/null; }
25-
test "$OS" = Darwin || function quietmd5 { /usr/bin/md5sum "$1" | sed 's/ .*$//' 2>/dev/null; }
24+
function quietmd5() {
25+
if command -v md5 >/dev/null 2>&1; then
26+
# macOS / BSD
27+
md5 -q "$1" 2>/dev/null
28+
elif command -v md5sum >/dev/null 2>&1; then
29+
# Linux / BusyBox
30+
md5sum "$1" 2>/dev/null | cut -d ' ' -f 1
31+
else
32+
echo "quietmd5: neither md5 nor md5sum found in PATH" >&2
33+
return 1
34+
fi
35+
}
2636

27-
test "$OS" = Darwin && function geturl { FILE=`basename "$1"`; curl -C - "`echo $1 | sed 's/ /%20/g'`" -o "$FILE"; }
28-
test "$OS" = Darwin || function geturl { wget -c "$1"; }
37+
function geturl() {
38+
local url="$1"
2939

30-
if [ "$OS" != Darwin -a ! -x "`which wget`" ]; then
31-
echo "cannot find wget. wget for Windows is available from http://gnuwin32.sourceforge.net/packages/wget.htm, probably as http://downloads.sourceforge.net/gnuwin32/wget-1.11.4-1-setup.exe" 1>&2
32-
exit
33-
fi
40+
if command -v curl >/dev/null 2>&1; then
41+
curl -C - -O "$url"
42+
elif command -v wget >/dev/null 2>&1; then
43+
wget -c "$url"
44+
else
45+
echo "geturl: neither curl nor wget found in PATH" >&2
46+
return 1
47+
fi
48+
}
3449

35-
if unzip --help >/dev/null; then
36-
true
37-
else
50+
if ! command -v unzip >/dev/null 2>&1; then
3851
echo 'could not find unzip. you can find instructions on how to install it on google.' 1>&2;
3952
exit 1
4053
fi

image/getGoodSpur64VM.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LATEST_RELEASE_URL="$RELEASES_URL/latest"
1111

1212
for foo in once; do # allow break to jump to end of script
1313

14-
if [ "$1" = -vm -a -n "$2" -a -x "`which "$2"`" ]; then
14+
if [ "$1" = -vm -a -n "$2" -a -x "$(which "$2")" ]; then
1515
VM="$2"
1616
shift;shift
1717
else
@@ -74,7 +74,7 @@ else
7474
Darwin)
7575
if open $LATESTVM; then
7676
while [ ! -d "/Volumes/$VOLUME/$VMDIR" ]; do sleep 1; done
77-
rm -rf $VMDIR
77+
rm -rf "$VMDIR"
7878
cp -Rp "/Volumes/$VOLUME/$VMDIR" $VMDIR
7979
diskutil eject "/Volumes/$VOLUME"
8080
fi;;

image/getGoodSpurVM.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ else
3535
curl -L "$URL" -o "$LATESTVM"
3636
open $LATESTVM
3737
while [ ! -d "/Volumes/$VOLUME/Squeak.app" ]; do sleep 1; done
38-
rm -rf $VM
38+
rm -rf "$VM"
3939
cp -Rp "/Volumes/$VOLUME/Squeak.app" $VM
4040
diskutil eject "/Volumes/$VOLUME"
4141
fi
@@ -83,7 +83,7 @@ else
8383
echo curl -L "$URL" -o "$LATESTVM"
8484
curl -L "$URL" -o "$LATESTVM"
8585
unzip $LATESTVM -d sqwin.$LATESTRELEASE
86-
rm -f $LATESTVM
86+
rm -f "$LATESTVM"
8787
fi
8888
VM=sqwin.$LATESTRELEASE/SqueakConsole.exe;;
8989
*) echo "do not know how to download a VM for your system" 1>&2

image/getsqueak50.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ set -e
55
IMAGEHASH=e6be0ea204a8409dc0976a792502ab65
66
ZIPHASH=2f17e1d8eb9bec2b7554d3405652b122
77

8-
if [ "`quietmd5 \"$SQUEAK50\".image`" != $IMAGEHASH ]; then
8+
if [ "$(quietmd5 "$SQUEAK50".image)" != $IMAGEHASH ]; then
99
ZIP=Squeak-5.0-All-in-One.zip
10-
if [ "`quietmd5 $ZIP`" != $ZIPHASH ]
10+
if [ "$(quietmd5 $ZIP)" != $ZIPHASH ]
1111
then
1212
geturl http://files.squeak.org/5.0/$ZIP
1313
fi
@@ -21,4 +21,4 @@ if [ "`quietmd5 \"$SQUEAK50\".image`" != $IMAGEHASH ]; then
2121
unzip $ZIP
2222
rm -rf __MACOSX
2323
fi
24-
test -f SqueakV50.sources || ln $SQUEAK50RESOURCES/SqueakV50.sources .
24+
test -f SqueakV50.sources || ln "$SQUEAK50RESOURCES/SqueakV50.sources" .

platforms/unix/config/mkmf

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#!/bin/sh
22

33
# mkmf -- configure subdirectory Makefiles -*- sh -*-
4-
#
4+
#
55
# Copyright (C) 1996-2004 by Ian Piumarta and other authors/contributors
66
# listed elsewhere in this file.
77
# All rights reserved.
8-
#
8+
#
99
# This file is part of Unix Squeak.
10-
#
10+
#
1111
# Permission is hereby granted, free of charge, to any person obtaining a copy
1212
# of this software and associated documentation files (the "Software"), to deal
1313
# in the Software without restriction, including without limitation the rights
1414
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1515
# copies of the Software, and to permit persons to whom the Software is
1616
# furnished to do so, subject to the following conditions:
17-
#
17+
#
1818
# The above copyright notice and this permission notice shall be included in
1919
# all copies or substantial portions of the Software.
20-
#
20+
#
2121
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2222
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2323
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2424
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2525
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2626
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2727
# SOFTWARE.
28-
#
28+
#
2929
30-
#
30+
#
3131
# Last edited: Thu Jan 21 14:10:49 PST 2010 by eliot (add support for .cpp)
3232

3333
. ./config.sh
@@ -46,7 +46,7 @@ findDirs() {
4646
shift
4747
dirs=""
4848
while test $# -gt 0; do
49-
dirs="${dirs} ${prefix}`dirname $1`"
49+
dirs="${dirs} ${prefix}$(dirname "$1")"
5050
shift
5151
done
5252
echo ${dirs} | tr ' ' '\012' | sort | uniq | tr '\012' ' '
@@ -82,16 +82,16 @@ mkmf() {
8282
if test -d ${d}; then
8383
dd=${d}
8484
if test -f ${d}/mkmf.subdirs; then
85-
subdirs="`cat ${d}/mkmf.subdirs | tr '\012' ' '`"
85+
subdirs="$(cat ${d}/mkmf.subdirs | tr '\012' ' ')"
8686
for sd in ${subdirs}; do dd="${dd} ${topdir}/${sd}"; done
8787
fi
88-
srcs="${srcs} `findFiles .c ${dd}`"
89-
srcs="${srcs} `findFiles .cc ${dd}`"
90-
srcs="${srcs} `findFiles .cpp ${dd}`"
91-
srcs="${srcs} `findFiles .S ${dd}`"
92-
srcs="${srcs} `findFiles .s ${dd}`"
93-
srcs="${srcs} `findFiles .m ${dd}`"
94-
hdrs="${hdrs} `findFiles .h ${dd}`"
88+
srcs="${srcs} $(findFiles .c ${dd})"
89+
srcs="${srcs} $(findFiles .cc ${dd})"
90+
srcs="${srcs} $(findFiles .cpp ${dd})"
91+
srcs="${srcs} $(findFiles .S ${dd})"
92+
srcs="${srcs} $(findFiles .s ${dd})"
93+
srcs="${srcs} $(findFiles .m ${dd})"
94+
hdrs="${hdrs} $(findFiles .h ${dd})"
9595
# override Makefile.in
9696
if test -f "${d}/Makefile.in"; then
9797
makefile_in="${d}/Makefile.in"
@@ -103,8 +103,8 @@ mkmf() {
103103
test -f "${d}/Targets.exclude" && cat "${d}/Targets.exclude" >>${excluded}
104104
fi
105105
done
106-
srcs="`echo ${srcs} | tr ' ' '\012' | fgrep -v '*'`"
107-
hdrs="`echo ${hdrs} | tr ' ' '\012' | fgrep -v '*'`"
106+
srcs="$(echo ${srcs} | tr ' ' '\012' | fgrep -v '*')"
107+
hdrs="$(echo ${hdrs} | tr ' ' '\012' | fgrep -v '*')"
108108
# create targets and rules
109109
if test "${srcs}" != ""; then
110110
# objs is used to make the list of targets unique so that a platform can
@@ -114,7 +114,7 @@ mkmf() {
114114
# in the platform plugin dir)
115115
echo "" > ${objs}
116116
for c in ${srcs}; do
117-
o=`basename ${c} | sed 's,\.cp*,$o,;s,\.[msS],$o,'`
117+
o=$(basename ${c} | sed 's,\.cp*,$o,;s,\.[msS],$o,')
118118
grep -qs "^$o$" ${excluded} || grep -qs "^$o$" ${objs} || targets="${targets} ${o}"
119119
echo "$o" >>${objs}
120120
echo >> ${make_targets}
@@ -130,7 +130,7 @@ mkmf() {
130130
fi
131131
# create includes
132132
if test "${hdrs}" != ""; then
133-
includes="${includes} `findDirs -I ${hdrs}`"
133+
includes="${includes} $(findDirs -I ${hdrs})"
134134
fi
135135
# default Makefile.in if no override
136136
if test ! -f "${makefile_in}"; then
@@ -167,7 +167,7 @@ s%\[make_plg\]%%g
167167
s%\[plibs\]%${plibs}%g
168168
/\[make_targets\]/r ${make_targets}
169169
s%\[make_targets\]%%g" > ${name}/Makefile
170-
/bin/rm -f ${make_targets} makefile.in makefile.sub
170+
rm -f ${make_targets} makefile.in makefile.sub
171171
}
172172

173173
plibs=""
@@ -181,7 +181,7 @@ plibs=""
181181
if test "${ext_modules}" != ""; then
182182
for p in ${ext_modules}; do
183183
if test -f ${p}.lib; then
184-
plibs="`cat ${p}.lib`"
184+
plibs="$(cat ${p}.lib)"
185185
else
186186
plibs=""
187187
fi
@@ -200,7 +200,7 @@ plibs=""
200200
if test "${ext_plugins}" != ""; then
201201
for p in ${ext_plugins}; do
202202
if test -f ${p}.lib; then
203-
plibs="`cat ${p}.lib`"
203+
plibs="$(cat ${p}.lib)"
204204
else
205205
plibs=""
206206
fi

0 commit comments

Comments
 (0)