vesta/bin/v-list-sys-config
2013-01-19 23:07:26 +02:00

62 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# info: list system config
# options: [FORMAT]
#
# The function for obtaining the list of system parameters.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
format=${1-shell}
# Json function
json_list_conf() {
lines=$(wc -l $VESTA/conf/vesta.conf | cut -f 1 -d ' ')
i='0'
IFS=$'\n'
echo -e "{\n\t\"config\": {"
for str in $(cat $VESTA/conf/vesta.conf); do
(( ++i))
key=${str%%=*}
value=${str#*=}
if [ "$i" -lt "$lines" ]; then
echo -e "\t\t\"$key\": \"${value//\'/}\","
else
echo -e "\t\t\"$key\": \"${value//\'/}\""
fi
done
echo -e "\t}\n}"
}
# Shell function
shell_list_conf() {
IFS=$'\n'
for str in $(cat $VESTA/conf/vesta.conf); do
key=${str%%=*}
value=${str#*=}
echo "$key: ${value//\'/}"
done
}
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Listing system config
case $format in
json) json_list_conf ;;
plain) shell_list_conf ;;
shell) shell_list_conf | column -t ;;
esac
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit