350 lines
12 KiB
Bash
Executable File
350 lines
12 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
#1 : action = default up
|
||
#2 : service = optionnel
|
||
|
||
# Fusionner l'ensemble des fichier .env en un seul
|
||
rm -f ./.env.local
|
||
cat ./env/.env* >> ./.env.local
|
||
. ./misc/tools/e-ihm.sh
|
||
. .env
|
||
. ./env/.env
|
||
. ./env/.env.local
|
||
|
||
# Start script
|
||
clear
|
||
BigTitle "ENVOLE"
|
||
|
||
# on remplace les valeur reprise dans les autres .env car podman interprète mal
|
||
sed -i 's#${WEB_URL}#'${WEB_URL}'#g' ./.env.local
|
||
sed -i 's#${WEB_PROTOCOL}#'${WEB_PROTOCOL}'#g' ./.env.local
|
||
. ./.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
|
||
|
||
# Include
|
||
. ./.env.local
|
||
|
||
|
||
|
||
#===========================================================================================================================================
|
||
#== STOP ===================================================================================================================================
|
||
#===========================================================================================================================================
|
||
#1 = service to stop if null all service
|
||
#2 = stopper par destroyall
|
||
|
||
stop() {
|
||
if [[ "$2" != 1 ]]; then Title "STOP"; fi
|
||
|
||
$PODCOMPOSEBIN stop $1
|
||
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
|
||
}
|
||
|
||
#===========================================================================================================================================
|
||
#== UPSERVICE ==============================================================================================================================
|
||
#===========================================================================================================================================
|
||
#1 = service to up
|
||
|
||
wait_for_container() {
|
||
container_id="envole-$1"
|
||
container_name="$($PODBIN inspect "${container_id}" --format '{{ .Name }}')"
|
||
waiting_done="false"
|
||
|
||
while [[ "${waiting_done}" != "true" ]]; do
|
||
container_state="$($PODBIN inspect "${container_id}" --format '{{ .State.Status }}')"
|
||
if [[ "${container_state}" == "running" ]]; then
|
||
health_status="$($PODBIN inspect "${container_id}" --format '{{ .State.Health.Status }}')"
|
||
if [[ ${health_status} == "healthy" ]]; then
|
||
waiting_done="true"
|
||
fi
|
||
else
|
||
waiting_done="true"
|
||
fi
|
||
sleep 1;
|
||
done;
|
||
}
|
||
|
||
upservice(){
|
||
$PODCOMPOSEBIN up -d $1
|
||
wait_for_container $1
|
||
}
|
||
|
||
#===========================================================================================================================================
|
||
#== UP =====================================================================================================================================
|
||
#===========================================================================================================================================
|
||
#1 = service to up if null all service
|
||
|
||
up(){
|
||
# Stop du ou des services
|
||
stop $1
|
||
|
||
# SERVICES
|
||
if [[ -z "$1" ]]
|
||
then
|
||
# 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
|
||
|
||
# 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
|
||
|
||
if [[ $NINEGATE_ACTIVATE == 1 && $NINEGATE_LOCAL == 1 ]]
|
||
then
|
||
EchoVert ${NINEGATE_SERVICE_NAME^^}
|
||
$PODCOMPOSEBIN exec $MARIADB_SERVICE_NAME /envole/init.sh $NINEGATE_SERVICE_NAME
|
||
fi
|
||
|
||
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
|
||
|
||
# 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
|
||
|
||
# CAS
|
||
if [[ $CAS_ACTIVATE == 1 && $CAS_LOCAL == 1 ]]
|
||
then
|
||
Title ${CAS_SERVICE_NAME^^}
|
||
upservice $CAS_SERVICE_NAME
|
||
fi
|
||
|
||
# NINEGATE
|
||
if [[ $NINEGATE_ACTIVATE == 1 && $NINEGATE_LOCAL == 1 ]]
|
||
then
|
||
Title ${NINEGATE_SERVICE_NAME^^}
|
||
upservice ${NINEGATE_SERVICE_NAME}
|
||
echo
|
||
fi
|
||
|
||
# NEXTCLOUD
|
||
if [[ $NEXTCLOUD_ACTIVATE == 1 && $NEXTCLOUD_LOCAL == 1 ]]
|
||
then
|
||
Title ${NEXTCLOUD_SERVICE_NAME^^}
|
||
upservice ${NEXTCLOUD_SERVICE_NAME}
|
||
echo
|
||
fi
|
||
|
||
# ADMINER
|
||
if [[ $ADMINER_ACTIVATE == 1 && $ADMINER_LOCAL == 1 ]]
|
||
then
|
||
Title ${ADMINER_SERVICE_NAME^^}
|
||
$PODCOMPOSEBIN up -d ${ADMINER_SERVICE_NAME}
|
||
echo
|
||
fi
|
||
|
||
# PHPLDAPADMIN
|
||
if [[ $PHPLDAPADMIN_ACTIVATE == 1 && $PHPLDAPADMIN_LOCAL == 1 ]]
|
||
then
|
||
Title ${PHPLDAPADMIN_SERVICE_NAME^^}
|
||
$PODCOMPOSEBIN up -d ${PHPLDAPADMIN_SERVICE_NAME}
|
||
echo
|
||
fi
|
||
|
||
# NINEAPACHE
|
||
if [[ $NINEAPACHE_ACTIVATE == 1 && $NINEAPACHE_LOCAL == 1 ]]
|
||
then
|
||
Title ${NINEAPACHE_SERVICE_NAME^^}
|
||
$PODCOMPOSEBIN up -d ${NINEAPACHE_SERVICE_NAME}
|
||
echo
|
||
fi
|
||
else
|
||
Title ${1^^}
|
||
$PODCOMPOSEBIN up -d $1
|
||
fi
|
||
}
|
||
|
||
#===========================================================================================================================================
|
||
#== 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(){
|
||
Title "DESTROY "${1^^}
|
||
|
||
stop $1 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
|
||
}
|
||
|
||
#===========================================================================================================================================
|
||
#== 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
|
||
$PODCOMPOSEBIN exec $2 "/bin/bash"
|
||
fi
|
||
elif [[ $1 == "destroyall" ]]
|
||
then
|
||
destroyall
|
||
elif [[ $1 == "destroy" ]]
|
||
then
|
||
if [[ -z $2 ]]
|
||
then
|
||
EchoRouge "Vous devez precisez un service"
|
||
EchoRouge "envole.sh destroy monservice"
|
||
else
|
||
destroy $2
|
||
fi
|
||
elif [[ $1 == "logs" ]]
|
||
then
|
||
$PODCOMPOSEBIN logs -f $2
|
||
elif [[ $1 == "iswait" ]]
|
||
then
|
||
wait_for_container $2
|
||
elif [[ $1 == "env" ]]
|
||
then
|
||
EchoVert "Fichier .env.local regénéré"
|
||
fi
|
||
echo
|
||
echo |