diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..723172122e8c5c96d1db9f663ddde411b324a43e --- /dev/null +++ b/README.md @@ -0,0 +1,61 @@ +# NoCloud Auto Installer + +NoCloud-Auto-Installer is designed to automatically install all applications for the [NoCloud solution](https://gitlab.tetras-libre.fr/nocloud). + +NoCloud-Auto-Installer is modular, it allows you to have a dockerized or non-dockerized installation and to deploy the desired services. + +## Environnement + +All configuration is on .env.main.sample. By default, this environnement is configure to feat with Tétras-libre's needs + +## Install + +1. intall `apt-get install vim git tmux` +2. `tmux new -s installation` +3. `cd /opt; git clone https://gitlab.tetras-libre.fr/nocloud/NoCloud-Auto-Installer; ln -s /opt/NoCloud-Auto-Installer /root` +4. `cd NoCloud-Auto-Installer` +5. `cp main.env.sample main.env` +6. Edit the 'main.env' file to put the right modules and domains do not touch the 'MAINTENANCE_LEVEL' **if you dont do that, Tetras Libre get access to your server** +7. `bash run.sh` +8. Test the connection with the ssh key (in case of hosting by OVH, remove the waring in '.ssh/authorized_keys') +9. **Delete temporary user as needed** `deluser [user] && rm -r /home/[user]` +10. `. main.env; bash validate.sh` +11. Put your ssh key in `/root/.ssh/authorized_keys` if needed + +If dockerweb doesn't have the right uid, you can chaange it **only if it's not already in use** thanks to: +```sh +groupmod -g 1000 dockerweb +usermod -u 1000 -g 1000 dockerweb +id dockerweb +``` + +At this point, you have a NoCloud server ready with the intended modules not configured and no DNS + +11. Set up your DNS through your provider +12. `apt dist-upgrade` +13. Reboot +14. `/opt/NoCloud-Auto-Installer/validate.sh` +15. Reverse DNS configuration (in the OVH order or at the ISP depending on the order) +16. Sending a test email `echo -e "Subject: test\n\nThis is a test" | sendmail -t root` and check its receipt + +Well done. + +## Backup + +Tu backup your services data you can use [duplicity-ftp-backup](https://gitlab.tetras-libre.fr/nocloud/duplicity-ftp-backup). All needed informaiton in readme of repository. + +## Upgrade + +1. `sudo tmux` +2. `cd /root/NoCloud-Auto-Installer; git pull; bash upgrade/All.sh` +3. Let it unfold and answer the question individually +4. À la fin vérifier sur chaque serveur en commencant + 1. That Rkhunter only displays green messages (if necessary, look in `/var/log/rkhunter.log`) + 2. Clamav detects nothing but fishing for people with their email on nextcloud + 3. The host names displayed for each client are accessible (`liste-domain.txt | xargs firefox`) + 4. Stop the maintenance service `cd /home/dockerweb/maintenance; docker-compose down` +5. Troubleshoot any issues + +## Licence + +This program is distributed under GPLV3 Licence, see `Licence.txt` diff --git a/Readme.md b/Readme.md deleted file mode 100644 index ac4953f63f1585169bb3d0f1371cfa9979f9ddc6..0000000000000000000000000000000000000000 --- a/Readme.md +++ /dev/null @@ -1,124 +0,0 @@ -# NoCloud Auto Installer - -NoCloud-Auto-Installer est conçu pour installer automatiquement l'ensemble des -applications pour la solution NoCloud. - -Deux types d'installations sont possibles : - -* Full installation : permet d'installer la totalité des packages pour la - Solution NoCloud. - * Installe les paquets pour Apache2, Certbot, Php - * Installe et configure MySql - * Installation automatisé de Nextcloud : - * Création de la database Nextcloud. - * Création de l'utilisateur Nextcloud. - * Création de l'utilisateur Admin pour Nextcloud - * Ajoute un fichier de préconfiguration pour l'accès à Nexcloud dans - apache. - * Installation automatisé de Dolibarr à partir du fichier d'installation de - debian. - * Installation automatisé de TetrasBack à partir du dépot TetrasBack de Tétras-Libre -* Installation sélective : permet d'installer l'outil voulu. - -## Pré-requis - -NoCloud-Auto-Installer a été testé sur Debian Jessie. -Pas de pré-requis nécessaires. - -## Installation - -### Full script - -L'installation totale du système se fait en trois temps : - -1. Configuration des variables d'environnement pour chaque logiciel à - installer.<br/> -A chaque fichier SH correspond un fichier ENV qui contient l'ensemble des -variables que l'installeur peut personnaliser.<br/> -Pour chaque variable existantes il existe une valeur par défaut. Donc si un -oubli est fait la valeur par défaut est utilisée. -2. Exécution automatisé des outils via ``sh run.sh`` -3. Actions Post installation. - 1. DNS + réseau - 2. Finalisation Dolibarr - 3. Ajout les certificats SSL - 4. Extractions MDP vers keepass - -### Selective script - -L'installation d'un script spécifique se fait aussi en trois étapes. - -1. Configuration du ENV du script à faire tourner -2. Exécution de la commande avec le script voulu : - * Mysql : ``sh initInstall.sh && sh installMySQL.sh`` - * Nextcloud : - ``sh initInstall.sh && sh installMySQL.sh && sh installNextcloud.sh`` - * Dolibarr : - ``sh initInstall.sh && sh installMySQL.sh && sh installDolibarr.sh`` - * TetrasBack : ``sh initInstall.sh && sh installTetrasBack.sh`` -3. Faire la post installationd du script - -### Actions post installation - -#### MySql - -* Vérifier le fichier /root/.my.cnf -* Le sauvegarder dans un lieu sûr. (Attention TetraBack a besoin de ce fichier - pour fonctionner correctement) - -#### Nextcloud - -* Activer l'accès à Nextcloud sur via apache2 - -#### Dolibarr - -* Ouvrir le navigateur pour aller sur Dolibarr et finaliser l'installation via - l'interface web. - -#### TetrasBack - -* Installation a partir du dépot de Tétras-Libre - -## Mises à jour - -Le script `upgradeAll.sh`, met à jour tous les logiciels installés via cet -installer. - -### Nextcloud - -Le script `upgradeNextcloud.sh` met nextcloud à jour depuis la dernière version -stable depuis les dépots nextcloud. - -En cas de lenteur en accés webdav aux fichiers depuis windows, il est possible d'utiliser [la solution décrite ici](https://help.nextcloud.com/t/trouble-with-webdav-performance/36423/5), nous ne recommandons pas ce réglage par défaut car il rends la base de donnée moins résiliante aux crash - -### Tetras-back - -Le script `upgradeTetras-back.sh` met Tetras-Back à jour en clonant la version -dans le gitlab tetras-libre. - -### Dolibarr - -Le script `upgradeDolibarr.sh` met Dolibarr à jour depuis la version deb -contenue dans ce dépot. - -## Project - -### TODO -+ [x] Ajouter clé maintenance de tetrix -+ [x] Permettre root sans password -+ [x] ufw permettre http https et ssh seulement. -+ [x] ClamAv en daemon -+ [x] HealthReport -+ [x] installation MySQL automatisée - + [x] Mot de passe root aléatoire ou prédéfinie - + [x] sauvegarde des informations de log dans /root/.my.cnf -+ [ ] installation de Nextcloud - + [x] Installation des fichiers de configuration pour apache2 - + [ ] Activation nextcloud sur apache - + [x] Variables de spécialisation installation Nextcloud -+ [x] Installation Dolibarr -+ [x] Installation TetrasBack - -## Licence - -This program is distributed under GPLV3 Licence, see `Licence.txt` diff --git a/install/Base.sh b/install/Base.sh index 4c9c542a1ad69f65fa69f0615fada849d7f6ce26..c030146fd9aa89678b2957fa2b7353631098b11f 100644 --- a/install/Base.sh +++ b/install/Base.sh @@ -118,7 +118,11 @@ bash $DIR/checks/rkhunter.sh # Allow maintenance operations: mkdir -p /root/.ssh -cat id_rsa.pub >> /root/.ssh/authorized_keys +if [ "$TETRAS_MAINTENANCE" = true ] ; then + cat id_rsa.pub >> /root/.ssh/authorized_keys +else + touch /root/.ssh/authorized_keys +fi chmod 600 /root/.ssh/authorized_keys #Ssh diff --git a/main.env.sample b/main.env.sample index 30a746dbe7e66c7e9a9178ff7a9db7f7b0a13456..4cce845b1218316a1be4f4ee3c324452642e06a8 100644 --- a/main.env.sample +++ b/main.env.sample @@ -1,6 +1,6 @@ # Listes of modules : Base GlpiAgent WebServer MySQL Nextcloud Collabora Dolibarr TetrasBack -# You always need : Base GlpiAgent +# You always need : Base # To use Docker you need : Traefik export MODS="Base GlpiAgent Traefik" @@ -8,11 +8,22 @@ export MODS="Base GlpiAgent Traefik" # Valid levels are security and upgrade export MAINTENANCE_LEVEL="security" -# TODO change domain for you domaine of server +# TODO change domain for you domain of server export DOMAIN="dev.tetras-libre.fr" +# TODO change admin mail export SERVER_ADMIN="sysadmin@tetras-libre.fr" +# TODO put this variable to false if tetras does not provide maintenance +# This has the consequence of whether or not the Tetras-Libre ssh public key is added to the authorized keys +export TETRAS_MAINTENANCE=true + +# TODO change ignore domains for fail2ban +export IGNORE_DOMAINS=( + "tetrix.tetras-libre.fr" + "piculus.tetras-libre.fr" +) + # can be set to nginx export WEB_SERVER="apache2" # You can define here some services that are badly detected by checkrestart diff --git a/utils/configure_base_tools.sh b/utils/configure_base_tools.sh index 095224683147d0a08b9336474279aa0cbeb6c07d..cd3f8515f10ff007b05fda33aba2ea588cfed262 100755 --- a/utils/configure_base_tools.sh +++ b/utils/configure_base_tools.sh @@ -1,6 +1,18 @@ #!/bin/bash +set -o nounset # Treat unset variables as an error + echo "RUN $(basename "$0") ===" +DIR=$(realpath $(dirname $0)/..) +if [ ! -e $DIR/main.env ] +then + echo "Please copy in root of NoCloud Auto Installer main.env.sample to main.env and edit it" + exit 1 +else + echo "Environment file loaded" +fi +. $DIR/main.env + if [ -z "$(grep '^alias ls=' /root/.bashrc)" ] then @@ -35,10 +47,21 @@ syntax on filetype plugin indent on EOF +ignoreips=() + +for domain in "${IGNORE_DOMAINS[@]}"; do + # Use dig to get the IP address + ip=$(dig +short "$domain") + ignoreips=("${ignoreips[@]}" $ip) + # Displays the domain name and IP addresss + echo "$domain : $ip" +done + cat <<EOF > /etc/fail2ban/jail.local [DEFAULT] -# Ignore Tetras Libre IPs -ignoreip = 127.0.0.1/8 ::1 $(dig +short servermon.tetras-libre.fr | tail -n 1) $(dig +short tetrix.tetras-libre.fr | tail -n 1) $(docker network inspect traefik | awk '/Subnet/{print $2}' | sed -e 's/"//g' -e 's/,$//') +ignoreip = 127.0.0.1/8 ::1 ${ignoreips[@]} $(docker network inspect traefik | awk '/Subnet/{print $2}' | sed -e 's/"//g' -e 's/,$//') + EOF + fail2ban-client reload diff --git a/utils/getIgnoreIp.sh b/utils/getIgnoreIp.sh new file mode 100644 index 0000000000000000000000000000000000000000..1cff80a5e82047ff6447dd5e8545a0ea4fc92287 --- /dev/null +++ b/utils/getIgnoreIp.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -o nounset # Treat unset variables as an error + +echo "RUN $(basename "$0") ===" + +DIR=$(realpath $(dirname $0)/..) +if [ ! -e $DIR/main.env ] +then + echo "Please copy in racine of NoCloud Auto Installer main.env.sample to main.env and edit it" + exit 1 +else + echo "Environment file loaded" +fi +. $DIR/main.env + + +ignoreips=() + +for domain in "${IGNORE_DOMAINS[@]}"; do + # Use dig to get the IP address + ip=$(dig +short "$domain") + ignoreips=("${ignoreips[@]}" $ip) + # Displays the domain name and IP address + echo "$domain : $ip" +done