v_list_sys_config 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. *) check_args '1' '0' '[format]'
  46. esac
  47. #----------------------------------------------------------#
  48. # Vesta #
  49. #----------------------------------------------------------#
  50. exit