diff --git a/package_check.sh b/package_check.sh index 76776d1..5c9e12a 100755 --- a/package_check.sh +++ b/package_check.sh @@ -64,10 +64,6 @@ if [ "$(whoami)" != "$(cat "$script_dir/sub_scripts/setup_user")" ] && test -e " exit 0 fi -source "$script_dir/sub_scripts/lxc_launcher.sh" -source "$script_dir/sub_scripts/testing_process.sh" -source /usr/share/yunohost/helpers - # Vérifie la connexion internet. ping -q -c 2 yunohost.org > /dev/null 2>&1 if [ "$?" -ne 0 ]; then # En cas d'échec de connexion, tente de pinger un autre domaine pour être sûr @@ -133,10 +129,42 @@ echo "$version_plinter" > "$script_dir/plinter_version" USER_TEST=package_checker PASSWORD_TEST=checker_pwd PATH_TEST=/check -LXC_NAME=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep LXC_NAME= | cut -d '=' -f2) -if [ -e "$script_dir/config" ]; then - main_iface=$(cat "$script_dir/config" | grep iface= | cut -d '=' -f2) -else # Si le fichier de config n'existe pas + +# Récupère les informations depuis le fichier de conf (Ou le complète le cas échéant) +pcheck_config="$script_dir/config" +# Tente de lire les informations depuis le fichier de config si il existe +if [ -e "$pcheck_config" ] +then + PLAGE_IP=$(cat "$pcheck_config" | grep PLAGE_IP= | cut -d '=' -f2) + DOMAIN=$(cat "$pcheck_config" | grep DOMAIN= | cut -d '=' -f2) + YUNO_PWD=$(cat "$pcheck_config" | grep YUNO_PWD= | cut -d '=' -f2) + LXC_NAME=$(cat "$pcheck_config" | grep LXC_NAME= | cut -d '=' -f2) + LXC_BRIDGE=$(cat "$pcheck_config" | grep LXC_BRIDGE= | cut -d '=' -f2) + main_iface=$(cat "$pcheck_config" | grep iface= | cut -d '=' -f2) +fi +echo "PLAGE_IP1=$PLAGE_IP" +# Utilise des valeurs par défaut si les variables sont vides, et génère le fichier de config +if [ -z "$PLAGE_IP" ]; then + PLAGE_IP=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep "|| PLAGE_IP=" | cut -d '"' -f4) + echo -e "# Plage IP du conteneur\nPLAGE_IP=$PLAGE_IP\n" >> "$pcheck_config" +fi +if [ -z "$DOMAIN" ]; then + DOMAIN=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep "|| DOMAIN=" | cut -d '=' -f2) + echo -e "# Domaine de test\nDOMAIN=$DOMAIN\n" >> "$pcheck_config" +fi +if [ -z "$YUNO_PWD" ]; then + YUNO_PWD=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep "|| YUNO_PWD=" | cut -d '=' -f2) + echo -e "# Mot de passe\nYUNO_PWD=$YUNO_PWD\n" >> "$pcheck_config" +fi +if [ -z "$LXC_NAME" ]; then + LXC_NAME=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep "|| LXC_NAME=" | cut -d '=' -f2) + echo -e "# Nom du conteneur\nLXC_NAME=$LXC_NAME\n" >> "$pcheck_config" +fi +if [ -z "$LXC_BRIDGE" ]; then + LXC_BRIDGE=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep "|| LXC_BRIDGE=" | cut -d '=' -f2) + echo -e "# Nom du bridge\nLXC_BRIDGE=$LXC_BRIDGE\n" >> "$pcheck_config" +fi +if [ -z "$main_iface" ]; then # Tente de définir l'interface réseau principale main_iface=$(sudo route | grep default | awk '{print $8;}') # Prend l'interface réseau défini par default if [ -z $main_iface ]; then @@ -144,9 +172,13 @@ else # Si le fichier de config n'existe pas exit 1 fi # Enregistre le nom de l'interface réseau de l'hôte dans un fichier de config - echo -e "# interface réseau principale de l'hôte\niface=$main_iface\n" > "$script_dir/config" + echo -e "# Interface réseau principale de l'hôte\niface=$main_iface\n" >> "$pcheck_config" fi +source "$script_dir/sub_scripts/lxc_launcher.sh" +source "$script_dir/sub_scripts/testing_process.sh" +source /usr/share/yunohost/helpers + if [ "$no_lxc" -eq 0 ] then DOMAIN=$(sudo cat /var/lib/lxc/$LXC_NAME/rootfs/etc/yunohost/current_host) diff --git a/sub_scripts/lxc_build.sh b/sub_scripts/lxc_build.sh index e7bee83..657ecb2 100755 --- a/sub_scripts/lxc_build.sh +++ b/sub_scripts/lxc_build.sh @@ -3,13 +3,24 @@ # Récupère le dossier du script if [ "${0:0:1}" == "/" ]; then script_dir="$(dirname "$0")"; else script_dir="$(echo $PWD/$(dirname "$0" | cut -d '.' -f2) | sed 's@/$@@')"; fi +pcheck_config="$script_dir/../config" +# Tente de lire les informations depuis le fichier de config si il existe +if [ -e "$pcheck_config" ] +then + PLAGE_IP=$(cat "$pcheck_config" | grep PLAGE_IP= | cut -d '=' -f2) + DOMAIN=$(cat "$pcheck_config" | grep DOMAIN= | cut -d '=' -f2) + YUNO_PWD=$(cat "$pcheck_config" | grep YUNO_PWD= | cut -d '=' -f2) + LXC_NAME=$(cat "$pcheck_config" | grep LXC_NAME= | cut -d '=' -f2) + LXC_BRIDGE=$(cat "$pcheck_config" | grep LXC_BRIDGE= | cut -d '=' -f2) +fi + LOG_BUILD_LXC="$script_dir/Build_lxc.log" -PLAGE_IP="10.1.4" +test -n "$PLAGE_IP" || PLAGE_IP="10.1.4" # Utilise des valeurs par défaut si les variables sont vides. +test -n "$DOMAIN" || DOMAIN=domain.tld +test -n "$YUNO_PWD" || YUNO_PWD=admin +test -n "$LXC_NAME" || LXC_NAME=pchecker_lxc +test -n "$LXC_BRIDGE" || LXC_BRIDGE=lxc-pchecker ARG_SSH="-t" -DOMAIN=domain.tld -YUNO_PWD=admin -LXC_NAME=pchecker_lxc -LXC_BRIDGE=lxc-pchecker # Tente de définir l'interface réseau principale main_iface=$(sudo route | grep default | awk '{print $8;}') # Prend l'interface réseau défini par default @@ -24,7 +35,14 @@ touch "$script_dir/../pcheck.lock" # Met en place le lock de Package check, le t echo $(whoami) > "$script_dir/setup_user" # Enregistre le nom de l'interface réseau de l'hôte dans un fichier de config -echo -e "# interface réseau principale de l'hôte\niface=$main_iface\n" > "$script_dir/../config" +echo -e "# interface réseau principale de l'hôte\niface=$main_iface\n" > "$pcheck_config" +# Enregistre les infos dans le fichier de config. +echo -e "# Plage IP du conteneur\nPLAGE_IP=$PLAGE_IP\n" >> "$pcheck_config" +echo -e "# Domaine de test\nDOMAIN=$DOMAIN\n" >> "$pcheck_config" +echo -e "# Mot de passe\nYUNO_PWD=$YUNO_PWD\n" >> "$pcheck_config" +echo -e "# Nom du conteneur\nLXC_NAME=$LXC_NAME\n" >> "$pcheck_config" +echo -e "# Nom du bridge\nLXC_BRIDGE=$LXC_BRIDGE\n" >> "$pcheck_config" + echo -e "\e[1m> Update et install lxc lxctl\e[0m" | tee "$LOG_BUILD_LXC" sudo apt-get update >> "$LOG_BUILD_LXC" 2>&1 diff --git a/sub_scripts/lxc_check.sh b/sub_scripts/lxc_check.sh index 50481dd..a4db9ca 100755 --- a/sub_scripts/lxc_check.sh +++ b/sub_scripts/lxc_check.sh @@ -6,13 +6,40 @@ # Récupère le dossier du script if [ "${0:0:1}" == "/" ]; then script_dir="$(dirname "$0")"; else script_dir="$(echo $PWD/$(dirname "$0" | cut -d '.' -f2) | sed 's@/$@@')"; fi -PLAGE_IP=$(cat "$script_dir/lxc_build.sh" | grep PLAGE_IP= | cut -d '"' -f2) ARG_SSH="-t" -LXC_NAME=$(cat "$script_dir/lxc_build.sh" | grep LXC_NAME= | cut -d '=' -f2) -LXC_BRIDGE=$(cat "$script_dir/lxc_build.sh" | grep LXC_BRIDGE= | cut -d '=' -f2) -if [ -e "$script_dir/../config" ]; then - main_iface=$(cat "$script_dir/../config" | grep iface= | cut -d '=' -f2) -else # Si le fichier de config n'existe pas +# Récupère les informations depuis le fichier de conf (Ou le complète le cas échéant) +pcheck_config="$script_dir/../config" +# Tente de lire les informations depuis le fichier de config si il existe +if [ -e "$pcheck_config" ] +then + PLAGE_IP=$(cat "$pcheck_config" | grep PLAGE_IP= | cut -d '=' -f2) + DOMAIN=$(cat "$pcheck_config" | grep DOMAIN= | cut -d '=' -f2) + YUNO_PWD=$(cat "$pcheck_config" | grep YUNO_PWD= | cut -d '=' -f2) + LXC_NAME=$(cat "$pcheck_config" | grep LXC_NAME= | cut -d '=' -f2) + LXC_BRIDGE=$(cat "$pcheck_config" | grep LXC_BRIDGE= | cut -d '=' -f2) +fi +# Utilise des valeurs par défaut si les variables sont vides, et génère le fichier de config +if [ -z "$PLAGE_IP" ]; then + PLAGE_IP=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep "|| PLAGE_IP=" | cut -d '"' -f4) + echo -e "# Plage IP du conteneur\nPLAGE_IP=$PLAGE_IP\n" >> "$pcheck_config" +fi +if [ -z "$DOMAIN" ]; then + DOMAIN=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep "|| DOMAIN=" | cut -d '=' -f2) + echo -e "# Domaine de test\nDOMAIN=$DOMAIN\n" >> "$pcheck_config" +fi +if [ -z "$YUNO_PWD" ]; then + YUNO_PWD=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep "|| YUNO_PWD=" | cut -d '=' -f2) + echo -e "# Mot de passe\nYUNO_PWD=$YUNO_PWD\n" >> "$pcheck_config" +fi +if [ -z "$LXC_NAME" ]; then + LXC_NAME=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep "|| LXC_NAME=" | cut -d '=' -f2) + echo -e "# Nom du conteneur\nLXC_NAME=$LXC_NAME\n" >> "$pcheck_config" +fi +if [ -z "$LXC_BRIDGE" ]; then + LXC_BRIDGE=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep "|| LXC_BRIDGE=" | cut -d '=' -f2) + echo -e "# Nom du bridge\nLXC_BRIDGE=$LXC_BRIDGE\n" >> "$pcheck_config" +fi +if [ -z "$main_iface" ]; then # Tente de définir l'interface réseau principale main_iface=$(sudo route | grep default | awk '{print $8;}') # Prend l'interface réseau défini par default if [ -z $main_iface ]; then @@ -20,7 +47,7 @@ else # Si le fichier de config n'existe pas exit 1 fi # Enregistre le nom de l'interface réseau de l'hôte dans un fichier de config - echo -e "# interface réseau principale de l'hôte\niface=$main_iface\n" > "$script_dir/../config" + echo -e "# Interface réseau principale de l'hôte\niface=$main_iface\n" >> "$pcheck_config" fi STOP_CONTAINER () { diff --git a/sub_scripts/lxc_remove.sh b/sub_scripts/lxc_remove.sh index 3ed0d74..c434704 100755 --- a/sub_scripts/lxc_remove.sh +++ b/sub_scripts/lxc_remove.sh @@ -3,8 +3,9 @@ # Récupère le dossier du script if [ "${0:0:1}" == "/" ]; then script_dir="$(dirname "$0")"; else script_dir="$(echo $PWD/$(dirname "$0" | cut -d '.' -f2) | sed 's@/$@@')"; fi -LXC_NAME=$(cat "$script_dir/lxc_build.sh" | grep LXC_NAME= | cut -d '=' -f2) -LXC_BRIDGE=$(cat "$script_dir/lxc_build.sh" | grep LXC_BRIDGE= | cut -d '=' -f2) +pcheck_config="$script_dir/../config" +LXC_NAME=$(cat "$pcheck_config" | grep LXC_NAME= | cut -d '=' -f2) +LXC_BRIDGE=$(cat "$pcheck_config" | grep LXC_BRIDGE= | cut -d '=' -f2) # Check user if [ "$(whoami)" != "$(cat "$script_dir/setup_user")" ] && test -e "$script_dir/setup_user"; then diff --git a/sub_scripts/lxc_upgrade.sh b/sub_scripts/lxc_upgrade.sh index dfa6561..cc05a9e 100755 --- a/sub_scripts/lxc_upgrade.sh +++ b/sub_scripts/lxc_upgrade.sh @@ -10,9 +10,11 @@ then # L'upgrade est annulé fi touch "$script_dir/../pcheck.lock" # Met en place le lock de Package check -PLAGE_IP=$(cat "$script_dir/lxc_build.sh" | grep PLAGE_IP= | cut -d '"' -f2) -LXC_NAME=$(cat "$script_dir/lxc_build.sh" | grep LXC_NAME= | cut -d '=' -f2) -LXC_BRIDGE=$(cat "$script_dir/lxc_build.sh" | grep LXC_BRIDGE= | cut -d '=' -f2) +pcheck_config="$script_dir/../config" +PLAGE_IP=$(cat "$pcheck_config" | grep PLAGE_IP= | cut -d '=' -f2) +LXC_NAME=$(cat "$pcheck_config" | grep LXC_NAME= | cut -d '=' -f2) +LXC_BRIDGE=$(cat "$pcheck_config" | grep LXC_BRIDGE= | cut -d '=' -f2) + if [ -e "$script_dir/../config" ]; then main_iface=$(cat "$script_dir/../config" | grep iface= | cut -d '=' -f2) else # Si le fichier de config n'existe pas