Skip to content

Commit

Permalink
updated pistop package
Browse files Browse the repository at this point in the history
1. create_services.in, host_status.in: added desktop notification to
   notifyhost or notify-fifo
2. pistopstart.in: send PowerOff, MusicOff notification as desktop
   notification
  • Loading branch information
mbhangui committed Apr 21, 2024
1 parent 3f1dd16 commit 186d8cd
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 20 deletions.
46 changes: 44 additions & 2 deletions create_service.in
@@ -1,6 +1,6 @@
#!/bin/sh
#
# $Id: create_service.in,v 1.59 2024-03-21 23:42:08+05:30 Cprogrammer Exp mbhangui $
# $Id: create_service.in,v 1.60 2024-04-21 23:12:22+05:30 Cprogrammer Exp mbhangui $
#

check_update_if_diff()
Expand Down Expand Up @@ -151,6 +151,19 @@ add_service()
> $servicedir/$service_name/variables/LCD_HOST
> $servicedir/$service_name/variables/LCD_PORT
fi
if [ -n "$notifyfifo" ] ; then
> $servicedir/$service_name/variables/NOTIFY_HOST
> $servicedir/$service_name/variables/NOTIFY_PORT
check_update_if_diff $servicedir/$service_name/variables/NOTIFY_FIFO $notifyfifo
elif [ -n "$notifyhost" -a -n "$notifyport" ] ; then
> $servicedir/$service_name/variables/LCD_FIFO
check_update_if_diff $servicedir/$service_name/variables/NOTIFY_HOST $notifyhost
check_update_if_diff $servicedir/$service_name/variables/NOTIFY_PORT $notifyport
else
> $servicedir/$service_name/variables/NOTIFY_FIFO
> $servicedir/$service_name/variables/NOTIFY_HOST
> $servicedir/$service_name/variables/NOTIFY_PORT
fi
check_update_if_diff $servicedir/$service_name/variables/TIMEOUT 60
check_update_if_diff $servicedir/$service_name/variables/MAXDAEMONS 10
check_update_if_diff $servicedir/$service_name/variables/USER "root"
Expand Down Expand Up @@ -190,6 +203,19 @@ add_service()
> $servicedir/$service_name/variables/LCD_HOST
> $servicedir/$service_name/variables/LCD_PORT
fi
if [ -n "$notifyfifo" ] ; then
> $servicedir/$service_name/variables/NOTIFY_HOST
> $servicedir/$service_name/variables/NOTIFY_PORT
check_update_if_diff $servicedir/$service_name/variables/NOTIFY_FIFO $notifyfifo
elif [ -n "$notifyhost" -a -n "$notifyport" ] ; then
> $servicedir/$service_name/variables/NOTIFY_FIFO
check_update_if_diff $servicedir/$service_name/variables/NOTIFY_HOST $notifyhost
check_update_if_diff $servicedir/$service_name/variables/NOTIFY_PORT $notifyport
else
> $servicedir/$service_name/variables/NOTIFY_FIFO
> $servicedir/$service_name/variables/NOTIFY_HOST
> $servicedir/$service_name/variables/NOTIFY_PORT
fi
check_update_if_diff $servicedir/$service_name/variables/MAXDAEMONS 10
check_update_if_diff $servicedir/$service_name/variables/USER "$user"
check_update_if_diff $servicedir/$service_name/variables/UID "$t_uid"
Expand Down Expand Up @@ -507,6 +533,7 @@ usage()
echo " --service_name=fclient|fserver\\"
echo " --user=username --host=host --port=port\\"
echo " --lcdhost=host --lcdport=port || --lcdfifo=fifo\\"
echo " --notifyhost=host --notifyport=port || --notifyfifo=fifo\\"
echo " --mdrive=mpd drive\\"
echo " --add-service"
echo " or"
Expand Down Expand Up @@ -535,10 +562,13 @@ user=""
lcdhost=""
lcdport=""
lcdfifo=""
notifyhost=""
notifyport=""
notifyfifo=""
prog_args="$0 $*"
SYSTEM=$(uname -s)
MDRIVE=""
RCSID="# \$Id: create_service.in,v 1.59 2024-03-21 23:42:08+05:30 Cprogrammer Exp mbhangui $"
RCSID="# \$Id: create_service.in,v 1.60 2024-04-21 23:12:22+05:30 Cprogrammer Exp mbhangui $"

[ -f /etc/mpd.conf ] && music_dir=$(get_mpd_conf_value music_dir) || music_dir=""
while test $# -gt 0; do
Expand Down Expand Up @@ -580,6 +610,15 @@ while test $# -gt 0; do
--lcdfifo=*)
lcdfifo=$optarg
;;
--notifyhost=*)
notifyhost=$optarg
;;
--notifyport=*)
notifyport=$optarg
;;
--notifyfifo=*)
notifyfifo=$optarg
;;

