Skip to content

Commit c1cd5a5

Browse files
committed
scripts: prevent globbing and word splitting and other improvements
Signed-off-by: Luís Ferreira <[email protected]>
1 parent aff9f8d commit c1cd5a5

File tree

3 files changed

+49
-52
lines changed

3 files changed

+49
-52
lines changed

linux/build_all.sh

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ if test $# -eq 0 ;then
4141
echo "Script to build all dmd v2 deb/rpm/exe packages at once"
4242
echo
4343
echo "Usage:"
44-
echo " build_all.sh -v\"version\" [-f] [-r\"release\"] [-h]"
44+
echo " build_all.sh -v\"version\" [-f] [-r\"release\"] [-h]"
4545
echo
4646
echo "Options:"
4747
echo " -v\"version\" dmd version (mandatory)"
@@ -76,15 +76,15 @@ do
7676
VER="${I:2}"
7777
;;
7878
*)
79-
ferror "unknown argument '$I'" "try '`basename $0` -h' for more information."
79+
ferror "unknown argument '$I'" "try '${0##*/} -h' for more information."
8080
esac
8181
done
8282

8383

8484
# version is mandatory
8585
if [ -z "$VER" ]
8686
then
87-
ferror "missing version" "try '`basename $0` -h' for more information."
87+
ferror "missing version" "try '${0##*/} -h' for more information."
8888
fi
8989

9090

@@ -95,13 +95,13 @@ VER_TYPE=0
9595
[[ $VER =~ ^[0-9]"."[0-9][0-9][0-9]"."[0-9]+$ ]] && VER_TYPE=10
9696
if [ $VER_TYPE -eq 0 ]
9797
then
98-
ferror "incorrect version number" "try '`basename $0` -h' for more information."
99-
elif test ${VER:0:1} -ne 2
98+
ferror "incorrect version number" "try '${0##*/} -h' for more information."
99+
elif test "${VER:0:1}" -ne 2
100100
then
101-
ferror "for dmd v2 only" "try '`basename $0` -h' for more information."
102-
elif test ${VER:0:1}${VER:2:3} -lt 2065
101+
ferror "for dmd v2 only" "try '${0##*/} -h' for more information."
102+
elif test "${VER:0:1}${VER:2:3}" -lt 2065
103103
then
104-
ferror "dmd v2.065 and newer only" "try '`basename $0` -h' for more information."
104+
ferror "dmd v2.065 and newer only" "try '${0##*/} -h' for more information."
105105
fi
106106

107107

