v_list_sys_config 1.6 KB

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