feat: add info_print flag

This commit is contained in:
2025-09-08 18:11:51 +00:00
parent 040f050d98
commit efc3065b55
7 changed files with 41 additions and 28 deletions

View File

@@ -16,7 +16,7 @@ fi
touch "$LOG" || ISERROR=true
if $ISERROR; then
info_print "Failed to Create $LOG" 3 false; exit 1
info_print "Failed to Create $LOG" $ERROR_FLAG false; exit 1
fi
chmod 644 "$LOG"
@@ -31,7 +31,7 @@ info_print "Date : Installation $(date '+%Y-%m-%d %H:%M:%S')"
if $ISERROR; then
info_print "Failed to move some scripts to $SCRIPT_FILE, See log $LOG" 3 false; exit 1
info_print "Failed to move some scripts to $SCRIPT_FILE, See log $LOG" $ERROR_FLAG false; exit 1
fi
info_print "\n\
@@ -45,12 +45,12 @@ for config in config/*; do
if [ -d "$config" ]; then
cp -r "$config" "$ETC_DIR/" \
&& { info_print "$ETC_DIR/$filename installed (directory)." 6; } \
|| { info_print "$ETC_DIR/$filename failed (directory)." 3; ISERROR=true; }
&& { info_print "$ETC_DIR/$filename installed (directory)." $SUCCESS_FLAG; } \
|| { info_print "$ETC_DIR/$filename failed (directory)." $ERROR_FLAG; ISERROR=true; }
else
install -Dm755 "$config" "$ETC_DIR/$filename" \
&& { info_print "$ETC_DIR/$filename installed." 6; } \
|| { info_print "$ETC_DIR/$filename failed." 3; ISERROR=true; }
&& { info_print "$ETC_DIR/$filename installed." $SUCCESS_FLAG; } \
|| { info_print "$ETC_DIR/$filename failed." $ERROR_FLAG; ISERROR=true; }
fi
done
@@ -65,15 +65,15 @@ info_print "\n\
for dep in ${INSTALLED_DEP[@]}; do
if command -v "$dep" &>/dev/null; then
info_print "$dep is installed." 6
info_print "$dep is installed." $SUCCESS_FLAG
else
info_print "$dep is not installed." 3
info_print "$dep is not installed." $ERROR_FLAG
ISERROR=true
fi
done
if $ISERROR; then
info_print "Some Dependencies are missing. Please check requirements.txt." 3 false; exit 1
info_print "Some Dependencies are missing. Please check requirements.txt." $ERROR_FLAG false; exit 1
fi
info_print "\n\
@@ -86,8 +86,8 @@ for scripts in libs/*.sh scripts/*.sh; do
output="$SCRIPT_FILE/$scripts"
install $argument "$scripts" $output -Dm755 \
&& { info_print "$output installed." 6; } \
|| { info_print "$output failed." 3; ISERROR=true; }
&& { info_print "$output installed." $SUCCESS_FLAG; } \
|| { info_print "$output failed." $ERROR_FLAG; ISERROR=true; }
done
touch $ENV_FILE

View File

@@ -14,6 +14,14 @@ ERROR="\e[31mERROR\e[0m"
DEBUG="\e[35mDEBUG\e[0m"
ACTION="\e[36mACTION\e[0m"
INFO_FLAG=1
WARN_FLAG=2
ERROR_FLAG=3
DEBUG_FLAG=4
ACTION_FLAG=5
SUCCESS_FLAG=6
DATETIME_FORMAT="%d-%m-%Y %H:%M:%S"
info_print() {
@@ -45,10 +53,10 @@ create_env_variable() {
if [[ -z "$value" ]]; then
if grep -q "^$key=*" "$file" 2>/dev/null; then
info_print "$key not updated." 2
info_print "$key not updated." $WARN_FLAG
return
else
info_print "$key not set (empty input)." 2
info_print "$key not set (empty input)." $WARN_FLAG
return
fi
fi
@@ -59,15 +67,15 @@ create_env_variable() {
case "$yn" in
[Yy]*)
sed -i "s/^$key=.*/$key=$value/" "$file"
info_print "$key updated." 6
info_print "$key updated." $SUCCESS_FLAG
;;
*)
info_print "$key not changed." 2
info_print "$key not changed." $WARN_FLAG
;;
esac
else
echo "$key=$value" >> "$file"
info_print "$key set." 6
info_print "$key set." $SUCCESS_FLAG
fi
}
@@ -76,9 +84,9 @@ create_raw_line_variable() {
local file="$2"
if grep -Fxq "$line" "$file" 2>/dev/null; then
info_print "'$line' already defined as raw line." 2
info_print "'$line' already defined as raw line." $WARN_FLAG
else
echo "$line" >> "$file"
info_print "'$line' added as raw line." 6
info_print "'$line' added as raw line." $SUCCESS_FLAG
fi
}

