#!/bin/bash # Check Debian Stretch or Buster host_codename=$(grep "VERSION_CODENAME" /etc/os-release | cut -d= -f2) if [ "$host_codename" != "stretch" ] && [ "$host_codename" != "buster" ] then echo "Package_check can only be installed on Debian Stretch or Debian Buster..." exit 1 fi # Load configuration dnsforce=1 cd $(dirname $(realpath $0) | sed 's@/sub_scripts$@@g') source "./sub_scripts/common.sh" LXC_BUILD() { # Met en place le lock de Package check, le temps de l'installation touch "$lock_file" echo $(whoami) > "./.setup_user" log_title "Installing host dependencies..." DEPENDENCIES="lxc lxctl git curl lynx jq python3-pip debootstrap rsync bridge-utils" sudo apt-get update sudo apt-get install -y $DEPENDENCIES # Créer le dossier lxcsnaps, pour s'assurer que lxc utilisera ce dossier, même avec lxc 2. sudo mkdir -p /var/lib/lxcsnaps # Si le conteneur existe déjà if sudo lxc-info -n $LXC_NAME > /dev/null 2>&1 then log_title "Suppression du conteneur existant." ./sub_scripts/lxc_remove.sh fi log_title "Création d'une machine debian $DISTRIB minimaliste." sudo lxc-create -n $LXC_NAME -t download -- -d debian -r $DISTRIB -a $(dpkg --print-architecture) log_title "Autoriser l'ip forwarding, pour router vers la machine virtuelle." echo "net.ipv4.ip_forward=1" | sudo tee /etc/sysctl.d/lxc_pchecker.conf sudo sysctl -p /etc/sysctl.d/lxc_pchecker.conf log_title "Ajoute un brige réseau pour la machine virtualisée" echo | sudo tee /etc/network/interfaces.d/$LXC_BRIDGE <> ~/.ssh/known_hosts # Initie une premier connexion SSH pour valider la clé. RUN_THROUGH_SSH "exit 0" # Si l'utilisateur tarde trop, la connexion sera refusée... ??? [ "$?" -ne 0 ] && RUN_THROUGH_SSH "exit 0" [ -n "$YNH_INSTALL_SCRIPT_BRANCH" ] && YNH_INSTALL_SCRIPT_BRANCH="--branch $YNH_INSTALL_SCRIPT_BRANCH" RUN_THROUGH_SSH git clone https://github.com/YunoHost/install_script $YNH_INSTALL_SCRIPT_BRANCH /tmp/install_script log_title "Installation de Yunohost..." RUN_THROUGH_SSH bash /tmp/install_script/install_yunohost -a log_title "Disable apt-daily to prevent it from messing with apt/dpkg lock" RUN_THROUGH_SSH systemctl -q stop apt-daily.timer RUN_THROUGH_SSH systemctl -q stop apt-daily-upgrade.timer RUN_THROUGH_SSH systemctl -q stop apt-daily.service RUN_THROUGH_SSH systemctl -q stop apt-daily-upgrade.service RUN_THROUGH_SSH systemctl -q disable apt-daily.timer RUN_THROUGH_SSH systemctl -q disable apt-daily-upgrade.timer RUN_THROUGH_SSH systemctl -q disable apt-daily.service RUN_THROUGH_SSH systemctl -q disable apt-daily-upgrade.service RUN_THROUGH_SSH rm -f /etc/cron.daily/apt-compat RUN_THROUGH_SSH cp /bin/true /usr/lib/apt/apt.systemd.daily log_title "Post install Yunohost" RUN_THROUGH_SSH yunohost tools postinstall --domain $DOMAIN --password $YUNO_PWD --force-password # Disable password strength check RUN_THROUGH_SSH yunohost settings set security.password.admin.strength -v -1 RUN_THROUGH_SSH yunohost settings set security.password.user.strength -v -1 # echo "Le mot de passe Yunohost est \'$YUNO_PWD\'" log_title "Ajout du sous domaine de test" RUN_THROUGH_SSH yunohost domain add $SUBDOMAIN TEST_USER_DISPLAY=${TEST_USER//"_"/""} log_title "Ajout de l'utilisateur de test" RUN_THROUGH_SSH yunohost user create $TEST_USER --firstname $TEST_USER_DISPLAY --mail $TEST_USER@$DOMAIN --lastname $TEST_USER_DISPLAY --password \"$YUNO_PWD\" log_title "Vérification de l'état de Yunohost" RUN_THROUGH_SSH yunohost --version log_title "Arrêt de la machine virtualisée" sudo lxc-stop -n $LXC_NAME log_title "Suppression des règles de parefeu" sudo iptables -D FORWARD -i $LXC_BRIDGE -o $MAIN_NETWORK_INTERFACE -j ACCEPT sudo iptables -D FORWARD -i $MAIN_NETWORK_INTERFACE -o $LXC_BRIDGE -j ACCEPT sudo iptables -t nat -D POSTROUTING -s $LXC_NETWORK.0/24 -j MASQUERADE sudo ifdown --force $LXC_BRIDGE log_title "Création d'un snapshot" sudo lxc-snapshot -n $LXC_NAME # Il sera nommé snap0 et stocké dans /var/lib/lxcsnaps/$LXC_NAME/snap0/ rm "$lock_file" } LXC_BUILD 2>&1 | tee -a "./Build_lxc.log"