Advertisement
thefinn93

Hyperboria init script

Jun 29th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.96 KB | None | 0 0
  1. #!/bin/sh -e
  2. ### BEGIN INIT INFO
  3. # Provides:          cjdroute
  4. # Required-Start:    $remote_fs $network
  5. # Required-Stop:     $remote_fs $network
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      0 1 6
  8. # Short-Description: Cjdns router
  9. # Description:       A routing engine designed for security, scalability, speed and ease of use.
  10. ### END INIT INFO
  11.  
  12. PROG="cjdroute"
  13. GIT_PATH="/opt/cjdns"
  14. PROG_PATH="/opt/cjdns/build"
  15. CJDNS_CONFIG="/etc/cjdroute.conf"
  16. CJDNS_LOG="/var/log/cjdns/cjdroute.log"
  17. CJDNS_USER="root"
  18. CJDNS_TUN="cjdroute0"
  19.  
  20. start() {
  21.      # Start it up with the user cjdns
  22.      if [ $(pgrep cjdroute | wc -l) != 0 ];
  23.      then
  24.          echo "Cjdroute is already running. Doing nothing..."
  25.      else
  26.          #Recreate the tunnel. By prurigro
  27.          echo "Cleaning old logs"
  28.          cat /dev/null > $CJDNS_LOG
  29.          echo "Starting cjdroute"
  30.          sudo -u $CJDNS_USER $PROG_PATH/$PROG < $CJDNS_CONFIG >> $CJDNS_LOG &
  31.      fi
  32.  }
  33.  
  34.  stop() {
  35.  
  36.      if [ $(pgrep cjdroute | wc -l) != 2 ];
  37.      then
  38.          echo "Cjdroute isn't running."
  39.      else
  40.          echo "Killing cjdroute"
  41.          killall cjdroute
  42.      fi
  43.  }
  44.  
  45.  flush() {
  46.      echo "Cleaning log file, leaving last 100 rows\n"
  47.      tail -100 $CJDNS_LOG > $CJDNS_LOG
  48.  }
  49.  
  50.  status() {
  51.      if [ $(pgrep cjdroute | wc -l) != 0 ];
  52.      then
  53.          echo "Hyperboria is running"
  54.      else
  55.          echo "Hyperboria is not running"
  56.      fi
  57.  }
  58.  
  59.  
  60.  update() {
  61.      cd $GIT_PATH
  62.      echo "Updating..."
  63.      git pull
  64.      cd build
  65.      echo "Running cmake..."
  66.      export LOG_LEVEL=debug
  67.      cmake ..
  68.      echo "Making..."
  69.      make
  70.  }
  71.  
  72. setup() {
  73.      echo "Ensuring you have the required software..."
  74.      apt-get install -y cmake make git
  75.      echo "Cloning from github..."
  76.      cd /opt/
  77.      git clone https://github.com/cjdelisle/cjdns.git
  78.      echo "Building..."
  79.      mkdir /opt/cjdns/build
  80.      cd /opt/cjdns/build
  81.      export LOG_LEVEL=debug
  82.      cmake ..
  83.      make
  84.      echo "Generating a config file..."
  85.      /opt/cjdns/build/cjdroute --genconf > $CJDNS_CONFIG
  86.      echo "Please add some peers."
  87.      nano $CJDNS_CONFIG
  88.      echo "Making a log dir"
  89.      mkdir /var/log/cjdns
  90.      start
  91.  }
  92.  
  93.  ## Check to see if we are running as root first.
  94.  if [ "$(id -u)" != "0" ]; then
  95.      echo "This script must be run as root" 1>&2
  96.      exit 1
  97.  fi
  98.  
  99.  case $1 in
  100.      start)
  101.          start
  102.          exit 0
  103.      ;;
  104.      stop)
  105.          stop
  106.          exit 0
  107.      ;;
  108.      reload|restart|force-reload)
  109.          stop
  110.          sleep 1
  111.          start
  112.          exit 0
  113.      ;;
  114.      status)
  115.          status
  116.          exit 0
  117.      ;;
  118.      flush)
  119.          flush
  120.          exit 0
  121.      ;;
  122.      update|upgrade)
  123.          update
  124.          stop
  125.          sleep 2
  126.          start
  127.          exit 0
  128.      ;;
  129.      install|setup)
  130.          setup
  131.      ;;
  132.      **)
  133.          echo "Usage: $0 {start|stop|reload|flush|status|update|install}" 1>&2
  134.          exit 1
  135.      ;;
  136.  esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement