Initial work on modem functionality

Including, checking for incoming calls, missed calls, sms and the start
of a dialer using rofi
master
Jonathan Hodgson 4 years ago
parent afb6634bec
commit 1ab519531c
  1. 128
      bin/.bin/modem/checkCall
  2. 58
      bin/.bin/modem/checkSMS
  3. 54
      bin/.bin/modem/common
  4. 7
      bin/.bin/modem/dialer
  5. 38
      bin/.bin/modem/missedCalls
  6. 29
      bin/.bin/modem/monitorModem

@ -0,0 +1,128 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source "$DIR/common"
usage(){
echo "checkCall [options] [message|-]"
echo "Options:"
echo " -h|--help Display this help text"
echo " -m|--modem Specify a modem"
echo " --dry-run Don't actually send the message"
}
# Stolen from sxmo
lookupnumberfromcallid() {
local id=$1
mmcli -m "$modem" --voice-list-calls -o "$id" -K |
grep call.properties.number |
cut -d ':' -f 2 |
tr -d ' '
}
lookupcontact(){
echo "$1" |
# Remove the +44 and replace with 0
sed 's/^\+44/0/'
# This will eventually work with abook but for now just return the number
}
answer-call(){
mmcli -m "$modem" -o "$1" --accept
}
reject-call(){
notify-send "Reject"
}
prompt-incoming(){
export DISPLAY=:0.0
local answer=""
local reject=""
local choice=''
# Used for testing
local number="${1:-01234 567890}"
local prompt="$(echo -en "Incoming Call\n$number")"
while [ -z "$choice" ]; do
choice="$(echo -e "$answer\n$reject" | rofi -dmenu -i \
-theme themes/incoming-call.rasi -a 0 -u 1 \
-p "$prompt" \
-me-select-entry '' -me-accept-entry MousePrimary)"
case "$choice" in
"$answer") echo "answer" ;;
"$reject") echo "reject" ;;
esac
done
}
mkdir -p "$CALL_DIR"
dryrun="false"
# Assume we want the first modem
# can be overwritten by the -m option
modem="$(mmcli -L | grep -oE 'Modem\/[0-9]+' | head -n 1 | cut -d'/' -f2)"
# Read the options and set stuff
while [[ $1 = -?* ]]; do
case $1 in
-h|--help) usage; exit;;
-m|--modem) modem="$2"; shift ;;
--dry-run) dryrun="true" ;;
--) shift; break ;;
*) die "invalid option: '$1'." ;;
esac
shift
done
checkIncoming(){
local id="$( mmcli -m "$modem" --voice-list-calls |
grep -Eo '[0-9]+ incoming \(ringing-in\)' | grep -Eo '[0-9]+' )"
local count="$(echo "$id" | deleteEmptyLines | wc -l)"
[ "$count" -eq 0 ] && return
local number="$(lookupnumberfromcallid "$id")"
local contact="$(lookupcontact "$number")"
local action="$(prompt-incoming "$contact")"
case action in
accept) answer-call "$id" ;;
reject) reject-call "$id" ;;
esac
}
checkFinished(){
local ids="$( mmcli -m "$modem" --voice-list-calls |
grep -Eo '[0-9]+ incoming \(terminated\)' | grep -Eo '[0-9]+' )"
local count="$(echo "$ids" | deleteEmptyLines | wc -l)"
[ "$count" -eq 0 ] && return
echo "$ids" | while read -r id; do
# Delete from the modem
local number="$(lookupnumberfromcallid "$id")"
local contact="$(lookupcontact "$number")"
echo "Missed call from $contact" >> "$CALL_DIR/missed-calls"
mmcli -m "$modem" --voice-delete-call "$id"
done
}
checkIncoming &
checkFinished &

