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