v-list-sys-shells 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. # info: list system shells
  3. # options: [FORMAT]
  4. # labels: panel
  5. #
  6. # example: v-list-sys-shells
  7. #
  8. # The function for obtaining the list of system shells.
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. format=${1-shell}
  14. # Includes
  15. # shellcheck source=/usr/local/hestia/func/main.sh
  16. source $HESTIA/func/main.sh
  17. # JSON list function
  18. json_list() {
  19. sh_counter=$(echo "$shells" | wc -l)
  20. i=1
  21. echo '['
  22. for shell in $shells; do
  23. if [ "$i" -lt "$sh_counter" ]; then
  24. echo -e "\t\"$shell\","
  25. else
  26. echo -e "\t\"$shell\""
  27. fi
  28. (( ++i))
  29. done
  30. echo "]"
  31. }
  32. # SHELL list function
  33. shell_list() {
  34. echo "SHELL"
  35. echo "-----"
  36. for shell in $shells; do
  37. echo "$shell"
  38. done
  39. }
  40. # PLAIN list function
  41. plain_list() {
  42. for shell in $shells; do
  43. echo "$shell"
  44. done
  45. }
  46. # CSV list function
  47. csv_list() {
  48. echo "SHELL"
  49. for shell in $shells; do
  50. echo "$shell"
  51. done
  52. }
  53. #----------------------------------------------------------#
  54. # Action #
  55. #----------------------------------------------------------#
  56. # Defining system shells
  57. shells=$(grep -v '#' /etc/shells |awk -F '/' '{print $NF}' |sort -u)
  58. # Listing data
  59. case $format in
  60. json) json_list ;;
  61. plain) plain_list ;;
  62. csv) csv_list ;;
  63. shell) shell_list ;;
  64. esac
  65. #----------------------------------------------------------#
  66. # Hestia #
  67. #----------------------------------------------------------#
  68. exit