@@ -110,7 +110,7 @@ unset LIST
110110
fcheck()
111111
{
112112
T="install ok installed"
113-
if dpkg -s $1 2>/dev/null | grep "$T" &>/dev/null
113+
if dpkg -s "$1" 2>/dev/null | grep "$T" &>/dev/null
114114
then
115115
echo "Found package $1..."
116116
else
@@ -177,4 +177,3 @@ echo -e "\n\033[32;40;7;1m Everything properly built! \033[0m"
177177

178178
# remove log file
179179
rm -f $LOGFILE
180-

linux/dmd_deb.sh

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fi
2121

2222

2323
# show help
24-
if test -z $1 ;then
24+
if test -z "$1" ;then
2525
echo "Script to create dmd v2 binary deb packages."
2626
echo
2727
echo "Usage:"
@@ -53,10 +53,10 @@ else
5353
if [ $VER_TYPE -eq 0 ]
5454
then
5555
ferror "incorrect version number" "Exiting..."
56-
elif test ${VER:0:1} -ne 2
56+
elif test "${VER:0:1}" -ne 2
5757
then
5858
ferror "for dmd v2 only" "Exiting..."
59-
elif test ${VER:0:1}${VER:2:3} -lt 2065
59+
elif test "${VER:0:1}${VER:2:3}" -lt 2065
6060
then
6161
ferror "dmd v2.065 and newer only" "Exiting..."
6262
fi
@@ -101,13 +101,13 @@ fi
101101
MAINTAINER="Jordi Sayol <[email protected]>"
102102
VERSION1=${1:2}
103103
MAJOR=0
104-
MINOR=$(awk -F. '{ print $2 +0 }' <<<$VERSION1)
105-
RELEASE=$(awk -F. '{ print $3 +0 }' <<<$VERSION1)
104+
MINOR=$(awk -F. '{ print $2 +0 }' <<< "$VERSION1")
105+
RELEASE=$(awk -F. '{ print $3 +0 }' <<< "$VERSION1")
106106
if [ "$REVISION" == "" ]
107107
then
108108
REVISION=0
109109
fi
110-
DESTDIR=`pwd`
110+
DESTDIR="$(pwd)"
111111
TEMPDIR='/tmp/'`date +"%s%N"`
112112
UNZIPDIR="dmd2"
113113
DMDURL="http://ftp.digitalmars.com/dmd.$VERSION1.linux.zip"
@@ -117,40 +117,40 @@ if test "$2" = "-m64" ;then
117117
elif test "$2" = "-m32" ;then
118118
ARCH="i386"
119119
fi
120-
ZIPFILE=`basename $DMDURL`
121-
DMDDIR="dmd_"$VERSION2"-"$REVISION"_"$ARCH
120+
ZIPFILE="$(basename "$DMDURL")"
121+
DMDDIR="dmd_${VERSION2}-${REVISION}_${ARCH}"
122122
DIR32="i386-linux-gnu"
123123
DIR64="x86_64-linux-gnu"
124-
DEBFILE=$DMDDIR".deb"
124+
DEBFILE="$DMDDIR.deb"
125125

126126

127127
# check if destination deb file already exist
128-
if `dpkg -I $DESTDIR"/"$DEBFILE &>/dev/null` && test "$3" != "-f" ;then
128+
if dpkg -I "$DESTDIR/$DEBFILE" &>/dev/null && test "$3" != "-f" ;then
129129
echo -e "$DEBFILE - already exist"
130130
else
131131
# remove bad formated deb file
132-
rm -f $DESTDIR"/"$DEBFILE
132+
rm -f "$DESTDIR/$DEBFILE"
133133

134134

135135
# download zip file if not exist
136-
if ! $(unzip -c $DESTDIR"/"$ZIPFILE &>/dev/null)
136+
if ! unzip -c "$DESTDIR/$ZIPFILE" &>/dev/null
137137
then
138-
rm -f $DESTDIR"/"$ZIPFILE
138+
rm -f "$DESTDIR/$ZIPFILE"
139139
echo "Downloading $ZIPFILE..."
140-
curl -fo $DESTDIR"/"$ZIPFILE $DMDURL
140+
curl -fo "$DESTDIR/$ZIPFILE" "$DMDURL"
141141
fi
142142

143143

144144
# create temp dir
145-
mkdir -p $TEMPDIR"/"$DMDDIR
145+
mkdir -p "$TEMPDIR/$DMDDIR"
146146

147147

148148
# unpacking sources
149-
unzip -q $DESTDIR"/"$ZIPFILE -d $TEMPDIR
149+
unzip -q "$DESTDIR/$ZIPFILE" -d "$TEMPDIR"
150150

151151

152152
# change unzipped folders and files permissions
153-
chmod -R 0755 $TEMPDIR/$UNZIPDIR/*
153+
chmod -R 0755 "$TEMPDIR/$UNZIPDIR/"*
154154
chmod 0644 $(find -L $TEMPDIR/$UNZIPDIR ! -type d)
155155

156156

@@ -277,29 +277,29 @@ else
277277
mkdir -p usr/share/doc/dmd
278278
for I in ../$UNZIPDIR/license.txt ../$UNZIPDIR/src/druntime/LICENSE.txt
279279
do
280-
sed 's/\r//;s/^[ \t]\+$//;s/^$/./;s/^/ /' $I > $I"_tmp"
281-
if [ $(sed -n '/====/=' $I"_tmp") ]
280+
sed 's/\r//;s/^[ \t]\+$//;s/^$/./;s/^/ /' $I > "${I}_tmp"
281+
if sed -n '/====/=' "${I}_tmp"
282282
then
283-
sed -i '1,/====/d' $I"_tmp"
283+
sed -i '1,/====/d' "${I}_tmp"
284284
fi
285-
sed -i ':a;$!{N;ba};s/^\( .\s*\n\)*\|\(\s*\n .\)*$//g' $I"_tmp"
285+
sed -i ':a;$!{N;ba};s/^\( .\s*\n\)*\|\(\s*\n .\)*$//g' "${I}_tmp"
286286
done
287-
echo 'Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
287+
echo "Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
288288
Source: https://github.com/dlang
289289
290290
Files: usr/bin/*
291-
Copyright: 1999-'$(date +%Y)' by Digital Mars written by Walter Bright
291+
Copyright: 1999-$(date +%Y) by Digital Mars written by Walter Bright
292292
License: Digital Mars License
293293
294294
Files: usr/lib/*
295-
Copyright: 1999-'$(date +%Y)' by Digital Mars written by Walter Bright
295+
Copyright: 1999-$(date +%Y) by Digital Mars written by Walter Bright
296296
License: Boost License 1.0
297297
298298
Files: usr/include/*
299-
Copyright: 1999-'$(date +%Y)' by Digital Mars written by Walter Bright
299+
Copyright: 1999-$(date +%Y) by Digital Mars written by Walter Bright
300300
License: Boost License 1.0
301301
302-
License: Digital Mars License' | sed 's/^\t//' > usr/share/doc/dmd/copyright
302+
License: Digital Mars License" | sed 's/^\t//' > usr/share/doc/dmd/copyright
303303
cat ../$UNZIPDIR/license.txt_tmp >> usr/share/doc/dmd/copyright
304304
echo '
305305
License: Boost License 1.0' | sed 's/^\t//' >> usr/share/doc/dmd/copyright
@@ -308,7 +308,7 @@ else
308308

309309
# create shlibs file
310310
mkdir -p DEBIAN
311-
echo "libphobos2 "$MAJOR.$MINOR" libphobos2-"$MINOR > DEBIAN/shlibs
311+
echo "libphobos2 $MAJOR.$MINOR libphobos2-$MINOR" > DEBIAN/shlibs
312312

313313

314314
# create /etc/dmd.conf file
@@ -349,14 +349,14 @@ else
349349

350350

351351
# create control file
352-
echo -e 'Package: dmd
353-
Version: '$VERSION2-$REVISION'
354-
Architecture: '$ARCH'
355-
Maintainer: '$MAINTAINER'
356-
Installed-Size: '$(du -ks usr/ | awk '{print $1}')'
357-
Depends: '$DEPENDS'
358-
Suggests: '$SUGGESTS'
359-
Provides: '$UNZIPDIR-$MINOR', d-compiler
352+
echo -e "Package: dmd
353+
Version: ${VERSION2}-${REVISION}
354+
Architecture: ${ARCH}
355+
Maintainer: ${MAINTAINER}
356+
Installed-Size: $(du -ks usr/ | awk '{print $1}')
357+
Depends: ${DEPENDS}
358+
Suggests: ${SUGGESTS}
359+
Provides: ${UNZIPDIR}-${MINOR}, d-compiler
360360
Section: devel
361361
Priority: optional
362362
Homepage: http://dlang.org/
@@ -375,7 +375,7 @@ else
375375
programming. The needs and contributions of the D programming community form
376376
the direction it goes.
377377
.
378-
Main designer: Walter Bright' | sed 's/^\t//' > DEBIAN/control
378+
Main designer: Walter Bright" | sed 's/^\t//' > DEBIAN/control
379379

380380

381381
# create md5sum file
@@ -405,18 +405,17 @@ else
405405

406406
# create deb package
407407
cd ..
408-
fakeroot dpkg-deb -b -Zxz -z9 $DMDDIR
408+
fakeroot dpkg-deb -b -Zxz -z9 "$DMDDIR"
409409

410410

411411
# disable pushd
412412
popd
413413

414414

415415
# place deb package
416-
mv $TEMPDIR"/"$DEBFILE $DESTDIR
416+
mv "$TEMPDIR/$DEBFILE" "$DESTDIR"
417417

418418

419419
# delete temp dir
420-
rm -Rf $TEMPDIR
420+
rm -rf "$TEMPDIR"
421421
fi
422-

linux/dmd_rpm.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ do
244244
;
245245
; The special name %@P% is replaced with the path to this file
246246
;
247-
247+
248248
[Environment32]
249249
DFLAGS=-I/usr/include/dmd/phobos -I/usr/include/dmd/druntime/import -L-L/usr/lib -L--export-dynamic
250250
' | sed 's/^\t\t//' > etc/dmd.conf
@@ -355,4 +355,3 @@ do
355355
rm -Rf $TEMPDIR
356356
fi
357357
done
358-

0 commit comments

Comments
 (0)