diff --git a/read_config b/read_config index ab8198f..2f06c29 100755 --- a/read_config +++ b/read_config @@ -1,4 +1,4 @@ -#!/bin/bash +#! /bin/bash - # set -x source ./log_helpers @@ -7,7 +7,8 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once readonly read_config_sourced=${BASH_SOURCE[0]} readonly DATEFLAGS="+%Y.%m.%dT%H.%M.%S" - readonly STRIPCOMMENTS='sed -e s/#.*$//' + readonly STRIPCOMMENTS='sed -e s/#.*$//g' + readonly STRIPWHITESPACE='sed -E -e s/^[[:space:]]*$//g' readonly INDENT="awk '{ print \"\t\t\t\" \$0 }'" readonly JOINLINES="tr '\n' '\040'" @@ -21,22 +22,21 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once readonly WORKSPACE_DIR=workspace - ${WORKING_DIRECTORY:=$UPDATEPSAHOME} - ${CONFIGFILENAME:=update_psa.conf} + WORKING_DIRECTORY=${WORKING_DIRECTORY:-$UPDATEPSAHOME} + CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'} if ! [ -f "$CONFIGFILENAME" ]; then log_fatal "$func:${LINENO}: $CONFIGFILENAME not found" fi - if [ -z "$WORKING_DIRECTORY" ]; then - log_fatal "$func:${LINENO}: WORKING_DIRECTORY not set in $cf" + if ! [ -d "$WORKING_DIRECTORY" ]; then + log_fatal "$func:${LINENO}: $WORKING_DIRECTORY not found" fi EXITCODE=0 CLONE_CUSTOMER_REPOSITORY=false # read config file (JSON syntax) - # read_config() { local func="${FUNCNAME[0]}" @@ -78,15 +78,24 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once readonly CUSTOMER_REPOSITORY_PATH="${__r_path}/${CUSTOMER_ID}.git" log_debug "$func:${LINENO}: customer-r-path=$CUSTOMER_REPOSITORY_PATH" - readonly number_of_zone_groups="$(cat "$cf" | jq -r .zone_group[0])" - log_debug "$func:${LINENO}: $number_of_zone_groups zone_group(s)" + local __number_of_zone_groups=$(cat "$cf" | + jq -r .zg[0] | + sed -E -e 's/[[:space:]]*//g') + # TODO: was ist hier falsch + # __n_of_zgroups=$(echo "$__n_of_zgrps" | ${STRIPWHITESPACE} ) + log_debug "$func:${LINENO}: #n of zone_groups: $__number_of_zone_groups" - local __zone_groups=(0) - for zg in `seq 1 $number_of_zone_groups`; do - local __n_zones="$(cat "$cf" | jq -r .zone_group[$zg].zone[0])" + local __zone_groups=($__number_of_zone_groups) + for zg in `seq 1 $__number_of_zone_groups`; do + local __n_zones=$(cat "$cf" | + jq -r .zg[$zg].z | + sed -E -e 's/[][,[:space:]]*//g') # rm ][ as well __zone_groups[$zg]=$__n_zones done + readonly ZONE_GROUPS=(${__zone_groups[@]}) + log_debug "$func:${LINENO}: ZONE_GROUPS=${ZONE_GROUPS[@]}" + log_debug "$func:${LINENO}: reading ${wd} done" return 0 @@ -97,16 +106,14 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once check_sanity_of_repository () { local func="${FUNCNAME[0]}" - local __customer_base_dir="$WORKING_DIRECTORY/${WORKSPACE_DIR}" - __customer_base_dir="${__customer_base_dir}/${CUSTOMER_ID}" + local __customer_id_base_dir="$WORKING_DIRECTORY/${WORKSPACE_DIR}" + readonly CUSTOMER_ID_BASE_DIR="${__customer_id_base_dir}/${CUSTOMER_ID}" - readonly CUSTOMER_ID_BASE_DIR=${__customer_base_dir} log_debug "$func:${LINENO}: CUSTOMER_ID_BASE_DIR=" log_debug "$func:${LINENO}: $CUSTOMER_ID_BASE_DIR" - __customer_base_dir="${__customer_base_dir}/${CUSTOMER_LOCATION}" + CUSTOMER_LOCATION_DIR="${CUSTOMER_ID_BASE_DIR}/${CUSTOMER_LOCATION}" - readonly CUSTOMER_LOCATION_DIR="$__customer_base_dir" log_debug "$func:${LINENO}: CUSTOMER_LOCATION_DIR=" log_debug "$func:${LINENO}: $CUSTOMER_LOCATION_DIR" @@ -114,26 +121,40 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once log_debug "$func:${LINENO}: UPDATE.CONF=" log_debug "$func:${LINENO}: $UPDATE_CONF" - readonly current_conf="${CUSTOMER_LOCATION_DIR}/current.conf" - log_debug "$func:${LINENO}: current.conf=" - log_debug "$func:${LINENO}: $current_conf" - # readonly zone_groups=(${__zone_groups[@]}) - # for (( j=0; j<${#zone_groups[@]}; ++j)); do - # log_debug "$func:${LINENO}: zgroup[$j]: ${zone_groups[$j]} zones" - # done + # by now (03.03.2023) there is only one zone group. + readonly local __zgroup=1 + local __number_of_zone_groups=${ZONE_GROUPS[0]} + local __zindex=1 + local __customer_base_dirs=("placeholder") + for __zg in `seq 1 $__number_of_zone_groups`; do + local __n_of_zones=${ZONE_GROUPS[$__zindex]} + log_debug "$func:${LINENO}: zgroup $__zg has $__n_of_zones zones" + for (( j=1; j<=$__n_of_zones; ++j)); do + __customer_base_dirs+=("${CUSTOMER_LOCATION_DIR}/$__zgroup/$j") + log_debug "$func:${LINENO}: zone $j" + ((++__zindex)) + done + done - # TODO: falls mehrere gruppen/zonen auftauchen hier anpassen - readonly zgroup=1 - readonly zone=1 - readonly CUSTOMER_BASE_DIR="${__customer_base_dir}/${zgroup}/${zone}" + readonly CUSTOMER_BASE_DIRS=(${__customer_base_dirs[@]}) + + if [ ${#CUSTOMER_BASE_DIRS[@]} -eq 0 ]; then + log_fatal "$func:${LINENO}: CUSTOMER_BASE_DIRS empty" + fi + + # TODO + # TODO: falls mehrere gruppen/zonen auftauchen hier anpassen + # TODO + readonly local __zone=1 + readonly CUSTOMER_BASE_DIR="${CUSTOMER_BASE_DIRS[$__zone]}" if [ -d "$CUSTOMER_BASE_DIR" ]; then - log_debug "$func:${LINENO}: customer-base-dir=" + log_debug "$func:${LINENO}: CUSTOMER-BASE-DIR=" log_debug "$func:${LINENO}: $CUSTOMER_BASE_DIR" else log_fatal "$func:${LINENO}: $CUSTOMER_BASE_DIR does not exist" fi - + readonly psa_config_dir="${CUSTOMER_BASE_DIR}/etc/psa_config" if [ -d "$psa_config_dir" ]; then log_debug "$func:${LINENO}: psa_config_dir=" @@ -239,30 +260,44 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once log_fatal "$func:${LINENO}: $SYSCONFIG_SYSCTRL_INI_FULL does not exist" fi - readonly emp_conf="${psa_config_dir}/emp.conf" - if [ -f "$emp_conf" ]; then - log_debug "$func:${LINENO}: emp.conf=" - log_debug "$func:${LINENO}: $emp_conf" + readonly DC2C_SERIAL_JSON="${psa_config_dir}/DC2C_serial.json" + if [ -f "$DC2C_SERIAL_JSON" ]; then + log_debug "$func:${LINENO}: DC2C_SERIAL_JSON=" + log_debug "$func:${LINENO}: $DC2C_SERIAL_JSON" else - log_fatal "$func:${LINENO}: $emp_conf does not exist" + log_fatal "$func:${LINENO}: $DC2C_SERIAL_JSON does not exist" fi - readonly device_conf="${psa_config_dir}/device.conf" - if [ -f "$device_conf" ]; then - log_debug "$func:${LINENO}: device.conf=" - log_debug "$func:${LINENO}: $device_conf" + readonly DC2C_CASH_JSON="${psa_config_dir}/DC2C_cash.json" + if [ -f "$DC2C_CASH_JSON" ]; then + log_debug "$func:${LINENO}: DC2C_CASH_JSON=" + log_debug "$func:${LINENO}: $DC2C_CASH_JSON" else - log_debug "$func:${LINENO}: $device_conf does not exist" + log_debug "$func:${LINENO}: $DC2C_CASH_JSON does not exist" fi - readonly printer_conf="${psa_config_dir}/printer.conf" - if [ -f "$printer_conf" ]; then - log_debug "$func:${LINENO}: printer.conf=" - log_debug "$func:${LINENO}: $printer_conf" + readonly DC2C_CONF_JSON="${psa_config_dir}/DC2C_conf.json" + if [ -f "$DC2C_CONF_JSON" ]; then + log_debug "$func:${LINENO}: DC2C_CONF_JSON=" + log_debug "$func:${LINENO}: $DC2C_CONF_JSON" else - log_fatal "$func:${LINENO}: $printer_conf does not exist" + log_fatal "$func:${LINENO}: $DC2C_CONF_JSON does not exist" fi + local DC2C_PRINT_JSON=() + for i in {1..32}; do # up to 32 print-json-files + local __f=${psa_config_dir}/DC2C_print$(printf "%02d" $i).json + readonly DC2C_PRINT$(printf "%02d" $i)_JSON=$__f + # local __g=$(eval echo '$'DC2C_PRINT$(printf "%02d" $i)_JSON) + if [ -f $__f ]; then + log_debug "$func:${LINENO}: DC2C_PRINT$(printf "%02d" $i)_JSON=" + log_debug "$func:${LINENO}: $__f" + else + log_fatal "$func:${LINENO}: $__f does not exist" + fi + DC2C_PRINT_JSON+=($__f) + done + readonly opkg_cmds_file="${psa_update_dir}/opkg_commands" if [ -f "$opkg_cmds_file" ]; then log_debug "$func:${LINENO}: opkg_commands=" @@ -271,16 +306,17 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once log_fatal "$func:${LINENO}: $opkg_cmds_file does not exist" fi - readonly KNOWN_CONF_FILES=(${CUSTOMER_LOCATION}/update.conf \ - ${CUSTOMER_LOCATION}/current.conf \ - ${device_conf##*${CUSTOMER_ID}/} \ - ${emp_conf##*${CUSTOMER_ID}/} \ - ${printer_conf##*${CUSTOMER_ID}/}) + # TODO: anpassen, da z.B. fuer szeged mehrere zonen vorhanden sind + readonly KNOWN_CONF_FILES=(${CUSTOMER_LOCATION}/update.conf \ + ${DC2C_PRINT_JSON[@]##*${CUSTOMER_ID}/} \ + ${DC2C_CONF_JSON##*${CUSTOMER_ID}/} \ + ${DC2C_CASH_JSON##*${CUSTOMER_ID}/} \ + ${DC2C_SERIAL_JSON##*${CUSTOMER_ID}/}) - readonly KNOWN_INI_FILES=(${ATBQT_INI_FULL##*${CUSTOMER_ID}/} \ - ${ISMASMGR_ISMASMGR_INI_FULL##*${CUSTOMER_ID}/} \ - ${SYSCONFIG_ISMASMGR_INI_FULL##*${CUSTOMER_ID}/} \ - ${SYSCONFIG_SYSCONFIG_INI_FULL##*${CUSTOMER_ID}/} \ + readonly KNOWN_INI_FILES=(${ATBQT_INI_FULL##*${CUSTOMER_ID}/} \ + ${ISMASMGR_ISMASMGR_INI_FULL##*${CUSTOMER_ID}/} \ + ${SYSCONFIG_ISMASMGR_INI_FULL##*${CUSTOMER_ID}/} \ + ${SYSCONFIG_SYSCONFIG_INI_FULL##*${CUSTOMER_ID}/} \ ${SYSCONFIG_SYSCTRL_INI_FULL##*${CUSTOMER_ID}/}) readonly KNOWN_FILES=(${KNOWN_CONF_FILES[@]} \ @@ -289,7 +325,8 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once log_debug "$func:${LINENO}: known conf/ini_files ->" for (( i=0; i < ${#KNOWN_FILES[@]}; ++i )); do - log_debug "$func:${LINENO}: \t\t ${KNOWN_FILES[$i]}" + tab=$'\t' + log_debug "$func:${LINENO}: $tab$tab ${KNOWN_FILES[$i]}" done log_debug "$func:${LINENO}: sanity of ${CUSTOMER_REPOSITORY_PATH} OK" @@ -297,3 +334,4 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once } fi +