--add-service)
if [ -z "$servicedir" -o -z "$service_name" ] ; then
Expand Down Expand Up @@ -616,6 +655,9 @@ while test $# -gt 0; do
done
#
# $Log: create_service.in,v $
# Revision 1.60 2024-04-21 23:12:22+05:30 Cprogrammer
# added desktop notification to notifyhost or notify-fifo
#
# Revision 1.59 2024-03-21 23:42:08+05:30 Cprogrammer
# work without mpd
# create FORCE_UMOUNT variable
Expand Down
5 changes: 5 additions & 0 deletions doc/ChangeLog
Expand Up @@ -58,6 +58,11 @@ Release 1.1 Start 30/06/2022 End --/--/----
- 27/03/2024
36. pistopstart: umount MDrive without triggering autofs
37. pistopstart: ignore sigpipe
- 21/04/2024
38. create_services.in, host_status.in: added desktop notification to
notifyhost or notify-fifo
39. pistopstart.in: send PowerOff, MusicOff notification as desktop
notification

* Thu Jun 30 2022 18:10:06 IST Manvendra Bhangui <pistop@indimail.org> 1.0-1.1%{?dist}
Release 1.0 Start 28/08/2020 End 30/06/2022
Expand Down
118 changes: 103 additions & 15 deletions host_status.in
@@ -1,20 +1,21 @@
#!/bin/sh
#
# $Id: host_status.in,v 1.2 2024-03-23 02:02:44+05:30 Cprogrammer Exp mbhangui $
# $Id: host_status.in,v 1.3 2024-04-21 23:12:28+05:30 Cprogrammer Exp mbhangui $
#

set_command()
set_command1()
{
if [ -n "$LCD_FIFO" ] ; then
cmd="/bin/cat > $LCD_FIFO"
cmd1="/bin/cat > $LCD_FIFO"
return 0
elif [ -n "$LCD_HOST" ] ; then
if [ -z "$LCD_PORT" ] ; then
LCD_PORT=1806
fi
cmd="nc -w 1 -u $LCD_HOST $LCD_PORT"
cmd1="nc -w 1 -u $LCD_HOST $LCD_PORT"
return 0
fi

if [ -d /run ] ; then
lcdfifo="/run/lcd-daemon/lcdfifo"
elif [ -d /var/run ] ; then
Expand All @@ -23,7 +24,7 @@ set_command()
lcdfifo="/tmp/lcd-daemon/lcdfifo"
fi
if [ -p $lcdfifo ] ; then
cmd="/bin/cat > /run/lcd-daemon/lcdfifo"
cmd1="/bin/cat > /run/lcd-daemon/lcdfifo"
return 0
elif [ -x /usr/bin/nc ] ; then
if [ -n "$LCD_HOST" ] ; then
Expand All @@ -35,7 +36,47 @@ set_command()
LCD_PORT=1806
fi
if [ -n "$lcdhost" ] ; then
cmd="nc -w 1 -u $lcdhost $LCD_PORT"
cmd1="nc -w 1 -u $lcdhost $LCD_PORT"
return 0
fi
fi
return 1
}

