v-list-user-notifications 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/bash
  2. # info: list user notifications
  3. # options: USER [FORMAT]
  4. #
  5. # The function for getting the list notifications
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. format=${2-shell}
  12. # Includes
  13. source $VESTA/func/main.sh
  14. # JSON list function
  15. json_list() {
  16. IFS=$'\n'
  17. i=1
  18. objects=$(grep NID $USER_DATA/notifications.conf |wc -l)
  19. echo "{"
  20. while read str; do
  21. eval $str
  22. TOPIC=$(echo "$TOPIC" |sed -e "s/%quote%/'/g")
  23. NOTICE=$(echo "$NOTICE" |sed -e "s/%quote%/'/g")
  24. echo -n ' "'$NID'": {
  25. "TOPIC": "'$TOPIC'",
  26. "NOTICE": "'$NOTICE'",
  27. "TYPE": "'$TYPE'",
  28. "ACK": "'$ACK'",
  29. "TPL": "'$TPL'",
  30. "TIME": "'$TIME'",
  31. "DATE": "'$DATE'"
  32. }'
  33. if [ "$i" -lt "$objects" ]; then
  34. echo ','
  35. else
  36. echo
  37. fi
  38. ((i++))
  39. done < <(cat $USER_DATA/notifications.conf)
  40. echo '}'
  41. }
  42. # SHELL list function
  43. shell_list() {
  44. IFS=$'\n'
  45. while read str; do
  46. eval $str
  47. echo "$TOPIC" |sed -e "s/%quote%/'/g"
  48. echo "$NOTICE" |sed -e "s/%quote%/'/g"
  49. echo "$DATE $TIME"
  50. echo "--"
  51. echo
  52. done < <(cat $USER_DATA/notifications.conf)
  53. }
  54. # PLAIN list function
  55. plain_list() {
  56. IFS=$'\n'
  57. while read str; do
  58. eval $str
  59. TOPIC=$(echo "$TOPIC" |sed -e "s/%quote%/'/g")
  60. NOTICE=$(echo "$NOTICE" |sed -e "s/%quote%/'/g")
  61. echo -e "$NID\t$TOPIC\t$NOTICE\t$TIME\t$DATE"
  62. done < <(cat $USER_DATA/notifications.conf)
  63. }
  64. # CSV list function
  65. csv_list() {
  66. IFS=$'\n'
  67. echo "NID,TOPIC,NOTICE,TIME,DATE"
  68. while read str; do
  69. eval $str
  70. TOPIC=$(echo "$TOPIC" |sed -e "s/%quote%/'/g")
  71. NOTICE=$(echo "$NOTICE" |sed -e "s/%quote%/'/g")
  72. echo "$NID,\"$TOPIC\",\"$NOTICE\",$TIME,$DATE"
  73. done < <(cat $USER_DATA/notifications.conf)
  74. }
  75. #----------------------------------------------------------#
  76. # Verifications #
  77. #----------------------------------------------------------#
  78. # Checking args
  79. check_args '1' "$#" 'USER [FORMAT]'
  80. is_format_valid 'user'
  81. is_object_valid 'user' 'USER' "$user"
  82. #----------------------------------------------------------#
  83. # Action #
  84. #----------------------------------------------------------#
  85. # Listing data
  86. case $format in
  87. json) json_list ;;
  88. plain) plain_list ;;
  89. csv) csv_list ;;
  90. shell) shell_list ;;
  91. esac
  92. #----------------------------------------------------------#
  93. # Vesta #
  94. #----------------------------------------------------------#
  95. exit