added quotes to avoid globbing, added tests for needed binaries so the script doesn't fail halfway through

AuthorKonata <konata@posteo.jp>
Date
Commite90e4fc270e41169066e9756b7a4c946e01a45b0
Parentc2c39d4
1 file changed, 15 insertions(+), 12 deletions(-)
Mbundle_deps.sh
@@ -1,19 +1,22 @@
11 #!/bin/bash
2-if [ $# -ne 2 ]
3- then
4- echo "Usage: $0 BINARY DESTINATION"
2+programs=(ldd mkdir cd cp grep echo chmod awk xargs)
3+
4+for prog in "${programs[@]}"; do
5+ command -v "$prog" >/dev/null 2>&1 || { echo >&2 "This script requires $prog but it's not installed. Aborting."; exit 1;}
6+done
7+
8+if [ $# -ne 2 ]; then
9+ echo "Usage: $0 BINARY DESTINATION"
510 else
6- BINARY=$(realpath $1)
7- DESTINATION=$(realpath $2)
8- SCRIPTFILENAME="$DESTINATION/start_$(basename $BINARY).sh"
11+ BINARY=$(realpath "$1")
12+ DESTINATION=$(realpath "$2")
13+ SCRIPTFILENAME="$DESTINATION/start_$(basename "$BINARY").sh"
914
1015 read -r -d '' SCRIPTFILE << EOM
11-#!/bin/bash
12-LD_LIBRARY_PATH=./libs ./$(basename $BINARY)
16+LD_LIBRARY_PATH=./libs ./$(basename "$BINARY")
1317 EOM
1418
15-
16- mkdir -p $DESTINATION && mkdir -p $DESTINATION/libs && cd $DESTINATION && cp $BINARY $DESTINATION
17- ldd $BINARY | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' $DESTINATION/libs &&
18- echo "$SCRIPTFILE" > $SCRIPTFILENAME && chmod +x $SCRIPTFILENAME
19+ mkdir -p "$DESTINATION" && mkdir -p "$DESTINATION"/libs && cd "$DESTINATION" && cp "$BINARY" "$DESTINATION"
20+ ldd "$BINARY" | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' "$DESTINATION"/libs &&
21+ echo "$SCRIPTFILE" > "$SCRIPTFILENAME" && chmod +x "$SCRIPTFILENAME"
1922 fi