Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh -e
- ### BEGIN INIT INFO
- # Provides: cjdroute
- # Required-Start: $remote_fs $network
- # Required-Stop: $remote_fs $network
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: Cjdns router
- # Description: A routing engine designed for security, scalability, speed and ease of use.
- ### END INIT INFO
- PROG="cjdroute"
- GIT_PATH="/opt/cjdns"
- PROG_PATH="/opt/cjdns/build"
- CJDNS_CONFIG="/etc/cjdroute.conf"
- CJDNS_LOG="/var/log/cjdns/cjdroute.log"
- CJDNS_USER="root"
- CJDNS_TUN="cjdroute0"
- start() {
- # Start it up with the user cjdns
- if [ $(pgrep cjdroute | wc -l) != 0 ];
- then
- echo "Cjdroute is already running. Doing nothing..."
- else
- #Recreate the tunnel. By prurigro
- echo "Cleaning old logs"
- cat /dev/null > $CJDNS_LOG
- echo "Starting cjdroute"
- sudo -u $CJDNS_USER $PROG_PATH/$PROG < $CJDNS_CONFIG >> $CJDNS_LOG &
- fi
- }
- stop() {
- if [ $(pgrep cjdroute | wc -l) != 2 ];
- then
- echo "Cjdroute isn't running."
- else
- echo "Killing cjdroute"
- killall cjdroute
- fi
- }
- flush() {
- echo "Cleaning log file, leaving last 100 rows\n"
- tail -100 $CJDNS_LOG > $CJDNS_LOG
- }
- status() {
- if [ $(pgrep cjdroute | wc -l) != 0 ];
- then
- echo "Hyperboria is running"
- else
- echo "Hyperboria is not running"
- fi
- }
- update() {
- cd $GIT_PATH
- echo "Updating..."
- git pull
- cd build
- echo "Running cmake..."
- export LOG_LEVEL=debug
- cmake ..
- echo "Making..."
- make
- }
- setup() {
- echo "Ensuring you have the required software..."
- apt-get install -y cmake make git
- echo "Cloning from github..."
- cd /opt/
- git clone https://github.com/cjdelisle/cjdns.git
- echo "Building..."
- mkdir /opt/cjdns/build
- cd /opt/cjdns/build
- export LOG_LEVEL=debug
- cmake ..
- make
- echo "Generating a config file..."
- /opt/cjdns/build/cjdroute --genconf > $CJDNS_CONFIG
- echo "Please add some peers."
- nano $CJDNS_CONFIG
- echo "Making a log dir"
- mkdir /var/log/cjdns
- start
- }
- ## Check to see if we are running as root first.
- if [ "$(id -u)" != "0" ]; then
- echo "This script must be run as root" 1>&2
- exit 1
- fi
- case $1 in
- start)
- start
- exit 0
- ;;
- stop)
- stop
- exit 0
- ;;
- reload|restart|force-reload)
- stop
- sleep 1
- start
- exit 0
- ;;
- status)
- status
- exit 0
- ;;
- flush)
- flush
- exit 0
- ;;
- update|upgrade)
- update
- stop
- sleep 2
- start
- exit 0
- ;;
- install|setup)
- setup
- ;;
- **)
- echo "Usage: $0 {start|stop|reload|flush|status|update|install}" 1>&2
- exit 1
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement