Update basics.yml

This commit is contained in:
olli 2023-06-30 12:32:11 +02:00
parent 04f83c2681
commit 4aa71d7bc7

View File

@ -735,6 +735,116 @@
state: absent state: absent
when: nocontainer.stat.exists == true when: nocontainer.stat.exists == true
- name: /usr/local/bin/notify.sh
blockinfile:
path: /usr/local/bin/notify.sh
mode: "0555"
owner: root
group: root
create: yes
marker: "# {mark} ANSIBLE MANAGED BLOCK"
block: |
if [ -n "$SSH_ORIGINAL_COMMAND" ]
then
opts=$SSH_ORIGINAL_COMMAND
unset SSH_ORIGINAL_COMMAND
echo $opts >/tmp/SSH
notify.sh $opts
exit $?
fi
. /etc/bash/gaboshlib.include
g_nice
g_lockfile
[ -f /usr/local/etc/notify.conf ] && . /usr/local/etc/notify.conf
to="$default_to"
togroup="$default_togroup"
while getopts s:t:g:h:m: o
do
case $o in
s) subj="$OPTARG";;
t) to="$OPTARG";;
g) togroup="$OPTARG";;
h) tohost="$OPTARG";;
m) tomail="$OPTARG"
esac
done
# If message should be sent by another host
if [ -n "$tohost" ]
then
if getent passwd signal >/dev/null
then
cat | sudo -u signal ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new -p33 $tohost " $@"
else
cat | ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new -p33 $tohost " $@"
fi
exit $?
fi
message="$(cat)"
[ "$message" = "''" ] && exit 0
[ -z "$message" ] && exit 0
if [ -n "$subj" ]
then
message=$(echo -e "$subj\n$message")
fi
if [ -n "$SSH_ORIGINAL_COMMAND" ]
then
subj=$(echo "$SSH_ORIGINAL_COMMAND" | sed 's#^/usr/local/bin/notify.sh##; s/^ *//; s/^\"//; s/\"$//')
message=$(echo -e "$subj$message")
fi
if [ -n "$tomail" ]
then
echo "$message" | mail -s "notify.sh: $subj" $tomail
fi
account=$(cat /home/signal/.local/share/signal-cli/data/accounts.json | jq -r '.accounts[0].number' | sed 's/+/_/')
if [ -z "$account" ]
then
echo "Didn't get Signal account"
exit 1
fi
if [ -n "$togroup" ]
then
# Send to group via dbus
# Get group ID via dbus according to: https://github.com/AsamK/signal-cli/issues/1046
groupid=$(dbus-send --system --type=method_call --print-reply --dest='org.asamk.Signal' /org/asamk/Signal/${account} org.asamk.Signal.listGroups | grep "$togroup" -B3 | head -n2 | perl -pe 's/\n/ /g;' | perl -pe 's/ +/ /g; s/ $//; s/ /,0x/g; s/^,//')
if [ -z "$groupid" ]
then
g_echo_error "Group(ID) $togroup not found (id=$groupid). Does Group really exist? -- Groups $(dbus-send --system --type=method_call --print-reply --dest='org.asamk.Signal' /org/asamk/Signal/${account} org.asamk.Signal.listGroups)"
exit 1
fi
dbus-send --system --type=method_call --print-reply --dest="org.asamk.Signal" /org/asamk/Signal/${account} org.asamk.Signal.sendGroupMessage string:"$message" array:string: array:byte:${groupid} | egrep -v '^method return time=|^ int64 '
fi
if [ -n "$to" ]
then
# Sent to a single Number via dbus
dbus-send --system --type=method_call --print-reply --dest="org.asamk.Signal" /org/asamk/Signal/${account} org.asamk.Signal.sendMessage string:"${message}" array:string: string:${to} | egrep -v '^method return time=|^ int64 '
fi
backup: yes
validate: /bin/bash -n %s
- name: /usr/local/bin/notify.sh shebang
lineinfile:
path: /usr/local/bin/notify.sh
insertbefore: BOF
line: "#!/bin/bash"
handlers: handlers:
- name: setupcon - name: setupcon