UpdateController/read_config

367 lines
16 KiB
Bash
Executable File

#! /bin/bash -
# set -x
source ./log_helpers
source ./general_utils
if [ ${read_config_sourced:-1} = "1" ]; then # include only once
readonly read_config_sourced=${BASH_SOURCE[0]}
readonly MAJOR="0"
readonly MINOR="1"
readonly PATCH="0"
readonly DATEFLAGS="+%Y.%m.%dT%H.%M.%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'"
readonly UPDATEPSAHOME=$HOME/.updatepsa
readonly UPDATEPSABEGIN=./.updatepsa/begin
readonly UPDATEPSAEND=./.updatepsa/end
readonly PROGRAM=`basename $0`
readonly WORKSPACE_DIR=workspace
# TODO: entfernen indem man subtree benutzt
WORKING_DIRECTORY=${WORKING_DIRECTORY:-$UPDATEPSAHOME}
CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'}
if ! [ -f "$CONFIGFILENAME" ]; then
log_fatal "$func:${LINENO}: $CONFIGFILENAME not found"
fi
if ! [ -d "$WORKING_DIRECTORY" ]; then
log_fatal "$func:${LINENO}: $WORKING_DIRECTORY not found"
fi
EXITCODE=$RC_SUCCESS
CLONE_CUSTOMER_REPOSITORY=false
# 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"
local readonly cf="$CONFIGFILENAME"
### TODO: wieso wird hier in das verzeichnis gewechselt
if cd $WORKING_DIRECTORY ; then
log_debug "$func:${LINENO}: cd to $WORKING_DIRECTORY"
else
log_fatal "$func:${LINENO}: cannot cd to $WORKING_DIRECTORY"
fi
readonly GIT_SSL_NO_VERIFY="$(cat "$cf" | jq -r .GIT_SSL_NO_VERIFY)"
assert_s GIT_SSL_NO_VERIFY
readonly CUSTOMER_LOCATION=$(cat "$cf" | jq -r .customer_location)
assert_s CUSTOMER_LOCATION
readonly CUSTOMER_ID="$(cat "$cf" | jq -r .customer_id)"
assert_s CUSTOMER_ID
readonly CUSTOMER_REPOSITORY_PATH="$(cat "$cf" |
jq -r .cust_repository_path)"
assert_s CUSTOMER_REPOSITORY_PATH
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
readonly ZONE_GROUPS=(${__zone_groups[@]})
assert_a ZONE_GROUPS
return 0
}
###############################################################################
########################## parsing with jq finished ###########################
###############################################################################
compute_hash () {
# TODO: wie genau soll der hash-wert berechnet werden ?
HASH="1234-abcd"
# HASH_="67890def"
echo $HASH
}
compute_version () {
VERSION="$MAJOR.$MINOR.$PATCH+$CUSTOMER_LOCATION-$(compute_hash)"
}
check_sanity_of_repository () {
local func="${FUNCNAME[0]}"
local __customer_id_base_dir="$WORKING_DIRECTORY/${WORKSPACE_DIR}"
readonly CUSTOMER_ID_BASE_DIR="${__customer_id_base_dir}/${CUSTOMER_ID}"
assert_d CUSTOMER_ID_BASE_DIR
CUSTOMER_LOCATION_DIR="${CUSTOMER_ID_BASE_DIR}/${CUSTOMER_LOCATION}"
assert_d CUSTOMER_LOCATION_DIR
# readonly zone_groups=(${__zone_groups[@]})
# 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
# for szeged:
# placeholder
# /home/root/szeged/UpdateController/workspace/customer_281/szeged/1/1
# /home/root/szeged/UpdateController/workspace/customer_281/szeged/1/2
# /home/root/szeged/UpdateController/workspace/customer_281/szeged/1/3
readonly CUST_BASE_DIRS=(${__customer_base_dirs[@]})
assert_a CUST_BASE_DIRS
# TODO
# TODO: falls mehrere gruppen/zonen auftauchen hier anpassen
# TODO
# Zone aus /etc/zone_nr auslesen
#
readonly ZONE=1
readonly CUST_BASE_DIR="${CUST_BASE_DIRS[$ZONE]}"
assert_d CUST_BASE_DIR
readonly ETC_SYS_DIR="/etc"
readonly ATB_SYS_DIR="/etc/atb"
readonly DC_SYS_DIR="/etc/dc"
readonly TARIFF_SYS_DIR="/etc/tariff"
readonly OPKG_SYS_DIR="/etc/psa_update"
readonly CONF_SYS_DIR="/etc/psa_config"
readonly OPT_SYS_DIR="/opt"
readonly APP_SYS_DIR="/opt/app"
readonly SYSCONFIG_SYS_DIR="/opt/app/sysconfig"
readonly ATBAPP_SYS_DIR="/opt/app/ATBAPP"
readonly ISMASMGR_SYS_DIR="/opt/app/ISMASMgr"
readonly ETC_PSA_DIR=${CUST_BASE_DIR}${ETC_SYS_DIR}
readonly ATB_PSA_DIR=${CUST_BASE_DIR}${ATB_SYS_DIR}
readonly DC_PSA_DIR=${CUST_BASE_DIR}${DC_SYS_DIR}
readonly TARIFF_PSA_DIR=${CUST_BASE_DIR}${TARIFF_SYS_DIR}
readonly OPKG_PSA_DIR=${CUST_BASE_DIR}${OPKG_SYS_DIR}
readonly CONF_PSA_DIR=${CUST_BASE_DIR}${CONF_SYS_DIR}
readonly OPT_PSA_DIR=${CUST_BASE_DIR}${OPT_SYS_DIR}
readonly APP_PSA_DIR=${CUST_BASE_DIR}${APP_SYS_DIR}
readonly ATBAPP_PSA_DIR=${CUST_BASE_DIR}${ATBAPP_SYS_DIR}
readonly SYSCONFIG_PSA_DIR=${CUST_BASE_DIR}${SYSCONFIG_SYS_DIR}
readonly ISMASMGR_PSA_DIR=${CUST_BASE_DIR}${ISMASMGR_SYS_DIR}
readonly ATBQT_BIN="ATBQT"
readonly ATBQT_INI="ATBQT.ini"
readonly ISMASMGR_INI="ISMASMgr.ini"
readonly SYSCONF_INI="sysconfig.ini"
readonly SYSCTRL_INI="SystemControl.ini"
readonly TARIFF_CURRENT="tariff.current"
readonly DC="dc2c.hex"
readonly DC_SYS_DC_FILE="${DC_SYS_DIR}/$DC"
readonly ATBQT_ATB_SYS_BIN_FILE="${ATBAPP_SYS_DIR}/$ATBQT_BIN"
readonly ATBQT_ATB_SYS_INI_FILE="${ATB_SYS_DIR}/$ATBQT_INI"
readonly ATBQT_APP_SYS_INI_FILE="${ATBAPP_SYS_DIR}/$ATBQT_INI"
readonly ATBQT_ETC_SYS_INI_FILE="${ETC_SYS_DIR}/$ATBQT_INI"
readonly ISMASMGRATB_SYS_INI_FILE="${ATB_SYS_DIR}/$ISMASMGR_INI"
readonly ISMASMGRAPP_SYS_INI_FILE="${ISMASMGR_SYS_DIR}/$ISMASMGR_INI"
readonly ISMASMGRETC_SYS_INI_FILE="${ETC_SYS_DIR}/$ISMASMGR_INI"
readonly ISMASMGRSCF_SYS_INI_FILE="${SYSCONFIG_SYS_DIR}/$ISMASMGR_INI"
readonly SYSCONF_ETC_SYS_INI_FILE="${ETC_SYS_DIR}/$SYSCONF_INI"
readonly SYSCONF_ATB_SYS_INI_FILE="${ATB_SYS_DIR}/$SYSCONF_INI"
readonly SYSCONF_SCF_SYS_INI_FILE="${SYSCONFIG_SYS_DIR}/$SYSCONF_INI"
readonly SYSCTRL_ETC_SYS_INI_FILE="${ETC_SYS_DIR}/$SYSCTRL_INI"
readonly SYSCTRL_ATB_SYS_INI_FILE="${ATB_SYS_DIR}/$SYSCTRL_INI"
readonly SYSCTRL_SCF_SYS_INI_FILE="${SYSCONFIG_SYS_DIR}/$SYSCTRL_INI"
readonly ZONE_FILE="$ETC_SYS_DIR/zone_nr"
readonly CUST_ID_FILE="$ETC_SYS_DIR/cust_nr"
readonly TC_SYS_TC_FILE="${ATBAPP_SYS_DIR}/$TARIFF_CURRENT"
readonly OPKG_CMDS_SYS_FILE="${OPKG_SYS_DIR}/opkg_commands"
readonly DC2C_SYS_SERIAL_JSON="${CONF_SYS_DIR}/DC2C_serial.json"
readonly DC2C_SYS_CASH_JSON="${CONF_SYS_DIR}/DC2C_cash.json"
readonly DC2C_SYS_CONF_JSON="${CONF_SYS_DIR}/DC2C_conf.json"
readonly DC_PSA_DC_FILE="${DC_PSA_DIR}/$DC"
readonly ATBQT_ATB_PSA_BIN_FILE="${ATBAPP_PSA_DIR}/$ATBQT_BIN"
readonly ATBQT_ATB_PSA_INI_FILE="${ATB_SYS_DIR}/$ATBQT_INI"
readonly ATBQT_APP_PSA_INI_FILE="${ATBAPP_SYS_DIR}/$ATBQT_INI"
readonly ATBQT_ETC_PSA_INI_FILE="${ETC_SYS_DIR}/$ATBQT_INI"
readonly ISMASMGRATB_PSA_INI_FILE="${ATB_PSA_DIR}/$ISMASMGR_INI"
readonly ISMASMGRAPP_PSA_INI_FILE="${ISMASMGR_PSA_DIR}/$ISMASMGR_INI"
readonly ISMASMGRETC_PSA_INI_FILE="${ETC_PSA_DIR}/$ISMASMGR_INI"
readonly ISMASMGRSCF_PSA_INI_FILE="${SYSCONFIG_PSA_DIR}/$ISMASMGR_INI"
readonly SYSCONF_ETC_PSA_INI_FILE="${ETC_PSA_DIR}/$SYSCONF_INI"
readonly SYSCONF_ATB_PSA_INI_FILE="${ATB_PSA_DIR}/$SYSCONF_INI"
readonly SYSCONF_SCF_PSA_INI_FILE="${SYSCONFIG_PSA_DIR}/$SYSCONF_INI"
readonly SYSCTRL_ETC_PSA_INI_FILE="${ETC_SYS_DIR}/$SYSCTRL_INI"
readonly SYSCTRL_ATB_PSA_INI_FILE="${ATB_SYS_DIR}/$SYSCTRL_INI"
readonly SYSCTRL_SCF_PSA_INI_FILE="${SYSCONFIG_SYS_DIR}/$SYSCTRL_INI"
readonly OPKG_CMDS_PSA_FILE="${OPKG_PSA_DIR}/opkg_commands"
readonly TC_PSA_TC_FILE="${ATBAPP_PSA_DIR}/$TARIFF_CURRENT"
readonly PSA_UPDATE_CONF="${CUSTOMER_LOCATION_DIR}/update.conf"
readonly DC2C_PSA_SERIAL_JSON="${CONF_PSA_DIR}/DC2C_serial.json"
readonly DC2C_PSA_CASH_JSON="${CONF_PSA_DIR}/DC2C_cash.json"
readonly DC2C_PSA_CONF_JSON="${CONF_PSA_DIR}/DC2C_conf.json"
assert_d ETC_SYS_DIR
assert_d ATB_SYS_DIR
assert_d DC_SYS_DIR
assert_d TARIFF_SYS_DIR
assert_d OPKG_SYS_DIR
assert_d CONF_SYS_DIR
assert_d OPT_SYS_DIR
assert_d APP_SYS_DIR
assert_d ATBAPP_SYS_DIR
assert_d SYSCONFIG_SYS_DIR
assert_d ISMASMGR_SYS_DIR
assert_d ETC_PSA_DIR
assert_d ATB_PSA_DIR
assert_d DC_PSA_DIR
assert_d TARIFF_PSA_DIR
assert_d OPKG_PSA_DIR
assert_d CONF_PSA_DIR
assert_d OPT_PSA_DIR
assert_d APP_PSA_DIR
assert_d ATBAPP_PSA_DIR
assert_d SYSCONFIG_PSA_DIR
assert_d ISMASMGR_PSA_DIR
assert_f DC_SYS_DC_FILE
assert_f ZONE_FILE
assert_f CUST_ID_FILE
assert_f ATBQT_ATB_SYS_BIN_FILE
assert_f ATBQT_ATB_SYS_INI_FILE
assert_f ATBQT_APP_SYS_INI_FILE
assert_f ATBQT_ETC_SYS_INI_FILE
assert_f ISMASMGRATB_SYS_INI_FILE
assert_f ISMASMGRAPP_SYS_INI_FILE
assert_f ISMASMGRETC_SYS_INI_FILE
assert_f ISMASMGRSCF_SYS_INI_FILE
assert_f SYSCONF_ETC_SYS_INI_FILE
assert_f SYSCONF_ATB_SYS_INI_FILE
assert_f SYSCONF_SCF_SYS_INI_FILE
assert_f SYSCTRL_ETC_SYS_INI_FILE
assert_f SYSCTRL_ATB_SYS_INI_FILE
assert_f SYSCTRL_SCF_SYS_INI_FILE
assert_f TC_SYS_TC_FILE
assert_f OPKG_CMDS_SYS_FILE
assert_f DC2C_SYS_CONF_JSON
assert_f DC2C_SYS_SERIAL_JSON
assert_f DC2C_SYS_CASH_JSON
assert_f DC_PSA_DC_FILE
assert_f ATBQT_ATB_PSA_BIN_FILE
assert_f ATBQT_ATB_PSA_INI_FILE
assert_f ATBQT_APP_PSA_INI_FILE
assert_f ATBQT_ETC_PSA_INI_FILE
assert_f ISMASMGRATB_PSA_INI_FILE
assert_f ISMASMGRAPP_PSA_INI_FILE
assert_f ISMASMGRETC_PSA_INI_FILE
assert_f ISMASMGRSCF_PSA_INI_FILE
assert_f SYSCONF_ETC_PSA_INI_FILE
assert_f SYSCONF_ATB_PSA_INI_FILE
assert_f SYSCONF_SCF_PSA_INI_FILE
assert_f SYSCTRL_ETC_PSA_INI_FILE
assert_f SYSCTRL_ATB_PSA_INI_FILE
assert_f SYSCTRL_SCF_PSA_INI_FILE
assert_f TC_PSA_TC_FILE
assert_f PSA_UPDATE_CONF
assert_f OPKG_CMDS_PSA_FILE
assert_f DC2C_PSA_CONF_JSON
assert_f DC2C_PSA_SERIAL_JSON
assert_f DC2C_PSA_CASH_JSON
readonly KNOWN_SYS_DIRS=($ETC_SYS_DIR
$ATB_SYS_DIR
$DC_SYS_DIR
$TARIFF_SYS_DIR
$OPKG_SYS_DIR
$CONF_SYS_DIR
$OPT_SYS_DIR
$APP_SYS_DIR
$ATBAPP_SYS_DIR
$SYSCONFIG_SYS_DIR)
readonly KNOWN_PSA_DIRS=($ETC_PSA_DIR
$ATB_PSA_DIR
$DC_PSA_DIR
$TARIFF_PSA_DIR
$OPKG_PSA_DIR
$CONF_PSA_DIR
$OPT_PSA_DIR
$APP_PSA_DIR
$ATBAPP_PSA_DIR
$SYSCONFIG_PSA_DIR)
local DC2C_PRINT_JSON=()
for i in {1..32}; do # up to 32 print-json-files
local __f=${CONF_PSA_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)
assert_f DC2C_PRINT$(printf "%02d" $i)_JSON
DC2C_PRINT_JSON+=($__f)
done
readonly KNOWN_CONF_FILES=(${CUSTOMER_LOCATION}/update.conf \
${DC2C_PRINT_JSON[@]##*${CUSTOMER_ID}/} \
${DC2C_PSA_CONF_JSON##*${CUSTOMER_ID}/} \
${DC2C_PSA_CASH_JSON##*${CUSTOMER_ID}/} \
${DC2C_PSA_SERIAL_JSON##*${CUSTOMER_ID}/})
readonly KNOWN_INI_FILES=(${ATBAPP_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${ISMASMGRATB_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${ISMASMGRAPP_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${ISMASMGRETC_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${ISMASMGRSCF_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${SYSCONF_ETC_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${SYSCONF_ATB_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${SYSCONF_SCF_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${SYSCTRL_ETC_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${SYSCTRL_ATB_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${SYSCTRL_SCF_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${ATBQT_ATB_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${ATBQT_APP_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${ATBQT_ETC_PSA_INI_FILE##*${CUSTOMER_ID}/})
readonly KNOWN_FILES=(${KNOWN_CONF_FILES[@]} \
${KNOWN_INI_FILES[@]} \
${OPKG_CMDS_PSA_FILE##*${CUSTOMER_ID}/})
log_debug "known conf/ini_files ->"
for (( i=0; i < ${#KNOWN_FILES[@]}; ++i )); do
tab=$'\t'
log_debug "$tab$tab ${KNOWN_FILES[$i]}"
done
log_debug "sanity of ${CUSTOMER_REPOSITORY_PATH} OK"
# compute version string for current (i.e. previous) version
compute_version
return 0
}
fi