Skip to content

Commit

Permalink
chore: add delay at boot for SpeederPads
Browse files Browse the repository at this point in the history
  • Loading branch information
mryel00 committed Nov 11, 2023
1 parent 361dfaa commit f4e0367
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
11 changes: 10 additions & 1 deletion crowsnest
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if [ "$#" -eq 0 ]; then
fi

## Parse Args
while getopts ":vhc:d" arg; do
while getopts ":vhcs:d" arg; do
case "${arg}" in
v )
echo -e "\ncrowsnest Version: $(self_version)\n"
Expand All @@ -55,6 +55,15 @@ while getopts ":vhc:d" arg; do
check_cfg "${OPTARG}"
export CROWSNEST_CFG="${OPTARG}"
;;
s )
if [[ "$(awk '{print $1}' /proc/uptime | cut -d '.' -f 1)" -lt "120" ]]; then
if [[ "${OPTARG}" ]]; then
sleep "${OPTARG}"
else
sleep 5
fi
fi
;;
d )
set -x
;;
Expand Down
3 changes: 2 additions & 1 deletion libs/messages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function help_msg {
echo -e "\t crowsnest [Options]"
echo -e "\n\t\t-h Prints this help."
echo -e "\n\t\t-v Prints Version of crowsnest."
echo -e "\n\t\t-c </path/to/configfile>\n\t\t\tPath to your webcam.conf\n"
echo -e "\n\t\t-c </path/to/configfile>\n\t\t\tPath to your webcam.conf"
echo -e "\n\t\t-s <sleep_seconds>\n\t\t\tDelay start \(in seconds\) after boot\n"
}

function deprecated_msg_1 {
Expand Down
12 changes: 6 additions & 6 deletions tools/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@ main() {
status_msg "Install service file ..." "1"
fi

if [[ "$(is_speederpad)" = "1" ]]; then
msg "\nSpeederpad detected!"
msg "Add startup delay to service file ...\n"
add_sleep_to_service_file
fi

if install_env_file; then
status_msg "Install environment file ..." "0"
else
status_msg "Install environment file ..." "1"
fi

if [[ "$(is_speederpad)" = "1" ]]; then
msg "\nSpeederpad detected!"
msg "Add startup delay to environment file ...\n"
add_sleep_to_crowsnest_env
fi

if install_logrotate_conf; then
status_msg "Install logrotate configuration ..." "0"
else
Expand Down
12 changes: 6 additions & 6 deletions tools/libs/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ is_ubuntu_arm() {
}

is_speederpad() {
if [[ "$(uname -rm)" = "4.9.191 aarch64" ]] &&
grep -q "Ubuntu 20.04." /etc/os-release; then
if grep -q "Ubuntu 20.04." /etc/os-release &&
[[ "$(uname -rm)" = "4.9.191 aarch64" ]]; then
echo "1"
else
echo "0"
Expand Down Expand Up @@ -198,12 +198,12 @@ install_service_file() {
grep -q "${BASE_USER}" "${target_dir}/crowsnest.service" || return 1
}

add_sleep_to_service_file() {
add_sleep_to_crowsnest_env() {
local service_file
service_file="/etc/systemd/system/crowsnest.service"
env_file="${CROWSNEST_ENV_PATH}/crowsnest.env"

if [[ -f "${service_file}" ]]; then
echo "ExecStartPre=/bin/sleep 5" >> "${service_file}"
if [[ -f "${env_file}" ]]; then
sed -i 's/\(CROWSNEST_ARGS="[^"]*\)"/\1 -s"/' "${env_file}"
fi
}

Expand Down

0 comments on commit f4e0367

Please sign in to comment.