Skip to content
Browse files

Clean up the bash scripts

  • Loading branch information...
1 parent bcb085e commit d8c0ec4c559acf7dd4a703ce60bd1aad0daeca97 @grawity grawity committed Nov 11, 2012
Showing with 82 additions and 65 deletions.
  1. +58 −38 do
  2. +24 −27 scripts/cjdns.sh
View
96 do
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
# 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,
# either version 3 of the License, or (at your option) any later version.
@@ -14,54 +14,74 @@
CMAKE_DOWNLOAD=http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
CMAKE_SHA256=2b59897864d6220ff20aa8eac64cac8994e004898a1c0f899c8cb4d7b7570b46
-[ `dirname $0` ] && cd `dirname $0`
-
# get a sha256sum implementation.
getsha256sum() {
- expected=4ee73c05d5158b0fdfec9f5e52cab3fa85b98d6992a221bbff28fdbd935e8afc
- testFile=test/$expected
- for hasher in sha256sum gsha256sum 'shasum -a 256' 'openssl sha256'
- do
- #echo "trying ${hasher} ${testFile}"
- ${hasher} ${testFile} 2>/dev/null | grep -q ${expected} && SHA256SUM=${hasher} && break
+ local testhash=4ee73c05d5158b0fdfec9f5e52cab3fa85b98d6992a221bbff28fdbd935e8afc
+ local testfile=test/$testhash
+ local program
+ for program in 'sha256sum' 'gsha256sum' 'shasum -a 256' 'openssl sha256'; do
+ if $program $testfile 2>/dev/null | grep -qs "$testhash"; then
+ SHA256SUM=$program
+ return 0
+ fi
done
- [ ! "${SHA256SUM}" ] && echo "couldn't find working sha256 hasher." && exit 1
+ echo "Couldn't find a working sha256 tool."
+ return 1
}
-getsha256sum
-
-if [ ! -d build ]; then
- mkdir build;
-fi
+cd "$(dirname "$0")"
+mkdir -p build
cd build
-CMAKE=`which cmake`
-if [ -f cmake-build/bin/cmake ]; then
- CMAKE=`pwd`/cmake-build/bin/cmake
+CMAKE=$PWD/cmake-build/bin/cmake
+
+if [ ! -x "$CMAKE" ]; then
+ CMAKE=$(which cmake)
fi
-[ ${CMAKE} ] && ${CMAKE} --version | grep 2.8.[2-9] ||
-while true; do
- [ -d cmake-build ] && rm -r cmake-build
+if ! { [ -x "$CMAKE" ] && "$CMAKE" --version |
+ egrep 'version 2\.8\.([2-9]|[1-9][0-9]+)(\.|$)'; }; then
+
+ set -e # exit if a command fails
+ rm -rf cmake-build
mkdir cmake-build
cd cmake-build
- APP=`which wget || which curl || echo 'none'`
- [[ "$APP" == 'none' ]] && echo 'Need wget curl' && exit -1;
- [[ "$APP" == `which wget` ]] && $APP ${CMAKE_DOWNLOAD}
- [[ "$APP" == `which curl` ]] && $APP ${CMAKE_DOWNLOAD} > cmake.tar.gz
+ getsha256sum
+
+ if which wget >&/dev/null; then
+ 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 ..
- break
-done
-
-${CMAKE} .. && make &&
- 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"
+ set +e
+fi
+
+set -e
+
+$CMAKE ..
+
+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"
View
51 scripts/cjdns.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
# 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,
# either version 3 of the License, or (at your option) any later version.
@@ -28,43 +28,40 @@
# to stop it and bring it back online immedietly.
##
-# path of cjdns
-CJDPATH="`dirname $0`/"
+CJDPATH="${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"
-stop()
-{
- killall cjdns;
+do_start() {
+ "$CJDROUTE" <"$CONF" >>"$LOGPATH" 2>&1 &
}
-start()
-{
- $CJDROUTE < $CONF 2>&1 >> $LOGTO &
+do_stop() {
+ pkill -x cjdns
}
-case "$1" in
-"start" )
- start
- ;;
+is_running() {
+ pgrep -x cjdns >/dev/null
+}
-"restart" )
- stop
- start
+case $1 in
+start)
+ do_start
;;
-
-"stop" )
- stop
+stop)
+ do_stop
;;
-
-"check" )
- ps aux | grep -v 'grep' | grep 'cjdns core' > /dev/null 2>/dev/null || start
+restart)
+ do_stop && do_start
+ ;;
+status)
+ is_running
+ ;;
+check)
+ is_running || start
;;
esac

0 comments on commit d8c0ec4

Please sign in to comment.
Something went wrong with that request. Please try again.