feat: password env variable

This commit is contained in:
2026-03-01 18:03:46 +01:00
parent f40eeff6be
commit cc9d388c0a
5 changed files with 79 additions and 53 deletions

View File

@@ -5,8 +5,8 @@
# It handles logging, environment variables, and Telegram notifications.
if [ -z "${PROJECT_DIR:-}" ]; then
PROJECT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
readonly PROJECT_DIR
PROJECT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
readonly PROJECT_DIR
fi
readonly PROJECT_NAME="serverconfig" 2>/dev/null
@@ -23,10 +23,10 @@ readonly NC='\033[0m'
DATETIME_FORMAT="%d-%m-%Y %H:%M:%S"
function log() {
local type="${1}"
local color="${2}"
local message="${3}"
echo -e "${color}[$(date +"$DATETIME_FORMAT")] [${type}]${NC} ${message}"
local type="${1}"
local color="${2}"
local message="${3}"
echo -e "${color}[$(date +"$DATETIME_FORMAT")] [${type}]${NC} ${message}"
}
function log_info() { log "INFO" "$BLUE" "$1"; }
@@ -36,16 +36,14 @@ function log_warn() { log "WARN " "$YELLOW" "$1" >&2; }
# USING TELEGRAM (may change later)
function send_notification() {
local message="$1"
curl -X POST "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendMessage" \
-d "chat_id=$TELEGRAM_CHAT_ID" \
-d "text=$message" \
-d "parse_mode=HTML"
local message="$1"
curl -X POST "https://api.telegram.org/bot$TELEGRAM_TOKEN/sendMessage" \
-d "chat_id=$TELEGRAM_CHAT_ID" \
-d "text=$message" \
-d "parse_mode=HTML"
}
function env_variable() {
source $ENV_FILE
function env_variable_interaction() {
local key="$1"
local value="$2"
@@ -56,30 +54,47 @@ function env_variable() {
if grep -Eq "^${key}=" "$ENV_FILE" 2>/dev/null; then
read -p "$key already set, overwrite? (y/N): " yn
case "$yn" in
[yY]*)
sed -i "s/^$key=.*/$key=$value/" "$ENV_FILE"
log_success "$key updated."
;;
*)
log_info "$key not changed."
;;
[yY]*)
sed -i "s/^$key=.*/$key=$value/" "$ENV_FILE"
log_success "$key updated."
;;
*)
log_info "$key not changed."
;;
esac
else
echo "$key=$value" >> "$ENV_FILE"
echo "$key=$value" >>"$ENV_FILE"
log_success "$key created."
fi
}
function env_variable() {
local key="$1"
local value="$2"
if grep -Eq "^${key}=" "$ENV_FILE" 2>/dev/null; then
sed -i "s/^$key=.*/$key=$value/" "$ENV_FILE"
log_success "$key updated."
else
echo "$key=$value" >>"$ENV_FILE"
log_success "$key created."
fi
}
function add_crontab() {
if ! command -v crontab >/dev/null 2>&1; then
log_error "Error: crontab not found."
fi
log_error "Error: crontab not found."
fi
CRON_JOB=$1
crontab -l 2>/dev/null | grep -F "$CRON_JOB" > /dev/null 2>&1
if ! crontab -l 2>/dev/null | grep -Fq "$CRON_JOB"; then
(crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab -
log_success "Cron job added."
fi
}
CRON_JOB=$1
crontab -l 2>/dev/null | grep -F "$CRON_JOB" >/dev/null 2>&1
if ! crontab -l 2>/dev/null | grep -Fq "$CRON_JOB"; then
(
crontab -l 2>/dev/null
echo "$CRON_JOB"
) | crontab -
log_success "Cron job added."
fi
}