defined new variables. started to capitalize global variables

This commit is contained in:
Gerhard Hoffmann 2022-06-03 21:47:55 +02:00
parent eb122ed51f
commit 43110e0cd7

View File

@ -6,58 +6,88 @@ source ./log_helpers
if [ ${read_config_sourced:-1} = "1" ]; then # include only once
readonly read_config_sourced=${BASH_SOURCE[0]}
readonly DATEFLAGS="+%Y.%m.%dT%H.%M.%S"
readonly STRIPCOMMENTS='sed -e s/#.*$//'
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
${WORKING_DIRECTORY:=$UPDATEPSAHOME}
${CONFIGFILENAME:=update_psa.conf}
if ! [ -f "$CONFIGFILENAME" ]; then
log_fatal "$func:${LINENO}: $CONFIGFILENAME not found"
fi
if [ -z "$WORKING_DIRECTORY" ]; then
log_fatal "$func:${LINENO}: WORKING_DIRECTORY not set in $cf"
fi
EXITCODE=0
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"
readonly GIT_SSL_NO_VERIFY="$(cat "$1" | jq -r .GIT_SSL_NO_VERIFY)"
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"
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 $1"
log_fatal "$func:${LINENO} GIT_SSL_NO_VERIFY not set in $cf"
fi
log_debug "$func:${LINENO}: GIT_SSL_NO_VERIFY=$GIT_SSL_NO_VERIFY"
log_debug "$func:${LINENO}: WORKSPACE_DIR=$WORKSPACE_DIR"
readonly working_directory="$(cat "$1" | jq -r .working_directory)"
if [ -z "$working_directory" ]; then
log_fatal "$func:${LINENO}: working_directory not set in $1"
readonly CUSTOMER_LOCATION=$(cat "$cf" | jq -r .customer_location)
if [ -z "$CUSTOMER_LOCATION" ]; then
log_fatal "$func:${LINENO}: CUSTOMER_LOCATION not set in $cf"
fi
log_debug "$func:${LINENO}: working_directory=$working_directory"
readonly workspace_dir="$(cat "$1" | jq -r .workspace_dir)"
if [ -z "$workspace_dir" ]; then
log_fatal "$func:${LINENO}: workspace_dir not set in $1"
fi
log_debug "$func:${LINENO}: workspace_dir=$workspace_dir"
readonly customer_location=$(cat "$1" | jq -r .customer_location)
if [ -z "$customer_location" ]; then
log_fatal "$func:${LINENO}: customer_location not set in $1"
fi
log_debug "$func:${LINENO}: customer-location=$customer_location"
log_debug "$func:${LINENO}: customer-location=$CUSTOMER_LOCATION"
readonly customer_id="customer_$(cat "$1" | jq -r .customer_id)"
if [ -z "$customer_id" ]; then
log_fatal "$func:${LINENO} customer_id not set in $1"
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
log_debug "$func:${LINENO}: customer-id=$customer_id"
readonly CUSTOMER_ID="customer_$CUST_ID"
log_debug "$func:${LINENO}: CUSTOMER-ID=$CUSTOMER_ID"
local __r_path="$(cat "$1" | jq -r .cust_repository_path)"
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 $1"
log_fatal "$func:${LINENO}: customer repository path not set in $cf"
fi
readonly customer_repository_path="${__r_path}/${customer_id}.git"
log_debug "$func:${LINENO}: customer r-path=$customer_repository_path"
readonly CUSTOMER_REPOSITORY_PATH="${__r_path}/${CUSTOMER_ID}.git"
log_debug "$func:${LINENO}: customer r-path=$CUSTOMER_REPOSITORY_PATH"
readonly number_of_zone_groups="$(cat "$1" | jq -r .zone_group[0])"
readonly number_of_zone_groups="$(cat "$cf" | jq -r .zone_group[0])"
log_debug "$func:${LINENO}: $number_of_zone_groups zone_group(s)"
local __zone_groups=(0)
for zg in `seq 1 $number_of_zone_groups`; do
local __n_zones="$(cat "$1" | jq -r .zone_group[$zg].zone[0])"
local __n_zones="$(cat "$cf" | jq -r .zone_group[$zg].zone[0])"
__zone_groups[$zg]=$__n_zones
done
log_debug "$func:${LINENO}: reading ${1} done"
log_debug "$func:${LINENO}: reading ${wd} done"
return 0
}
@ -67,24 +97,24 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
check_sanity_of_repository () {
local func="${FUNCNAME[0]}"
local __customer_base_dir="$working_directory/${workspace_dir}"
__customer_base_dir="${__customer_base_dir}/${customer_id}"
local __customer_base_dir="$WORKING_DIRECTORY/${WORKSPACE_DIR}"
__customer_base_dir="${__customer_base_dir}/${CUSTOMER_ID}"
readonly customer_id_base_dir=${__customer_base_dir}
log_debug "$func:${LINENO}: customer_id_base_dir="
log_debug "$func:${LINENO}: $customer_id_base_dir"
readonly CUSTOMER_ID_BASE_DIR=${__customer_base_dir}
log_debug "$func:${LINENO}: CUSTOMER_ID_BASE_DIR="
log_debug "$func:${LINENO}: $CUSTOMER_ID_BASE_DIR"
__customer_base_dir="${__customer_base_dir}/${customer_location}"
__customer_base_dir="${__customer_base_dir}/${CUSTOMER_LOCATION}"
readonly customer_location_dir="$__customer_base_dir"
log_debug "$func:${LINENO}: customer_location_dir="
log_debug "$func:${LINENO}: $customer_location_dir"
readonly CUSTOMER_LOCATION_DIR="$__customer_base_dir"
log_debug "$func:${LINENO}: CUSTOMER_LOCATION_DIR="
log_debug "$func:${LINENO}: $CUSTOMER_LOCATION_DIR"
readonly update_conf="${customer_location_dir}/update.conf"
log_debug "$func:${LINENO}: update.conf="
log_debug "$func:${LINENO}: $update_conf"
readonly UPDATE_CONF="${CUSTOMER_LOCATION_DIR}/update.conf"
log_debug "$func:${LINENO}: UPDATE.CONF="
log_debug "$func:${LINENO}: $UPDATE_CONF"
readonly current_conf="${customer_location_dir}/current.conf"
readonly current_conf="${CUSTOMER_LOCATION_DIR}/current.conf"
log_debug "$func:${LINENO}: current.conf="
log_debug "$func:${LINENO}: $current_conf"
@ -224,24 +254,30 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
else
log_fatal "$func:${LINENO}: $opkg_cmds_file does not exist"
fi
readonly known_files=(${customer_location}/update.conf \
${customer_location}/current.conf \
${device_conf##*${customer_id}/} \
${emp_conf##*${customer_id}/} \
${printer_conf##*${customer_id}/} \
${opkg_cmds_file##*${customer_id}/} \
${atbqt_ini##*${customer_id}/} \
${ismasmgr_ismasmgr_ini##*${customer_id}/} \
${sysconfig_ismasmgr_ini##*${customer_id}/} \
${sysconfig_sysconfig_ini##*${customer_id}/} \
${sysconfig_sysctrl_ini##*${customer_id}/})
log_debug "$func:${LINENO}: conf/ini_files=$(echo ${known_files[@]})"
log_debug "$func:${LINENO}: sanity of ${customer_repository_path} OK"
readonly KNOWN_CONF_FILES=(${CUSTOMER_LOCATION}/update.conf \
${CUSTOMER_LOCATION}/current.conf \
${device_conf##*${CUSTOMER_ID}/} \
${emp_conf##*${CUSTOMER_ID}/} \
${printer_conf##*${CUSTOMER_ID}/})
readonly KNOWN_INI_FILES=(${atbqt_ini##*${CUSTOMER_ID}/} \
${ismasmgr_ismasmgr_ini##*${CUSTOMER_ID}/} \
${sysconfig_ismasmgr_ini##*${CUSTOMER_ID}/} \
${sysconfig_sysconfig_ini##*${CUSTOMER_ID}/}\
${sysconfig_sysctrl_ini##*${CUSTOMER_ID}/})
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
log_debug "$func:${LINENO}: \t\t ${KNOWN_FILES[$i]}"
done
log_debug "$func:${LINENO}: sanity of ${CUSTOMER_REPOSITORY_PATH} OK"
return 0
}
# read_config UpdateController.conf
fi