#!/bin/bash #### Configparser library #### webcamd - A webcam Service for multiple Cams and Stream Services. #### #### Written by Stephan Wendel aka KwadFan #### Copyright 2021 #### https://github.com/mainsail-crew/crowsnest #### #### This File is distributed under GPLv3 #### # shellcheck enable=require-variable-braces # Exit upon Errors set -Ee # Read Configuration File # call get_param section param # spits out raw value function get_param { local cfg section param cfg="${WEBCAMD_CFG}" section="${1}" param="${2}" crudini --get "${cfg}" "${section}" "${param}" 2> /dev/null | \ sed 's/\#.*//;s/[[:space:]]*$//' } # Check for existing file # Exit with error if not exist function check_cfg { if [ ! -r "${1}" ]; then log_msg "ERROR: No Configuration File found. Exiting!" exit 1 fi } ## Spits out all [cam ] configured sections function configured_cams { local cams cfg cfg="${WEBCAMD_CFG}" for i in $(crudini --existing=file --get "${cfg}" | \ sed '/webcamd/d;s/cam//'); do cams+=("${i}") done echo "${cams[@]}" } # Checks [cam ] if all needed configuration sections are present # call check_section ex.: check_section foobar function check_section { local section exist param must_exist missing section="cam ${1}" # Ignore missing custom flags exist="$(crudini --existing=param --get "${WEBCAMD_CFG}" "${section}" \ 2> /dev/null | sed '/custom_flags/d;/v4l2ctl/d')" for i in ${exist}; do param+=("${i}") done # Stop on deprecated conf for i in "${param[@]}"; do if [ "${i}" = "streamer" ]; then deprecated_msg_1 exit 1 fi done must_exist=(mode port device resolution max_fps) missing="$(echo "${param[@]}" "${must_exist[@]}" | \ tr ' ' '\n' | sort | uniq -u)" for i in "${missing[@]}"; do if [ -n "${i}" ]; then log_msg "ERROR: Parameter ${missing} not found in \ Section [${section}]. Start skipped!" else log_msg "INFO: Configuration of Section [${section}] looks good. \ Continue..." fi done }