envole/docker/envole.sh

548 lines
18 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
#1 : action = default up
#2 : service = optionnel
cd /usr/share/envole/docker
# Fusionner l'ensemble des fichier .env en un seul
rm -f ./.env.local
cat ./env/.env* >> ./.env.local
. ./misc/e-ihm.sh
. .env
. ./env/.env
. ./env/.env.local
# Start script
BigTitle "ENVOLE"
# on remplace les valeur reprise dans les autres .env car podman interprète mal
if [[ "$PODCOMPOSEBIN" == "podman-compose" ]]
then
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#${OPENLDAP_SERVICE_NAME}#'${OPENLDAP_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
fi
# Include
. ./.env.local
#===========================================================================================================================================
#== ENV ====================================================================================================================================
#===========================================================================================================================================
#1 = service to stop if null all service
destroyall(){
Question_ouinon "Souhaitez-vous supprimer l'ensemble des containers : Attention cela supprimera vraiment tout ?"
if [[ "$?" = 0 ]]
then
destroy $MARIADB_SERVICE_NAME 1
destroy $OPENLDAP_SERVICE_NAME 1
destroy $KEYCLOAK_SERVICE_NAME 1
destroy $NINEGATE_SERVICE_NAME 1
destroy $NINEBOARD_SERVICE_NAME 1
destroy $NEXTCLOUD_SERVICE_NAME 1
destroy $WORDPRESS_SERVICE_NAME 1
destroy $ADMINER_SERVICE_NAME 1
destroy $PHPLDAPADMIN_SERVICE_NAME 1
destroy $NINEAPACHE_SERVICE_NAME 1
fi
}
env() {
rm -rf ./tmp/.env.$1
mkdir -p ./tmp
cat ./env/.env >> ./tmp/.env.$1
if [[ -f ./env/.env.local ]]; then cat ./env/.env.local >> ./tmp/.env.$1; fi
if [[ -f ./env/.env.zapp.$1 ]]; then cat ./env/.env.zapp.$1 >> ./tmp/.env.$1; fi
if [[ -f ./env/.env.zapp.$1.local ]]; then cat ./env/.env.zapp.$1.local >> ./tmp/.env.$1; fi
};
#===========================================================================================================================================
#== ENVALL =================================================================================================================================
#===========================================================================================================================================
envall(){
env $MARIADB_SERVICE_NAME
env $OPENLDAP_SERVICE_NAME
env $KEYCLOAK_SERVICE_NAME
env $NINEGATE_SERVICE_NAME
env $NINEBOARD_SERVICE_NAME
env $NEXTCLOUD_SERVICE_NAME
env $WORDPRESS_SERVICE_NAME
env $ADMINER_SERVICE_NAME
env $PHPLDAPADMIN_SERVICE_NAME
env $NINEAPACHE_SERVICE_NAME
}
#===========================================================================================================================================
#== 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
}
createdatabase(){
# DATABASE
if [[ $MARIADB_ACTIVATE == 1 && $MARIADB_LOCAL == 1 ]]
then
Title "DATABASE"
# CREATE BDD
if [[ $CAS_ACTIVATE == 1 && $CAS_LOCAL == 1 ]]
then
EchoVert ${KEYCLOAK_SERVICE_NAME^^}
$PODCOMPOSEBIN exec $MARIADB_SERVICE_NAME /envole/init.sh $KEYCLOAK_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 [[ $NINEBOARD_ACTIVATE == 1 && $NINEBOARD_LOCAL == 1 ]]
then
EchoVert ${NINEBOARD_SERVICE_NAME^^}
$PODCOMPOSEBIN exec $MARIADB_SERVICE_NAME /envole/init.sh $NINEBOARD_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
if [[ $WORDPRESS_ACTIVATE == 1 && $WORDPRESS_LOCAL == 1 ]]
then
EchoVert ${WORDPRESS_SERVICE_NAME^^}
$PODCOMPOSEBIN exec $MARIADB_SERVICE_NAME /envole/init.sh $WORDPRESS_SERVICE_NAME
fi
fi
}
function upmariadb {
if [[ $MARIADB_ACTIVATE == 1 && $MARIADB_LOCAL == 1 ]]
then
Title "MARIADB"
upservice $MARIADB_SERVICE_NAME
createdatabase
fi
}
function upopenldap {
if [[ $LDAP_ACTIVATE == 1 && $LDAP_LOCAL == 1 ]]
then
Title ${OPENLDAP_SERVICE_NAME^^}
mkdir -p ./volume/openldap/data
chmod a+wr ./volume/openldap/data
upservice $OPENLDAP_SERVICE_NAME
$PODCOMPOSEBIN exec $OPENLDAP_SERVICE_NAME /envole/init.sh
echo
fi
}
function upkeycloak {
if [[ $CAS_ACTIVATE == 1 && $CAS_LOCAL == 1 ]]
then
Title ${KEYCLOAK_SERVICE_NAME^^}
upservice $KEYCLOAK_SERVICE_NAME
echo
fi
}
function upninegate {
if [[ $NINEGATE_ACTIVATE == 1 && $NINEGATE_LOCAL == 1 ]]
then
Title ${NINEGATE_SERVICE_NAME^^}
upservice ${NINEGATE_SERVICE_NAME}
chmod -R a+wr ./volume/ninegate/data
echo
fi
}
function upnineboard {
if [[ $NINEBOARD_ACTIVATE == 1 && $NINEBOARD_LOCAL == 1 ]]
then
Title ${NINEBOARD_SERVICE_NAME^^}
upservice ${NINEBOARD_SERVICE_NAME}
chmod -R a+wr ./volume/nineboard/data
echo
fi
}
function upnextcloud {
if [[ $NEXTCLOUD_ACTIVATE == 1 && $NEXTCLOUD_LOCAL == 1 ]]
then
Title ${NEXTCLOUD_SERVICE_NAME^^}
upservice ${NEXTCLOUD_SERVICE_NAME}
echo
fi
}
function upwordpress {
if [[ $WORDPRESS_ACTIVATE == 1 && $WORDPRESS_LOCAL == 1 ]]
then
Title ${WORDPRESS_SERVICE_NAME^^}
upservice ${WORDPRESS_SERVICE_NAME}
echo
fi
}
function upadminer {
if [[ $ADMINER_ACTIVATE == 1 && $ADMINER_LOCAL == 1 ]]
then
Title ${ADMINER_SERVICE_NAME^^}
$PODCOMPOSEBIN up -d ${ADMINER_SERVICE_NAME}
echo
fi
}
function upphpldapadmin {
if [[ $PHPLDAPADMIN_ACTIVATE == 1 && $PHPLDAPADMIN_LOCAL == 1 ]]
then
Title ${PHPLDAPADMIN_SERVICE_NAME^^}
$PODCOMPOSEBIN up -d ${PHPLDAPADMIN_SERVICE_NAME}
echo
fi
}
function upnineapache {
if [[ $NINEAPACHE_ACTIVATE == 1 && $NINEAPACHE_LOCAL == 1 ]]
then
Title ${NINEAPACHE_SERVICE_NAME^^}
$PODCOMPOSEBIN up -d ${NINEAPACHE_SERVICE_NAME}
echo
fi
}
#===========================================================================================================================================
#== 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"
EchoRouge "ATTENTION SOLUTION DE CONTOURNEMENT POUR LE POC"
EchoRouge "A résoudre si l'on souhaite mettre en production"
# 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
# ATTENTION A REVOIR car ouvre complétement le firewall
iptables -P INPUT ACCEPT
fi
# MARIADB
upmariadb
# OPENLDAP
upopenldap
# KEYCLOAK
upkeycloak
# NINEGATE
upninegate
# NINEBOARD
upnineboard
# NEXTCLOUD
upnextcloud
# WORDPRESS
upwordpress
# ADMINER
upadminer
# PHPLDAPADMIN
upphpldapadmin
# NINEAPACHE
upnineapache
else
env ${1}
if [[ $1 != "mariadb" ]]
then
createdatabase
fi
up${1}
fi
}
#===========================================================================================================================================
#== DESTROY ================================================================================================================================
#===========================================================================================================================================
destroyall(){
Question_ouinon "Souhaitez-vous supprimer l'ensemble des containers : Attention cela supprimera vraiment tout ?"
if [[ "$?" = 0 ]]
then
destroy $MARIADB_SERVICE_NAME 1
destroy $OPENLDAP_SERVICE_NAME 1
destroy $KEYCLOAK_SERVICE_NAME 1
destroy $NINEGATE_SERVICE_NAME 1
destroy $NINEBOARD_SERVICE_NAME 1
destroy $NEXTCLOUD_SERVICE_NAME 1
destroy $WORDPRESS_SERVICE_NAME 1
destroy $ADMINER_SERVICE_NAME 1
destroy $PHPLDAPADMIN_SERVICE_NAME 1
destroy $NINEAPACHE_SERVICE_NAME 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" == "$OPENLDAP_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" == "$KEYCLOAK_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 $KEYCLOAK_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" == "$NINEBOARD_SERVICE_NAME" && $NINEBOARD_ACTIVATE == 1 && $NINEBOARD_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 $NINEBOARD_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
if [[ "$1" == "$WORDPRESS_SERVICE_NAME" && $WORDPRESS_ACTIVATE == 1 && $WORDPRESS_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 $WORDPRESS_SERVICE_NAME
fi
fi
}
#===========================================================================================================================================
#== MAIN ===================================================================================================================================
#===========================================================================================================================================
envall
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
if [[ -z $2 ]]
then
EchoRouge "Vous devez precisez un service"
EchoRouge "envole.sh env monservice"
else
env $2
EchoVert "Fichier tmp/.env.$1 regénéré"
fi
elif [[ $1 == "regen" ]]
then
if [[ -z $2 ]]
then
destroyall
up
else
destroy $2
up $2
fi
else
EchoRouge "Action possible ="
EchoRouge "envole.sh > UP de l'ensemble des services actifs"
EchoRouge "envole.sh up > UP de l'ensemble des services actifs"
EchoRouge "envole.sh up monservice> UP de monservice"
EchoRouge "envole.sh stop > STOP de l'ensemble des services"
EchoRouge "envole.sh stop monservice> STOP de monservice"
EchoRouge "envole.sh bash monservice> lance un terminel dans le conteneur de monservice"
EchoRouge "envole.sh destroyall> détruit l'ensemble des services avec l'ensemble des BDD et des volumes persistant"
EchoRouge "envole.sh destroy monservice> détruit monservices et si souhaitez sa BDD et ses volumes persistant"
EchoRouge "envole.sh logs > LOGS de l'ensemble des services"
EchoRouge "envole.sh logs monservice > LOGS de monservice"
EchoRouge "envole.sh iswait monservice > monservice est-il en cours de construction"
EchoRouge "envole.sh env monservice > regeneration du fichier d'environnement de monservice"
EchoRouge "envole.sh regen > lance destroyall puis up sur l'ensemble des service"
EchoRouge "envole.sh regen monservice > lance destroy monservice puis up monservice"
fi
echo
echo