myvesta/bin/v-change-sys-config-value
2022-06-04 19:06:23 +02:00

59 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# info: change sysconfig value
# options: KEY VALUE
#
# The function is for changing main config settings such as COMPANY_NAME or
# COMPANY_EMAIL and so on.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
key=$(echo "$1" | tr '[:lower:]' '[:upper:]' )
value=$2
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
PATH="$PATH:/usr/local/sbin:/sbin:/usr/sbin:/root/bin"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'KEY VALUE'
is_format_valid 'key'
format_no_quotes "$value" 'value'
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Updating conf
check_ckey=$(grep "^$key='" $VESTA/conf/vesta.conf)
if [ -z "$check_ckey" ]; then
echo "$key='$value'" >> $VESTA/conf/vesta.conf
else
sed -i "s|$key=.*|$key='$value'|g" $VESTA/conf/vesta.conf
fi
if [ "$key" = "BACKUP" ] && [ "$value" != '/backup' ]; then
rm /backup
ln -s $value /backup
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
exit