envole/src/envole-1.0/envole.sh

349 lines
12 KiB
Bash
Raw Normal View History

2023-11-02 14:22:16 +01:00
#!/bin/bash
#1 : action = default up
#2 : service = optionnel
2023-11-02 17:32:25 +01:00
# Fusionner l'ensemble des fichier .env en un seul
rm -f ./.env.local
cat ./env/.env* >> ./.env.local
2023-11-03 14:11:23 +01:00
. ./.env.local
# on remplace les valeur reprise dans les autres .env car podman interprète mal
#while IFS= read -r match; do
# eval "val=\${$match}"
# echo ${ADMIN_PASSWORD}
# echo ${match}
# echo ${!match}
# echo $val
# sed -i "s/${match}/${val}/g" ./.env.local
#done < <(grep -oP '\$\{\w+\}' ./.env.local)
sed -i 's#${ADMIN_PASSWORD}#'${ADMIN_PASSWORD}'#g' ./.env.local
sed -i 's#${ADMIN_USER}#'${ADMIN_USER}'#g' ./.env.local
sed -i 's#${CAS_HOST}#'${CAS_HOST}'#g' ./.env.local
sed -i 's#${CAS_PORT}#'${CAS_PORT}'#g' ./.env.local
sed -i 's#${CAS_USER}#'${CAS_USER}'#g' ./.env.local
sed -i 's#${CAS_PASSWORD}#'${CAS_PASSWORD}'#g' ./.env.local
sed -i 's#${LDAP_SERVICE_NAME}#'${LDAP_SERVICE_NAME}'#g' ./.env.local
sed -i 's#${LDAP_ADMIN_USERNAME}#'${LDAP_ADMIN_USERNAME}'#g' ./.env.local
sed -i 's#${LDAP_BASEDN}#'${LDAP_BASEDN}'#g' ./.env.local
sed -i 's#${LDAP_PASSWORD}#'${LDAP_PASSWORD}'#g' ./.env.local
sed -i 's#${LDAP_USER}#'${LDAP_USER}'#g' ./.env.local
sed -i 's#${LDAP_PORT}#'${LDAP_PORT}'#g' ./.env.local
sed -i 's#${MARIADB_SERVICE_NAME}#'${MARIADB_SERVICE_NAME}'#g' ./.env.local
sed -i 's#${MARIADB_USER}#'${MARIADB_USER}'#g' ./.env.local
sed -i 's#${MARIADB_PASSWORD}#'${MARIADB_PASSWORD}'#g' ./.env.local
sed -i 's#${ADMINER_ACTIVATE}#'${ADMINER_ACTIVATE}'#g' ./.env.local
sed -i 's#${ADMINER_URL}#'${ADMINER_URL}'#g' ./.env.local
sed -i 's#${PHPLDAPADMIN_ACTIVATE}#'${PHPLDAPADMIN_ACTIVATE}'#g' ./.env.local
sed -i 's#${PHPLDAPADMIN_URL}#'${PHPLDAPADMIN_URL}'#g' ./.env.local
sed -i 's#${NEXTCLOUD_ACTIVATE}#'${NEXTCLOUD_ACTIVATE}'#g' ./.env.local
sed -i 's#${NEXTCLOUD_URL}#'${NEXTCLOUD_URL}'#g' ./.env.local
2023-11-02 17:32:25 +01:00
# Include
2023-11-03 14:11:23 +01:00
. .env
2023-11-02 14:22:16 +01:00
. ./misc/tools/e-ihm.sh
. ./env/.env
. ./env/.env.local
2023-11-02 17:32:25 +01:00
# Start script
2023-11-02 14:22:16 +01:00
clear
BigTitle "ENVOLE"
#===========================================================================================================================================
#== STOP ===================================================================================================================================
#===========================================================================================================================================
#1 = service to stop if null all service
stop() {
Title "STOP"
2023-11-03 14:11:23 +01:00
$PODCOMPOSEBIN stop $1
2023-11-06 16:18:09 +01:00
if [[ "$PODCOMPOSEBIN" == "podman-compose" ]]
then
if [[ "$1" == "" ]]
then
CONTAINER_NAMES=$($PODCOMPOSEBIN -f docker-compose.yml ps | awk 'NR > 1 {print $1}')
for CONTAINER_NAME in $CONTAINER_NAMES; do
$PODBIN rm -f $CONTAINER_NAME
done
else
$PODBIN rm "envole-"$1
fi
fi
2023-11-02 14:22:16 +01:00
}
#===========================================================================================================================================
#== UPSERVICE ==============================================================================================================================
#===========================================================================================================================================
#1 = service to up
wait_for_container() {
container_id="envole-$1"
2023-11-03 14:11:23 +01:00
container_name="$($PODBIN inspect "${container_id}" --format '{{ .Name }}')"
2023-11-02 14:22:16 +01:00
waiting_done="false"
while [[ "${waiting_done}" != "true" ]]; do
2023-11-03 14:11:23 +01:00
container_state="$($PODBIN inspect "${container_id}" --format '{{ .State.Status }}')"
2023-11-02 14:22:16 +01:00
if [[ "${container_state}" == "running" ]]; then
2023-11-03 14:11:23 +01:00
health_status="$($PODBIN inspect "${container_id}" --format '{{ .State.Health.Status }}')"
2023-11-02 14:22:16 +01:00
if [[ ${health_status} == "healthy" ]]; then
waiting_done="true"
fi
else
waiting_done="true"
fi
sleep 1;
done;
}
upservice(){
2023-11-06 16:18:09 +01:00
$PODCOMPOSEBIN up -d $1
2023-11-02 14:22:16 +01:00
wait_for_container $1
}
#===========================================================================================================================================
#== UP =====================================================================================================================================
#===========================================================================================================================================
#1 = service to up if null all service
up(){
# Stop du ou des services
stop $1
2023-11-06 16:18:09 +01:00
# SERVICES
if [[ -z "$1" ]]
2023-11-02 14:22:16 +01:00
then
2023-11-06 16:18:09 +01:00
# NETWORK
if [[ "$RELEASE_SYSTEM" == "eole" ]]
then
Title "NETWORK"
# On réinstall docker-ce car le reconf détruit le reseau docker, la reinstall de docker-ce rétablit le reseau
apt-get install docker-ce --reinstall
fi
2023-11-02 14:22:16 +01:00
2023-11-06 16:18:09 +01:00
# MARIADB
if [[ $MARIADB_ACTIVATE == 1 && $MARIADB_LOCAL == 1 ]]
then
Title "MARIADB"
upservice $MARIADB_SERVICE_NAME
echo
# CREATE BDD
if [[ $CAS_ACTIVATE == 1 && $CAS_LOCAL == 1 ]]
then
EchoVert ${CAS_SERVICE_NAME^^}
$PODCOMPOSEBIN exec $MARIADB_SERVICE_NAME /envole/init.sh $CAS_SERVICE_NAME
fi
2023-11-02 14:22:16 +01:00
2023-11-06 16:18:09 +01:00
if [[ $NINEGATE_ACTIVATE == 1 && $NINEGATE_LOCAL == 1 ]]
then
EchoVert ${NINEGATE_SERVICE_NAME^^}
$PODCOMPOSEBIN exec $MARIADB_SERVICE_NAME /envole/init.sh $NINEGATE_SERVICE_NAME
fi
2023-11-02 14:22:16 +01:00
2023-11-06 16:18:09 +01:00
if [[ $NEXTCLOUD_ACTIVATE == 1 && $NEXTCLOUD_LOCAL == 1 ]]
then
EchoVert ${NEXTCLOUD_SERVICE_NAME^^}
$PODCOMPOSEBIN exec $MARIADB_SERVICE_NAME /envole/init.sh $NEXTCLOUD_SERVICE_NAME
fi
fi
2023-11-02 14:22:16 +01:00
2023-11-06 16:18:09 +01:00
# OPENLDAP
if [[ $LDAP_ACTIVATE == 1 && $LDAP_LOCAL == 1 ]]
then
Title ${LDAP_SERVICE_NAME^^}
mkdir -p ./volume/openldap/data
chmod a+wr ./volume/openldap/data
upservice $LDAP_SERVICE_NAME
$PODCOMPOSEBIN exec $LDAP_SERVICE_NAME /envole/init.sh
fi
2023-11-02 14:22:16 +01:00
2023-11-06 16:18:09 +01:00
# CAS
if [[ $CAS_ACTIVATE == 1 && $CAS_LOCAL == 1 ]]
then
Title ${CAS_SERVICE_NAME^^}
upservice $CAS_SERVICE_NAME
fi
# NINEGATE
2023-11-02 14:22:16 +01:00
if [[ $NINEGATE_ACTIVATE == 1 && $NINEGATE_LOCAL == 1 ]]
then
2023-11-06 16:18:09 +01:00
Title ${NINEGATE_SERVICE_NAME^^}
upservice ${NINEGATE_SERVICE_NAME}
2023-11-02 14:22:16 +01:00
echo
fi
2023-11-06 16:18:09 +01:00
# NEXTCLOUD
2023-11-02 14:22:16 +01:00
if [[ $NEXTCLOUD_ACTIVATE == 1 && $NEXTCLOUD_LOCAL == 1 ]]
then
2023-11-06 16:18:09 +01:00
Title ${NEXTCLOUD_SERVICE_NAME^^}
2023-11-02 14:22:16 +01:00
upservice ${NEXTCLOUD_SERVICE_NAME}
echo
fi
2023-11-06 16:18:09 +01:00
# ADMINER
2023-11-02 14:22:16 +01:00
if [[ $ADMINER_ACTIVATE == 1 && $ADMINER_LOCAL == 1 ]]
then
2023-11-06 16:18:09 +01:00
Title ${ADMINER_SERVICE_NAME^^}
2023-11-03 14:11:23 +01:00
$PODCOMPOSEBIN up -d ${ADMINER_SERVICE_NAME}
2023-11-02 14:22:16 +01:00
echo
fi
2023-11-06 16:18:09 +01:00
# PHPLDAPADMIN
2023-11-02 14:22:16 +01:00
if [[ $PHPLDAPADMIN_ACTIVATE == 1 && $PHPLDAPADMIN_LOCAL == 1 ]]
then
2023-11-06 16:18:09 +01:00
Title ${PHPLDAPADMIN_SERVICE_NAME^^}
2023-11-03 14:11:23 +01:00
$PODCOMPOSEBIN up -d ${PHPLDAPADMIN_SERVICE_NAME}
2023-11-02 14:22:16 +01:00
echo
fi
2023-11-03 14:11:23 +01:00
2023-11-06 16:18:09 +01:00
# NINEAPACHE
2023-11-03 14:11:23 +01:00
if [[ $NINEAPACHE_ACTIVATE == 1 && $NINEAPACHE_LOCAL == 1 ]]
then
2023-11-06 16:18:09 +01:00
Title ${NINEAPACHE_SERVICE_NAME^^}
2023-11-03 14:11:23 +01:00
$PODCOMPOSEBIN up -d ${NINEAPACHE_SERVICE_NAME}
echo
fi
2023-11-02 14:22:16 +01:00
else
EchoVert ${1^^}
2023-11-03 14:11:23 +01:00
$PODCOMPOSEBIN up -d $1
2023-11-02 14:22:16 +01:00
fi
}
2023-11-06 16:18:09 +01:00
#===========================================================================================================================================
#== DESTROY ================================================================================================================================
#===========================================================================================================================================
destroyall(){
Question_ouinon "Souhaitez-vous supprimer l'ensemble des containers : Attention cela supprimera vraiment tout ?"
if [[ "$?" = 0 ]]
then
destroy mariadb 1
destroy openldap 1
destroy keycloak 1
destroy ninegate 1
destroy nextcloud 1
destroy adminer 1
destroy phpldapadmin 1
destroy nineapache 1
fi
}
#===========================================================================================================================================
#== DESTROY ================================================================================================================================
#===========================================================================================================================================
#1 = service to destroy
#2 = ne pas poser de questions
destroy(){
stop $1
Title "DESTROY "${1^^}
if [[ "$PODCOMPOSEBIN" == "docker-compose" ]]
then
$PODBIN rm "envole-$1"
fi
if [[ "$1" == "$MARIADB_SERVICE_NAME" && $MARIADB_ACTIVATE == 1 && $MARIADB_LOCAL == 1 ]]
then
if [[ -z $2 ]]; then Question_ouinon "Souhaitez-vous supprimer l'ensemble des bases ?";fi
if [[ "$?" = 0 || -z $2 ]]
then
sudo rm -rf volume/mariadb/mysql
fi
fi
if [[ "$1" == "$LDAP_SERVICE_NAME" && $LDAP_ACTIVATE == 1 && $LDAP_LOCAL == 1 ]]
then
if [[ -z $2 ]]; then Question_ouinon "Souhaitez-vous supprimer l'annuaire associé à $1 ?";fi
if [[ "$?" = 0 || -z $2 ]]
then
sudo rm -rf volume/openldap/data
mkdir volume/openldap/data
chmod a+w volume/openldap/data -R
chmod a+r volume/openldap/data -R
fi
fi
if [[ "$1" == "$CAS_SERVICE_NAME" && $CAS_ACTIVATE == 1 && $CAS_LOCAL == 1 ]]
then
if [[ -z $2 ]]; then Question_ouinon "Souhaitez-vous supprimer la BDD associé à $1 ?";fi
if [[ "$?" = 0 || -z $2 ]]
then
$PODCOMPOSEBIN exec $MARIADB_SERVICE_NAME /envole/delete.sh $CAS_SERVICE_NAME
fi
fi
if [[ "$1" == "$NINEGATE_SERVICE_NAME" && $NINEGATE_ACTIVATE == 1 && $NINEGATE_LOCAL == 1 ]]
then
if [[ -z $2 ]]; then Question_ouinon "Souhaitez-vous supprimer la BDD associé à $1 ?";fi
if [[ "$?" = 0 || -z $2 ]]
then
$PODCOMPOSEBIN exec $MARIADB_SERVICE_NAME /envole/delete.sh $NINEGATE_SERVICE_NAME
fi
fi
if [[ "$1" == "$NEXTCLOUD_SERVICE_NAME" && $NEXTCLOUD_ACTIVATE == 1 && $NEXTCLOUD_LOCAL == 1 ]]
then
if [[ -z $2 ]]; then Question_ouinon "Souhaitez-vous supprimer la BDD associé à $1 ainsi que les fichiers utilisateurs ?";fi
if [[ "$?" = 0 || -z $2 ]]
then
$PODCOMPOSEBIN exec $MARIADB_SERVICE_NAME /envole/delete.sh $NEXTCLOUD_SERVICE_NAME
sudo rm -rf volume/nextcloud/data
sudo rm -rf volume/nextcloud/html
sudo rm -rf volume/nextcloud/app
fi
fi
}
2023-11-02 14:22:16 +01:00
#===========================================================================================================================================
#== MAIN ===================================================================================================================================
#===========================================================================================================================================
if [[ $1 == "up" || $1 == "" ]]
then
up $2
elif [[ $1 == "stop" ]]
then
stop $2
elif [[ $1 == "bash" ]]
then
if [[ -z $2 ]]
then
EchoRouge "Vous devez precisez un service"
EchoRouge "envole.sh bash monservice"
else
2023-11-03 14:11:23 +01:00
$PODCOMPOSEBIN exec $2 "/bin/bash"
2023-11-02 14:22:16 +01:00
fi
2023-11-06 16:18:09 +01:00
elif [[ $1 == "destroyall" ]]
then
destroyall
2023-11-02 14:22:16 +01:00
elif [[ $1 == "destroy" ]]
then
if [[ -z $2 ]]
then
EchoRouge "Vous devez precisez un service"
2023-11-06 16:18:09 +01:00
EchoRouge "envole.sh destroy monservice"
2023-11-02 14:22:16 +01:00
else
2023-11-06 16:18:09 +01:00
destroy $2
2023-11-02 14:22:16 +01:00
fi
2023-11-06 16:18:09 +01:00
elif [[ $1 == "logs" ]]
then
$PODCOMPOSEBIN logs -f $2
2023-11-02 14:22:16 +01:00
elif [[ $1 == "env" ]]
then
2023-11-06 16:18:09 +01:00
EchoVert "Fichier .env.local regénéré"
2023-11-02 14:22:16 +01:00
fi
echo
2023-11-02 17:30:24 +01:00
echo