v-list-sys-config 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. # Json function
  12. json_list_conf() {
  13. lines=$(wc -l $VESTA/conf/vesta.conf | cut -f 1 -d ' ')
  14. i='0'
  15. IFS=$'\n'
  16. echo -e "{\n\t\"config\": {"
  17. for str in $(cat $VESTA/conf/vesta.conf); do
  18. (( ++i))
  19. key=${str%%=*}
  20. value=${str#*=}
  21. if [ "$i" -lt "$lines" ]; then
  22. echo -e "\t\t\"$key\": \"${value//\'/}\","
  23. else
  24. echo -e "\t\t\"$key\": \"${value//\'/}\""
  25. fi
  26. done
  27. echo -e "\t}\n}"
  28. }
  29. # Shell function
  30. shell_list_conf() {
  31. IFS=$'\n'
  32. for str in $(cat $VESTA/conf/vesta.conf); do
  33. key=${str%%=*}
  34. value=${str#*=}
  35. echo "$key: ${value//\'/}"
  36. done
  37. }
  38. #----------------------------------------------------------#
  39. # Action #
  40. #----------------------------------------------------------#
  41. # Listing system config
  42. case $format in
  43. json) json_list_conf ;;
  44. plain) shell_list_conf ;;
  45. shell) shell_list_conf | column -t ;;
  46. esac
  47. #----------------------------------------------------------#
  48. # Vesta #
  49. #----------------------------------------------------------#
  50. exit