diff --git a/functions/00_generateConf b/functions/00_generateConf index 769c0fe..3096c2e 100644 --- a/functions/00_generateConf +++ b/functions/00_generateConf @@ -11,11 +11,11 @@ function generateConf echo '[CONFIGURATION]' > "$CONF" echo 'PROFILE="Bare-metal"' >> "$CONF" echo 'ENV="prod"' >> "$CONF" - echo 'MAIL_ENABLED="no"' >> "$CONF" + echo 'MAIL_ENABLED="false"' >> "$CONF" echo 'MAIL_RECIPIENT=""' >> "$CONF" echo -e '\n[SOFTWARE CONFIGURATION]' >> "$CONF" echo 'EXCLUDE_MAJOR=""' >> "$CONF" echo 'EXCLUDE=""' >> "$CONF" - echo 'NEED_RESTART=""' >> "$CONF" + echo 'SERVICE_RESTART=""' >> "$CONF" } \ No newline at end of file diff --git a/functions/00_get-conf b/functions/00_get-conf index 0d95761..f2a355b 100644 --- a/functions/00_get-conf +++ b/functions/00_get-conf @@ -1,32 +1,34 @@ #!/usr/bin/env bash -# Récupération de la conf renseignée dans linupdate.conf +# Retrieve configuration from linupdate.conf function getConf { - # Si le fichier de configuration n'existe pas alors on quitte + # If config file doesn't exist, exit if [ ! -f "$CONF" ];then echo -e "[${YELLOW} ERROR ${RESET}] No config file was found on this server. Use --install param to finalize linupdate installation.\n" (( UPDATE_ERROR++ )) - # On supprime le fichier de log, inutile + + # Delete log file rm "$LOG" -f clean_exit fi - PROFILE=$(egrep "^PROFILE=" "$CONF" | cut -d'=' -f 2 | sed 's/"//g') # Type de serveur - SERVER_ENV=$(egrep "^ENV=" "$CONF" | cut -d'=' -f 2 | sed 's/"//g') # Env - MAIL_ENABLED=$(egrep "^MAIL_ENABLED=" "$CONF" | cut -d'=' -f 2 | sed 's/"//g') - MAIL_RECIPIENT=$(egrep "^MAIL_RECIPIENT=" "$CONF" | cut -d'=' -f 2 | sed 's/"//g') - CONF_SOFT_EXCLUDE_MAJOR=$(egrep "^EXCLUDE_MAJOR=" "$CONF" | cut -d'=' -f 2 | sed 's/"//g') # Paquets critiques à exclure en cas de maj majeure - CONF_SOFT_EXCLUDE=$(egrep "^EXCLUDE=" "$CONF" | cut -d'=' -f 2 | sed 's/"//g') # Paquets critiques à exclure dans tous les cas - CONF_SOFT_NEED_RESTART=$(egrep "^NEED_RESTART=" "$CONF" | cut -d'=' -f 2 | sed 's/"//g') # Paquets critiques ou non à redémarrer + PROFILE=$(egrep "^PROFILE=" "$CONF" | cut -d'=' -f 2 | sed 's/"//g') # Profile name + ENV=$(egrep "^ENV=" "$CONF" | cut -d'=' -f 2 | sed 's/"//g') # Environment + MAIL_ENABLED=$(egrep "^MAIL_ENABLED=" "$CONF" | cut -d'=' -f 2 | sed 's/"//g') # Enable mail notification + MAIL_RECIPIENT=$(egrep "^MAIL_RECIPIENT=" "$CONF" | cut -d'=' -f 2 | sed 's/"//g') # Mail recipient + PACKAGES_EXCLUDE_MAJOR=$(egrep "^EXCLUDE_MAJOR=" "$CONF" | cut -d'=' -f 2 | sed 's/"//g') # Packages to exclude on a major update + PACKAGES_EXCLUDE=$(egrep "^EXCLUDE=" "$CONF" | cut -d'=' -f 2 | sed 's/"//g') # Packages to always exclude + SERVICE_RESTART=$(egrep "^SERVICE_RESTART=" "$CONF" | cut -d'=' -f 2 | sed 's/"//g') # Services to restart after update if [ -z "$PROFILE" ];then echo -e "[${RED} ERROR ${RESET}] No profile is defined\n" (( UPDATE_ERROR++ )) clean_exit fi - if [ -z "$SERVER_ENV" ];then - echo -e "[${RED} ERROR ${RESET}] No env is defined\n" + + if [ -z "$ENV" ];then + echo -e "[${RED} ERROR ${RESET}] No environment is defined\n" (( UPDATE_ERROR++ )) clean_exit fi diff --git a/functions/00_space-left b/functions/00_space-left index 3cef256..da8ffe3 100644 --- a/functions/00_space-left +++ b/functions/00_space-left @@ -9,7 +9,7 @@ function spaceLeft if [ "$SPACE_LEFT" -lt 1000000 ];then echo -ne "${RED}"; df -h | egrep "/$" | awk '{print $4}'; echo -ne "${RESET}" (( UPDATE_ERROR++ )) - if [ "$MAIL_ENABLED" -eq "yes" ];then + if [ "$MAIL_ENABLED" -eq "true" ];then sendMail fi clean_exit diff --git a/functions/02_check-packages-before-update b/functions/02_check-packages-before-update index 02825bc..17370ae 100644 --- a/functions/02_check-packages-before-update +++ b/functions/02_check-packages-before-update @@ -82,17 +82,17 @@ function checkPackagesBeforeUpdate #  trouvées quoi qu'il arrive. # Process packages to exclude on major release update (EXCLUDE_MAJOR): - if [ ! -z "$CONF_SOFT_EXCLUDE_MAJOR" ];then + if [ ! -z "$PACKAGES_EXCLUDE_MAJOR" ];then - PACKAGES_EXCLUDE_MAJOR="" + PACKAGES_EXCLUDE_MAJOR_ARRAY="" IFS=',' - # Inject exclusion list into PACKAGES_EXCLUDE_MAJOR - read -ra PACKAGES_EXCLUDE_MAJOR <<< "$CONF_SOFT_EXCLUDE_MAJOR" + # Inject exclusion list into PACKAGES_EXCLUDE_MAJOR_ARRAY + read -ra PACKAGES_EXCLUDE_MAJOR_ARRAY <<< "$PACKAGES_EXCLUDE_MAJOR" - # Run through all packages in PACKAGES_EXCLUDE_MAJOR + # Run through all packages in PACKAGES_EXCLUDE_MAJOR_ARRAY # For each package name, check if an update is available by looking in $CHECK_UPDATE_TMP - for PACKAGE in "${PACKAGES_EXCLUDE_MAJOR[@]}"; do + for PACKAGE in "${PACKAGES_EXCLUDE_MAJOR_ARRAY[@]}"; do # If package occurence is found in $CHECK_UPDATE_TMP, then it means that an update is available for this package # We will have to check if it is a major release update or a minor release update @@ -173,17 +173,17 @@ function checkPackagesBeforeUpdate fi # Process packages to exclude no matter the release update, they always have to be excluded. - if [ ! -z "$CONF_SOFT_EXCLUDE" ];then + if [ ! -z "$PACKAGES_EXCLUDE" ];then - PACKAGES_EXCLUDE="" + PACKAGES_EXCLUDE_ARRAY="" IFS=',' - # Inject exclusion list into PACKAGES_EXCLUDE - read -ra PACKAGES_EXCLUDE <<< "$CONF_SOFT_EXCLUDE" + # Inject exclusion list into PACKAGES_EXCLUDE_ARRAY + read -ra PACKAGES_EXCLUDE_ARRAY <<< "$PACKAGES_EXCLUDE" - # Run through all packages in PACKAGES_EXCLUDE_MAJOR + # Run through all packages in PACKAGES_EXCLUDE # For each package name, check if an update is available by looking in $CHECK_UPDATE_TMP - for PACKAGE in "${PACKAGES_EXCLUDE[@]}";do + for PACKAGE in "${PACKAGES_EXCLUDE_ARRAY[@]}";do # If package occurence is found in $CHECK_UPDATE_TMP, then it means that an update is available for this package # It will be excluded @@ -214,18 +214,38 @@ function checkPackagesBeforeUpdate fi # Process services that will need a restart after packages update - if [ ! -z "$CONF_SOFT_NEED_RESTART" ];then + if [ ! -z "$SERVICE_RESTART" ];then OLD_IFS=$IFS IFS=',' # Inject services list into SERVICES_TO_RESTART - read -ra SERVICES_TO_RESTART <<< "$CONF_SOFT_NEED_RESTART" + read -ra SERVICES_TO_RESTART <<< "$SERVICE_RESTART" # Run through SERVICES_TO_RESTART for SERVICE in "${SERVICES_TO_RESTART[@]}"; do - # Check if specified service really exists, if yes then add it to the final services to restart list + # If service restart is conditionned by a specific package update, then get the package name, e.g: + # httpd:ca-certificates => httpd service will be restarted if ca-certificates package is updated + if echo "$SERVICE" | grep -q ":"; then + SERVICE_CONDITIONNAL_PACKAGE_NAME=$(echo "$SERVICE" | awk -F: '{print $2}') + SERVICE=$(echo "$SERVICE" | awk -F: '{print $1}') + + # If conditionnal package is empty, ignore this service and continue + if [ -z "$SERVICE_CONDITIONNAL_PACKAGE_NAME" ];then + continue + fi + + # Check if the package is in the list of packages that will be updated, if not then ignore this service and continue + if ! printf '%s\n' "${PACKAGES[@]}" | grep -q "^${SERVICE_CONDITIONNAL_PACKAGE_NAME}$";then + continue + fi + fi + + # Check if specified service really exists, if yes, then add it to the final services to restart list if systemctl list-units --all -t service --full | grep -q "${SERVICE}.service";then - SERVICE_TO_BE_RESTARTED+=" $SERVICE" + # Also check if the service is active + if systemctl is-active --quiet "$SERVICE";then + SERVICE_TO_BE_RESTARTED+=" $SERVICE" + fi fi done @@ -254,7 +274,7 @@ function checkPackagesBeforeUpdate echo -e "${YELLOW}No available package for update${RESET}\n" # Indicate that there is no need to execute apt/yum packages update - SOMETHING_TO_UPDATE="no" + SOMETHING_TO_UPDATE="false" return fi @@ -270,7 +290,7 @@ function checkPackagesBeforeUpdate fi while read PACKAGE;do - # Packahe name + # Package name PKG_NAME=$(echo "$PACKAGE" | awk '{print $1}') # Package version update that is available and will be installed diff --git a/functions/04_update b/functions/04_update index e7afe6c..0972393 100644 --- a/functions/04_update +++ b/functions/04_update @@ -4,7 +4,7 @@ function update { # Si la vérification des paquets n'a trouvé aucun paquet à mettre à jour alors il est inutile d'exécuter les mises à jour # On sort de la fonction - if [ "$SOMETHING_TO_UPDATE" == "no" ];then + if [ "$SOMETHING_TO_UPDATE" == "false" ];then return fi diff --git a/functions/09_service-restart b/functions/09_service-restart index ab2bfe1..dfd1e51 100644 --- a/functions/09_service-restart +++ b/functions/09_service-restart @@ -1,24 +1,30 @@ #!/usr/bin/env bash -# Redémarrage des services post-mise à jour +# Restart services after update function restartService { - # Si $SERVICE_TO_BE_RESTARTED contient des services nécessitant un redémarrage, on traite - if [ ! -z "$SERVICE_TO_BE_RESTARTED" ];then - OLD_IFS=$IFS - IFS=' ' + # If $SERVICE_TO_BE_RESTARTED contains services that need to be restarted + if [ -z "$SERVICE_TO_BE_RESTARTED" ];then + return + fi - for SERVICE in $(echo "$SERVICE_TO_BE_RESTARTED"); do - SERVICE=$(echo "$SERVICE" | sed 's/ //g') - echo -ne "→ Restarting ${YELLOW}${SERVICE}${RESET} service: " - systemctl restart "$SERVICE" --quiet - if [ "$?" != "0" ];then - echo -e "[$YELLOW ERROR $RESET] while restarting" - else - echo -e "[$GREEN OK $RESET]" - fi - done + OLD_IFS=$IFS + IFS=' ' - IFS=$OLD_IFS - fi + for SERVICE in $(echo "$SERVICE_TO_BE_RESTARTED"); do + # Clean eventual spaces + SERVICE=$(echo "$SERVICE" | sed 's/ //g') + + echo -ne "→ Restarting ${YELLOW}${SERVICE}${RESET} service: " + + systemctl restart "$SERVICE" --quiet + + if [ "$?" != "0" ];then + echo -e "[$YELLOW ERROR $RESET] while restarting" + else + echo -e "[$GREEN OK $RESET]" + fi + done + + IFS=$OLD_IFS } \ No newline at end of file diff --git a/functions/10_send-mail b/functions/10_send-mail index 5a3dbf0..4e01a9b 100644 --- a/functions/10_send-mail +++ b/functions/10_send-mail @@ -2,7 +2,7 @@ function sendMail { - if [ "$MAIL_ENABLED" == "yes" ];then + if [ "$MAIL_ENABLED" == "true" ];then # Remove ANSI color codes before sending mail: sed 's,\x1B[[(][0-9;]*[a-zA-Z],,g' "$LOG" > "$LOG_REPORT_MAIL" diff --git a/linupdate b/linupdate index 9cefd18..8720d36 100755 --- a/linupdate +++ b/linupdate @@ -32,13 +32,13 @@ VIRT_TYPE="" PKG_MANAGER="" PKG_TYPE="" PROFILE="" -SERVER_ENV="" +ENV="" FAILLEVEL="" MAIL_ENABLED="" MAIL_RECIPIENT="" -CONF_SOFT_EXCLUDE_MAJOR="" -CONF_SOFT_EXCLUDE="" -CONF_SOFT_NEED_RESTART="" +PACKAGES_EXCLUDE_MAJOR="" +PACKAGES_EXCLUDE="" +SERVICE_RESTART="" HISTORIQUE="${BASE_DIR}/linupdate.history" # Packages updates history file REPORT="${DATE_YMD}_${TIME_FULL}_linupdate_${HOSTNAME}.log" # Name of the log/report file LOG="${LOGS_DIR}/${REPORT}" # Location of the log/report file @@ -48,7 +48,7 @@ APT_OPTIONS="" YUM_OPTIONS="" KEEP_OLDCONF="0" UPDATE_ERROR="0" -SOMETHING_TO_UPDATE="yes" +SOMETHING_TO_UPDATE="true" ONLY_CHECK_UPDATE="false" IGNORE_EXCLUDE="0" UPDATE_EXCLUDE="" @@ -129,6 +129,18 @@ checkSystem # Generate config file if not exist generateConf +# Patch 2.2.12 +if [ -f "$CONF" ];then + # Replace NEED_RESTART by SERVICE_RESTART + sed -i "s/^NEED_RESTART/SERVICE_RESTART/g" "$CONF" + # Remove ALLOW_SELF_UPDATE + sed -i "/^ALLOW_SELF_UPDATE/d" "$CONF" + # Replace "yes" by "true" in MAIL_ENABLED + sed -i 's/^MAIL_ENABLED="yes"/MAIL_ENABLED="true"/g' "$CONF" + # Replace "no" by "false" in MAIL_ENABLED + sed -i 's/^MAIL_ENABLED="no"/MAIL_ENABLED="false"/g' "$CONF" +fi + ## ↓ EXECUTION ↓ ## @@ -190,8 +202,8 @@ while [ $# -ge 1 ];do --environment|--env) # If nothing has been specified then print actual env if [ -z "$2" ];then - ENV=$(grep "^ENV=" $CONF | sed 's/ENV=//g' | sed 's/"//g') - echo -e "Current environment: ${YELLOW}$ENV${RESET}" + CURRENT_ENV=$(grep "^ENV=" $CONF | sed 's/ENV=//g' | sed 's/"//g') + echo -e "Current environment: ${YELLOW}$CURRENT_ENV${RESET}" else # If an env name has been specified then replace actual env with it if grep -q "ENV=" $CONF;then @@ -341,7 +353,7 @@ if [ ! -z "$VIRT_TYPE" ];then echo -e " Virtualization: ${YELLOW}${VIRT_TYPE}${RESET}" fi echo -e " Profile: ${YELLOW}${PROFILE}${RESET}" -echo -e " Environment: ${YELLOW}${SERVER_ENV}${RESET}" +echo -e " Environment: ${YELLOW}${ENV}${RESET}" echo -e " Executed on: ${YELLOW}${DATE_DMY} ${TIME}${RESET}" echo -ne " Executed by: ${YELLOW} "; whoami; echo -ne "${RESET}" echo -ne " Execution method: " diff --git a/mods-available/configurations/reposerver.conf b/mods-available/configurations/reposerver.conf index f67ef76..b0457c9 100644 --- a/mods-available/configurations/reposerver.conf +++ b/mods-available/configurations/reposerver.conf @@ -6,7 +6,6 @@ ID="" TOKEN="" GET_PROFILE_PKG_CONF_FROM_REPOSERVER="" GET_PROFILE_REPOS_FROM_REPOSERVER="" -GET_PROFILE_PARAMS_OVERWRITE="" [REPOSERVER] IP="" diff --git a/mods-available/reposerver.mod b/mods-available/reposerver.mod index 27c3857..2280fdc 100644 --- a/mods-available/reposerver.mod +++ b/mods-available/reposerver.mod @@ -212,7 +212,6 @@ function mod_help echo -e " --register → Register this host to reposerver" echo -e " --unregister → Unregister this host from reposerver" echo -e " --get-server-conf → Get reposerver global configuration." - echo -e " --get-profile-conf → Get profile global configuration from reposerver." echo -e " --get-profile-packages-conf → Get profile packages excludes configurtion from reposerver." echo -e " --get-profile-repos → Get repos sources configuration from reposerver." echo -e " --send-general-status → Send host global informations to reposerver (OS, version, kernel..)" @@ -293,7 +292,6 @@ function mod_configure FAILLEVEL="" GET_PROFILE_PKG_CONF_FROM_REPOSERVER="" GET_PROFILE_REPOS_FROM_REPOSERVER="" - GET_PROFILE_PARAMS_OVERWRITE="" # Variables de status UPDATE_REQUEST_TYPE="" @@ -407,32 +405,17 @@ function mod_configure sed -i "s/GET_PROFILE_REPOS_FROM_REPOSERVER=.*/GET_PROFILE_REPOS_FROM_REPOSERVER=\"$GET_PROFILE_REPOS_FROM_REPOSERVER\"/g" $MOD_CONF fi ;; - --allow-overwrite) - if [ "$2" == "yes" ];then - GET_PROFILE_PARAMS_OVERWRITE="true" - else - GET_PROFILE_PARAMS_OVERWRITE="false" - fi - shift - - # Ajout du paramètre dans le fichier de conf - if ! grep -q "^GET_PROFILE_PARAMS_OVERWRITE" $MOD_CONF;then - sed -i "/^\[CLIENT\]/a GET_PROFILE_PARAMS_OVERWRITE=\"$GET_PROFILE_PARAMS_OVERWRITE\"" $MOD_CONF - else - sed -i "s/GET_PROFILE_PARAMS_OVERWRITE=.*/GET_PROFILE_PARAMS_OVERWRITE=\"$GET_PROFILE_PARAMS_OVERWRITE\"/g" $MOD_CONF - fi - ;; # Récupération de la configuration complète du serveur Repomanager distant --get-server-conf|--server-get-conf) getModConf getServerConf clean_exit ;; - --get-profile-conf|--profile-get-conf) - getModConf - getProfileConf - clean_exit - ;; + # --get-profile-conf|--profile-get-conf) + # getModConf + # getProfileConf + # clean_exit + # ;; --get-profile-packages-conf) getModConf getProfilePackagesConf @@ -498,18 +481,14 @@ function mod_configure # Retourner 0 si tout est OK function mod_load { - # Patch 2.1.0: - # Changing params names and values + # Patch 2.2.12 if [ -f "$MOD_CONF" ];then - if [ -f "$MOD_CONF" ];then - sed -i 's/REPOSERVER_ALLOW_CONFUPDATE/GET_PROFILE_PKG_CONF_FROM_REPOSERVER/g' "$MOD_CONF" - sed -i 's/REPOSERVER_ALLOW_REPOSFILES_UPDATE/GET_PROFILE_REPOS_FROM_REPOSERVER/g' "$MOD_CONF" - sed -i 's/REPOSERVER_ALLOW_OVERWRITE/GET_PROFILE_PARAMS_OVERWRITE/g' "$MOD_CONF" - sed -i 's/"yes"/"true"/g' "$MOD_CONF" - sed -i 's/"no"/"false"/g' "$MOD_CONF" - sed -i '/MANAGE_CLIENTS_CONF/d' "$MOD_CONF" - sed -i '/MANAGE_CLIENTS_REPOSCONF/d' "$MOD_CONF" - fi + # Remove REPOSERVER_MANAGE_CLIENT_CONF + sed -i '/REPOSERVER_MANAGE_CLIENT_CONF/d' "$MOD_CONF" + # Remove REPOSERVER_MANAGE_CLIENT_REPOS + sed -i '/REPOSERVER_MANAGE_CLIENT_REPOS/d' "$MOD_CONF" + # Remove GET_PROFILE_PARAMS_OVERWRITE + sed -i '/GET_PROFILE_PARAMS_OVERWRITE/d' "$MOD_CONF" fi echo -e " - ${YELLOW}reposerver${RESET}" @@ -557,12 +536,7 @@ function mod_load else grep "^GET_PROFILE_PKG_CONF_FROM_REPOSERVER=" "$MOD_CONF" >> "$TMP_MOD_CONF" fi - # Si le paramètre GET_PROFILE_PARAMS_OVERWRITE est manquant alors on l'ajoute avec une valeur par défaut - if ! grep -q "^GET_PROFILE_PARAMS_OVERWRITE=" "$MOD_CONF";then - echo "GET_PROFILE_PARAMS_OVERWRITE=\"false\"" >> "$TMP_MOD_CONF" - else - grep "^GET_PROFILE_PARAMS_OVERWRITE=" "$MOD_CONF" >> "$TMP_MOD_CONF" - fi + # Si le paramètre GET_PROFILE_REPOS_FROM_REPOSERVER est manquant alors on l'ajoute avec une valeur par défaut if ! grep -q "^GET_PROFILE_REPOS_FROM_REPOSERVER=" "$MOD_CONF";then echo "GET_PROFILE_REPOS_FROM_REPOSERVER=\"false\"" >> "$TMP_MOD_CONF" @@ -617,7 +591,6 @@ function getModConf TOKEN="$(grep "^TOKEN=" $MOD_CONF | cut -d'=' -f2 | sed 's/"//g')" GET_PROFILE_PKG_CONF_FROM_REPOSERVER="$(grep "^GET_PROFILE_PKG_CONF_FROM_REPOSERVER=" $MOD_CONF | cut -d'=' -f2 | sed 's/"//g')" GET_PROFILE_REPOS_FROM_REPOSERVER="$(grep "^GET_PROFILE_REPOS_FROM_REPOSERVER=" $MOD_CONF | cut -d'=' -f2 | sed 's/"//g')" - GET_PROFILE_PARAMS_OVERWRITE="$(grep "^GET_PROFILE_PARAMS_OVERWRITE=" $MOD_CONF | cut -d'=' -f2 | sed 's/"//g')" # Configuration serveur (section [REPOSERVER]) REPOSERVER_URL="$(grep "^URL=" $MOD_CONF | cut -d'=' -f2 | sed 's/"//g')" @@ -677,8 +650,6 @@ function getServerConf REPOSERVER_IP=$(_jq '.Ip') REPOSERVER_URL=$(_jq '.Url') REPOSERVER_PACKAGE_TYPE=$(_jq '.Package_type') - REPOSERVER_MANAGE_CLIENT_CONF=$(_jq '.Manage_client_conf') - REPOSERVER_MANAGE_CLIENT_REPOS=$(_jq '.Manage_client_repos') done # Retrieve the server IP address from the server URL @@ -697,20 +668,6 @@ function getServerConf fi done - # converting to boolean - if [ "$REPOSERVER_MANAGE_CLIENT_CONF" == "no" ];then - REPOSERVER_MANAGE_CLIENT_CONF="false" - fi - if [ "$REPOSERVER_MANAGE_CLIENT_CONF" == "yes" ];then - REPOSERVER_MANAGE_CLIENT_CONF="true" - fi - if [ "$REPOSERVER_MANAGE_CLIENT_REPOS" == "no" ];then - REPOSERVER_MANAGE_CLIENT_REPOS="false" - fi - if [ "$REPOSERVER_MANAGE_CLIENT_REPOS" == "yes" ];then - REPOSERVER_MANAGE_CLIENT_REPOS="true" - fi - # Sauvegarde de la partie [MODULE] sed -n -e '/\[MODULE\]/,/^$/p' "$MOD_CONF" > "$TMP_FILE_MODULE" # Ajout d'un saut de ligne car chaque section doit être correctement séparée @@ -763,66 +720,66 @@ function preCheck } # Get profile general configuration from reposerver -function getProfileConf -{ - # Si le serveur reposerver ne gère pas les profils ou que le client refuse d'être mis à jour par son serveur de repo, on quitte la fonction - echo -ne " → Getting ${YELLOW}${PROFILE}${RESET} profile configuration: " - - # Demande de la configuration des repos auprès du serveur de repos - # Ce dernier renverra la configuration au format JSON - CURL=$(curl -L --post301 -s -q -H "Authorization: Host $HOST_ID:$TOKEN" -X GET "${REPOSERVER_URL}/api/v2/profile/${PROFILE}" 2> /dev/null) - curl_result_parse - - # Si il y a eu une erreur lors de la requête on quitte la fonction - if [ "$CURL_ERROR" != "0" ];then - return 2 - fi - - # Puis on récupère la configuration transmise par le serveur au format JSON - # On parcourt chaque configuration et on récupère le nom du fichier à créer, la description et le contenu à insérer - # On remplace à la volée l'environnement dans le contenu récupéré - for ROW in $(echo "${CURL}" | jq -r '.results[] | @base64'); do - _jq() { - echo ${ROW} | base64 --decode | jq -r ${1} - } - - GET_PROFILE_PKG_CONF_FROM_REPOSERVER=$(_jq '.Linupdate_get_pkg_conf') - GET_PROFILE_REPOS_FROM_REPOSERVER=$(_jq '.Linupdate_get_repos_conf') - done - - if [ "$GET_PROFILE_PKG_CONF_FROM_REPOSERVER" == "null" ];then - echo -e "[$YELLOW ERROR $RESET] Server sent ${YELLOW}null${RESET} data" - return 2 - fi - - if [ "$GET_PROFILE_REPOS_FROM_REPOSERVER" == "null" ];then - echo -e "[$YELLOW ERROR $RESET] Server sent ${YELLOW}null${RESET} data" - return 2 - fi - - # converting to boolean - if [ "$GET_PROFILE_PKG_CONF_FROM_REPOSERVER" == "no" ];then - GET_PROFILE_PKG_CONF_FROM_REPOSERVER="false" - fi - if [ "$GET_PROFILE_PKG_CONF_FROM_REPOSERVER" == "yes" ];then - GET_PROFILE_PKG_CONF_FROM_REPOSERVER="true" - fi - if [ "$GET_PROFILE_REPOS_FROM_REPOSERVER" == "no" ];then - GET_PROFILE_REPOS_FROM_REPOSERVER="false" - fi - if [ "$GET_PROFILE_REPOS_FROM_REPOSERVER" == "yes" ];then - GET_PROFILE_REPOS_FROM_REPOSERVER="true" - fi - - # On applique la nouvelle configuration récupérée - sed -i "s/GET_PROFILE_PKG_CONF_FROM_REPOSERVER.*/GET_PROFILE_PKG_CONF_FROM_REPOSERVER=\"$GET_PROFILE_PKG_CONF_FROM_REPOSERVER\"/g" "$MOD_CONF" - sed -i "s/GET_PROFILE_REPOS_FROM_REPOSERVER.*/GET_PROFILE_REPOS_FROM_REPOSERVER=\"$GET_PROFILE_REPOS_FROM_REPOSERVER\"/g" "$MOD_CONF" - - echo -e "[${GREEN} OK ${RESET}]" - - # Enfin on applique la nouvelle conf en récupérant de nouveau les paramètres du fichier de conf : - getConf -} +# function getProfileConf +# { +# # Si le serveur reposerver ne gère pas les profils ou que le client refuse d'être mis à jour par son serveur de repo, on quitte la fonction +# echo -ne " → Getting ${YELLOW}${PROFILE}${RESET} profile configuration: " + +# # Demande de la configuration des repos auprès du serveur de repos +# # Ce dernier renverra la configuration au format JSON +# CURL=$(curl -L --post301 -s -q -H "Authorization: Host $HOST_ID:$TOKEN" -X GET "${REPOSERVER_URL}/api/v2/profile/${PROFILE}" 2> /dev/null) +# curl_result_parse + +# # Si il y a eu une erreur lors de la requête on quitte la fonction +# if [ "$CURL_ERROR" != "0" ];then +# return 2 +# fi + +# # Puis on récupère la configuration transmise par le serveur au format JSON +# # On parcourt chaque configuration et on récupère le nom du fichier à créer, la description et le contenu à insérer +# # On remplace à la volée l'environnement dans le contenu récupéré +# for ROW in $(echo "${CURL}" | jq -r '.results[] | @base64'); do +# _jq() { +# echo ${ROW} | base64 --decode | jq -r ${1} +# } + +# GET_PROFILE_PKG_CONF_FROM_REPOSERVER=$(_jq '.Linupdate_get_pkg_conf') +# GET_PROFILE_REPOS_FROM_REPOSERVER=$(_jq '.Linupdate_get_repos_conf') +# done + +# if [ "$GET_PROFILE_PKG_CONF_FROM_REPOSERVER" == "null" ];then +# echo -e "[$YELLOW ERROR $RESET] Server sent ${YELLOW}null${RESET} data" +# return 2 +# fi + +# if [ "$GET_PROFILE_REPOS_FROM_REPOSERVER" == "null" ];then +# echo -e "[$YELLOW ERROR $RESET] Server sent ${YELLOW}null${RESET} data" +# return 2 +# fi + +# # converting to boolean +# if [ "$GET_PROFILE_PKG_CONF_FROM_REPOSERVER" == "no" ];then +# GET_PROFILE_PKG_CONF_FROM_REPOSERVER="false" +# fi +# if [ "$GET_PROFILE_PKG_CONF_FROM_REPOSERVER" == "yes" ];then +# GET_PROFILE_PKG_CONF_FROM_REPOSERVER="true" +# fi +# if [ "$GET_PROFILE_REPOS_FROM_REPOSERVER" == "no" ];then +# GET_PROFILE_REPOS_FROM_REPOSERVER="false" +# fi +# if [ "$GET_PROFILE_REPOS_FROM_REPOSERVER" == "yes" ];then +# GET_PROFILE_REPOS_FROM_REPOSERVER="true" +# fi + +# # On applique la nouvelle configuration récupérée +# sed -i "s/GET_PROFILE_PKG_CONF_FROM_REPOSERVER.*/GET_PROFILE_PKG_CONF_FROM_REPOSERVER=\"$GET_PROFILE_PKG_CONF_FROM_REPOSERVER\"/g" "$MOD_CONF" +# sed -i "s/GET_PROFILE_REPOS_FROM_REPOSERVER.*/GET_PROFILE_REPOS_FROM_REPOSERVER=\"$GET_PROFILE_REPOS_FROM_REPOSERVER\"/g" "$MOD_CONF" + +# echo -e "[${GREEN} OK ${RESET}]" + +# # Enfin on applique la nouvelle conf en récupérant de nouveau les paramètres du fichier de conf : +# getConf +# } # Get profile packages configuratin (packages excludes) function getProfilePackagesConf @@ -839,15 +796,9 @@ function getProfilePackagesConf return 2 fi - if [ "$REPOSERVER_MANAGE_CLIENT_CONF" == "false" ] || [ "$GET_PROFILE_PKG_CONF_FROM_REPOSERVER" == "false" ];then - if [ "$REPOSERVER_MANAGE_CLIENT_CONF" == "false" ];then - echo -e "${YELLOW}Disabled (not handled by reposerver)${RESET}" - return 1 - fi - if [ "$GET_PROFILE_PKG_CONF_FROM_REPOSERVER" == "false" ];then - echo -e "${YELLOW}Disabled by profile configuration${RESET}" - return 1 - fi + if [ "$GET_PROFILE_PKG_CONF_FROM_REPOSERVER" == "false" ];then + echo -e "${YELLOW}Disabled${RESET}" + return 1 fi # Puis on récupère la configuration transmise par le serveur au format JSON @@ -860,7 +811,7 @@ function getProfilePackagesConf EXCLUDE_MAJOR=$(_jq '.Package_exclude_major') EXCLUDE=$(_jq '.Package_exclude') - NEED_RESTART=$(_jq '.Service_restart') + SERVICE_RESTART=$(_jq '.Service_restart') done # Si la valeur des paramètres == null alors cela signifie qu'il n'y a aucune exclusion de paquet @@ -870,8 +821,8 @@ function getProfilePackagesConf if [ "$EXCLUDE" == "null" ];then EXCLUDE="" fi - if [ "$NEED_RESTART" == "null" ];then - NEED_RESTART="" + if [ "$SERVICE_RESTART" == "null" ];then + SERVICE_RESTART="" fi # On applique la nouvelle configuration récupérée @@ -879,7 +830,7 @@ function getProfilePackagesConf sed -i '/^\[SOFTWARE CONFIGURATION\]/,$d' "$CONF" && # Puis on injecte la nouvelle conf récupérée - echo -e "[SOFTWARE CONFIGURATION]\nEXCLUDE_MAJOR=\"${EXCLUDE_MAJOR}\"\nEXCLUDE=\"${EXCLUDE}\"\nNEED_RESTART=\"${NEED_RESTART}\"" >> "$CONF" + echo -e "[SOFTWARE CONFIGURATION]\nEXCLUDE_MAJOR=\"${EXCLUDE_MAJOR}\"\nEXCLUDE=\"${EXCLUDE}\"\nSERVICE_RESTART=\"${SERVICE_RESTART}\"" >> "$CONF" echo -e "[${GREEN} OK ${RESET}]" @@ -912,15 +863,9 @@ function getProfileRepos return 2 fi - if [ "$REPOSERVER_MANAGE_CLIENT_REPOS" == "false" ] || [ "$GET_PROFILE_REPOS_FROM_REPOSERVER" == "false" ];then - if [ "$REPOSERVER_MANAGE_CLIENT_REPOS" != "true" ];then - echo -e "${YELLOW}Disabled (not handled by reposerver)${RESET}" - return 1 - fi - if [ "$GET_PROFILE_REPOS_FROM_REPOSERVER" != "true" ];then - echo -e "${YELLOW}Disabled by profile configuration${RESET}" - return 1 - fi + if [ "$GET_PROFILE_REPOS_FROM_REPOSERVER" == "false" ];then + echo -e "${YELLOW}Disabled${RESET}" + return 1 fi # Si le paramètre existe alors on peut continuer le traitement @@ -944,7 +889,7 @@ function getProfileRepos FILENAME=$(_jq '.filename') DESCRIPTION=$(_jq '.description') - CONTENT=$(_jq '.content' | sed "s/__ENV__/${SERVER_ENV}/g") + CONTENT=$(_jq '.content' | sed "s/__ENV__/${ENV}/g") if [ "$OS_FAMILY" == "Redhat" ];then FILENAME_PATH="/etc/yum.repos.d/$FILENAME" @@ -1020,10 +965,10 @@ function pre if [ "$FAILLEVEL" -eq "2" ] && [ "$RESULT" -ge "2" ];then (( MOD_ERROR++ )); clean_exit;fi # On met à jour notre configuration à partir du serveur de repo (profils), si cela est autorisé des deux côtés - getProfileConf - RESULT="$?" - if [ "$FAILLEVEL" -eq "1" ] && [ "$RESULT" -gt "0" ];then (( MOD_ERROR++ )); clean_exit;fi - if [ "$FAILLEVEL" -eq "2" ] && [ "$RESULT" -ge "2" ];then (( MOD_ERROR++ )); clean_exit;fi + # getProfileConf + # RESULT="$?" + # if [ "$FAILLEVEL" -eq "1" ] && [ "$RESULT" -gt "0" ];then (( MOD_ERROR++ )); clean_exit;fi + # if [ "$FAILLEVEL" -eq "2" ] && [ "$RESULT" -ge "2" ];then (( MOD_ERROR++ )); clean_exit;fi getProfilePackagesConf RESULT="$?" @@ -1057,7 +1002,7 @@ function post update_request_status # Si il y a eu des paquets à mettre à jour lors de cette exécution alors on exécute les actions suivantes - if [ "$SOMETHING_TO_UPDATE" == "yes" ];then + if [ "$SOMETHING_TO_UPDATE" == "true" ];then # Généralement les paquets "*-release" sur Redhat/CentOS remettent en place des fichiers .repo. Si un paquet de ce type a été mis à jour alors on remets à jour la configuration des repos à partir du serveurs de repo (profils), si cela est autorisé des deux côtés if echo "${PACKAGES[*]}" | grep -q "-release";then getProfileRepos @@ -1186,8 +1131,8 @@ function send_general_status if [ ! -z "$PROFILE" ];then CURL_PARAMS+="\"profile\":\"$PROFILE\"," fi - if [ ! -z "$SERVER_ENV" ];then - CURL_PARAMS+="\"env\":\"$SERVER_ENV\"," + if [ ! -z "$ENV" ];then + CURL_PARAMS+="\"env\":\"$ENV\"," fi if [ ! -z "$AGENT_STATUS" ];then CURL_PARAMS+="\"agent_status\":\"$AGENT_STATUS\"," diff --git a/version b/version index 4c22129..c45a01d 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.2.11 \ No newline at end of file +2.2.12 \ No newline at end of file