Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ring committed Jul 2, 2016
1 parent 6f5130d commit a502259
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 50 deletions.
28 changes: 14 additions & 14 deletions build-js.sh
@@ -1,29 +1,29 @@
#!/usr/bin/env bash
root=$(readlink -e $(dirname $0))
root=$(readlink -e "$(dirname "$0")")
set -e
if [ "x" == "x$root" ] ; then
root=$PWD/${0##*}
fi
cd $root
cd "$root"

if [ -z "$GOPATH" ]; then
export GOPATH=$root/go
mkdir -p $GOPATH
mkdir -p "$GOPATH"
fi

if [ ! -f $GOPATH/bin/minify ]; then
echo "set up minifiy"
if [ ! -f "$GOPATH/bin/minify" ]; then
echo "set up minifiy"
go get -v github.com/tdewolff/minify/cmd/minify
fi
if [ ! -f $GOPATH/bin/gopherjs ]; then
if [ ! -f "$GOPATH/bin/gopherjs" ]; then
echo "set up gopherjs"
go get -v -u github.com/gopherjs/gopherjs
fi

# build cuckoo miner
echo "Building cuckoo miner"
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
rm ./miner_js.js.map

Expand All @@ -35,37 +35,37 @@ lint() {
true
else
echo "jslint: $1"
jslint --browser $1
jslint --browser "$1"
fi
}

mini() {
echo "minify $1"
echo "" >> $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
if [ "x$1" == "xlint" ] ; then
echo "linting..."
for f in ./contrib/js/*.js ; do
lint $f
lint "$f"
done
fi

echo -e "//For source code and license information please check https://github.com/majestrate/nntpchan \n" > $outfile

if [ -e ./contrib/js/contrib/*.js ] ; then
for f in ./contrib/js/contrib/*.js ; do
mini $f $outfile
mini "$f" "$outfile"
done
fi
mini ./contrib/js/main.js_ $outfile

mini ./contrib/js/main.js_ "$outfile"

# local js
for f in ./contrib/js/*.js ; do
mini $f $outfile
mini "$f" "$outfile"
done
echo "ok"
36 changes: 18 additions & 18 deletions build.sh
@@ -1,20 +1,20 @@
#!/usr/bin/env bash
root=$(readlink -e $(dirname $0))
root=$(readlink -e "$(dirname "$0")")
set -e
if [ "x" == "x$root" ] ; then
root=$PWD/${0##*}
fi
cd $root
cd "$root"

tags=""

help_text="usage: $0 [--disable-redis]"

# check for help flags first
for arg in $@ ; do
for arg in "$@" ; do
case $arg in
-h|--help)
echo $help_text
echo "$help_text"
exit 0
;;
esac
Expand All @@ -25,7 +25,7 @@ ipfs="no"
rebuildjs="yes"
_next=""
# check for build flags
for arg in $@ ; do
for arg in "$@" ; do
case $arg in
"--no-js")
rebuildjs="no"
Expand All @@ -43,7 +43,7 @@ for arg in $@ ; do
_next="rev"
;;
"--revision=*")
rev=$(echo $arg | cut -d'=' -f2)
rev=$(echo "$arg" | cut -d'=' -f2)
;;
*)
if [ "x$_next" == "xrev" ] ; then
Expand All @@ -57,35 +57,35 @@ if [ "x$rev" == "x" ] ; then
exit 1
fi

cd $root
cd "$root"
if [ "x$rebuildjs" == "xyes" ] ; then
echo "rebuilding generated js..."
./build-js.sh
fi
unset GOPATH
unset GOPATH
export GOPATH=$PWD/go
mkdir -p $GOPATH
mkdir -p "$GOPATH"

if [ "x$ipfs" == "xyes" ] ; then
if [ ! -e $GOPATH/bin/gx ] ; then
if [ ! -e "$GOPATH/bin/gx" ] ; then
echo "obtaining gx"
go get -u -v github.com/whyrusleeping/gx
fi
if [ ! -e $GOPATH/bin/gx-go ] ; then
if [ ! -e "$GOPATH/bin/gx-go" ] ; then
echo "obtaining gx-go"
go get -u -v github.com/whyrusleeping/gx-go
fi
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
cd $GOPATH/src/gx/ipfs
$GOPATH/bin/gx get $rev
cd $root
go get -d -v
mkdir -p "$GOPATH/src/gx/ipfs"
cd "$GOPATH/src/gx/ipfs"
"$GOPATH/bin/gx" get "$rev"
cd "$root"
go get -d -v
go build -v .
mv nntpchan srndv2
else
go get -u -v github.com/majestrate/srndv2
cp $GOPATH/bin/srndv2 $root
go get -u -v github.com/majestrate/srndv2
cp "$GOPATH/bin/srndv2" "$root"
fi

echo -e "Built\n"
Expand Down
6 changes: 3 additions & 3 deletions contrib/tools/keys/keys.sh
Expand Up @@ -3,8 +3,8 @@
# script to make sql file for inserting all "currently trusted" keys
#

root=$(readlink -e $(dirname $0))
touch $root/keys.sql
for key in $(cat $root/keys.txt) ; do
root=$(readlink -e "$(dirname "$0")")
touch "$root/keys.sql"
for key in $(cat "$root/keys.txt") ; do
echo "insert into modprivs(pubkey, newsgroup, permission) values('$key', 'overchan', 'all');" >> keys.sql ;
done
30 changes: 15 additions & 15 deletions install.sh
@@ -1,16 +1,16 @@
#!/usr/bin/env bash
set -e
root=$(readlink -e $(dirname $0))
root=$(readlink -e "$(dirname "$0")")

prefix="/opt/nntpchan"

help_text="usage: $0 [--prefix /opt/nntpchan] [-q|--quiet] [-r|--rebuild] [--disable-redis]"

# check for help flags first
for arg in $@ ; do
for arg in "$@" ; do
case $arg in
-h|--help)
echo $help_text
echo "$help_text"
exit 0
;;
esac
Expand All @@ -22,7 +22,7 @@ want_quiet="0"
build_args=""

# check for main flags
for arg in $@ ; do
for arg in "$@" ; do
case $arg in
-q|--quiet)
want_quiet="1"
Expand All @@ -34,7 +34,7 @@ for arg in $@ ; do
_next="prefix"
;;
--prefix=*)
prefix=$(echo $arg | cut -d'=' -f2)
prefix=$(echo "$arg" | cut -d'=' -f2)
;;
--disable-redis)
build_args="$build_args --disable-redis"
Expand All @@ -51,27 +51,27 @@ done

_cmd() {
if [ "X$want_quiet" == "X1" ] ; then
$@ &> /dev/null
"$@" &> /dev/null
else
$@
"$@"
fi
}

if [ "X$want_rebuild" == "X1" ] ; then
_cmd echo "rebuilding daemon";
_cmd $root/build.sh $build_args
_cmd "$root/build.sh" $build_args
fi

if [ ! -e $root/srndv2 ] ; then
if [ ! -e "$root/srndv2" ] ; then
_cmd echo "building daemon"
# TODO: use different GOPATH for root?
_cmd $root/build.sh $build_args
_cmd "$root/build.sh" "$build_args"
fi


_cmd mkdir -p $prefix
_cmd mkdir -p $prefix/webroot/thm
_cmd mkdir -p $prefix/webroot/img
_cmd cp -f $root/srndv2 $prefix/srndv2
_cmd cp -rf $root/{doc,contrib,certs} $prefix/
_cmd mkdir -p "$prefix"
_cmd mkdir -p "$prefix/webroot/thm"
_cmd mkdir -p "$prefix/webroot/img"
_cmd cp -f "$root/srndv2" "$prefix/srndv2"
_cmd cp -rf "$root/"{doc,contrib,certs} "$prefix/"
_cmd echo "installed to $prefix"

0 comments on commit a502259

Please sign in to comment.