From 8653a3b96765a2bd3ec40628478064c97721896d Mon Sep 17 00:00:00 2001 From: Gael Date: Wed, 21 Jun 2023 14:45:47 +0200 Subject: [PATCH] Merge branch 'develop-unpeudeclean' --- bin/.commonFunctions.sh | 61 ++ ...n.bash => .gestContainers-completion.bash} | 8 +- bin/.initAgora-completion.bash | 20 - bin/.initCloud-completion.bash | 20 - bin/.initWP-completion.bash | 20 - bin/.initWiki-completion.bash | 20 - bin/.updateCloud-completion.bash | 21 - bin/cloudOrgas.sh | 163 ----- bin/createUser.sh | 2 +- bin/gestContainers.sh | 639 ++++++++++++++++++ bin/initAgora.sh | 96 --- bin/initCloud.sh | 81 --- bin/initWP.sh | 74 -- bin/initWiki.sh | 118 ---- bin/manageAgora.sh | 180 +++++ bin/manageCloud.sh | 382 +++++++++++ bin/manageWiki.sh | 171 +++++ bin/manageWp.sh | 130 ++++ bin/restartAllCollabora.sh | 24 - bin/sauve_memory.sh | 2 +- bin/stop_start_all_cloud.sh | 23 - bin/updateCloud.sh | 100 --- bin/updateCloudApp.sh | 71 -- bin/updateWP.sh | 47 -- bin/upgradeCloud.sh | 74 -- config/orgaTmpl/app/Dockerfile | 2 +- config/orgaTmpl/docker-compose.yml | 11 + config/orgaTmpl/init-cloud.sh | 71 -- config/orgaTmpl/init-db.sh | 63 ++ config/orgaTmpl/init-matter.sh | 96 --- config/orgaTmpl/init-wiki.sh | 81 --- config/orgaTmpl/init-wp.sh | 64 -- config/orgaTmpl/orga-gen.sh | 22 +- config/orgaTmpl/orga-migrate.sh | 63 -- config/orgaTmpl/reload.sh | 6 +- dockers/cloud/first.sh | 94 +-- dockers/dokuwiki/first.sh | 2 +- dockers/mattermost/first.sh | 22 +- secret.tmpl/SetAllPass.sh | 8 + secret.tmpl/env-dokuwikiServ | 4 + 40 files changed, 1674 insertions(+), 1482 deletions(-) rename bin/{.upgradeCloud-completion.bash => .gestContainers-completion.bash} (52%) delete mode 100644 bin/.initAgora-completion.bash delete mode 100644 bin/.initCloud-completion.bash delete mode 100644 bin/.initWP-completion.bash delete mode 100644 bin/.initWiki-completion.bash delete mode 100755 bin/.updateCloud-completion.bash delete mode 100755 bin/cloudOrgas.sh create mode 100644 bin/gestContainers.sh delete mode 100755 bin/initAgora.sh delete mode 100755 bin/initCloud.sh delete mode 100755 bin/initWP.sh delete mode 100755 bin/initWiki.sh create mode 100755 bin/manageAgora.sh create mode 100755 bin/manageCloud.sh create mode 100755 bin/manageWiki.sh create mode 100755 bin/manageWp.sh delete mode 100755 bin/restartAllCollabora.sh delete mode 100755 bin/stop_start_all_cloud.sh delete mode 100755 bin/updateCloud.sh delete mode 100755 bin/updateCloudApp.sh delete mode 100755 bin/updateWP.sh delete mode 100755 bin/upgradeCloud.sh delete mode 100755 config/orgaTmpl/init-cloud.sh create mode 100755 config/orgaTmpl/init-db.sh delete mode 100755 config/orgaTmpl/init-matter.sh delete mode 100755 config/orgaTmpl/init-wiki.sh delete mode 100755 config/orgaTmpl/init-wp.sh delete mode 100755 config/orgaTmpl/orga-migrate.sh create mode 100644 secret.tmpl/env-dokuwikiServ diff --git a/bin/.commonFunctions.sh b/bin/.commonFunctions.sh index 4c95280..f9a1507 100755 --- a/bin/.commonFunctions.sh +++ b/bin/.commonFunctions.sh @@ -36,6 +36,8 @@ setKazVars () { export DOCK_LIB="/var/lib/docker" export DOCK_VOL="${DOCK_LIB}/volumes" export DOCK_VOL_GAR_ORGA="${DOCK_LIB}/volumes/garradin_assoUsers/_data/" + + export NAS_VOL="/mnt/disk-nas1/docker/volumes/" } ######################################## @@ -197,14 +199,73 @@ serviceOnInOrga () { ######################################## waitUrl () { + # $1 URL to waitfor + # $2 timeout en secondes (optional) + starttime=$(date +%s) if [[ $(curl --connect-timeout 2 -s -D - "$1" -o /dev/null 2>/dev/null | head -n1) != *[23]0[0-9]* ]]; then printKazMsg "service not available ($1). Please wait..." echo curl --connect-timeout 2 -s -D - "$1" -o /dev/null \| head -n1 while [[ $(curl --connect-timeout 2 -s -D - "$1" -o /dev/null 2>/dev/null | head -n1) != *[23]0[0-9]* ]] do sleep 5 + if [ $# -gt 1 ]; then + actualtime=$(date +%s) + delta=$(($actualtime-$starttime)) + [[ $2 -lt $delta ]] && return 1 + fi + done + fi + return 0 +} + +######################################## +waitContainerHealthy () { + # $1 ContainerName + # $2 timeout en secondes (optional) + + healthy="false" + starttime=$(date +%s) + running="false" + [[ $(docker ps -f name="$1" | grep -w "$1") ]] && running="true" + [[ $running == "true" && $(docker inspect -f {{.State.Health.Status}} "$1") == "healthy" ]] && healthy="true" + if [[ ! $running == "true" || ! $healthy == "true" ]]; then + printKazMsg "Docker not healthy ($1). Please wait..." + while [[ ! $running == "true" || ! $healthy == "true" ]] + do + sleep 5 + if [ $# -gt 1 ]; then + actualtime=$(date +%s) + delta=$(($actualtime-$starttime)) + [[ $2 -lt $delta ]] && printKazMsg "Docker not healthy ($1)... abort..." && return 1 + fi + [[ ! $running == "true" ]] && [[ $(docker ps -f name="$1" | grep -w "$1") ]] && running="true" + [[ $running == "true" && $(docker inspect -f {{.State.Health.Status}} "$1") == "healthy" ]] && healthy="true" + done + fi + return 0 +} +######################################## +waitContainerRunning () { + # $1 ContainerName + # $2 timeout en secondes (optional) + + starttime=$(date +%s) + running="false" + [[ $(docker ps -f name="$1" | grep -w "$1") ]] && running="true" + if [[ ! $running == "true" ]]; then + printKazMsg "Docker not running ($1). Please wait..." + while [[ ! $running == "true" ]] + do + sleep 5 + if [ $# -gt 1 ]; then + actualtime=$(date +%s) + delta=$(($actualtime-$starttime)) + [[ $2 -lt $delta ]] && printKazMsg "Docker did not start ($1)... abort..." && return 1 + fi + [[ ! $running == "true" ]] && [[ $(docker ps -f name="$1" | grep -w "$1") ]] && running="true" done fi + return 0 } ######################################## diff --git a/bin/.upgradeCloud-completion.bash b/bin/.gestContainers-completion.bash similarity index 52% rename from bin/.upgradeCloud-completion.bash rename to bin/.gestContainers-completion.bash index 0fb3e20..03b279f 100644 --- a/bin/.upgradeCloud-completion.bash +++ b/bin/.gestContainers-completion.bash @@ -1,6 +1,6 @@ #/usr/bin/env bash -_upgradeCloud_completion () { +_gestContainers_completion () { KAZ_ROOT=$(cd "$(dirname ${COMP_WORDS[0]})"/..; pwd) COMPREPLY=() . "${KAZ_ROOT}/bin/.commonFunctions.sh" @@ -8,15 +8,15 @@ _upgradeCloud_completion () { local cword=${COMP_CWORD} cur=${COMP_WORDS[COMP_CWORD]} case "$cur" in -*) - local proposal="-all -n" + local proposal="-h --help -n --simu -q --quiet -m --main -M --nas --local -v --version -l --list -cloud -agora -wp -wiki -office -I --install -r -t -exec --optim -occ -u -i -a -U--upgrade -p --post -mmctl" COMPREPLY=( $(compgen -W "${proposal}" -- "${cur}" ) ) ;; *) # orga name - local available_orga=$(ls -d /var/lib/docker/volumes/orga*-cloudMain 2>/dev/null | sed "s%.*/orga_\\(.*\\)-cloudMain%\\1%" | sort -u) + local available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "service" "enable" 2>/dev/null) COMPREPLY=($(compgen -W "${available_orga}" -- "${cur}")) ;; esac return 0 } -complete -F _upgradeCloud_completion upgradeCloud.sh +complete -F _gestContainers_completion gestContainers.sh diff --git a/bin/.initAgora-completion.bash b/bin/.initAgora-completion.bash deleted file mode 100644 index 663604a..0000000 --- a/bin/.initAgora-completion.bash +++ /dev/null @@ -1,20 +0,0 @@ -#/usr/bin/env bash - -_initAgora_completion () { - KAZ_ROOT=$(cd "$(dirname ${COMP_WORDS[0]})"/..; pwd) - COMPREPLY=() - . "${KAZ_ROOT}/bin/.commonFunctions.sh" - setKazVars - local cword=${COMP_CWORD} cur=${COMP_WORDS[COMP_CWORD]} - case "${cword}" in - 1) - # orga name - local available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "service" "agora" 2>/dev/null) - COMPREPLY=($(compgen -W "${available_orga}" -- "${cur}")) - ;; - *) - ;; - esac - return 0 -} -complete -F _initAgora_completion initAgora.sh diff --git a/bin/.initCloud-completion.bash b/bin/.initCloud-completion.bash deleted file mode 100644 index a3520f3..0000000 --- a/bin/.initCloud-completion.bash +++ /dev/null @@ -1,20 +0,0 @@ -#/usr/bin/env bash - -_initCloud_completion () { - KAZ_ROOT=$(cd "$(dirname ${COMP_WORDS[0]})"/..; pwd) - COMPREPLY=() - . "${KAZ_ROOT}/bin/.commonFunctions.sh" - setKazVars - local cword=${COMP_CWORD} cur=${COMP_WORDS[COMP_CWORD]} - case "${cword}" in - 1) - # orga name - local available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "service" "cloud" 2>/dev/null) - COMPREPLY=($(compgen -W "${available_orga}" -- "${cur}")) - ;; - *) - ;; - esac - return 0 -} -complete -F _initCloud_completion initCloud.sh diff --git a/bin/.initWP-completion.bash b/bin/.initWP-completion.bash deleted file mode 100644 index 73c645f..0000000 --- a/bin/.initWP-completion.bash +++ /dev/null @@ -1,20 +0,0 @@ -#/usr/bin/env bash - -_initWP_completion () { - KAZ_ROOT=$(cd "$(dirname ${COMP_WORDS[0]})"/..; pwd) - COMPREPLY=() - . "${KAZ_ROOT}/bin/.commonFunctions.sh" - setKazVars - local cword=${COMP_CWORD} cur=${COMP_WORDS[COMP_CWORD]} - case "${cword}" in - 1) - # orga name - local available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "service" "wp" 2>/dev/null) - COMPREPLY=($(compgen -W "${available_orga}" -- "${cur}")) - ;; - *) - ;; - esac - return 0 -} -complete -F _initWP_completion initWP.sh diff --git a/bin/.initWiki-completion.bash b/bin/.initWiki-completion.bash deleted file mode 100644 index 1c66191..0000000 --- a/bin/.initWiki-completion.bash +++ /dev/null @@ -1,20 +0,0 @@ -#/usr/bin/env bash - -_initWiki_completion () { - KAZ_ROOT=$(cd "$(dirname ${COMP_WORDS[0]})"/..; pwd) - COMPREPLY=() - . "${KAZ_ROOT}/bin/.commonFunctions.sh" - setKazVars - local cword=${COMP_CWORD} cur=${COMP_WORDS[COMP_CWORD]} - case "${cword}" in - 1) - # orga name - local available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "service" "wiki" 2>/dev/null) - COMPREPLY=($(compgen -W "${available_orga}" -- "${cur}")) - ;; - *) - ;; - esac - return 0 -} -complete -F _initWiki_completion initWiki.sh diff --git a/bin/.updateCloud-completion.bash b/bin/.updateCloud-completion.bash deleted file mode 100755 index d380655..0000000 --- a/bin/.updateCloud-completion.bash +++ /dev/null @@ -1,21 +0,0 @@ -#/usr/bin/env bash - -_updateCloud_completion () { - KAZ_ROOT=$(cd "$(dirname ${COMP_WORDS[0]})"/..; pwd) - COMPREPLY=() - . "${KAZ_ROOT}/bin/.commonFunctions.sh" - setKazVars - local cword=${COMP_CWORD} cur=${COMP_WORDS[COMP_CWORD]} - case "${cword}" in - 1) - # orga name - #local available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "compose" "enable" "orga" 2>/dev/null) - local available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "service" "cloud" 2>/dev/null) - COMPREPLY=($(compgen -W "${available_orga}" -- "${cur}")) - ;; - *) - ;; - esac - return 0 -} -complete -F _updateCloud_completion updateCloud.sh diff --git a/bin/cloudOrgas.sh b/bin/cloudOrgas.sh deleted file mode 100755 index 192030c..0000000 --- a/bin/cloudOrgas.sh +++ /dev/null @@ -1,163 +0,0 @@ -#!/bin/bash -# Script de relance des dockers Nextcloud des Orgas -# Permet de lancer la commande d' optimisation des clouds -# Permet de connaitre la version des clouds -# Permet de relancer les dockers en mode a chaud ou à froid ( docker restart ou docker-compose down et up) -# lancer le script san arguments pour optenir de l' aide -# -KAZ_ROOT=$(cd "$(dirname $0)"/..; pwd) -. $KAZ_ROOT/bin/.commonFunctions.sh -setKazVars -. $DOCKERS_ENV -. $KAZ_ROOT/secret/SetAllPass.sh - -PRG=$(basename $0) -RACINE=$(echo $PRG | awk '{print $1}') - -TEMPO_ACTION_STOP=2 -TEMPO_ACTION_START=120 -LIST_CLOUDS=$(ls /var/lib/docker/volumes/ | grep -i orga | grep -i cloudMain| sed -e 's/-cloudMain$//g' | sed -e 's/^orga_//') -NB_CLOUDS=$(ls /var/lib/docker/volumes/ | grep -i orga | grep -i cloudMain| sed -e 's/-cloudMain$//g' | sed -e 's/^orga_//' | wc -l ) -COMPTEUR=$NB_CLOUDS - -# On ne met pas le -ti dans la ligne avec docker exec pour l'update -# Ceci afin de permettre son lancement en cron -UpdateApplis() { - echo -e "${NC}" - echo "Mise à jour de toutes les applis installées y compris le cloud Principal" - for CLOUD in ${LIST_CLOUDS} - do - echo -e "${GREEN}${COMPTEUR}/${NB_CLOUDS} : ${CLOUD} " - echo -e "${NC}" - docker exec -u 33 ${CLOUD}-nextcloudServ /var/www/html/occ app:update --all - COMPTEUR=$(expr $COMPTEUR - 1) - done - echo -e "${GREEN} Mise à jour des applis du cloud principal " - echo -e "${NC}" - docker exec -u 33 nextcloudServ /var/www/html/occ app:update --all -} - - -Optimise_Cloud() { - echo "--------------------------------------------------------" - echo "${NC}Optimisation des cloud" - echo "--------------------------------------------------------" - for CLOUD in ${LIST_CLOUDS} - do - echo -e "$RED${CLOUD} (${COMPTEUR}/${NB_CLOUDS}) " - echo -e "$GREEN execution de :occ db:add-missing-indices" - docker exec -ti -u 33 ${CLOUD}-nextcloudServ /var/www/html/occ db:add-missing-indices - docker exec -ti -u 33 ${CLOUD}-nextcloudServ /var/www/html/occ db:convert-filecache-bigint --no-interaction - COMPTEUR=$(expr ${COMPTEUR} - 1) - done - echo "${NC}" -} - - -restart-compose() { - echo "--------------------------------------------------------" - echo "${NC} Arret / Relance de ${NB_CLOUDS} orga(s)" - echo "--------------------------------------------------------" - for CLOUD in ${LIST_CLOUDS} - do - echo "${RED}- ${CLOUD}-orga${NC}($COMPTEUR/$NB_CLOUDS)" - cd /kaz/dockers/$CLOUD-orga - echo -n "${NC}Arrêt ... " - docker-compose stop cloud - sleep ${TEMPO_ACTION_STOP} - echo "${GREEN}OK" - echo -n "${NC}Démarrage ... " - docker-compose up -d cloud - echo "${GREEN}OK" - COMPTEUR=$(expr $COMPTEUR - 1) - done - sleep ${TEMPO_ACTION_START} - reloadProxy - echo "${NC}" - echo "--------------------------------------------------------" - echo "${GREEN}FIN${NC} " - echo "--------------------------------------------------------" -} - -restart() { - echo "--------------------------------------------------------" - echo "${NC} Arret / Relance de ${NB_CLOUDS} orga(s)" - echo "--------------------------------------------------------" - for CLOUD in ${LIST_CLOUDS} - do - echo "${RED} ${CLOUD}-orga ${NC}($COMPTEUR/$NB_CLOUDS)" - echo -n "${NC}Redemarrage ... " - docker restart $CLOUD-nextcloudServ - echo "${GREEN}OK" - COMPTEUR=$(expr $COMPTEUR - 1) - done - reloadProxy - echo "${NC}" - echo "--------------------------------------------------------" - echo "${GREEN}FIN${NC} " - echo "--------------------------------------------------------" -} - -reloadProxy() { - echo "${NC}" - availableProxyComposes=($(getList "${KAZ_CONF_DIR}/container-proxy.list")) - - for item in "${availableProxyComposes[@]}"; do - ${KAZ_COMP_DIR}/${item}/reload.sh - done -} - - -version() { - for CLOUD in ${LIST_CLOUDS} - do - VERSION_CLOUD=$(docker exec -ti -u 33 ${CLOUD}-nextcloudServ /var/www/html/occ status | grep -i version:) - VERSION_UPDATE=$(docker exec -ti -u 33 ${CLOUD}-nextcloudServ /var/www/html/occ update:check | grep -i "available\." | cut -c 1-17) - echo -e "-($COMPTEUR/$NB_CLOUDS): ${CLOUD}-orga ${GREEN}${VERSION_CLOUD}${NC} " - if [ ! -z "${VERSION_UPDATE}" ] - then - echo -e "\t -Version disponible : ${RED} ${VERSION_UPDATE} ${NC}" - fi - COMPTEUR=$(expr $COMPTEUR - 1) - done -} - -usage() { -echo "${PRG} -v -r -t -h -quand : - -v Donne la version des clouds et signale les MàJ - -o Lance la procédure Nextcloud pour optimiser les performances - -u Mets à jour les apllis des clouds - -t Dans le cas d' une mise à jour , redémarre avec tempo tous les dockers des orga ( docker-compose ) - -r Redémarre tous les dockers des orga ( docker restart ) - -h Cette aide :-)" -} - -########## Main ################# -[ -z "$1" ] && { usage;exit; } -case "$1" in - '-o' ) - Optimise_Cloud - exit - ;; - '-v' ) - version - exit - ;; - '-t' ) - restart-compose - exit - ;; - '-u' ) - UpdateApplis - exit - ;; - '-r' ) - restart - exit - ;; - '-h' ) - usage - ;; -esac - diff --git a/bin/createUser.sh b/bin/createUser.sh index 26cb551..f00d9fd 100755 --- a/bin/createUser.sh +++ b/bin/createUser.sh @@ -415,7 +415,7 @@ userPassword: {CRYPT}${pass}\n\n' | ldapmodify -c -H ldap://${LDAP_IP} -D \"cn=$ if [ "${nb}" == "0" ];then echo " * +cloud +collabora ${ORGA}" CREATE_ORGA_SERVICES="${CREATE_ORGA_SERVICES} +cloud +collabora" - # installe les plugins initiaux dans "config/orgaTmpl/init-cloud.sh" + # installe les plugins initiaux dans "/kaz/bin/gestClouds.sh" fi NB_SERVICES_DEDIES=$((NB_SERVICES_DEDIES+1)) diff --git a/bin/gestContainers.sh b/bin/gestContainers.sh new file mode 100644 index 0000000..467d48c --- /dev/null +++ b/bin/gestContainers.sh @@ -0,0 +1,639 @@ +#!/bin/bash +# Script de manipulation des containers en masse +# init /versions / restart ... +# + +KAZ_ROOT=$(cd "$(dirname $0)"/..; pwd) +. $KAZ_ROOT/bin/.commonFunctions.sh +setKazVars +. $DOCKERS_ENV +. $KAZ_ROOT/secret/SetAllPass.sh + +PRG=$(basename $0) + +#GLOBAL VARS +NAS_VOL="/mnt/disk-nas1/docker/volumes/" + +availableOrga=($(getList "${KAZ_CONF_DIR}/container-orga.list")) +AVAILABLE_ORGAS=${availableOrga[*]//-orga/} + +availableContainersCommuns=( $(getList "${KAZ_CONF_DIR}/container-withMail.list") $(getList "${KAZ_CONF_DIR}/container-withoutMail.list")) + +OPERATE_ON_MAIN= # par defaut NON on ne traite que des orgas +OPERATE_ON_NAS_ORGA="OUI" # par defaut oui, on va aussi sur les orgas du NAS +OPERATE_LOCAL_ORGA="OUI" # par defaut oui + +TEMPO_ACTION_STOP=2 # Lors de redémarrage avec tempo, on attend après le stop +TEMPO_ACTION_START=120 # Lors de redémarrage avec tempo, avant de reload le proxy + +CONTAINERS_TYPES= + +defaultContainersTypes="cloud agora wp wiki office" # les containers gérés par ce script. + +declare -A DockerServNames # le nom des containers correspondant +DockerServNames=( [cloud]="${nextcloudServName}" [agora]="${mattermostServName}" [wiki]="${dokuwikiServName}" [wp]="${wordpressServName}" [office]="${officeServName}") + +declare -A FilterLsVolume # Pour trouver quel volume appartient à quel container +FilterLsVolume=( [cloud]="cloudMain" [agora]="matterConfig" [wiki]="wikiConf" [wp]="wordpress" ) + +declare -A composeDirs # Le nom du repertoire compose pour le commun +composeDirs=( [cloud]="cloud" [agora]="mattermost" [wiki]="dokuwiki" [office]="collabora") + +declare -A serviceNames # Le nom du du service dans le dockerfile d'orga +serviceNames=( [cloud]="cloud" [agora]="agora" [wiki]="dokuwiki" [wp]="wordpress" [office]="collabora") + +declare -A subScripts +subScripts=( [cloud]="manageCloud.sh" [agora]="manageAgora.sh" [wiki]="manageWiki.sh" [wp]="manageWp.sh" ) + +declare -A OrgasOnNAS +declare -A OrgasLocales +declare -A NbOrgas +declare -A RunningOrgas +declare -A Posts + +QUIET="1" # redirection des echo + +OCCCOMANDS=() +MMCTLCOMANDS=() +EXECCOMANDS=() + +# CLOUD +APPLIS_PAR_DEFAUT="tasks calendar contacts bookmarks mail richdocuments external drawio snappymail ransomware_protection" #rainloop richdocumentscode + + +usage() { +echo "${PRG} [OPTION] [CONTAINERS_TYPES] [COMMANDES] [ORGAS] +Ce script regroupe l'ensemble des opérations que l'on souhaite automatiser sur plusieurs containers +Par defaut, sur les orgas, mais on peut aussi ajouter les communs + +OPTIONS + -h|--help Cette aide :-) + -n|--simu SIMULATION + -q|--quiet On ne parle pas (utile avec le -n pour avoir que les commandes) + -m|--main Traite aussi le container commun (cloud commun / agora commun / wiki commun) + -M Ne traite que le container commun, et pas les orgas + --nas Ne traite QUE les orgas sur le NAS + --local Ne traite pas les orgas sur le NAS + -v|--version Donne la version des containers et signale les MàJ + -l|--list Liste des containers (up / down, local ou nas) de cette machine + +CONTAINERS_TYPES + -cloud Pour agir sur les clouds + -agora Pour agir sur les agoras + -wp Les wp + -wiki Les wiki + -office Les collabora + +COMMANDES (on peut en mettre plusieurs dans l'ordre souhaité) + -I|--install L'initialisation du container + -t Redémarre avec tempo (docker-compose down puis sleep ${TEMPO_ACTION_STOP} puis up puis sleep ${TEMPO_ACTION_START}) + -r Redémarre sans tempo (docker restart) + -exec \"command\" Envoie une commande docker exec + + --optim Lance la procédure Nextcloud pour optimiser les performances ** ** + -occ \"command\" Envoie une commande via occ ** ** + -u Mets à jour les applis ** SPECIFIQUES ** + -i Install des applis ** CLOUD ** + -a \"app1 app2 ...\" Choix des appli à installer ou mettre à jour (entre guillemets) ** ** + -U|--upgrade Upgrade des clouds ** ** + + -mmctl \"command\" Envoie une commande via mmctl ** SPECIFIQUES ** + -p|--post \"team\" \"message\" Poste un message dans une team agora ** AGORA ** + +ORGAS + [orga1 orga2 ... ] on peut filtrer parmi : ${AVAILABLE_ORGAS} + + +Exemples : +${PRG} -office -m -r restart de tous les collaboras (libére RAM) +${PRG} -cloud -u -r -q -n Affiche toutes les commandes (-n -q ) pour mettre à jour toutes les applis des clouds + restart (-u -r) +${PRG} -p \"monorga:town-square\" \"Hello\" monorga # envoie Hello sur le centreville de l'orga monorga sur son mattermost dédié + +" +} + + +#################################################### +################ fonctions clefs ################### +#################################################### + +_populate_lists(){ + # récupère les listes d'orga à traiter + # on rempli les tableaux OrgasOnNAS / OrgasLocales / NbOrgas ... par type de container + + if [ -z "${CONTAINERS_TYPES}" ]; then + # wow, on traite tout le monde d'un coup... + CONTAINERS_TYPES="$defaultContainersTypes" + fi + + for TYPE in ${CONTAINERS_TYPES}; do + if [ -n "${FilterLsVolume[$TYPE]}" ] ; then # on regarde dans les volumes + [ -n "$OPERATE_ON_NAS_ORGA" ] && OrgasOnNAS["$TYPE"]=$( _getListOrgas ${NAS_VOL} ${FilterLsVolume[$TYPE]} ) + [ -n "$OPERATE_LOCAL_ORGA" ] && OrgasLocales["$TYPE"]=$( _getListOrgas ${DOCK_VOL} ${FilterLsVolume[$TYPE]} "SANSLN") + else # un docker ps s'il n'y a pas de volumes + [ -n "$OPERATE_LOCAL_ORGA" ] && OrgasLocales["$TYPE"]=$(docker ps --format '{{.Names}}' | grep ${DockerServNames[$TYPE]} | sed -e "s/-*${DockerServNames[$TYPE]}//") + fi + NbOrgas["$TYPE"]=$(($(echo ${OrgasOnNAS["$TYPE"]} | wc -w) + $(echo ${OrgasLocales["$TYPE"]} | wc -w))) + RunningOrgas["$TYPE"]=$(docker ps --format '{{.Names}}' | grep ${DockerServNames[$TYPE]} | sed -e "s/-*${DockerServNames[$TYPE]}//") + done +} + +_getListOrgas(){ + # retrouve les orgas à partir des volume présents + # $1 where to lookup + # $2 filter + # $3 removeSymbolicLinks + [ ! -d $1 ] || [ -z "$2" ] && return 1 # si le repertoire n'existe pas on skip + LIST=$(ls "${1}" | grep -i orga | grep -i "$2" | sed -e "s/-${2}$//g" | sed -e 's/^orga_//') + [ -n "$3" ] && LIST=$(ls -F "${1}" | grep '/' | grep -i orga | grep -i "$2" | sed -e "s/-${2}\/$//g" | sed -e 's/^orga_//') + LIST=$(comm -12 <(printf '%s\n' ${LIST} | sort) <(printf '%s\n' ${AVAILABLE_ORGAS} | sort)) + echo "$LIST" +} + +_executeFunctionForAll(){ + # Parcours des container et lancement des commandes + # Les commandes ont en derniers paramètres le type et l'orga et une string parmi KAZ/ORGANAS/ORGALOCAL pour savoir sur quoi on opère + # $1 function + # $2 nom de la commande + # $3 quel types de containers + # $4 params : quels paramètres à passer à la commande (les clefs sont #ORGA# #DOCKERSERVNAME# #SURNAS# #ISMAIN# #TYPE# #COMPOSEDIR# ) + for TYPE in ${3}; do + if [ -n "$OPERATE_ON_MAIN" ]; then + if [[ -n "${composeDirs[$TYPE]}" && "${availableContainersCommuns[*]}" =~ "${composeDirs[$TYPE]}" ]]; then # pas de cloud / agora / wp / wiki sur cette instance + Dockername=${DockerServNames[$TYPE]} + PARAMS=$(echo $4 | sed -e "s/#ORGA#//g;s/#DOCKERSERVNAME#/$Dockername/g;s/#ISMAIN#/OUI/g;s/#SURNAS#/NON/g;s/#TYPE#/$TYPE/g;s%#COMPOSEDIR#%${KAZ_COMP_DIR}/${composeDirs[$TYPE]}%g" ) + echo "-------- $2 $TYPE COMMUN ----------------------------" >& $QUIET + eval "$1" $PARAMS + fi + fi + if [[ ${NbOrgas[$TYPE]} -gt 0 ]]; then + echo "-------- $2 des $TYPE des ORGAS ----------------------------" >& $QUIET + COMPTEUR=1 + if [ -n "$OPERATE_LOCAL_ORGA" ]; then + for ORGA in ${OrgasLocales[$TYPE]}; do + Dockername=${ORGA}-${DockerServNames[$TYPE]} + PARAMS=$(echo $4 | sed -e "s/#ORGA#/${ORGA}/g;s/#DOCKERSERVNAME#/$Dockername/g;s/#ISMAIN#/NON/g;s/#SURNAS#/NON/g;s/#TYPE#/$TYPE/g;s%#COMPOSEDIR#%${KAZ_COMP_DIR}/${ORGA}-orga%g" ) + echo "${RED} ${ORGA}-orga ${NC}($COMPTEUR/${NbOrgas[$TYPE]})" >& $QUIET + eval "$1" $PARAMS + COMPTEUR=$((COMPTEUR + 1)) + done + fi + if [ -n "$OPERATE_ON_NAS_ORGA" ]; then + for ORGA in ${OrgasOnNAS[$TYPE]}; do + Dockername=${ORGA}-${DockerServNames[$TYPE]} + PARAMS=$(echo $4 | sed -e "s/#ORGA#/${ORGA}/g;s/#DOCKERSERVNAME#/$Dockername/g;s/#ISMAIN#/NON/g;s/#SURNAS#/OUI/g;s/#TYPE#/$TYPE/g;s%#COMPOSEDIR#%${KAZ_COMP_DIR}/${ORGA}-orga%g" ) + echo "${RED} ${ORGA}-orga ${NC}($COMPTEUR/${NbOrgas[$TYPE]})" >& $QUIET + eval "$1" $PARAMS + COMPTEUR=$((COMPTEUR + 1)) + done + fi + fi + done +} + + +############################################## +################ COMMANDES ################### +############################################## +Init(){ + # Initialisation des containers + echo "${NC}--------------------------------------------------------" >& $QUIET + echo "Initialisation" >& $QUIET + echo "--------------------------------------------------------" >& $QUIET + + _executeFunctionForAll "_initContainer" "Initialisation" "${CONTAINERS_TYPES[@]}" "#TYPE# #ISMAIN# #SURNAS# #ORGA# " +} + +restart-compose() { + # Parcours les containers et redémarre avec tempo + echo "${NC}--------------------------------------------------------" >& $QUIET + echo "DOCKER-COMPOSE DOWN puis sleep ${TEMPO_ACTION_STOP}" >& $QUIET + echo "DOCKER-COMPOSE UP puis sleep ${TEMPO_ACTION_START}" >& $QUIET + echo "de ${CONTAINERS_TYPES} pour $NB_ORGAS_STR" >& $QUIET + echo "--------------------------------------------------------" >& $QUIET + + _executeFunctionForAll "_restartContainerAvecTempo" "Restart" "${CONTAINERS_TYPES[@]}" "#TYPE# #ISMAIN# #COMPOSEDIR#" + + ${SIMU} sleep ${TEMPO_ACTION_START} + _reloadProxy + echo "--------------------------------------------------------" >& $QUIET + echo "${GREEN}FIN${NC} " >& $QUIET + echo "--------------------------------------------------------" >& $QUIET +} + +restart() { + # Parcours les containers et redémarre + echo "${NC}--------------------------------------------------------" >& $QUIET + echo "DOCKER RESTART des ${CONTAINERS_TYPES} pour $NB_ORGAS_STR" >& $QUIET + echo "--------------------------------------------------------" >& $QUIET + + _executeFunctionForAll "_restartContainer" "Restart" "${CONTAINERS_TYPES[@]}" "#DOCKERSERVNAME#" + + _reloadProxy + echo "--------------------------------------------------------" >& $QUIET + echo "${GREEN}FIN${NC} " >& $QUIET + echo "--------------------------------------------------------" >& $QUIET +} + +version(){ + # Parcours les containers et affiche leurs versions + echo "${NC}--------------------------------------------------------" >& $QUIET + echo "VERSIONS" >& $QUIET + echo "--------------------------------------------------------" >& $QUIET + _executeFunctionForAll "_versionContainer" "Version" "${CONTAINERS_TYPES[@]}" "#TYPE# #ISMAIN# #ORGA#" +} + + +listContainers(){ + echo "${NC}--------------------------------------------------------" + echo "LISTES" + echo "------------------------------------------------------------" + for TYPE in ${CONTAINERS_TYPES}; do + echo "****************** $TYPE ****************" + _listContainer "$TYPE" + done +} + + + +######################## Fonctions génériques ####################### + +_initContainer(){ + # $1 type + # $2 COMMUN + # $3 ON NAS + # $4 orgas + if [ -n "${subScripts[$1]}" ] ; then + evalStr="${KAZ_BIN_DIR}/${subScripts[$1]} --install" + if [ "$3" = "OUI" ]; then evalStr="${evalStr} -nas" ; fi + if [ ! "$QUIET" = "1" ]; then evalStr="${evalStr} -q" ; fi + if [ -n "$SIMU" ]; then evalStr="${evalStr} -n" ; fi + if [ ! "$2" = "OUI" ]; then evalStr="${evalStr} $4" ; fi + eval $evalStr + fi +} + +_restartContainer(){ + # $1 Dockername + echo -n "${NC}Redemarrage ... " >& $QUIET + ${SIMU} + ${SIMU} docker restart $1 + echo "${GREEN}OK${NC}" >& $QUIET +} + +_restartContainerAvecTempo(){ + # $1 type + # $2 main container + # $2 composeDir + dir=$3 + if [ -z $dir ]; then return 1; fi # le compose n'existe pas ... par exemple wordpress commun + cd "$dir" + echo -n "${NC}Arrêt ... " >& $QUIET + ${SIMU} + if [ "$2" = "OUI" ]; then ${SIMU} docker-compose stop ; + else ${SIMU} docker-compose stop "${serviceNames[$1]}" + fi + ${SIMU} sleep ${TEMPO_ACTION_STOP} + echo "${GREEN}OK${NC}" >& $QUIET + echo -n "${NC}Démarrage ... " >& $QUIET + if [ "$2" = "OUI" ]; then ${SIMU} docker-compose up -d ; + else ${SIMU} docker-compose up -d "${serviceNames[$1]}" + fi + #${SIMU} sleep ${TEMPO_ACTION_START} + echo "${GREEN}OK${NC}" >& $QUIET +} + + +_reloadProxy() { + availableProxyComposes=($(getList "${KAZ_CONF_DIR}/container-proxy.list")) + + for item in "${availableProxyComposes[@]}"; do + ${SIMU} ${KAZ_COMP_DIR}/${item}/reload.sh + done +} + +_versionContainer() { + # Affiche la version d'un container donné + # $1 type + # $2 COMMUN + # $3 orgas + if [ -n "${subScripts[$1]}" ] ; then + evalStr="${KAZ_BIN_DIR}/${subScripts[$1]} --version" + if [ ! "$2" = "OUI" ]; then evalStr="${evalStr} $3" ; fi + eval $evalStr + fi +} + + +_listContainer(){ + # pour un type donné (cloud / agora / wiki / wp), fait une synthèse de qui est up et down / nas ou local + # $1 type + RUNNING_FROM_NAS=$(comm -12 <(printf '%s\n' ${OrgasOnNAS[$1]} | sort) <(printf '%s\n' ${RunningOrgas[$1]} | sort) | sed -e ':a;N;$!ba;s/\n/ /g') + RUNNING_LOCAL=$(comm -12 <(printf '%s\n' ${OrgasLocales[$1]} | sort) <(printf '%s\n' ${RunningOrgas[$1]} | sort) | sed -e ':a;N;$!ba;s/\n/ /g') + # tu l'a vu la belle commande pour faire une exclusion de liste + DOWN_ON_NAS=$(comm -23 <(printf '%s\n' ${OrgasOnNAS[$1]} | sort) <(printf '%s\n' ${RunningOrgas[$1]} | sort) | sed -e ':a;N;$!ba;s/\n/ /g') + DOWN_LOCAL=$(comm -23 <(printf '%s\n' ${OrgasLocales[$1]} | sort) <(printf '%s\n' ${RunningOrgas[$1]} | sort)| sed -e ':a;N;$!ba;s/\n/ /g') + NB_SUR_NAS=$(echo ${OrgasOnNAS[$1]} | wc -w) + NB_LOCAUX=$(echo ${OrgasLocales[$1]} | wc -w) + NB_RUNNING_SUR_NAS=$(echo $RUNNING_FROM_NAS | wc -w) + NB_RUNNING_LOCALLY=$(echo $RUNNING_LOCAL | wc -w) + MAIN_RUNNING="${RED}DOWN${NC}" + if docker ps | grep -q " ${DockerServNames[$1]}" + then + MAIN_RUNNING="${GREEN}UP${NC}" + fi + + [ -n "${composeDirs[${1}]}" ] && echo "${NC}Le ${1} commun est $MAIN_RUNNING" + if [[ ${NbOrgas[$1]} -gt 0 ]]; then + ENLOCALSTR= + if [[ ${NB_RUNNING_SUR_NAS[$1]} -gt 0 ]]; then ENLOCALSTR=" en local" ; fi + echo "Orgas : $NB_RUNNING_LOCALLY / $NB_LOCAUX running ${1}$ENLOCALSTR" + echo "${NC}UP : ${GREEN}${RUNNING_LOCAL}" + echo "${NC}DOWN : ${RED}$DOWN_LOCAL${NC}" + if [[ ${NB_RUNNING_SUR_NAS[$1]} -gt 0 ]]; then + echo "${NC}Orgas : $NB_RUNNING_SUR_NAS / $NB_SUR_NAS running depuis le NAS :" + echo "${NC}UP : ${GREEN}${RUNNING_FROM_NAS}" + echo "${NC}DOWN : ${RED}$DOWN_ON_NAS${NC}" + fi + fi +} + + +######################################################### +############# FONCTIONS SPECIFIQUES ##################### +######################################################### + +################################## +############### CLOUD ############ +################################## + +UpgradeClouds() { + echo "${NC}--------------------------------------------------------" >& $QUIET + echo "UPGRADE des cloud" >& $QUIET + echo "--------------------------------------------------------" >& $QUIET + RunOCCCommand "upgrade" +} + +OptimiseClouds() { + echo "${NC}--------------------------------------------------------" >& $QUIET + echo "Optimisation des cloud" >& $QUIET + echo "--------------------------------------------------------" >& $QUIET + RunOCCCommands "db:add-missing-indices" "db:convert-filecache-bigint --no-interaction" +} + +InstallApps(){ + echo "${NC}--------------------------------------------------------" >& $QUIET + echo "INSTALL DES APPLIS sur les clouds : ${LISTE_APPS}" >& $QUIET + echo "-------------------------------------------------------------" >& $QUIET + if [ -z "${LISTE_APPS}" ]; then + echo "Aucune appli n'est précisée, j'installe les applis par défaut : ${APPLIS_PAR_DEFAUT}" >& $QUIET + LISTE_APPS="${APPLIS_PAR_DEFAUT}" + fi + PARAMS="-a \"$LISTE_APPS\"" + if [ ! "$QUIET" = "1" ]; then PARAMS="${PARAMS} -q" ; fi + if [ -n "$SIMU" ]; then PARAMS="${PARAMS} -n" ; fi + _executeFunctionForAll "${KAZ_BIN_DIR}/${subScripts["cloud"]} -i $PARAMS" "Install des applis" "cloud" "#ORGA#" +} + +UpdateApplis() { + echo "${NC}--------------------------------------------------------" >& $QUIET + echo "UPDATE DES APPLIS des cloud : ${LISTE_APPS}" >& $QUIET + echo "--------------------------------------------------------" >& $QUIET + PARAMS="-a ${LISTE_APPS}" + if [ -z "${LISTE_APPS}" ]; then + echo "Aucune appli n'est précisée, je les met toutes à jour! " >& $QUIET + PARAMS= + fi + if [ ! "$QUIET" = "1" ]; then PARAMS="${PARAMS} -q" ; fi + if [ -n "$SIMU" ]; then PARAMS="${PARAMS} -n" ; fi + _executeFunctionForAll "${KAZ_BIN_DIR}/${subScripts["cloud"]} -u $PARAMS" "Maj des applis" "cloud" "#ORGA#" +} + + +################################## +############### AGORA ############ +################################## + + +PostMessages(){ + echo "${NC}--------------------------------------------------------" >& $QUIET + echo "Envoi de messages sur mattermost" >& $QUIET + echo "--------------------------------------------------------" >& $QUIET + + for TEAM in "${!Posts[@]}" + do + MSG=${Posts[$TEAM]/\"/\\\"} + PARAMS="-p \"$TEAM\" \"$MSG\"" + if [ ! "$QUIET" = "1" ]; then PARAMS="${PARAMS} -q" ; fi + if [ -n "$SIMU" ]; then PARAMS="${PARAMS} -n" ; fi + _executeFunctionForAll "${KAZ_BIN_DIR}/${subScripts["agora"]} $PARAMS" "Post vers $TEAM sur l'agora" "agora" "#ORGA#" + done +} + + +########## LANCEMENT COMMANDES OCC / MMCTL ############ + +RunCommands() { + echo "${NC}--------------------------------------------------------" >& $QUIET + echo "Envoi de commandes en direct" >& $QUIET + echo "--------------------------------------------------------" >& $QUIET + # $1 OCC / MMCTL / EXEC + # $ suivants : les commandes + for command in "${@:2}" + do + if [ $1 = "OCC" ]; then RunOCCCommand "$command" ; fi + if [ $1 = "MMCTL" ]; then RunMMCTLCommand "$command" ; fi + if [ $1 = "EXEC" ]; then RunEXECCommand "$command" ; fi + done +} + +_runSingleOccCommand(){ + # $1 Command + # $2 Dockername + ${SIMU} docker exec -u 33 $2 /var/www/html/occ $1 +} + +_runSingleMmctlCommand(){ + # $1 Command + # $2 Dockername + ${SIMU} docker exec $2 bin/mmctl $1 +} + +_runSingleExecCommand(){ + # $1 Command + # $2 Dockername + ${SIMU} docker exec $2 $1 +} + +RunOCCCommand() { + # $1 Command + _executeFunctionForAll "_runSingleOccCommand \"${1}\"" "OCC $1" "cloud" "#DOCKERSERVNAME#" +} + +RunMMCTLCommand() { + # $1 Command + _executeFunctionForAll "_runSingleMmctlCommand \"${1}\"" "MMCTL $1" "agora" "#DOCKERSERVNAME#" +} + +RunEXECCommand() { + # $1 Command + _executeFunctionForAll "_runSingleExecCommand \"${1}\"" "docker exec $1" "${CONTAINERS_TYPES[@]}" "#DOCKERSERVNAME#" +} + + + +########## Main ################# +for ARG in "$@"; do + if [ -n "${GETOCCCOMAND}" ]; then # après un -occ + OCCCOMANDS+=("${ARG}") + GETOCCCOMAND= + elif [ -n "${GETEXECCOMAND}" ]; then # après un -exec + EXECCOMANDS+=("${ARG}") + GETEXECCOMAND= + elif [ -n "${GETAPPS}" ]; then # après un -a + LISTE_APPS="${LISTE_APPS} ${ARG}" + GETAPPS="" + elif [ -n "${GETMMCTLCOMAND}" ]; then # après un -mmctl + MMCTLCOMANDS+=("${ARG}") + GETMMCTLCOMAND= + elif [ -n "${GETTEAM}" ]; then # après un --post + GETMESSAGE="now" + GETTEAM="" + TEAM="${ARG}" + elif [ -n "${GETMESSAGE}" ]; then # après un --post "team:channel" + if [[ $TEAM == "-*" && ${#TEAM} -le 5 ]]; then echo "J'envoie mon message à \"${TEAM}\" ?? Arf, ça me plait pas j'ai l'impression que tu t'es planté sur la commande."; usage ; exit 1 ; fi + if [[ $ARG == "-*" && ${#ARG} -le 5 ]]; then echo "J'envoie le message \"${ARG}\" ?? Arf, ça me plait pas j'ai l'impression que tu t'es planté sur la commande."; usage ; exit 1 ; fi + if [[ ! $TEAM =~ .*:.+ ]]; then echo "Il faut mettre un destinataire sous la forme team:channel. Recommence !"; usage ; exit 1 ; fi + Posts+=( ["${TEAM}"]="$ARG" ) + GETMESSAGE="" + TEAM="" + else + case "${ARG}" in + '-h' | '--help' ) + usage && exit ;; + '-n' | '--simu') + SIMU="echo" ;; + '-q' ) + QUIET="/dev/null" ;; + '-m' | '--main' ) + OPERATE_ON_MAIN="OUI-OUI" ;; + '-M' ) + AVAILABLE_ORGAS= && OPERATE_ON_MAIN="OUI-OUI" ;; #pas d'orgas + '--nas' | '-nas' ) + OPERATE_LOCAL_ORGA= ;; # pas les locales + '--local' | '-local' ) + OPERATE_ON_NAS_ORGA= ;; # pas celles sur NAS + '-cloud'|'--cloud') + CONTAINERS_TYPES="${CONTAINERS_TYPES} cloud" ;; + '-agora'|'--agora') + CONTAINERS_TYPES="${CONTAINERS_TYPES} agora" ;; + '-wiki'|'--wiki') + CONTAINERS_TYPES="${CONTAINERS_TYPES} wiki" ;; + '-wp'|'--wp') + CONTAINERS_TYPES="${CONTAINERS_TYPES} wp" ;; + '-office'|'--office') + CONTAINERS_TYPES="${CONTAINERS_TYPES} office" ;; + '-t' ) + COMMANDS="${COMMANDS} RESTART-COMPOSE" ;; + '-r' ) + COMMANDS="${COMMANDS} RESTART-DOCKER" ;; + '-l' | '--list' ) + COMMANDS="$(echo "${COMMANDS} LIST" | sed "s/\s/\n/g" | sort | uniq)" ;; + '-v' | '--version') + COMMANDS="$(echo "${COMMANDS} VERSION" | sed "s/\s/\n/g" | sort | uniq)" ;; + '-I' | '--install' ) + COMMANDS="$(echo "${COMMANDS} INIT" | sed "s/\s/\n/g" | sort | uniq)" ;; # le sed sort uniq, c'est pour pas l'avoir en double + '-U' | '--upgrade') + COMMANDS="$(echo "${COMMANDS} UPGRADE" | sed "s/\s/\n/g" | sort | uniq)" ;; + '--optim' ) + COMMANDS="$(echo "${COMMANDS} OPTIMISE-CLOUD" | sed "s/\s/\n/g" | sort | uniq)" ;; + '-u' ) + COMMANDS="$(echo "${COMMANDS} UPDATE-CLOUD-APP" | sed "s/\s/\n/g" | sort | uniq)" ;; + '-i' ) + COMMANDS="$(echo "${COMMANDS} INSTALL-CLOUD-APP" | sed "s/\s/\n/g" | sort | uniq)" ;; + '-a' ) + GETAPPS="now" ;; + '-occ' ) + COMMANDS="$(echo "${COMMANDS} RUN-CLOUD-OCC" | sed "s/\s/\n/g" | sort | uniq)" + GETOCCCOMAND="now" ;; + '-mmctl' ) + COMMANDS="$(echo "${COMMANDS} RUN-AGORA-MMCTL" | sed "s/\s/\n/g" | sort | uniq)" + GETMMCTLCOMAND="now" ;; + '-exec' ) + COMMANDS="$(echo "${COMMANDS} RUN-DOCKER-EXEC" | sed "s/\s/\n/g" | sort | uniq)" + GETEXECCOMAND="now" ;; + '-p' | '--post' ) + COMMANDS="$(echo "${COMMANDS} POST-AGORA" | sed "s/\s/\n/g" | sort | uniq)" + GETTEAM="now" ;; + '-*' ) # ignore + ;; + *) + GIVEN_ORGA="${GIVEN_ORGA} ${ARG%-orga}" + ;; + esac + fi +done + + +if [[ "${COMMANDS[*]}" =~ "RESTART-COMPOSE" && "${COMMANDS[*]}" =~ "RESTART-TYPE" ]]; then + echo "Je restarte via docker-compose ou via docker mais pas les deux !" + usage + exit 1 +fi +if [ -z "${COMMANDS}" ]; then + usage && exit +fi +if [ -n "${GIVEN_ORGA}" ]; then + # intersection des 2 listes : quelle commande de ouf !! + AVAILABLE_ORGAS=$(comm -12 <(printf '%s\n' ${AVAILABLE_ORGAS} | sort) <(printf '%s\n' ${GIVEN_ORGA} | sort)) +fi + +NB_ORGAS=$(echo "${AVAILABLE_ORGAS}" | wc -w ) + +if [[ $NB_ORGAS = 0 && -z "${OPERATE_ON_MAIN}" ]]; then + echo "Aucune orga trouvée." + exit 1 +fi + +NB_ORGAS_STR="$NB_ORGAS orgas" +[ -n "${OPERATE_ON_MAIN}" ] && NB_ORGAS_STR="$NB_ORGAS_STR + les communs" + +_populate_lists # on récupère les clouds / agora / wiki / wp correspondants aux orga + +if [[ $NB_ORGAS -gt 2 && "${COMMANDS[*]}" =~ 'INIT' ]]; then + ETLECLOUDCOMMUN= + [ -n "${OPERATE_ON_MAIN}" ] && ETLECLOUDCOMMUN=" ainsi que les containers commun" + echo "On s'apprête à initialiser les ${CONTAINERS_TYPES} suivants : ${AVAILABLE_ORGAS}${ETLECLOUDCOMMUN}" + checkContinue +fi + +for COMMAND in ${COMMANDS}; do + case "${COMMAND}" in + 'LIST' ) + listContainers && exit ;; + 'VERSION' ) + version && exit ;; + 'OPTIMISE-CLOUD' ) + OptimiseClouds ;; + 'RESTART-COMPOSE' ) + restart-compose ;; + 'RESTART-DOCKER' ) + restart ;; + 'UPDATE-CLOUD-APP' ) + UpdateApplis ;; + 'UPGRADE' ) + UpgradeClouds ;; + 'INIT' ) + Init ;; + 'INSTALL-CLOUD-APP' ) + InstallApps ;; + 'RUN-CLOUD-OCC' ) + RunCommands "OCC" "${OCCCOMANDS[@]}" ;; + 'RUN-AGORA-MMCTL' ) + RunCommands "MMCTL" "${MMCTLCOMANDS[@]}" ;; + 'RUN-DOCKER-EXEC' ) + RunCommands "EXEC" "${EXECCOMANDS[@]}" ;; + 'POST-AGORA' ) + PostMessages ${Posts} ;; + esac +done \ No newline at end of file diff --git a/bin/initAgora.sh b/bin/initAgora.sh deleted file mode 100755 index b0ddf6e..0000000 --- a/bin/initAgora.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/bash - -KAZ_ROOT=$(cd $(dirname $0)/..; pwd) -. "${KAZ_ROOT}/bin/.commonFunctions.sh" -setKazVars - -cd $(dirname $0) -. "${DOCKERS_ENV}" - -available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "service" "agora" 2>/dev/null) -usage () { - echo "Usage: $0 orga${NL}" \ - " -h : this help${NL}" \ - " -n : simulation${NL}" \ - " [orga] : in${NL}" \ - " ${CYAN}${available_orga}${NC}${NL}" - exit 1 -} - -SIMU= -for ARG in $*; do - case "$1" in - -h*) usage ;; - -n) SIMU=echo; shift ;; - *) break;; - esac -done - -. ${KAZ_KEY_DIR}/SetAllPass.sh - -case "$#" in - 0) - # shared - ORGA="Kaz" - agoraName="" - - DockerServName="${mattermostServName}" - MATTER_URI="${matterHost}.${domain}" - MATTER_URL="${httpProto}://${MATTER_URI}" - VOL_PREFIX="${DOCK_VOL}/mattermost_" - ;; - 1) - # orga - [[ " ${available_orga} " =~ "$1" ]] || usage - ORGA=${1%-orga} - agoraName="${ORGA}" - - DockerServName="${ORGA}-${mattermostServName}" - MATTER_URI="${ORGA}-${matterHost}.${domain}" - MATTER_URL="${httpProto}://${MATTER_URI}" - VOL_PREFIX="${VOL_DIR}/orga_${ORGA}-" - ;; - *) - usage - ;; -esac - -JSON_CONF="${VOL_PREFIX}matterConfig/_data/config.json" -sed -i \ - -e 's|"SiteURL": ".*"|"SiteURL": "'${MATTER_URL}'"|g' \ - -e 's|"ListenAddress": ".*"|"ListenAddress": ":'${matterPort}'"|g' \ - -e 's|"WebsocketURL": ".*"|"WebsocketURL": "wss://'${MATTER_URI}'"|g' \ - -e 's|"AllowCorsFrom": ".*"|"AllowCorsFrom": "'${domain}' '${MATTER_URI}':443 '${MATTER_URI}'"|g' \ - -e 's|"ConsoleLevel": ".*"|"ConsoleLevel": "ERROR"|g' \ - -e 's|"SendEmailNotifications": false|"SendEmailNotifications": true|g' \ - -e 's|"FeedbackEmail": ".*"|"FeedbackEmail": "admin@'${domain}'"|g' \ - -e 's|"FeedbackOrganization": ".*"|"FeedbackOrganization": "Cochez la KAZ du libre !"|g' \ - -e 's|"ReplyToAddress": ".*"|"ReplyToAddress": "admin@'${domain}'"|g' \ - -e 's|"SMTPServer": ".*"|"SMTPServer": "mail.'${domain}'"|g' \ - -e 's|"SMTPPort": ".*"|"SMTPPort": "25"|g' \ - -e 's|"DefaultServerLocale": ".*"|"DefaultServerLocale": "fr"|g' \ - -e 's|"DefaultClientLocale": ".*"|"DefaultClientLocale": "fr"|g' \ - -e 's|"AvailableLocales": ".*"|"AvailableLocales": "fr"|g' \ - ${JSON_CONF} - -# on redémarre pour prendre en compte (changement de port) -docker restart "${DockerServName}" -#checkDockerRunning "${DockerServName}" "${agoraName}" || exit - -getToken(){ - curl -i -s -d "{\"login_id\":\"${mattermost_MM_ADMIN_USER}\",\"password\":\"${mattermost_MM_ADMIN_PASSWORD}\"}" "${MATTER_URL}/api/v4/users/login" | grep 'token' | sed 's/token:\s*\(.*\)\s*/\1/' | tr -d '\r' -} - -waitUrl "${MATTER_URL}" -[ -z "$(getToken)" ] || exit - -printKazMsg "\n *** Premier lancement de Mattermost" - -curl -i -d "{\"email\":\"${mattermost_MM_ADMIN_EMAIL}\",\"username\":\"${mattermost_MM_ADMIN_USER}\",\"password\":\"${mattermost_MM_ADMIN_PASSWORD}\",\"allow_marketing\":true}" "${MATTER_URL}/api/v4/users" - -waitUrl "${MATTER_URL}" -MM_TOKEN=$(getToken) - -curl -i -H "Authorization: Bearer ${MM_TOKEN}" -d "{\"display_name\":\"${ORGA}\",\"name\":\"${ORGA,,}\",\"type\":\"O\"}" "${MATTER_URL}/api/v4/teams" - - diff --git a/bin/initCloud.sh b/bin/initCloud.sh deleted file mode 100755 index b0e4cc8..0000000 --- a/bin/initCloud.sh +++ /dev/null @@ -1,81 +0,0 @@ -#!/bin/bash - -KAZ_ROOT=$(cd $(dirname $0)/..; pwd) -. "${KAZ_ROOT}/bin/.commonFunctions.sh" -setKazVars - -cd $(dirname $0) -. "${DOCKERS_ENV}" - -available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "service" "cloud" 2>/dev/null) -usage () { - echo "Usage: $0 orga${NL}" \ - " -h : this help${NL}" \ - " -n : simulation${NL}" \ - " [orga] : in${NL}" \ - " ${CYAN}${available_orga}${NC}${NL}" - exit 1 -} - -SIMU= -for ARG in $*; do - case "$1" in - -h*) usage ;; - -n) SIMU=echo; shift ;; - *) break;; - esac -done - -. ${KAZ_KEY_DIR}/SetAllPass.sh - -DNLD_DIR="${KAZ_DNLD_DIR}/dokuwiki" -case "$#" in - 0) - # shared - ORGA="Kaz" - cloudName="" - - CLOUD_URL="${httpProto}://${cloudHost}.${domain}" - DockerServName="${nextcloudServName}" - VOL_PREFIX="${DOCK_VOL}/cloud_" - ;; - 1) - # orga - [[ " ${available_orga} " =~ "$1" ]] || usage - ORGA=${1%-orga} - cloudName="${ORGA}" - - CLOUD_URL="${httpProto}://${ORGA}-${cloudHost}.${domain}" - DockerServName="${ORGA}-${nextcloudServName}" - VOL_PREFIX="${DOCK_VOL}/orga_${ORGA}-" - ;; - *) - usage - ;; -esac - -PHP_CONF="${VOL_PREFIX}cloudConfig/_data/config.php" - -checkDockerRunning "${DockerServName}" "${cloudName}" || exit - -if ! grep -q "'installed' => true," "${CONF_PHP}" 2> /dev/null; then - printKazMsg "\n *** Premier lancement de NextCloud de ${cloudName}" - - waitUrl "${CLOUD_URL}" - - ${SIMU} curl -X POST \ - -d "install=true" \ - -d "adminlogin=${nextcloud_NEXTCLOUD_ADMIN_USER}" \ - -d "adminpass=${nextcloud_NEXTCLOUD_ADMIN_PASSWORD}" \ - -d "directory=/var/www/html/data" \ - -d "dbtype=mysql" \ - -d "dbuser=${nextcloud_MYSQL_USER}" \ - -d "dbpass=${nextcloud_MYSQL_PASSWORD}" \ - -d "dbname=${nextcloud_MYSQL_DATABASE}" \ - -d "dbhost=${nextcloud_MYSQL_HOST}" \ - -d "install-recommended-apps=true" \ - "${CLOUD_URL}" -fi - -${SIMU} "${KAZ_ROOT}/bin/updateCloudConf.sh" $1 -${SIMU} "${KAZ_ROOT}/bin/updateCloudApp.sh" $1 diff --git a/bin/initWP.sh b/bin/initWP.sh deleted file mode 100755 index 3f161f5..0000000 --- a/bin/initWP.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash - -KAZ_ROOT=$(cd $(dirname $0)/..; pwd) -. "${KAZ_ROOT}/bin/.commonFunctions.sh" -setKazVars - -cd $(dirname $0) -. "${DOCKERS_ENV}" - -available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "service" "wp" 2>/dev/null) -usage () { - echo "Usage: $0 orga${NL}" \ - " -h : this help${NL}" \ - " -n : simulation${NL}" \ - " [orga] : in${NL}" \ - " ${CYAN}${available_orga}${NC}${NL}" - exit 1 -} - -SIMU= -for ARG in $*; do - case "$1" in - -h*) usage ;; - -n) SIMU=echo; shift ;; - *) break;; - esac -done - -. ${KAZ_KEY_DIR}/SetAllPass.sh - -case "$#" in - 0) - # shared - ORGA="Kaz" - wpName="" - - DockerServName="${wordpressServName}" - WP_URL="${httpProto}://${wordpressHost}.${domain}" - VOL_PREFIX="${DOCK_VOL}/wordpress_" - ;; - 1) - # orga - [[ " ${available_orga} " =~ "$1" ]] || usage - ORGA=${1%-orga} - wpName="${ORGA}" - - DockerServName="${ORGA}-${wordpressServName}" - WP_URL="${httpProto}://${ORGA}-${wordpressHost}.${domain}" - VOL_PREFIX="${DOCK_VOL}/orga_${ORGA}-" - ;; - *) - usage - ;; -esac - -CONF_DIR="${VOL_PREFIX}wordpress/_data" - -checkDockerRunning "${DockerServName}" "${cloudName}" || exit - -# XXX trouver un test du genre if ! grep -q "'installed' => true," "${PHP_CONF}" 2> /dev/null; then -printKazMsg "\n *** Premier lancement de WP" - -waitUrl "${WP_URL}" - -${SIMU} curl -X POST \ - -d "user_name=${wp_WORDPRESS_ADMIN_USER}" \ - -d "admin_password=${wp_WORDPRESS_ADMIN_PASSWORD}" \ - -d "admin_password2=${wp_WORDPRESS_ADMIN_PASSWORD}" \ - -d "pw_weak=true" \ - -d "admin_email=admin@kaz.bzh" \ - -d "blog_public=0" \ - -d "language=fr_FR" \ - "${WP_URL}/wp-admin/install.php?step=2" -echo diff --git a/bin/initWiki.sh b/bin/initWiki.sh deleted file mode 100755 index 052c75b..0000000 --- a/bin/initWiki.sh +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/bash - -KAZ_ROOT=$(cd $(dirname $0)/..; pwd) -. "${KAZ_ROOT}/bin/.commonFunctions.sh" -setKazVars - -cd $(dirname $0) -. "${DOCKERS_ENV}" - -available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "service" "wiki" 2>/dev/null) -usage () { - echo "Usage: $0 orga${NL}" \ - " -h : this help${NL}" \ - " -n : simulation${NL}" \ - " [orga] : in${NL}" \ - " ${CYAN}${available_orga}${NC}${NL}" - exit 1 -} - -SIMU= -for ARG in $*; do - case "$1" in - -h*) usage ;; - -n) SIMU=echo; shift ;; - *) break;; - esac -done - -. ${KAZ_KEY_DIR}/SetAllPass.sh - -#wiki_ROOT="admin" -#wiki_PASSWORD="bojhypmihem7ortU" - -DNLD_DIR="${KAZ_DNLD_DIR}/dokuwiki" -case "$#" in - 0) - # shared - ORGA="Kaz" - wikiName="" - - WIKI_TITLE=Kaz - WIKI_EMAIL="wiki@${domain}" - DockerServName="${dokuwikiServName}" - VOL_PREFIX="${DOCK_VOL}/dokuwiki_doku" - WIKI_URL="${httpProto}://${dokuwikiHost}.${domain}" - ;; - 1) - # orga - [[ " ${available_orga} " =~ "$1" ]] || usage - ORGA=${1%-orga} - wikiName="${ORGA}" - - WIKI_TITLE=${wikiName} - WIKI_EMAIL="wiki@${domain}" - DockerServName="${ORGA}-${dokuwikiServName}" - VOL_PREFIX="${DOCK_VOL}/orga_${ORGA}-" - WIKI_URL="${httpProto}://${ORGA}-${dokuwikiHost}.${domain}" - ;; - *) - usage - ;; -esac - -TPL_DIR="${VOL_PREFIX}wikiLibtpl/_data" -PLG_DIR="${VOL_PREFIX}wikiPlugins/_data" -CONF_DIR="${VOL_PREFIX}wikiConf/_data" - -checkDockerRunning "${DockerServName}" "${wikiName}}" || exit -cd "${KAZ_COMP_DIR}/dokuwiki/wiki-conf" - -if [ ! -f "${CONF_DIR}/local.php" ] ; then - printKazMsg "\n *** Premier lancement de Dokuwiki de ${wikiName}" - - waitUrl "${WIKI_URL}" - - # XXX test local - - ${SIMU} curl -X POST \ - -A "Mozilla/5.0 (X11; Linux x86_64)" \ - -d "l=fr" \ - -d "d[title]=${WIKI_TITLE}" \ - -d "d[acl]=true" \ - -d "d[superuser]=${wiki_ROOT}" \ - -d "d[fullname]=Admin"\ - -d "d[email]=${WIKI_EMAIL}" \ - -d "d[password]=${wiki_PASSWORD}" \ - -d "d[confirm]=${wiki_PASSWORD}" \ - -d "d[policy]=1" \ - -d "d[allowreg]=false" \ - -d "d[license]=0" \ - -d "d[pop]=false" \ - -d "submit=Enregistrer" \ - "${WIKI_URL}/install.php" - - # XXX initialiser admin::admin::admin,user - #${SIMU} rsync -auHAX local.php users.auth.php acl.auth.php "${CONF_DIR}/" - - ${SIMU} sed -i "${CONF_DIR}/local.php" \ - -e "s|\(.*conf\['title'\].*=.*'\).*';|\1${ORGA}';|g" \ - -e "s|\(.*conf\['title'\].*=.*'\).*';|\1${ORGA}';|g" \ - -e "/conf\['template'\]/d" \ - -e '$a\'"\$conf['template'] = 'docnavwiki';"'' - - ${SIMU} sed -i -e "s|\(.*conf\['lang'\].*=.*'\)en';|\1fr';|g" "${CONF_DIR}/dokuwiki.php" - - ${SIMU} chown -R www-data: "${CONF_DIR}/" -fi - -${SIMU} unzipInDir "${DNLD_DIR}/docnavwiki.zip" "${TPL_DIR}/" -${SIMU} cp logo.png favicon.ico "${TPL_DIR}/docnavwiki/images/" -${SIMU} chown -R www-data: "${TPL_DIR}/" - -# ckgedit : bof -for plugin in captcha smtp todo wrap wrapadd; do - ${SIMU} unzipInDir "${DNLD_DIR}/${plugin}.zip" "${PLG_DIR}" -done -${SIMU} chown -R www-data: "${PLG_DIR}/" - diff --git a/bin/manageAgora.sh b/bin/manageAgora.sh new file mode 100755 index 0000000..5e235cd --- /dev/null +++ b/bin/manageAgora.sh @@ -0,0 +1,180 @@ +#!/bin/bash +# Script de manipulation d'un mattermost' +# init /versions / restart ... +# + +KAZ_ROOT=$(cd "$(dirname $0)"/..; pwd) +. $KAZ_ROOT/bin/.commonFunctions.sh +setKazVars +. $DOCKERS_ENV +. $KAZ_ROOT/secret/SetAllPass.sh + +#GLOBAL VARS +PRG=$(basename $0) + +availableOrga=($(getList "${KAZ_CONF_DIR}/container-orga.list")) +AVAILABLE_ORGAS=${availableOrga[*]//-orga/} + +QUIET="1" +ONNAS= + +AGORACOMMUN="OUI_PAR_DEFAUT" +DockerServName=${mattermostServName} + +declare -A Posts + +usage() { +echo "${PRG} [OPTION] [COMMANDES] [ORGA] +Manipulation d'un mattermost + +OPTIONS + -h|--help Cette aide :-) + -n|--simu SIMULATION + -q|--quiet On ne parle pas (utile avec le -n pour avoir que les commandes) + --nas L'orga se trouve sur le NAS ! + +COMMANDES (on peut en mettre plusieurs dans l'ordre souhaité) + -I|--install L'initialisation du mattermost + -v|--version Donne la version du mattermost et signale les MàJ + + + -mmctl \"command\" Envoie une commande via mmctl ** SPECIFIQUES ** + -p|--post \"team\" \"message\" Poste un message dans une team agora ** AGORA ** + +ORGA parmi : ${AVAILABLE_ORGAS} + ou vide si mattermost commun +" +} + + +Init(){ + NOM=$ORGA + if [ -n "$AGORACOMMUN" ] ; then NOM="KAZ" ; fi + CONF_FILE="${DOCK_VOL}/orga_${ORGA}-matterConfig/_data/config.json" + if [ -n "${AGORACOMMUN}" ]; then + CONF_FILE="${DOCK_VOL}/mattermost_matterConfig/_data/config.json" + elif [ -n "${ONNAS}" ]; then + CONF_FILE="${NAS_VOL}/orga_${ORGA}-matterConfig/_data/config.json" + fi + + + ${SIMU} sed -i \ + -e 's|"SiteURL": ".*"|"SiteURL": "'${MATTER_URL}'"|g' \ + -e 's|"ListenAddress": ".*"|"ListenAddress": ":'${matterPort}'"|g' \ + -e 's|"WebsocketURL": ".*"|"WebsocketURL": "wss://'${MATTER_URI}'"|g' \ + -e 's|"AllowCorsFrom": ".*"|"AllowCorsFrom": "'${domain}' '${MATTER_URI}':443 '${MATTER_URI}'"|g' \ + -e 's|"ConsoleLevel": ".*"|"ConsoleLevel": "ERROR"|g' \ + -e 's|"SendEmailNotifications": false|"SendEmailNotifications": true|g' \ + -e 's|"FeedbackEmail": ".*"|"FeedbackEmail": "admin@'${domain}'"|g' \ + -e 's|"FeedbackOrganization": ".*"|"FeedbackOrganization": "Cochez la KAZ du libre !"|g' \ + -e 's|"ReplyToAddress": ".*"|"ReplyToAddress": "admin@'${domain}'"|g' \ + -e 's|"SMTPServer": ".*"|"SMTPServer": "mail.'${domain}'"|g' \ + -e 's|"SMTPPort": ".*"|"SMTPPort": "25"|g' \ + -e 's|"DefaultServerLocale": ".*"|"DefaultServerLocale": "fr"|g' \ + -e 's|"DefaultClientLocale": ".*"|"DefaultClientLocale": "fr"|g' \ + -e 's|"AvailableLocales": ".*"|"AvailableLocales": "fr"|g' \ + ${CONF_FILE} + + # on redémarre pour prendre en compte (changement de port) + ${SIMU} docker restart "${DockerServName}" + [ $? -ne 0 ] && printKazError "$DockerServName est down : impossible de terminer l'install" && return 1 >& $QUIET + + ${SIMU} waitUrl "$MATTER_URL" 300 + [ $? -ne 0 ] && printKazError "$DockerServName ne parvient pas à démarrer correctement : impossible de terminer l'install" && return 1 >& $QUIET + + # creation compte admin + ${SIMU} curl -i -d "{\"email\":\"${mattermost_MM_ADMIN_EMAIL}\",\"username\":\"${mattermost_MM_ADMIN_USER}\",\"password\":\"${mattermost_MM_ADMIN_PASSWORD}\",\"allow_marketing\":true}" "${MATTER_URL}/api/v4/users" + + MM_TOKEN=$(_getMMToken ${MATTER_URL}) + + #on crée la team + ${SIMU} curl -i -H "Authorization: Bearer ${MM_TOKEN}" -d "{\"display_name\":\"${NOM}\",\"name\":\"${NOM,,}\",\"type\":\"O\"}" "${MATTER_URL}/api/v4/teams" +} + +Version(){ + VERSION=$(docker exec "$DockerServName" bin/mmctl version | grep -i version:) + echo "Version $DockerServName : ${GREEN}${VERSION}${NC}" +} + +_getMMToken(){ + #$1 MATTER_URL + ${SIMU} curl -i -s -d "{\"login_id\":\"${mattermost_MM_ADMIN_USER}\",\"password\":\"${mattermost_MM_ADMIN_PASSWORD}\"}" "${1}/api/v4/users/login" | grep 'token' | sed 's/token:\s*\(.*\)\s*/\1/' | tr -d '\r' +} + +PostMessage(){ + printKazMsg "Envoi à $TEAM : $MESSAGE" >& $QUIET + + ${SIMU} docker exec -ti "${DockerServName}" bin/mmctl auth login "${MATTER_URL}" --name local-server --username ${mattermost_MM_ADMIN_USER} --password ${mattermost_MM_ADMIN_PASSWORD} + ${SIMU} docker exec -ti "${DockerServName}" bin/mmctl post create "${TEAM}" --message "${MESSAGE}" +} + +MmctlCommand(){ + # $1 command + ${SIMU} docker exec -u 33 "$DockerServName" bin/mmctl $1 +} + + +########## Main ################# +for ARG in "$@"; do + if [ -n "${GETMMCTLCOMAND}" ]; then # après un -mmctl + MMCTLCOMAND="${ARG}" + GETMMCTLCOMAND= + elif [ -n "${GETTEAM}" ]; then # après un --post + GETMESSAGE="now" + GETTEAM="" + TEAM="${ARG}" + elif [ -n "${GETMESSAGE}" ]; then # après un --post "team:channel" + if [[ $TEAM == "-*" && ${#TEAM} -le 5 ]]; then echo "J'envoie mon message à \"${TEAM}\" ?? Arf, ça me plait pas j'ai l'impression que tu t'es planté sur la commande."; usage ; exit 1 ; fi + if [[ $ARG == "-*" && ${#ARG} -le 5 ]]; then echo "J'envoie le message \"${ARG}\" ?? Arf, ça me plait pas j'ai l'impression que tu t'es planté sur la commande."; usage ; exit 1 ; fi + if [[ ! $TEAM =~ .*:.+ ]]; then echo "Il faut mettre un destinataire sous la forme team:channel. Recommence !"; usage ; exit 1 ; fi + MESSAGE="$ARG" + GETMESSAGE="" + else + case "${ARG}" in + '-h' | '--help' ) + usage && exit ;; + '-n' | '--simu') + SIMU="echo" ;; + '-q' ) + QUIET="/dev/null" ;; + '--nas' | '-nas' ) + ONNAS="SURNAS" ;; + '-v' | '--version') + COMMANDS="$(echo "${COMMANDS} VERSION" | sed "s/\s/\n/g" | sort | uniq)" ;; + '-I' | '--install' ) + COMMANDS="$(echo "${COMMANDS} INIT" | sed "s/\s/\n/g" | sort | uniq)" ;; # le sed sort uniq, c'est pour pas l'avoir en double + '--mmctl' | '-mmctl' ) + COMMANDS="$(echo "${COMMANDS} RUN-AGORA-MMCTL" | sed "s/\s/\n/g" | sort | uniq)" + GETMMCTLCOMAND="now" ;; + '-p' | '--post' ) + COMMANDS="$(echo "${COMMANDS} POST-AGORA" | sed "s/\s/\n/g" | sort | uniq)" + GETTEAM="now" ;; + '-*' ) # ignore + ;; + *) + ORGA="${ARG%-orga}" + DockerServName="${ORGA}-${mattermostServName}" + AGORACOMMUN= + ;; + esac + fi +done + +if [ -z "${COMMANDS}" ]; then usage && exit ; fi + +MATTER_URI="${ORGA}-${matterHost}.${domain}" +if [ -n "$AGORACOMMUN" ]; then MATTER_URI="${matterHost}.${domain}" ; fi +MATTER_URL="${httpProto}://${MATTER_URI}" + +for COMMAND in ${COMMANDS}; do + case "${COMMAND}" in + 'VERSION' ) + Version && exit ;; + 'INIT' ) + Init ;; + 'RUN-AGORA-MMCTL' ) + MmctlCommand "$MMCTLCOMAND" ;; + 'POST-AGORA' ) + PostMessage ;; + esac +done \ No newline at end of file diff --git a/bin/manageCloud.sh b/bin/manageCloud.sh new file mode 100755 index 0000000..8aa09f7 --- /dev/null +++ b/bin/manageCloud.sh @@ -0,0 +1,382 @@ +#!/bin/bash +# Script de manipulation d'un cloud' +# init /versions / restart ... +# + +KAZ_ROOT=$(cd "$(dirname $0)"/..; pwd) +. $KAZ_ROOT/bin/.commonFunctions.sh +setKazVars +. $DOCKERS_ENV +. $KAZ_ROOT/secret/SetAllPass.sh + +#GLOBAL VARS +PRG=$(basename $0) + +availableOrga=($(getList "${KAZ_CONF_DIR}/container-orga.list")) +AVAILABLE_ORGAS=${availableOrga[*]//-orga/} + +# CLOUD +APPLIS_PAR_DEFAUT="tasks calendar contacts bookmarks mail richdocuments external drawio snappymail ransomware_protection" #rainloop richdocumentscode +QUIET="1" +ONNAS= + +CLOUDCOMMUN="OUI_PAR_DEFAUT" +DockerServName=${nextcloudServName} + +usage() { +echo "${PRG} [OPTION] [COMMANDES] [ORGA] +Manipulation d'un cloud + +OPTIONS + -h|--help Cette aide :-) + -n|--simu SIMULATION + -q|--quiet On ne parle pas (utile avec le -n pour avoir que les commandes) + --nas L'orga se trouve sur le NAS ! + +COMMANDES (on peut en mettre plusieurs dans l'ordre souhaité) + -I|--install L'initialisation du cloud + -v|--version Donne la version du cloud et signale les MàJ + + --optim Lance la procédure Nextcloud pour optimiser les performances ** ** + -occ \"command\" Envoie une commande via occ ** ** + -u Mets à jour les applis ** SPECIFIQUES ** + -i Install des applis ** CLOUD ** + -a \"app1 app2 ...\" Choix des appli à installer ou mettre à jour (entre guillemets) ** ** + -U|--upgrade Upgrade des clouds ** ** + +ORGA parmi : ${AVAILABLE_ORGAS} + ou vide si cloud commun +" +} + + +################################## +############### CLOUD ############ +################################## + +Init(){ + NOM=$ORGA + [ -n "${CLOUDCOMMUN}" ] && NOM="commun" + if [ -z "${LISTE_APPS}" ]; then + printKazMsg "Aucune appli n'est précisée, j'installerais les applis par défaut : ${APPLIS_PAR_DEFAUT}" >& $QUIET + LISTE_APPS="${APPLIS_PAR_DEFAUT}" + fi + + checkDockerRunning "$DockerServName" "$NOM" + [ $? -ne 0 ] && echo "${CYAN}\n $DockerServName est down : impossible de terminer l'install${NC}" && return 1 >& $QUIET + + CONF_FILE="${DOCK_VOL}/orga_${ORGA}-cloudConfig/_data/config.php" + OFFICE_URL="https://${ORGA}-${officeHost}.${domain}" + CLOUD_URL="https://${ORGA}-${cloudHost}.${domain}" + if [ -n "$CLOUDCOMMUN" ]; then + CONF_FILE="${DOCK_VOL}/cloud-cloudConfig/_data/config.php" + OFFICE_URL="https://${officeHost}.${domain}" + CLOUD_URL="https://${cloudHost}.${domain}" + elif [ -n "${ONNAS}" ]; then + CONF_FILE="${NAS_VOL}/orga_${ORGA}-cloudConfig/_data/config.php" + fi + + firstInstall "$CLOUD_URL" "$CONF_FILE" " NextCloud de $NOM" + updatePhpConf "$CONF_FILE" + InstallApplis + echo "${CYAN} *** Paramétrage richdocuments pour $ORGA${NC}" >& $QUIET + occCommand "config:app:set --value $OFFICE_URL richdocuments public_wopi_url" + occCommand "config:app:set --value $OFFICE_URL richdocuments wopi_url" + occCommand "config:app:set --value $OFFICE_URL richdocuments disable_certificate_verification" + occCommand "config:app:set --value 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16 richdocuments wopi_allowlist" + occCommand "config:system:set overwrite.cli.url --value=$CLOUD_URL" + occCommand "config:system:set disable_certificate_verification --value=true" + + if [ -n "$CLOUDCOMMUN" ]; then initLdap "$NOM" ; fi +} + +Version(){ + VERSION=$(docker exec -u 33 ${DockerServName} /var/www/html/occ status | grep -i version:) + VERSION_UPDATE=$(docker exec -u 33 ${DockerServName} /var/www/html/occ update:check | grep -i "available\." | cut -c 1-17) + versionSTR="Version ${DockerServName} : ${GREEN}${VERSION}${NC}" + [ -n "${VERSION_UPDATE}" ] && versionSTR="$versionSTR -- Disponible : ${RED} ${VERSION_UPDATE} ${NC}" + echo "$versionSTR" +} + +firstInstall(){ + # $1 CLOUD_URL + # $2 phpConfFile + # $3 orga + if ! grep -q "'installed' => true," "$2" 2> /dev/null; then + printKazMsg "\n *** Premier lancement de $3" >& $QUIET + + ${SIMU} waitUrl "$1" + + ${SIMU} curl -X POST \ + -d "install=true" \ + -d "adminlogin=${nextcloud_NEXTCLOUD_ADMIN_USER}" \ + -d "adminpass=${nextcloud_NEXTCLOUD_ADMIN_PASSWORD}" \ + -d "directory=/var/www/html/data" \ + -d "dbtype=mysql" \ + -d "dbuser=${nextcloud_MYSQL_USER}" \ + -d "dbpass=${nextcloud_MYSQL_PASSWORD}" \ + -d "dbname=${nextcloud_MYSQL_DATABASE}" \ + -d "dbhost=${nextcloud_MYSQL_HOST}" \ + -d "install-recommended-apps=true" \ + "$1" + fi +} + +initLdap(){ + # $1 Nom du cloud + echo "${CYAN} *** Installation LDAP pour $1${NC}" >& $QUIET + occCommand "app:enable user_ldap" "${DockerServName}" + occCommand "ldap:delete-config s01" "${DockerServName}" + occCommand "ldap:create-empty-config" "${DockerServName}" + occCommand "ldap:set-config s01 ldapAgentName cn=cloud,ou=applications,${ldap_root}" "${DockerServName}" + occCommand "ldap:set-config s01 ldapAgentPassword ${ldap_LDAP_CLOUD_PASSWORD}" "${DockerServName}" + occCommand "ldap:set-config s01 ldapBase ${ldap_root}" "${DockerServName}" + occCommand "ldap:set-config s01 ldapBaseGroups ${ldap_root}" "${DockerServName}" + occCommand "ldap:set-config s01 ldapBaseUsers ou=users,${ldap_root}" "${DockerServName}" + occCommand "ldap:set-config s01 ldapExpertUsernameAttr identifiantKaz" "${DockerServName}" + occCommand "ldap:set-config s01 ldapHost ${ldapServName}" "${DockerServName}" + occCommand "ldap:set-config s01 ldapPort 389" "${DockerServName}" + occCommand "ldap:set-config s01 ldapTLS 0" "${DockerServName}" + occCommand "ldap:set-config s01 ldapLoginFilter \"(&(objectclass=nextcloudAccount)(|(cn=%uid)(identifiantKaz=%uid)))\"" "${DockerServName}" + occCommand "ldap:set-config s01 ldapQuotaAttribute nextcloudQuota" "${DockerServName}" + occCommand "ldap:set-config s01 ldapUserFilter \"(&(objectclass=nextcloudAccount)(nextcloudEnabled=TRUE))\"" "${DockerServName}" + occCommand "ldap:set-config s01 ldapUserFilterObjectclass nextcloudAccount" "${DockerServName}" + occCommand "ldap:set-config s01 ldapEmailAttribute mail" "${DockerServName}" + occCommand "ldap:set-config s01 ldapUserDisplayName cn" "${DockerServName}" + occCommand "ldap:set-config s01 ldapUserFilterMode 1" "${DockerServName}" + occCommand "ldap:set-config s01 ldapConfigurationActive 1" "${DockerServName}" + + # Dans le mariadb, pour permettre au ldap de reprendre la main : delete from oc_users where uid<>'admin'; + # docker exec -i nextcloudDB mysql --user= --password= <<< "delete from oc_users where uid<>'admin';" + + # Doc : https://help.nextcloud.com/t/migration-to-ldap-keeping-users-and-data/13205 + + # Exemple de table/clés : + # +-------------------------------+----------------------------------------------------------+ + # | Configuration | s01 | + # +-------------------------------+----------------------------------------------------------+ + # | hasMemberOfFilterSupport | 0 | + # | homeFolderNamingRule | | + # | lastJpegPhotoLookup | 0 | + # | ldapAgentName | cn=cloud,ou=applications,dc=kaz,dc=sns | + # | ldapAgentPassword | *** | + # | ldapAttributesForGroupSearch | | + # | ldapAttributesForUserSearch | | + # | ldapBackgroundHost | | + # | ldapBackgroundPort | | + # | ldapBackupHost | | + # | ldapBackupPort | | + # | ldapBase | ou=users,dc=kaz,dc=sns | + # | ldapBaseGroups | ou=users,dc=kaz,dc=sns | + # | ldapBaseUsers | ou=users,dc=kaz,dc=sns | + # | ldapCacheTTL | 600 | + # | ldapConfigurationActive | 1 | + # | ldapConnectionTimeout | 15 | + # | ldapDefaultPPolicyDN | | + # | ldapDynamicGroupMemberURL | | + # | ldapEmailAttribute | mail | + # | ldapExperiencedAdmin | 0 | + # | ldapExpertUUIDGroupAttr | | + # | ldapExpertUUIDUserAttr | | + # | ldapExpertUsernameAttr | uid | + # | ldapExtStorageHomeAttribute | | + # | ldapGidNumber | gidNumber | + # | ldapGroupDisplayName | cn | + # | ldapGroupFilter | | + # | ldapGroupFilterGroups | | + # | ldapGroupFilterMode | 0 | + # | ldapGroupFilterObjectclass | | + # | ldapGroupMemberAssocAttr | | + # | ldapHost | ldap | + # | ldapIgnoreNamingRules | | + # | ldapLoginFilter | (&(|(objectclass=nextcloudAccount))(cn=%uid)) | + # | ldapLoginFilterAttributes | | + # | ldapLoginFilterEmail | 0 | + # | ldapLoginFilterMode | 0 | + # | ldapLoginFilterUsername | 1 | + # | ldapMatchingRuleInChainState | unknown | + # | ldapNestedGroups | 0 | + # | ldapOverrideMainServer | | + # | ldapPagingSize | 500 | + # | ldapPort | 389 | + # | ldapQuotaAttribute | nextcloudQuota | + # | ldapQuotaDefault | | + # | ldapTLS | 0 | + # | ldapUserAvatarRule | default | + # | ldapUserDisplayName | cn | + # | ldapUserDisplayName2 | | + # | ldapUserFilter | (&(objectclass=nextcloudAccount)(nextcloudEnabled=TRUE)) | + # | ldapUserFilterGroups | | + # | ldapUserFilterMode | 1 | + # | ldapUserFilterObjectclass | nextcloudAccount | + # | ldapUuidGroupAttribute | auto | + # | ldapUuidUserAttribute | auto | + # | turnOffCertCheck | 0 | + # | turnOnPasswordChange | 0 | + # | useMemberOfToDetectMembership | 1 | + # +-------------------------------+----------------------------------------------------------+ +} + +updatePhpConf(){ + # $1 php_conf_file + if [ $# -ne 1 ]; then + echo "${RED}#Je ne sais pas ou écrire la conf php !${NC}" + return 1 + fi + + echo "${CYAN} *** Maj de la conf $1${NC}" >& $QUIET + PHPCONF="$1" + _addVarAfterInConf "default_language" " 'default_language' => 'fr'," "CONFIG = array (" "${PHPCONF}" + _addVarAfterInConf "theme" " 'theme' => ''," "'installed' => true," "${PHPCONF}" + _addVarAfterInConf "default_phone_region" " 'default_phone_region' => 'FR'," "'installed' => true," "${PHPCONF}" + _addVarAfterInConf "loglevel" " 'loglevel' => 2," "'installed' => true," "${PHPCONF}" + _addVarAfterInConf "maintenance" " 'maintenance' => false," "'installed' => true," "${PHPCONF}" + _addVarAfterInConf "app_install_overwrite" " 'app_install_overwrite' => \n array (\n 0 => 'documents',\n )," "'installed' => true," "${PHPCONF}" + _addVarAfterInConf "overwriteprotocol" " 'overwriteprotocol' => 'https'," "'installed' => true," "${PHPCONF}" + _addVarAfterInConf "mail_domain" " 'mail_domain' => '${domain}'," "'installed' => true," "${PHPCONF}" + _addVarAfterInConf "mail_from_address" " 'mail_from_address' => 'admin'," "'installed' => true," "${PHPCONF}" + _addVarAfterInConf "mail_smtpport" " 'mail_smtpport' => '25'," "'installed' => true," "${PHPCONF}" + _addVarAfterInConf "mail_sendmailmode" " 'mail_sendmailmode' => 'smtp'," "'installed' => true," "${PHPCONF}" + _addVarAfterInConf "mail_smtphost" " 'mail_smtphost' => '${smtpHost}.${domain}'," "'installed' => true," "${PHPCONF}" + _addVarAfterInConf "mail_smtpmode" " 'mail_smtpmode' => 'smtp'," "'installed' => true," "${PHPCONF}" + _addVarAfterInConf "enable_previews" " 'enable_previews' => true," "'installed' => true," "${PHPCONF}" + _addVarAfterInConf "trashbin_retention_obligation" " 'trashbin_retention_obligation' => '30, auto'," "'installed' => true," "${PHPCONF}" + #pour supprimer le message "obtenir un compte gratuit" dans le footer + _addVarAfterInConf "simpleSignUpLink.shown" " 'simpleSignUpLink.shown' => false," "'installed' => true," "${PHPCONF}" + _addVarAfterInConf "trusted_proxies" " 'trusted_proxies' => array( 0 => '10.0.0.0/8', 1 => '172.16.0.0/12', 2 => '192.168.0.0/16' )," "'installed' => true," "${PHPCONF}" +} + +UpgradeClouds() { + echo "${NC}--------------------------------------------------------" >& $QUIET + echo "UPGRADE des cloud" >& $QUIET + echo "--------------------------------------------------------" >& $QUIET + occCommand "upgrade" +} + +OptimiseClouds() { + occCommand "db:add-missing-indices" "db:convert-filecache-bigint --no-interaction" +} + + +UpdateApplis() { + printKazMsg "UPDATE DES APPLIS du cloud ${DockerServName} : ${LISTE_APPS}" >& $QUIET + if [ -z "${LISTE_APPS}" ]; then + occCommand "app:update --all" + return + fi + echo "Mise à jour de ${LISTE_APPS}" >& $QUIET + for app in ${LISTE_APPS} + do + occCommand "app:update ${app}" + done +} + +InstallApplis(){ + if [ -z "${LISTE_APPS}" ]; then + printKazMsg "Aucune appli n'est précisée, j'installe les applis par défaut : ${APPLIS_PAR_DEFAUT}" >& $QUIET + LISTE_APPS="${APPLIS_PAR_DEFAUT}" + fi + apps=$LISTE_APPS + + if ! [[ "$(docker ps -f name=${DockerServName} | grep -w ${DockerServName})" ]]; then + printKazError "${RED}# ${DockerServName} not running... impossible d'installer les applis${NC}" >& $QUIET + return 1 + fi + LIST_ALL=$(docker exec -ti -u 33 "${DockerServName}" /var/www/html/occ app:list | + awk 'BEGIN {cp=0} + /Enabled:/ {cp=1 ; next}; + /Disabled:/ {cp=0; next}; + {if (cp) print $0};') + + for app in $apps + do + grep -wq "${app}" <<<"${LIST_ALL}" 2>/dev/null && echo "${app} dejà installée" >& $QUIET && continue + echo " install ${app}" >& $QUIET + occCommand "app:install ${app}" + done +} + +occCommand(){ + # $1 Command + ${SIMU} docker exec -u 33 $DockerServName /var/www/html/occ $1 +} + +_addVarAfterInConf(){ + # $1 key + # $2 val + # $3 where + # $4 confFile + if ! grep -q "$1" "${4}" ; then + echo -n " ${CYAN}${BOLD}$1${NC}" >& $QUIET + ${SIMU} sed -i -e "/$3/a\ $2" "$4" + fi +} + +########## Main ################# +for ARG in "$@"; do + if [ -n "${GETOCCCOMAND}" ]; then # après un -occ + OCCCOMAND="${ARG}" + GETOCCCOMAND= + elif [ -n "${GETAPPS}" ]; then # après un -a + LISTE_APPS="${LISTE_APPS} ${ARG}" + GETAPPS="" + else + case "${ARG}" in + '-h' | '--help' ) + usage && exit ;; + '-n' | '--simu') + SIMU="echo" ;; + '-q' ) + QUIET="/dev/null" ;; + '--nas' | '-nas' ) + ONNAS="SURNAS" ;; + '-v' | '--version') + COMMANDS="$(echo "${COMMANDS} VERSION" | sed "s/\s/\n/g" | sort | uniq)" ;; + '-I' | '--install' ) + COMMANDS="$(echo "${COMMANDS} INIT" | sed "s/\s/\n/g" | sort | uniq)" ;; # le sed sort uniq, c'est pour pas l'avoir en double + '-U' | '--upgrade') + COMMANDS="$(echo "${COMMANDS} UPGRADE" | sed "s/\s/\n/g" | sort | uniq)" ;; + '--optim' | '-optim' ) + COMMANDS="$(echo "${COMMANDS} OPTIMISE-CLOUD" | sed "s/\s/\n/g" | sort | uniq)" ;; + '-u' ) + COMMANDS="$(echo "${COMMANDS} UPDATE-CLOUD-APP" | sed "s/\s/\n/g" | sort | uniq)" ;; + '-i' ) + COMMANDS="$(echo "${COMMANDS} INSTALL-CLOUD-APP" | sed "s/\s/\n/g" | sort | uniq)" ;; + '-a' ) + GETAPPS="now" ;; + '--occ' | '-occ' ) + COMMANDS="$(echo "${COMMANDS} RUN-CLOUD-OCC" | sed "s/\s/\n/g" | sort | uniq)" + GETOCCCOMAND="now" ;; + '-*' ) # ignore + ;; + *) + ORGA="${ARG%-orga}" + DockerServName="${ORGA}-${nextcloudServName}" + CLOUDCOMMUN= + ;; + esac + fi +done + +if [ -z "${COMMANDS}" ]; then + usage && exit +fi + +for COMMAND in ${COMMANDS}; do + case "${COMMAND}" in + 'VERSION' ) + Version && exit ;; + 'OPTIMISE-CLOUD' ) + OptimiseClouds ;; + 'UPDATE-CLOUD-APP' ) + UpdateApplis ;; + 'UPGRADE' ) + UpgradeClouds ;; + 'INIT' ) + Init ;; + 'INSTALL-CLOUD-APP' ) + InstallApplis ;; + 'RUN-CLOUD-OCC' ) + occCommand "${OCCCOMAND}";; + esac +done \ No newline at end of file diff --git a/bin/manageWiki.sh b/bin/manageWiki.sh new file mode 100755 index 0000000..f4ac73a --- /dev/null +++ b/bin/manageWiki.sh @@ -0,0 +1,171 @@ +#!/bin/bash +# Script de manipulation d'un dokuwiki' +# init /versions / restart ... +# + +KAZ_ROOT=$(cd "$(dirname $0)"/..; pwd) +. $KAZ_ROOT/bin/.commonFunctions.sh +setKazVars +. $DOCKERS_ENV +. $KAZ_ROOT/secret/SetAllPass.sh + +#GLOBAL VARS +PRG=$(basename $0) + +availableOrga=($(getList "${KAZ_CONF_DIR}/container-orga.list")) +AVAILABLE_ORGAS=${availableOrga[*]//-orga/} +DNLD_DIR="${KAZ_DNLD_DIR}/dokuwiki" + +QUIET="1" +ONNAS= + +WIKICOMMUN="OUI_PAR_DEFAUT" +DockerServName=${dokuwikiServName} + +declare -A Posts + +usage() { +echo "${PRG} [OPTION] [COMMANDES] [ORGA] +Manipulation d'un dokuwiki + +OPTIONS + -h|--help Cette aide :-) + -n|--simu SIMULATION + -q|--quiet On ne parle pas (utile avec le -n pour avoir que les commandes) + --nas L'orga se trouve sur le NAS ! + +COMMANDES (on peut en mettre plusieurs dans l'ordre souhaité) + -I|--install L'initialisation du dokuwiki + -v|--version Donne la version du dokuwiki et signale les MàJ + + --reload kill lighthttpd + +ORGA parmi : ${AVAILABLE_ORGAS} + ou vide si dokuwiki commun +" +} + + + +Init(){ + + NOM=$ORGA + if [ -n "$WIKICOMMUN" ] ; then NOM="KAZ" ; fi + TPL_DIR="${VOL_PREFIX}wikiLibtpl/_data" + PLG_DIR="${VOL_PREFIX}wikiPlugins/_data" + CONF_DIR="${VOL_PREFIX}wikiConf/_data" + + WIKI_ROOT="${dokuwiki_WIKI_ROOT}" + WIKI_EMAIL="${dokuwiki_WIKI_EMAIL}" + WIKI_PASS="${dokuwiki_WIKI_PASSWORD}" + + ${SIMU} checkDockerRunning "${DockerServName}" "${NOM}" || exit + + if [ ! -f "${CONF_DIR}/local.php" ] ; then + echo "\n *** Premier lancement de Dokuwiki ${NOM}" >& $QUIET + + ${SIMU} waitUrl "${WIKI_URL}" + + ${SIMU} curl -X POST \ + -A "Mozilla/5.0 (X11; Linux x86_64)" \ + -d "l=fr" \ + -d "d[title]=${NOM}" \ + -d "d[acl]=true" \ + -d "d[superuser]=${WIKI_ROOT}" \ + -d "d[fullname]=Admin"\ + -d "d[email]=${WIKI_EMAIL}" \ + -d "d[password]=${WIKI_PASS}" \ + -d "d[confirm]=${WIKI_PASS}" \ + -d "d[policy]=1" \ + -d "d[allowreg]=false" \ + -d "d[license]=0" \ + -d "d[pop]=false" \ + -d "submit=Enregistrer" \ + "${WIKI_URL}/install.php" + + # XXX initialiser admin::admin::admin,user + #${SIMU} rsync -auHAX local.php users.auth.php acl.auth.php "${CONF_DIR}/" + + ${SIMU} sed -i "${CONF_DIR}/local.php" \ + -e "s|\(.*conf\['title'\].*=.*'\).*';|\1${NOM}';|g" \ + -e "s|\(.*conf\['title'\].*=.*'\).*';|\1${NOM}';|g" \ + -e "/conf\['template'\]/d" \ + -e '$a\'"\$conf['template'] = 'docnavwiki';"'' + + ${SIMU} sed -i -e "s|\(.*conf\['lang'\].*=.*'\)en';|\1fr';|g" "${CONF_DIR}/dokuwiki.php" + + ${SIMU} chown -R www-data: "${CONF_DIR}/" + fi + + ${SIMU} unzipInDir "${DNLD_DIR}/docnavwiki.zip" "${TPL_DIR}/" + ${SIMU} chown -R www-data: "${TPL_DIR}/" + # ckgedit : bof + for plugin in captcha smtp todo wrap wrapadd; do + ${SIMU} unzipInDir "${DNLD_DIR}/${plugin}.zip" "${PLG_DIR}" + done + ${SIMU} chown -R www-data: "${PLG_DIR}/" +} + +Version(){ + # $1 ContainerName + VERSION=$(docker exec $1 cat /dokuwiki/VERSION) + echo "Version $1 : ${GREEN}${VERSION}${NC}" +} + + +Reload(){ + # $1 ContainerName + if [ -f "${VOL_PREFIX}wikiData/_data/farms/init.sh" ]; then + ${SIMU} docker exec -ti "${1}" /dokuwiki/data/farms/init.sh + ${SIMU} pkill -KILL lighttpd + fi +} + +########## Main ################# +for ARG in "$@"; do + case "${ARG}" in + '-h' | '--help' ) + usage && exit ;; + '-n' | '--simu') + SIMU="echo" ;; + '-q' ) + QUIET="/dev/null" ;; + '--nas' | '-nas' ) + ONNAS="SURNAS" ;; + '-v' | '--version') + COMMANDS="$(echo "${COMMANDS} VERSION" | sed "s/\s/\n/g" | sort | uniq)" ;; + '--reload' ) + COMMANDS="$(echo "${COMMANDS} RELOAD" | sed "s/\s/\n/g" | sort | uniq)" ;; # le sed sort uniq, c'est pour pas l'avoir en double + '-I' | '--install' ) + COMMANDS="$(echo "${COMMANDS} INIT" | sed "s/\s/\n/g" | sort | uniq)" ;; # le sed sort uniq, c'est pour pas l'avoir en double + '-*' ) # ignore + ;; + *) + ORGA="${ARG%-orga}" + DockerServName="${ORGA}-${dokuwikiServName}" + WIKICOMMUN= + ;; + esac +done + +if [ -z "${COMMANDS}" ]; then usage && exit ; fi + +VOL_PREFIX="${DOCK_VOL}/orga_${ORGA}-" +WIKI_URL="${httpProto}://${ORGA}-${dokuwikiHost}.${domain}" +if [ -n "${WIKICOMMUN}" ]; then + VOL_PREFIX="${DOCK_VOL}/dokuwiki_doku" + WIKI_URL="${httpProto}://${dokuwikiHost}.${domain}" +elif [ -n "${ONNAS}" ]; then + VOL_PREFIX="${NAS_VOL}/orga_${ORGA}-" +fi + +for COMMAND in ${COMMANDS}; do + case "${COMMAND}" in + 'VERSION' ) + Version "${DockerServName}" && exit ;; + 'INIT' ) + Init "${DockerServName}" ;; + 'RELOAD' ) + Reload "${DockerServName}";; + esac +done \ No newline at end of file diff --git a/bin/manageWp.sh b/bin/manageWp.sh new file mode 100755 index 0000000..ba016f7 --- /dev/null +++ b/bin/manageWp.sh @@ -0,0 +1,130 @@ +#!/bin/bash +# Script de manipulation d'un wordpress' +# init /versions / restart ... +# + +KAZ_ROOT=$(cd "$(dirname $0)"/..; pwd) +. $KAZ_ROOT/bin/.commonFunctions.sh +setKazVars +. $DOCKERS_ENV +. $KAZ_ROOT/secret/SetAllPass.sh + +#GLOBAL VARS +PRG=$(basename $0) + +availableOrga=($(getList "${KAZ_CONF_DIR}/container-orga.list")) +AVAILABLE_ORGAS=${availableOrga[*]//-orga/} + +QUIET="1" +ONNAS= + +WPCOMMUN="OUI_PAR_DEFAUT" +DockerServName=${wordpressServName} + +declare -A Posts + +usage() { +echo "${PRG} [OPTION] [COMMANDES] [ORGA] +Manipulation d'un wordpress + +OPTIONS + -h|--help Cette aide :-) + -n|--simu SIMULATION + -q|--quiet On ne parle pas (utile avec le -n pour avoir que les commandes) + --nas L'orga se trouve sur le NAS ! + +COMMANDES (on peut en mettre plusieurs dans l'ordre souhaité) + -I|--install L'initialisation du wordpress + -v|--version Donne la version du wordpress et signale les MàJ + +ORGA parmi : ${AVAILABLE_ORGAS} + ou vide si wordpress commun +" +} + + + +Init(){ + PHP_CONF="${DOCK_VOL}/orga_${ORGA}-wordpress/_data/wp-config.php" + WP_URL="${httpProto}://${ORGA}-${wordpressHost}.${domain}" + + if [ -n "${ONNAS}" ]; then + PHP_CONF="${NAS_VOL}/orga_${ORGA}-wordpress/_data/wp-config.php" + fi + + if ! [[ "$(docker ps -f name=${DockerServName} | grep -w ${DockerServName})" ]]; then + printKazError "Wordpress not running... abort" + exit + fi + + # XXX trouver un test du genre if ! grep -q "'installed' => true," "${PHP_CONF}" 2> /dev/null; then + echo "\n *** Premier lancement de WP" >& $QUIET + + ${SIMU} waitUrl "${WP_URL}" + + ${SIMU} curl -X POST \ + -d "user_name=${wp_WORDPRESS_ADMIN_USER}" \ + -d "admin_password=${wp_WORDPRESS_ADMIN_PASSWORD}" \ + -d "admin_password2=${wp_WORDPRESS_ADMIN_PASSWORD}" \ + -d "pw_weak=true" \ + -d "admin_email=admin@kaz.bzh" \ + -d "blog_public=0" \ + -d "language=fr_FR" \ + "${WP_URL}/wp-admin/install.php?step=2" + + #/* pour forcer les maj autrement qu'en ftp */ + _addVarBeforeInConf "FS_METHOD" "define('FS_METHOD', 'direct');" "\/\* That's all, stop editing! Happy publishing. \*\/" "$PHP_CONF" +} + +Version(){ + VERSION=$(docker exec $DockerServName cat /var/www/html/wp-includes/version.php | grep "wp_version " | sed -e "s/.*version\s*=\s*[\"\']//" | sed "s/[\"\'].*//") + echo "Version $DockerServName : ${GREEN}${VERSION}${NC}" +} + + +_addVarBeforeInConf(){ + # $1 key + # $2 ligne à ajouter avant la ligne + # $3 where + # $4 fichier de conf php + if ! grep -q "$1" "${4}" ; then + echo -n " ${CYAN}${BOLD}$1${NC}" >& $QUIET + ${SIMU} sed -i -e "s/$3/$2\\n$3/" "${4}" + fi +} + +########## Main ################# +for ARG in "$@"; do + case "${ARG}" in + '-h' | '--help' ) + usage && exit ;; + '-n' | '--simu') + SIMU="echo" ;; + '-q' ) + QUIET="/dev/null" ;; + '--nas' | '-nas' ) + ONNAS="SURNAS" ;; + '-v' | '--version') + COMMANDS="$(echo "${COMMANDS} VERSION" | sed "s/\s/\n/g" | sort | uniq)" ;; + '-I' | '--install' ) + COMMANDS="$(echo "${COMMANDS} INIT" | sed "s/\s/\n/g" | sort | uniq)" ;; # le sed sort uniq, c'est pour pas l'avoir en double + '-*' ) # ignore + ;; + *) + ORGA="${ARG%-orga}" + DockerServName="${ORGA}-${wordpressServName}" + WPCOMMUN= + ;; + esac +done + +if [ -z "${COMMANDS}" ]; then usage && exit ; fi + +for COMMAND in ${COMMANDS}; do + case "${COMMAND}" in + 'VERSION' ) + Version && exit ;; + 'INIT' ) + Init ;; + esac +done \ No newline at end of file diff --git a/bin/restartAllCollabora.sh b/bin/restartAllCollabora.sh deleted file mode 100755 index 7e202de..0000000 --- a/bin/restartAllCollabora.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -# kan: 09/06/2022 -# ki: françois -# koi: redémarrer tous les collabora en cours pour récupérer de la RAM - -KAZ_ROOT=$(cd "$(dirname $0)/.."; pwd) -. "${KAZ_ROOT}/bin/.commonFunctions.sh" -setKazVars -. "${DOCKERS_ENV}" - -cd "${KAZ_COMP_DIR}" -for ORGA_DIR in *-orga; do - ORGA=${ORGA_DIR%-orga} - SERV_NAME="${ORGA}-${nextcloudServName}" - [[ "$(docker ps -f name=${SERV_NAME} | grep -w ${SERV_NAME})" ]] || continue - ( - echo restart collabora - ${ORGA} - cd "${KAZ_COMP_DIR}/${ORGA_DIR}" - docker-compose stop collabora - docker-compose start collabora - ) -done - diff --git a/bin/sauve_memory.sh b/bin/sauve_memory.sh index 680cb60..a83bd45 100755 --- a/bin/sauve_memory.sh +++ b/bin/sauve_memory.sh @@ -28,7 +28,7 @@ docker restart ethercalcDB ethercalcServ #docker exec sympaServ sendmail -q #pour restart cette s.... de collabora -/kaz/bin/restartAllCollabora.sh +/kaz/bin/gestContainers.sh -office -m -r #postfix docker exec -it mailServ supervisorctl restart changedetector diff --git a/bin/stop_start_all_cloud.sh b/bin/stop_start_all_cloud.sh deleted file mode 100755 index fdba83b..0000000 --- a/bin/stop_start_all_cloud.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -#date: 28/03/2022 -#ki: fab -#koi: relancer tous les clouds et collabora (pour regagner de la RAM/SWAP) - -KAZ_ROOT=$(cd "$(dirname $0)"/..; pwd) -. $KAZ_ROOT/bin/.commonFunctions.sh -setKazVars -. $DOCKERS_ENV -. $KAZ_ROOT/secret/SetAllPass.sh - -#tous les clouds -for cloud in $(docker ps | grep -i nextcloudServ |awk '{print $12}') -do - docker restart $cloud -done - -#tous les collabora -for colla in $(docker ps | grep -i officeServ |awk '{print $11}') -do - docker restart $colla -done diff --git a/bin/updateCloud.sh b/bin/updateCloud.sh deleted file mode 100755 index 0d3170f..0000000 --- a/bin/updateCloud.sh +++ /dev/null @@ -1,100 +0,0 @@ -#!/bin/bash - -KAZ_ROOT=$(cd $(dirname $0)/..; pwd) -. "${KAZ_ROOT}/bin/.commonFunctions.sh" -setKazVars - -cd $(dirname $0) -. "${DOCKERS_ENV}" - -available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "compose" "enable" "orga" 2>/dev/null | sed "s/-orga\b//g") -usage () { - echo "Usage: $0 orga" - echo " -n : simulation" - echo " [orga] : in ${available_orga}" - exit 1 -} - -case "$#" in - 0) - # common - CloudName="" - OFFICE_URL="${httpProto}://${officeHost}.${domain}" - DockerServName="${nextcloudServName}" - CONF_DIR="${DOCK_VOL}/cloud_cloudConfig/_data" - ;; - 1) - # orga - available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "compose" "enable" "orga" 2>/dev/null | sed "s/-orga\b//g") - [[ " ${available_orga} " =~ "$1" ]] || usage - ORGA=${1%-orga} - CloudName="${ORGA}" - OFFICE_URL="https://${ORGA}-${officeHost}.${domain}" - DockerServName="${ORGA}-${nextcloudServName}" - CONF_DIR="${DOCK_VOL}/orga_${ORGA}-cloudConfig/_data" - ;; - *) - usage - ;; -esac - -PHP_CONF="${CONF_DIR}/config.php" - -printKazMsg "update cloud config" -addVarInConf(){ - # $1 key - # $2 val - # $3 where - if ! grep -q "$1" "${PHP_CONF}" ; then - echo -n " ${CYAN}${BOLD}$1${NC}" - sed -i -e "/$3/a\ $2" "${PHP_CONF}" - fi -} - -printKazMsg "update ${CloudName}:" -echo -n " " -addVarInConf "default_language" " 'default_language' => 'fr'," "CONFIG = array (" - -addVarInConf "theme" " 'theme' => ''," "'installed' => true," -addVarInConf "default_phone_region" " 'default_phone_region' => 'FR'," "'installed' => true," -addVarInConf "loglevel" " 'loglevel' => 2," "'installed' => true," -addVarInConf "maintenance" " 'maintenance' => false," "'installed' => true," -addVarInConf "app_install_overwrite" " 'app_install_overwrite' => \n array (\n 0 => 'documents',\n )," "'installed' => true," -addVarInConf "overwriteprotocol" " 'overwriteprotocol' => 'https'," "'installed' => true," - -addVarInConf "mail_domain" " 'mail_domain' => 'kaz.bzh'," "'installed' => true," -addVarInConf "mail_from_address" " 'mail_from_address' => 'admin'," "'installed' => true," -addVarInConf "mail_smtpport" " 'mail_smtpport' => '25'," "'installed' => true," -addVarInConf "mail_sendmailmode" " 'mail_sendmailmode' => 'smtp'," "'installed' => true," -addVarInConf "mail_smtphost" " 'mail_smtphost' => 'smtp.kaz.bzh'," "'installed' => true," -addVarInConf "mail_smtpmode" " 'mail_smtpmode' => 'smtp'," "'installed' => true," -addVarInConf "enable_previews" " 'enable_previews' => true," "'installed' => true," -addVarInConf "trashbin_retention_obligation" " 'trashbin_retention_obligation' => '30, auto'," "'installed' => true," -#pour supprimer le message "obtenir un compte gratuit" dans le footer -addVarInConf "simpleSignUpLink.shown" " 'simpleSignUpLink.shown' => false," "'installed' => true," - -if ! [[ "$(docker ps -f name=${DockerServName} | grep -w ${DockerServName})" ]]; then - printKazError "DockerServName not running... abort" - exit -fi - -LIST_ALL=$(docker exec -ti -u 33 "${DockerServName}" /var/www/html/occ app:list | - awk 'BEGIN {cp=0} - /Enabled:/ {cp=1 ; next}; - /Disabled:/ {cp=0; next}; - {if (cp) print $0};') - -printKazMsg "add applications" -for app in tasks calendar bookmarks contacts mail richdocuments drawio rainloop -do - grep -wq "${app}" <<<"${LIST_ALL}" 2>/dev/null && continue - echo " install ${app}" - docker exec -ti -u 33 "${DockerServName}" /var/www/html/occ app:install "${app}" -done - -docker exec -ti -u 33 "${DockerServName}" /var/www/html/occ config:app:set --value "${OFFICE_URL}" richdocuments public_wopi_url -docker exec -ti -u 33 "${DockerServName}" /var/www/html/occ config:app:set --value "${OFFICE_URL}" richdocuments wopi_url -docker exec -ti -u 33 "${DockerServName}" /var/www/html/occ config:app:set --value "${OFFICE_URL}" richdocuments disable_certificate_verification - -# A tester... Didier : normalement elle fonctionne, mais bon ! -docker exec -ti -u 33 "${DockerServName}" /var/www/html/occ config:system:set overwrite.cli.url --value=https\:\/\/${ORGA}-cloud.kaz.bzh diff --git a/bin/updateCloudApp.sh b/bin/updateCloudApp.sh deleted file mode 100755 index 5c4c050..0000000 --- a/bin/updateCloudApp.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash -KAZ_ROOT=$(cd "$(dirname $0)"/..; pwd) -. $KAZ_ROOT/bin/.commonFunctions.sh -setKazVars -. $DOCKERS_ENV -. $KAZ_ROOT/secret/SetAllPass.sh - -LISTE_APPS="tasks calendar contacts bookmarks mail richdocuments richdocumentscode external drawio rainloop ransomware_protection" -NB_CLOUDS=$(ls /var/lib/docker/volumes/ | grep -i orga | grep -i cloudMain| sed -e 's/-cloudMain$//g' | sed -e 's/^orga_//' | wc -l ) -COMPTEUR=${NB_CLOUDS} - -usage() { - echo "Usage $0 -h -a -l" - echo "-a : met à jour tous les applications" - echo "-l : met à jour ces applications ${LISTE_APPS}" - echo "-h : Cette aide" - exit -} - - -ToutesApplis() { - echo -e "${NC}" - echo "Mise à jour de toutes les applis installées" - for cloud in $(docker ps | grep -i cloud |awk '{print $12}') - do - echo -e "${COMPTEUR}/${NB_CLOUDS} : ${cloud} " - echo -e "${GREEN}" - docker exec -ti -u 33 ${cloud} /var/www/html/occ app:update --all - echo -e "${NC}" - COMPTEUR=$(expr $COMPTEUR - 1) - done -} - -Liste_Apps() { - echo -e "${NC}" - echo "Mise à jour de ${LISTE_APPS}" - for cloud in $(docker ps | grep -i cloud |awk '{print $12}') - do - echo -e "${COMPTEUR}/${NB_CLOUDS} : ${cloud} " - for app in $(echo ${LISTE_APPS}) - do - echo -e "${GREEN} ${app} ${NC}" - docker exec -ti -u 33 ${cloud} /var/www/html/occ app:update ${app} - echo -e "${NC}" - done - COMPTEUR=$(expr $COMPTEUR - 1) - done -} - - -################### Main ################# - -case "$1" in - '-h'|'' ) - usage - exit - ;; - '-l' ) - Liste_Apps - exit - ;; - '-a' ) - ToutesApplis - exit - ;; - '*' ) - usage - exit - :: -esac - diff --git a/bin/updateWP.sh b/bin/updateWP.sh deleted file mode 100755 index b67d05e..0000000 --- a/bin/updateWP.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -KAZ_ROOT=$(cd $(dirname $0)/..; pwd) -. "${KAZ_ROOT}/bin/.commonFunctions.sh" -setKazVars - -cd $(dirname $0) -. "${DOCKERS_ENV}" - -available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "compose" "enable" "orga" 2>/dev/null | sed "s/-orga\b//g") -usage () { - echo "Usage: $0 orga" - echo " -n : simulation" - echo " [orga] : in ${available_orga}" - exit 1 -} - -case "$#" in - 1) - # orga - available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "compose" "enable" "orga" 2>/dev/null | sed "s/-orga\b//g") - [[ " ${available_orga} " =~ "$1" ]] || usage - ORGA=${1%-orga} - WPName="${ORGA}" - DockerServName="${ORGA}-${webServName}" - CONF_DIR="${DOCK_VOL}/orga_${ORGA}-wordpress/_data" - ;; - *) - usage - ;; -esac - -PHP_CONF="${CONF_DIR}/wp-config.php" - -addVarInWordPressConf(){ - # $1 key - # $2 ligne à ajouter avant la ligne $MOTIF - MOTIF="\/\* That's all, stop editing! Happy publishing. \*\/" - - if ! grep -q "$1" "${PHP_CONF}" ; then - echo -n " ${CYAN}${BOLD}$1${NC}" - sed -i -e "s/$MOTIF/$2\\n$MOTIF/" "${PHP_CONF}" - fi -} - -#/* pour forcer les maj autrement qu'en ftp */ -addVarInWordPressConf "FS_METHOD" "define('FS_METHOD', 'direct');" diff --git a/bin/upgradeCloud.sh b/bin/upgradeCloud.sh deleted file mode 100755 index f9c0cfd..0000000 --- a/bin/upgradeCloud.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash - -KAZ_ROOT=$(cd $(dirname $0)/..; pwd) -. "${KAZ_ROOT}/bin/.commonFunctions.sh" -setKazVars - -cd $(dirname $0) -. "${DOCKERS_ENV}" - -declare -a available_orga target_cloud -available_orga=$("${KAZ_BIN_DIR}/kazList.sh" "compose" "enable" "orga" 2>/dev/null | sed "s/-orga\b//g") -export SIMU="" -ALL="" -ERROR="" - -usage () { - echo "Usage: $0 [-n] [-all] orga..." - echo " -n : simulation" - echo " -all : simulation" - echo " [orga] : in ${available_orga}" - exit 1 -} - -upgradeNC () { - # $1 nextcloud ${orga}-nextcloud - if [ "$1" == "nextcloud" ]; then - ORGA="common" - [ -e "${DOCK_VOL}/cloud_cloudMain" ] || return - DockerServName="nextcloudServ" - else - #ORGA="$1" - ORGA=${1%-nextcloud} - [ -e "${DOCK_VOL}/orga_${ORGA}-cloudMain" ] || return - DockerServName="${ORGA}-nextcloudServ" - fi - echo "upgrade cloud ${BLUE}${ORGA}${NC}" - ${SIMU} docker exec -ti -u 33 ${DockerServName} /var/www/html/occ upgrade; -} - -for ARG in $@; do - case "${ARG}" in - '-h' | '-help' ) - usage - ;; - '-n' ) - export SIMU="echo" - ;; - '-all' ) - ALL="yes" - ;; - * ) - if [[ ! " ${available_orga[*]} " =~ " ${ARG} " ]]; then - echo "${RED}${ARG}${NC} not an orga" - ERROR="yes" - else - target_cloud+=("${ARG}-nextcloud") - fi - ;; - esac -done - -[ -n "${ERROR}" ] && usage - -if [ -n "${ALL}" ]; then - target_cloud=("nextcloud") - for orga in ${available_orga[@]}; do - target_cloud+=("${orga}-nextcloud") - done -fi -[ ${#target_cloud[@]} -eq 0 ] && target_cloud+=("nextcloud") - -for nc in ${target_cloud[@]}; do - upgradeNC "${nc}" -done diff --git a/config/orgaTmpl/app/Dockerfile b/config/orgaTmpl/app/Dockerfile index bcd3f26..539d978 100644 --- a/config/orgaTmpl/app/Dockerfile +++ b/config/orgaTmpl/app/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.10 +FROM alpine:3.17 # Some ENV variables ENV PATH="/mattermost/bin:${PATH}" diff --git a/config/orgaTmpl/docker-compose.yml b/config/orgaTmpl/docker-compose.yml index 11ce2a9..99d98e0 100644 --- a/config/orgaTmpl/docker-compose.yml +++ b/config/orgaTmpl/docker-compose.yml @@ -21,6 +21,11 @@ services: - ../../secret/env-${wordpressDBName} networks: - orgaNet + healthcheck: # utilisé par init-db.sh pour la créa d'orga + test: ["CMD", 'mysqladmin', 'ping', '-h', 'localhost', '-u', 'root', '-p$$MYSQL_ROOT_PASSWORD' ] + interval: 30s + timeout: 30s + retries: 5 #}} #{{cloud cloud: @@ -33,6 +38,8 @@ services: # - postfixNet depends_on: - db + #db: + # condition: service_healthy # on peut mais ca va ralentir le process links: - db external_links: @@ -115,6 +122,8 @@ services: - ${matterPort} depends_on: - db + #db: + # condition: service_healthy # on peut mais ca va ralentir le process links: - db external_links: @@ -151,6 +160,8 @@ services: # - postfixNet depends_on: - db + #db: + # condition: service_healthy # on peut mais ca va ralentir le process links: - db external_links: diff --git a/config/orgaTmpl/init-cloud.sh b/config/orgaTmpl/init-cloud.sh deleted file mode 100755 index b321998..0000000 --- a/config/orgaTmpl/init-cloud.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash - -KAZ_ROOT=$(cd $(dirname $0)/../..; pwd) -. "${KAZ_ROOT}/bin/.commonFunctions.sh" -setKazVars -. "${DOCKERS_ENV}" -. "${KAZ_KEY_DIR}/SetAllPass.sh" - -# begin commun service init -cd $(dirname $0) -PWD=$(pwd) -ORGA_DIR=$(basename ${PWD}) - -if [[ "${ORGA_DIR}" != *"-orga" ]] -then - printKazError "it's not an orga dir" - exit -fi -ORGA=${ORGA_DIR%-orga} -if [[ -z "${ORGA}" ]] -then - printKazError "it's not an orga dir" - exit -fi - -printKazMsg "init cloud ${ORGA}" - -CONF_DIR="${DOCK_VOL}/orga_${ORGA}-cloudConfig/_data" -PHP_CONF="${CONF_DIR}/config.php" - -CLOUD_URL="${httpProto}://${ORGA}-${cloudHost}.${domain}" -DockerServName="${ORGA}-${nextcloudServName}" - -if ! [[ "$(docker ps -f name=${DockerServName} | grep -w ${DockerServName})" ]]; then - printKazError "NextCloud not running... abort" - exit -fi - -echo " -CREATE DATABASE IF NOT EXISTS ${nextcloud_MYSQL_DATABASE}; - -DROP USER IF EXISTS '${nextcloud_MYSQL_USER}'; -CREATE USER '${nextcloud_MYSQL_USER}'@'%'; - -GRANT ALL ON ${nextcloud_MYSQL_DATABASE}.* TO '${nextcloud_MYSQL_USER}'@'%' IDENTIFIED BY '${nextcloud_MYSQL_PASSWORD}'; - -FLUSH PRIVILEGES;" | \ - docker exec -i ${ORGA}-DB bash -c "mysql --user=root --password=${nextcloud_MYSQL_ROOT_PASSWORD}" - -if ! grep -q "'installed' => true," "${PHP_CONF}" 2> /dev/null; then - printKazMsg "\n *** Premier lancement de NextCLoud" - - waitUrl "${CLOUD_URL}" - - printKazMsg "reset cloud ${ORGA}" - - curl -X POST \ - -d "install=true" \ - -d "adminlogin=${nextcloud_NEXTCLOUD_ADMIN_USER}" \ - -d "adminpass=${nextcloud_NEXTCLOUD_ADMIN_PASSWORD}" \ - -d "directory=/var/www/html/data" \ - -d "dbtype=mysql" \ - -d "dbuser=${nextcloud_MYSQL_USER}" \ - -d "dbpass=${nextcloud_MYSQL_PASSWORD}" \ - -d "dbname=${nextcloud_MYSQL_DATABASE}" \ - -d "dbhost=${nextcloud_MYSQL_HOST}" \ - -d "install-recommended-apps=true" \ - "${CLOUD_URL}" -fi - -"${KAZ_BIN_DIR}/updateCloud.sh" "${ORGA}" diff --git a/config/orgaTmpl/init-db.sh b/config/orgaTmpl/init-db.sh new file mode 100755 index 0000000..782c152 --- /dev/null +++ b/config/orgaTmpl/init-db.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +KAZ_ROOT=$(cd $(dirname $0)/../..; pwd) +. "${KAZ_ROOT}/bin/.commonFunctions.sh" +setKazVars +. "${DOCKERS_ENV}" +. "${KAZ_KEY_DIR}/SetAllPass.sh" + +cd $(dirname $0) +ORGA_DIR="$(basename "$(pwd)")" + +ORGA=${ORGA_DIR%-orga} +if [[ -z "${ORGA}" ]] +then + printKazError "it's not an orga dir" + exit +fi + + +waitContainerHealthy "${ORGA}-DB" 180 +[ $? -ne 0 ] && printKazError "\n La base de donnée démarre pas : impossible de terminer l'install" && exit + +SQL="" + +for ARG in "$@"; do + case "${ARG}" in + 'cloud' ) + SQL="$SQL +CREATE DATABASE IF NOT EXISTS ${nextcloud_MYSQL_DATABASE}; + +DROP USER IF EXISTS '${nextcloud_MYSQL_USER}'; +CREATE USER '${nextcloud_MYSQL_USER}'@'%'; + +GRANT ALL ON ${nextcloud_MYSQL_DATABASE}.* TO '${nextcloud_MYSQL_USER}'@'%' IDENTIFIED BY '${nextcloud_MYSQL_PASSWORD}'; + +FLUSH PRIVILEGES;" + ;; + 'agora' ) + SQL="$SQL +CREATE DATABASE IF NOT EXISTS ${mattermost_MYSQL_DATABASE}; + +DROP USER IF EXISTS '${mattermost_MYSQL_USER}'; +CREATE USER '${mattermost_MYSQL_USER}'@'%'; + +GRANT ALL ON ${mattermost_MYSQL_DATABASE}.* TO '${mattermost_MYSQL_USER}'@'%' IDENTIFIED BY '${mattermost_MYSQL_PASSWORD}'; + +FLUSH PRIVILEGES;" + ;; + 'wp' ) + SQL="$SQL +CREATE DATABASE IF NOT EXISTS ${wp_MYSQL_DATABASE}; + +DROP USER IF EXISTS '${wp_MYSQL_USER}'; +CREATE USER '${wp_MYSQL_USER}'@'%'; + +GRANT ALL ON ${wp_MYSQL_DATABASE}.* TO '${wp_MYSQL_USER}'@'%' IDENTIFIED BY '${wp_MYSQL_PASSWORD}'; + +FLUSH PRIVILEGES;" + ;; + esac +done + +echo $SQL | docker exec -i ${ORGA}-DB bash -c "mysql --user=root --password=${wp_MYSQL_ROOT_PASSWORD}" \ No newline at end of file diff --git a/config/orgaTmpl/init-matter.sh b/config/orgaTmpl/init-matter.sh deleted file mode 100755 index e4ea284..0000000 --- a/config/orgaTmpl/init-matter.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/bash - -KAZ_ROOT=$(cd $(dirname $0)/../..; pwd) -. "${KAZ_ROOT}/bin/.commonFunctions.sh" -setKazVars -. "${DOCKERS_ENV}" -. "${KAZ_KEY_DIR}/SetAllPass.sh" - -# begin commun service init -cd $(dirname $0) -PWD=$(pwd) -ORGA_DIR=$(basename ${PWD}) - -if [[ "${ORGA_DIR}" != *"-orga" ]] -then - printKazError "it's not an orga dir" - exit -fi -ORGA=${ORGA_DIR%-orga} -if [[ -z "${ORGA}" ]] -then - printKazError "it's not an orga dir" - exit -fi - -printKazMsg "init agora ${ORGA}" - -CONF_DIR="${VOL_DIR}/orga_${ORGA}-matterConfig/_data" -JSON_CONF="${CONF_DIR}/config.json" -MATTER_URI="${ORGA}-${matterHost}.${domain}" -MATTER_URL="${httpProto}://${MATTER_URI}" -ORGA_FLAG="${ORGA_DIR//-/_}" -DockerServName="${ORGA_FLAG}-${mattermostServName}" - -if ! [[ "$(docker ps -f name=${DockerServName} | grep -w ${DockerServName})" ]]; then - printKazError "Agora not running... abort" - exit -fi - -echo " -CREATE DATABASE IF NOT EXISTS ${mattermost_MYSQL_DATABASE}; - -DROP USER IF EXISTS '${mattermost_MYSQL_USER}'; -CREATE USER '${mattermost_MYSQL_USER}'@'%'; - -GRANT ALL ON ${mattermost_MYSQL_DATABASE}.* TO '${mattermost_MYSQL_USER}'@'%' IDENTIFIED BY '${mattermost_MYSQL_PASSWORD}'; - -FLUSH PRIVILEGES;" | \ - docker exec -i "${ORGA}-DB" bash -c "mysql --user=root --password=${mattermost_MYSQL_ROOT_PASSWORD}" - - -getToken(){ - curl -i -s -d "{\"login_id\":\"${mattermost_MM_ADMIN_USER}\",\"password\":\"${mattermost_MM_ADMIN_PASSWORD}\"}" "${MATTER_URL}/api/v4/users/login" | grep 'token' | sed 's/token:\s*\(.*\)\s*/\1/' | tr -d '\r' -} - -waitUrl "${MATTER_URL}" -[ -z "$(getToken)" ] || exit - -printKazMsg "\n *** Premier lancement de Mattermost" - - -# XXX utiliser le compte de l'admin -curl -i -d "{\"email\":\"${mattermost_MM_ADMIN_EMAIL}\",\"username\":\"${mattermost_MM_ADMIN_USER}\",\"password\":\"${mattermost_MM_ADMIN_PASSWORD}\",\"allow_marketing\":true}" "${MATTER_URL}/api/v4/users" - -waitUrl "${MATTER_URL}" -MM_TOKEN=$(getToken) - -curl -i -H "Authorization: Bearer ${MM_TOKEN}" -d "{\"display_name\":\"${ORGA}\",\"name\":\"${ORGA,,}\",\"type\":\"O\"}" "${MATTER_URL}/api/v4/teams" - -sed -i \ - -e 's|"SiteURL": ".*"|"SiteURL": "'${MATTER_URL}'"|g' \ - -e 's|"WebsocketURL": ".*"|"WebsocketURL": "wss://'${MATTER_URI}'"|g' \ - -e 's|"AllowCorsFrom": ".*"|"AllowCorsFrom": "'${domain}' '${MATTER_URI}':443 '${MATTER_URI}'"|g' \ - -e 's|"ConsoleLevel": ".*"|"ConsoleLevel": "ERROR"|g' \ - -e 's|"SendEmailNotifications": false|"SendEmailNotifications": true|g' \ - -e 's|"FeedbackEmail": ".*"|"FeedbackEmail": "admin@'${domain}'"|g' \ - -e 's|"FeedbackOrganization": ".*"|"FeedbackOrganization": "Cochez la KAZ du libre !"|g' \ - -e 's|"ReplyToAddress": ".*"|"ReplyToAddress": "admin@'${domain}'"|g' \ - -e 's|"SMTPServer": ".*"|"SMTPServer": "mail.'${domain}'"|g' \ - -e 's|"SMTPPort": ".*"|"SMTPPort": "25"|g' \ - -e 's|"DefaultServerLocale": ".*"|"DefaultServerLocale": "fr"|g' \ - -e 's|"DefaultClientLocale": ".*"|"DefaultClientLocale": "fr"|g' \ - -e 's|"AvailableLocales": ".*"|"AvailableLocales": "fr"|g' \ - ${JSON_CONF} - -# "jitsi": { -# "jitsiappid": null, -# "jitsiappsecret": null, -# "jitsicompatibilitymode": false, -# "jitsiembedded": false, -# "jitsijwt": null, -# "jitsilinkvalidtime": 30, -# "jitsinamingscheme": "words", -# "jitsiurl": "https://meet.jit.si", -# "Enable": true -# } diff --git a/config/orgaTmpl/init-wiki.sh b/config/orgaTmpl/init-wiki.sh deleted file mode 100755 index 47d8cbe..0000000 --- a/config/orgaTmpl/init-wiki.sh +++ /dev/null @@ -1,81 +0,0 @@ -#!/bin/bash - -KAZ_ROOT=$(cd $(dirname $0)/../..; pwd) -. "${KAZ_ROOT}/bin/.commonFunctions.sh" -setKazVars -. "${DOCKERS_ENV}" -. "${KAZ_KEY_DIR}/SetAllPass.sh" - -cd $(dirname $0) -PWD=$(pwd) -ORGA_DIR=$(basename ${PWD}) - -if [[ "${ORGA_DIR}" != *"-orga" ]] -then - printKazError "it's not an orga dir" - exit -fi -ORGA=${ORGA_DIR%-orga} -if [[ -z "${ORGA}" ]] -then - printKazError "it's not an orga dir" - exit -fi - -TPL_DIR="${DOCK_VOL}/orga_${ORGA}-wikiLibtpl/_data" -PLG_DIR="${DOCK_VOL}/orga_${ORGA}-wikiPlugins/_data" -CONF_DIR="${DOCK_VOL}/orga_${ORGA}-wikiConf/_data" -DNLD_DIR="${KAZ_DNLD_DIR}/dokuwiki" -DockerServName="${ORGA}-${dokuwikiServName}" -WIKI_URL="${httpProto}://${ORGA}-${dokuwikiHost}.${domain}" - -WIKI_TITLE=Kaz -WIKI_ROOT=Kaz -WIKI_EMAIL=wiki@kaz.local -WIKI_PASS=azerty - - -printKazMsg "init wiki ${ORGA}" - -if ! [[ "$(docker ps -f name=${DockerServName} | grep -w ${DockerServName})" ]]; then - printKazError "Dokuwiki not running... abort" - exit -fi - -if [ ! -f "${CONF_DIR}/local.php" ] ; then - printKazMsg "\n *** Premier lancement de Dokuwiki" - - waitUrl "${WIKI_URL}" - - curl -X POST \ - -d "l=fr" \ - -d "d[title]=${WIKI_TITLE}" \ - -d "d[acl]=true" \ - -d "d[superuser]=${WIKI_ROOT}" \ - -d "d[fullname]=Admin"\ - -d "d[email]=${WIKI_EMAIL}" \ - -d "d[password]=${WIKI_PASS}" \ - -d "d[confirm]=${WIKI_PASS}" \ - -d "d[policy]=1" \ - -d "d[allowreg]=false" \ - -d "d[license]=lic_0" \ - -d "d[pop]=false" \ - "${WIKI_URL}/install.php" - - - unzipInDir "${DNLD_DIR}/docnavwiki.zip" "${TPL_DIR}/" - chown -R www-data: "${TPL_DIR}/" - - for plugin in captcha ckgedit smtp todo wrap wrapadd; do - unzipInDir "${DNLD_DIR}/${plugin}.zip" "${PLG_DIR}" - done - chown -R www-data: "${PLG_DIR}/" - - cd wiki-conf - # XXX initialiser admin::admin::admin,user - rsync -auHAX local.php users.auth.php acl.auth.php "${CONF_DIR}/" - chown -R www-data: "${CONF_DIR}/" - - sed -i -e "s|\(.*conf\['title'\].*=.*'\).*';|\1${ORGA}';|g" "${CONF_DIR}/local.php" - sed -i -e "s|\(.*conf\['lang'\].*=.*'\)en';|\1fr';|g" "${CONF_DIR}/dokuwiki.php" -fi diff --git a/config/orgaTmpl/init-wp.sh b/config/orgaTmpl/init-wp.sh deleted file mode 100755 index 3b372ad..0000000 --- a/config/orgaTmpl/init-wp.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash - -KAZ_ROOT=$(cd $(dirname $0)/../..; pwd) -. "${KAZ_ROOT}/bin/.commonFunctions.sh" -setKazVars -. "${DOCKERS_ENV}" -. "${KAZ_KEY_DIR}/SetAllPass.sh" - -cd $(dirname $0) -PWD=$(pwd) -ORGA_DIR=$(basename ${PWD}) -VOL_DIR=/var/lib/docker/volumes - -if [[ "${ORGA_DIR}" != *"-orga" ]] -then - printKazError "it's not an orga dir" - exit -fi -ORGA=${ORGA_DIR%-orga} -if [[ -z "${ORGA}" ]] -then - printKazError "it's not an orga dir" - exit -fi - -printKazMsg "init wordpress ${ORGA}" - -CONF_DIR="${VOL_DIR}/orga_${ORGA}-wordpress/_data" -WP_URL="${httpProto}://${ORGA}-${wordpressHost}.${domain}" -DockerServName="${ORGA}-${wordpressServName}" - -if ! [[ "$(docker ps -f name=${DockerServName} | grep -w ${DockerServName})" ]]; then - printKazError "Wordpress not running... abort" - exit -fi - -echo " -CREATE DATABASE IF NOT EXISTS ${wp_MYSQL_DATABASE}; - -DROP USER IF EXISTS '${wp_MYSQL_USER}'; -CREATE USER '${wp_MYSQL_USER}'@'%'; - -GRANT ALL ON ${wp_MYSQL_DATABASE}.* TO '${wp_MYSQL_USER}'@'%' IDENTIFIED BY '${wp_MYSQL_PASSWORD}'; - -FLUSH PRIVILEGES;" | \ - docker exec -i ${ORGA}-DB bash -c "mysql --user=root --password=${wp_MYSQL_ROOT_PASSWORD}" - -# XXX trouver un test du genre if ! grep -q "'installed' => true," "${PHP_CONF}" 2> /dev/null; then -printKazMsg "\n *** Premier lancement de WP" - -waitUrl "${WP_URL}" - -printKazMsg "reset wp ${ORGA}" - -curl -X POST \ - -d "user_name=${wp_WORDPRESS_ADMIN_USER}" \ - -d "admin_password=${wp_WORDPRESS_ADMIN_PASSWORD}" \ - -d "admin_password2=${wp_WORDPRESS_ADMIN_PASSWORD}" \ - -d "pw_weak=true" \ - -d "admin_email=admin@kaz.bzh" \ - -d "blog_public=0" \ - -d "language=fr_FR" \ - "${WP_URL}/wp-admin/install.php?step=2" -echo diff --git a/config/orgaTmpl/orga-gen.sh b/config/orgaTmpl/orga-gen.sh index a796c6a..7b500a4 100755 --- a/config/orgaTmpl/orga-gen.sh +++ b/config/orgaTmpl/orga-gen.sh @@ -150,6 +150,8 @@ if [[ -f docker-compose.yml ]]; then fi fi +DBaInitialiser="" + for ARG in "$@"; do case "${ARG}" in '-show' ) @@ -192,18 +194,21 @@ for ARG in "$@"; do '+cloud' ) cloud="on" collabora="on" + DBaInitialiser="$DBaInitialiser cloud" ;; '+coll'* | '+offi'* ) collabora="on" ;; '+matter'* | '+agora' ) agora="on" + DBaInitialiser="$DBaInitialiser agora" ;; '+wiki' ) wiki="on" ;; '+wp' | '+word'* ) wp="on" + DBaInitialiser="$DBaInitialiser wp" ;; [.0-9]*[GMk] ) quota="${ARG}" @@ -365,14 +370,11 @@ if [[ -n "${STAGE_DEFAULT}${STAGE_CREATE}" ]]; then ln -sf ../../config/orgaTmpl/orga-gen.sh ln -sf ../../config/orgaTmpl/orga-rm.sh ln -sf ../../config/orgaTmpl/init-garradin.sh - ln -sf ../../config/orgaTmpl/init-matter.sh - ln -sf ../../config/orgaTmpl/init-cloud.sh - ln -sf ../../config/orgaTmpl/init-wiki.sh - ln -sf ../../config/orgaTmpl/init-wp.sh ln -sf ../../config/orgaTmpl/initdb.d/ ln -sf ../../config/orgaTmpl/app/ ln -sf ../../config/orgaTmpl/wiki-conf/ ln -sf ../../config/orgaTmpl/reload.sh + ln -sf ../../config/orgaTmpl/init-db.sh fi if [[ -n "${STAGE_DEFAULT}${STAGE_CREATE}" ]]; then @@ -439,15 +441,19 @@ if [[ -n "${STAGE_DEFAULT}" ]]; then fi if [[ -n "${STAGE_DEFAULT}${STAGE_INIT}" ]]; then + [ -z "$DBaInitialiser" ] || ./init-db.sh $DBaInitialiser # ########## init services [[ "${garradin}" = "on" ]] && ./init-garradin.sh + + initCmd="--install" # XXX risque d'écraser user DB - [[ "${cloud}" = "on" ]] && ./init-cloud.sh + [[ "${cloud}" = "on" ]] && initCmd="$initCmd -cloud" # XXX risque d'écraser user DB - [[ "${wp}" = "on" ]] && ./init-wp.sh - [[ "${wiki}" = "on" ]] && ./init-wiki.sh + [[ "${wp}" = "on" ]] && initCmd="$initCmd -wp" + [[ "${wiki}" = "on" ]] && initCmd="$initCmd -wiki" # XXX risque d'écraser user DB - [[ "${agora}" = "on" ]] && ./init-matter.sh + [[ "${agora}" = "on" ]] && initCmd="$initCmd -agora" + ${KAZ_BIN_DIR}/gestContainers.sh $initCmd "${ORGA}" fi if [[ -n "${STAGE_DEFAULT}" ]]; then diff --git a/config/orgaTmpl/orga-migrate.sh b/config/orgaTmpl/orga-migrate.sh deleted file mode 100755 index 5b97d00..0000000 --- a/config/orgaTmpl/orga-migrate.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash - -#kan: 06/10/2022 -#koi: recopie les volumes d'une orga depuis l'emplacement originel vers un autre emplacement. Utile quand on n'a plus de place sur le disque principal. -#ki : fab - -KAZ_ROOT=$(cd "$(dirname $0)/../.."; pwd) -. "${KAZ_ROOT}/bin/.commonFunctions.sh" -setKazVars - -cd $(dirname $0) - -PWD=$(pwd) -ORGA_DIR=$(basename ${PWD}) - -if [[ "${ORGA_DIR}" != *"-orga" ]] -then - echo "it's not an orga dir" - exit -fi -ORGA=${ORGA_DIR%-orga} - -REP_SOURCE="/var/lib/docker/volumes/" -REP_DISTANT="/mnt/disk-nas1/docker/volumes/" - -docker-compose down - -#******************************** -# de REP_SOURCE vers REP_DISTANT -#******************************** - -#on fait du propre dans le rep distant -rm ${REP_DISTANT}orga_${ORGA}-* -rf -# on ramène toutes les data de l'orga dans le rep distant -cp -a ${REP_SOURCE}orga_${ORGA}-* ${REP_DISTANT} -#une fois copiés, on vire tout du rep source -rm ${REP_SOURCE}orga_${ORGA}-* -rf - -#on crée les liens dans le rep source -for volume in $(ls ${REP_DISTANT}); -do - if [[ ${volume} == *orga_${ORGA}-* ]] - then - ln -s ${REP_DISTANT}${volume} ${REP_SOURCE}${volume} - fi -done; - -#************************************************ -# machine arrière: de REP_DISTANT vers REP_SOURCE -#************************************************ - -#on vire les liens présent en source -#rm ${REP_SOURCE}orga_${ORGA}-* -f -#on copie en gardant les permissions et owner -#cp -a ${REP_DISTANT}orga_${ORGA}-* ${REP_SOURCE} -#une fois copiés, on vire tout du rep distant -#rm ${REP_DISTANT}orga_${ORGA}-* -rf - -docker-compose up -d -availableProxyComposes=($(getList "${KAZ_CONF_DIR}/container-proxy.list")) -for item in "${availableProxyComposes[@]}"; do - ${KAZ_COMP_DIR}/${item}/reload.sh -done diff --git a/config/orgaTmpl/reload.sh b/config/orgaTmpl/reload.sh index 8fff947..7488206 100755 --- a/config/orgaTmpl/reload.sh +++ b/config/orgaTmpl/reload.sh @@ -11,9 +11,5 @@ PWD=$(pwd) ORGA_DIR=$(basename ${PWD}) ORGA=${ORGA_DIR%-orga} -DockerServName="${ORGA}-${dokuwikiServName}" -if [ -f "${DOCK_VOL}/orga_${ORGA}-wikiData/_data/farms/init.sh" ]; then - docker exec -ti ${DockerServName} /dokuwiki/data/farms/init.sh - pkill -KILL lighttpd -fi +${KAZ_BIN_DIR}/manageWiki.sh --reload $ORGA \ No newline at end of file diff --git a/dockers/cloud/first.sh b/dockers/cloud/first.sh index 1740ddd..cab49a8 100755 --- a/dockers/cloud/first.sh +++ b/dockers/cloud/first.sh @@ -7,96 +7,4 @@ setKazVars . $KAZ_ROOT/secret/SetAllPass.sh -"${KAZ_BIN_DIR}/initCloud.sh" - -docker exec -ti -u 33 nextcloudServ /var/www/html/occ app:enable user_ldap -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:delete-config s01 -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:create-empty-config -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapAgentName cn=cloud,ou=applications,${ldap_root} -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapAgentPassword ${ldap_LDAP_CLOUD_PASSWORD} -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapAgentPassword ${ldap_LDAP_CLOUD_PASSWORD} -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapBase ${ldap_root} -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapBaseGroups ${ldap_root} -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapBaseUsers ou=users,${ldap_root} -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapExpertUsernameAttr identifiantKaz -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapHost ${ldapServName} -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapPort 389 -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapTLS 0 -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapLoginFilter "(&(objectclass=nextcloudAccount)(|(cn=%uid)(identifiantKaz=%uid)))" -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapQuotaAttribute nextcloudQuota -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapUserFilter "(&(objectclass=nextcloudAccount)(nextcloudEnabled=TRUE))" -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapUserFilterObjectclass nextcloudAccount -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapEmailAttribute mail -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapUserDisplayName cn -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapUserFilterMode 1 -docker exec -ti -u 33 nextcloudServ /var/www/html/occ ldap:set-config s01 ldapConfigurationActive 1 - -# Dans le mariadb, pour permettre au ldap de reprendre la main : delete from oc_users where uid<>'admin'; -# docker exec -i nextcloudDB mysql --user= --password= <<< "delete from oc_users where uid<>'admin';" - -# Doc : https://help.nextcloud.com/t/migration-to-ldap-keeping-users-and-data/13205 - -# Exemple de table/clés : -# +-------------------------------+----------------------------------------------------------+ -# | Configuration | s01 | -# +-------------------------------+----------------------------------------------------------+ -# | hasMemberOfFilterSupport | 0 | -# | homeFolderNamingRule | | -# | lastJpegPhotoLookup | 0 | -# | ldapAgentName | cn=cloud,ou=applications,dc=kaz,dc=sns | -# | ldapAgentPassword | *** | -# | ldapAttributesForGroupSearch | | -# | ldapAttributesForUserSearch | | -# | ldapBackgroundHost | | -# | ldapBackgroundPort | | -# | ldapBackupHost | | -# | ldapBackupPort | | -# | ldapBase | ou=users,dc=kaz,dc=sns | -# | ldapBaseGroups | ou=users,dc=kaz,dc=sns | -# | ldapBaseUsers | ou=users,dc=kaz,dc=sns | -# | ldapCacheTTL | 600 | -# | ldapConfigurationActive | 1 | -# | ldapConnectionTimeout | 15 | -# | ldapDefaultPPolicyDN | | -# | ldapDynamicGroupMemberURL | | -# | ldapEmailAttribute | mail | -# | ldapExperiencedAdmin | 0 | -# | ldapExpertUUIDGroupAttr | | -# | ldapExpertUUIDUserAttr | | -# | ldapExpertUsernameAttr | uid | -# | ldapExtStorageHomeAttribute | | -# | ldapGidNumber | gidNumber | -# | ldapGroupDisplayName | cn | -# | ldapGroupFilter | | -# | ldapGroupFilterGroups | | -# | ldapGroupFilterMode | 0 | -# | ldapGroupFilterObjectclass | | -# | ldapGroupMemberAssocAttr | | -# | ldapHost | ldap | -# | ldapIgnoreNamingRules | | -# | ldapLoginFilter | (&(|(objectclass=nextcloudAccount))(cn=%uid)) | -# | ldapLoginFilterAttributes | | -# | ldapLoginFilterEmail | 0 | -# | ldapLoginFilterMode | 0 | -# | ldapLoginFilterUsername | 1 | -# | ldapMatchingRuleInChainState | unknown | -# | ldapNestedGroups | 0 | -# | ldapOverrideMainServer | | -# | ldapPagingSize | 500 | -# | ldapPort | 389 | -# | ldapQuotaAttribute | nextcloudQuota | -# | ldapQuotaDefault | | -# | ldapTLS | 0 | -# | ldapUserAvatarRule | default | -# | ldapUserDisplayName | cn | -# | ldapUserDisplayName2 | | -# | ldapUserFilter | (&(objectclass=nextcloudAccount)(nextcloudEnabled=TRUE)) | -# | ldapUserFilterGroups | | -# | ldapUserFilterMode | 1 | -# | ldapUserFilterObjectclass | nextcloudAccount | -# | ldapUuidGroupAttribute | auto | -# | ldapUuidUserAttribute | auto | -# | turnOffCertCheck | 0 | -# | turnOnPasswordChange | 0 | -# | useMemberOfToDetectMembership | 1 | -# +-------------------------------+----------------------------------------------------------+ +${KAZ_BIN_DIR}/gestContainers.sh --install -M -cloud diff --git a/dockers/dokuwiki/first.sh b/dockers/dokuwiki/first.sh index 3175f0f..b014df3 100755 --- a/dockers/dokuwiki/first.sh +++ b/dockers/dokuwiki/first.sh @@ -7,4 +7,4 @@ setKazVars cd $(dirname $0) . "${DOCKERS_ENV}" -"${KAZ_BIN_DIR}/initWiki.sh" +"${KAZ_BIN_DIR}/gestContainers.sh" -M -I -wiki diff --git a/dockers/mattermost/first.sh b/dockers/mattermost/first.sh index 56f3991..46b81be 100755 --- a/dockers/mattermost/first.sh +++ b/dockers/mattermost/first.sh @@ -8,26 +8,6 @@ cd $(dirname $0) . "${DOCKERS_ENV}" . "${KAZ_KEY_DIR}/SetAllPass.sh" -"${KAZ_BIN_DIR}/initAgora.sh" +"${KAZ_BIN_DIR}/gestContainers.sh" --install -M -agora -printKazMsg "\n *** copy favicon de Mattermost" - -cd images -MAT_VOL="${DOCK_VOL}/matterIcons/_data" -if [ -d "${MAT_VOL}/favicon" ]; then - - rsync -a logo_email* "${MAT_VOL}/" - rsync -a kaz-tete-192.png "${MAT_VOL}/favicon/android-chrome-192x192.png" - for dim in 152 57 60 72 76 120 144; do - rsync -a "kaz-tete-${dim}.png" "${MAT_VOL}/favicon/apple-touch-icon-${dim}x${dim}.png" - done - for dim in 16 32 96; do - rsync -a "kaz-tete-${dim}.png" "${MAT_VOL}/favicon/favicon-${dim}x${dim}.png" - done - for dim in 16 24 32 64 96; do - rsync -a "kaz-tete-${dim}.png" "${MAT_VOL}/favicon/favicon-default-${dim}x${dim}.png" - rsync -a "kaz-tete-rouge-${dim}.png" "${MAT_VOL}/favicon/favicon-mentions-${dim}x${dim}.png" - rsync -a "kaz-tete-bleu-${dim}.png" "${MAT_VOL}/favicon/favicon-unread-${dim}x${dim}.png" - done -fi diff --git a/secret.tmpl/SetAllPass.sh b/secret.tmpl/SetAllPass.sh index 51114ac..5a19f60 100755 --- a/secret.tmpl/SetAllPass.sh +++ b/secret.tmpl/SetAllPass.sh @@ -279,3 +279,11 @@ vaultwarden_ADMIN_TOKEN="--clean_val--" traefik_DASHBOARD_USER="admin" traefik_DASHBOARD_PASSWORD="--clean_val--" + + +##################### +# dokuwiki + +dokuwiki_WIKI_ROOT=Kaz +dokuwiki_WIKI_EMAIL=wiki@kaz.local +dokuwiki_WIKI_PASSWORD="--clean_val--" \ No newline at end of file diff --git a/secret.tmpl/env-dokuwikiServ b/secret.tmpl/env-dokuwikiServ new file mode 100644 index 0000000..35e8c91 --- /dev/null +++ b/secret.tmpl/env-dokuwikiServ @@ -0,0 +1,4 @@ + +WIKI_ROOT= +WIKI_EMAIL= +WIKI_PASSWORD= \ No newline at end of file