293 lines
11 KiB
Bash
Executable File
293 lines
11 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
|
|
|
|
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="12345abc"
|
|
# 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 UPDATE_CONF="${CUSTOMER_LOCATION_DIR}/update.conf"
|
|
assert_f UPDATE_CONF
|
|
|
|
readonly DC="dc2c.hex"
|
|
readonly DC_SYS_DIR="/etc/dc"
|
|
readonly DC_SYS_DC_FULL="${DC_SYS_DIR}/$DC"
|
|
assert_d DC_SYS_DIR
|
|
assert_f DC_SYS_DC_FULL
|
|
|
|
readonly DC_DIR="${CUSTOMER_LOCATION_DIR}/dc"
|
|
readonly DC_FULL="${DC_DIR}/$DC"
|
|
assert_d DC_DIR
|
|
assert_f DC_FULL
|
|
|
|
# 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
|
|
|
|
readonly CUSTOMER_BASE_DIRS=(${__customer_base_dirs[@]})
|
|
assert_a CUSTOMER_BASE_DIRS
|
|
|
|
# TODO
|
|
# TODO: falls mehrere gruppen/zonen auftauchen hier anpassen
|
|
# TODO
|
|
readonly ZONE=1
|
|
readonly CUSTOMER_BASE_DIR="${CUSTOMER_BASE_DIRS[$ZONE]}"
|
|
assert_d CUSTOMER_BASE_DIR
|
|
|
|
readonly PSA_CONFIG_DIR="${CUSTOMER_BASE_DIR}/etc/psa_config"
|
|
assert_d PSA_CONFIG_DIR
|
|
|
|
readonly PSA_UPDATE_DIR="${CUSTOMER_BASE_DIR}/etc/psa_update"
|
|
assert_d PSA_UPDATE_DIR
|
|
|
|
readonly ATB_SYS_DIR="/etc/atb"
|
|
assert_d ATB_SYS_DIR
|
|
|
|
readonly PSA_ATB_SYS_DIR="${CUSTOMER_BASE_DIR}${ATB_SYS_DIR}"
|
|
assert_d PSA_ATB_SYS_DIR
|
|
|
|
readonly PSA_BASE_INI_DIR="${CUSTOMER_BASE_DIR}/opt/app"
|
|
assert_d PSA_BASE_INI_DIR
|
|
|
|
readonly SYSCONFIG_SYS_DIR="/opt/app/sysconfig"
|
|
assert_d SYSCONFIG_SYS_DIR
|
|
|
|
readonly PSA_SYSCONFIG_DIR="${CUSTOMER_BASE_DIR}${SYSCONFIG_SYS_DIR}"
|
|
assert_d PSA_SYSCONFIG_DIR
|
|
|
|
readonly PSA_ISMASMGR_DIR="${PSA_BASE_INI_DIR}/ISMASMgr"
|
|
assert_d PSA_ISMASMGR_DIR
|
|
|
|
readonly CONF_SYS_DIR="/etc/psa_config"
|
|
assert_d CONF_SYS_DIR
|
|
|
|
readonly OPKG_SYS_DIR="/etc/psa_update"
|
|
assert_d OPKG_SYS_DIR
|
|
|
|
readonly ATBAPP_SYS_DIR="/opt/app/ATBAPP"
|
|
assert_d ATBAPP_SYS_DIR
|
|
|
|
readonly PSA_ATBQT_DIR="$CUSTOMER_BASE_DIR$ATBAPP_SYS_DIR"
|
|
assert_d PSA_ATBQT_DIR
|
|
|
|
readonly TARIFF_CURRENT="tariff.current"
|
|
readonly TARIFF_CURRENT_FULL="${PSA_ATBQT_DIR}/$TARIFF_CURRENT"
|
|
assert_f TARIFF_CURRENT_FULL
|
|
|
|
readonly ATBQT_INI="ATBQT.ini"
|
|
readonly ATBQT_INI_FULL="${PSA_ATBQT_DIR}/$ATBQT_INI"
|
|
assert_f ATBQT_INI_FULL
|
|
|
|
readonly ATBQT="ATBQT"
|
|
readonly ATBQT_SYS_FULL="${ATBAPP_SYS_DIR}/$ATBQT"
|
|
assert_f ATBQT_SYS_FULL
|
|
|
|
readonly ISMASMGR_INI="ISMASMgr.ini"
|
|
readonly ISMASMGR_SYS_DIR="/opt/app/ISMASMgr"
|
|
assert_d ISMASMGR_SYS_DIR
|
|
|
|
readonly ISMASMGR_ISMASMGR_INI_FULL="${PSA_ISMASMGR_DIR}/$ISMASMGR_INI"
|
|
assert_f ISMASMGR_ISMASMGR_INI_FULL
|
|
|
|
readonly SYSCONFIG_ISMASMGR_INI_FULL="${PSA_SYSCONFIG_DIR}/ISMASMgr.ini"
|
|
assert_f SYSCONFIG_ISMASMGR_INI_FULL
|
|
|
|
readonly ATB_ISMASMGR_INI_FULL="${PSA_ATB_SYS_DIR}/$ISMASMGR_INI"
|
|
assert_f ATB_ISMASMGR_INI_FULL
|
|
|
|
readonly SYS_CONFIG_INI="sysconfig.ini"
|
|
readonly __sysc_sysc_full="${PSA_SYSCONFIG_DIR}/$SYS_CONFIG_INI"
|
|
readonly SYSCONFIG_SYSCONFIG_INI_FULL="$__sysc_sysc_full"
|
|
assert_f SYSCONFIG_SYSCONFIG_INI_FULL
|
|
|
|
readonly ATB_SYSCONFIG_INI_FULL="${PSA_ATB_SYS_DIR}/$SYS_CONFIG_INI"
|
|
assert_f ATB_SYSCONFIG_INI_FULL
|
|
|
|
readonly "SYSTEM_CONTROL_INI"="SystemControl.ini"
|
|
local __sysctrl_ini_full="${PSA_SYSCONFIG_DIR}/$SYSTEM_CONTROL_INI"
|
|
readonly SYSCONFIG_SYSCTRL_INI_FULL="$__sysctrl_ini_full"
|
|
assert_f SYSCONFIG_SYSCTRL_INI_FULL
|
|
|
|
readonly ATB_SYSCTRL_INI_FULL="${PSA_ATB_SYS_DIR}/$SYSTEM_CONTROL_INI"
|
|
assert_f ATB_SYSCTRL_INI_FULL
|
|
|
|
readonly ATB_ATBQT_INI_FULL="${PSA_ATB_SYS_DIR}/$ATBQT_INI"
|
|
assert_f ATB_ATBQT_INI_FULL
|
|
|
|
readonly DC2C_SERIAL_JSON="${PSA_CONFIG_DIR}/DC2C_serial.json"
|
|
assert_f DC2C_SERIAL_JSON
|
|
|
|
readonly DC2C_CASH_JSON="${PSA_CONFIG_DIR}/DC2C_cash.json"
|
|
assert_f DC2C_CASH_JSON
|
|
|
|
readonly DC2C_CONF_JSON="${PSA_CONFIG_DIR}/DC2C_conf.json"
|
|
assert_f DC2C_CONF_JSON
|
|
|
|
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)
|
|
assert_f DC2C_PRINT$(printf "%02d" $i)_JSON
|
|
DC2C_PRINT_JSON+=($__f)
|
|
done
|
|
|
|
readonly OPKG_CMDS_FILE="${PSA_UPDATE_DIR}/opkg_commands"
|
|
assert_f OPKG_CMDS_FILE
|
|
|
|
# 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}/} \
|
|
${SYSCONFIG_SYSCTRL_INI_FULL##*${CUSTOMER_ID}/} \
|
|
${ATB_ISMASMGR_INI_FULL##*${CUSTOMER_ID}/} \
|
|
${ATB_SYSCONFIG_INI_FULL##*${CUSTOMER_ID}/} \
|
|
${ATB_SYSCTRL_INI_FULL##*${CUSTOMER_ID}/} \
|
|
${ATB_ATBQT_INI_FULL##*${CUSTOMER_ID}/})
|
|
|
|
readonly KNOWN_FILES=(${KNOWN_CONF_FILES[@]} \
|
|
${KNOWN_INI_FILES[@]} \
|
|
${OPKG_CMDS_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
|
|
|
|
|