install.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. #!/bin/sh
  2. #
  3. # MOTDs32 installation instructions
  4. # ==================================
  5. #
  6. # (2017) New project MOTDs32 Customized by Erreur32
  7. # Version 0.0.5
  8. #
  9. # https://gitlab.echosystem.fr/Erreur32/MOTDs32
  10. #
  11. # ,--. ,--. ,-----. ,--------.,------. ,----. ,---.
  12. # | `.' |' .-. ''--. .--'| .-. \ ,---. '.-. |'.-. \
  13. # | |'.'| || | | | | | | | \ :( .-' .' < .-' .'
  14. # | | | |' '-' ' | | | '--' /.-' `)/'-' |/ '-.
  15. # `--' `--' `-----' `--' `-------' `----' `----' '-----'
  16. #
  17. # | + Stats32 |
  18. #
  19. # MOTDstat is dynamicaly refreshing the /etc/motd file with current informations
  20. # about system status and usage.
  21. #
  22. # Copyright 2017 🅴🆁🆁🅴🆄🆁32
  23. # original project: Pavol Krigler <pavol.krigler@gelogic.net>
  24. #
  25. # make sur this file is executable +x
  26. ################################################################################
  27. #
  28. # Installation
  29. # ============
  30. #
  31. # As root execute this command (the easy way!):
  32. #
  33. # # ./install.sh
  34. # or
  35. # # bash install-sh
  36. #
  37. #
  38. ################################################################################
  39. # Make sure only root can run our script
  40. if [[ $EUID -ne 0 ]]; then
  41. echo "This script must be run as root" 1>&2
  42. exit 1
  43. fi
  44. ## clean terminal
  45. #clear;
  46. BG_BLUE="$(tput setab 4)"
  47. BG_BLACK="$(tput setab 0)"
  48. FG_GREEN="$(tput setaf 2)"
  49. FG_WHITE="$(tput setaf 7)"
  50. # Save screen
  51. tput smcup
  52. # Display menu until selection == 0
  53. while [[ $REPLY != 0 ]]; do
  54. echo -n ${BG_BLACK}${FG_WHITE}
  55. clear
  56. cat <<- "EOFMO"
  57. Installation of MOTDs32 | + Stats32 |
  58. ,--. ,--. ,-----. ,--------.,------. ,----. ,---.
  59. | `.' |' .-. ''--. .--'| .-. \ ,---. '.-. |'.-. \
  60. | |'.'| || | | | | | | | \ :( .-' .' ; .-' .'
  61. | | | |' '-' ' | | | '--' /.-' `)/'-' |/ '-.
  62. `--' `--' `-----' `--' `-------' `----' `----' '-----'
  63. By Erreur32
  64. EOFMO
  65. echo -e "\033[1;30m # MOTDs32 is dynamicaly refreshing the /etc/motd file with current informations"
  66. echo -e "\033[1;30m # about system status and usage."
  67. echo -e "\n \e[34m Installation of MOTDs32 in progress... \e[0m\n\n"
  68. # Check dependenciess
  69. echo -e "\e[34m Check required dependencies ! (need to be installed)"
  70. # Check installed
  71. if [ -f "/usr/sbin/sendmail" ]
  72. then
  73. echo -e " \e[34m- Posfix \e[92m OK\e[0m\n"
  74. else
  75. echo -e " \e[34m- Select option 1 \e[91m Missing package !! \e[0m\n"
  76. fi
  77. if [ -f "/usr/share/build-essential/essential-packages-list" ]
  78. then
  79. echo -e " \e[34m- build-dep \e[32m✔ installed.\e[0m"
  80. else
  81. echo -e " \e[34m- build-dep \e[1;31mSelect option 1 \e[91m Missing package !!\e[0m"
  82. fi
  83. # Check files
  84. if hash figlet 2>/dev/null; then
  85. echo -e " \e[34m- Figlet \e[32m✔ installed.\e[0m"
  86. else
  87. echo -e " \e[34m- Figlet \e[1;31m Select option 1 \e[91m Missing package !!\e[0m"
  88. fi
  89. if hash ntpd 2>/dev/null; then
  90. echo -e " \e[34m- NTP \e[32m✔ installed.\e[0m"
  91. else
  92. echo -e " \e[34m- NTP \e[1;31mSelect option 1 \e[91m Missing package !!\e[0m"
  93. fi
  94. if hash make 2>/dev/null; then
  95. echo -e " \e[34m- build-essential \e[32m✔ installed.\e[0m"
  96. else
  97. echo -e " \e[34m- build-essential \e[1;31mSelect option 1 \e[91m Missing package !!\e[0m"
  98. fi
  99. echo -e "\n YOU CAN SKIP (auto) install if you want"
  100. echo -e "\n\e[92m Please Select:"
  101. echo -e " 1. \e[0m(auto) Install Missing Package\e[92m"
  102. echo -e " 2. \e[0mInstallation MOTDs32 script\e[92m"
  103. echo -e " 3. \e[0mUninstall completly MOTDs32 script\e[92m"
  104. echo -e " 0. \e[0m(Enter or any key) to Quit\n \e[0m"
  105. read -p " Enter selection [0-3] or (Enter) to Quit > " selection
  106. # Clear area beneath menu
  107. tput cup 10 0
  108. echo -n ${BG_BLACK}${FG_GREEN}
  109. tput ed
  110. tput cup 11 0
  111. # Act on selection
  112. case $selection in
  113. 1) echo -e " \e[32m install missing package ...\e[0m\n"
  114. apt-get install --allow-unauthenticated -y build-essential ntp figlet postfix sasl2-bin
  115. echo -e "\n\e[34m - apt-get installation build-essential ntp figlet \e[0m>> Succesfull"
  116. if [ -f "/usr/bin/motds32" ]
  117. then
  118. echo -e "\n\e[34m - Make file \e[0m>> founded.\e[0m\n"
  119. #make install
  120. #echo -e "\n\e[34m - REMake file done.\e[0m\n"
  121. else
  122. echo -e "\n\e[92m -Building binary \e[0m\n"
  123. make install
  124. echo -e "\n\e[34m - Make file done.\e[0m\n"
  125. fi
  126. echo -e "\e[92m"
  127. if [ `grep -c /etc/motd /root/.bashrc` == 0 ]
  128. then
  129. echo -e " \e[1;31m code bash missing"
  130. echo "cat /etc/motd" >> /root/.bashrc
  131. echo -e "\e[92m - Code bash \e[0madded.\n"
  132. else
  133. grepmot=`grep '/etc/motd' /root/.bashrc`
  134. echo -e " \e[1;30m Code bash found: \e[0m>>\e[0m $grepmot \e[0m<<\n"
  135. echo -e " -->\e[34m Code bash: \e[92mOK\e[0m"
  136. fi
  137. # Check if MOTDs32 is already add
  138. if test ! -d /etc/motds32; then mkdir -p /etc/motds32; fi
  139. if [ -f "/etc/motds32/Stats32" ]
  140. then
  141. echo -e " -->\e[34m Stats32 \e[92mFOUND\e[0m"
  142. cp Stats32 /etc/motds32/Stats32 -Rf
  143. else
  144. cp Stats32 /etc/motds32/Stats32 -Rf
  145. echo -e " -->\e[34m Stats32 \e[92mINSTALLED\e[0m"
  146. fi
  147. # Copy font figlet
  148. if [ -f "/usr/share/figlet" ]
  149. then
  150. echo -e " -->\e[31m figlet not FOUND\e[0m"
  151. else
  152. cp -Rf fonts/chunky.flf /usr/share/figlet/
  153. echo -e " -->\e[34m Font figlet \e[92mOK\e[0m"
  154. fi
  155. # Check if motd is installed correctly
  156. if [ -f "/usr/bin/motd" ]
  157. then
  158. echo -e " -->\e[34m motd check \e[92mOK\e[0m\n"
  159. else
  160. ln -s /usr/bin/motds32 /usr/bin/motd
  161. echo -e " -->\e[34m motd bin \e[92mOK\e[0m\n"
  162. fi
  163. ## Install Crontab
  164. if crontab -l | grep -q '/usr/bin/motds32'; then
  165. echo -e " \e[34m -Cron \e[0m>> already added.\e[0m"
  166. else
  167. echo -e "\e[34m - Cron added.\e[0m"
  168. (crontab -l ; echo "*/5 * * * * /usr/bin/motds32 -g 2>1")| crontab -
  169. fi
  170. ## Generate first stats
  171. if test -f /usr/bin/motds32; then /usr/bin/motds32 -g; fi
  172. echo -e "\n\n\e[34m \e[92m Installation of MOTDs32 completed!\e[0m \n\n\n Help? Use: \n \033[1;30m /usr/bin/motds32\e[0m \n or \033[1;30m\n motd\e[0m\n"
  173. printf "\n \e[1;33m (Press 0 to exit)\e[0m"
  174. printf "\n \e[1;33m (Or any key to go back.)\e[0m"
  175. ;;
  176. 2) echo -e "\n\e[92m"
  177. if [ `grep -c /etc/motd /root/.bashrc` == 0 ]
  178. then
  179. echo -e " code bash missing"
  180. echo "cat /etc/motd" >> /root/.bashrc
  181. echo -e "\e[92m - Code bash \e[0madded.\n"
  182. else
  183. grepmot=`grep '/etc/motd' /root/.bashrc`
  184. echo -e " \e[1;30m Code bash found: \e[0m>>\e[0m $grepmot \e[0m<<\n"
  185. echo -e " -->\e[34m Code bash: \e[92mOK\e[0m"
  186. fi
  187. # Check if MOTDs32 is already add
  188. if test ! -d /etc/motds32; then mkdir -p /etc/motds32; fi
  189. if [ -f "/usr/bin/motds32" ]
  190. then
  191. echo -e "\n\e[34m - Make file \e[0m>> founded.\e[0m\n"
  192. #make install
  193. #echo -e "\n\e[34m - REMake file done.\e[0m\n"
  194. else
  195. echo -e "\n\e[92m -Building binary \e[0m\n"
  196. make install
  197. echo -e "\n\e[34m - Make file done.\e[0m\n"
  198. fi
  199. if [ -f "/etc/motds32/Stats32" ]
  200. then
  201. echo -e " -->\e[34m Stats32 \e[92mFOUND\e[0m"
  202. cp Stats32 /etc/motds32/Stats32 -Rf
  203. else
  204. cp Stats32 /etc/motds32/Stats32 -Rf
  205. echo -e " -->\e[34m Stats32 \e[92mINSTALLED\e[0m"
  206. fi
  207. # Copy font figlet
  208. if [ -f "/usr/share/figlet" ]
  209. then
  210. echo -e " -->\e[31m figlet not FOUND\e[0m"
  211. else
  212. cp -Rf fonts/chunky.flf /usr/share/figlet/
  213. echo -e " -->\e[34m Font figlet \e[92mOK\e[0m"
  214. fi
  215. # Check if motd ins talled correctly
  216. if [ -f "/usr/bin/motd" ]
  217. then
  218. echo -e " -->\e[34m motd check \e[92mOK\e[0m\n"
  219. else
  220. ln -s /usr/bin/motds32 /usr/bin/motd
  221. echo -e " -->\e[34m motd bin \e[92mOK\e[0m\n"
  222. fi
  223. ## Install Crontab
  224. if crontab -l | grep -q '/usr/bin/motds32'; then
  225. echo -e "\e[34m - Cron \e[0m>> already added.\e[0m"
  226. else
  227. echo -e "\e[34m - Cron added.\e[0m"
  228. (crontab -l ; echo "*/5 * * * * /usr/bin/motds32 -g 2>1")| crontab -
  229. fi
  230. ## Generate first stats
  231. if test -f /usr/bin/motds32; then /usr/bin/motds32 -g; fi
  232. echo -e "\n\n\e[34m \e[92m Installation of MOTDs32 completed!\e[0m \n\n\n Help? Use: \n \033[1;30m /usr/bin/motds32\e[0m \n or \033[1;30m\n motd\e[0m\n"
  233. printf "\n \e[1;33m (Press any key to exit.)\e[0m"
  234. ;;
  235. 3) echo -e "\n\e[34m Dsinstallation of MOTDs32 in progress... \e[0m"
  236. ## remove file and directory
  237. make uninstall
  238. rm /etc/motds32/ -Rf
  239. rm /usr/bin/motd -f
  240. rm /var/cache/motds32/ -Rf
  241. ## remove cron
  242. if crontab -l | grep -q '/usr/bin/motds32'; then
  243. echo -e " \e[92m Cron localized\n"
  244. crontab -l | grep -v '/usr/bin/motds32 -g 2>1' | crontab -u root -
  245. echo -e " \e[92m Cron removed\n"
  246. else
  247. echo -e " \e[93m Cron not find\n"
  248. fi
  249. if [ `grep -c /etc/motd /root/.bashrc` == 0 ]
  250. then
  251. echo " Code bash not founded"
  252. else
  253. echo " code bash founded"
  254. sed -i '/cat \/etc\/motd/d' /root/.bashrc
  255. echo -e "\e[92m Code .bashrc remove.\e[0m"
  256. grep -n '/etc/motd' /root/.bashrc
  257. fi
  258. echo -e "\n\e[92m Script MOTDs32 has been completly removed \e[0m"
  259. printf "\n \e[1;33m (Press any key.)\e[0m"
  260. ;;
  261. 0) break
  262. ;;
  263. *) break
  264. ;;
  265. esac
  266. read -n 1
  267. # echo -e "\n\n\e[34m \e[92m Installation of MOTDs32 completed!\e[0m \n\n\n Help? Use: \n \033[1;30m /usr/bin/motds32\e[0m \n or \033[1;30m\n motd\e[0m\n"
  268. # printf "\n \e[1;33m (Press any key to exit.)\e[0m"
  269. done
  270. # Restore screen
  271. tput rmcup
  272. echo "Installation MOTDs32 terminated."