View File

@@ -9,7 +9,7 @@ if [[ "--install" == $INSTALLED ]]; then
notifications Installation\n\
--------------------------------------------------"
ENV_LIST=("TELEGRAM_CHAT_ID" "TELEGRAM_TOKEN")
ENV_LIST=("TELEGRAM_TOKEN" "TELEGRAM_CHAT_ID")
for env in "${ENV_LIST[@]}"; do
read -p "Enter value for $env: " value

View File

@@ -39,7 +39,7 @@ if [[ "--install" == $INSTALLED ]]; then
crontab -l | grep -F "$CRON_JOB" > /dev/null 2>&1
if ! crontab -l | grep -Fq "$CRON_JOB"; then
(crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab -
info_print "Cron job added." 6
info_print "Cron job added." $SUCCESS_FLAG
fi
exit 0
@@ -76,16 +76,16 @@ while IFS= read -r SOURCE_PATH || [ -n "$SOURCE_PATH" ]; do
"${aws_cmd[@]}"
if [ $? -ne 0 ]; then
info_print "Error while syncing $SOURCE_PATH to the AWS server." 3
info_print "Error while syncing $SOURCE_PATH to the AWS server." $ERROR_FLAG
BACKUPSUCCESSED=false
exit 1
else
info_print "Successfully synced $SOURCE_PATH" 6
info_print "Successfully synced $SOURCE_PATH" $SUCCESS_FLAG
BACKUPSUCCESSED=true
fi
else
info_print "$SOURCE_PATH not found or inaccessible." 3
info_print "$SOURCE_PATH not found or inaccessible." $ERROR_FLAG
BACKUPSUCCESSED=false
exit 1
fi

View File

@@ -9,11 +9,16 @@ if [[ "--install" == $INSTALLED ]]; then
==================================================\n\
disk-monitor Installation\n\
--------------------------------------------------"
if ! command -v crontab >/dev/null 2>&1; then
info_print "Cron job added." $ERROR_FLAG
exit 1
fi
CRON_JOB="0 3 * * 1 $SCRIPT_FILE/scripts/disk-monitor.sh"
crontab -l | grep -F "$CRON_JOB" > /dev/null 2>&1
if ! crontab -l | grep -Fq "$CRON_JOB"; then
(crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab -
info_print "Cron job added." 6
info_print "Cron job added." $SUCCESS_FLAG
fi
exit 0;
fi

View File

@@ -19,7 +19,7 @@ if [[ "--install" == $INSTALLED ]]; then
source /etc/serverconfig/.env
if [[ -f "$ETC_DIR/docker-compose.yml" ]]; then
docker compose -f "$ETC_DIR/docker-compose.yml" up -d --force-recreate && \
docker compose -f "$ETC_DIR/docker-compose.yml" up -d --force-recreate --remove-orphans && \
info_print "$ETC_DIR/docker-compose.yml is running." 6;
else info_print "no docker-compose.yml found at $ETC_DIR" 3;

View File

@@ -14,15 +14,15 @@ if [[ "--install" == $INSTALLED ]]; then
file='/etc/pam.d/common-session'
if [[ ! -f "$file" ]]; then
info_print "$file doesn't found." 3
info_print "$file doesn't found." $ERROR_FLAG
exit 1
fi
if ! grep -Fxq "$login" "$file"; then
echo "$login" >> "$file"
info_print "login command added to $file." 6
info_print "login command added to $file." $SUCCESS_FLAG
else
info_print "login command already added to $file." 2
info_print "login command already added to $file." $WARN_FLAG
fi
exit 0;
fi