mosquitto: Update from 1.4.10 to 1.4.11
[termux-packages] / packages / termux-api / termux-notification
CommitLineData
a78e1140 1#!/data/data/com.termux/files/usr/bin/bash
0ec2b704 2set -e -u
59f0d218 3
0ec2b704 4SCRIPTNAME=termux-notification
59f0d218 5show_usage () {
a78e1140
FF
6 echo "Usage: termux-notification [options]"
7 echo "Display a system notification. Context text is read from stdin or specified using --content."
8 echo " --action action action to execute when pressing the notification"
9 echo " --button1 text text to show on the first notification button"
10 echo " --button1-action action action to execute on the first notification button"
11 echo " --button2 text text to show on the second notification button"
12 echo " --button2-action action action to execute on the second notification button"
13 echo " --button3 text text to show on the third notification button"
14 echo " --button3-action action action to execute on the third notification button"
15 echo " --content content contnet to show in the notification. Read from stdin not specified here."
16 echo " --id id notification id (will overwrite any previous notification with the same id)"
17 echo " --led-color rrggbb color of the blinking led as RRGGBB (default: none)"
18 echo " --led-on milliseconds number of milliseconds for the LED to be on while it's flashing (default: 800)"
19 echo " --led-off milliseconds number of milliseconds for the LED to be off while it's flashing (default: 800)"
20 echo " --priority prio notification priority (high/low/max/min/default)"
21 echo " --sound play a sound with the notification"
22 echo " --title title notification title to show"
23 echo " --vibrate pattern vibrate pattern, comma separated as in 500,1000,200"
bea93fbd 24 exit 0
59f0d218
FF
25}
26
a78e1140 27OPT_ACTION=""
b4443d5e 28OPT_ID=""
b4443d5e 29OPT_LED_COLOR=""
b4443d5e 30OPT_LED_OFF=""
a78e1140
FF
31OPT_LED_ON=""
32OPT_PRIORITY=""
b4443d5e 33OPT_SOUND=""
a78e1140
FF
34OPT_TITLE=""
35OPT_VIBRATE=""
36OPT_BUTTON1_TEXT=""
37OPT_BUTTON1_ACTION=""
38OPT_BUTTON2_TEXT=""
39OPT_BUTTON2_ACTION=""
40OPT_BUTTON3_TEXT=""
41OPT_BUTTON3_ACTION=""
0ec2b704 42
b4443d5e
FF
43TEMP=`busybox getopt \
44 -n $SCRIPTNAME \
a78e1140
FF
45 -o hc:i:t: \
46 --long action:,\
47button1:,button1-action:,\
48button2:,button2-action:,\
49button3:,button3-action:,\
50content:,help,id:,\
51led-color:,led-on:,led-off:,\
52priority:,sound,title:,vibrate: \
b4443d5e
FF
53 -s bash \
54 -- "$@"`
55eval set -- "$TEMP"
56
57while true; do
58 case "$1" in
a78e1140
FF
59 --action) OPT_ACTION="$2"; shift 2;;
60 --button1) OPT_BUTTON1_TEXT="$2"; shift 2;;
61 --button1-action) OPT_BUTTON1_ACTION="$2"; shift 2;;
62 --button2) OPT_BUTTON2_TEXT="$2"; shift 2;;
63 --button2-action) OPT_BUTTON2_ACTION="$2"; shift 2;;
64 --button3) OPT_BUTTON3_TEXT="$2"; shift 2;;
65 --button3-action) OPT_BUTTON3_ACTION="$2"; shift 2;;
66 -c | --content) OPT_CONTENT="$2"; shift 2;;
b4443d5e
FF
67 -h | --help) show_usage;;
68 -i | --id) OPT_ID="$2"; shift 2;;
69 --led-color) OPT_LED_COLOR="$2"; shift 2;;
70 --led-on) OPT_LED_ON="$2"; shift 2;;
71 --led-off) OPT_LED_OFF="$2"; shift 2;;
72 --priority) OPT_PRIORITY="$2"; shift 2;;
73 --sound) OPT_SOUND="true"; shift 1;;
a78e1140 74 -t | --title) OPT_TITLE="$2"; shift 2;;
b4443d5e
FF
75 --vibrate) OPT_VIBRATE="$2"; shift 2;;
76 --) shift; break ;;
0ec2b704 77 esac
59f0d218 78done
0ec2b704
FF
79
80if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
59f0d218 81
8d6e165f 82set --
a78e1140
FF
83if [ -n "$OPT_ACTION" ]; then set -- "$@" --es action "$OPT_ACTION"; fi
84if [ -n "$OPT_BUTTON1_ACTION" ]; then set -- "$@" --es button_action_1 "$OPT_BUTTON1_ACTION"; fi
85if [ -n "$OPT_BUTTON1_TEXT" ]; then set -- "$@" --es button_text_1 "$OPT_BUTTON1_TEXT"; fi
86if [ -n "$OPT_BUTTON2_ACTION" ]; then set -- "$@" --es button_action_2 "$OPT_BUTTON2_ACTION"; fi
87if [ -n "$OPT_BUTTON2_TEXT" ]; then set -- "$@" --es button_text_2 "$OPT_BUTTON2_TEXT"; fi
88if [ -n "$OPT_BUTTON3_ACTION" ]; then set -- "$@" --es button_action_3 "$OPT_BUTTON3_ACTION"; fi
89if [ -n "$OPT_BUTTON3_TEXT" ]; then set -- "$@" --es button_text_3 "$OPT_BUTTON3_TEXT"; fi
b4443d5e 90if [ -n "$OPT_ID" ]; then set -- "$@" --es id "$OPT_ID"; fi
b4443d5e 91if [ -n "$OPT_LED_COLOR" ]; then set -- "$@" --es led-color "$OPT_LED_COLOR"; fi
b4443d5e 92if [ -n "$OPT_LED_OFF" ]; then set -- "$@" --ei led-off "$OPT_LED_OFF"; fi
a78e1140 93if [ -n "$OPT_LED_ON" ]; then set -- "$@" --ei led-on "$OPT_LED_ON"; fi
b4443d5e
FF
94if [ -n "$OPT_PRIORITY" ]; then set -- "$@" --es priority "$OPT_PRIORITY"; fi
95if [ -n "$OPT_SOUND" ]; then set -- "$@" --ez sound "$OPT_SOUND"; fi
a78e1140 96if [ -n "$OPT_TITLE" ]; then set -- "$@" --es title "$OPT_TITLE"; fi
b4443d5e 97if [ -n "$OPT_VIBRATE" ]; then set -- "$@" --ela vibrate "$OPT_VIBRATE"; fi
8d6e165f 98
85699cc8
FF
99if [ -v OPT_CONTENT ]; then
100 # Note that we want to accept an empty content (--content "").
101 echo ${OPT_CONTENT:=""} | /data/data/com.termux/files/usr/libexec/termux-api Notification "$@"
a78e1140
FF
102else
103 /data/data/com.termux/files/usr/libexec/termux-api Notification "$@"
104fi