install-debian-server.sh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. #!/bin/sh
  2. # bachir soussi chiadmi
  3. #
  4. # http://www.pontikis.net/blog/debian-9-stretch-rc3-web-server-setup-php7-mariadb
  5. # http://web-74.com/blog/reseaux/gerer-le-deploiement-facilement-avec-git/
  6. #
  7. echo '\033[35m
  8. ____ __ _ _____
  9. / __ \___ / /_ (_)___ _____ / ___/___ ______ _____ _____
  10. / / / / _ \/ __ \/ / __ `/ __ \ \__ \/ _ \/ ___/ | / / _ \/ ___/
  11. / /_/ / __/ /_/ / / /_/ / / / / ___/ / __/ / | |/ / __/ /
  12. /_____/\___/_.___/_/\__,_/_/ /_/ /____/\___/_/ |___/\___/_/
  13. \033[0m'
  14. echo "\033[35;1mThis script has been tested only on Linux Debian 9 \033[0m"
  15. echo "Please run this script as root"
  16. echo -n "Should we start? [Y|n] "
  17. read yn
  18. yn=${yn:-y}
  19. if [ "$yn" != "y" ]; then
  20. echo "aborting script!"
  21. exit
  22. fi
  23. # get the current position
  24. _cwd="$(pwd)"
  25. echo '\033[35m
  26. __ ______ __________ ___ ____ ______
  27. / / / / __ \/ ____/ __ \/ | / __ \/ ____/
  28. / / / / /_/ / / __/ /_/ / /| | / / / / __/
  29. / /_/ / ____/ /_/ / _, _/ ___ |/ /_/ / /___
  30. \____/_/ \____/_/ |_/_/ |_/_____/_____/
  31. \033[0m'
  32. apt-get update
  33. apt-get upgrade
  34. echo '\033[35m
  35. __ ____
  36. / |/ (_)_________
  37. / /|_/ / / ___/ ___/
  38. / / / / (__ ) /__
  39. /_/ /_/_/____/\___/
  40. \033[0m'
  41. apt-get install vim
  42. sed -i "s/^# en_GB.UTF-8/en_GB.UTF-8/g" /etc/locale.gen
  43. locale-gen
  44. apt-get install ntp
  45. echo '\033[35m
  46. ______________ _______ _____ __ __
  47. / ____/ _/ __ \/ ____/ | / / | / / / /
  48. / /_ / // /_/ / __/ | | /| / / /| | / / / /
  49. / __/ _/ // _, _/ /___ | |/ |/ / ___ |/ /___/ /___
  50. /_/ /___/_/ |_/_____/ |__/|__/_/ |_/_____/_____/
  51. \033[0m'
  52. echo "\033[35;1mInstalling ufw and setup firewall (allowing only ssh and http) \033[0m"
  53. sleep 3
  54. apt-get install ufw
  55. # ufw allow ssh # knockd will open the ssh port
  56. ufw allow http
  57. ufw allow https
  58. ufw enable
  59. ufw status verbose
  60. echo "\033[92;1mufw installed and firwall configured\033[Om"
  61. echo '\033[35m
  62. ______ _ _____ __
  63. / ____/___ _(_) /__ \ / /_ ____ _____
  64. / /_ / __ `/ / /__/ // __ \/ __ `/ __ \
  65. / __/ / /_/ / / // __// /_/ / /_/ / / / /
  66. /_/ \__,_/_/_//____/_.___/\__,_/_/ /_/
  67. \033[0m'
  68. echo "\033[35;1mInstalling fall2ban \033[0m"
  69. apt-get install fail2ban
  70. cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
  71. # ToDo ask for email and configure jail.local with it
  72. service fail2ban restart
  73. echo "\033[92;1mfail2ban installed and configured\033[Om"
  74. echo '\033[35m
  75. __ __ __
  76. / /______ ____ _____/ /______/ /
  77. / //_/ __ \/ __ \/ ___/ //_/ __ /
  78. / ,< / / / / /_/ / /__/ ,< / /_/ /
  79. /_/|_/_/ /_/\____/\___/_/|_|\__,_/
  80. \033[0m'
  81. echo "\033[35;1mInstalling knockd \033[0m"
  82. sleep 3
  83. apt-get install knockd
  84. echo -n "define a sequence number for opening (as 7000,8000,9000) : "
  85. read sq1
  86. echo -n "define a sequence number for closing (as 9000,8000,7000) : "
  87. read sq2
  88. sed -i "s/7000,8000,9000/$sq1/g" /etc/knockd.conf
  89. sed -i "s/9000,8000,7000/$sq2/g" /etc/knockd.conf
  90. sed -i 's/START_KNOCKD=0/START_KNOCKD=1/g' /etc/default/knockd
  91. service knockd start
  92. echo "\033[92;1mknockd installed and configured\033[Om"
  93. echo "\033[92;1mplease note these sequences for future knocking\033[Om"
  94. echo "opening : $sq1 ; closing : $sq2"
  95. echo '\033[35m
  96. __ _______ __________
  97. / / / / ___// ____/ __ \
  98. / / / /\__ \/ __/ / /_/ /
  99. / /_/ /___/ / /___/ _, _/
  100. \____//____/_____/_/ |_|
  101. \033[0m'
  102. echo "\033[35;1mCreate new user (you will be asked a user name and a password) \033[0m"
  103. sleep 3
  104. echo -n "Enter user name: "
  105. read user
  106. # read -p "Continue? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
  107. adduser "$user"
  108. echo "adding $user to admin group and limiting su to the admin group"
  109. groupadd admin
  110. usermod -a -G admin "$user"
  111. # allow admin group to su
  112. dpkg-statoverride --update --add root admin 4750 /bin/su
  113. echo "\033[92;1muser $user configured\033[Om"
  114. echo '\033[35m
  115. __ ______ ______
  116. / |/ / | / _/ /
  117. / /|_/ / /| | / // /
  118. / / / / ___ |_/ // /___
  119. /_/ /_/_/ |_/___/_____/
  120. \033[0m'
  121. echo "\033[35;1mEnable mail sending for php \033[0m"
  122. # http://www.sycha.com/lamp-setup-debian-linux-apache-mysql-php#anchor13
  123. sleep 3
  124. apt-get install exim4
  125. echo "\033[35;1mConfiguring EXIM4 \033[0m"
  126. while [ "$configexim" != "y" ] && [ "$configexim" != "n" ]
  127. do
  128. echo -n "Should we configure exim4 ? [y|n] "
  129. read configexim
  130. done
  131. if [ "$configexim" = "y" ]; then
  132. echo "choose the first option :internet site; mail is sent and received directly using SMTP. Leave the other options as default exepted for domain name which should be valid domain name if you want your mails to not be considered as spam"
  133. echo "press any key to continue."
  134. read continu
  135. dpkg-reconfigure exim4-config
  136. else
  137. echo 'exim not configured'
  138. fi
  139. service exim4 restart
  140. # dkim spf
  141. # https://debian-administration.org/article/718/DKIM-signing_outgoing_mail_with_exim4
  142. echo "\033[35;1mConfiguring DKIM \033[0m"
  143. while [ "$installdkim" != "y" ] && [ "$installdkim" != "n" ]
  144. do
  145. echo -n "Should we install dkim for exim4 ? [y|n] "
  146. read installdkim
  147. done
  148. if [ "$installdkim" = "y" ]; then
  149. echo -n "Choose a domain for dkim (same domain as you chose before for exim4): "
  150. read domain
  151. selector=$(date +%Y%m%d)
  152. mkdir /etc/exim4/dkim
  153. openssl genrsa -out /etc/exim4/dkim/"$domain"-private.pem 1024 -outform PEM
  154. openssl rsa -in /etc/exim4/dkim/"$domain"-private.pem -out /etc/exim4/dkim/"$domain".pem -pubout -outform PEM
  155. chown root:Debian-exim /etc/exim4/dkim/"$domain"-private.pem
  156. chmod 440 /etc/exim4/dkim/"$domain"-private.pem
  157. cp "$_cwd"/assets/exima4_dkim.conf /etc/exim4/conf.d/main/00_local_macros
  158. sed -ir "s/DOMAIN_TO_CHANGE/$domain/g" /etc/exim4/conf.d/main/00_local_macros
  159. sed -ir "s/DATE_TO_CHANGE/$selector/g" /etc/exim4/conf.d/main/00_local_macros
  160. update-exim4.conf
  161. service exim4 restart
  162. echo "please create a TXT entry in your dns zone : $selector._domainkey.$domain \n"
  163. echo "your public key is : \n"
  164. cat /etc/exim4/dkim/"$domain".pem
  165. echo "press any key to continue."
  166. read continu
  167. else
  168. echo 'dkim not installed'
  169. fi
  170. echo '\033[35m
  171. __________ __ __
  172. / ___/ ___// / / /
  173. \__ \\__ \/ /_/ /
  174. ___/ /__/ / __ /
  175. /____/____/_/ /_/
  176. \033[0m'
  177. while [ "$securssh" != "y" ] && [ "$securssh" != "n" ]
  178. do
  179. echo -n "Securing ssh (disabling root login)? [y|n] "
  180. read securssh
  181. # securssh=${securssh:-y}
  182. done
  183. if [ "$securssh" = "y" ]; then
  184. sed -i 's/PermitRootLogin\ yes/PermitRootLogin no/g' /etc/ssh/sshd_config
  185. sed -i 's/PermitEmptyPasswords\ yes/PermitEmptyPasswords no/g' /etc/ssh/sshd_config
  186. sed -i 's/Protocol\ [0-9]/Protocol 2/g' /etc/ssh/sshd_config
  187. service ssh reload
  188. echo "\033[92;1mSSH secured\033[Om"
  189. else
  190. echo 'root user can still conect through ssh'
  191. fi
  192. echo '\033[35m
  193. ______ _______ _____
  194. | ____|__ __| __ \
  195. | |__ | | | |__) |
  196. | __| | | | ___/
  197. | | | | | |
  198. |_| |_| |_|
  199. \033[0m'
  200. echo -n "Should we install ftp server? [Y|n] "
  201. read yn
  202. yn=${yn:-y}
  203. if [ "$yn" = "y" ]; then
  204. echo "installing proftpd"
  205. apt-get install proftpd
  206. while [ "$_server_name" = "" ]
  207. do
  208. read -p "enter a server name ? " _server_name
  209. if [ "$_server_name" != "" ]; then
  210. read -p "is server name $_server_name correcte [y|n] " validated
  211. if [ "$validated" = "y" ]; then
  212. break
  213. else
  214. _server_name=""
  215. fi
  216. fi
  217. done
  218. echo "Configuring proftpd"
  219. cp "$_cwd"/assets/proftpd.conf /etc/proftpd/conf.d/"$_server_name".conf
  220. sed -ir "s/example/$_server_name/g" /etc/proftpd/conf.d/"$_server_name".conf
  221. ufw allow ftp
  222. addgroup ftpuser
  223. echo "ftp installtion done"
  224. echo "to permit to a user to connect through ftp, add him to the ftpuser group by running : usermod -a -G admin USERNAME"
  225. echo "FTP users are jailed on their home by default"
  226. fi
  227. # TODO : allow ssh/ftp connection only from given ips
  228. echo "\033[35;1mInstalling AMP web server \033[0m"
  229. echo '\033[35m
  230. __ ___ __
  231. / |/ /_ ___________ _/ /
  232. / /|_/ / / / / ___/ __ `/ /
  233. / / / / /_/ (__ ) /_/ / /
  234. /_/ /_/\__, /____/\__, /_/
  235. /____/ /_/
  236. \033[0m'
  237. echo "\033[35;1minstalling Mysql \033[0m"
  238. sleep 3
  239. apt-get install mariadb-server
  240. mysql_secure_installation
  241. systemctl restart mariadb.service
  242. echo "\033[92;1mmysql installed\033[Om"
  243. echo '\033[35m
  244. ___ __ ___
  245. / | ____ ____ ______/ /_ ___ |__ \
  246. / /| | / __ \/ __ `/ ___/ __ \/ _ \__/ /
  247. / ___ |/ /_/ / /_/ / /__/ / / / __/ __/
  248. /_/ |_/ .___/\__,_/\___/_/ /_/\___/____/
  249. /_/
  250. \033[0m'
  251. echo "\033[35;1mInstalling Apache2 \033[0m"
  252. sleep 3
  253. apt-get install apache2
  254. a2enmod rewrite
  255. # cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.back
  256. # cat "$_cwd"/assets/apache2.conf > /etc/apache2/apache2.conf
  257. # Change logrotate for Apache2 log files to keep 10 days worth of logs
  258. sed -i 's/\tweekly/\tdaily/' /etc/logrotate.d/apache2
  259. sed -i 's/\trotate .*/\trotate 10/' /etc/logrotate.d/apache2
  260. # Remove Apache server information from headers.
  261. sed -i 's/ServerTokens .*/ServerTokens Prod/' /etc/apache2/conf-enabled/security.conf
  262. sed -i 's/ServerSignature .*/ServerSignature Off/' /etc/apache2/conf-enabled/security.conf
  263. service apache2 restart
  264. echo "\033[92;1mApache2 installed\033[Om"
  265. echo '\033[35m
  266. ____ __ ______
  267. / __ \/ / / / __ \
  268. / /_/ / /_/ / /_/ /
  269. / ____/ __ / ____/
  270. /_/ /_/ /_/_/
  271. \033[0m'
  272. echo "\033[35;1mInstalling PHP \033[0m"
  273. sleep 3
  274. apt-get install php7.0 php-pear php7-gd
  275. echo "Configuring PHP"
  276. cp "$_cwd"/assets/99-lamp-php.ini /etc/php/7.0/apache2/conf.d/
  277. # conffile=/etc/php/7.0/apache2/conf.d/99-lamp-php.ini
  278. # cp /etc/php/7.0/apache2/php.ini $conffile
  279. # sed -i "s/max_execution_time\ =\ [0-9]\+/max_execution_time = 60/g" $conffile
  280. # sed -i "s/max_input_time\ =\ [0-9]\+/max_input_time = 60/g" $conffile
  281. # sed -i "s/memory_limit\ =\ [0-9]\+M/memory_limit = 512M/g" $conffile
  282. # sed -i "s/;\?error_reporting\ =\ [^\n]\+/error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR/g" $conffile
  283. # sed -i "s/;\?display_errors\ =\ On/display_errors = Off/g" $conffile
  284. # sed -i "s/;\?log_errors\ =\ Off/log_errors = On/g" $conffile
  285. # echo "register_globals = Off" >> $conffile
  286. # following command doesn't work, make teh change manualy
  287. #sed -ri ":a;$!{N;ba};s/;\?\ \?error_log\ =\ [^\n]\+([^\n]*\n(\n|$))/error_log = \/var\/log\/php\/error.log\1/g" /etc/php5/apache2/php.ini
  288. mkdir /var/log/php
  289. chown www-data /var/log/php
  290. cp "$_cwd"/assets/logrotate-php /etc/logrotate.d/php
  291. apt-get install php7.0-mysql php7.0-curl php7.0-mbstring php7.0-zip php7.0-xml php7.0-gd php7.0-mcrypt php-memcached
  292. apt-get install memcached
  293. sed -i "s/-m\s64/-m 128/g" /etc/memcached.conf
  294. systemctl start memcached
  295. echo "\033[92;1mphp installed\033[Om"
  296. echo '\033[35m
  297. __ __ ___ ___ __ _
  298. ____ / /_ ____ / |/ /_ __/ | ____/ /___ ___ (_)___
  299. / __ \/ __ \/ __ \/ /|_/ / / / / /| |/ __ / __ `__ \/ / __ \
  300. / /_/ / / / / /_/ / / / / /_/ / ___ / /_/ / / / / / / / / / /
  301. / .___/_/ /_/ .___/_/ /_/\__, /_/ |_\__,_/_/ /_/ /_/_/_/ /_/
  302. /_/ /_/ /____/
  303. \033[0m'
  304. echo "\033[35;1mInstalling phpMyAdmin \033[0m"
  305. apt-get install phpmyadmin
  306. # echo "include /etc/phpmyadmin/apache.conf" >> /etc/apache2/apache2.conf
  307. ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
  308. a2enconf phpmyadmin.conf
  309. echo "\033[35;1msecuring phpMyAdmin \033[0m"
  310. # sed -i "s/DirectoryIndex index.php/DirectoryIndex index.php\nAllowOverride all/"
  311. cp "$_cwd"/assets/phpmyadmin_htaccess > /usr/share/phpmyadmin/.htaccess
  312. echo -n "define a user name for phpmyadmin : "
  313. read un
  314. htpasswd -c /etc/phpmyadmin/.htpasswd $un
  315. service apache2 restart
  316. echo "\033[92;1mphpMyAdmin installed\033[Om"
  317. echo "\033[92;1mYou can access it at yourip/phpmyadmin\033[Om"
  318. echo '\033[35m
  319. __ __
  320. _ __/ /_ ____ _____/ /_
  321. | | / / __ \/ __ \/ ___/ __/
  322. | |/ / / / / /_/ (__ ) /_
  323. |___/_/ /_/\____/____/\__/
  324. \033[0m'
  325. echo "\033[35;1mVHOST install \033[0m"
  326. while [ "$vh" != "y" ] && [ "$vh" != "n" ]
  327. do
  328. echo -n "Should we install a vhost? [y|n] "
  329. read vh
  330. # vh=${vh:-y}
  331. done
  332. if [ "$vh" = "y" ]; then
  333. while [ "$_host_name" = "" ]
  334. do
  335. read -p "enter a hostname ? " _host_name
  336. if [ "$_host_name" != "" ]; then
  337. read -p "is hostname $_host_name correcte [y|n] " validated
  338. if [ "$validated" = "y" ]; then
  339. break
  340. else
  341. _host_name=""
  342. fi
  343. fi
  344. done
  345. cp "$_cwd"/assets/example.org.conf /etc/apache2/sites-available/"$_host_name".conf
  346. sed -ir "s/example\.org/$_host_name/g" /etc/apache2/sites-available/"$_host_name".conf
  347. mkdir -p /srv/www/"$_host_name"/public_html
  348. mkdir /srv/www/"$_host_name"/logs
  349. #set proper right to user will handle the app
  350. chown -R root:admin /srv/www/"$_host_name"/
  351. chmod -R g+w /srv/www/"$_host_name"/
  352. chmod -R g+r /srv/www/"$_host_name"/
  353. # create a shortcut to the site
  354. mkdir /home/"$user"/www/
  355. chown "$user":admin /home/"$user"/www/
  356. ln -s /srv/www/"$_host_name" /home/"$user"/www/"$_host_name"
  357. #activate the vhost
  358. a2ensite "$_host_name".conf
  359. #restart apache
  360. service apache2 restart
  361. echo "\033[92;1mvhost $_host_name configured\033[Om"
  362. else
  363. echo "Vhost installation aborted"
  364. fi
  365. # TODO supervising
  366. # echo '\033[35m
  367. # __ ___ _ __ __ __ ___ _
  368. # / |/ /__ ___ (_) /_ _/_/ / |/ /_ _____ (_)__
  369. # / /|_/ / _ \/ _ \/ / __/ _/_/ / /|_/ / // / _ \/ / _ \
  370. # /_/ /_/\___/_//_/_/\__/ /_/ /_/ /_/\_,_/_//_/_/_//_/
  371. # \033[0m'
  372. # echo "\033[35;1mInstalling Munin \033[0m"
  373. # sleep 3
  374. # # https://www.howtoforge.com/tutorial/server-monitoring-with-munin-and-monit-on-debian/
  375. # apt-get install munin munin-node munin-plugins-extra
  376. # # Configure Munin
  377. # # enable plugins
  378. # ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_
  379. # ln -s /usr/share/munin/plugins/mysql_bytes /etc/munin/plugins/mysql_bytes
  380. # ln -s /usr/share/munin/plugins/mysql_innodb /etc/munin/plugins/mysql_innodb
  381. # ln -s /usr/share/munin/plugins/mysql_isam_space_ /etc/munin/plugins/mysql_isam_space_
  382. # ln -s /usr/share/munin/plugins/mysql_queries /etc/munin/plugins/mysql_queries
  383. # ln -s /usr/share/munin/plugins/mysql_slowqueries /etc/munin/plugins/mysql_slowqueries
  384. # ln -s /usr/share/munin/plugins/mysql_threads /etc/munin/plugins/mysql_threads
  385. #
  386. # ln -s /usr/share/munin/plugins/apache_accesses /etc/munin/plugins/
  387. # ln -s /usr/share/munin/plugins/apache_processes /etc/munin/plugins/
  388. # ln -s /usr/share/munin/plugins/apache_volume /etc/munin/plugins/
  389. #
  390. # # ln -s /usr/share/munin/plugins/fail2ban /etc/munin/plugins/
  391. #
  392. # # dbdir, htmldir, logdir, rundir, and tmpldir
  393. # sed -i 's/^#dbdir/dbdir/' /etc/munin/munin.conf
  394. # sed -i 's/^#htmldir/htmldir/' /etc/munin/munin.conf
  395. # sed -i 's/^#logdir/logdir/' /etc/munin/munin.conf
  396. # sed -i 's/^#rundir/rundir/' /etc/munin/munin.conf
  397. # sed -i 's/^#tmpldir/tmpldir/' /etc/munin/munin.conf
  398. #
  399. # sed -i "s/^\[localhost.localdomain\]/[${HOSTNAME}]/" /etc/munin/munin.conf
  400. #
  401. # # ln -s /etc/munin/apache24.conf /etc/apache2/conf-enabled/munin.conf
  402. # sed -i 's/Require local/Require all granted\nOptions FollowSymLinks SymLinksIfOwnerMatch/g' /etc/munin/apache24.conf
  403. # htpasswd -c /etc/munin/munin-htpasswd admin
  404. # sed -i 's/Require all granted/AuthUserFile \/etc\/munin\/munin-htpasswd\nAuthName "Munin"\nAuthType Basic\nRequire valid-user/g' /etc/munin/apache24.conf
  405. #
  406. #
  407. # service apache2 restart
  408. # service munin-node restart
  409. # echo "\033[92;1mMunin installed\033[Om"
  410. #
  411. # echo "\033[35;1mInstalling Monit \033[0m"
  412. # sleep 3
  413. # # https://www.howtoforge.com/tutorial/server-monitoring-with-munin-and-monit-on-debian/2/
  414. # apt-get install monit
  415. # # TODO setup monit rc
  416. # cat "$_cwd"/assets/monitrc > /etc/monit/monitrc
  417. #
  418. # # TODO setup webaccess
  419. # passok=0
  420. # while [ "$passok" = "0" ]
  421. # do
  422. # echo -n "Write web access password to monit"
  423. # read passwda
  424. # echo -n "ReWrite web access password to monit"
  425. # read passwdb
  426. # if [ "$passwda" = "$passwdb" ]; then
  427. # sed -i 's/PASSWD_TO_REPLACE/$passwda/g' /etc/monit/monitrc
  428. # passok=1
  429. # else
  430. # echo "pass words don't match, please try again"
  431. # fi
  432. # done
  433. #
  434. # # TODO setup mail settings
  435. # sed -i "s/server1\.example\.com/$HOSTNAME/g" /etc/monit/monitrc
  436. #
  437. # mkdir /var/www/html/monit
  438. # echo "hello" > /var/www/html/monit/token
  439. #
  440. # service monit start
  441. #
  442. # echo "\033[92;1mMonit installed\033[Om"
  443. # echo '\033[35m
  444. # ___ __ __
  445. # / |_ _______/ /_____ _/ /_
  446. # / /| | | /| / / ___/ __/ __ `/ __/
  447. # / ___ | |/ |/ (__ ) /_/ /_/ / /_
  448. # /_/ |_|__/|__/____/\__/\__,_/\__/
  449. # \033[0m'
  450. # echo "\033[35;1mInstalling Awstat \033[0m"
  451. # sleep 3
  452. # apt-get install awstats
  453. # # Configure AWStats
  454. # temp=`grep -i sitedomain /etc/awstats/awstats.conf.local | wc -l`
  455. # if [ $temp -lt 1 ]; then
  456. # echo SiteDomain="$_host_name" >> /etc/awstats/awstats.conf.local
  457. # fi
  458. # # Disable Awstats from executing every 10 minutes. Put a hash in front of any line.
  459. # sed -i 's/^[^#]/#&/' /etc/cron.d/awstats
  460. # echo "\033[92;1mAwstat installed\033[Om"
  461. # echo '\033[35m
  462. # ______________ _______
  463. # /_ __/ ____/ |/ / __ \
  464. # / / / __/ / /|_/ / /_/ /
  465. # / / / /___/ / / / ____/
  466. # /_/ /_____/_/ /_/_/
  467. # \033[0m'
  468. # function check_tmp_secured {
  469. # temp1=`grep -w "/var/tempFS /tmp ext3 loop,nosuid,noexec,rw 0 0" /etc/fstab | wc -l`
  470. # temp2=`grep -w "tmpfs /tmp tmpfs rw,noexec,nosuid 0 0" /etc/fstab | wc -l`
  471. # if [ $temp1 -gt 0 ] || [ $temp2 -gt 0 ]; then
  472. # return 1
  473. # else
  474. # return 0
  475. # fi
  476. # } # End function check_tmp_secured
  477. # function secure_tmp_tmpfs {
  478. # cp /etc/fstab /etc/fstab.bak
  479. # # Backup /tmp
  480. # cp -Rpf /tmp /tmpbackup
  481. # rm -rf /tmp
  482. # mkdir /tmp
  483. # mount -t tmpfs -o rw,noexec,nosuid tmpfs /tmp
  484. # chmod 1777 /tmp
  485. # echo "tmpfs /tmp tmpfs rw,noexec,nosuid 0 0" >> /etc/fstab
  486. # # Restore /tmp
  487. # cp -Rpf /tmpbackup/* /tmp/ >/dev/null 2>&1
  488. # #Remove old tmp dir
  489. # rm -rf /tmpbackup
  490. # # Backup /var/tmp and link it to /tmp
  491. # mv /var/tmp /var/tmpbackup
  492. # ln -s /tmp /var/tmp
  493. # # Copy the old data back
  494. # cp -Rpf /var/tmpold/* /tmp/ >/dev/null 2>&1
  495. # # Remove old tmp dir
  496. # rm -rf /var/tmpbackup
  497. # echo -e "\033[35;1m /tmp and /var/tmp secured using tmpfs. \033[0m"
  498. # } # End function secure_tmp_tmpfs
  499. # check_tmp_secured
  500. # if [ $? = 0 ]; then
  501. # secure_tmp_tmpfs
  502. # else
  503. # echo -e "\033[35;1mFunction canceled. /tmp already secured. \033[0m"
  504. # fi
  505. echo '\033[35m
  506. ____ __ _______ __
  507. / __ \____ / /_ / ____(_) /__ _____
  508. / / / / __ \/ __/ / /_ / / / _ \/ ___/
  509. / /_/ / /_/ / /_ / __/ / / / __(__ )
  510. /_____/\____/\__/ /_/ /_/_/\___/____/
  511. \033[0m'
  512. #installing better prompt and some goodies for root
  513. echo "\033[35;1mInstalling shell prompt for root \033[0m"
  514. sleep 3
  515. echo "cloning github.com/bachy/dotfiles-server"
  516. git clone git://github.com/bachy/dotfiles-server.git ~/.dotfiles-server && cd ~/.dotfiles-server && ./install.sh && cd ~
  517. source ~/.bashrc
  518. echo "\033[92;1mDot files installed for root, you should installed them manually for $USER\033[0m"
  519. # TODO add warning message on ssh connection if system needs updates
  520. # TODO install and configure tmux
  521. echo '\033[35m
  522. ___ __ __ __ __ __
  523. / | __ __/ /_____ / / / /___ ____/ /___ _/ /____
  524. / /| |/ / / / __/ __ \ / / / / __ \/ __ / __ `/ __/ _ \
  525. / ___ / /_/ / /_/ /_/ / / /_/ / /_/ / /_/ / /_/ / /_/ __/
  526. /_/ |_\__,_/\__/\____/ \____/ .___/\__,_/\__,_/\__/\___/
  527. /_/
  528. \033[0m'
  529. # https://www.howtoforge.com/how-to-configure-automatic-updates-on-debian-wheezy
  530. # https://www.bisolweb.com/tutoriels/serveur-vps-ovh-partie-5-installation-apticron/
  531. echo "\033[35;1mInstalling apticron \033[0m"
  532. apt-get install apticron
  533. sleep 3
  534. echo -n "Enter an email: "
  535. read email
  536. sed -ir "s/EMAIL=\"root\"/EMAIL=\"$email\"/g" /etc/apticron/apticron.conf
  537. # sed -ir "s/# DIFF_ONLY=\"1\"/DIFF_ONLY=\"1\"/g" /etc/apticron/apticron.conf
  538. sed -ir "s/# NOTIFY_NEW=\"0\"/NOTIFY_NEW=\"0\"/g" /etc/apticron/apticron.conf
  539. echo "\033[92;1mApticron installed and configured\033[0m"
  540. echo '\033[35m
  541. __
  542. ___ ____ ____/ /
  543. / _ \/ __ \/ __ /
  544. / __/ / / / /_/ /
  545. \___/_/ /_/\__,_/
  546. \033[0m'
  547. echo "\033[35;1m* * script done * * \033[0m"