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 touch "$LOG" || ISERROR=true
if $ISERROR; then 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 fi
chmod 644 "$LOG" chmod 644 "$LOG"
@@ -31,7 +31,7 @@ info_print "Date : Installation $(date '+%Y-%m-%d %H:%M:%S')"
if $ISERROR; then 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 fi
info_print "\n\ info_print "\n\
@@ -45,12 +45,12 @@ for config in config/*; do
if [ -d "$config" ]; then if [ -d "$config" ]; then
cp -r "$config" "$ETC_DIR/" \ cp -r "$config" "$ETC_DIR/" \
&& { info_print "$ETC_DIR/$filename installed (directory)." 6; } \ && { info_print "$ETC_DIR/$filename installed (directory)." $SUCCESS_FLAG; } \
|| { info_print "$ETC_DIR/$filename failed (directory)." 3; ISERROR=true; } || { info_print "$ETC_DIR/$filename failed (directory)." $ERROR_FLAG; ISERROR=true; }
else else
install -Dm755 "$config" "$ETC_DIR/$filename" \ install -Dm755 "$config" "$ETC_DIR/$filename" \
&& { info_print "$ETC_DIR/$filename installed." 6; } \ && { info_print "$ETC_DIR/$filename installed." $SUCCESS_FLAG; } \
|| { info_print "$ETC_DIR/$filename failed." 3; ISERROR=true; } || { info_print "$ETC_DIR/$filename failed." $ERROR_FLAG; ISERROR=true; }
fi fi
done done
@@ -65,15 +65,15 @@ info_print "\n\
for dep in ${INSTALLED_DEP[@]}; do for dep in ${INSTALLED_DEP[@]}; do
if command -v "$dep" &>/dev/null; then if command -v "$dep" &>/dev/null; then
info_print "$dep is installed." 6 info_print "$dep is installed." $SUCCESS_FLAG
else else
info_print "$dep is not installed." 3 info_print "$dep is not installed." $ERROR_FLAG
ISERROR=true ISERROR=true
fi fi
done done
if $ISERROR; then 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 fi
info_print "\n\ info_print "\n\
@@ -86,8 +86,8 @@ for scripts in libs/*.sh scripts/*.sh; do
output="$SCRIPT_FILE/$scripts" output="$SCRIPT_FILE/$scripts"
install $argument "$scripts" $output -Dm755 \ install $argument "$scripts" $output -Dm755 \
&& { info_print "$output installed." 6; } \ && { info_print "$output installed." $SUCCESS_FLAG; } \
|| { info_print "$output failed." 3; ISERROR=true; } || { info_print "$output failed." $ERROR_FLAG; ISERROR=true; }
done done
touch $ENV_FILE touch $ENV_FILE

View File

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

View File

@@ -9,7 +9,7 @@ if [[ "--install" == $INSTALLED ]]; then
notifications Installation\n\ notifications Installation\n\
--------------------------------------------------" --------------------------------------------------"
ENV_LIST=("TELEGRAM_CHAT_ID" "TELEGRAM_TOKEN") ENV_LIST=("TELEGRAM_TOKEN" "TELEGRAM_CHAT_ID")
for env in "${ENV_LIST[@]}"; do for env in "${ENV_LIST[@]}"; do
read -p "Enter value for $env: " value 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 crontab -l | grep -F "$CRON_JOB" > /dev/null 2>&1
if ! crontab -l | grep -Fq "$CRON_JOB"; then if ! crontab -l | grep -Fq "$CRON_JOB"; then
(crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab - (crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab -
info_print "Cron job added." 6 info_print "Cron job added." $SUCCESS_FLAG
fi fi
exit 0 exit 0
@@ -76,16 +76,16 @@ while IFS= read -r SOURCE_PATH || [ -n "$SOURCE_PATH" ]; do
"${aws_cmd[@]}" "${aws_cmd[@]}"
if [ $? -ne 0 ]; then 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 BACKUPSUCCESSED=false
exit 1 exit 1
else else
info_print "Successfully synced $SOURCE_PATH" 6 info_print "Successfully synced $SOURCE_PATH" $SUCCESS_FLAG
BACKUPSUCCESSED=true BACKUPSUCCESSED=true
fi fi
else else
info_print "$SOURCE_PATH not found or inaccessible." 3 info_print "$SOURCE_PATH not found or inaccessible." $ERROR_FLAG
BACKUPSUCCESSED=false BACKUPSUCCESSED=false
exit 1 exit 1
fi fi

View File

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

View File

@@ -19,7 +19,7 @@ if [[ "--install" == $INSTALLED ]]; then
source /etc/serverconfig/.env source /etc/serverconfig/.env
if [[ -f "$ETC_DIR/docker-compose.yml" ]]; then 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; info_print "$ETC_DIR/docker-compose.yml is running." 6;
else info_print "no docker-compose.yml found at $ETC_DIR" 3; 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' file='/etc/pam.d/common-session'
if [[ ! -f "$file" ]]; then if [[ ! -f "$file" ]]; then
info_print "$file doesn't found." 3 info_print "$file doesn't found." $ERROR_FLAG
exit 1 exit 1
fi fi
if ! grep -Fxq "$login" "$file"; then if ! grep -Fxq "$login" "$file"; then
echo "$login" >> "$file" echo "$login" >> "$file"
info_print "login command added to $file." 6 info_print "login command added to $file." $SUCCESS_FLAG
else else
info_print "login command already added to $file." 2 info_print "login command already added to $file." $WARN_FLAG
fi fi
exit 0; exit 0;
fi fi