ninedocker/nine.sh

547 lines
17 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
# Fusionner l'ensemble des fichier .env en un seul
rm -f ./.env.local
cat ./env/.env* >> ./.env.local
. ./misc/e-ihm.sh
. ./env/.env
if [ -f ./env/.env.local ]
then
. ./env/.env.local
fi
# Start script
BigTitle "NINE"
# 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 $NINEAPACHE_SERVICE_NAME 1
destroy $MARIADB_SERVICE_NAME 1
destroy $REDIS_SERVICE_NAME 1
destroy $MINIO_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
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 $NINEAPACHE_SERVICE_NAME
env $MARIADB_SERVICE_NAME
env $REDIS_SERVICE_NAME
env $MINIO_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
}
#===========================================================================================================================================
#== STOP ===================================================================================================================================
#===========================================================================================================================================
#1 = service to stop if null all service
#2 = stopper par destroyall
stop() {
if [[ "$2" != 1 ]]; then Title "STOP"; fi
docker-compose stop $1
}
#===========================================================================================================================================
#== UPSERVICE ==============================================================================================================================
#===========================================================================================================================================
#1 = service to up
wait_for_container() {
container_id="nine-$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
if [[ $2 == "wait" ]]
then
wait_for_container $1
fi
}
function upnineapache {
if [[ $NINEAPACHE_ACTIVATE == 1 && $NINEAPACHE_LOCAL == 1 ]]
then
Title ${NINEAPACHE_SERVICE_NAME^^}
EchoVert "CONTAINER"
upservice ${NINEAPACHE_SERVICE_NAME}
Echo
fi
}
function upmariadb {
if [[ $MARIADB_ACTIVATE == 1 && $MARIADB_LOCAL == 1 ]]
then
Title "MARIADB"
EchoVert "CONTAINER"
upservice $MARIADB_SERVICE_NAME wait
Echo
fi
}
function upredis {
if [[ $REDIS_ACTIVATE == 1 && $REDIS_LOCAL == 1 ]]
then
Title "REDIS"
EchoVert "CONTAINER"
upservice $REDIS_SERVICE_NAME
Echo
fi
}
function upminio {
if [[ $MINIO_ACTIVATE == 1 && $MINIO_LOCAL == 1 ]]
then
Title "MINIO"
EchoVert "CONTAINER"
upservice $MINIO_SERVICE_NAME
Echo
fi
}
function upopenldap {
if [[ $LDAP_ACTIVATE == 1 && $LDAP_LOCAL == 1 ]]
then
Title ${OPENLDAP_SERVICE_NAME^^}
EchoVert "CONTAINER"
mkdir -p ./volume/openldap/data
chmod a+wr ./volume/openldap/data
upservice $OPENLDAP_SERVICE_NAME wait
docker-compose exec $OPENLDAP_SERVICE_NAME /nine/init.sh
Echo
fi
}
function upkeycloak {
if [[ $CAS_ACTIVATE == 1 && $CAS_LOCAL == 1 ]]
then
Title ${KEYCLOAK_SERVICE_NAME^^}
# CREATE BDD
if [[ $MARIADB_ACTIVATE == 1 && $MARIADB_LOCAL == 1 ]]
then
EchoVert "DATABASE"
Echo ${KEYCLOAK_SERVICE_NAME^^}
docker-compose exec $MARIADB_SERVICE_NAME /nine/init.sh $KEYCLOAK_SERVICE_NAME
Echo
fi
EchoVert "CONTAINER"
upservice $KEYCLOAK_SERVICE_NAME
Echo
fi
}
function upninegate {
if [[ $NINEGATE_ACTIVATE == 1 && $NINEGATE_LOCAL == 1 ]]
then
Title ${NINEGATE_SERVICE_NAME^^}
if [[ $MARIADB_ACTIVATE == 1 && $MARIADB_LOCAL == 1 ]]
then
EchoVert "DATABASE"
Echo ${NINEGATE_SERVICE_NAME^^}
docker-compose exec $MARIADB_SERVICE_NAME /nine/init.sh $NINEGATE_SERVICE_NAME
Echo
fi
EchoVert "CONTAINER"
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^^}
if [[ $MARIADB_ACTIVATE == 1 && $MARIADB_LOCAL == 1 ]]
then
EchoVert "DATABASE"
Echo ${NINEBOARD_SERVICE_NAME^^}
docker-compose exec $MARIADB_SERVICE_NAME /nine/init.sh $NINEBOARD_SERVICE_NAME
Echo
fi
EchoVert "CONTAINER"
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^^}
if [[ $MARIADB_ACTIVATE == 1 && $MARIADB_LOCAL == 1 ]]
then
EchoVert "DATABASE"
Echo ${NEXTCLOUD_SERVICE_NAME^^}
Echo
docker-compose exec $MARIADB_SERVICE_NAME /nine/init.sh $NEXTCLOUD_SERVICE_NAME
fi
EchoVert "CONTAINER"
upservice ${NEXTCLOUD_SERVICE_NAME}
Echo
fi
}
function upwordpress {
if [[ $WORDPRESS_ACTIVATE == 1 && $WORDPRESS_LOCAL == 1 ]]
then
Title ${WORDPRESS_SERVICE_NAME^^}
if [[ $MARIADB_ACTIVATE == 1 && $MARIADB_LOCAL == 1 ]]
then
EchoVert "DATABASE"
Echo ${WORDPRESS_SERVICE_NAME^^}
docker-compose exec $MARIADB_SERVICE_NAME /nine/init.sh $WORDPRESS_SERVICE_NAME
Echo
fi
EchoVert "CONTAINER"
upservice ${WORDPRESS_SERVICE_NAME}
Echo
fi
}
function upadminer {
if [[ $ADMINER_ACTIVATE == 1 && $ADMINER_LOCAL == 1 ]]
then
Title ${ADMINER_SERVICE_NAME^^}
EchoVert "CONTAINER"
upservice ${ADMINER_SERVICE_NAME}
Echo
fi
}
function upphpldapadmin {
if [[ $PHPLDAPADMIN_ACTIVATE == 1 && $PHPLDAPADMIN_LOCAL == 1 ]]
then
Title ${PHPLDAPADMIN_SERVICE_NAME^^}
EchoVert "CONTAINER"
upservice ${PHPLDAPADMIN_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
# NINEAPACHE
upnineapache
# MARIADB
upmariadb
# REDIS
upredis
# MINIO
upminio
# OPENLDAP
upopenldap
# KEYCLOAK
upkeycloak
# NINEGATE
upninegate
# NINEBOARD
upnineboard
# NEXTCLOUD
upnextcloud
# WORDPRESS
upwordpress
# ADMINER
upadminer
# PHPLDAPADMIN
upphpldapadmin
else
env ${1}
up${1}
fi
}
#===========================================================================================================================================
#== DESTROY ================================================================================================================================
#===========================================================================================================================================
destroyall(){
Question_ouinon "Souhaitez-vous supprimer l'ensemble des containers : Attention cela supprimera vraiment tout ?"
if [[ "$?" = 0 ]]
then
destroy $NINEAPACHE_SERVICE_NAME 1
destroy $MARIADB_SERVICE_NAME 1
destroy $REDIS_SERVICE_NAME 1
destroy $MINIO_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
fi
}
#===========================================================================================================================================
#== DESTROY ================================================================================================================================
#===========================================================================================================================================
#1 = service to destroy
#2 = ne pas poser de questions
destroy(){
Title "DESTROY "${1^^}
stop $1 1
docker-compose rm -s -v -f "$1"
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
docker-compose exec $MARIADB_SERVICE_NAME /nine/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
docker-compose exec $MARIADB_SERVICE_NAME /nine/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
docker-compose exec $MARIADB_SERVICE_NAME /nine/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
docker-compose exec $MARIADB_SERVICE_NAME /nine/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
docker-compose exec $MARIADB_SERVICE_NAME /nine/delete.sh $WORDPRESS_SERVICE_NAME
sudo rm -rf volume/wordpress/data
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 "nine.sh bash monservice"
else
docker-compose 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 "nine.sh destroy monservice"
else
destroy $2
fi
elif [[ $1 == "logs" ]]
then
docker-compose 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 "nine.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 "nine.sh > UP de l'ensemble des services actifs"
EchoRouge "nine.sh up > UP de l'ensemble des services actifs"
EchoRouge "nine.sh up monservice> UP de monservice"
EchoRouge "nine.sh stop > STOP de l'ensemble des services"
EchoRouge "nine.sh stop monservice> STOP de monservice"
EchoRouge "nine.sh bash monservice> lance un terminel dans le conteneur de monservice"
EchoRouge "nine.sh destroyall> détruit l'ensemble des services avec l'ensemble des BDD et des volumes persistant"
EchoRouge "nine.sh destroy monservice> détruit monservices et si souhaitez sa BDD et ses volumes persistant"
EchoRouge "nine.sh logs > LOGS de l'ensemble des services"
EchoRouge "nine.sh logs monservice > LOGS de monservice"
EchoRouge "nine.sh iswait monservice > monservice est-il en cours de construction"
EchoRouge "nine.sh env monservice > regeneration du fichier d'environnement de monservice"
EchoRouge "nine.sh regen > lance destroyall puis up sur l'ensemble des service"
EchoRouge "nine.sh regen monservice > lance destroy monservice puis up monservice"
fi
echo
echo