2025-04-10 07:42:17 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-12-27 18:31:56 +00:00
|
|
|
|
2020-12-30 03:32:16 +00:00
|
|
|
USAGE="
|
2021-01-02 04:47:30 +00:00
|
|
|
USAGE: avds <mod_list|-h|-[-]help> [<when>] [<repeat>]
|
2020-12-27 18:31:56 +00:00
|
|
|
|
2021-01-01 18:17:08 +00:00
|
|
|
mod_list
|
|
|
|
A comma or space separated list of modules to request that
|
2021-01-03 06:10:16 +00:00
|
|
|
the daemon execute. If mod_list begins this '>>* ', then
|
|
|
|
requests are sent to all running daemons.
|
2020-12-27 18:31:56 +00:00
|
|
|
|
|
|
|
when The integer number of milliseconds to wait before sending the
|
2021-01-01 18:17:08 +00:00
|
|
|
request, or one of the following values:
|
|
|
|
- m to send the update request at the top of the next minute
|
|
|
|
- h to send the update request at the top of the next hour
|
|
|
|
- d to send the update request at the top of the next day
|
|
|
|
If not present, the request will be sent immediately.
|
2020-12-27 18:31:56 +00:00
|
|
|
|
2021-01-01 18:17:08 +00:00
|
|
|
repeat If present, the request will be sent repeatedly according
|
2020-12-27 18:31:56 +00:00
|
|
|
to <when>.
|
|
|
|
|
|
|
|
EXAMPLES:
|
|
|
|
|
2021-01-02 04:47:30 +00:00
|
|
|
Any of these will display this help message.
|
|
|
|
|
|
|
|
avds -h
|
|
|
|
avds -help
|
|
|
|
avds --help
|
|
|
|
|
2021-01-01 18:17:08 +00:00
|
|
|
If there are volume and backlight modules named 'vol' and 'bl' that
|
|
|
|
update the volume and backlight statuses, send a requst to update
|
|
|
|
both of those statuses immediately.
|
2020-12-27 18:31:56 +00:00
|
|
|
|
2020-12-30 06:05:06 +00:00
|
|
|
avds 'vol,bl'
|
2020-12-27 18:31:56 +00:00
|
|
|
|
2021-01-03 06:10:16 +00:00
|
|
|
Send the previous requests to all running daemons.
|
|
|
|
|
|
|
|
avds '>>* vol,bl'
|
|
|
|
|
2021-01-01 18:17:08 +00:00
|
|
|
If there are cpu and memory usage modules named 'cpu' and 'mem'
|
|
|
|
that update the cpu and memory usage statuses, send a requst to
|
|
|
|
update both of those statuses every 5 seconds.
|
2020-12-27 18:31:56 +00:00
|
|
|
|
2020-12-30 06:05:06 +00:00
|
|
|
avds 'cpu,mem' 5000 1
|
2020-12-27 18:31:56 +00:00
|
|
|
|
2021-01-01 18:17:08 +00:00
|
|
|
If there are battery and date/time modules named 'bat' and 'dt'
|
|
|
|
that update the battery and date/time statuses, send a requst to
|
|
|
|
update both of those statuses at the top of every minute.
|
2020-12-27 18:31:56 +00:00
|
|
|
|
2020-12-30 06:05:06 +00:00
|
|
|
avds 'bat,dt' m true
|
2020-12-27 18:31:56 +00:00
|
|
|
"
|
2020-12-30 06:05:06 +00:00
|
|
|
DAEMON=avdd
|
2020-12-27 18:31:56 +00:00
|
|
|
|
|
|
|
# Convert integer milliseconds to floating point seconds
|
2021-01-18 19:11:11 +00:00
|
|
|
ms_to_s() {
|
2020-12-27 18:31:56 +00:00
|
|
|
printf '%.3f' "${1}e-3"
|
|
|
|
}
|
|
|
|
|
2021-01-02 05:19:55 +00:00
|
|
|
# Validate the number arguments
|
2020-12-27 18:31:56 +00:00
|
|
|
if [[ "$#" -lt 1 || "$#" -gt 3 ]]; then
|
|
|
|
printf '%s' "${USAGE}" 1>&2
|
|
|
|
exit 128
|
|
|
|
fi
|
|
|
|
|
2021-01-02 05:19:55 +00:00
|
|
|
mod_list="$1"
|
2021-01-02 04:47:30 +00:00
|
|
|
|
|
|
|
# Check if the user needs help
|
2021-01-02 05:19:55 +00:00
|
|
|
if [[ "${mod_list}" =~ ^(-h|-(-)?help)$ ]]; then
|
2021-01-02 04:47:30 +00:00
|
|
|
printf '%s' "${USAGE}" 1>&2
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2021-01-03 06:10:16 +00:00
|
|
|
# Check if we will be sending requests to all daemons, or set the named pipe
|
|
|
|
# for this login session
|
|
|
|
if [[ "${mod_list}" =~ ^\>\>\*\ ]]; then
|
|
|
|
mod_list="${mod_list:4}"
|
|
|
|
is_request_all=1
|
|
|
|
else
|
2021-10-26 02:43:46 +00:00
|
|
|
fifo="/tmp/${DAEMON}-fifo-$("$(dirname "$0")/rpid" $$)"
|
2021-01-03 06:10:16 +00:00
|
|
|
fi
|
|
|
|
|
2020-12-27 18:31:56 +00:00
|
|
|
when="${2:-0}"
|
|
|
|
|
2021-01-02 05:19:55 +00:00
|
|
|
# Validate when
|
2020-12-27 18:31:56 +00:00
|
|
|
if [[ ! "${when}" =~ ^[0-9]+|[mhd]$ ]]; then
|
|
|
|
printf 'Invalid argument <when>: %s\n' "${when}" 1>&2
|
|
|
|
exit 128
|
|
|
|
fi
|
|
|
|
|
2021-01-02 05:19:55 +00:00
|
|
|
repeat="$3"
|
|
|
|
|
2021-01-01 18:17:08 +00:00
|
|
|
# Write to the pipe if this is the first run or if repeat is on
|
2020-12-27 18:31:56 +00:00
|
|
|
first_run=1
|
|
|
|
while [[ "${first_run}" -eq 1 || -n "${repeat}" ]]; do
|
|
|
|
first_run=0
|
|
|
|
|
2021-01-01 18:17:08 +00:00
|
|
|
# Sleep until it's time to write to the pipe
|
2020-12-27 18:31:56 +00:00
|
|
|
if [[ "${when}" != '0' ]]; then
|
|
|
|
if [[ "${when}" =~ ^[0-9]+$ ]]; then
|
|
|
|
sleep "$(ms_to_s "${when}")"
|
|
|
|
else
|
|
|
|
case "${when}" in
|
|
|
|
m)
|
2021-02-16 19:10:37 +00:00
|
|
|
sleep $((60 - 10#$(date +%S)))
|
2020-12-27 18:31:56 +00:00
|
|
|
;;
|
|
|
|
h)
|
|
|
|
readarray -t ms < <(date +'%M%n%S')
|
|
|
|
sleep $((3600 - ms[0] * 60 - ms[1]))
|
|
|
|
;;
|
|
|
|
d)
|
|
|
|
readarray -t hms < <(date +'%H%n%M%n%S')
|
2020-12-31 21:51:27 +00:00
|
|
|
sleep $(((24 - hms[0]) * 3600 - hms[1] * 60 - hms[2]))
|
2020-12-27 18:31:56 +00:00
|
|
|
;;
|
2020-12-30 02:59:23 +00:00
|
|
|
*)
|
|
|
|
;;
|
2020-12-27 18:31:56 +00:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-01-03 06:10:16 +00:00
|
|
|
# Write each command to the named pipe for this login session
|
|
|
|
if [[ ! -v is_request_all ]]; then
|
|
|
|
if [[ ! -p "${fifo}" ]]; then
|
|
|
|
printf 'The daemon %s is not running\n' "${DAEMON}" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
printf '%s\n' "${mod_list}" >> "${fifo}"
|
|
|
|
# Write each command to all the daemon named pipes
|
|
|
|
else
|
|
|
|
readarray -d '' fifos \
|
|
|
|
< <(find /tmp -maxdepth 1 -type p -name "${DAEMON}-fifo-*" -print0)
|
|
|
|
if [[ "${#fifos[@]}" -eq 0 ]]; then
|
|
|
|
printf 'There are no daemons running\n' 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
for fifo in "${fifos[@]}"; do
|
|
|
|
printf '%s\n' "${mod_list}" >> "${fifo}"
|
|
|
|
done
|
2020-12-27 18:31:56 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|