#!/bin/bash ########################################### #This script was written by rob newland # #and is free (as in speech) for all uses. # #it may be modified or have anything done # #to it as long as this notice remains. # ########################################### ############# VARIABLES ############# var1="$1" var2="$2" ############# FUNCTIONS ############# function arguments () { echo " Rob's tlm-project seed-server script." echo "Please supply one of the following arguments:" echo " --check / -c checks dependencies" echo " --instdeps / -id installs dependencies" echo " --install / -i installs the program" echo " --help / -h Displays this message" } checkforroot () { if [[ ! `whoami`=="root" ]] then echo "********ERROR********" echo "You must be logged in as root to run this script" echo "Please log in as root and re-run this script." echo "Aborting installation." echo "********ERROR********" exit fi } function checkdeps () { checkforroot echo "Checking for bittorrent" which launchmany-curses.py &>/dev/null if [ $? != "0" ]; then echo -e "ERROR: bittorrent is either not installed or the required scripts are not installed." ; read -p "Hit Enter to continue" blankvar else echo "Bittorrent is installed" ; fi echo "" echo "Checking for cron" if [[ -d /etc/cron.hourly ]] then echo "cron is installed" ; else echo "You do not have cron." ; fi echo "" echo "checking for rsync" which rsync &>/dev/null if [ $? != "0" ]; then echo -e "rsync is not installed. Run instdeps from the menu." ; read -p "hit return to continue" blankvar ; else echo "rsync is installed" ; fi sleep 5 } function instdeps () { checkforroot echo checking for bittorrent which launchmany-curses.py &>/dev/null if [ $? != "0" ]; then echo -e "bittorrent -- NOT INSTALLED (OR INSTALLED CORRECTLY)"; cd /home/$USER ; echo "Downloading bittorrent" ; sleep 1 ; wget http://download.bittorrent.com/dl/BitTorrent-4.4.0.tar.gz ; tar -zxvf BitTorrent-4.4.0.tar.gz ; cd BitTorrent-4.4.0 ; echo "#!/bin/bash" >> /usr/bin/launchmany-curses.py ; echo "cd /home/$USER/BitTorrent-4.4.0 && ./launchmany-curses.py --torrent_dir /home/$USER/torrents --save_in /home/$USER/data --max_upload_rate 200" >> /usr/bin/launchmany-curses.py ; chmod 777 /usr/bin/launchmany-curses.py ; echo "" fi echo "Bittorrent is installed" echo "" echo checking for cron if [[ -d /etc/cron.hourly ]] then echo "cron is installed" else echo "You do not have crond. Please find a way to install it. " fi echo "" echo checking for rsync... which rsync &>/dev/null if [ $? != "0" ]; then echo "rsync -- NOT INSTALLED" ; wget http://samba.anu.edu.au/ftp/rsync/rsync-2.6.7.tar.gz tar -zxvf rsync-2.6.7.tar.gz cd rsync* ./configure && make & make install read -p "hit return to continue" var echo "" fi echo "rsync is installed." } function installandcheck () { checkforroot echo "You need the following installed to run a seed server." echo "1. bittorrent" echo "2. cron" echo "3. rsync " echo "" read -p "Press ENTER to start" enter echo "" echo "Checking for bittorrent" which launchmany-curses.py &>/dev/null if [ $? != "0" ]; then echo -e "bittorrent -- NOT INSTALLED"; read -p "hit return to continue" var exit; fi echo bittorrent is installed echo "" echo checking for cron if [[ -d /etc/cron.hourly ]] then echo "cron is installed" else echo "You do not have cron. Installation will now quit"; sleep 3; exit 0 fi echo "" echo checking for rsync... which rsync &>/dev/null if [ $? != "0" ]; then echo -e "rsync -- NOT INSTALLED"; read -p "Hit Enter to continue" var exit; fi echo "rsync is installed." echo "" echo "Making directories." if [[ ! -d /home/$USER/data ]] then mkdir /home/$USER/data fi if [[ ! -d /home/$USER/torrents ]] then mkdir /home/$USER/torrents fi torrentnum } function torrentnum () { if [[ -e /etc/cron.hourly/torrents ]] then rm -f /etc/cron.hourly/torrents fi read -p "How many torrents would you like to seed? - CHOOSE 5, 10, 15 or 20 : " torrents case "$torrents" in 5 ) echo "Ok"; echo "rsync --delete --recursive -v rsync.tlm-project.org::seed-05 /home/$USER/torrents" &> /etc/cron.hourly/torrents; restinst;; 10 ) echo "Ok"; echo "rsync --delete --recursive -v rsync.tlm-project.org::seed-10 /home/$USER/torrents" &> /etc/cron.hourly/torrents; restinst;; 15 ) echo "Ok"; echo "rsync --delete --recursive -v rsync.tlm-project.org::seed-15 /home/$USER/torrents" &> /etc/cron.hourly/torrents; restinst;; 20 ) echo "Ok"; echo "rsync --delete --recursive -v rsync.tlm-project.org::seed-20 /home/$USER/torrents" &> /etc/cron.hourly/torrents; restinst;; * ) echo "Invalid option!"; torrentnum; restinst;; esac } function restinst () { chmod 777 /etc/cron.hourly/torrents if [[ -e /usr/bin/torrentserver ]] then rm -f /usr/bin/torrentserver fi echo "#!/bin/bash" &> /usr/bin/torrentserver echo "launchmany-curses.py" &> /usr/bin/torrentserver chmod 777 /usr/bin/torrentserver echo "Starting torrent server..." cd /etc/cron.hourly/ ./torrents torrentserver } function checkargs () { case "$var1" in -c ) checkdeps;; --check ) checkdeps;; --installdeps ) instdeps;; -id ) instdeps;; -i ) installandcheck;; --install ) installandcheck;; --help ) arguments;; -h ) arguments;; * ) arguments;; esac } ########## END OF FUNCTIONS ######### ############## PROGRAM ############## checkargs exit