UpdateController/read_config

365 lines
15 KiB
Plaintext
Raw Normal View History

2022-06-06 18:53:30 +02:00
#! /bin/bash -
2022-06-03 20:49:33 +02:00
# set -x
2022-06-04 18:14:16 +02:00
source ./log_helpers
2022-06-03 20:49:33 +02:00
2022-06-04 18:14:16 +02:00
if [ ${read_config_sourced:-1} = "1" ]; then # include only once
readonly read_config_sourced=${BASH_SOURCE[0]}
2022-06-03 20:49:33 +02:00
readonly DATEFLAGS="+%Y.%m.%dT%H.%M.%S"
2022-06-06 18:53:30 +02:00
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'"
readonly UPDATEPSAHOME=$HOME/.updatepsa
readonly UPDATEPSABEGIN=./.updatepsa/begin
readonly UPDATEPSAEND=./.updatepsa/end
readonly PROGRAM=`basename $0`
readonly VERSION="0.8.0"
readonly WORKSPACE_DIR=workspace
2022-06-06 18:53:30 +02:00
WORKING_DIRECTORY=${WORKING_DIRECTORY:-$UPDATEPSAHOME}
CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'}
if ! [ -f "$CONFIGFILENAME" ]; then
log_fatal "$func:${LINENO}: $CONFIGFILENAME not found"
fi
2022-06-06 18:53:30 +02:00
if ! [ -d "$WORKING_DIRECTORY" ]; then
log_fatal "$func:${LINENO}: $WORKING_DIRECTORY not found"
fi
2022-06-02 21:52:10 +02:00
EXITCODE=$RC_SUCCESS
CLONE_CUSTOMER_REPOSITORY=false
2022-06-04 18:14:16 +02:00
# read config file (JSON syntax)
read_config() {
local func="${FUNCNAME[0]}"
log_debug "$func:${LINENO}: CONFIGFILENAME=$CONFIGFILENAME"
log_debug "$func:${LINENO}: WORKING_DIRECTORY=$WORKING_DIRECTORY"
2022-06-04 18:14:16 +02:00
local readonly cf="$CONFIGFILENAME"
if cd $WORKING_DIRECTORY ; then
log_debug "$func:${LINENO}: cd to $WORKING_DIRECTORY"
else
log_fatal "$func:${LINENO}: cannot cd to $WORKING_DIRECTORY"
2022-06-04 18:14:16 +02:00
fi
readonly GIT_SSL_NO_VERIFY="$(cat "$cf" | jq -r .GIT_SSL_NO_VERIFY)"
if [ -z "$GIT_SSL_NO_VERIFY" ]; then
log_fatal "$func:${LINENO} GIT_SSL_NO_VERIFY not set in $cf"
2022-06-04 18:14:16 +02:00
fi
log_debug "$func:${LINENO}: GIT_SSL_NO_VERIFY=$GIT_SSL_NO_VERIFY"
log_debug "$func:${LINENO}: WORKSPACE_DIR=$WORKSPACE_DIR"
2022-06-04 18:14:16 +02:00
readonly CUSTOMER_LOCATION=$(cat "$cf" | jq -r .customer_location)
if [ -z "$CUSTOMER_LOCATION" ]; then
log_fatal "$func:${LINENO}: CUSTOMER_LOCATION not set in $cf"
2022-06-04 18:14:16 +02:00
fi
log_debug "$func:${LINENO}: customer-location=$CUSTOMER_LOCATION"
readonly CUST_ID="$(cat "$cf" | jq -r .customer_id)"
if [ -z "$CUST_ID" ]; then
log_fatal "$func:${LINENO} CUST_ID not set in $cf"
fi
readonly CUSTOMER_ID="customer_$CUST_ID"
log_debug "$func:${LINENO}: CUSTOMER-ID=$CUSTOMER_ID"
2022-06-04 18:14:16 +02:00
local __r_path="$(cat "$cf" | jq -r .cust_repository_path)"
if [ -z "$__r_path" ]; then
log_fatal "$func:${LINENO}: customer repository path not set in $cf"
fi
readonly CUSTOMER_REPOSITORY_PATH="${__r_path}/${CUSTOMER_ID}.git"
2022-06-04 21:44:33 +02:00
log_debug "$func:${LINENO}: customer-r-path=$CUSTOMER_REPOSITORY_PATH"
2022-06-06 18:53:30 +02:00
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=($__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
2022-06-06 18:53:30 +02:00
readonly ZONE_GROUPS=(${__zone_groups[@]})
log_debug "$func:${LINENO}: ZONE_GROUPS=${ZONE_GROUPS[@]}"
log_debug "$func:${LINENO}: reading ${wd} done"
2022-06-02 22:25:57 +02:00
return 0
}
###############################################################################
########################## parsing with jq finished ###########################
###############################################################################
2022-06-02 22:25:57 +02:00
check_sanity_of_repository () {
local func="${FUNCNAME[0]}"
2022-06-03 20:49:33 +02:00
2022-06-06 18:53:30 +02:00
local __customer_id_base_dir="$WORKING_DIRECTORY/${WORKSPACE_DIR}"
readonly CUSTOMER_ID_BASE_DIR="${__customer_id_base_dir}/${CUSTOMER_ID}"
2022-06-03 19:24:13 +02:00
log_debug "$func:${LINENO}: CUSTOMER_ID_BASE_DIR="
log_debug "$func:${LINENO}: $CUSTOMER_ID_BASE_DIR"
2022-06-03 19:24:13 +02:00
2022-06-06 18:53:30 +02:00
CUSTOMER_LOCATION_DIR="${CUSTOMER_ID_BASE_DIR}/${CUSTOMER_LOCATION}"
2022-06-03 20:49:33 +02:00
log_debug "$func:${LINENO}: CUSTOMER_LOCATION_DIR="
log_debug "$func:${LINENO}: $CUSTOMER_LOCATION_DIR"
readonly UPDATE_CONF="${CUSTOMER_LOCATION_DIR}/update.conf"
2022-06-02 21:52:10 +02:00
log_debug "$func:${LINENO}: UPDATE.CONF=$UPDATE_CONF"
readonly DC="dc2c.hex"
readonly DC_SYS_DIR="/etc/dc"
readonly DC_DIR="${CUSTOMER_LOCATION_DIR}/dc"
readonly DC_FULL="${DC_DIR}/$DC"
if [ -f "$DC_FULL" ]; then
log_debug "$func:${LINENO}: d2dc.hex=$DC_FULL"
else
log_fatal "$func:${LINENO}: $DC_FULL does not exist"
fi
2022-06-04 18:14:16 +02:00
# readonly zone_groups=(${__zone_groups[@]})
2022-06-06 18:53:30 +02:00
# 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
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 ZONE=1
readonly CUSTOMER_BASE_DIR="${CUSTOMER_BASE_DIRS[$ZONE]}"
2022-06-05 19:24:41 +02:00
if [ -d "$CUSTOMER_BASE_DIR" ]; then
2022-06-06 18:53:30 +02:00
log_debug "$func:${LINENO}: CUSTOMER-BASE-DIR="
2022-06-05 19:24:41 +02:00
log_debug "$func:${LINENO}: $CUSTOMER_BASE_DIR"
2022-06-02 22:25:57 +02:00
else
2022-06-05 19:24:41 +02:00
log_fatal "$func:${LINENO}: $CUSTOMER_BASE_DIR does not exist"
2022-06-02 22:25:57 +02:00
fi
2022-06-06 18:53:30 +02:00
2022-06-05 19:24:41 +02:00
readonly psa_config_dir="${CUSTOMER_BASE_DIR}/etc/psa_config"
2022-06-02 22:25:57 +02:00
if [ -d "$psa_config_dir" ]; then
log_debug "$func:${LINENO}: psa_config_dir="
log_debug "$func:${LINENO}: $psa_config_dir"
else
log_fatal "$func:${LINENO}: $psa_config_dir does not exist"
fi
2022-06-05 19:24:41 +02:00
readonly psa_update_dir="${CUSTOMER_BASE_DIR}/etc/psa_update"
2022-06-02 22:25:57 +02:00
if [ -d "$psa_update_dir" ]; then
log_debug "$func:${LINENO}: psa_update_dir="
log_debug "$func:${LINENO}: $psa_update_dir"
else
log_fatal "$func:${LINENO}: $psa_update_dir does not exist"
fi
2022-06-05 19:24:41 +02:00
readonly psa_base_ini_dir="${CUSTOMER_BASE_DIR}/opt/app"
2022-06-02 22:25:57 +02:00
if [ -d "$psa_base_ini_dir" ]; then
log_debug "$func:${LINENO}: psa_base_ini_dir="
log_debug "$func:${LINENO}: $psa_base_ini_dir"
else
log_fatal "$func:${LINENO}: $psa_base_ini_dir does not exist"
fi
2022-06-05 19:24:41 +02:00
readonly SYSCONFIG_SYS_DIR="/opt/app/sysconfig"
readonly PSA_SYSCONFIG_DIR="$CUSTOMER_BASE_DIR$SYSCONFIG_SYS_DIR"
2022-06-02 22:25:57 +02:00
# if [ -d "$psa_syconfig_dir" ]; DOES NOT WORK !!!
2022-06-05 19:24:41 +02:00
if ls -al $PSA_SYSCONFIG_DIR > /dev/null; then
log_debug "$func:${LINENO}: PSA_SYSCONFIG_DIR="
log_debug "$func:${LINENO}: $PSA_SYSCONFIG_DIR"
2022-06-02 22:25:57 +02:00
else
2022-06-05 19:24:41 +02:00
log_error "$func:${LINENO}: $PSA_SYSCONFIG_DIR does not exist"
2022-06-02 22:25:57 +02:00
fi
2022-06-03 20:49:33 +02:00
2022-06-02 22:25:57 +02:00
readonly psa_ismasmgr_dir="${psa_base_ini_dir}/ISMASMgr"
if [ -d "$psa_ismasmgr_dir" ]; then
log_debug "$func:${LINENO}: psa_ismasmgr_dir="
log_debug "$func:${LINENO}: $psa_ismasmgr_dir"
else
log_fatal "$func:${LINENO}: $psa_ismasmgr_dir does not exist"
fi
2022-06-05 19:24:41 +02:00
readonly CONF_SYS_DIR="/etc/psa_config"
readonly OPKG_SYS_DIR="/etc/psa_update"
readonly ATBAPP_SYS_DIR="/opt/app/ATBAPP"
2022-06-04 18:14:16 +02:00
2022-06-05 19:24:41 +02:00
readonly psa_atbqt_dir="$CUSTOMER_BASE_DIR$ATBAPP_SYS_DIR"
2022-06-02 22:25:57 +02:00
if [ -d "$psa_atbqt_dir" ]; then
log_debug "$func:${LINENO}: psa_atbqt_dir="
log_debug "$func:${LINENO}: $psa_atbqt_dir"
else
log_fatal "$func:${LINENO}: $psa_atbqt_dir does not exist"
fi
readonly TARIFF_CURRENT="tariff.current"
readonly TARIFF_CURRENT_FULL="${psa_atbqt_dir}/$TARIFF_CURRENT"
if [ -f "$TARIFF_CURRENT_FULL" ]; then
log_debug "$func:${LINENO}: tariff.current="
log_debug "$func:${LINENO}: $TARIFF_CURRENT_FULL"
else
log_fatal "$func:${LINENO}: $TARIFF_CURRENT_FULL does not exist"
fi
2022-06-05 19:24:41 +02:00
readonly ATBQT_INI="ATBQT.ini"
readonly ATBQT_INI_FULL="${psa_atbqt_dir}/$ATBQT_INI"
if [ -f "$ATBQT_INI_FULL" ]; then
2022-06-02 22:25:57 +02:00
log_debug "$func:${LINENO}: ATBTQT.ini="
2022-06-05 19:24:41 +02:00
log_debug "$func:${LINENO}: $ATBQT_INI_FULL"
2022-06-02 22:25:57 +02:00
else
2022-06-05 19:24:41 +02:00
log_fatal "$func:${LINENO}: $ATBQT_INI_FULL does not exist"
2022-06-02 22:25:57 +02:00
fi
2022-06-02 21:52:10 +02:00
readonly ATBQT="ATBQT"
readonly ATBQT_SYS_FULL="${ATBAPP_SYS_DIR}/$ATBQT"
if [ -f "$ATBQT_SYS_FULL" ]; then
log_debug "$func:${LINENO}: ATBQT="
log_debug "$func:${LINENO}: $ATBQT_SYS_FULL"
else
log_fatal "$func:${LINENO}: $ATBQT_SYS_FULL does not exist"
fi
2022-06-05 19:24:41 +02:00
readonly ISMASMGR_INI="ISMASMgr.ini"
readonly ISMASMGR_SYS_DIR="/opt/app/ISMASMgr"
2022-06-02 22:25:57 +02:00
2022-06-05 19:24:41 +02:00
readonly ISMASMGR_ISMASMGR_INI_FULL="${psa_ismasmgr_dir}/$ISMASMGR_INI"
if [ -f "$ISMASMGR_ISMASMGR_INI_FULL" ]; then
2022-06-02 22:25:57 +02:00
log_debug "$func:${LINENO}: ismasmgr_ismasmgr.ini="
2022-06-05 19:24:41 +02:00
log_debug "$func:${LINENO}: $ISMASMGR_ISMASMGR_INI_FULL"
2022-06-02 22:25:57 +02:00
else
2022-06-05 19:24:41 +02:00
log_fatal "$func:${LINENO}: $ISMASMGR_ISMASMGR_INI_FULL "\
"does not exist"
2022-06-02 22:25:57 +02:00
fi
2022-06-05 19:24:41 +02:00
readonly SYSCONFIG_ISMASMGR_INI_FULL="${PSA_SYSCONFIG_DIR}/ISMASMgr.ini"
if [ -f "$SYSCONFIG_ISMASMGR_INI_FULL" ]; then
2022-06-02 22:25:57 +02:00
log_debug "$func:${LINENO}: sysconfig_ismasmgr.ini="
2022-06-05 19:24:41 +02:00
log_debug "$func:${LINENO}: $SYSCONFIG_ISMASMGR_INI_FULL"
2022-06-02 22:25:57 +02:00
else
2022-06-05 19:24:41 +02:00
log_fatal "$func:${LINENO}: $SYSCONFIG_ISMASMGR_INI_FULL "\
"does not exist"
2022-06-02 22:25:57 +02:00
fi
2022-06-05 19:24:41 +02:00
readonly SYS_CONFIG_INI="sysconfig.ini"
readonly __sysc_sysc_full="${PSA_SYSCONFIG_DIR}/$SYS_CONFIG_INI"
readonly SYSCONFIG_SYSCONFIG_INI_FULL="$__sysc_sysc_full"
if [ -f "$SYSCONFIG_SYSCONFIG_INI_FULL" ]; then
2022-06-02 22:25:57 +02:00
log_debug "$func:${LINENO}: sysconfig_sysconfig.ini="
2022-06-05 19:24:41 +02:00
log_debug "$func:${LINENO}: $SYSCONFIG_SYSCONFIG_INI_FULL"
2022-06-02 22:25:57 +02:00
else
2022-06-05 19:24:41 +02:00
log_fatal "$func:${LINENO}: "\
"$SYSCONFIG_SYSCONFIG_INI_FULL does not exist"
2022-06-02 22:25:57 +02:00
fi
2022-06-05 19:24:41 +02:00
readonly "SYSTEM_CONTROL_INI"="SystemControl.ini"
local __sysctrl_ini_full="${PSA_SYSCONFIG_DIR}/$SYSTEM_CONTROL_INI"
readonly SYSCONFIG_SYSCTRL_INI_FULL="$__sysctrl_ini_full"
if [ -f "$SYSCONFIG_SYSCTRL_INI_FULL" ]; then
2022-06-02 22:25:57 +02:00
log_debug "$func:${LINENO}: sysconfig_systemcontrol.ini="
2022-06-05 19:24:41 +02:00
log_debug "$func:${LINENO}: $SYSCONFIG_SYSCTRL_INI_FULL"
2022-06-02 22:25:57 +02:00
else
2022-06-05 19:24:41 +02:00
log_fatal "$func:${LINENO}: $SYSCONFIG_SYSCTRL_INI_FULL does not exist"
2022-06-02 22:25:57 +02:00
fi
2022-06-06 18:53:30 +02:00
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"
2022-06-02 22:25:57 +02:00
else
2022-06-06 18:53:30 +02:00
log_fatal "$func:${LINENO}: $DC2C_SERIAL_JSON does not exist"
2022-06-02 22:25:57 +02:00
fi
2022-06-06 18:53:30 +02:00
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"
2022-06-02 22:25:57 +02:00
else
2022-06-06 18:53:30 +02:00
log_debug "$func:${LINENO}: $DC2C_CASH_JSON does not exist"
2022-06-02 22:25:57 +02:00
fi
2022-06-06 18:53:30 +02:00
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"
2022-06-02 22:25:57 +02:00
else
2022-06-06 18:53:30 +02:00
log_fatal "$func:${LINENO}: $DC2C_CONF_JSON does not exist"
2022-06-02 22:25:57 +02:00
fi
2022-06-06 18:53:30 +02:00
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"
2022-06-02 22:25:57 +02:00
if [ -f "$opkg_cmds_file" ]; then
log_debug "$func:${LINENO}: opkg_commands="
log_debug "$func:${LINENO}: $opkg_cmds_file"
else
log_fatal "$func:${LINENO}: $opkg_cmds_file does not exist"
fi
2022-06-06 18:53:30 +02:00
# 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}/} \
2022-06-05 19:24:41 +02:00
${SYSCONFIG_SYSCTRL_INI_FULL##*${CUSTOMER_ID}/})
2022-06-02 22:25:57 +02:00
readonly KNOWN_FILES=(${KNOWN_CONF_FILES[@]} \
${KNOWN_INI_FILES[@]} \
${opkg_cmds_file##*${CUSTOMER_ID}/})
log_debug "$func:${LINENO}: known conf/ini_files ->"
for (( i=0; i < ${#KNOWN_FILES[@]}; ++i )); do
2022-06-06 18:53:30 +02:00
tab=$'\t'
log_debug "$func:${LINENO}: $tab$tab ${KNOWN_FILES[$i]}"
done
log_debug "$func:${LINENO}: sanity of ${CUSTOMER_REPOSITORY_PATH} OK"
2022-06-04 18:14:16 +02:00
return 0
}
fi
2022-06-03 20:49:33 +02:00
2022-06-06 18:53:30 +02:00