From 03fb5db6bb700d366f8ffd9d61d493065e117cfe Mon Sep 17 00:00:00 2001 From: arakasi72 Date: Wed, 22 Oct 2014 13:30:04 +0100 Subject: [PATCH] Update rtadduser --- rtadduser | 270 ++++++++++++++++++++++++------------------------------ 1 file changed, 121 insertions(+), 149 deletions(-) diff --git a/rtadduser b/rtadduser index 498600f..5270735 100644 --- a/rtadduser +++ b/rtadduser @@ -41,22 +41,20 @@ while [ $script_size = 0 ] do rm -f $script_name attempts=$(( $attempts + 1 )) - if [ $attempts = 20 ] - then - echo "There is a problem downloading the scripts. Please check your network or there may be an issue with the github website" - echo "If the Github website is down, you can try again later" - exit 1 + if [ $attempts = 20 ]; then + echo "There is a problem downloading the scripts. Please check your network or there may be an issue with the github website" + echo "If the Github website is down, you can try again later" + exit 1 fi wget --no-check-certificate https://raw.githubusercontent.com/arakasi72/rtinst/master/$script_name script_size=$(du -b $script_name | cut -f1) done -if ! [ -z "$script_dest" ] - then - mv -f $script_name $script_dest - if case $script_dest in *"${bindest}"*) true;; *) false;; esac; then - chmod 755 $script_dest - fi +if ! [ -z "$script_dest" ]; then + mv -f $script_name $script_dest + if case $script_dest in *"${bindest}"*) true;; *) false;; esac; then + chmod 755 $script_dest + fi fi } @@ -67,23 +65,21 @@ local no_match=1 while ! [ $no_match = 0 ] do - if [ "$port_type" = "adl" ] - then - port_count=$(random 34000 39000) - else - port_count=$(( $port_count + 1 )) + if [ "$port_type" = "adl" ]; then + port_count=$(random 34000 39000) + else + port_count=$(( $port_count + 1 )) fi for i in $user_list do current_user=$i current_port=$(grep $port_type /var/www/rutorrent/conf/users/$current_user/config.php | sed 's/[^0-9]*//g') - if [ "$current_port" = "$port_count" ] - then - no_match=1 - break - else - no_match=0 + if [ "$current_port" = "$port_count" ]; then + no_match=1 + break + else + no_match=0 fi done done @@ -105,14 +101,12 @@ while ! [ $no_match = 0 ] base_user=$i base_low=$(grep "port_range =" /home/$base_user/.rtorrent.rc | sed 's/[^0-9-]*//g' | cut -d- -f1) base_high=$(grep "port_range =" /home/$base_user/.rtorrent.rc | sed 's/[^0-9-]*//g' | cut -d- -f2) - if [ $low_count -gt $base_high ] - then - no_match=0 - higher=0 - elif [ $high_count -lt $base_low ] - then - no_match=0 - higher=1 + if [ $low_count -gt $base_high ]; then + no_match=0 + higher=0 + elif [ $high_count -lt $base_low ]; then + no_match=0 + higher=1 else no_match=1 break @@ -121,50 +115,40 @@ while ! [ $no_match = 0 ] for n in $user_list do compare_user=$n - if [ $no_match=1 ] - then + if [ $no_match=1 ]; then + break + fi + + if ! [ $base_user = $compare_user ]; then + compare_low=$(grep "port_range =" /home/$compare_user/.rtorrent.rc | sed 's/[^0-9-]*//g' | cut -d- -f1) + compare_high=$(grep "port_range =" /home/$compare_user/.rtorrent.rc | sed 's/[^0-9-]*//g' | cut -d- -f2) + + if [ $higher = 0 ]; then + if [ $base_low -gt $compare_high ]; then + no_match=0 + elif [ $high_count -lt $compare_low ]; then + no_match=0 + elif [ $compare_low -gt $base_high ] && [ $compare_high -lt $count_low ]; then + no_match=0 + else + no_match=1 + break + fi + fi + + if [ $higher = 1 ]; then + if [ $base_high -lt $compare_low ]; then + no_match=0 + elif [ $low_count -gt $compare_high ]; then + no_match=0 + elif [ $compare_high -lt $base_low -a $compare_low -gt $count_high ]; then + no_match=0 + else + no_match=1 break + fi fi - - if ! [ $base_user = $compare_user ] - then - compare_low=$(grep "port_range =" /home/$compare_user/.rtorrent.rc | sed 's/[^0-9-]*//g' | cut -d- -f1) - compare_high=$(grep "port_range =" /home/$compare_user/.rtorrent.rc | sed 's/[^0-9-]*//g' | cut -d- -f2) - - if [ $higher = 0 ] - then - if [ $base_low -gt $compare_high ] - then - no_match=0 - elif [ $high_count -lt $compare_low ] - then - no_match=0 - elif [ $compare_low -gt $base_high ] && [ $compare_high -lt $count_low ] - then - no_match=0 - else - no_match=1 - break - fi - fi - - if [ $higher = 1 ] - then - if [ $base_high -lt $compare_low ] - then - no_match=0 - elif [ $low_count -gt $compare_high ] - then - no_match=0 - elif [ $compare_high -lt $base_low -a $compare_low -gt $count_high ] - then - no_match=0 - else - no_match=1 - break - fi - fi - fi + fi done done done @@ -187,10 +171,9 @@ while [ $confirm_name = 1 ] read -p "Enter user name: " answer addname=$answer check_name=1 - if [ "$addname" = "root" ] - then - echo "Don't mess with root" - exit 1 + if [ "$addname" = "root" ]; then + echo "Don't mess with root" + exit 1 fi while [ $check_name = 1 ] @@ -205,24 +188,21 @@ while [ $confirm_name = 1 ] user=$addname home="/home/$user" -if id -u $user >/dev/null 2>&1 - then - echo "$user already exists" - else - echo "adding $user" - adduser --gecos "" $user +if id -u $user >/dev/null 2>&1; then + echo "$user already exists" +else + echo "adding $user" + adduser --gecos "" $user fi -if [ -d "/var/www/rutorrent/conf/users/$user" ] - then - echo "Will reset $user config, filters and torrents will not be deleted" +if [ -d "/var/www/rutorrent/conf/users/$user" ]; then + echo "Will reset $user config, filters and torrents will not be deleted" fi check_ssh=1 -if groups $user | grep -q -E ' sshuser(\s|$)' || groups $user | grep -q -E ' sudo(\s|$)' - then - echo "ssh already granted" - check_ssh=0 +if groups $user | grep -q -E ' sshuser(\s|$)' || groups $user | grep -q -E ' sudo(\s|$)'; then + echo "ssh already granted" + check_ssh=0 fi while [ $check_ssh = 1 ] @@ -234,44 +214,40 @@ fi esac done -if [ "$sshaccess" = "0" ] - then - groupadd sshuser - allowlist=$(grep AllowUsers /etc/ssh/sshd_config) - if ! [ -z "$allowlist" ] - then - for ssh_user in $allowlist - do - if ! [ "$ssh_user" = "AllowUsers" ]; then - adduser $ssh_user sshuser - fi - done - perl -pi -e "s/$allowlist//g" /etc/ssh/sshd_config - service ssh restart - fi +if [ "$sshaccess" = "0" ]; then + groupadd sshuser + allowlist=$(grep AllowUsers /etc/ssh/sshd_config) + if ! [ -z "$allowlist" ]; then + for ssh_user in $allowlist + do + if ! [ "$ssh_user" = "AllowUsers" ]; then + adduser $ssh_user sshuser + fi + done + perl -pi -e "s/$allowlist//g" /etc/ssh/sshd_config + service ssh restart + fi - groupslist=$(grep AllowGroups /etc/ssh/sshd_config) - echo $groupslist - if [ -z "$groupslist" ] - then - echo "AllowGroups sudo sshuser" | tee -a /etc/ssh/sshd_config > /dev/null - service ssh restart - fi + groupslist=$(grep AllowGroups /etc/ssh/sshd_config) + echo $groupslist + if [ -z "$groupslist" ]; then + echo "AllowGroups sudo sshuser" | tee -a /etc/ssh/sshd_config > /dev/null + service ssh restart + fi - if [ -z "$(groups $user | grep "sshuser")" ]; then + if [ -z "$(groups $user | grep "sshuser")" ]; then adduser $user sshuser - fi + fi fi -if [ "$user" = "$SUDO_USER" ] - then - echo "Will reset $user config, autodl filters and torrents will not be deleted" - get_scripts ru.config /var/www/rutorrent/conf/config.php +if [ "$user" = "$SUDO_USER" ]; then + echo "Will reset $user config, autodl filters and torrents will not be deleted" + get_scripts ru.config /var/www/rutorrent/conf/config.php fi #remove existing directory if there if [ -d "/var/www/rutorrent/conf/users/$user" ]; then -rm -r /var/www/rutorrent/conf/users/$user + rm -r /var/www/rutorrent/conf/users/$user fi #assign ports @@ -306,29 +282,27 @@ htpasswd -b $passfile $user $WEBPASS get_scripts .rtorrent.rc $home/.rtorrent.rc -if ! [ -x /usr/local/bin/rt ] - then - get_scripts rt /usr/local/bin/rt +if ! [ -x /usr/local/bin/rt ]; then + get_scripts rt /usr/local/bin/rt fi -if ! [ -x /usr/local/bin/rtcheck ] - then - get_scripts rtcheck /usr/local/bin/rtcheck +if ! [ -x /usr/local/bin/rtcheck ]; then + get_scripts rtcheck /usr/local/bin/rtcheck fi -perl -pi -e "s//$user/g" $home/.rtorrent.rc -sudo perl -pi -e "s/port_range = 51001-51250/port_range = $newrange/g" $home/.rtorrent.rc -sudo perl -pi -e "s/network\.scgi\.open_port = 127\.0\.0\.1:5000/network\.scgi\.open_port = 127\.0\.0\.1:$newscgi/g" $home/.rtorrent.rc +sed -i "s//$user/g" $home/.rtorrent.rc +sed -i "s/port_range = 51001-51250/port_range = $newrange/g" $home/.rtorrent.rc +sed -i "s/network\.scgi\.open_port = 127\.0\.0\.1:5000/network\.scgi\.open_port = 127\.0\.0\.1:$newscgi/g" $home/.rtorrent.rc -echo " /dev/null -echo | tee -a /var/www/rutorrent/conf/users/$user/config.php > /dev/null -echo "\$topDirectory = '$home';" | tee -a /var/www/rutorrent/conf/users/$user/config.php > /dev/null -echo "\$scgi_port = $newscgi;" | tee -a /var/www/rutorrent/conf/users/$user/config.php > /dev/null -echo "\$XMLRPCMountPoint = \"/RPC$newrpc\";" | tee -a /var/www/rutorrent/conf/users/$user/config.php > /dev/null -echo | tee -a /var/www/rutorrent/conf/users/$user/config.php > /dev/null -echo "?>" | tee -a /var/www/rutorrent/conf/users/$user/config.php > /dev/null +echo " /var/www/rutorrent/conf/users/$user/config.php +echo >> /var/www/rutorrent/conf/users/$user/config.php +echo "\$topDirectory = '$home';" >> /var/www/rutorrent/conf/users/$user/config.php +echo "\$scgi_port = $newscgi;" >> /var/www/rutorrent/conf/users/$user/config.php +echo "\$XMLRPCMountPoint = \"/RPC$newrpc\";" >> /var/www/rutorrent/conf/users/$user/config.php +echo >> /var/www/rutorrent/conf/users/$user/config.php +echo "?>" >> /var/www/rutorrent/conf/users/$user/config.php #add auto-dl mkdir /var/www/rutorrent/conf/users/$user/plugins/autodl-irssi @@ -341,30 +315,28 @@ cp autodl-irssi.pl autorun/ mkdir -p $home/.autodl touch $home/.autodl/autodl.cfg && touch $home/.autodl/autodl2.cfg -echo " /dev/null -echo | tee -a /var/www/rutorrent/conf/users/$user/plugins/autodl-irssi/conf.php > /dev/null -echo "\$autodlPort = $adlport;" | tee -a /var/www/rutorrent/conf/users/$user/plugins/autodl-irssi/conf.php > /dev/null -echo "\$autodlPassword = \"$adlpass\";" | tee -a /var/www/rutorrent/conf/users/$user/plugins/autodl-irssi/conf.php > /dev/null -echo | tee -a /var/www/rutorrent/conf/users/$user/plugins/autodl-irssi/conf.php > /dev/null -echo "?>" | tee -a /var/www/rutorrent/conf/users/$user/plugins/autodl-irssi/conf.php > /dev/null +echo " /var/www/rutorrent/conf/users/$user/plugins/autodl-irssi/conf.php +echo >> /var/www/rutorrent/conf/users/$user/plugins/autodl-irssi/conf.php +echo "\$autodlPort = $adlport;" >> /var/www/rutorrent/conf/users/$user/plugins/autodl-irssi/conf.php +echo "\$autodlPassword = \"$adlpass\";" >> /var/www/rutorrent/conf/users/$user/plugins/autodl-irssi/conf.php +echo >> /var/www/rutorrent/conf/users/$user/plugins/autodl-irssi/conf.php +echo "?>" >> /var/www/rutorrent/conf/users/$user/plugins/autodl-irssi/conf.php cd $home/.autodl -echo "[options]" | tee autodl2.cfg > /dev/null -echo "gui-server-port = $adlport" | tee -a autodl2.cfg > /dev/null -echo "gui-server-password = $adlpass" | tee -a autodl2.cfg > /dev/null +echo "[options]" > autodl2.cfg +echo "gui-server-port = $adlport" >> autodl2.cfg +echo "gui-server-password = $adlpass" >> autodl2.cfg chown -R $user:$user $home chown -R www-data:www-data /var/www/rutorrent chmod -R 755 /var/www/rutorrent -if [ -z "$(crontab -u $user -l | grep "$cronline1")" ] - then - (crontab -u $user -l; echo "$cronline1" ) | crontab -u $user - +if [ -z "$(crontab -u $user -l | grep "$cronline1")" ]; then + (crontab -u $user -l; echo "$cronline1" ) | crontab -u $user - fi -if [ -z "$(crontab -u $user -l | grep "\*/10 \* \* \* \* /usr/local/bin/rtcheck irssi rtorrent")" ] - then - (crontab -u $user -l; echo "$cronline2" ) | crontab -u $user - +if [ -z "$(crontab -u $user -l | grep "\*/10 \* \* \* \* /usr/local/bin/rtcheck irssi rtorrent")" ]; then + (crontab -u $user -l; echo "$cronline2" ) | crontab -u $user - fi su $user -c '/usr/local/bin/rt restart'