Skip to content

Commit

Permalink
Clean up the bash scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
grawity committed Nov 11, 2012
1 parent bcb085e commit d8c0ec4
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 65 deletions.
96 changes: 58 additions & 38 deletions do
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# You may redistribute this program and/or modify it under the terms of # You may redistribute this program and/or modify it under the terms of
# the GNU General Public License as published by the Free Software Foundation, # the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version. # either version 3 of the License, or (at your option) any later version.
Expand All @@ -14,54 +14,74 @@
CMAKE_DOWNLOAD=http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz CMAKE_DOWNLOAD=http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
CMAKE_SHA256=2b59897864d6220ff20aa8eac64cac8994e004898a1c0f899c8cb4d7b7570b46 CMAKE_SHA256=2b59897864d6220ff20aa8eac64cac8994e004898a1c0f899c8cb4d7b7570b46


[ `dirname $0` ] && cd `dirname $0`

# get a sha256sum implementation. # get a sha256sum implementation.
getsha256sum() { getsha256sum() {
expected=4ee73c05d5158b0fdfec9f5e52cab3fa85b98d6992a221bbff28fdbd935e8afc local testhash=4ee73c05d5158b0fdfec9f5e52cab3fa85b98d6992a221bbff28fdbd935e8afc
testFile=test/$expected local testfile=test/$testhash
for hasher in sha256sum gsha256sum 'shasum -a 256' 'openssl sha256' local program
do for program in 'sha256sum' 'gsha256sum' 'shasum -a 256' 'openssl sha256'; do
#echo "trying ${hasher} ${testFile}" if $program $testfile 2>/dev/null | grep -qs "$testhash"; then
${hasher} ${testFile} 2>/dev/null | grep -q ${expected} && SHA256SUM=${hasher} && break SHA256SUM=$program
return 0
fi
done done
[ ! "${SHA256SUM}" ] && echo "couldn't find working sha256 hasher." && exit 1 echo "Couldn't find a working sha256 tool."
return 1
} }


getsha256sum cd "$(dirname "$0")"

mkdir -p build
if [ ! -d build ]; then
mkdir build;
fi
cd build cd build


CMAKE=`which cmake` CMAKE=$PWD/cmake-build/bin/cmake
if [ -f cmake-build/bin/cmake ]; then
CMAKE=`pwd`/cmake-build/bin/cmake if [ ! -x "$CMAKE" ]; then
CMAKE=$(which cmake)
fi fi


[ ${CMAKE} ] && ${CMAKE} --version | grep 2.8.[2-9] || if ! { [ -x "$CMAKE" ] && "$CMAKE" --version |
while true; do egrep 'version 2\.8\.([2-9]|[1-9][0-9]+)(\.|$)'; }; then
[ -d cmake-build ] && rm -r cmake-build
set -e # exit if a command fails
rm -rf cmake-build
mkdir cmake-build mkdir cmake-build
cd cmake-build cd cmake-build


APP=`which wget || which curl || echo 'none'` getsha256sum
[[ "$APP" == 'none' ]] && echo 'Need wget curl' && exit -1;
[[ "$APP" == `which wget` ]] && $APP ${CMAKE_DOWNLOAD} if which wget >&/dev/null; then
[[ "$APP" == `which curl` ]] && $APP ${CMAKE_DOWNLOAD} > cmake.tar.gz wget "$CMAKE_DOWNLOAD" -O cmake.tar.gz
elif which curl >&/dev/null; then
curl "$CMAKE_DOWNLOAD" -o cmake.tar.gz
else
echo "Please download the following file to 'cmake.tar.gz'"
echo " $CMAKE_DOWNLOAD"
exit 1
fi

if ! $SHA256SUM cmake.tar.gz | grep -qs "$CMAKE_SHA256"; then
echo "Checksum of cmake.tar.gz incorrect"
exit 1
fi

tar -xf cmake.tar.gz
find . -mindepth 1 -maxdepth 1 -type d -exec mv {} build \;
build/configure
make
CMAKE="$PWD/bin/cmake"


${SHA256SUM} ./*.tar.gz | grep ${CMAKE_SHA256} || exit -1
tar -xf *.tar.gz
find ./ -mindepth 1 -maxdepth 1 -type d -exec mv {} build \;
./build/configure && make || exit -1
CMAKE=`pwd`/bin/cmake
cd .. cd ..
break set +e
done fi


${CMAKE} .. && make && set -e
make test || rm cjdroute &&
[ -f admin/angel/cjdroute2 ] && [ ! -f ../cjdroute ] || rm ../cjdroute && cp admin/angel/cjdroute2 ../cjdroute && $CMAKE ..
[ -f admin/angel/cjdns ] && [ ! -f ../cjdns ] || rm ../cjdns && cp admin/angel/cjdns ../ &&
echo -e "\033[1;32mBuild completed successfully, type ./cjdroute to begin setup.\033[0m" make

# I'm not drunk enough to understand this.
make test || rm cjdroute &&
[ -f admin/angel/cjdroute2 ] && [ ! -f ../cjdroute ] || rm ../cjdroute && cp admin/angel/cjdroute2 ../cjdroute &&
[ -f admin/angel/cjdns ] && [ ! -f ../cjdns ] || rm ../cjdns && cp admin/angel/cjdns ../ &&
echo -e "\033[1;32mBuild completed successfully, type ./cjdroute to begin setup.\033[0m"
51 changes: 24 additions & 27 deletions scripts/cjdns.sh
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
# You may redistribute this program and/or modify it under the terms of # You may redistribute this program and/or modify it under the terms of
# the GNU General Public License as published by the Free Software Foundation, # the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version. # either version 3 of the License, or (at your option) any later version.
Expand Down Expand Up @@ -28,43 +28,40 @@
# to stop it and bring it back online immedietly. # to stop it and bring it back online immedietly.
## ##


# path of cjdns CJDPATH="${0##*/}"
CJDPATH="`dirname $0`/"


# path to the cjdroute process CJDROUTE="$CJDPATH/cjdns/cjdroute"
CJDROUTE="${CJDPATH}cjdns/cjdroute"


# path to the configuration CONF="$CJDPATH/cjdroute.conf"
CONF="${CJDPATH}cjdroute.conf"


# path ot the log file.
LOGTO="/dev/null" LOGTO="/dev/null"


stop() do_start() {
{ "$CJDROUTE" <"$CONF" >>"$LOGPATH" 2>&1 &
killall cjdns;
} }


start() do_stop() {
{ pkill -x cjdns
$CJDROUTE < $CONF 2>&1 >> $LOGTO &
} }


case "$1" in is_running() {
"start" ) pgrep -x cjdns >/dev/null
start }
;;


"restart" ) case $1 in
stop start)
start do_start
;; ;;

stop)
"stop" ) do_stop
stop
;; ;;

restart)
"check" ) do_stop && do_start
ps aux | grep -v 'grep' | grep 'cjdns core' > /dev/null 2>/dev/null || start ;;
status)
is_running
;;
check)
is_running || start
;; ;;
esac esac

0 comments on commit d8c0ec4

Please sign in to comment.