Advertisement
gnihtemoSgnihtemos

Shell Script...... debianConfigAwsome.5.3.sh

Apr 13th, 2019
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 25.07 KB | None | 0 0
  1. #!/bin/bash -x
  2.  
  3. ########### Copy or Move the accompanied directory called "svaka" to /tmp ######################
  4. ################################################################################################
  5.  
  6. ################## shopt (shopt [-pqsu] [-o] [optname …]) = This builtin allows you to change additional shell optional behavior.
  7. ################## -s = Enable (set) each optname.
  8. ################## -o = Restricts the values of optname to be those defined for the -o option to the set builtin (see The Set Builtin).
  9. ################## nounset = Treat unset variables and parameters other than the special parameters ‘@’ or ‘*’ as an error when performing parameter expansion. An
  10. # error message will be written to the standard error, and a non-interactive shell will exit.
  11. ################## The Set Builtin
  12. #This builtin is so complicated that it deserves its own section. set allows you to change the values of shell options and set the positional parameters, or to
  13. #display the names and values of shell variables.
  14. shopt -s -o nounset
  15.  
  16. ############################################################
  17. #The set -e option instructs bash to immediately exit if any command [1] has a non-zero exit status. You wouldn't want to set this for your command-line shell,
  18. #but in a script it's massively helpful. In all widely used general-purpose programming languages, an unhandled runtime error - whether that's a thrown exception
  19. #in Java, or #a segmentation fault in C, or a syntax error in Python - immediately halts execution of the program; subsequent lines are not executed.
  20.  
  21. #set -u affects variables. When set, a reference to any variable you haven't previously defined - with the exceptions of $* and $@ - is an error, and causes the
  22. #program to immediately exit. Languages like Python, C, Java and more all behave the same way, for all sorts of good reasons. One is so typos don't create new
  23. #variables without you realizing it.
  24.  
  25. #set -o pipefail
  26. #This setting prevents errors in a pipeline from being masked. If any command in a pipeline fails, that return code will be used as the return code of the whole
  27. #pipeline. By default, the pipeline's return code is that of the last command - even if it succeeds. Imagine finding a sorted list of matching lines in a file:
  28.  
  29. #    % grep some-string /non/existent/file | sort
  30. #    grep: /non/existent/file: No such file or directory
  31. #    % echo $?
  32. #    0
  33. #set -euo pipefail
  34. #set -euo pipefail
  35. #####33 Also use this↓↓↓↓↓↑↑↑↑↑↑↑↑↑↑
  36. #set -euo pipefail
  37. IFS_OLD=$IFS
  38. IFS=$'\n\t'
  39. #↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
  40. #Setting IFS to $'\n\t' means that word splitting will happen only on newlines and tab characters. This very often produces useful splitting behavior. By default,
  41. #bash sets this to $' \n\t' - space, newline, tab - which is too eager.
  42. #######################↑↑↑↑↑↑↑↑
  43. #
  44. ################################### Successful exit then this cleanup ###########################################################3
  45.  
  46. successfulExit()
  47. {
  48.     IFS=$IFS_OLD
  49.     cd "$HOME" || { echo "cd $HOME failed"; exit 155; }
  50.     rm -rf /tmp/svaka || { echo "Failed to remove the install directory!!!!!!!!"; exit 155; }
  51. }
  52. ###############################################################################################################################33
  53. ####### Catch the program on successful exit and cleanup
  54. trap successfulExit EXIT
  55. ####### Catch signals that could stop the script
  56. trap : SIGINT SIGQUIT SIGTERM
  57. #################################
  58.  
  59. ####################################################### Setup system to send email with your google/gmail account and sendmail ##############################
  60. ######################################################## TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO ##############################
  61.  
  62.  
  63. # Configuring Gmail as a Sendmail email relay
  64. #
  65. #
  66. #Introduction
  67. #
  68. #In this configuration tutorial we will guide you through the process of configuring sendmail to be an email relay for your gmail or google apps account.
  69. #This allows #you to send email from your bash scripts, hosted website or from command line using mail command.
  70. #Other examples where you can utilize this setting is for a #notification purposes such or failed backups etc.
  71. #Sendmail is just one of many utilities which can be configured to rely on gmail account where the others include #postfix, exim , ssmpt etc.
  72. #In this tutorial we will use Debian and sendmail for this task.
  73. #Install prerequisites
  74. #
  75. ## CODE:apt-get install sendmail mailutils sendmail-bin
  76. #
  77. #Create Gmail Authentication file
  78. #
  79. ## CODE:mkdir -m 700 /etc/mail/authinfo/
  80. ## CODE:cd /etc/mail/authinfo/
  81. #
  82. #next we need to create an auth file with a following content. File can have any name, in this example the name is gmail-auth:
  83. #
  84. # CODE: printf 'AuthInfo: "U:root" "I:YOUR GMAIL EMAIL ADDRESS" "P:YOUR PASSWORD"\n' > gmail-auth
  85. #
  86. #Replace the above email with your gmail or google apps email.
  87. #
  88. #Please note that in the above password example you need to keep 'P:' as it is not a part of the actual password.
  89. #
  90. #In the next step we will need to create a hash map for the above authentication file:
  91. #
  92. ## CODE:makemap hash gmail-auth < gmail-auth
  93. #
  94. #Configure your sendmail
  95. #
  96. #Put bellow lines into your sendmail.mc configuration file right above first "MAILER" definition line: ######################################################
  97. #
  98. #define(`SMART_HOST',`[smtp.gmail.com]')dnl
  99. #define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
  100. #define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
  101. #define(`confAUTH_OPTIONS', `A p')dnl
  102. #TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
  103. #define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
  104. #FEATURE(`authinfo',`hash -o /etc/mail/authinfo/gmail-auth.db')dnl
  105. #############################################################################################################################################################
  106. #Do not put the above lines on the top of your sendmail.mc configuration file !
  107. #
  108. #In the next step we will need to re-build sendmail's configuration. To do that execute:
  109. #
  110. ## CODE: make -C /etc/mail
  111. #
  112. #Reload sendmail service:
  113. #
  114. # CODE:/etc/init.d/sendmail reload
  115. #
  116. #and you are done.
  117. #Configuration test
  118. #
  119. #Now you can send an email from your command line using mail command:
  120. #
  121. # CODE: echo "Just testing my sendmail gmail relay" | mail -s "Sendmail gmail Relay" "This email address is being protected from spambots."
  122. #
  123.  
  124. #######################################################3 Trap signals and exit to send email on it #######################################################
  125. #trap 'echo "Subject: Program finsihed execution" | sendmail -v "This email address is being protected from spambots."' exit # It will mail on normal exit
  126. #trap 'echo "Subject: Program interrupted" | /usr/sbin/sendmail -v "This email address is being protected from spambots."' INT HUP
  127. # it will mail on interrupt or hangup  of the process
  128.  
  129. # redirect all errors to a file                                                                    #### MUNA setja þetta í sshd_config="#HISTAMIN98"
  130. if [ -w /tmp/svaka ]
  131. then
  132.     exec 2>debianConfigVersion5.3__ERRORS__.txt
  133. else
  134.     echo "can't write error file!"
  135.     exit 127
  136. fi
  137. ##################################################################################################### TODO exec 3>cpSuccessCodes.txt ##
  138. #############################################################################################################
  139.  
  140.  
  141. SCRIPTNAME=$(basename "$0")
  142.  
  143. if [ "$UID" != 0 ]
  144.     then
  145.     echo "This program should be run as root, exiting! now....."
  146.     sleep 3
  147.     exit 1
  148. fi
  149.  
  150. if [ "$#" -eq 0 ]
  151. then
  152.     echo "RUN AS ROOT...Usage if you want to create users:...$SCRIPTNAME USER_1 USER_2 USER_3 etc."
  153.     echo "If you create users they will be set with a semi strong password which you need to change later as root with the passwd command"
  154.     echo
  155.     echo
  156.     echo "#################### ↓↓↓↓↓↓↓↓↓↓↓ OR ↓↓↓↓↓↓↓↓↓↓ #############################"
  157.     echo
  158.     echo
  159.     echo "RUN AS ROOT...Usage without creating users: $SCRIPTNAME"
  160.     echo
  161.     sleep 10
  162.  
  163. fi
  164.  
  165. echo "Here starts the party!"
  166. echo "Setting up server..........please wait!!!!!"
  167. sleep 3
  168.  
  169. ### ↓↓↓↓ Initialization of VARIABLES............NEXT TIME USE "declare VARIABLE" ↓↓↓↓↓↓↓↓↓↓ #####
  170. OAUTH_TOKEN=d6637f7ccf109a0171a2f55d21b6ca43ff053616
  171. WORK_DIR=/tmp/svaka
  172. BASHRC=.bashrc
  173. NANORC=.nanorc
  174. BASHRCROOT=.bashrcroot
  175. SOURCE=sources.list
  176. PORT=""
  177.  
  178. ########### Commands
  179. PWD=$(pwd)
  180.  
  181. #-----------------------------------------------------------------------↓↓
  182. export DEBIAN_FRONTEND=noninteractive
  183. #-----------------------------------------------------------------------↑↑
  184.  
  185. ################ Enter the working directory where all work happens ##########################################
  186. cd "$WORK_DIR" || { echo "cd $WORK_DIR failed"; exit 127; }
  187.  
  188. ############################### make all files writable, executable and readable in the working directory#########
  189. if ! chown -R root:root "$WORK_DIR"
  190. then
  191.     echo "chown WORK_DIR failed"
  192.     exit 127
  193. fi
  194.  
  195. if ! chmod -R 750 "$WORK_DIR"
  196. then
  197.     echo "chmod WORK_DIR failed"
  198.     exit 127
  199. fi
  200.  
  201. ############################################################## Check if files exist and are writable #########################################
  202.  
  203. if [[ ! -f "$WORK_DIR"/.bashrc && ! -w "$WORK_DIR"/.bashrc ]]
  204. then
  205.     echo "missing .bashrc file or is not writable.. exiting now....." && { exit 127; }
  206. fi
  207. if [[ ! -f "$WORK_DIR"/.nanorc && ! -w "$WORK_DIR"/.nanorc ]]
  208. then
  209.     echo "missing .nanorc file or is not writable.. exiting now....." && { exit 127; }
  210. fi
  211.     if [[ ! -f "$WORK_DIR"/.bashrcroot && ! -w "$WORK_DIR"/.bashrcroot ]]
  212. then
  213.     echo "missing .bashrcroot file or is not writable..exiting now....." && { exit 127; }
  214. fi
  215. if [[ ! -f "$WORK_DIR"/sources.list && ! -w "$WORK_DIR"/sources.list ]]
  216. then
  217.     echo "missing sources.list file or is not writable..exiting now....." && { exit 127; }
  218. fi
  219.  
  220. ########################################### Check if PORT is set and if sshd_config is set and if PORT is set in iptables ####################
  221. if [[ $PORT == "" ]] && ! grep -q "#HISTAMIN98" /etc/ssh/sshd_config && ! grep -q $PORT /etc/iptables.up.rules
  222. then
  223.     echo -n "Please select/provide the port-number for ssh in iptables setup or sshd_config file:"
  224.     read -r port ### when using the "-p" option then the value is stored in $REPLY
  225.     PORT=$port
  226. fi
  227.  
  228. ############################ Check internet connection ##############################
  229. checkInternet()
  230. {
  231.     ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && return 0 || return 1
  232. }
  233.  
  234. ################ Creating new users #####################1
  235.  
  236. creatingNewUsers()
  237. {
  238.     for name in "$@"
  239.     do
  240.         if id -u "$name" #>/dev/null 2>&1
  241.         then
  242.             echo "User: $name exists....setting up now!"
  243.             sleep 2
  244.         else
  245.             echo "User: $name does not exists....creating now!"            
  246.             useradd -m -s /bin/bash "$name" #>/dev/null 2>&1
  247.             sleep 2
  248.         fi
  249.     done
  250. }
  251.  
  252. ###########################################################################3
  253. ################# GET USERS ON THE SYSTEM ###################################
  254.  
  255. prepare_USERS.txt()
  256. {
  257.     awk -F: '$3 >= 1000 { print $1 }' /etc/passwd > "$WORK_DIR"/USERS.txt
  258.  
  259.     chmod 750 "$WORK_DIR"/USERS.txt
  260.     if [[ ! -f "$WORK_DIR"/USERS.txt && ! -w "$WORK_DIR"/USERS.txt ]]
  261.     then
  262.         echo "USERS.txt doesn't exist or is not writable..exiting!"
  263.         sleep 3
  264.         exit 127
  265.     fi
  266. #   if [[ ! "$@" == "" ]]
  267. #   then
  268. #        for user in "$@"
  269. #        do
  270. #            echo "$user" >> /tmp/svaka/USERS.txt || { echo "writing to USERS.txt failed"; exit 127; }
  271. #        done
  272. #    fi
  273. }
  274. ###########################################################################33
  275. ################33 user passwords2
  276. userPasswords()
  277. {
  278.     if [[ ! -f "$WORK_DIR"/USERS.txt && ! -w "$WORK_DIR"/USERS.txt ]]
  279.     then
  280.         echo "USERS.txt doesn't exist or is not writable..exiting!"
  281.         sleep 3
  282.         exit 127
  283.     fi
  284.     while read -r user
  285.     do
  286.         if [ "$user" = root ]
  287.         then
  288.             continue
  289.         fi
  290.         if [[ $(passwd --status "$user" | awk '{print $2}') = NP ]] || [[ $(passwd --status "$user" | awk '{print $2}') = L ]]
  291.         then
  292.             echo "$user doesn't have a password."
  293.             echo "Changing password for $user:"
  294.             sleep 3
  295.             echo "$user":"$user""YOURSTRONGPASSWORDHERE12345Áá" | /usr/sbin/chpasswd
  296.             if [ "$?" = 0 ]
  297.                 then
  298.                 echo "Password for user $user changed successfully"
  299.                 sleep 3
  300.             fi
  301.         fi
  302.     done < "$WORK_DIR"/USERS.txt
  303. }
  304.  
  305. ################################################ setting up iptables ####################3
  306. setUPiptables()
  307. {
  308.     #if ! grep -e '-A INPUT -p tcp --dport 80 -j ACCEPT' /etc/iptables.test.rules
  309.     if [[ $(/sbin/iptables-save | grep -c '^\-') -gt 0 ]]
  310.     then
  311.         echo "Iptables already set, skipping..........!"
  312.         sleep 2
  313.     else
  314.         if [ "$PORT" = "" ]
  315.         then
  316.             echo "Port not set for iptables, setting now......."
  317.             echo -n "Setting port now, insert portnumber: "
  318.             read -r port
  319.             PORT=$port
  320.         fi
  321.         if [ ! -f /etc/iptables.test.rules ]
  322.         then
  323.             touch /etc/iptables.test.rules
  324.         else
  325.             cat /dev/null > /etc/iptables.test.rules
  326.         fi
  327.  
  328.         cat << EOT >> /etc/iptables.test.rules
  329.         *filter
  330.  
  331.         # Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
  332.         -A INPUT -i lo -j ACCEPT
  333.         -A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT
  334.  
  335.         # Accepts all established inbound connections
  336.         -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  337.  
  338.         # Allows all outbound traffic
  339.         # You could modify this to only allow certain traffic
  340.         -A OUTPUT -j ACCEPT
  341.  
  342.         # Allows HTTP and HTTPS connections from anywhere (the normal ports for websites)
  343.         -A INPUT -p tcp --dport 80 -j ACCEPT
  344.         -A INPUT -p tcp --dport 443 -j ACCEPT
  345.  
  346.         # Allows SSH connections
  347.         # The --dport number is the same as in /etc/ssh/sshd_config
  348.         -A INPUT -p tcp -m state --state NEW --dport $PORT -j ACCEPT
  349.  
  350.         # Now you should read up on iptables rules and consider whether ssh access
  351.         # for everyone is really desired. Most likely you will only allow access from certain IPs.
  352.  
  353.         # Allow ping
  354.         #  note that blocking other types of icmp packets is considered a bad idea by some
  355.         #  remove -m icmp --icmp-type 8 from this line to allow all kinds of icmp:
  356.         #  https://security.stackexchange.com/questions/22711
  357.         -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
  358.  
  359.         # log iptables denied calls (access via dmesg command)
  360.         -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
  361.  
  362.         # Reject all other inbound - default deny unless explicitly allowed policy:
  363.         -A INPUT -j REJECT
  364.         -A FORWARD -j REJECT
  365.  
  366.         COMMIT
  367. EOT
  368.         sed "s/^[ \t]*//" -i /etc/iptables.test.rules ## remove tabs and spaces
  369.         /sbin/iptables-restore < /etc/iptables.test.rules || { echo "iptables-restore failed"; exit 127; }
  370.         /sbin/iptables-save > /etc/iptables.up.rules || { echo "iptables-save failed"; exit 127; }
  371.         printf "#!/bin/bash\n/sbin/iptables-restore < /etc/iptables.up.rules" > /etc/network/if-pre-up.d/iptables ## create a script to run iptables on startup
  372.         chmod +x /etc/network/if-pre-up.d/iptables || { echo "chmod +x failed"; exit 127; }
  373.     fi
  374. }
  375.  
  376. ###################################################33 sshd_config4
  377. setUPsshd()
  378. {
  379.     if grep "Port $PORT" /etc/ssh/sshd_config
  380.     then
  381.         echo "sshd already set, skipping!"
  382.         sleep 3
  383.     else
  384.  
  385.         if [ "$PORT" = "" ]
  386.         then
  387.             echo "Port not set"
  388.             sleep 3
  389.             exit 12
  390.         fi
  391.         users=""
  392.         /bin/cp -f "$WORK_DIR"/sshd_config /etc/ssh/sshd_config
  393.         sed -i "s/Port 22300/Port $PORT/" /etc/ssh/sshd_config
  394.         for user in $(awk -F: '$3 >= 1000 { print $1 }' /etc/passwd)
  395.         do
  396.             users+="${user} "
  397.         done
  398.         if grep "AllowUsers" /etc/ssh/sshd_config
  399.         then
  400.             sed -i "/AllowUsers/c\AllowUsers $users" /etc/ssh/sshd_config
  401.         else
  402.             sed -i "6 a \
  403.            AllowUsers $users" /etc/ssh/sshd_config
  404.         fi
  405.  
  406.         chmod 644 /etc/ssh/sshd_config
  407.         /etc/init.d/ssh restart
  408.     fi
  409. }
  410.  
  411. #################################################3333 Remove or comment out DVD/cd line from sources.list5
  412. editSources()
  413. {
  414.     if grep '^# *deb cdrom:\[Debian' /etc/apt/sources.list
  415.     then
  416.         echo "cd already commented out, skipping!"
  417.     else
  418.         sed -i '/deb cdrom:\[Debian GNU\/Linux/s/^/#/' /etc/apt/sources.list
  419.     fi
  420. }
  421.  
  422. ####################################################33 update system6
  423.  
  424. updateSystem()
  425. {
  426.     apt update && apt upgrade -y
  427. }
  428.  
  429.  
  430. ###############################################################7
  431. ############################# check if programs installed and/or install
  432. checkPrograms()
  433. {
  434.     if [ ! -x /usr/bin/git ] && [ ! -x /usr/bin/wget ] && [ ! -x /usr/bin/curl ] && [ ! -x /usr/bin/gcc ] && [ ! -x /usr/bin/make ]
  435.     then
  436.         echo "Some tools with which to work with data not found installing now......................"
  437.         sleep 2
  438.         apt install -y git wget curl gcc make
  439.     fi
  440. }
  441.  
  442. #####################################################3 update sources.list and install software ############################################################
  443. updateSources_installSoftware()
  444. {
  445.     if grep "deb http://www.deb-multimedia.org" /etc/apt/sources.list
  446.     then
  447.         echo "Sources are setup already, skipping!"
  448.     else
  449.         /bin/cp -f "$WORK_DIR"/"$SOURCE" /etc/apt/sources.list || { echo "cp failed"; exit 127; }
  450.         chmod 644 /etc/apt/sources.list
  451.         wget http://www.deb-multimedia.org/pool/main/d/deb-multimedia-keyring/deb-multimedia-keyring_2016.8.1_all.deb || { echo "wget failed"; exit 127; }
  452.         dpkg -i deb-multimedia-keyring_2016.8.1_all.deb
  453.         wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
  454.         updateSystem || { echo "update system failed"; exit 127; }
  455.         apt install -y vlc vlc-data browser-plugin-vlc mplayer youtube-dl libdvdcss2 libdvdnav4 libdvdread4 smplayer mencoder build-essential \
  456.         gstreamer1.0-libav gstreamer1.0-plugins-bad gstreamer1.0-vaapi lame libfaac0 aacskeys libbdplus0 libbluray1 audacious audacious-plugins \
  457.         deadbeef kodi audacity cinelerra handbrake-gtk ffmpeg amarok k3b || { echo "some software failed to install!!!!!"; echo "some software failed to install"; \
  458.         sleep 10; }
  459.         ########################## Install flash in Mozilla Firefox ############################################
  460.         wget https://raw.githubusercontent.com/cybernova/fireflashupdate/master/fireflashupdate.sh || { echo "wget flash failed"; sleep 4; exit 127; }
  461.         chmod +x fireflashupdate.sh || { echo "chmod flash failed"; sleep 4; exit 127; }
  462.         ./fireflashupdate.sh
  463.         ######################### Setup the update tool to update flash weekly ###################################3
  464.         chown root:root fireflashupdate.sh || { echo "chown flash failed"; sleep 4; exit 127; }
  465.         /bin/mv fireflashupdate.sh /etc/cron.weekly/fireflashupdate || { echo "mv flash script failed"; sleep 4; exit 127; }
  466.        
  467.     fi
  468. }
  469.  
  470. ###############################################33  SETUP PORTSENTRY ############################################################
  471. ##############################################3                     ############################################################33
  472.  
  473. setup_portsentry()
  474. {
  475.     if  ! grep -q '^TCP_PORTS="1,7,9,11,15,70,79' /etc/portsentry/portsentry.conf
  476.     then
  477.         if [[ -f /etc/portsentry/portsentry.conf ]]
  478.         then
  479.             /bin/mv /etc/portsentry/portsentry.conf /etc/portsentry/portsentry.old
  480.         fi
  481.         if [[ ! -x /usr/sbin/portsentry ]]
  482.         then
  483.             apt install -y portsentry logcheck
  484.             /bin/cp -f "$WORK_DIR"/portsentry.conf /etc/portsentry/portsentry.conf || { echo "cp portsentry failed"; exit 127; }
  485.             /usr/sbin/service portsentry restart || { echo "service portsentry restart failed"; exit 127; }
  486.         fi
  487.     fi
  488. }
  489.  
  490. #####################################################3 run methods here↓   ###################################################3
  491. #####################################################                      ###################################################
  492. checkInternet || (echo "no network, bye" && exit 199)
  493. if [[ ! "$*" == "" ]]
  494. then
  495.     creatingNewUsers "$@"
  496. fi
  497. prepare_USERS.txt
  498. userPasswords
  499. setUPiptables
  500. setUPsshd
  501. editSources
  502. updateSystem
  503. #setup_portsentry    ######3 NEEDS WORK ##################################
  504. checkPrograms
  505. updateSources_installSoftware
  506. ###########################################################################################################            #####3##
  507. ##############################################################################################################3Methods
  508. ##########################################3 Disable login for www-data #########
  509. passwd -l www-data
  510. #################################### firmware
  511. apt install -y firmware-linux-nonfree firmware-linux
  512. apt install -y firmware-linux-free intel-microcode
  513. sleep 3
  514. ################ NANO SYNTAX-HIGHLIGHTING #####################3
  515. if [ ! -d "$WORK_DIR"/nanorc  ]
  516. then
  517.     if [ "$UID" != 0 ]
  518.     then
  519.         echo "This program should be run as root, goodbye!"
  520.         exit 127
  521.  
  522.     else
  523.         echo "Setting up Nanorc file for all users....please, wait!"
  524.         if [[ $PWD == "$WORK_DIR" ]]
  525.         then
  526.             echo "Program is in WORK_DIR...success!......."
  527.         else
  528.             echo "not in WORK_DIR...TRYING 'cd WORK_DIR'"
  529.             cd "$WORK_DIR" || { echo "cd failed"; exit 127; }
  530.         fi
  531.         git clone https://$OAUTH_TOKEN:x-auth-basic@github.com/gnihtemoSgnihtemos/nanorc || { echo "git in Nano SYNTAX-HIGHLIGHTING failed"; exit 127; }
  532.         chmod 755 "$WORK_DIR"/nanorc || { echo "chmod in Nano SYNTAX-HIGHLIGHTING failed"; exit 127; }
  533.         cd "$WORK_DIR"/nanorc || { echo "cd in Nano SYNTAX-HIGHLIGHTING failed"; exit 127; }
  534.         make install-global || { echo "make in Nano SYNTAX-HIGHLIGHTING failed"; exit 127; }
  535.         /bin/cp -f "$WORK_DIR/$NANORC" /etc/nanorc || { echo "cp in Nano SYNTAX-HIGHLIGHTING failed"; exit 127; }
  536.         chown root:root /etc/nanorc || { echo "chown in Nano SYNTAX-HIGHLIGHTING failed"; exit 127; }
  537.         chmod 644 /etc/nanorc || { echo "chmod in Nano SYNTAX-HIGHLIGHTING failed"; exit 127; }
  538.         if [ "$?" = 0 ]
  539.         then
  540.             echo "Implementing a custom nanorc file succeeded!"
  541.         else
  542.             echo "Nano setup DID NOT SUCCEED!"
  543.             exit 127
  544.         fi
  545.         echo "Finished setting up nano!"
  546.     fi
  547. fi
  548.  
  549. ################ LS_COLORS SETTINGS and bashrc file for all users #############################
  550. if ! grep 'eval $(dircolors -b $HOME/.dircolors)' /root/.bashrc
  551. then
  552.     echo "Setting root bashrc file....please wait!!!!"
  553.     if /bin/cp -f "$WORK_DIR/$BASHRCROOT" "$HOME"/.bashrc
  554.     then
  555.         echo "Root bashrc copy succeeded!"
  556.         sleep 2
  557.     else
  558.         echo "Root bashrc cp failed, exiting now!"
  559.         exit 127
  560.     fi
  561.     chown root:root "$HOME/.bashrc" || { echo "chown failed"; exit 127; }
  562.     chmod 644 "$HOME/.bashrc" || { echo "failed to chmod"; exit 127; }
  563.     wget https://raw.github.com/trapd00r/LS_COLORS/master/LS_COLORS -O "$HOME"/.dircolors || { echo "wget failed"; exit 127; }
  564.     echo 'eval $(dircolors -b $HOME/.dircolors)' >> "$HOME"/.bashrc || { echo "echo 'eval...dircolors -b'....to bashrc failed"; exit 127; }
  565. fi
  566. while read -r user
  567. do
  568.     if [ "$user" = root ]
  569.     then
  570.         continue
  571.     fi
  572.  
  573.     sudo -i -u "$user" user="$user" WORK_DIR="$WORK_DIR" BASHRC="$BASHRC" bash <<'EOF'
  574.     if grep 'eval $(dircolors -b $HOME/.dircolors)' "$HOME"/.bashrc
  575.     then
  576.         :
  577.     else
  578.         echo "Setting users=Bashrc files!"
  579.         if /bin/cp -f "$WORK_DIR"/"$BASHRC" "$HOME/.bashrc"
  580.         then
  581.             echo "Copy for $user (bashrc) succeeded!"
  582.             sleep 2
  583.         else
  584.             echo "Couldn't cp .bashrc for user $user"
  585.             exit 127
  586.         fi
  587.         chown $user:$user "$HOME/.bashrc" || { echo "chown failed"; exit 127; }
  588.         chmod 644 "$HOME/.bashrc" || { echo "chmod failed"; exit 127; }
  589.         wget https://raw.github.com/trapd00r/LS_COLORS/master/LS_COLORS -O "$HOME"/.dircolors || { echo "wget failed"; exit 127; }
  590.         echo 'eval $(dircolors -b $HOME/.dircolors)' >> "$HOME"/.bashrc
  591.     fi
  592. EOF
  593. done < "$WORK_DIR"/USERS.txt
  594.  
  595. echo "Finished setting up your system!"
  596. sleep 2
  597. ############ Give control back to these signals
  598. trap SIGINT SIGQUIT SIGTERM
  599. ############################
  600.  
  601. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement