Prepared for using several zones.
This commit is contained in:
parent
98a2e09bd5
commit
d6131e04e9
148
read_config
148
read_config
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#! /bin/bash -
|
||||||
# set -x
|
# set -x
|
||||||
|
|
||||||
source ./log_helpers
|
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 read_config_sourced=${BASH_SOURCE[0]}
|
||||||
|
|
||||||
readonly DATEFLAGS="+%Y.%m.%dT%H.%M.%S"
|
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 INDENT="awk '{ print \"\t\t\t\" \$0 }'"
|
||||||
readonly JOINLINES="tr '\n' '\040'"
|
readonly JOINLINES="tr '\n' '\040'"
|
||||||
|
|
||||||
@ -21,22 +22,21 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
|||||||
|
|
||||||
readonly WORKSPACE_DIR=workspace
|
readonly WORKSPACE_DIR=workspace
|
||||||
|
|
||||||
${WORKING_DIRECTORY:=$UPDATEPSAHOME}
|
WORKING_DIRECTORY=${WORKING_DIRECTORY:-$UPDATEPSAHOME}
|
||||||
${CONFIGFILENAME:=update_psa.conf}
|
CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'}
|
||||||
|
|
||||||
if ! [ -f "$CONFIGFILENAME" ]; then
|
if ! [ -f "$CONFIGFILENAME" ]; then
|
||||||
log_fatal "$func:${LINENO}: $CONFIGFILENAME not found"
|
log_fatal "$func:${LINENO}: $CONFIGFILENAME not found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$WORKING_DIRECTORY" ]; then
|
if ! [ -d "$WORKING_DIRECTORY" ]; then
|
||||||
log_fatal "$func:${LINENO}: WORKING_DIRECTORY not set in $cf"
|
log_fatal "$func:${LINENO}: $WORKING_DIRECTORY not found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
EXITCODE=0
|
EXITCODE=0
|
||||||
CLONE_CUSTOMER_REPOSITORY=false
|
CLONE_CUSTOMER_REPOSITORY=false
|
||||||
|
|
||||||
# read config file (JSON syntax)
|
# read config file (JSON syntax)
|
||||||
#
|
|
||||||
read_config() {
|
read_config() {
|
||||||
local func="${FUNCNAME[0]}"
|
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"
|
readonly CUSTOMER_REPOSITORY_PATH="${__r_path}/${CUSTOMER_ID}.git"
|
||||||
log_debug "$func:${LINENO}: customer-r-path=$CUSTOMER_REPOSITORY_PATH"
|
log_debug "$func:${LINENO}: customer-r-path=$CUSTOMER_REPOSITORY_PATH"
|
||||||
|
|
||||||
readonly number_of_zone_groups="$(cat "$cf" | jq -r .zone_group[0])"
|
local __number_of_zone_groups=$(cat "$cf" |
|
||||||
log_debug "$func:${LINENO}: $number_of_zone_groups zone_group(s)"
|
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)
|
local __zone_groups=($__number_of_zone_groups)
|
||||||
for zg in `seq 1 $number_of_zone_groups`; do
|
for zg in `seq 1 $__number_of_zone_groups`; do
|
||||||
local __n_zones="$(cat "$cf" | jq -r .zone_group[$zg].zone[0])"
|
local __n_zones=$(cat "$cf" |
|
||||||
|
jq -r .zg[$zg].z |
|
||||||
|
sed -E -e 's/[][,[:space:]]*//g') # rm ][ as well
|
||||||
__zone_groups[$zg]=$__n_zones
|
__zone_groups[$zg]=$__n_zones
|
||||||
done
|
done
|
||||||
|
|
||||||
|
readonly ZONE_GROUPS=(${__zone_groups[@]})
|
||||||
|
log_debug "$func:${LINENO}: ZONE_GROUPS=${ZONE_GROUPS[@]}"
|
||||||
|
|
||||||
log_debug "$func:${LINENO}: reading ${wd} done"
|
log_debug "$func:${LINENO}: reading ${wd} done"
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@ -97,16 +106,14 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
|||||||
check_sanity_of_repository () {
|
check_sanity_of_repository () {
|
||||||
local func="${FUNCNAME[0]}"
|
local func="${FUNCNAME[0]}"
|
||||||
|
|
||||||
local __customer_base_dir="$WORKING_DIRECTORY/${WORKSPACE_DIR}"
|
local __customer_id_base_dir="$WORKING_DIRECTORY/${WORKSPACE_DIR}"
|
||||||
__customer_base_dir="${__customer_base_dir}/${CUSTOMER_ID}"
|
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="
|
||||||
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="
|
||||||
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="
|
||||||
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[@]})
|
# readonly zone_groups=(${__zone_groups[@]})
|
||||||
# for (( j=0; j<${#zone_groups[@]}; ++j)); do
|
# by now (03.03.2023) there is only one zone group.
|
||||||
# log_debug "$func:${LINENO}: zgroup[$j]: ${zone_groups[$j]} zones"
|
readonly local __zgroup=1
|
||||||
# done
|
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 CUSTOMER_BASE_DIRS=(${__customer_base_dirs[@]})
|
||||||
readonly zgroup=1
|
|
||||||
readonly zone=1
|
if [ ${#CUSTOMER_BASE_DIRS[@]} -eq 0 ]; then
|
||||||
readonly CUSTOMER_BASE_DIR="${__customer_base_dir}/${zgroup}/${zone}"
|
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
|
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"
|
log_debug "$func:${LINENO}: $CUSTOMER_BASE_DIR"
|
||||||
else
|
else
|
||||||
log_fatal "$func:${LINENO}: $CUSTOMER_BASE_DIR does not exist"
|
log_fatal "$func:${LINENO}: $CUSTOMER_BASE_DIR does not exist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
readonly psa_config_dir="${CUSTOMER_BASE_DIR}/etc/psa_config"
|
readonly psa_config_dir="${CUSTOMER_BASE_DIR}/etc/psa_config"
|
||||||
if [ -d "$psa_config_dir" ]; then
|
if [ -d "$psa_config_dir" ]; then
|
||||||
log_debug "$func:${LINENO}: psa_config_dir="
|
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"
|
log_fatal "$func:${LINENO}: $SYSCONFIG_SYSCTRL_INI_FULL does not exist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
readonly emp_conf="${psa_config_dir}/emp.conf"
|
readonly DC2C_SERIAL_JSON="${psa_config_dir}/DC2C_serial.json"
|
||||||
if [ -f "$emp_conf" ]; then
|
if [ -f "$DC2C_SERIAL_JSON" ]; then
|
||||||
log_debug "$func:${LINENO}: emp.conf="
|
log_debug "$func:${LINENO}: DC2C_SERIAL_JSON="
|
||||||
log_debug "$func:${LINENO}: $emp_conf"
|
log_debug "$func:${LINENO}: $DC2C_SERIAL_JSON"
|
||||||
else
|
else
|
||||||
log_fatal "$func:${LINENO}: $emp_conf does not exist"
|
log_fatal "$func:${LINENO}: $DC2C_SERIAL_JSON does not exist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
readonly device_conf="${psa_config_dir}/device.conf"
|
readonly DC2C_CASH_JSON="${psa_config_dir}/DC2C_cash.json"
|
||||||
if [ -f "$device_conf" ]; then
|
if [ -f "$DC2C_CASH_JSON" ]; then
|
||||||
log_debug "$func:${LINENO}: device.conf="
|
log_debug "$func:${LINENO}: DC2C_CASH_JSON="
|
||||||
log_debug "$func:${LINENO}: $device_conf"
|
log_debug "$func:${LINENO}: $DC2C_CASH_JSON"
|
||||||
else
|
else
|
||||||
log_debug "$func:${LINENO}: $device_conf does not exist"
|
log_debug "$func:${LINENO}: $DC2C_CASH_JSON does not exist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
readonly printer_conf="${psa_config_dir}/printer.conf"
|
readonly DC2C_CONF_JSON="${psa_config_dir}/DC2C_conf.json"
|
||||||
if [ -f "$printer_conf" ]; then
|
if [ -f "$DC2C_CONF_JSON" ]; then
|
||||||
log_debug "$func:${LINENO}: printer.conf="
|
log_debug "$func:${LINENO}: DC2C_CONF_JSON="
|
||||||
log_debug "$func:${LINENO}: $printer_conf"
|
log_debug "$func:${LINENO}: $DC2C_CONF_JSON"
|
||||||
else
|
else
|
||||||
log_fatal "$func:${LINENO}: $printer_conf does not exist"
|
log_fatal "$func:${LINENO}: $DC2C_CONF_JSON does not exist"
|
||||||
fi
|
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"
|
readonly opkg_cmds_file="${psa_update_dir}/opkg_commands"
|
||||||
if [ -f "$opkg_cmds_file" ]; then
|
if [ -f "$opkg_cmds_file" ]; then
|
||||||
log_debug "$func:${LINENO}: opkg_commands="
|
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"
|
log_fatal "$func:${LINENO}: $opkg_cmds_file does not exist"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
readonly KNOWN_CONF_FILES=(${CUSTOMER_LOCATION}/update.conf \
|
# TODO: anpassen, da z.B. fuer szeged mehrere zonen vorhanden sind
|
||||||
${CUSTOMER_LOCATION}/current.conf \
|
readonly KNOWN_CONF_FILES=(${CUSTOMER_LOCATION}/update.conf \
|
||||||
${device_conf##*${CUSTOMER_ID}/} \
|
${DC2C_PRINT_JSON[@]##*${CUSTOMER_ID}/} \
|
||||||
${emp_conf##*${CUSTOMER_ID}/} \
|
${DC2C_CONF_JSON##*${CUSTOMER_ID}/} \
|
||||||
${printer_conf##*${CUSTOMER_ID}/})
|
${DC2C_CASH_JSON##*${CUSTOMER_ID}/} \
|
||||||
|
${DC2C_SERIAL_JSON##*${CUSTOMER_ID}/})
|
||||||
|
|
||||||
readonly KNOWN_INI_FILES=(${ATBQT_INI_FULL##*${CUSTOMER_ID}/} \
|
readonly KNOWN_INI_FILES=(${ATBQT_INI_FULL##*${CUSTOMER_ID}/} \
|
||||||
${ISMASMGR_ISMASMGR_INI_FULL##*${CUSTOMER_ID}/} \
|
${ISMASMGR_ISMASMGR_INI_FULL##*${CUSTOMER_ID}/} \
|
||||||
${SYSCONFIG_ISMASMGR_INI_FULL##*${CUSTOMER_ID}/} \
|
${SYSCONFIG_ISMASMGR_INI_FULL##*${CUSTOMER_ID}/} \
|
||||||
${SYSCONFIG_SYSCONFIG_INI_FULL##*${CUSTOMER_ID}/} \
|
${SYSCONFIG_SYSCONFIG_INI_FULL##*${CUSTOMER_ID}/} \
|
||||||
${SYSCONFIG_SYSCTRL_INI_FULL##*${CUSTOMER_ID}/})
|
${SYSCONFIG_SYSCTRL_INI_FULL##*${CUSTOMER_ID}/})
|
||||||
|
|
||||||
readonly KNOWN_FILES=(${KNOWN_CONF_FILES[@]} \
|
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 ->"
|
log_debug "$func:${LINENO}: known conf/ini_files ->"
|
||||||
for (( i=0; i < ${#KNOWN_FILES[@]}; ++i )); do
|
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
|
done
|
||||||
log_debug "$func:${LINENO}: sanity of ${CUSTOMER_REPOSITORY_PATH} OK"
|
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
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user