mirror of
https://github.com/guezoloic/serverconfig.git
synced 2026-01-25 09:34:23 +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 key="$1"
|
||||||
local value="$2"
|
local value="$2"
|
||||||
local file="${3:-$ENV_FILE}"
|
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
|
if grep -q "^$key=*" "$file" 2>/dev/null; then
|
||||||
info_print "$key not updated." $WARN_FLAG
|
info_print "$key not updated." $WARN_FLAG
|
||||||
return
|
return
|
||||||
@@ -61,6 +66,7 @@ create_env_variable() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "$isUpdated" == true ]]; then
|
||||||
if grep -Eq "^${key}=" "$file" 2>/dev/null; then
|
if grep -Eq "^${key}=" "$file" 2>/dev/null; then
|
||||||
read -p "$key already set, overwrite? (y/N): " yn
|
read -p "$key already set, overwrite? (y/N): " yn
|
||||||
|
|
||||||
@@ -77,6 +83,7 @@ create_env_variable() {
|
|||||||
echo "$key=$value" >> "$file"
|
echo "$key=$value" >> "$file"
|
||||||
info_print "$key set." $SUCCESS_FLAG
|
info_print "$key set." $SUCCESS_FLAG
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
create_raw_line_variable() {
|
create_raw_line_variable() {
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ if [[ "--install" == $INSTALLED ]]; then
|
|||||||
info_print "AWS configuration."
|
info_print "AWS configuration."
|
||||||
aws configure
|
aws configure
|
||||||
|
|
||||||
create_env_variable AWS_ACCESS_KEY_ID $(aws configure get aws_access_key_id)
|
create_env_variable AWS_ACCESS_KEY_ID $(aws configure get aws_access_key_id) -- false
|
||||||
create_env_variable AWS_SECRET_ACCESS_KEY $(aws configure get aws_secret_access_key)
|
create_env_variable AWS_SECRET_ACCESS_KEY $(aws configure get aws_secret_access_key) -- false
|
||||||
|
|
||||||
touch "$BACKUP"
|
touch "$BACKUP"
|
||||||
info_print "$BACKUP created."
|
info_print "$BACKUP created."
|
||||||
@@ -35,6 +35,11 @@ if [[ "--install" == $INSTALLED ]]; then
|
|||||||
done
|
done
|
||||||
info_print "You can add more names later by editing $BACKUP."
|
info_print "You can add more names later by editing $BACKUP."
|
||||||
|
|
||||||
|
if ! command -v crontab >/dev/null 2>&1; then
|
||||||
|
info_print "Error: crontab not found." $ERROR_FLAG
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
CRON_JOB="0 0 * * * $SCRIPT_FILE/scripts/aws-backup.sh"
|
CRON_JOB="0 0 * * * $SCRIPT_FILE/scripts/aws-backup.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
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ if [[ "--install" == $INSTALLED ]]; then
|
|||||||
disk-monitor Installation\n\
|
disk-monitor Installation\n\
|
||||||
--------------------------------------------------"
|
--------------------------------------------------"
|
||||||
if ! command -v crontab >/dev/null 2>&1; then
|
if ! command -v crontab >/dev/null 2>&1; then
|
||||||
info_print "Cron job added." $ERROR_FLAG
|
info_print "Error: crontab not found." $ERROR_FLAG
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user