You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
6.4 KiB

  1. #!/bin/bash
  2. # Allo-GG
  3. # Installation de Allo-GG sur un Pi Zero avec Rasbian.
  4. ################################################
  5. # MERCI DE MODIFIER LA CONFIGURATION SUIVANTE :#
  6. ################################################
  7. # NOM DU RESEAU WI-FI (SSID) #
  8. wifi_ssid='nom-du-reseau-wifi-SSID'
  9. # #
  10. # MOT DE PASSE DU RESEAU WI-FI
  11. wifi_psw='mdp-du-reseau-wifi'
  12. # #
  13. # MOT DE PASSE POUR L'ACCES ALLO-GG #
  14. allogg_psw='mdp-pour-acces-allogg'
  15. ################################################
  16. # Configuration du nom reseau du module
  17. echo "allo-gg" > /etc/hostname
  18. # Configuration du Wi-FI
  19. echo "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev" > /etc/wpa_supplicant/wpa_supplicant.conf
  20. echo "update_config=1" >> /etc/wpa_supplicant/wpa_supplicant.conf
  21. echo "country=FR" >> /etc/wpa_supplicant/wpa_supplicant.conf
  22. echo >> /etc/wpa_supplicant/wpa_supplicant.conf
  23. echo "network={" >> /etc/wpa_supplicant/wpa_supplicant.conf
  24. echo ' ssid="'$wifi_ssid'"' >> /etc/wpa_supplicant/wpa_supplicant.conf
  25. echo ' psk="'$wifi_psw'"' >> /etc/wpa_supplicant/wpa_supplicant.conf
  26. echo "}" >> /etc/wpa_supplicant/wpa_supplicant.conf
  27. sleep 2
  28. echo
  29. echo "Connexion en cours sur internet ..."
  30. ifdown --force wlan0
  31. sleep 2
  32. ifup wlan0
  33. sleep 2
  34. # tester 5 ping
  35. if ping -c5 1.1.1.1 | grep -q '0% packet loss'
  36. # Si la reponse est 0 paquets perdu, alors OK
  37. then
  38. echo "[✅ OK] Internet"
  39. # Mais sinon, il y a un probleme
  40. else
  41. # Tentative de relancer le wifi ...
  42. sleep 2
  43. echo
  44. echo "[❌ ERREUR] Probleme sur le Wifi ? Tentative de relancer la connexion en cours ..."
  45. ifdown --force wlan0
  46. sleep 2
  47. ifup wlan0
  48. sleep 2
  49. # ... puis refaire un test, en testant 10 ping cette fois
  50. if ping -c10 1.1.1.1 | grep -q '0% packet loss'
  51. # Si la reponse est 0 paquets perdu, alors finalement tout va bien
  52. then
  53. echo "[✅ OK] Internet"
  54. # Mais si le probleme est toujours present, alors on alerte :
  55. else
  56. echo "[❌ ERREUR] Internet"
  57. echo "Merci de verifier la configuration Wi-Fi dans le fichier /etc/wpa_supplicant/wpa_supplicant.conf"
  58. exit
  59. fi
  60. fi
  61. # Activation du SSH
  62. systemctl enable ssh
  63. systemctl start ssh
  64. # Installation des utilitaires
  65. cd || exit
  66. apt-get -y install apache2 php7.0 git-core vim tree rsync lsof curl screen
  67. # Installation de log2ram
  68. git clone https://git.heuzef.com/heuzef/log2ram.git
  69. cd log2ram || exit
  70. chmod +x install.sh
  71. ./install.sh
  72. cd || exit
  73. # Installation de wiringPi
  74. git clone https://git.heuzef.com/heuzef/WiringPi.git
  75. cd wiringPi || exit
  76. chmod +x build
  77. ./build
  78. cd || exit
  79. # Creation des utilisateurs
  80. useradd --create-home allo-gg
  81. adduser allo-gg sudo
  82. echo allo-gg:$allogg_psw | chpasswd
  83. echo root:$allogg_psw | chpasswd
  84. # Suppression de l'utilisateur "pi"
  85. deluser -f --remove-home pi
  86. # Execution automatique de bash a la connexion
  87. echo "bash" >> /home/allo-gg/.profile
  88. # Définition de la Timezone et activation de la synchro NTP
  89. timedatectl set-timezone Europe/Paris
  90. timedatectl set-ntp true
  91. sed -i '$ d' /etc/systemd/timesyncd.conf
  92. echo "FallbackNTP=0.arch.pool.ntp.org 1.arch.pool.ntp.org 2.arch.pool.ntp.org 3.arch.pool.ntp.org" >> /etc/systemd/timesyncd.conf
  93. # Autoriser le reboot du module
  94. echo >> /etc/sudoers
  95. echo "## user is allowed to execute halt and reboot" >> /etc/sudoers
  96. echo "allo-gg ALL=NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/poweroff" >> /etc/sudoers
  97. echo "www-data ALL=NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/poweroff" >> /etc/sudoers
  98. # Autorisation de clefs SSH publiques
  99. mkdir /home/allo-gg/.ssh/
  100. echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDhcGWA/uNEz7AFTfSZJBrxZjSB3KVHNNl0xnRfQWlEkJvqNeap64kv39DWajCKUsGpx2TDvJjQVoeMZFKFiA952S6+rkboO4piWOe7PswWwHAD/UrJYzTOEt+Dk8RnYH+FbMsj8gFrJZCJeOtjcflVIaaGAKX0gIDvf/1RAlBKM9KrsOLs/ELBzfGgIfa4ODF1qm3x6UnEu/X339Qk6A4OwzCkKtkzDIFjXt8BymO/iUiFe5DAaBk2IwOrnloQqHL6ROSDvtaHDsWkuLt8M6p1HB+7VdFMSgKfYXmiRxOyxnAYA4fcy8PLmyzStOkpAsy0BxoIeNsehTA4HtL14tgsJMWVhZ33guIP6F2d2cg9lzl0q2qSiKNc+XX+923LbWr6AlSaWyWQk0Z60jkAL1xyfJlUJ3r4kz+AYtp8AuV+9L7I8t8QWtDfjE8RNDwhjZNKyciDUHggbl+qIJ2e7del3izEtE9IBdIqWTKYTWk1canUCGYvGuZP+cacP8p6lFFSIVcoO6rvnbhBW8BcqkZl3rkhmGifYG40r+0a7wpZ/JJh/heQ2BRUI+xtmNBgJcF/6DhtqWdSZdRXAsBZPiX99EJR+RlFRi+l1MBnLb0fZafn6H3zKuOEv2NYlmBHccW5ZrFIWyQ4yUnKJ75i1wXtsoJ4BYlUhv7EaHPp4CvpYQ== Heuzef" >> /home/allo-gg/.ssh/authorized_keys
  101. echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDkdi/Nt+Remfwx5vM/lBmnTUOQ3+UJtbT4P1P+sOXt0dADUHj7gRvZxfb73n7A8y6rfocDiV4IRf1yvg8JWrAFC7/aDCMYDAOMAld9fKFU7u73beWl0zMSTVSGxt2MTSpyU+POx6VvucWppJQJN8R2VtAPHheUZlpLEf0n2gzgyYEYuHEOPHfx91u3omu4QCYRVWv4ZFRCCvznC2Cd+GW2S8uNqe6oxe2HuXtghAIRO+XXDSfwJc0lsm7uKMJ9rtQMYSYUI0f3HErHArf5ssQMCMcHivdJuoWEmvK2UarQdT5kKlytDUjFMrjj4Ks6+Ew6mdvp6H4/PeRjONaDWOQ3 karimcisse@Karims-MacBook-Air.local" >> /home/allo-gg/.ssh/authorized_keys
  102. # Desactiver toutes authentifications SSH par mot de passe
  103. echo "PasswordAuthentication no" >> /etc/ssh/sshd_config
  104. echo "PermitRootLogin no" >> /etc/ssh/sshd_config
  105. # Desactiver les services innutiles
  106. systemctl stop bluetooth
  107. systemctl disable bluetooth
  108. systemctl mask bluetooth.service
  109. # Installation de Allo-GG
  110. rm -vf /var/www/html/index.html
  111. chown -R allo-gg:allo-gg /var/www/html/
  112. su -l allo-gg -c "git clone https://git.heuzef.com/heuzef/Allo-GG.git /var/www/html/"
  113. mv -vf /var/www/html/log2ram.conf /etc/
  114. mv /etc/cron.hourly/log2ram /etc/cron.daily/log2ram
  115. # Definition du mot de passe
  116. sed -i "s/#allogg_psw#/$allogg_psw/g" /var/www/html/ui/index.php
  117. # Lancement automatique du script de demarrage
  118. cp -a /etc/rc.local /etc/rc.local.bak
  119. echo "#!/bin/sh -e" > /etc/rc.local
  120. echo "#" >> /etc/rc.local
  121. echo "# rc.local" >> /etc/rc.local
  122. echo "" >> /etc/rc.local
  123. echo "/bin/bash /var/www/html/scripts/boot.sh &" >> /etc/rc.local
  124. echo "" >> /etc/rc.local
  125. echo "exit 0" >> /etc/rc.local
  126. # Mise en place de la routine de verification de l'etat des services
  127. echo '*/20 * * * * /var/www/html/scripts/check_services.sh > /dev/null' | crontab -u allo-gg -
  128. # Creation du fichier de log
  129. date > /var/www/html/ui/allo-gg.log
  130. echo "Installation du module ALLO-GG" >> /var/www/html/ui/allo-gg.log
  131. echo "----------------------------" >> /var/www/html/ui/allo-gg.log
  132. echo >> /var/www/html/ui/allo-gg.log
  133. echo
  134. echo "----------------------------"
  135. echo "Installation OK ! Redemarrage dans 10 secondes ..."
  136. echo "L'interface web est maintenant accessible sur l'adresse IP du module :"
  137. echo "----------------------------"
  138. hostname -I
  139. echo "----------------------------"
  140. sleep 10
  141. sh /var/www/html/scripts/reboot.sh