install-debian-server.sh 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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 --yes --force-yes install vim curl
  42. sed -i "s/^# en_GB.UTF-8/en_GB.UTF-8/g" /etc/locale.gen
  43. locale-gen
  44. apt-get --yes --force-yes install ntp
  45. dpkg-reconfigure tzdata
  46. echo '\033[35m
  47. ______________ _______ _____ __ __
  48. / ____/ _/ __ \/ ____/ | / / | / / / /
  49. / /_ / // /_/ / __/ | | /| / / /| | / / / /
  50. / __/ _/ // _, _/ /___ | |/ |/ / ___ |/ /___/ /___
  51. /_/ /___/_/ |_/_____/ |__/|__/_/ |_/_____/_____/
  52. \033[0m'
  53. echo "\033[35;1mInstalling ufw and setup firewall (allowing only ssh and http) \033[0m"
  54. sleep 3
  55. apt-get --yes --force-yes install ufw
  56. # ufw allow ssh # knockd will open the ssh port
  57. ufw allow http
  58. ufw allow https
  59. ufw enable
  60. ufw status verbose
  61. echo "\033[92;1mufw installed and firwall configured\033[Om"
  62. echo '\033[35m
  63. ______ _ _____ __
  64. / ____/___ _(_) /__ \ / /_ ____ _____
  65. / /_ / __ `/ / /__/ // __ \/ __ `/ __ \
  66. / __/ / /_/ / / // __// /_/ / /_/ / / / /
  67. /_/ \__,_/_/_//____/_.___/\__,_/_/ /_/
  68. \033[0m'
  69. echo "\033[35;1mInstalling fall2ban \033[0m"
  70. apt-get --yes --force-yes install fail2ban
  71. cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
  72. # ToDo ask for email and configure jail.local with it
  73. systemctl enable fail2ban
  74. systemctl restart fail2ban
  75. echo "\033[92;1mfail2ban installed and configured\033[Om"
  76. echo '\033[35m
  77. __ __ __
  78. / /______ ____ _____/ /______/ /
  79. / //_/ __ \/ __ \/ ___/ //_/ __ /
  80. / ,< / / / / /_/ / /__/ ,< / /_/ /
  81. /_/|_/_/ /_/\____/\___/_/|_|\__,_/
  82. \033[0m'
  83. echo "\033[35;1mInstalling knockd to control ssh port opening\033[0m"
  84. sleep 3
  85. apt-get --yes --force-yes install knockd
  86. mv /etc/knockd.conf /etc/knockd.conf.ori
  87. cp "$_cwd"/assets/knockd.conf /etc/knockd.conf
  88. echo -n "define a sequence number for opening ssh (as 7000,8000,9000) : "
  89. read sq
  90. sed -i "s/7000,8000,9000/$sq/g" /etc/knockd.conf
  91. sed -i 's/START_KNOCKD=0/START_KNOCKD=1/g' /etc/default/knockd
  92. /etc/init.d/knockd start
  93. echo "\033[92;1mknockd installed and configured\033[Om"
  94. echo "\033[92;1mplease note this sequence for future ssh knocking\033[Om"
  95. echo "$sq1"
  96. sleep 3
  97. echo '\033[35m
  98. __ _______ __________
  99. / / / / ___// ____/ __ \
  100. / / / /\__ \/ __/ / /_/ /
  101. / /_/ /___/ / /___/ _, _/
  102. \____//____/_____/_/ |_|
  103. \033[0m'
  104. echo "\033[35;1mCreate new user (you will be asked a user name and a password) \033[0m"
  105. sleep 3
  106. echo -n "Enter user name: "
  107. read user
  108. # read -p "Continue? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
  109. adduser "$user"
  110. echo "adding $user to admin group and limiting su to the admin group"
  111. groupadd admin
  112. usermod -a -G admin "$user"
  113. # allow admin group to su
  114. dpkg-statoverride --update --add root admin 4750 /bin/su
  115. echo "\033[92;1muser $user configured\033[Om"
  116. echo '\033[35m
  117. __ ______ ______
  118. / |/ / | / _/ /
  119. / /|_/ / /| | / // /
  120. / / / / ___ |_/ // /___
  121. /_/ /_/_/ |_/___/_____/
  122. \033[0m'
  123. echo "\033[35;1mEnable mail sending for php \033[0m"
  124. # http://www.sycha.com/lamp-setup-debian-linux-apache-mysql-php#anchor13
  125. sleep 3
  126. apt-get --yes --force-yes install exim4
  127. echo "\033[35;1mConfiguring EXIM4 \033[0m"
  128. while [ "$configexim" != "y" ] && [ "$configexim" != "n" ]
  129. do
  130. echo -n "Should we configure exim4 ? [y|n] "
  131. read configexim
  132. done
  133. if [ "$configexim" = "y" ]; then
  134. 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"
  135. echo "press any key to continue."
  136. read continu
  137. dpkg-reconfigure exim4-config
  138. else
  139. echo 'exim not configured'
  140. fi
  141. systemctl enable exim4
  142. systemctl restart exim4
  143. # dkim spf
  144. # https://debian-administration.org/article/718/DKIM-signing_outgoing_mail_with_exim4
  145. echo "\033[35;1mConfiguring DKIM \033[0m"
  146. while [ "$installdkim" != "y" ] && [ "$installdkim" != "n" ]
  147. do
  148. echo -n "Should we install dkim for exim4 ? [y|n] "
  149. read installdkim
  150. done
  151. if [ "$installdkim" = "y" ]; then
  152. echo -n "Choose a domain for dkim (same domain as you chose before for exim4): "
  153. read domain
  154. selector=$(date +%Y%m%d)
  155. mkdir /etc/exim4/dkim
  156. openssl genrsa -out /etc/exim4/dkim/"$domain"-private.pem 1024 -outform PEM
  157. openssl rsa -in /etc/exim4/dkim/"$domain"-private.pem -out /etc/exim4/dkim/"$domain".pem -pubout -outform PEM
  158. chown root:Debian-exim /etc/exim4/dkim/"$domain"-private.pem
  159. chmod 440 /etc/exim4/dkim/"$domain"-private.pem
  160. cp "$_cwd"/assets/exima4_dkim.conf /etc/exim4/conf.d/main/00_local_macros
  161. sed -ir "s/DOMAIN_TO_CHANGE/$domain/g" /etc/exim4/conf.d/main/00_local_macros
  162. sed -ir "s/DATE_TO_CHANGE/$selector/g" /etc/exim4/conf.d/main/00_local_macros
  163. update-exim4.conf
  164. systemctl restart exim4
  165. echo "please create a TXT entry in your dns zone : $selector._domainkey.$domain \n"
  166. echo "your public key is : \n"
  167. cat /etc/exim4/dkim/"$domain".pem
  168. echo "press any key to continue."
  169. read continu
  170. else
  171. echo 'dkim not installed'
  172. fi
  173. echo '\033[35m
  174. __________ __ __
  175. / ___/ ___// / / /
  176. \__ \\__ \/ /_/ /
  177. ___/ /__/ / __ /
  178. /____/____/_/ /_/
  179. \033[0m'
  180. while [ "$securssh" != "y" ] && [ "$securssh" != "n" ]
  181. do
  182. echo -n "Securing ssh (disabling root login)? [y|n] "
  183. read securssh
  184. # securssh=${securssh:-y}
  185. done
  186. if [ "$securssh" = "y" ]; then
  187. sed -i 's/PermitRootLogin\ yes/PermitRootLogin no/g' /etc/ssh/sshd_config
  188. sed -i 's/PermitEmptyPasswords\ yes/PermitEmptyPasswords no/g' /etc/ssh/sshd_config
  189. sed -i 's/Protocol\ [0-9]/Protocol 2/g' /etc/ssh/sshd_config
  190. systemctl reload ssh
  191. echo "\033[92;1mSSH secured\033[Om"
  192. else
  193. echo 'root user can still conect through ssh'
  194. fi
  195. echo '\033[35m
  196. ______ _______ _____
  197. | ____|__ __| __ \
  198. | |__ | | | |__) |
  199. | __| | | | ___/
  200. | | | | | |
  201. |_| |_| |_|
  202. \033[0m'
  203. echo -n "Should we install ftp server? [Y|n] "
  204. read yn
  205. yn=${yn:-y}
  206. if [ "$yn" = "y" ]; then
  207. echo "installing proftpd"
  208. apt-get --yes --force-yes install proftpd
  209. while [ "$_server_name" = "" ]
  210. do
  211. read -p "enter a server name ? " _server_name
  212. if [ "$_server_name" != "" ]; then
  213. read -p "is server name $_server_name correcte [y|n] " validated
  214. if [ "$validated" = "y" ]; then
  215. break
  216. else
  217. _server_name=""
  218. fi
  219. fi
  220. done
  221. echo "Configuring proftpd"
  222. cp "$_cwd"/assets/proftpd.conf /etc/proftpd/conf.d/"$_server_name".conf
  223. sed -ir "s/example/$_server_name/g" /etc/proftpd/conf.d/"$_server_name".conf
  224. ufw allow ftp
  225. addgroup ftpuser
  226. systemctl enable proftpd
  227. systemctl restart proftpd
  228. echo "ftp installtion done"
  229. echo "to permit to a user to connect through ftp, add him to the ftpuser group by running : usermod -a -G ftpuser USERNAME"
  230. echo "FTP users are jailed on their home by default"
  231. fi
  232. # TODO : allow ssh/ftp connection only from given ips
  233. echo '\033[35m
  234. __
  235. / /__ ____ ___ ____
  236. / / _ \/ __ `__ \/ __ \
  237. / / __/ / / / / / /_/ /
  238. /_/\___/_/ /_/ /_/ .___/
  239. /_/
  240. \033[0m'
  241. echo "\033[35;1mLEMP server (Nginx Mysql Php) \033[0m"
  242. sleep 3
  243. while [ "$lemp" != "y" ] && [ "$lemp" != "n" ]
  244. do
  245. echo -n "Should we install lemp ? [y|n] "
  246. read lemp
  247. done
  248. if [ "$lemp" = "y" ]; then
  249. echo '\033[35m
  250. __ ___ __
  251. / |/ /_ ___________ _/ /
  252. / /|_/ / / / / ___/ __ `/ /
  253. / / / / /_/ (__ ) /_/ / /
  254. /_/ /_/\__, /____/\__, /_/
  255. /____/ /_/
  256. \033[0m'
  257. echo "\033[35;1minstalling Mysql \033[0m"
  258. sleep 3
  259. apt-get --yes --force-yes install mariadb-server
  260. mysql_secure_installation
  261. systemctl enable mariadb.service
  262. systemctl restart mariadb.service
  263. echo "\033[92;1mmysql installed\033[Om"
  264. echo '\033[35m
  265. ____ __ ______
  266. / __ \/ / / / __ \
  267. / /_/ / /_/ / /_/ /
  268. / ____/ __ / ____/
  269. /_/ /_/ /_/_/
  270. \033[0m'
  271. echo "\033[35;1mInstalling PHP 7.0 \033[0m"
  272. sleep 3
  273. apt-get --yes --force-yes install php7.0-fpm php7.0-mysql php7.0-opcache php7.0-curl php7.0-mbstring php7.0-zip php7.0-xml php7.0-gd php7.0-mcrypt php-memcached
  274. mv /etc/php/7.0/fpm/php.ini /etc/php/7.0/fpm/php.ini.back
  275. cp "$_cwd"/assets/php-fpm.ini /etc/php/7.0/fpm/php.ini
  276. echo "Configuring PHP"
  277. mkdir /var/log/php
  278. chown www-data /var/log/php
  279. cp "$_cwd"/assets/logrotate-php /etc/logrotate.d/php
  280. systemctl enable php7.0-fpm
  281. systemctl start php7.0-fpm
  282. # echo "Installing memecached"
  283. # replaced by redis
  284. # apt-get --yes --force-yes install memcached
  285. # sed -i "s/-m\s64/-m 128/g" /etc/memcached.conf
  286. #
  287. # systemctl start memcached
  288. echo "\033[92;1mphp installed\033[Om"
  289. echo '\033[35m
  290. _ __ _
  291. / | / /___ _(_)___ _ __
  292. / |/ / __ `/ / __ \| |/_/
  293. / /| / /_/ / / / / /> <
  294. /_/ |_/\__, /_/_/ /_/_/|_|
  295. /____/
  296. \033[0m'
  297. echo "\033[35;1mInstalling Nginx \033[0m"
  298. sleep 3
  299. apt-get --yes --force-yes install nginx
  300. mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.ori
  301. cp "$_cwd"/assets/default.nginxconf /etc/nginx/sites-available/default
  302. systemctl enable nginx
  303. systemctl restart nginx
  304. echo "\033[92;1mNginx installed\033[Om"
  305. echo '\033[35m
  306. __ __ ___ ___ __ _
  307. ____ / /_ ____ / |/ /_ __/ | ____/ /___ ___ (_)___
  308. / __ \/ __ \/ __ \/ /|_/ / / / / /| |/ __ / __ `__ \/ / __ \
  309. / /_/ / / / / /_/ / / / / /_/ / ___ / /_/ / / / / / / / / / /
  310. / .___/_/ /_/ .___/_/ /_/\__, /_/ |_\__,_/_/ /_/ /_/_/_/ /_/
  311. /_/ /_/ /____/
  312. \033[0m'
  313. echo "\033[35;1mInstalling phpMyAdmin \033[0m"
  314. apt-get --yes --force-yes install phpmyadmin
  315. ln -s /usr/share/phpmyadmin /var/www/html/
  316. # cp "$_cwd"/assets/nginx-phpmyadmin.conf > /etc/nginx/sites-available/phpmyadmin.conf
  317. # ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/phpmyadmin.conf
  318. # echo "\033[35;1msecuring phpMyAdmin \033[0m"
  319. # sed -i "s/DirectoryIndex index.php/DirectoryIndex index.php\nAllowOverride all/"
  320. # cp "$_cwd"/assets/phpmyadmin_htaccess > /usr/share/phpmyadmin/.htaccess
  321. # echo -n "define a user name for phpmyadmin : "
  322. # read un
  323. # htpasswd -c /etc/phpmyadmin/.htpasswd $un
  324. # service apache2 restart
  325. echo "\033[92;1mphpMyAdmin installed\033[Om"
  326. echo "\033[92;1mYou can access it at yourip/phpmyadmin\033[Om"
  327. echo '\033[35m
  328. ____ ___
  329. / __ \___ ____/ (_)____
  330. / /_/ / _ \/ __ / / ___/
  331. / _, _/ __/ /_/ / (__ )
  332. /_/ |_|\___/\__,_/_/____/
  333. \033[0m'
  334. echo "\033[35;1mInstalling Redis \033[0m"
  335. sleep 3
  336. apt-get --yes --force-yes install redis-server php-redis
  337. systemctl enable redis-server
  338. systemctl restart redis-server
  339. echo "\033[92;1mRedis installed\033[Om"
  340. echo '\033[35m
  341. ______
  342. / ____/___ ____ ___ ____ ____ ________ _____
  343. / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
  344. / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
  345. \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
  346. /_/
  347. \033[0m'
  348. echo "\033[35;1mInstalling Composer \033[0m"
  349. sleep 3
  350. export COMPOSER_HOME=/usr/local/composer
  351. curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  352. echo "\033[92;1mComposer installed\033[Om"
  353. echo '\033[35m
  354. ____ __
  355. / __ \_______ _______/ /_
  356. / / / / ___/ / / / ___/ __ \
  357. / /_/ / / / /_/ (__ ) / / /
  358. /_____/_/ \__,_/____/_/ /_/
  359. \033[0m'
  360. echo "\033[35;1mInstalling Drush and DrupalConsole\033[0m"
  361. sleep 3
  362. curl https://drupalconsole.com/installer -L -o /usr/local/bin/drupal
  363. chmod +x /usr/local/bin/drupal
  364. curl https://github.com/drush-ops/drush-launcher/releases/download/0.6.0/drush.phar -L -o /usr/local/bin/drush
  365. chmod +x /usr/local/bin/drush
  366. echo "\033[92;1mDrush and DrupalConsoleinstalled\033[Om"
  367. echo '\033[35m
  368. __ __
  369. _ __/ /_ ____ _____/ /_
  370. | | / / __ \/ __ \/ ___/ __/
  371. | |/ / / / / /_/ (__ ) /_
  372. |___/_/ /_/\____/____/\__/
  373. \033[0m'
  374. echo "\033[35;1mVHOST install \033[0m"
  375. while [ "$vh" != "y" ] && [ "$vh" != "n" ]
  376. do
  377. echo -n "Should we install a vhost? [y|n] "
  378. read vh
  379. # vh=${vh:-y}
  380. done
  381. if [ "$vh" = "y" ]; then
  382. while [ "$_domain" = "" ]
  383. do
  384. read -p "enter a hostname ? " _domain
  385. if [ "$_domain" != "" ]; then
  386. read -p "is hostname $_domain correcte [y|n] " validated
  387. if [ "$validated" = "y" ]; then
  388. break
  389. else
  390. _domain=""
  391. fi
  392. fi
  393. done
  394. # ask for simple php conf or drupal conf
  395. while [ "$_drupal" != "yes" ] && [ "$_drupal" != "no" ]
  396. do
  397. echo -n "Is your site is a drupal one? [yes|no] "
  398. read _drupal
  399. done
  400. # ask for let's encrypt
  401. while [ "$_letsencrypt" != "yes" ] && [ "$_letsencrypt" != "no" ]
  402. do
  403. echo "Let's encrypt"
  404. echo "Let's encrypt needs a public registered domain name with proper DNS records ( A records or CNAME records for subdomains pointing to your server)."
  405. echo -n "Should we install let's encrypt certificate with $_domain? [yes|no] "
  406. read _letsencrypt
  407. done
  408. # lets'encrypt
  409. # https://certbot.eff.org/lets-encrypt/debianstretch-nginx
  410. if [ "$_letsencrypt" = "yes" ]; then
  411. apt-get install certbot
  412. certbot certonly --cert-name "$_domain" --standalone –d "$_domain"
  413. openssl dhparam –out /etc/nginx/dhparam.pem 2048
  414. # TODO renewing
  415. touch /var/spool/crontab/root
  416. crontab -l > mycron
  417. echo "0 3 * * * certbot renew --pre-hook 'systemctl stop nginx' --post-hook 'systemctl start nginx' --cert-name $_domain" >> mycron
  418. crontab mycron
  419. rm mycron
  420. fi
  421. if [ "$_drupal" = "yes" ]; then
  422. if [ "$_letsencrypt" = "yes" ]; then
  423. _conffile = "drupal-ssl.nginxconf"
  424. else
  425. _conffile = "drupal.nginxconf"
  426. fi
  427. else
  428. if [ "$_letsencrypt" = "yes" ]; then
  429. _conffile = "simple-phpfpm-ssl.nginxconf"
  430. else
  431. _conffile = "simple-phpfpm.nginxconf"
  432. fi
  433. fi
  434. cp "$_cwd"/assets/"$_conffile" /etc/nginx/sites-available/"$_domain".conf
  435. sed -ir "s/DOMAIN\.LTD/$_domain/g" /etc/nginx/sites-available/"$_domain".conf
  436. mkdir -p /var/www/"$_domain"/public_html
  437. mkdir /var/www/"$_domain"/logs
  438. #set proper right to user will handle the app
  439. chown -R root:admin /var/www/"$_domain"/
  440. chmod -R g+w /var/www/"$_domain"/
  441. chmod -R g+r /var/www/"$_domain"/
  442. # create a shortcut to the site
  443. mkdir /home/"$user"/www/
  444. chown "$user":admin /home/"$user"/www/
  445. ln -s /var/www/"$_domain" /home/"$user"/www/"$_domain"
  446. # activate the vhost
  447. ln -s /etc/nginx/sites-available/"$_domain".conf /etc/nginx/sites-enabled/"$_domain".conf
  448. # restart nginx
  449. systemctl restart nginx
  450. echo "\033[92;1mvhost $_domain configured\033[Om"
  451. else
  452. echo "Vhost installation aborted"
  453. fi
  454. # TODO supervising
  455. # echo '\033[35m
  456. # __ ___ _ __ __ __ ___ _
  457. # / |/ /__ ___ (_) /_ _/_/ / |/ /_ _____ (_)__
  458. # / /|_/ / _ \/ _ \/ / __/ _/_/ / /|_/ / // / _ \/ / _ \
  459. # /_/ /_/\___/_//_/_/\__/ /_/ /_/ /_/\_,_/_//_/_/_//_/
  460. # \033[0m'
  461. # echo "\033[35;1mInstalling Munin \033[0m"
  462. # sleep 3
  463. # # https://www.howtoforge.com/tutorial/server-monitoring-with-munin-and-monit-on-debian/
  464. # apt-get --yes --force-yes install munin munin-node munin-plugins-extra
  465. # # Configure Munin
  466. # # enable plugins
  467. # ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_
  468. # ln -s /usr/share/munin/plugins/mysql_bytes /etc/munin/plugins/mysql_bytes
  469. # ln -s /usr/share/munin/plugins/mysql_innodb /etc/munin/plugins/mysql_innodb
  470. # ln -s /usr/share/munin/plugins/mysql_isam_space_ /etc/munin/plugins/mysql_isam_space_
  471. # ln -s /usr/share/munin/plugins/mysql_queries /etc/munin/plugins/mysql_queries
  472. # ln -s /usr/share/munin/plugins/mysql_slowqueries /etc/munin/plugins/mysql_slowqueries
  473. # ln -s /usr/share/munin/plugins/mysql_threads /etc/munin/plugins/mysql_threads
  474. #
  475. # ln -s /usr/share/munin/plugins/apache_accesses /etc/munin/plugins/
  476. # ln -s /usr/share/munin/plugins/apache_processes /etc/munin/plugins/
  477. # ln -s /usr/share/munin/plugins/apache_volume /etc/munin/plugins/
  478. #
  479. # # ln -s /usr/share/munin/plugins/fail2ban /etc/munin/plugins/
  480. #
  481. # # dbdir, htmldir, logdir, rundir, and tmpldir
  482. # sed -i 's/^#dbdir/dbdir/' /etc/munin/munin.conf
  483. # sed -i 's/^#htmldir/htmldir/' /etc/munin/munin.conf
  484. # sed -i 's/^#logdir/logdir/' /etc/munin/munin.conf
  485. # sed -i 's/^#rundir/rundir/' /etc/munin/munin.conf
  486. # sed -i 's/^#tmpldir/tmpldir/' /etc/munin/munin.conf
  487. #
  488. # sed -i "s/^\[localhost.localdomain\]/[${HOSTNAME}]/" /etc/munin/munin.conf
  489. #
  490. # # ln -s /etc/munin/apache24.conf /etc/apache2/conf-enabled/munin.conf
  491. # sed -i 's/Require local/Require all granted\nOptions FollowSymLinks SymLinksIfOwnerMatch/g' /etc/munin/apache24.conf
  492. # htpasswd -c /etc/munin/munin-htpasswd admin
  493. # sed -i 's/Require all granted/AuthUserFile \/etc\/munin\/munin-htpasswd\nAuthName "Munin"\nAuthType Basic\nRequire valid-user/g' /etc/munin/apache24.conf
  494. #
  495. #
  496. # service apache2 restart
  497. # service munin-node restart
  498. # echo "\033[92;1mMunin installed\033[Om"
  499. #
  500. # echo "\033[35;1mInstalling Monit \033[0m"
  501. # sleep 3
  502. # # https://www.howtoforge.com/tutorial/server-monitoring-with-munin-and-monit-on-debian/2/
  503. # apt-get --yes --force-yes install monit
  504. # # TODO setup monit rc
  505. # cat "$_cwd"/assets/monitrc > /etc/monit/monitrc
  506. #
  507. # # TODO setup webaccess
  508. # passok=0
  509. # while [ "$passok" = "0" ]
  510. # do
  511. # echo -n "Write web access password to monit"
  512. # read passwda
  513. # echo -n "ReWrite web access password to monit"
  514. # read passwdb
  515. # if [ "$passwda" = "$passwdb" ]; then
  516. # sed -i 's/PASSWD_TO_REPLACE/$passwda/g' /etc/monit/monitrc
  517. # passok=1
  518. # else
  519. # echo "pass words don't match, please try again"
  520. # fi
  521. # done
  522. #
  523. # # TODO setup mail settings
  524. # sed -i "s/server1\.example\.com/$HOSTNAME/g" /etc/monit/monitrc
  525. #
  526. # mkdir /var/www/html/monit
  527. # echo "hello" > /var/www/html/monit/token
  528. #
  529. # service monit start
  530. #
  531. # echo "\033[92;1mMonit installed\033[Om"
  532. # echo '\033[35m
  533. # ___ __ __
  534. # / |_ _______/ /_____ _/ /_
  535. # / /| | | /| / / ___/ __/ __ `/ __/
  536. # / ___ | |/ |/ (__ ) /_/ /_/ / /_
  537. # /_/ |_|__/|__/____/\__/\__,_/\__/
  538. # \033[0m'
  539. # echo "\033[35;1mInstalling Awstat \033[0m"
  540. # sleep 3
  541. # apt-get --yes --force-yes install awstats
  542. # # Configure AWStats
  543. # temp=`grep -i sitedomain /etc/awstats/awstats.conf.local | wc -l`
  544. # if [ $temp -lt 1 ]; then
  545. # echo SiteDomain="$_domain" >> /etc/awstats/awstats.conf.local
  546. # fi
  547. # # Disable Awstats from executing every 10 minutes. Put a hash in front of any line.
  548. # sed -i 's/^[^#]/#&/' /etc/cron.d/awstats
  549. # echo "\033[92;1mAwstat installed\033[Om"
  550. else
  551. echo 'lemp server not installed'
  552. fi
  553. # echo '\033[35m
  554. # ______________ _______
  555. # /_ __/ ____/ |/ / __ \
  556. # / / / __/ / /|_/ / /_/ /
  557. # / / / /___/ / / / ____/
  558. # /_/ /_____/_/ /_/_/
  559. # \033[0m'
  560. # function check_tmp_secured {
  561. # temp1=`grep -w "/var/tempFS /tmp ext3 loop,nosuid,noexec,rw 0 0" /etc/fstab | wc -l`
  562. # temp2=`grep -w "tmpfs /tmp tmpfs rw,noexec,nosuid 0 0" /etc/fstab | wc -l`
  563. # if [ $temp1 -gt 0 ] || [ $temp2 -gt 0 ]; then
  564. # return 1
  565. # else
  566. # return 0
  567. # fi
  568. # } # End function check_tmp_secured
  569. # function secure_tmp_tmpfs {
  570. # cp /etc/fstab /etc/fstab.bak
  571. # # Backup /tmp
  572. # cp -Rpf /tmp /tmpbackup
  573. # rm -rf /tmp
  574. # mkdir /tmp
  575. # mount -t tmpfs -o rw,noexec,nosuid tmpfs /tmp
  576. # chmod 1777 /tmp
  577. # echo "tmpfs /tmp tmpfs rw,noexec,nosuid 0 0" >> /etc/fstab
  578. # # Restore /tmp
  579. # cp -Rpf /tmpbackup/* /tmp/ >/dev/null 2>&1
  580. # #Remove old tmp dir
  581. # rm -rf /tmpbackup
  582. # # Backup /var/tmp and link it to /tmp
  583. # mv /var/tmp /var/tmpbackup
  584. # ln -s /tmp /var/tmp
  585. # # Copy the old data back
  586. # cp -Rpf /var/tmpold/* /tmp/ >/dev/null 2>&1
  587. # # Remove old tmp dir
  588. # rm -rf /var/tmpbackup
  589. # echo -e "\033[35;1m /tmp and /var/tmp secured using tmpfs. \033[0m"
  590. # } # End function secure_tmp_tmpfs
  591. # check_tmp_secured
  592. # if [ $? = 0 ]; then
  593. # secure_tmp_tmpfs
  594. # else
  595. # echo -e "\033[35;1mFunction canceled. /tmp already secured. \033[0m"
  596. # fi
  597. echo '\033[35m
  598. ____ __ _______ __
  599. / __ \____ / /_ / ____(_) /__ _____
  600. / / / / __ \/ __/ / /_ / / / _ \/ ___/
  601. / /_/ / /_/ / /_ / __/ / / / __(__ )
  602. /_____/\____/\__/ /_/ /_/_/\___/____/
  603. \033[0m'
  604. #installing better prompt and some goodies for root
  605. echo "\033[35;1mInstalling shell prompt for root \033[0m"
  606. sleep 3
  607. echo "cloning github.com/bachy/dotfiles-server"
  608. git clone git://github.com/bachy/dotfiles-server.git ~/.dotfiles-server && cd ~/.dotfiles-server && ./install.sh && cd ~
  609. source ~/.bashrc
  610. echo "\033[92;1mDot files installed for root, you should installed them manually for $USER\033[0m"
  611. # TODO add warning message on ssh connection if system needs updates
  612. # TODO install and configure tmux
  613. echo '\033[35m
  614. ___ __ __ __ __ __
  615. / | __ __/ /_____ / / / /___ ____/ /___ _/ /____
  616. / /| |/ / / / __/ __ \ / / / / __ \/ __ / __ `/ __/ _ \
  617. / ___ / /_/ / /_/ /_/ / / /_/ / /_/ / /_/ / /_/ / /_/ __/
  618. /_/ |_\__,_/\__/\____/ \____/ .___/\__,_/\__,_/\__/\___/
  619. /_/
  620. \033[0m'
  621. # https://www.howtoforge.com/how-to-configure-automatic-updates-on-debian-wheezy
  622. # https://www.bisolweb.com/tutoriels/serveur-vps-ovh-partie-5-installation-apticron/
  623. echo "\033[35;1mInstalling apticron \033[0m"
  624. apt-get --yes --force-yes install apticron
  625. sleep 3
  626. echo -n "Enter an email: "
  627. read email
  628. sed -ir "s/EMAIL=\"root\"/EMAIL=\"$email\"/g" /etc/apticron/apticron.conf
  629. # sed -ir "s/# DIFF_ONLY=\"1\"/DIFF_ONLY=\"1\"/g" /etc/apticron/apticron.conf
  630. sed -ir "s/# NOTIFY_NEW=\"0\"/NOTIFY_NEW=\"0\"/g" /etc/apticron/apticron.conf
  631. echo "\033[92;1mApticron installed and configured\033[0m"
  632. echo '\033[35m
  633. __
  634. ___ ____ ____/ /
  635. / _ \/ __ \/ __ /
  636. / __/ / / / /_/ /
  637. \___/_/ /_/\__,_/
  638. \033[0m'
  639. echo "\033[35;1m* * script done * * \033[0m"