fix: store log_level in var instead in function

Instead of checking multiple times the log level store in Variable.

Signed-off-by: Stephan Wendel <me@stephanwe.de>
This commit is contained in:
Stephan Wendel 2023-02-16 17:21:39 +01:00
parent 541855054f
commit 9a66358443
No known key found for this signature in database
GPG Key ID: F465B83ACBA45639
5 changed files with 37 additions and 36 deletions

View File

@ -115,9 +115,9 @@ function initial_check {
check_dep "ffmpeg"
check_apps
versioncontrol
# print cfg if ! log_level: quiet
# print cfg if ! "${CROWSNEST_LOG_LEVEL}": quiet
if [ -z "$(check_cfg "${CROWSNEST_CFG}")" ]; then
if [ "$(log_level)" != "quiet" ]; then
if [[ "${CROWSNEST_LOG_LEVEL}" != "quiet" ]]; then
print_cfg
fi
fi

View File

@ -21,13 +21,13 @@ function detect_avail_cams {
local avail realpath
avail="$(find /dev/v4l/by-id/ -iname "*index0" 2> /dev/null)"
count="$(echo "${avail}" | wc -l)"
if [ -d "/dev/v4l/by-id/" ] &&
[ -n "${avail}" ]; then
if [[ -d "/dev/v4l/by-id/" ]] &&
[[ -n "${avail}" ]]; then
log_msg "INFO: Found ${count} available camera(s)"
echo "${avail}" | while read -r v4l; do
realpath=$(readlink -e "${v4l}")
log_msg "${v4l} -> ${realpath}"
if [ "$(log_level)" != "quiet" ]; then
if [[ "${CROWSNEST_LOG_LEVEL}" != "quiet" ]]; then
list_cam_formats "${v4l}"
list_cam_v4l2ctrls "${v4l}"
fi
@ -41,8 +41,8 @@ function detect_avail_csi {
local avail count realpath
avail="$(find /dev/v4l/by-path/ -iname "*csi*index0" 2> /dev/null)"
count="$(echo "${avail}" | wc -l)"
if [ -d "/dev/v4l/by-path/" ] &&
[ -n "${avail}" ]; then
if [[ -d "/dev/v4l/by-path/" ]] &&
[[ -n "${avail}" ]]; then
log_msg "INFO: Found ${count} available csi device(s)"
echo "${avail}" | while read -r csi; do
realpath=$(readlink -e "${csi}")
@ -77,7 +77,7 @@ function list_cam_v4l2ctrls {
# Determine connected "raspicam" device
function detect_raspicam {
local avail
if [ -f /proc/device-tree/model ] &&
if [[ -f /proc/device-tree/model ]] &&
grep -q "Raspberry" /proc/device-tree/model; then
avail="$(vcgencmd get_camera | awk -F '=' '{ print $3 }' | cut -d',' -f1)"
else

View File

@ -29,6 +29,7 @@ function set_log_path {
function init_logging {
set_log_path
set_log_level
delete_log
log_msg "crowsnest - A webcam Service for multiple Cams and Stream Services."
log_msg "Version: $(self_version)"
@ -36,16 +37,16 @@ function init_logging {
print_host
}
function log_level {
function set_log_level {
local loglevel
loglevel="$(get_param crowsnest log_level 2> /dev/null)"
# Set default log_level to quiet
if [ -z "${loglevel}" ] || [[ "${loglevel}" != @(quiet|verbose|debug) ]];
then
echo "quiet"
if [ -z "${loglevel}" ] || [[ "${loglevel}" != @(quiet|verbose|debug) ]]; then
CROWSNEST_LOG_LEVEL="quiet"
else
echo "${loglevel}"
CROWSNEST_LOG_LEVEL="${loglevel}"
fi
declare -r CROWSNEST_LOG_LEVEL
}
function delete_log {
@ -69,10 +70,10 @@ function log_output {
local prefix
prefix="DEBUG: ${1}"
while read -r line; do
if [ "$(log_level)" == "debug" ]; then
if [[ "${CROWSNEST_LOG_LEVEL}" = "debug" ]]; then
log_msg "${prefix}: ${line}"
fi
if [ -n "${line}" ]; then
if [[ -n "${line}" ]]; then
# needed to prettify ustreamers output
echo "${line//^--/ustreamer}" | logger -t crowsnest
fi
@ -94,25 +95,25 @@ function print_cams {
v4l="$(find /dev/v4l/by-id/ -iname "*index0" 2> /dev/null | wc -l)"
csi="$(find /dev/v4l/by-path/ -iname "*csi*index0" 2> /dev/null | wc -l)"
total="$((v4l+$(detect_raspicam)+csi))"
if [ "${total}" -eq 0 ]; then
if [[ "${total}" -eq 0 ]]; then
log_msg "ERROR: No usable Devices Found. Stopping $(basename "${0}")."
exit 1
else
log_msg "INFO: Found ${total} total available Device(s)"
fi
if [ "$(detect_raspicam)" -ne 0 ]; then
if [[ "$(detect_raspicam)" -ne 0 ]]; then
raspicam="$(v4l2-ctl --list-devices | grep -A1 -e 'mmal' | \
awk 'NR==2 {print $1}')"
log_msg "Detected 'Raspicam' Device -> ${raspicam}"
if [ ! "$(log_level)" = "quiet" ]; then
if [[ ! "${CROWSNEST_LOG_LEVEL}" = "quiet" ]]; then
list_cam_formats "${raspicam}"
list_cam_v4l2ctrls "${raspicam}"
fi
fi
if [ -d "/dev/v4l/by-id/" ]; then
if [[ -d "/dev/v4l/by-id/" ]]; then
detect_avail_cams
fi
if [ -d "/dev/v4l/by-path" ]; then
if [[ -d "/dev/v4l/by-path" ]]; then
detect_avail_csi
fi
}
@ -123,28 +124,28 @@ function print_host {
sbc_model="$(grep "Model" /proc/cpuinfo | cut -d':' -f2)"
memtotal="$(grep "MemTotal:" /proc/meminfo | awk '{print $2" "$3}')"
disksize="$(LC_ALL=C df -h / | awk 'NR==2 {print $4" / "$2}')"
## print only if not log_level: quiet
if [ "$(log_level)" != "quiet" ]; then
## print only if not "${CROWSNEST_LOG_LEVEL}": quiet
if [[ "${CROWSNEST_LOG_LEVEL}" != "quiet" ]]; then
log_msg "INFO: Host information:"
## OS Infos
## OS Version
if [ -f /etc/os-release ]; then
if [[ -f /etc/os-release ]]; then
log_msg "Host Info: Distribution: $(grep "PRETTY" /etc/os-release | \
cut -d '=' -f2 | sed 's/^"//;s/"$//')"
fi
## Release Version of MainsailOS (if file present)
if [ -f /etc/mainsailos-release ]; then
if [[ -f /etc/mainsailos-release ]]; then
log_msg "Host Info: Release: $(cat /etc/mainsailos-release)"
fi
## Kernel version
log_msg "Host Info: Kernel: $(uname -s) $(uname -rm)"
## Host Machine Infos
## Host model
if [ -n "${sbc_model}" ]; then
if [[ -n "${sbc_model}" ]]; then
log_msg "Host Info: Model: ${sbc_model}"
fi
if [ -n "${generic_model}" ] &&
[ -z "${sbc_model}" ]; then
if [[ -n "${generic_model}" ]] &&
[[ -z "${sbc_model}" ]]; then
log_msg "Host Info: Model: ${generic_model}"
fi
## CPU count

View File

@ -29,7 +29,7 @@ function v4l2_control {
# get v4l2ctl parameters
v4l2ctl="$(get_param "cam ${cam}" v4l2ctl)"
# if not empty do
if [ -n "${v4l2ctl}" ]; then
if [[ -n "${v4l2ctl}" ]]; then
# Write configured options to Log
log_msg "Device: [cam ${cam}]"
log_msg "Options: ${v4l2ctl}"
@ -48,7 +48,7 @@ function v4l2_control {
v4l2-ctl -d "${device}" -c "${param}" 2> /dev/null
fi
done
if [ "$(log_level)" == "debug" ]; then
if [[ "${CROWSNEST_LOG_LEVEL}" == "debug" ]]; then
v4l2-ctl -d "${device}" -L | log_output "v4l2ctl"
fi
else
@ -123,7 +123,7 @@ function brokenfocus {
detected_broken_dev_msg
set_focus_absolute "${device}" "${conf_val}"
fi
if [ "$(log_level)" == "debug" ] && [ -n "${cur_val}" ]; then
if [[ "${CROWSNEST_LOG_LEVEL}" == "debug" ]] && [[ -n "${cur_val}" ]]; then
debug_focus_val_msg "$(get_current_value "${device}")"
fi
done

View File

@ -29,10 +29,10 @@ function versioncontrol {
pushd "${BASE_CN_PATH}"/bin/ustreamer || exit 1
avail_ver="$(git describe --tags --always)"
cur_ver="v$("${PWD}"/ustreamer -v)"
if [ "${cur_ver}" == "${avail_ver}" ]; then
if [[ "${cur_ver}" == "${avail_ver}" ]]; then
vc_log_msg "ustreamer is up to date. (${cur_ver})"
fi
if [ "${cur_ver}" != "${avail_ver}" ]; then
if [[ "${cur_ver}" != "${avail_ver}" ]]; then
vc_log_msg "ustreamer new version available: ${avail_ver} (${cur_ver})."
fi
popd || exit 1
@ -43,7 +43,7 @@ function versioncontrol {
pushd "${BASE_CN_PATH}"/bin/rtsp-simple-server || exit 1
avail_ver="$(cat version)"
cur_ver="$("${PWD}"/rtsp-simple-server --version)"
if [ "${cur_ver}" == "${avail_ver}" ]; then
if [[ "${cur_ver}" == "${avail_ver}" ]]; then
vc_log_msg "rtsp-simple-server is up to date. (${cur_ver})"
fi
if [ "${cur_ver}" != "${avail_ver}" ]; then
@ -56,17 +56,17 @@ function versioncontrol {
local cur_ver avail_ver
avail_ver="$(dpkg-query -W ffmpeg | awk -F':' '{print $2}')"
cur_ver="$(ffmpeg -version | awk 'NR==1 {print $3}')"
if [ "${cur_ver}" == "${avail_ver}" ]; then
if [[ "${cur_ver}" == "${avail_ver}" ]]; then
vc_log_msg "ffmpeg is up to date. (${cur_ver})"
fi
if [ "${cur_ver}" != "${avail_ver}" ]; then
if [[ "${cur_ver}" != "${avail_ver}" ]]; then
vc_log_msg "ffmpeg new version available: ${avail_ver} (${cur_ver})."
fi
}
### MAIN
function main {
if [ "$(log_level)" != "quiet" ]; then
if [[ "${CROWSNEST_LOG_LEVEL}" != "quiet" ]]; then
get_ustreamer_version
get_rtsp_version
get_ffmpeg_version