mirror of
https://github.com/guezoloic/serverconfig.git
synced 2026-01-25 09:34:23 +00:00
feat: rework aws-backup and add --install command
This commit is contained in:
@@ -36,4 +36,40 @@ info_print() {
|
||||
if [ "$write_log" = true ]; then echo -e "$output" | tee -a "$LOG"
|
||||
else echo -e "$output"
|
||||
fi
|
||||
}
|
||||
|
||||
create_env_variable() {
|
||||
local key="$1"
|
||||
local value="$2"
|
||||
local file="${3:-$ENV_FILE}"
|
||||
|
||||
if [[ -z "$value" ]]; then
|
||||
if grep -q "^$key=*" "$file" 2>/dev/null; then
|
||||
info_print "$key not updated."
|
||||
return
|
||||
else
|
||||
info_print "$key not set (empty input)."
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
if grep -q "^$key=" "$file" 2>/dev/null; then
|
||||
if $AUTO_CONFIRM; then
|
||||
yn="y"
|
||||
else
|
||||
read -p "$key already set, overwrite? (y/N): " yn
|
||||
fi
|
||||
case "$yn" in
|
||||
[Yy]*)
|
||||
sed -i "s/^$key=.*/$key=$value/" "$file"
|
||||
info_print "$key updated."
|
||||
;;
|
||||
*)
|
||||
info_print "$key not changed."
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "$key=$value" >> "$file"
|
||||
info_print "$key \e[32mset\e[0m."
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user