diff --git a/programs/sxmo_megiaudioroute.c b/programs/sxmo_megiaudioroute.c index ac49eac..6ddd926 100644 --- a/programs/sxmo_megiaudioroute.c +++ b/programs/sxmo_megiaudioroute.c @@ -351,7 +351,7 @@ static struct audio_setup audio_setup = { .hp_vol = 15, .spk_vol = 15, - .ear_vol = 31, + .ear_vol = 15, .mic_gain = 1, }; diff --git a/programs/sxmo_vibratepine.c b/programs/sxmo_vibratepine.c index 0d194fd..ddcba5b 100644 --- a/programs/sxmo_vibratepine.c +++ b/programs/sxmo_vibratepine.c @@ -68,7 +68,7 @@ int main(int argc, char* argv[]) int durationMs, strength; - if (argc < 1) { + if (argc < 2) { usage(); return 1; } diff --git a/scripts/appscripts/sxmo_youtube.sh b/scripts/appscripts/sxmo_youtube.sh index 8d2ab73..3fd671a 100755 --- a/scripts/appscripts/sxmo_youtube.sh +++ b/scripts/appscripts/sxmo_youtube.sh @@ -1,23 +1,35 @@ #!/usr/bin/env sh -pidof svkbd-sxmo || svkbd-sxmo & -SEARCHTERMS="$( - echo "Search term" | - dmenu -p "Yt Search" -c -l 10 -fn Terminus-20 -)" -pkill svkbd-sxmo +menu() { + pidof svkbd-sxmo || svkbd-sxmo & + SEARCHTERMS="$( + echo "Search term" | + dmenu -p "Yt Search" -c -l 10 -fn Terminus-20 + )" + pkill svkbd-sxmo -IDIOTRESULTS="$(idiotbox-cli $SEARCHTERMS)" -RESULT="$( - echo "$IDIOTRESULTS" | - grep -Ev '^(Channelid|Atom feed|Channel title|Published|Viewcount|Userid):' | - sed -E 's/^(URL|Duration):\s+/\t/g' | - tr -d '\n' | - sed 's/===/\n/g' | - gawk -F'\t' '{ print $3 " " $1 " " $2}' | - dmenu -c -l 10 -fn Terminus-20 -)" + IDIOTRESULTS="$(idiotbox-cli $SEARCHTERMS)" + RESULT="$( + echo "$IDIOTRESULTS" | + grep -Ev '^(Channelid|Atom feed|Channel title|Published|Viewcount|Userid):' | + sed -E 's/^(URL|Duration):\s+/\t/g' | + tr -d '\n' | + sed 's/===/\n/g' | + gawk -F'\t' '{ print $3 " " $1 " " $2}' | + dmenu -c -l 10 -fn Terminus-20 + )" -[[ "CLOSE_MENU" == "$RESULT" ]] && exit 0 + [[ "CLOSE_MENU" == "$RESULT" ]] && exit 0 + URL=$(echo "$RESULT" | awk -F " " '{print $NF}') +} -URL=$(echo "$RESULT" | awk -F " " '{print $NF}') -st -e mpv --ytdl-format='[height<420]' $@ "$URL" +video() { + menu + st -e mpv -v --ytdl-format='[height<420]' "$URL" +} + +audio() { + menu + st -e mpv -v --no-video "$URL" +} + +$@ diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh index 4a201ad..3f396fa 100755 --- a/scripts/core/sxmo_appmenu.sh +++ b/scripts/core/sxmo_appmenu.sh @@ -10,11 +10,11 @@ programchoicesinit() { Apps ^ 0 ^ sxmo_appmenu.sh applications Volume ↑ ^ 1 ^ sxmo_vol.sh up Volume ↓ ^ 1 ^ sxmo_vol.sh down - Dialer ^ 1 ^ sxmo_modemcall.sh dial - Texts ^ 0 ^ sxmo_readtexts.sh + Dialer ^ 0 ^ sxmo_modemcall.sh dial + Texts ^ 0 ^ sxmo_modemtext.sh Camera ^ 0 ^ sxmo_camera.sh Wifi ^ 0 ^ st -e "nmtui" - System Config ^ 0 ^ sxmo_appmenu.sh control + Config ^ 0 ^ sxmo_appmenu.sh config Logout ^ 0 ^ pkill -9 dwm ")" && WINNAME=Sys @@ -32,24 +32,25 @@ programchoicesinit() { # Scripts menu echo $WMCLASS | grep -i "scripts" && CHOICES="$(echo " Timer ^ 0 ^ sxmo_timermenu.sh - Youtube ^ 0 ^ sxmo_youtube.sh - Youtube (Audio) ^ 0 ^ sxmo_youtube.sh --no-video + Youtube ^ 0 ^ sxmo_youtube.sh video + Youtube (Audio) ^ 0 ^ sxmo_youtube.sh audio Weather ^ 0 ^ sxmo_weather.sh RSS ^ 0 ^ sxmo_rss.sh ")" && WINNAME=Scripts && return # System Control menu - echo $WMCLASS | grep -i "control" && CHOICES="$(echo " + echo $WMCLASS | grep -i "config" && CHOICES="$(echo " Volume ↑ ^ 1 ^ sxmo_vol.sh up Volume ↓ ^ 1 ^ sxmo_vol.sh down Brightesss ↑ ^ 1 ^ sxmo_brightness.sh up Brightness ↓ ^ 1 ^ sxmo_brightness.sh down Modem $(pgrep -f sxmo_modemmonitor.sh >/dev/null && echo -n "On → Off" || echo -n "Off → On") ^ 1 ^ sxmo_modemmonitortoggle.sh - Modem Info ^ 1 ^ sxmo_modeminfo.sh + Modem Info ^ 0 ^ sxmo_modeminfo.sh + Modem Log ^ 0 ^ sxmo_modemlog.sh Rotate ^ 1 ^ rotate Wifi ^ 0 ^ st -e "nmtui" Upgrade Pkgs ^ 0 ^ st -e sxmo_upgrade.sh - ")" && WINNAME=Control && return + ")" && WINNAME=Config && return # MPV echo $WMCLASS | grep -i "mpv" && CHOICES="$(echo " @@ -68,8 +69,8 @@ programchoicesinit() { # St echo $WMCLASS | grep -i "st-256color" && CHOICES="$(echo " - Pastecomplete ^ 0 ^ key Ctrl+Shift+u - Copycomplete ^ 0 ^ key Ctrl+Shift+i + Type complete ^ 0 ^ key Ctrl+Shift+u + Copy complete ^ 0 ^ key Ctrl+Shift+i Paste ^ 0 ^ key Ctrl+Shift+v Zoom + ^ 1 ^ key Ctrl+Shift+Prior Zoom - ^ 1 ^ key Ctrl+Shift+Next @@ -117,7 +118,7 @@ programchoicesinit() { Zoom - ^ 1 ^ key Ctrl+minus History ← ^ 1 ^ key Alt+Left History → ^ 1 ^ key Alt+Right - ")" && WINNAME=netsurf && return + ")" && WINNAME=firefox && return # Foxtrot GPS echo $WMCLASS | grep -i foxtrot && CHOICES="$(echo " @@ -162,8 +163,8 @@ rotate() { } key() { - xdotool windowactivate $WIN - xdotool key --clearmodifiers $1 + xdotool windowactivate "$WIN" + xdotool key --clearmodifiers "$1" #--window $WIN } diff --git a/scripts/core/sxmo_brightness.sh b/scripts/core/sxmo_brightness.sh index 1dea256..a6692ec 100755 --- a/scripts/core/sxmo_brightness.sh +++ b/scripts/core/sxmo_brightness.sh @@ -4,7 +4,8 @@ MAX=$(cat $DEV/max_brightness) MIN=2 -STEP=$(echo "($MAX - $MIN) / 10" | bc) +MINSTEP=1 +STEP=$(echo "($MAX - $MIN) / 10" | bc | xargs -ISTP echo -e "$MINSTEP\nSTP" | sort -r | head -n1) setdelta() { sxmo_setpinebacklight $( diff --git a/scripts/core/sxmo_dmenu_with_kb.sh b/scripts/core/sxmo_dmenu_with_kb.sh index 9661293..ccdaae5 100755 --- a/scripts/core/sxmo_dmenu_with_kb.sh +++ b/scripts/core/sxmo_dmenu_with_kb.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh pidof svkbd-sxmo >&2 || svkbd-sxmo & -OUTPUT="$(cat | dmenu -t $@)" +OUTPUT="$(cat | dmenu $@)" pkill svkbd-sxmo >&2 echo "$OUTPUT" diff --git a/scripts/core/sxmo_pipecomplete.sh b/scripts/core/sxmo_pipecomplete.sh index 7566798..79f134b 100755 --- a/scripts/core/sxmo_pipecomplete.sh +++ b/scripts/core/sxmo_pipecomplete.sh @@ -1,38 +1,35 @@ #!/usr/bin/env sh INPUT="$(cat)" +STWIN="$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')" -pidof svkbd-sxmo || svkbd-sxmo & - -capfirstchar() { - awk -F -vOFS= {$1=toupper($1);print $0} +menu() { + pidof svkbd-sxmo || svkbd-sxmo & + RESULT="$( + echo "$( + echo "Close Menu" && + echo "$INPUT" | grep -Eo '\S+' | tr -d '[:blank:]' | sort | uniq + )" | dmenu -p "$PROMPT" -l 10 -i -c -fn Terminus-20 + )" + pkill svkbd-sxmo } -RESULT="$( - echo "$( - echo "Close Menu" && - echo "$INPUT" |\ - grep -Eo '\S+' |\ - tr -d '[:blank:]' |\ - sort |\ - uniq - )" | dmenu -p $(echo $1 | capfirstchar) -l 10 -i -c -fn Terminus-20 -)" - -pkill svkbd-sxmo - copy() { + PROMPT=Copy + menu if [[ "$RESULT" = "Close Menu" ]]; then exit 0 else - echo "$RESULT" | xsel -i + echo "$RESULT" | xclip -i fi } type() { + PROMPT=Type + menu if [[ "$RESULT" = "Close Menu" ]]; then exit 0 else - xdotool type "$RESULT" + xdotool type --window $STWIN "$RESULT" fi } diff --git a/scripts/core/sxmo_statusbar.sh b/scripts/core/sxmo_statusbar.sh index fc20995..b702c54 100755 --- a/scripts/core/sxmo_statusbar.sh +++ b/scripts/core/sxmo_statusbar.sh @@ -1,6 +1,11 @@ #!/usr/bin/env sh pgrep -f sxmo_statusbar.sh | grep -v $$ | xargs kill -9 +audiodevice() { + amixer sget Earpiece | grep -E [[]on[]] && echo Earpiece > /dev/null && return + amixer sget Headphone > /dev/null && echo Headphone || echo Speaker +} + UPDATEFILE=/tmp/sxmo_bar touch $UPDATEFILE @@ -19,7 +24,7 @@ do # Volume VOL=$( - echo "$(amixer sget Headphone || amixer sget Speaker)" | + echo "$(audiodevice)" | grep -oE '([0-9]+)%' | tr -d ' %' | awk '{ s += $1; c++ } END { print s/c }' | diff --git a/scripts/core/sxmo_vol.sh b/scripts/core/sxmo_vol.sh index f6c1036..a08edcf 100755 --- a/scripts/core/sxmo_vol.sh +++ b/scripts/core/sxmo_vol.sh @@ -1,5 +1,6 @@ #!/usr/bin/env sh device() { + amixer sget Earpiece | grep -E '[[]on[]]' > /dev/null && echo Earpiece && return amixer sget Headphone > /dev/null && echo Headphone || echo Speaker } @@ -22,5 +23,8 @@ down() { amixer set $(device) 1- notify } +setvol() { + amixer set $(device) $1 +} $@ diff --git a/scripts/modem/sxmo_modemcall.sh b/scripts/modem/sxmo_modemcall.sh index 624a7d2..87d7161 100755 --- a/scripts/modem/sxmo_modemcall.sh +++ b/scripts/modem/sxmo_modemcall.sh @@ -1,14 +1,39 @@ #!/usr/bin/env sh +LOGDIR=/home/$USER/.sxmo err() { - echo $1 | dmenu -fn Terminus-20 -c -l 10 - exit 1 + echo -e "$1" | dmenu -fn Terminus-20 -c -l 10 + kill $$ } modem_n() { mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 } +contacts() { + cat $LOGDIR/modemlog.tsv | cut -f3 | sort | uniq | awk NF +} + + +modem_cmd_errcheck() { + ARGS="$@" + RES="$(sudo mmcli $ARGS 2>&1)" + [[ $? -eq 0 ]] || err "Problem executing mmcli command!\n$RES" + echo $RES +} + +vid_to_number() { + sudo mmcli -m $(modem_n) -o $1 -K | grep call.properties.number | cut -d ':' -f2 | tr -d ' ' +} + +log_event() { + EVT_HANDLE="$1" + EVT_VID="$2" + NUMBER="$(vid_to_number $EVT_VID)" + TIME="$(date --iso-8601=seconds)" + echo -ne "$TIME\t$EVT_HANDLE\t$NUMBER\n" >> $LOGDIR/modemlog.tsv +} + toggleflag() { TOGGLEFLAG=$1 shift @@ -25,13 +50,15 @@ toggleflag() { } dialmenu() { - NUMS=$(ls -1 ~/.sxmo || "") + CONTACTS="$(contacts)" NUMBER="$( - echo -e "$NUMS\nTest Number 804-222-1111" | - dmenu -l 10 -p Number -c -fn Terminus-20 | + echo -e "Close Menu\n$CONTACTS\nTest Number 804-222-1111" | + sxmo_dmenu_with_kb.sh -l 10 -p Number -c -fn Terminus-20 | awk -F' ' '{print $NF}' | tr -d - )" + echo $NUMBER | grep "Close Menu" && kill $$ + echo "Attempting to dial: $NUMBER" >&2 VID="$( sudo mmcli -m $(modem_n) --voice-create-call "number=$NUMBER" | grep -Eo Call/[0-9]+ | grep -oE [0-9]+ @@ -43,32 +70,40 @@ dialmenu() { startcall() { VID="$1" - sudo mmcli --voice-status -o $VID - sudo mmcli -m $(modem_n) -o $VID --start | grep "successfully started" || err "Couldn't start call!" + #modem_cmd_errcheck --voice-status -o $VID + modem_cmd_errcheck -m $(modem_n) -o $VID --start + log_event "call_start" $VID } acceptcall() { VID="$1" echo "Attempting to pickup VID $VID" - sudo mmcli --voice-status -o $VID - sudo mmcli -m $(modem_n) -o $VID --accept | grep "successfully" || err "Couldn't accept call!" + #sudo mmcli --voice-status -o $VID + modem_cmd_errcheck -m $(modem_n) -o $VID --accept + log_event "call_pickup" $VID } hangup() { VID=$1 - sudo mmcli -m $(modem_n) -o $VID --hangup | grep "successfully hung up" || err "Failed to hangup the call?" + modem_cmd_errcheck -m $(modem_n) -o $VID --hangup + log_event "call_hangup" $VID + err "Call hungup ok" exit 1 } incallmenu() { DMENUIDX=0 VID="$1" - NUMBER=$(mmcli -m $(modem_n) -o $VID -K | grep call.properties.number | cut -d ':' -f2 | tr -d ' ') - # E.g. Run once w/o -2, and then run once with -2 - FLAGS="-e -m" - sxmo_megiaudioroute $FLAGS - FLAGS="$FLAGS -2" - sxmo_megiaudioroute $FLAGS + NUMBER="$(vid_to_number $VID)" + + # E.g. There's some bug with the modem that' requires us to toggle the + # DAI a few times before starting the call for it to kick in + FLAGS=" " + FLAGS="$(toggleflag "-e" "$FLAGS")" + FLAGS="$(toggleflag "-m" "$FLAGS")" + FLAGS="$(toggleflag "-2" "$FLAGS")" + FLAGS="$(toggleflag "-2" "$FLAGS")" + FLAGS="$(toggleflag "-2" "$FLAGS")" while true do @@ -79,19 +114,20 @@ incallmenu() { echo -- "$FLAGS" | grep -- "-s" && TSPEAKER="Speakerphone Off" || TSPEAKER="Speakerphone On" CHOICES="$(echo -ne ' - Volume ↑ ^ sxmo_vol.sh up - Volume ↓ ^ sxmo_vol.sh down - TMUTE ^ FLAGS="$(toggleflag "-m" "$FLAGS")" - TECHO ^ FLAGS="$(toggleflag "-z" "$FLAGS")" - TEARPIECE ^ FLAGS="$(toggleflag "-e" "$FLAGS")" - TLINEJACK ^ FLAGS="$(toggleflag "-h" "$FLAGS")" - TSPEAKER ^ FLAGS="$(toggleflag "-s" "$FLAGS")" - DTMF Tones ^ dtmfmenu $VID - Hangup ^ hangup $VID + Volume ↑ ^ sxmo_vol.sh up + Volume ↓ ^ sxmo_vol.sh down + TMUTE ^ FLAGS="$(toggleflag "-m" "$FLAGS")" + TECHO ^ FLAGS="$(toggleflag "-z" "$FLAGS")" + TEARPIECE ^ FLAGS="$(toggleflag "-e" "$FLAGS")" + TLINEJACK ^ FLAGS="$(toggleflag "-h" "$FLAGS")" + TSPEAKER ^ FLAGS="$(toggleflag "-s" "$FLAGS")" + DTMF Tones ^ dtmfmenu $VID + Hangup ^ hangup $VID Lock Screen ^ sxmo_screenlock ' | sed "s/TMUTE/$TMUTE/;s/TECHO/$TECHO/;s/TEARPIECE/$TEARPIECE/;s/TLINEJACK/$TLINEJACK/;s/TSPEAKER/$TSPEAKER/" )" + PICKED="" PICKED=$( echo "$CHOICES" | xargs -0 echo | @@ -100,6 +136,10 @@ incallmenu() { awk '{$1=$1};1' | dmenu -idx $DMENUIDX -l 14 -c -fn "Terminus-30" -p "$NUMBER" ) + + # E.g. in modem watcher script we just kill dmenu if the other side hangsup + echo "$PICKED" | grep -Ev "." && err "$NUMBER hung up the call" + CMD=$(echo "$CHOICES" | grep "$PICKED" | cut -d '^' -f2) DMENUIDX=$(echo $(echo "$CHOICES" | grep -n "$PICKED" | cut -d ':' -f1) - 1 | bc) eval $CMD @@ -108,19 +148,18 @@ incallmenu() { dtmfmenu() { VID=$1 - DMENUIDX=0 + DTMFINDEX=0 NUMS="0123456789*#ABCD" while true do PICKED="$( echo "$NUMS" | grep -o . | sed '1 iReturn to Call Menu' | - dmenu -l 20 -fn Terminus-20 -c -idx $DMENUIDX -p "DTMF Tone" + dmenu -l 20 -fn Terminus-20 -c -idx $DTMFINDEX -p "DTMF Tone" )" - DMENUIDX=$(echo "$NUMS" | grep -bo "$PICKED" | cut -d: -f1 | xargs -IN echo 2+N | bc) - - echo "$PICKED" | grep "Return to Call Menu" && break - sudo mmcli -m $(modem_n) -o $VID --send-dtmf="$PICKED" + echo "$PICKED" | grep "Return to Call Menu" && return + DTMFINDEX=$(echo "$NUMS" | grep -bo "$PICKED" | cut -d: -f1 | xargs -IN echo 2+N | bc) + modem_cmd_errcheck -m $(modem_n) -o $VID --send-dtmf="$PICKED" done } diff --git a/scripts/modem/sxmo_modeminfo.sh b/scripts/modem/sxmo_modeminfo.sh index 7614011..9078fc2 100755 --- a/scripts/modem/sxmo_modeminfo.sh +++ b/scripts/modem/sxmo_modeminfo.sh @@ -1,5 +1,4 @@ #!/usr/bin/env sh - modem_n() { mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 } diff --git a/scripts/modem/sxmo_modemlog.sh b/scripts/modem/sxmo_modemlog.sh new file mode 100755 index 0000000..8eae791 --- /dev/null +++ b/scripts/modem/sxmo_modemlog.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +st -fn "Terminus-14" -e tail -f ~/.sxmo/modemlog.tsv diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh index e3aec2d..e7f04f5 100755 --- a/scripts/modem/sxmo_modemmonitor.sh +++ b/scripts/modem/sxmo_modemmonitor.sh @@ -1,5 +1,7 @@ #!/usr/bin/env sh TIMEOUT=3 +LOGDIR=/home/$USER/.sxmo +ACTIVECALL="NONE" modem_n() { mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 @@ -7,6 +9,7 @@ modem_n() { newcall() { VID="$1" + sxmo_vibratepine 2000 & sxmo_setpineled green 1 for i in $(sudo mmcli -m $(modem_n) --voice-list-calls | grep terminated | grep -oE Call\/[0-9]+ | cut -d'/' -f2); do @@ -19,8 +22,12 @@ newcall() { grep call.properties.number | cut -d ':' -f 2 ) + + TIME="$(date --iso-8601=seconds)" + echo -ne "$TIME\tcall_ring\t$NUMBER\n" >> $LOGDIR/modemlog.tsv echo "$VID:$INCOMINGNUMBER" > /tmp/sxmo_incomingcall echo "Number: $INCOMINGNUMBER (VID: $VID)" + } newtexts() { @@ -35,13 +42,46 @@ newtexts() { TIME="$(echo "$DAT" | grep sms.properties.timestamp | sed -E 's/^sms\.properties\.timestamp\s+:\s+//')" TEXTSIZE="$(echo $TEXT | wc -c)" - mkdir -p ~/.sxmo/$NUM - echo -ne "$NUM at $TIME:\n$TEXT\n\n" >> ~/.sxmo/$NUM/sms.txt - echo -ne "$TIME\trecv_txt\t$NUM\t$TEXTSIZE chars\n" >> ~/.sxmo/$NUM/log.tsv + mkdir -p "$LOGDIR/$NUM" + echo -ne "Received from $NUM at $TIME:\n$TEXT\n\n" >> $LOGDIR/$NUM/sms.txt + echo -ne "$TIME\trecv_txt\t$NUM\t$TEXTSIZE chars\n" >> $LOGDIR/modemlog.tsv sudo mmcli -m $(modem_n) --messaging-delete-sms=$i + + sxmo_vibratepine 300 && sleep 0.1 + sxmo_vibratepine 300 && sleep 0.1 + sxmo_vibratepine 300 done } +killinprogresscall() { + echo "Kill the in progress call" + pkill -9 dmenu +} + +inprogresscallchecker() { + # E.g. register current call in progress as ACTIVECALL + CURRENTCALLS="$(mmcli -m $(modem_n) --voice-list-calls)" + + # E.g. if we've previously registered an ACTIVECALL, check if it + # was terminated by the otherside, if so kill the incall script + # and notify user + echo "$ACTIVECALL" | grep -E '[0-9]+' && $( + echo "$CURRENTCALLS" | + grep -E "Call/${ACTIVECALL}.+terminated" && + killinprogresscall + ) + + # Register the active call so we can check in future loops if + # other side hung up + ACTIVECALL="$( + echo "$CURRENTCALLS" | + grep -oE "[0-9]+ (incoming|outgoing).+active" | + cut -d' ' -f1 + )" + + echo "Set new Activecall:<$ACTIVECALL>" +} + while true do sxmo_setpineled green 0 @@ -57,10 +97,11 @@ do grep -Eo '[0-9]+' )" - echo VIDS $VOICECALLID - echo TIDS $TEXTIDS + echo "Check status, VIDS: $VOICECALLID, TIDS: $TEXTIDS" + + inprogresscallchecker - echo "$VOICECALLID" | grep . && newcall "$VOICECALLID" || rm /tmp/sxmo_incomingcall + echo "$VOICECALLID" | grep . && newcall "$VOICECALLID" || rm -f /tmp/sxmo_incomingcall echo "$TEXTIDS" | grep . && newtexts "$TEXTIDS" sleep $TIMEOUT done diff --git a/scripts/modem/sxmo_modemsendtext.sh b/scripts/modem/sxmo_modemsendtext.sh deleted file mode 100755 index cb3c224..0000000 --- a/scripts/modem/sxmo_modemsendtext.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env sh -EDITOR=vis - -err() { - echo $1 | dmenu -fn Terminus-20 -c -l 10 - exit 1 -} - -modem_n() { - mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 -} - -editmsg() { - TMP="$(mktemp --suffix $1_msg)" - echo "$2" > "$TMP" - TEXT="$(st -e $EDITOR $TMP)" - cat $TMP -} - -sendmsg() { - MODEM=$(modem_n) - SMSNO=$( - sudo mmcli -m $MODEM --messaging-create-sms="text='$2',number=$1" | - grep -o [0-9]*$ - ) - sudo mmcli -s ${SMSNO} --send - for i in $(mmcli -m $MODEM --messaging-list-sms | grep " (sent)" | cut -f5 -d' ') ; do - sudo mmcli -m $MODEM --messaging-delete-sms=$i - done -} - -main() { - modem_n || err "Couldn't determine modem number - is modem online?" - - # Prompt for number - NUMBER=$( - echo -e "Enter Number: \nCancel" | - dmenu -p "Number" -fn "Terminus-20" -l 10 -c - ) - echo "$NUMBER" | grep -E "^Cancel$" && exit 1 - - # Compose first version of msg - TEXT="$(editmsg $NUMBER 'Enter text message here')" - - while true - do - CHARS=$(echo "$TEXT" | wc -c) - CONFIRM=$( - echo -e "Message ($CHARS) to -> $NUMBER: ($TEXT)\nEdit\nSend\nCancel" | - dmenu -c -idx 1 -p "Confirm" -fn "Terminus-20" -l 10 - ) - echo "$CONFIRM" | grep -E "^Send$" && sendmsg "$NUMBER" "$TEXT" && exit 0 - echo "$CONFIRM" | grep -E "^Cancel$" && exit 1 - echo "$CONFIRM" | grep -E "^Edit$" && TEXT="$(editmsg "$NUMBER" "$TEXT")" - done -} - -main diff --git a/scripts/modem/sxmo_modemtext.sh b/scripts/modem/sxmo_modemtext.sh new file mode 100755 index 0000000..f276fda --- /dev/null +++ b/scripts/modem/sxmo_modemtext.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env sh +EDITOR=vis +LOGDIR=/home/$USER/.sxmo + +err() { + echo $1 | dmenu -fn Terminus-20 -c -l 10 + kill $$ +} + +modem_n() { + mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 +} + +contacts() { + cat $LOGDIR/modemlog.tsv | cut -f3 | sort | uniq | awk NF +} + +editmsg() { + TMP="$(mktemp --suffix $1_msg)" + echo "$2" > "$TMP" + TEXT="$(st -e $EDITOR $TMP)" + cat $TMP +} + +sendmsg() { + MODEM=$(modem_n) + NUMBER="$1" + TEXT="$2" + TEXTSIZE="$(echo "$TEXT" | wc -c)" + + SMSNO=$( + sudo mmcli -m $MODEM --messaging-create-sms="text='$TEXT',number=$NUMBER" | + grep -o [0-9]*$ + ) + sudo mmcli -s ${SMSNO} --send || err "Couldn't send text message" + for i in $(mmcli -m $MODEM --messaging-list-sms | grep " (sent)" | cut -f5 -d' ') ; do + sudo mmcli -m $MODEM --messaging-delete-sms=$i + done + + TIME="$(date --iso-8601=seconds)" + mkdir -p ~/.sxmo/$NUMBER + echo -ne "Sent to $NUMBER at $TIME:\n$TEXT\n\n" >> $LOGDIR/$NUMBER/sms.txt + echo -ne "$TIME\tsent_txt\t$NUMBER\t$TEXTSIZE chars\n" >> $LOGDIR/modemlog.tsv + + err "Sent text message ok" +} + +sendtextmenu() { + modem_n || err "Couldn't determine modem number - is modem online?" + + # Prompt for number + NUMBER=$( + echo -e "\nCancel\n$(contacts)" | + awk NF | + sxmo_dmenu_with_kb.sh -p "Number" -fn "Terminus-20" -l 10 -c + ) + echo "$NUMBER" | grep -E "^Cancel$" && exit 1 + echo "$NUMBER" | grep -E '[0-9]+' || err "That doesn't seem like a valid number" + + # Compose first version of msg + TEXT="$(editmsg $NUMBER 'Enter text message here')" + + while true + do + CHARS=$(echo "$TEXT" | wc -c) + CONFIRM=$( + echo -e "Edit Message ($TEXT)\nSend to → $NUMBER\nCancel" | + dmenu -c -idx 1 -p "Confirm" -fn "Terminus-20" -l 10 + ) + echo "$CONFIRM" | grep -E "^Send" && sendmsg "$NUMBER" "$TEXT" && exit 0 + echo "$CONFIRM" | grep -E "^Cancel$" && exit 1 + echo "$CONFIRM" | grep -E "^Edit Message" && TEXT="$(editmsg "$NUMBER" "$TEXT")" + done +} + +tailtextlog() { + st -e tail -f $LOGDIR/$1/sms.txt +} + +main() { + # Display + ENTRIES="$(echo -e "$(contacts)" | xargs -INUM echo NUM logfile)" + ENTRIES="$(echo -e "Close Menu\nSend a Text\n$ENTRIES")" + NUMBER="$(echo -e "$ENTRIES" | dmenu -p Texts -c -fn Terminus-20 -l 10)" + echo $NUMBER | grep "Close Menu" && exit 1 + echo $NUMBER | grep "Send a Text" && sendtextmenu && exit 1 + tailtextlog "$(echo $NUMBER | sed 's/ logfile//g')" +} + +main \ No newline at end of file diff --git a/scripts/modem/sxmo_readtexts.sh b/scripts/modem/sxmo_readtexts.sh deleted file mode 100755 index 00caca5..0000000 --- a/scripts/modem/sxmo_readtexts.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env sh -DIR=/home/$USER/.sxmo - -# Warn for no texts -ls -1 $DIR | wc -l | grep -E '^0$' && echo "No texts!" | dmenu -fn Terminus-20 -l 10 -c && exit 1 - -# Display -ls -1 $DIR | dmenu -p Messages -c -fn Terminus-20 -l 10 | xargs -INUMBER st -e tail -f $DIR/NUMBER/sms.txt \ No newline at end of file