UpdateController/read_config

367 lines
16 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-05 21:42:53 +02:00
source ./general_utils
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]}
readonly MAJOR="0"
readonly MINOR="1"
readonly PATCH="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 WORKSPACE_DIR=workspace
2022-06-07 21:50:03 +02:00
# TODO: entfernen indem man subtree benutzt
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-07 21:50:03 +02:00
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"
2022-06-05 21:42:53 +02:00
### 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"
2022-06-04 18:14:16 +02:00
fi
readonly GIT_SSL_NO_VERIFY="$(cat "$cf" | jq -r .GIT_SSL_NO_VERIFY)"
2022-06-05 21:42:53 +02:00
assert_s GIT_SSL_NO_VERIFY
readonly CUSTOMER_LOCATION=$(cat "$cf" | jq -r .customer_location)
2022-06-05 21:42:53 +02:00
assert_s CUSTOMER_LOCATION
2022-06-05 21:42:53 +02:00
readonly CUSTOMER_ID="$(cat "$cf" | jq -r .customer_id)"
assert_s CUSTOMER_ID
2022-06-04 18:14:16 +02:00
2022-06-05 21:42:53 +02:00
readonly CUSTOMER_REPOSITORY_PATH="$(cat "$cf" |
jq -r .cust_repository_path)"
assert_s 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[@]})
2022-06-05 21:42:53 +02:00
assert_a ZONE_GROUPS
2022-06-06 18:53:30 +02:00
2022-06-02 22:25:57 +02:00
return 0
}
###############################################################################
########################## parsing with jq finished ###########################
###############################################################################
compute_hash () {
# TODO: wie genau soll der hash-wert berechnet werden ?
2022-06-02 16:06:07 +02:00
HASH="1234-abcd"
# HASH_="67890def"
echo $HASH
}
compute_version () {
VERSION="$MAJOR.$MINOR.$PATCH+$CUSTOMER_LOCATION-$(compute_hash)"
}
2022-06-02 22:25:57 +02:00
check_sanity_of_repository () {
local func="${FUNCNAME[0]}"
2022-06-07 21:50:03 +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-05 21:42:53 +02:00
assert_d 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-05 21:42:53 +02:00
assert_d CUSTOMER_LOCATION_DIR
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
2022-06-07 21:50:03 +02:00
# 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
2022-06-06 18:53:30 +02:00
# TODO
# TODO: falls mehrere gruppen/zonen auftauchen hier anpassen
# TODO
2022-06-07 21:50:03 +02:00
# Zone aus /etc/zone_nr auslesen
#
readonly ZONE=1
2022-06-07 21:50:03 +02:00
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}
2022-06-02 15:04:24 +02:00
readonly ATBQT_BIN="ATBQT"
2022-06-07 21:50:03 +02:00
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"
2022-06-02 15:04:24 +02:00
readonly ATBQT_ATB_SYS_BIN_FILE="${ATBAPP_SYS_DIR}/$ATBQT_BIN"
2022-06-07 21:50:03 +02:00
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"
2022-06-02 15:04:24 +02:00
readonly ATBQT_ATB_PSA_BIN_FILE="${ATBAPP_PSA_DIR}/$ATBQT_BIN"
2022-06-07 21:50:03 +02:00
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
2022-06-05 21:42:53 +02:00
assert_d ATB_SYS_DIR
2022-06-07 21:50:03 +02:00
assert_d DC_SYS_DIR
assert_d TARIFF_SYS_DIR
2022-06-05 21:42:53 +02:00
assert_d OPKG_SYS_DIR
2022-06-07 21:50:03 +02:00
assert_d CONF_SYS_DIR
assert_d OPT_SYS_DIR
assert_d APP_SYS_DIR
2022-06-05 21:42:53 +02:00
assert_d ATBAPP_SYS_DIR
2022-06-07 21:50:03 +02:00
assert_d SYSCONFIG_SYS_DIR
assert_d ISMASMGR_SYS_DIR
2022-06-04 18:14:16 +02:00
2022-06-07 21:50:03 +02:00
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
2022-06-02 15:04:24 +02:00
assert_f ATBQT_ATB_SYS_BIN_FILE
2022-06-07 21:50:03 +02:00
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
2022-06-02 15:04:24 +02:00
# assert_f ATBQT_ATB_PSA_BIN_FILE
2022-06-07 21:50:03 +02:00
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)
2022-06-02 21:52:10 +02:00
2022-06-06 18:53:30 +02:00
local DC2C_PRINT_JSON=()
for i in {1..32}; do # up to 32 print-json-files
2022-06-07 21:50:03 +02:00
local __f=${CONF_PSA_DIR}/DC2C_print$(printf "%02d" $i).json
2022-06-06 18:53:30 +02:00
readonly DC2C_PRINT$(printf "%02d" $i)_JSON=$__f
# local __g=$(eval echo '$'DC2C_PRINT$(printf "%02d" $i)_JSON)
2022-06-05 21:42:53 +02:00
assert_f DC2C_PRINT$(printf "%02d" $i)_JSON
DC2C_PRINT_JSON+=($__f)
2022-06-06 18:53:30 +02:00
done
2022-06-07 21:50:03 +02:00
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}/})
2022-06-02 22:25:57 +02:00
readonly KNOWN_FILES=(${KNOWN_CONF_FILES[@]} \
${KNOWN_INI_FILES[@]} \
2022-06-07 21:50:03 +02:00
${OPKG_CMDS_PSA_FILE##*${CUSTOMER_ID}/})
2022-06-05 21:42:53 +02:00
log_debug "known conf/ini_files ->"
for (( i=0; i < ${#KNOWN_FILES[@]}; ++i )); do
2022-06-06 18:53:30 +02:00
tab=$'\t'
2022-06-05 21:42:53 +02:00
log_debug "$tab$tab ${KNOWN_FILES[$i]}"
done
2022-06-05 21:42:53 +02:00
log_debug "sanity of ${CUSTOMER_REPOSITORY_PATH} OK"
# compute version string for current (i.e. previous) version
compute_version
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