v-list-user-notifications 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 function
  15. json_list_notifications() {
  16. echo '{'
  17. fileds_count=$(echo $fields| wc -w )
  18. while read line; do
  19. eval $line
  20. if [ -n "$data" ]; then
  21. echo -e ' },'
  22. fi
  23. i=1
  24. IFS=' '
  25. for field in $fields; do
  26. eval value=\"$field\"
  27. value=$(echo "$value"|sed -e 's/"/\\"/g' -e "s/%quote%/'/g")
  28. if [ $i -eq 1 ]; then
  29. (( ++i))
  30. echo -e "\t\"$value\": {"
  31. else
  32. if [ $i -lt $fileds_count ]; then
  33. (( ++i))
  34. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  35. else
  36. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  37. data=1
  38. fi
  39. fi
  40. done
  41. done < $conf
  42. if [ -n "$data" ]; then
  43. echo -e ' }'
  44. fi
  45. echo -e '}'
  46. }
  47. # Shell function
  48. shell_list_notifications() {
  49. while read line ; do
  50. eval $line
  51. echo "$TOPIC" |sed -e "s/%quote%/'/g"
  52. echo "$NOTICE" |sed -e "s/%quote%/'/g"
  53. echo "$DATE $TIME"
  54. echo "--"
  55. echo
  56. done < $conf
  57. }
  58. #----------------------------------------------------------#
  59. # Verifications #
  60. #----------------------------------------------------------#
  61. # Checking args
  62. check_args '1' "$#" 'USER [FORMAT]'
  63. validate_format 'user'
  64. is_object_valid 'user' 'USER' "$user"
  65. #----------------------------------------------------------#
  66. # Action #
  67. #----------------------------------------------------------#
  68. # Defining fileds to select
  69. conf=$USER_DATA/notifications.conf
  70. fields='$NID $TOPIC $NOTICE $TYPE $ACK $TIME $DATE'
  71. # Listing favourites
  72. case $format in
  73. json) json_list_notifications ;;
  74. plain) shell_list_notifications ;;
  75. shell) shell_list_notifications ;;
  76. *) check_args '1' '0' 'USER [FORMAT]'
  77. esac
  78. #----------------------------------------------------------#
  79. # Vesta #
  80. #----------------------------------------------------------#
  81. exit