moved some code into read_config() to make sure proper initialization

This commit is contained in:
Gerhard Hoffmann 2022-06-06 20:07:47 +02:00
parent 326c6ea001
commit 8f07fbcf53

View File

@ -25,7 +25,13 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
readonly PROGRAM=`basename $0` readonly PROGRAM=`basename $0`
readonly WORKSPACE_DIR=workspace readonly WORKSPACE_DIR=workspace
# TODO: entfernen indem man subtree benutzt EXITCODE=$RC_SUCCESS
CLONE_CUSTOMER_REPOSITORY=false
# read config file (JSON syntax)
read_config() {
local func="${FUNCNAME[0]}"
WORKING_DIRECTORY=${WORKING_DIRECTORY:-$UPDATEPSAHOME} WORKING_DIRECTORY=${WORKING_DIRECTORY:-$UPDATEPSAHOME}
CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'} CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'}
@ -37,14 +43,6 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
log_fatal "$func:${LINENO}: $WORKING_DIRECTORY not found" log_fatal "$func:${LINENO}: $WORKING_DIRECTORY not found"
fi 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}: CONFIGFILENAME=$CONFIGFILENAME"
log_debug "$func:${LINENO}: WORKING_DIRECTORY=$WORKING_DIRECTORY" log_debug "$func:${LINENO}: WORKING_DIRECTORY=$WORKING_DIRECTORY"
@ -70,6 +68,9 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
jq -r .cust_repository_path)" jq -r .cust_repository_path)"
assert_s CUSTOMER_REPOSITORY_PATH assert_s CUSTOMER_REPOSITORY_PATH
local __customer_id_base_dir="$WORKING_DIRECTORY/${WORKSPACE_DIR}"
readonly CUSTOMER_ID_BASE_DIR="${__customer_id_base_dir}/${CUSTOMER_ID}"
local __number_of_zone_groups=$(cat "$cf" | local __number_of_zone_groups=$(cat "$cf" |
jq -r .zg[0] | jq -r .zg[0] |
sed -E -e 's/[[:space:]]*//g') sed -E -e 's/[[:space:]]*//g')
@ -94,50 +95,56 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
########################## parsing with jq finished ########################### ########################## parsing with jq finished ###########################
############################################################################### ###############################################################################
compute_hash () { compute_hash () {
# TODO: wie genau soll der hash-wert berechnet werden ? if cd_customer_repository; then
HASH="1234-abcd" local hash=""
# HASH_="67890def" if [[ -z $1 ]]; then
echo $HASH hash=$(git log -n 1 --pretty=format:%H)
else
hash=$(git log -n 1 --pretty=format:%H -- $1)
fi
echo ${hash:0:10} # return the first 10 hex characters
fi
} }
compute_version () { compute_version () {
VERSION="$MAJOR.$MINOR.$PATCH+$CUSTOMER_LOCATION-$(compute_hash)" VERSION="$MAJOR.$MINOR.$PATCH+$CUSTOMER_LOCATION-$(compute_hash)"
cd_home; return 0
return 1
} }
check_sanity_of_repository () { check_sanity_of_repository () {
local func="${FUNCNAME[0]}" 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 assert_d CUSTOMER_ID_BASE_DIR
CUSTOMER_LOCATION_DIR="${CUSTOMER_ID_BASE_DIR}/${CUSTOMER_LOCATION}" CUSTOMER_LOCATION_DIR="$CUSTOMER_ID_BASE_DIR"
CUST_LOC_DIR=$CUSTOMER_LOCATION_DIR #CUSTOMER_LOCATION_DIR="${CUSTOMER_ID_BASE_DIR}/${CUSTOMER_LOCATION}"
#CUST_LOC_DIR=$CUSTOMER_LOCATION_DIR
assert_d CUSTOMER_LOCATION_DIR assert_d CUSTOMER_LOCATION_DIR
# readonly zone_groups=(${__zone_groups[@]}) # readonly zone_groups=(${__zone_groups[@]})
# by now (03.03.2023) there is only one zone group. # by now (03.03.2023) there is only one zone group.
readonly local __zgroup=1 #readonly local __zgroup=1
local __number_of_zone_groups=${ZONE_GROUPS[0]} #local __number_of_zone_groups=${ZONE_GROUPS[0]}
local __zindex=1 #local __zindex=1
local __customer_base_dirs=("placeholder") #local __customer_base_dirs=("placeholder")
for __zg in `seq 1 $__number_of_zone_groups`; do #for __zg in `seq 1 $__number_of_zone_groups`; do
local __n_of_zones=${ZONE_GROUPS[$__zindex]} # local __n_of_zones=${ZONE_GROUPS[$__zindex]}
log_debug "$func:${LINENO}: zgroup $__zg has $__n_of_zones zones" # log_debug "$func:${LINENO}: zgroup $__zg has $__n_of_zones zones"
for (( j=1; j<=$__n_of_zones; ++j)); do # for (( j=1; j<=$__n_of_zones; ++j)); do
__customer_base_dirs+=("${CUSTOMER_LOCATION_DIR}/$__zgroup/$j") # __customer_base_dirs+=("${CUSTOMER_LOCATION_DIR}/$__zgroup/$j")
log_debug "$func:${LINENO}: zone $j" # log_debug "$func:${LINENO}: zone $j"
((++__zindex)) # ((++__zindex))
done # done
done #done
# for szeged: # for szeged:
# placeholder # placeholder
# /home/root/szeged/UpdateController/workspace/customer_281/szeged/1/1 # /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/2
# /home/root/szeged/UpdateController/workspace/customer_281/szeged/1/3 # /home/root/szeged/UpdateController/workspace/customer_281/szeged/1/3
readonly CUST_BASE_DIRS=(${__customer_base_dirs[@]}) # readonly CUST_BASE_DIRS=(${__customer_base_dirs[@]})
assert_a CUST_BASE_DIRS # assert_a CUST_BASE_DIRS
# TODO # TODO
# TODO: falls mehrere gruppen/zonen auftauchen hier anpassen # TODO: falls mehrere gruppen/zonen auftauchen hier anpassen
@ -146,8 +153,9 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
# #
readonly ZONE_GROUP=1 readonly ZONE_GROUP=1
readonly ZONE=1 readonly ZONE=1
readonly CUST_BASE_DIR="${CUST_BASE_DIRS[$ZONE]}" readonly CUST_BASE_DIR="$CUSTOMER_ID_BASE_DIR"
assert_d CUST_BASE_DIR #readonly CUST_BASE_DIR="${CUST_BASE_DIRS[$ZONE]}"
#assert_d CUST_BASE_DIR
readonly ETC_SYS_DIR="/etc" readonly ETC_SYS_DIR="/etc"
readonly ATB_SYS_DIR="/etc/atb" readonly ATB_SYS_DIR="/etc/atb"
@ -224,7 +232,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
readonly SYSCTRL_SCF_PSA_INI_FILE="${SYSCONFIG_PSA_DIR}/$SYSCTRL_INI" readonly SYSCTRL_SCF_PSA_INI_FILE="${SYSCONFIG_PSA_DIR}/$SYSCTRL_INI"
readonly OPKG_CMDS_PSA_FILE="${OPKG_PSA_DIR}/opkg_commands" readonly OPKG_CMDS_PSA_FILE="${OPKG_PSA_DIR}/opkg_commands"
readonly TC_PSA_TC_FILE="${ATBAPP_PSA_DIR}/$TARIFF_CURRENT" readonly TC_PSA_TC_FILE="${ATBAPP_PSA_DIR}/$TARIFF_CURRENT"
readonly PSA_UPDATE_CONF="${CUSTOMER_LOCATION_DIR}/update.conf" # readonly PSA_UPDATE_CONF="${CUSTOMER_LOCATION_DIR}/update.conf"
readonly DC2C_PSA_SERIAL_JSON="${CONF_PSA_DIR}/DC2C_serial.json" 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_CASH_JSON="${CONF_PSA_DIR}/DC2C_cash.json"
readonly DC2C_PSA_CONF_JSON="${CONF_PSA_DIR}/DC2C_conf.json" readonly DC2C_PSA_CONF_JSON="${CONF_PSA_DIR}/DC2C_conf.json"
@ -291,7 +299,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
assert_f SYSCTRL_ATB_PSA_INI_FILE assert_f SYSCTRL_ATB_PSA_INI_FILE
assert_f SYSCTRL_SCF_PSA_INI_FILE assert_f SYSCTRL_SCF_PSA_INI_FILE
assert_f TC_PSA_TC_FILE assert_f TC_PSA_TC_FILE
assert_f PSA_UPDATE_CONF # assert_f PSA_UPDATE_CONF
assert_f OPKG_CMDS_PSA_FILE assert_f OPKG_CMDS_PSA_FILE
assert_f DC2C_PSA_CONF_JSON assert_f DC2C_PSA_CONF_JSON
assert_f DC2C_PSA_SERIAL_JSON assert_f DC2C_PSA_SERIAL_JSON
@ -336,8 +344,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
TARIFF_FILES_JSON+=($__f) TARIFF_FILES_JSON+=($__f)
done done
readonly KNOWN_CONF_FILES=(${CUSTOMER_LOCATION}/update.conf \ readonly KNOWN_CONF_FILES=(${DC2C_PRINT_JSON[@]##*${CUSTOMER_ID}/} \
${DC2C_PRINT_JSON[@]##*${CUSTOMER_ID}/} \
${DC2C_PSA_CONF_JSON##*${CUSTOMER_ID}/} \ ${DC2C_PSA_CONF_JSON##*${CUSTOMER_ID}/} \
${DC2C_PSA_CASH_JSON##*${CUSTOMER_ID}/} \ ${DC2C_PSA_CASH_JSON##*${CUSTOMER_ID}/} \
${DC2C_PSA_SERIAL_JSON##*${CUSTOMER_ID}/}) ${DC2C_PSA_SERIAL_JSON##*${CUSTOMER_ID}/})