From a2251186e9733a852791686a36763844714ddb0a Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Wed, 9 Nov 2016 17:46:12 +0200 Subject: [PATCH] user notification in main func inc --- func/main.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/func/main.sh b/func/main.sh index e0ea2c3d6..b2a59e92a 100644 --- a/func/main.sh +++ b/func/main.sh @@ -110,6 +110,7 @@ is_system_enabled() { fi } + # User package check is_package_full() { case "$1" in @@ -367,6 +368,40 @@ decrease_user_value() { sed -i "s/$key='$old'/$key='$new'/g" $conf } +# Notify user +send_notice() { + topic=$1 + notice=$2 + + if [ "$notify" = 'yes' ]; then + touch $USER_DATA/notifications.conf + chmod 660 $USER_DATA/notifications.conf + + time_n_date=$(date +'%T %F') + time=$(echo "$time_n_date" |cut -f 1 -d \ ) + date=$(echo "$time_n_date" |cut -f 2 -d \ ) + + nid=$(grep "NID=" $USER_DATA/notifications.conf |cut -f 2 -d \') + nid=$(echo "$nid" |sort -n |tail -n1) + if [ ! -z "$nid" ]; then + nid="$((nid +1))" + else + nid=1 + fi + + str="NID='$nid' TOPIC='$topic' NOTICE='$notice' TYPE='$type'" + str="$str ACK='no' TIME='$time' DATE='$date'" + + echo "$str" >> $USER_DATA/notifications.conf + + if [ -z "$(grep NOTIFICATIONS $USER_DATA/user.conf)" ]; then + sed -i "s/^TIME/NOTIFICATIONS='yes'\nTIME/g" $USER_DATA/user.conf + else + update_user_value "$user" '$NOTIFICATIONS' "yes" + fi + fi +} + # Recalculate U_DISK value recalc_user_disk_usage() { u_usage=0