@ -1,19 +1,15 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source "$DIR/common"
# This is largely borrowed from:
# https://git.sr.ht/~mil/sxmo-utils/tree/master/item/scripts/modem/sxmo_modemmonitor.sh
# This is where sms messages will be stored
SMS_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/SMS/"
die(){
echo "$@" > /dev/stderr
rm "$FILE"
exit 1
}
usage(){
echo "checkSMS [options] [message|-]"
echo "checkSMS [options]"
echo "Options:"
echo " -h|--help Display this help text"
echo " -m|--modem Specify a modem"
@ -21,57 +17,15 @@ usage(){
}
trimWhitespace(){
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
}
mkdir -p "$SMS_DIR"
dryrun="false"
edit="false"
# Assume we want the first modem
# can be overwritten by the -m option
modem="$(mmcli -L | grep -oE 'Modem\/[0-9]+' | head -n 1 | cut -d'/' -f2)"
# Iterate over options breaking -ab into -a -b when needed and --foo=bar into
# --foo bar
optstring=h
unset options
while (($#)); do
case $1 in
# If option is of type -ab
-[!-]?*)
# Loop over each character starting with the second
for ((i=1; i < ${#1}; i++)); do
c=${1:i:1}
# Add current char to options
options+=("-$c")
# If option takes a required argument, and it's not the last char make
# the rest of the string its argument
if [[ $optstring = *"$c:"* && ${1:i+1} ]]; then
options+=("${1:i+1}")
break
fi
done
;;
# If option is of type --foo=bar
--?*=*) options+=("${1%%=*}" "${1#*=}") ;;
# add --endopts for --
--) options+=(--endopts) ;;
# Otherwise, nothing special
*) options+=("$1") ;;
esac
shift
done
set -- "${options[@]}"
unset options
# Read the options and set stuff
while [[ $1 = -?* ]]; do
case $1 in
@ -88,9 +42,9 @@ done
ids="$( mmcli -m "$modem" --messaging-list-sms |
grep -Eo '/SMS/[0-9]+ \(received\)' | grep -Eo '[0-9]+' )"
count="$(echo "$ids" | wc -l)"
count="$(echo "$ids" | deleteEmptyLines | wc -l)"
[ "$count" -eq 0 ] && return
[ "$count" -eq 0 ] && exit
echo "$ids" | while read -r id; do
# Get the details of the message

@ -0,0 +1,54 @@
#!/usr/bin/env bash
CALL_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/Calls/"
SMS_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/SMS/"
die(){
echo "$@" > /dev/stderr
rm "$FILE"
exit 1
}
trimWhitespace(){
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
}
deleteEmptyLines(){
sed '/^$/ d'
}
# Iterate over options breaking -ab into -a -b when needed and --foo=bar into
# --foo bar
optstring=h
unset options
while (($#)); do
case $1 in
# If option is of type -ab
-[!-]?*)
# Loop over each character starting with the second
for ((i=1; i < ${#1}; i++)); do
c=${1:i:1}
# Add current char to options
options+=("-$c")
# If option takes a required argument, and it's not the last char make
# the rest of the string its argument
if [[ $optstring = *"$c:"* && ${1:i+1} ]]; then
options+=("${1:i+1}")
break
fi
done
;;
# If option is of type --foo=bar
--?*=*) options+=("${1%%=*}" "${1#*=}") ;;
# add --endopts for --
--) options+=(--endopts) ;;
# Otherwise, nothing special
*) options+=("$1") ;;
esac
shift
done
set -- "${options[@]}"
unset options

@ -1,4 +1,5 @@
#!/usr/bin/env bash
export DISPLAY=:0.0
prompt=""
@ -19,14 +20,14 @@ $answer
6
9
#
# "
X"
while true; do
notify-send "$prompt"
#notify-send "$prompt"
input="$(echo "$options" |
rofi -dmenu -p "$prompt" -theme themes/dialer.rasi \
-me-select-entry '' -me-accept-entry MousePrimary)"
[ "$input" = "#" ] && exit
[ "$input" = "X" ] && exit
#exit
prompt+="$input"
done

@ -0,0 +1,38 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source "$DIR/common"
usage(){
echo "missedCalls"
echo "-a --all Print all (default)"
echo "-c --count Print count"
echo "-l --list Print list"
}
toprint="all"
# Read the options and set stuff
while [[ $1 = -?* ]]; do
case $1 in
-a|--all) toprint="all" ;;
-c|--count) toprint="count" ;;
-l|--list) toprint="list" ;;
-h|--help) usage; exit;;
--) shift; break ;;
*) die "invalid option: '$1'." ;;
esac
shift
done
[ -f "$CALL_DIR/missed-calls" ] || exit
if [ "$toprint" = "count" ] || [ "$toprint" = "all" ]; then
count="$(cat "$CALL_DIR/missed-calls" | deleteEmptyLines | wc -l )"
echo "$count missed calls"
fi
if [ "$toprint" = "list" ] || [ "$toprint" = "all" ]; then
cat "$CALL_DIR/missed-calls"
fi

@ -0,0 +1,29 @@
#!/usr/bin/env bash
# This was mostly taken from sxmo:
# https://git.sr.ht/~mil/sxmo-utils/tree/1.3.2/item/scripts/modem/sxmo_modemmonitor.sh#L181-205
#
# Although the proccess for managing calls etc is a bit simpler IMO
# Monitor for incoming calls
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Voice',type='signal',member='CallAdded'" | \
while read -r line; do
echo "$line" | grep -E "^signal" && checkCall
done &
# Monitor for incoming texts
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Messaging',type='signal',member='Added'" | \
while read -r line; do
echo "$line" | grep -E "^signal" && checkSMS
done &
# Monitor for finished calls
dbus-monitor --system "interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.freedesktop.ModemManager1.Call'" | \
while read -r line; do
echo "$line" | grep -E "^signal" && checkCall
done &
wait
wait
wait
Loading…
Cancel
Save