envole/src/envole-1.0/envole.sh

200 lines
6.3 KiB
Bash
Raw Normal View History

2023-11-02 14:22:16 +01:00
#!/bin/bash
#1 : action = default up
#2 : service = optionnel
. ./misc/tools/e-ihm.sh
. ./env/.env
. ./env/.env.local
clear
BigTitle "ENVOLE"
#===========================================================================================================================================
#== STOP ===================================================================================================================================
#===========================================================================================================================================
#1 = service to stop if null all service
stop() {
Title "STOP"
docker-compose stop $1
}
#===========================================================================================================================================
#== UPSERVICE ==============================================================================================================================
#===========================================================================================================================================
#1 = service to up
wait_for_container() {
container_id="envole-$1"
container_name="$(docker inspect "${container_id}" --format '{{ .Name }}')"
waiting_done="false"
while [[ "${waiting_done}" != "true" ]]; do
container_state="$(docker inspect "${container_id}" --format '{{ .State.Status }}')"
if [[ "${container_state}" == "running" ]]; then
health_status="$(docker 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(){
docker-compose up -d $1
wait_for_container $1
}
#===========================================================================================================================================
#== UP =====================================================================================================================================
#===========================================================================================================================================
#1 = service to up if null all service
up(){
# Stop du ou des services
stop $1
# Fusionner l'ensemble des fichier .env en un seul
rm -f ./.env.local
cat ./env/.env* >> ./.env.local
# MARIADB
Title "MARIADB"
upservice $MARIADB_SERVICE_NAME
echo
# CREATE BDD
if [[ $CAS_ACTIVATE == 1 && $CAS_LOCAL == 1 ]]
then
EchoVert ${CAS_SERVICE_NAME^^}
docker-compose exec $MARIADB_SERVICE_NAME /envole/init.sh $CAS_SERVICE_NAME
fi
if [[ $NINEGATE_ACTIVATE == 1 && $NINEGATE_LOCAL == 1 ]]
then
EchoVert ${NINEGATE_SERVICE_NAME^^}
docker-compose exec $MARIADB_SERVICE_NAME /envole/init.sh $NINEGATE_SERVICE_NAME
fi
if [[ $NEXTCLOUD_ACTIVATE == 1 && $NEXTCLOUD_LOCAL == 1 ]]
then
EchoVert ${NEXTCLOUD_SERVICE_NAME^^}
docker-compose exec $MARIADB_SERVICE_NAME /envole/init.sh $NEXTCLOUD_SERVICE_NAME
fi
# OPENLDAP
if [[ $LDAP_ACTIVATE == 1 && $LDAP_LOCAL == 1 ]]
then
Title ${LDAP_SERVICE_NAME^^}
2023-11-02 16:37:13 +01:00
mkdir -p ./volume/openldap/data
chmod a+wr ./volume/openldap/data
2023-11-02 14:22:16 +01:00
upservice $LDAP_SERVICE_NAME
docker-compose 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
# SERVICES
Title "UP"
if [[ -z "$1" ]]
then
if [[ $NINEGATE_ACTIVATE == 1 && $NINEGATE_LOCAL == 1 ]]
then
EchoVert ${NINEGATE_SERVICE_NAME^^}
upservice ${NINEGATE_SERVICE_NAME}
echo
fi
if [[ $NEXTCLOUD_ACTIVATE == 1 && $NEXTCLOUD_LOCAL == 1 ]]
then
ctrlUpdate ${NEXTCLOUD_SERVICE_NAME}
EchoVert ${NEXTCLOUD_SERVICE_NAME^^}
upservice ${NEXTCLOUD_SERVICE_NAME}
echo
fi
if [[ $ADMINER_ACTIVATE == 1 && $ADMINER_LOCAL == 1 ]]
then
EchoVert ${ADMINER_SERVICE_NAME^^}
docker-compose up -d ${ADMINER_SERVICE_NAME}
echo
fi
if [[ $PHPLDAPADMIN_ACTIVATE == 1 && $PHPLDAPADMIN_LOCAL == 1 ]]
then
EchoVert ${PHPLDAPADMIN_SERVICE_NAME^^}
docker-compose up -d ${PHPLDAPADMIN_SERVICE_NAME}
echo
fi
else
EchoVert ${1^^}
docker-compose up -d $1
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
docker-compose exec $2 "/bin/bash"
fi
elif [[ $1 == "destroy" ]]
then
if [[ -z $2 ]]
then
EchoRouge "Vous devez precisez un service"
EchoRouge "envole.sh bash monservice"
else
docker-compose stop $2
docker-compose rm $2
if [[ "$2" == "$LDAP_SERVICE_NAME" && $LDAP_ACTIVATE == 1 && $LDAP_LOCAL == 1 ]]
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
if [[ "$2" == "$CAS_SERVICE_NAME" && $CAS_ACTIVATE == 1 && $CAS_LOCAL == 1 ]]
then
Question_ouinon "Souhaitez-vous supprimer la BDD associé à $2 ?"
if [ "$?" = 0 ]
then
docker-compose exec $MARIADB_SERVICE_NAME /envole/delete.sh $CAS_SERVICE_NAME
fi
fi
fi
elif [[ $1 == "env" ]]
then
rm -f ./.env.local
cat ./env/.env* >> ./.env.local
fi
echo
2023-11-02 16:37:13 +01:00
echo2,5G