s+ow: many (#53)

* s+ow: many

- fix #52: handle SPOW_CRON=n
- start sm phase at 59, not after
- print failed to get location message
- fix usage text indentation

* s+ow: lint and format
This commit is contained in:
Mark Joshwel 2023-11-03 00:44:53 +08:00 committed by GitHub
parent 01c540750a
commit 8fecc090bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

17
s+ow
View file

@ -46,6 +46,11 @@ if [ "$LOCATION_PRIORITISE_NETWORK" = "n" ]; then
LOCATION_PRIORITISE_NETWORK="" LOCATION_PRIORITISE_NETWORK=""
fi fi
# check for cron status
if [ "$SPOW_CRON" = "n" ]; then
SPOW_CRON=""
fi
# ensure commands exist # ensure commands exist
if ! command -v termux-location >/dev/null 2>&1; then if ! command -v termux-location >/dev/null 2>&1; then
printf "s+ow: error: termux-location is not installed.\ninstall it with 'pkg install termux-api' and with installing the termux:api app from the play store or f-droid.\n" printf "s+ow: error: termux-location is not installed.\ninstall it with 'pkg install termux-api' and with installing the termux:api app from the play store or f-droid.\n"
@ -88,7 +93,7 @@ locate() {
else else
printf "net?" | tee -a "$SPOW_SESH_ERR" printf "net?" | tee -a "$SPOW_SESH_ERR"
fi fi
cat "$SPOW_NETLC_OUT" >> "$SPOW_SESH_OUT" cat "$SPOW_NETLC_OUT" >>"$SPOW_SESH_OUT"
) & ) &
tl_net_pid="$!" tl_net_pid="$!"
sleep 1 sleep 1
@ -99,7 +104,7 @@ locate() {
else else
printf "gps?" | tee -a "$SPOW_SESH_ERR" printf "gps?" | tee -a "$SPOW_SESH_ERR"
fi fi
cat "$SPOW_GPSLC_OUT" >> "$SPOW_SESH_OUT" cat "$SPOW_GPSLC_OUT" >>"$SPOW_SESH_OUT"
) & ) &
tl_gps_pid="$!" tl_gps_pid="$!"
@ -251,11 +256,13 @@ run() {
for locate_run in 1 2 3; do # run three times in case :p for locate_run in 1 2 3; do # run three times in case :p
notify "Running termux-location" "$locate_run" notify "Running termux-location" "$locate_run"
locate if [ "$locate_run" -gt "1" ]; then
LOCATION_TIMEOUT=75 locate
fi
if [ ! -s "$SPOW_LOCTN_OUT" ]; then if [ ! -s "$SPOW_LOCTN_OUT" ]; then
# erroneous: is empty # erroneous: is empty
echo "s+ow: error: failed to get location" >>"$SPOW_SESH_ERR" echo "s+ow: error: failed to get location" | tee -a "$SPOW_SESH_ERR"
status=1 status=1
else else
# nominal: is not empty # nominal: is not empty
@ -295,7 +302,7 @@ run() {
if [ -n "$SPOW_CRON" ]; then if [ -n "$SPOW_CRON" ]; then
notify "Waiting for the new hour..." notify "Waiting for the new hour..."
printf "waiting until the new hour...\n" printf "waiting until the new hour...\n"
while [ "$(date +'%M')" -eq 59 ]; do while [ "$(date +'%M')" -lt 59 ]; do
printf " $(date)\n" printf " $(date)\n"
sleep 1 sleep 1
done done