FunKey-OS/FunKey/board/funkey/rootfs-overlay/usr/local/sbin/pid

48 lines
626 B
Bash
Executable File

#!/bin/sh
# Uncomment the following line to get debug info
#set -x
SELF="$(basename ${0})"
PID_FILE="/var/run/funkey.pid"
usage() {
>&2 echo "Usage: ${SELF} record pid"
>&2 echo " ${SELF} erase"
exit 1
}
record_pid() {
local pid="${1}"
if ! [ ! "${pid}" -ne "${pid}" ]; then
>&2 echo "error: ${pid} is not a number"
exit 2
fi
echo "${1}" > "${PID_FILE}"
}
erase_pid() {
rm -f "${PID_FILE}"
}
case "${1}" in
record)
if [ ${#} -ne 2 ]; then
usage
fi
record_pid "${2}"
;;
erase)
if [ ${#} -ne 1 ]; then
usage
fi
erase_pid
;;
*)
usage
;;
esac
exit 0