mirror of
https://github.com/guezoloic/serverconfig.git
synced 2026-01-25 06:34:22 +00:00
feat: add isUpdated and cron error statement
- isUpdated (create_env_variable common.sh) to not propose overwrite field - if cron does not exist, print error (log too)
This commit is contained in:
@@ -50,8 +50,13 @@ create_env_variable() {
|
||||
local key="$1"
|
||||
local value="$2"
|
||||
local file="${3:-$ENV_FILE}"
|
||||
local isUpdated="${4:-true}"
|
||||
|
||||
if [[ -z "$value" ]]; then
|
||||
if [[ "$file" == '--' ]]; then
|
||||
file=$ENV_FILE
|
||||
fi
|
||||
|
||||
if [[ -z "$value" && "$isUpdated" == true ]]; then
|
||||
if grep -q "^$key=*" "$file" 2>/dev/null; then
|
||||
info_print "$key not updated." $WARN_FLAG
|
||||
return
|
||||
@@ -61,21 +66,23 @@ create_env_variable() {
|
||||
fi
|
||||
fi
|
||||
|
||||
if grep -Eq "^${key}=" "$file" 2>/dev/null; then
|
||||
read -p "$key already set, overwrite? (y/N): " yn
|
||||
if [[ "$isUpdated" == true ]]; then
|
||||
if grep -Eq "^${key}=" "$file" 2>/dev/null; then
|
||||
read -p "$key already set, overwrite? (y/N): " yn
|
||||
|
||||
case "$yn" in
|
||||
[Yy]*)
|
||||
sed -i "s/^$key=.*/$key=$value/" "$file"
|
||||
info_print "$key updated." $SUCCESS_FLAG
|
||||
;;
|
||||
*)
|
||||
info_print "$key not changed." $WARN_FLAG
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "$key=$value" >> "$file"
|
||||
info_print "$key set." $SUCCESS_FLAG
|
||||
case "$yn" in
|
||||
[Yy]*)
|
||||
sed -i "s/^$key=.*/$key=$value/" "$file"
|
||||
info_print "$key updated." $SUCCESS_FLAG
|
||||
;;
|
||||
*)
|
||||
info_print "$key not changed." $WARN_FLAG
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "$key=$value" >> "$file"
|
||||
info_print "$key set." $SUCCESS_FLAG
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user