#!/bin/bash

######################################################################
#
#  Copyright (c) 2015 arakasi72 (https://github.com/arakasi72)
#
#  --> Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
#
######################################################################

PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/bin:/sbin

rtdstatus=$(rtdload)

select_task(){
while true
  do
    read answer
    case $answer in [1] ) rtsetup && return 0 ;;
                    [2] ) rtadduser && return 0 ;;
                    [3] ) rtremove && return 0 ;;
                    [4] ) rtdload $rtdaction && return 0 ;;
                    [5] ) rtupdate && return 0 ;;
                    [6] ) rutupgrade && return 0 ;;
                    [7] ) rtwebmin && return 0 ;;
                    [8] ) rtletsencrypt && return 0 ;;
                    [9] ) rtsslcert && return 0 ;;
                   [Qq] ) exit ;;
                      * ) echo "Enter 1-9 (q to quit)";;
    esac
  done
}

if [ "$(id -u)" != "0" ]; then
  echo "Must be run as root, or with sudo"
  exit 1
fi

if [ $rtdstatus = enabled ]; then
  rtdaction=disable
elif [ $rtdstatus = disabled ]; then
  rtdaction=enable
fi

clear

echo "For more information go to:"
echo "https://github.com/arakasi72/rtinst/blob/master/README.md"
echo "Select from the following options:"
echo "1.) rtsetup - update the rtinst scripts"
echo "2.) rtadduser - add new user"
echo "3.) rtremove - delete a user"
echo "4.) rtdload $rtdaction - $rtdaction https downloads"
echo "5.) rtupdate - up/down-grade rtorent/libtorrent"
echo "6.) rutupgrade - upgrade to latest version of RuTorrent"
echo "7.) rtwebmin - install webmin"
echo "8.) rtletsencrypt - install Lets Encypt ssl certificate"
echo "9.) rtsslcert - generate new self signed ssl certificate"
echo "Enter option or q to quit"

select_task
