UpdateController/read_config

300 lines
12 KiB
Bash
Executable File

#!/bin/bash
# set -x
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"
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 $cf"
fi
log_debug "$func:${LINENO}: GIT_SSL_NO_VERIFY=$GIT_SSL_NO_VERIFY"
log_debug "$func:${LINENO}: WORKSPACE_DIR=$WORKSPACE_DIR"
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}: customer-location=$CUSTOMER_LOCATION"
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
readonly CUSTOMER_ID="customer_$CUST_ID"
log_debug "$func:${LINENO}: CUSTOMER-ID=$CUSTOMER_ID"
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 $cf"
fi
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 "$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 "$cf" | jq -r .zone_group[$zg].zone[0])"
__zone_groups[$zg]=$__n_zones
done
log_debug "$func:${LINENO}: reading ${wd} done"
return 0
}
###############################################################################
########################## parsing with jq finished ###########################
###############################################################################
check_sanity_of_repository () {
local func="${FUNCNAME[0]}"
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"
__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 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"
log_debug "$func:${LINENO}: current.conf="
log_debug "$func:${LINENO}: $current_conf"
# readonly zone_groups=(${__zone_groups[@]})
# for (( j=0; j<${#zone_groups[@]}; ++j)); do
# log_debug "$func:${LINENO}: zgroup[$j]: ${zone_groups[$j]} zones"
# done
# TODO: falls mehrere gruppen/zonen auftauchen hier anpassen
readonly zgroup=1
readonly zone=1
readonly CUSTOMER_BASE_DIR="${__customer_base_dir}/${zgroup}/${zone}"
if [ -d "$CUSTOMER_BASE_DIR" ]; then
log_debug "$func:${LINENO}: customer-base-dir="
log_debug "$func:${LINENO}: $CUSTOMER_BASE_DIR"
else
log_fatal "$func:${LINENO}: $CUSTOMER_BASE_DIR does not exist"
fi
readonly psa_config_dir="${CUSTOMER_BASE_DIR}/etc/psa_config"
if [ -d "$psa_config_dir" ]; then
log_debug "$func:${LINENO}: psa_config_dir="
log_debug "$func:${LINENO}: $psa_config_dir"
else
log_fatal "$func:${LINENO}: $psa_config_dir does not exist"
fi
readonly psa_update_dir="${CUSTOMER_BASE_DIR}/etc/psa_update"
if [ -d "$psa_update_dir" ]; then
log_debug "$func:${LINENO}: psa_update_dir="
log_debug "$func:${LINENO}: $psa_update_dir"
else
log_fatal "$func:${LINENO}: $psa_update_dir does not exist"
fi
readonly psa_base_ini_dir="${CUSTOMER_BASE_DIR}/opt/app"
if [ -d "$psa_base_ini_dir" ]; then
log_debug "$func:${LINENO}: psa_base_ini_dir="
log_debug "$func:${LINENO}: $psa_base_ini_dir"
else
log_fatal "$func:${LINENO}: $psa_base_ini_dir does not exist"
fi
readonly SYSCONFIG_SYS_DIR="/opt/app/sysconfig"
readonly PSA_SYSCONFIG_DIR="$CUSTOMER_BASE_DIR$SYSCONFIG_SYS_DIR"
# if [ -d "$psa_syconfig_dir" ]; DOES NOT WORK !!!
if ls -al $PSA_SYSCONFIG_DIR > /dev/null; then
log_debug "$func:${LINENO}: PSA_SYSCONFIG_DIR="
log_debug "$func:${LINENO}: $PSA_SYSCONFIG_DIR"
else
log_error "$func:${LINENO}: $PSA_SYSCONFIG_DIR does not exist"
fi
readonly psa_ismasmgr_dir="${psa_base_ini_dir}/ISMASMgr"
if [ -d "$psa_ismasmgr_dir" ]; then
log_debug "$func:${LINENO}: psa_ismasmgr_dir="
log_debug "$func:${LINENO}: $psa_ismasmgr_dir"
else
log_fatal "$func:${LINENO}: $psa_ismasmgr_dir does not exist"
fi
readonly CONF_SYS_DIR="/etc/psa_config"
readonly OPKG_SYS_DIR="/etc/psa_update"
readonly ATBAPP_SYS_DIR="/opt/app/ATBAPP"
readonly psa_atbqt_dir="$CUSTOMER_BASE_DIR$ATBAPP_SYS_DIR"
if [ -d "$psa_atbqt_dir" ]; then
log_debug "$func:${LINENO}: psa_atbqt_dir="
log_debug "$func:${LINENO}: $psa_atbqt_dir"
else
log_fatal "$func:${LINENO}: $psa_atbqt_dir does not exist"
fi
readonly ATBQT_INI="ATBQT.ini"
readonly ATBQT_INI_FULL="${psa_atbqt_dir}/$ATBQT_INI"
if [ -f "$ATBQT_INI_FULL" ]; then
log_debug "$func:${LINENO}: ATBTQT.ini="
log_debug "$func:${LINENO}: $ATBQT_INI_FULL"
else
log_fatal "$func:${LINENO}: $ATBQT_INI_FULL does not exist"
fi
readonly ISMASMGR_INI="ISMASMgr.ini"
readonly ISMASMGR_SYS_DIR="/opt/app/ISMASMgr"
readonly ISMASMGR_ISMASMGR_INI_FULL="${psa_ismasmgr_dir}/$ISMASMGR_INI"
if [ -f "$ISMASMGR_ISMASMGR_INI_FULL" ]; then
log_debug "$func:${LINENO}: ismasmgr_ismasmgr.ini="
log_debug "$func:${LINENO}: $ISMASMGR_ISMASMGR_INI_FULL"
else
log_fatal "$func:${LINENO}: $ISMASMGR_ISMASMGR_INI_FULL "\
"does not exist"
fi
readonly SYSCONFIG_ISMASMGR_INI_FULL="${PSA_SYSCONFIG_DIR}/ISMASMgr.ini"
if [ -f "$SYSCONFIG_ISMASMGR_INI_FULL" ]; then
log_debug "$func:${LINENO}: sysconfig_ismasmgr.ini="
log_debug "$func:${LINENO}: $SYSCONFIG_ISMASMGR_INI_FULL"
else
log_fatal "$func:${LINENO}: $SYSCONFIG_ISMASMGR_INI_FULL "\
"does not exist"
fi
readonly SYS_CONFIG_INI="sysconfig.ini"
readonly __sysc_sysc_full="${PSA_SYSCONFIG_DIR}/$SYS_CONFIG_INI"
readonly SYSCONFIG_SYSCONFIG_INI_FULL="$__sysc_sysc_full"
if [ -f "$SYSCONFIG_SYSCONFIG_INI_FULL" ]; then
log_debug "$func:${LINENO}: sysconfig_sysconfig.ini="
log_debug "$func:${LINENO}: $SYSCONFIG_SYSCONFIG_INI_FULL"
else
log_fatal "$func:${LINENO}: "\
"$SYSCONFIG_SYSCONFIG_INI_FULL does not exist"
fi
readonly "SYSTEM_CONTROL_INI"="SystemControl.ini"
local __sysctrl_ini_full="${PSA_SYSCONFIG_DIR}/$SYSTEM_CONTROL_INI"
readonly SYSCONFIG_SYSCTRL_INI_FULL="$__sysctrl_ini_full"
if [ -f "$SYSCONFIG_SYSCTRL_INI_FULL" ]; then
log_debug "$func:${LINENO}: sysconfig_systemcontrol.ini="
log_debug "$func:${LINENO}: $SYSCONFIG_SYSCTRL_INI_FULL"
else
log_fatal "$func:${LINENO}: $SYSCONFIG_SYSCTRL_INI_FULL does not exist"
fi
readonly emp_conf="${psa_config_dir}/emp.conf"
if [ -f "$emp_conf" ]; then
log_debug "$func:${LINENO}: emp.conf="
log_debug "$func:${LINENO}: $emp_conf"
else
log_fatal "$func:${LINENO}: $emp_conf does not exist"
fi
readonly device_conf="${psa_config_dir}/device.conf"
if [ -f "$device_conf" ]; then
log_debug "$func:${LINENO}: device.conf="
log_debug "$func:${LINENO}: $device_conf"
else
log_debug "$func:${LINENO}: $device_conf does not exist"
fi
readonly printer_conf="${psa_config_dir}/printer.conf"
if [ -f "$printer_conf" ]; then
log_debug "$func:${LINENO}: printer.conf="
log_debug "$func:${LINENO}: $printer_conf"
else
log_fatal "$func:${LINENO}: $printer_conf does not exist"
fi
readonly opkg_cmds_file="${psa_update_dir}/opkg_commands"
if [ -f "$opkg_cmds_file" ]; then
log_debug "$func:${LINENO}: opkg_commands="
log_debug "$func:${LINENO}: $opkg_cmds_file"
else
log_fatal "$func:${LINENO}: $opkg_cmds_file does not exist"
fi
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_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}/})
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
}
fi