Archived
1
0

Quote variables, remove trailing whitespace

If you don't quote your variables the scripts get very buggy if you run
them with arguments with spaces in them, or even run them from a
directory with spaces in its path.
This commit is contained in:
ring 2016-07-02 23:30:03 +02:00
parent 6f5130d8fd
commit a502259ba9
4 changed files with 50 additions and 50 deletions

View File

@ -1,21 +1,21 @@
#!/usr/bin/env bash #!/usr/bin/env bash
root=$(readlink -e $(dirname $0)) root=$(readlink -e "$(dirname "$0")")
set -e set -e
if [ "x" == "x$root" ] ; then if [ "x" == "x$root" ] ; then
root=$PWD/${0##*} root=$PWD/${0##*}
fi fi
cd $root cd "$root"
if [ -z "$GOPATH" ]; then if [ -z "$GOPATH" ]; then
export GOPATH=$root/go export GOPATH=$root/go
mkdir -p $GOPATH mkdir -p "$GOPATH"
fi fi
if [ ! -f $GOPATH/bin/minify ]; then if [ ! -f "$GOPATH/bin/minify" ]; then
echo "set up minifiy" echo "set up minifiy"
go get -v github.com/tdewolff/minify/cmd/minify go get -v github.com/tdewolff/minify/cmd/minify
fi fi
if [ ! -f $GOPATH/bin/gopherjs ]; then if [ ! -f "$GOPATH/bin/gopherjs" ]; then
echo "set up gopherjs" echo "set up gopherjs"
go get -v -u github.com/gopherjs/gopherjs go get -v -u github.com/gopherjs/gopherjs
fi fi
@ -23,7 +23,7 @@ fi
# build cuckoo miner # build cuckoo miner
echo "Building cuckoo miner" echo "Building cuckoo miner"
go get -v -u github.com/ZiRo-/cuckgo/miner_js go get -v -u github.com/ZiRo-/cuckgo/miner_js
$GOPATH/bin/gopherjs -m -v build github.com/ZiRo-/cuckgo/miner_js "$GOPATH/bin/gopherjs" -m -v build github.com/ZiRo-/cuckgo/miner_js
mv ./miner_js.js ./contrib/static/miner-js.js mv ./miner_js.js ./contrib/static/miner-js.js
rm ./miner_js.js.map rm ./miner_js.js.map
@ -35,7 +35,7 @@ lint() {
true true
else else
echo "jslint: $1" echo "jslint: $1"
jslint --browser $1 jslint --browser "$1"
fi fi
} }
@ -43,14 +43,14 @@ mini() {
echo "minify $1" echo "minify $1"
echo "" >> $2 echo "" >> $2
echo "/* local file: $1 */" >> $2 echo "/* local file: $1 */" >> $2
$GOPATH/bin/minify --mime=text/javascript >> $2 < $1 "$GOPATH/bin/minify" --mime=text/javascript >> $2 < $1
} }
# do linting too # do linting too
if [ "x$1" == "xlint" ] ; then if [ "x$1" == "xlint" ] ; then
echo "linting..." echo "linting..."
for f in ./contrib/js/*.js ; do for f in ./contrib/js/*.js ; do
lint $f lint "$f"
done done
fi fi
@ -58,14 +58,14 @@ echo -e "//For source code and license information please check https://github.c
if [ -e ./contrib/js/contrib/*.js ] ; then if [ -e ./contrib/js/contrib/*.js ] ; then
for f in ./contrib/js/contrib/*.js ; do for f in ./contrib/js/contrib/*.js ; do
mini $f $outfile mini "$f" "$outfile"
done done
fi fi
mini ./contrib/js/main.js_ $outfile mini ./contrib/js/main.js_ "$outfile"
# local js # local js
for f in ./contrib/js/*.js ; do for f in ./contrib/js/*.js ; do
mini $f $outfile mini "$f" "$outfile"
done done
echo "ok" echo "ok"

View File

@ -1,20 +1,20 @@
#!/usr/bin/env bash #!/usr/bin/env bash
root=$(readlink -e $(dirname $0)) root=$(readlink -e "$(dirname "$0")")
set -e set -e
if [ "x" == "x$root" ] ; then if [ "x" == "x$root" ] ; then
root=$PWD/${0##*} root=$PWD/${0##*}
fi fi
cd $root cd "$root"
tags="" tags=""
help_text="usage: $0 [--disable-redis]" help_text="usage: $0 [--disable-redis]"
# check for help flags first # check for help flags first
for arg in $@ ; do for arg in "$@" ; do
case $arg in case $arg in
-h|--help) -h|--help)
echo $help_text echo "$help_text"
exit 0 exit 0
;; ;;
esac esac
@ -25,7 +25,7 @@ ipfs="no"
rebuildjs="yes" rebuildjs="yes"
_next="" _next=""
# check for build flags # check for build flags
for arg in $@ ; do for arg in "$@" ; do
case $arg in case $arg in
"--no-js") "--no-js")
rebuildjs="no" rebuildjs="no"
@ -43,7 +43,7 @@ for arg in $@ ; do
_next="rev" _next="rev"
;; ;;
"--revision=*") "--revision=*")
rev=$(echo $arg | cut -d'=' -f2) rev=$(echo "$arg" | cut -d'=' -f2)
;; ;;
*) *)
if [ "x$_next" == "xrev" ] ; then if [ "x$_next" == "xrev" ] ; then
@ -57,35 +57,35 @@ if [ "x$rev" == "x" ] ; then
exit 1 exit 1
fi fi
cd $root cd "$root"
if [ "x$rebuildjs" == "xyes" ] ; then if [ "x$rebuildjs" == "xyes" ] ; then
echo "rebuilding generated js..." echo "rebuilding generated js..."
./build-js.sh ./build-js.sh
fi fi
unset GOPATH unset GOPATH
export GOPATH=$PWD/go export GOPATH=$PWD/go
mkdir -p $GOPATH mkdir -p "$GOPATH"
if [ "x$ipfs" == "xyes" ] ; then if [ "x$ipfs" == "xyes" ] ; then
if [ ! -e $GOPATH/bin/gx ] ; then if [ ! -e "$GOPATH/bin/gx" ] ; then
echo "obtaining gx" echo "obtaining gx"
go get -u -v github.com/whyrusleeping/gx go get -u -v github.com/whyrusleeping/gx
fi fi
if [ ! -e $GOPATH/bin/gx-go ] ; then if [ ! -e "$GOPATH/bin/gx-go" ] ; then
echo "obtaining gx-go" echo "obtaining gx-go"
go get -u -v github.com/whyrusleeping/gx-go go get -u -v github.com/whyrusleeping/gx-go
fi fi
echo "building stable revision, this will take a bit. to speed this part up install and run ipfs locally" echo "building stable revision, this will take a bit. to speed this part up install and run ipfs locally"
mkdir -p $GOPATH/src/gx/ipfs mkdir -p "$GOPATH/src/gx/ipfs"
cd $GOPATH/src/gx/ipfs cd "$GOPATH/src/gx/ipfs"
$GOPATH/bin/gx get $rev "$GOPATH/bin/gx" get "$rev"
cd $root cd "$root"
go get -d -v go get -d -v
go build -v . go build -v .
mv nntpchan srndv2 mv nntpchan srndv2
else else
go get -u -v github.com/majestrate/srndv2 go get -u -v github.com/majestrate/srndv2
cp $GOPATH/bin/srndv2 $root cp "$GOPATH/bin/srndv2" "$root"
fi fi
echo -e "Built\n" echo -e "Built\n"

View File

@ -3,8 +3,8 @@
# script to make sql file for inserting all "currently trusted" keys # script to make sql file for inserting all "currently trusted" keys
# #
root=$(readlink -e $(dirname $0)) root=$(readlink -e "$(dirname "$0")")
touch $root/keys.sql touch "$root/keys.sql"
for key in $(cat $root/keys.txt) ; do for key in $(cat "$root/keys.txt") ; do
echo "insert into modprivs(pubkey, newsgroup, permission) values('$key', 'overchan', 'all');" >> keys.sql ; echo "insert into modprivs(pubkey, newsgroup, permission) values('$key', 'overchan', 'all');" >> keys.sql ;
done done

View File

@ -1,16 +1,16 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
root=$(readlink -e $(dirname $0)) root=$(readlink -e "$(dirname "$0")")
prefix="/opt/nntpchan" prefix="/opt/nntpchan"
help_text="usage: $0 [--prefix /opt/nntpchan] [-q|--quiet] [-r|--rebuild] [--disable-redis]" help_text="usage: $0 [--prefix /opt/nntpchan] [-q|--quiet] [-r|--rebuild] [--disable-redis]"
# check for help flags first # check for help flags first
for arg in $@ ; do for arg in "$@" ; do
case $arg in case $arg in
-h|--help) -h|--help)
echo $help_text echo "$help_text"
exit 0 exit 0
;; ;;
esac esac
@ -22,7 +22,7 @@ want_quiet="0"
build_args="" build_args=""
# check for main flags # check for main flags
for arg in $@ ; do for arg in "$@" ; do
case $arg in case $arg in
-q|--quiet) -q|--quiet)
want_quiet="1" want_quiet="1"
@ -34,7 +34,7 @@ for arg in $@ ; do
_next="prefix" _next="prefix"
;; ;;
--prefix=*) --prefix=*)
prefix=$(echo $arg | cut -d'=' -f2) prefix=$(echo "$arg" | cut -d'=' -f2)
;; ;;
--disable-redis) --disable-redis)
build_args="$build_args --disable-redis" build_args="$build_args --disable-redis"
@ -51,27 +51,27 @@ done
_cmd() { _cmd() {
if [ "X$want_quiet" == "X1" ] ; then if [ "X$want_quiet" == "X1" ] ; then
$@ &> /dev/null "$@" &> /dev/null
else else
$@ "$@"
fi fi
} }
if [ "X$want_rebuild" == "X1" ] ; then if [ "X$want_rebuild" == "X1" ] ; then
_cmd echo "rebuilding daemon"; _cmd echo "rebuilding daemon";
_cmd $root/build.sh $build_args _cmd "$root/build.sh" $build_args
fi fi
if [ ! -e $root/srndv2 ] ; then if [ ! -e "$root/srndv2" ] ; then
_cmd echo "building daemon" _cmd echo "building daemon"
# TODO: use different GOPATH for root? # TODO: use different GOPATH for root?
_cmd $root/build.sh $build_args _cmd "$root/build.sh" "$build_args"
fi fi
_cmd mkdir -p $prefix _cmd mkdir -p "$prefix"
_cmd mkdir -p $prefix/webroot/thm _cmd mkdir -p "$prefix/webroot/thm"
_cmd mkdir -p $prefix/webroot/img _cmd mkdir -p "$prefix/webroot/img"
_cmd cp -f $root/srndv2 $prefix/srndv2 _cmd cp -f "$root/srndv2" "$prefix/srndv2"
_cmd cp -rf $root/{doc,contrib,certs} $prefix/ _cmd cp -rf "$root/"{doc,contrib,certs} "$prefix/"
_cmd echo "installed to $prefix" _cmd echo "installed to $prefix"