install-debian-server.sh 19 KB

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