Skip to content

Commit

Permalink
2.2.12
Browse files Browse the repository at this point in the history
  • Loading branch information
lbr38 committed Dec 15, 2023
1 parent c73df33 commit a381275
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 208 deletions.
4 changes: 2 additions & 2 deletions functions/00_generateConf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
26 changes: 14 additions & 12 deletions functions/00_get-conf
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion functions/00_space-left
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 38 additions & 18 deletions functions/02_check-packages-before-update
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion functions/04_update
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
40 changes: 23 additions & 17 deletions functions/09_service-restart
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion functions/10_send-mail
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
28 changes: 20 additions & 8 deletions linupdate
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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=""
Expand Down Expand Up @@ -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 ↓ ##

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: "
Expand Down
1 change: 0 additions & 1 deletion mods-available/configurations/reposerver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ ID=""
TOKEN=""
GET_PROFILE_PKG_CONF_FROM_REPOSERVER=""
GET_PROFILE_REPOS_FROM_REPOSERVER=""
GET_PROFILE_PARAMS_OVERWRITE=""

[REPOSERVER]
IP=""
Expand Down
Loading

0 comments on commit a381275

Please sign in to comment.