v_list_sys_config 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. # info: listing system config
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. format=${1-shell}
  8. # Importing variables
  9. source $VESTA/conf/vars.conf
  10. # Json function
  11. json_list_conf() {
  12. lines=$(wc -l $V_CONF/vesta.conf | cut -f 1 -d ' ')
  13. i='0'
  14. echo -e "{\n\t\"config\": {"
  15. for str in $(cat $V_CONF/vesta.conf); do
  16. (( ++i))
  17. key=${str%%=*}
  18. value=${str#*=}
  19. value=${value//%spc%/ }
  20. if [ "$i" -lt "$lines" ]; then
  21. echo -e "\t\t\"$key\": \"${value//\'/}\","
  22. else
  23. echo -e "\t\t\"$key\": \"${value//\'/}\""
  24. fi
  25. done
  26. echo -e "\t}\n}"
  27. }
  28. # Shell function
  29. shell_list_conf() {
  30. for str in $(cat $V_CONF/vesta.conf); do
  31. key=${str%%=*}
  32. value=${str#*=}
  33. value=${value//%spc%/ }
  34. echo "$key: ${value//\'/}"
  35. done
  36. }
  37. #----------------------------------------------------------#
  38. # Action #
  39. #----------------------------------------------------------#
  40. # Listing system config
  41. case $format in
  42. json) json_list_conf ;;
  43. plain) shell_list_conf ;;
  44. shell) shell_list_conf | column -t ;;
  45. esac
  46. #----------------------------------------------------------#
  47. # Vesta #
  48. #----------------------------------------------------------#
  49. exit