set_command2()
{
if [ -n "$NOTIFY_FIFO" ] ; then
cmd2="/bin/cat > $NOTIFY_FIFO"
return 0
elif [ -n "$NOTIFY_HOST" ] ; then
if [ -z "$NOTIFY_PORT" ] ; then
NOTIFY_PORT=1807
fi
cmd2="nc -w 1 -u $NOTIFY_HOST $NOTIFY_PORT"
return 0
fi

if [ -d /run ] ; then
notifyfifo="/run/notify-desktop/notify-fifo"
elif [ -d /var/run ] ; then
notifyfifo="/var/run/notify-desktop/notify-fifo"
else
notifyfifo="/tmp/notify-desktop/notify-fifo"
fi
if [ -p $notifyfifo ] ; then
cmd2="/bin/cat > /run/notify-desktop/notify-fifo"
return 0
elif [ -x /usr/bin/nc ] ; then
if [ -n "$NOTIFY_HOST" ] ; then
notifyhost=$NOTIFY_HOST
else
notifyhost=$(grep notifyhost /etc/hosts|awk '{print $1}')
fi
if [ -z "$NOTIFY_PORT" ] ; then
NOTIFY_PORT=1807
fi
if [ -n "$notifyhost" ] ; then
cmd2="nc -w 1 -u $notifyhost $LCD_PORT"
return 0
fi
fi
Expand All @@ -46,27 +87,74 @@ if [ $# -ne 1 ] ; then
exit 1
fi

set_command
set_command1
set_command2
case "$1" in
load)
echo "Sending load information to LCD $cmd"
if [ -n "$cmd1" ] ; then
echo "Sending load information to LCD $cmd1"
load=$(cat /proc/loadavg|awk '{print $1" "$2" "$3}')
echo "0 0 3:Load $load" | sh -c "$cmd"
echo "0 0 3:Load $load" | sh -c "$cmd1"
if [ -n "$LCD_FIFO" ] ; then
sleep 0.5
fi
echo "1 0 0:$(hostname -I)" | sort -u | sh -c "$cmd"
echo "2 0 0:$(date +"%d-%m-%y %H:%M:%S")" | sh -c "$cmd"
echo "3 0 0:$(uname -n) On" | sh -c "$cmd"
;;
echo "1 0 0:$(hostname -I)" | sort -u | sh -c "$cmd1"
echo "2 0 0:$(date +"%d-%m-%y %H:%M:%S")" | sh -c "$cmd1"
echo "3 0 0:$(uname -n) On" | sh -c "$cmd1"
fi
if [ -n "$cmd2" ] ; then
echo "Sending load information desktop notification $cmd2"
load=$(cat /proc/loadavg|awk '{print $1" "$2" "$3}')
(
printf "summary:host-status\n"
printf "body:Load $load\n"
printf "body:\"$(hostname -I | sort -u)\"\n"
printf "body: Boot complete for %s\n" $(hostname)
) | sh -c "$cmd2"
fi
;;
PowerOff)
if [ -n "$cmd1" ] ; then
echo "3 0 3:$(uname -n) PowerOff" | sh -c "$cmd1"
fi
if [ -n "$cmd2" ] ; then
(
printf "summary:host-status\n"
printf "body: PowerOff %s\n" $(hostname)
) | sh -c "$cmd2"
fi
;;
MusicOff)
if [ -n "$cmd1" ] ; then
echo "3 0 3:$(uname -n) MusicOff" | sh -c "$cmd1"
fi
if [ -n "$cmd2" ] ; then
(
printf "summary:host-status\n"
printf "body: MusicOff %s\n" $(hostname)
) | sh -c "$cmd2"
fi
;;
*)
echo "Sending text to LCD $cmd"
echo $1 | sh -c "$cmd"
if [ -n "$cmd1" ] ; then
echo "Sending text to LCD $cmd1"
echo $1 | sh -c "$cmd1"
fi
if [ -n "$cmd2" ] ; then
echo "Sending desktop notification $cmd2"
(
printf "summary: host-status\n"
printf "body:$1\n"
) | sh -c "$cmd2"
fi
;;
esac

#
# $Log: host_status.in,v $
# Revision 1.3 2024-04-21 23:12:28+05:30 Cprogrammer
# added desktop notification to notifyhost or notify-fifo
#
# Revision 1.2 2024-03-23 02:02:44+05:30 Cprogrammer
# add delay when resetting LCD display
# eliminate duplicate ip addresses
Expand Down
9 changes: 6 additions & 3 deletions pistopstart.in
@@ -1,6 +1,6 @@
#!/bin/sh
#
# $Id: pistopstart.in,v 1.16 2024-03-27 09:44:56+05:30 Cprogrammer Exp mbhangui $
# $Id: pistopstart.in,v 1.17 2024-04-21 23:12:32+05:30 Cprogrammer Exp mbhangui $
#

systemctl=$(which systemctl)
Expand Down Expand Up @@ -99,9 +99,9 @@ stop()
done
fi
if [ -n "$POWER_OFF" ] ; then
@pistoplibexecdir@/host_status "3 0 3:$(uname -n) PowerOff"
@pistoplibexecdir@/host_status PowerOff
else
@pistoplibexecdir@/host_status "3 0 3:$(uname -n) Off"
@pistoplibexecdir@/host_status MusicOff
fi
if [ -n "$POWER_OFF" ] ; then
echo "shutdown $(uname -n) localtime $(date)" 1>&7
Expand Down Expand Up @@ -278,6 +278,9 @@ esac

#
# $Log: pistopstart.in,v $
# Revision 1.17 2024-04-21 23:12:32+05:30 Cprogrammer
# send PowerOff, MusicOff notification as desktop notification
#
# Revision 1.16 2024-03-27 09:44:56+05:30 Cprogrammer
# ignore sigpipe
# umount MDrive without triggering autof
Expand Down

0 comments on commit 186d8cd

Please sign in to comment.