Compare commits

...

7 Commits

6 changed files with 254 additions and 82 deletions

View File

@ -3,6 +3,9 @@
source ./log_helpers source ./log_helpers
if [ "${general_utils_sourced:-1}" = "1" ]; then # include only once
readonly general_utils_sourced=${BASH_SOURCE[0]}
exec_process_substitution () { exec_process_substitution () {
local func="${FUNCNAME[0]}" local func="${FUNCNAME[0]}"
log_debug "$func:${LINENO} exec-ing [$*]" log_debug "$func:${LINENO} exec-ing [$*]"
@ -47,3 +50,14 @@ error () {
echo "$@" 1>&2 echo "$@" 1>&2
usage_and_exit 1 usage_and_exit 1
} }
alert () {
# usage: alert <$?> <object>
if [ "$1" ne 0 ]; then
echo "WARNING: $2 did not complete successfully." >&2
exit 1
else
echo "INFO: $2 completed successfully" >&2
fi
}
fi

View File

@ -62,14 +62,14 @@ revert_to_commit_before_pull () {
clone_customer_repository () { clone_customer_repository () {
local func="${FUNCNAME[0]}" local func="${FUNCNAME[0]}"
if [ "$PWD" = "$working_directory" ]; then if [ "$PWD" = "$working_directory" ]; then
if ! [[ -d $workspace_dir ]]; then if ! [[ -d "./$workspace_dir" ]]; then
{ mkdir -p ./$workspace_dir; } { mkdir -p ./$workspace_dir; }
fi fi
# check if the directory is empty. If so, clone the # check if the directory is empty. If so, clone the
# customer repository # customer repository
if ! find ./$workspace_dir -mindepth 1 -maxdepth 1 | read; then if ! find ./$workspace_dir -mindepth 1 -maxdepth 1 | read; then
log_debug "$func:${LINENO} cloning ${1} ..." log_debug "$func:${LINENO} cloning ${1} ..."
if { cd ./$workspace_dir ; }; then if { cd "./$workspace_dir" ; }; then
$(exec_git_command git clone "$1") $(exec_git_command git clone "$1")
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
log_debug "$func:${LINENO} cloning ${1} done" log_debug "$func:${LINENO} cloning ${1} done"
@ -80,7 +80,7 @@ clone_customer_repository () {
else else
# the directory is not empty, so we assume the # the directory is not empty, so we assume the
# customer-repository has been cloned already # customer-repository has been cloned already
if ! [[ -d ./${workspace_dir}/$customer_id ]]; then if ! [[ -d "./${workspace_dir}/$customer_id" ]]; then
log_fatal "$func:${LINENO} "\ log_fatal "$func:${LINENO} "\
"wrong repository: $(ls -d './${workspace_dir}/*')" "wrong repository: $(ls -d './${workspace_dir}/*')"
else else
@ -147,12 +147,22 @@ pull_customer_repository () {
return 1 return 1
fi fi
# see 'man -Pless\ +/parameter/pattern/string/bash' # see https://www.gnu.org/
# software/bash/manual/html_node/Shell-Parameter-Expansion.html
# [...]
#
# ${parameter//pattern/string}
#
# If there are two slashes separating parameter and pattern (...),
# all matches of pattern are replaced with string.
#
# If the expansion of string is null, matches of pattern are deleted.
# [...]
git_result=${git_result//[$'\r\n\t']/ } git_result=${git_result//[$'\r\n\t']/ }
log_debug "$func:${LINENO} git-pull-result=${git_result}" log_debug "$func:${LINENO} git-pull-result=${git_result}"
if grep -qE "^Already\s+\up\s+\to\s+date.*$" <<< $git_result; then if grep -qE "^Already\s+\up\s+\to\s+date.*$" <<< "$git_result"; then
log_warn "$func:${LINENO}: repository $PWD already up to date." log_warn "$func:${LINENO}: repository $PWD already up to date."
read $1 <<< 'yes' read $1 <<< 'yes'
cd_home ; return 1 cd_home ; return 1
@ -237,6 +247,8 @@ changed_file_names () {
local file_names="" local file_names=""
local known_files=(update.conf current.conf emp.conf) local known_files=(update.conf current.conf emp.conf)
known_files=(${known_files[@]} device.conf printer.conf opkg_commands) known_files=(${known_files[@]} device.conf printer.conf opkg_commands)
known_files=(${known_files[@]} ATBQT.ini sysconfig.ini ISMASMgr.ini)
known_files=(${known_files[@]} SystemControl.ini)
for f in ${known_files[@]} ; do for f in ${known_files[@]} ; do
if grep -qE ".*/${f}\s+.*" <<< $git_res; then if grep -qE ".*/${f}\s+.*" <<< $git_res; then
if ! [ -z $file_names ]; then if ! [ -z $file_names ]; then

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# set -x # set -x
if [ ${log_helpers_sourced:-1} = "1" ]; then # include ony once if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
readonly log_helpers_sourced=${BASH_SOURCE[0]} readonly log_helpers_sourced=${BASH_SOURCE[0]}
readonly log_file=/var/log/update_controller.log readonly log_file=/var/log/update_controller.log

View File

@ -29,7 +29,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
fi fi
log_debug "$func:${LINENO}: workspace_dir=$working_dir" log_debug "$func:${LINENO}: workspace_dir=$working_dir"
local customer_location=$(cat "$1" | jq -r .customer_location) readonly customer_location=$(cat "$1" | jq -r .customer_location)
if [ -z "$customer_location" ]; then if [ -z "$customer_location" ]; then
log_fatal "$func:${LINENO}: customer_location not set in $1" log_fatal "$func:${LINENO}: customer_location not set in $1"
fi fi
@ -57,9 +57,15 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
__zone_groups[$zg]=$__n_zones __zone_groups[$zg]=$__n_zones
done done
log_debug "$func:${LINENO}: reading ${1} done"
return 0
}
############################################################################### ###############################################################################
########################## parsing with jq finished ########################### ########################## parsing with jq finished ###########################
############################################################################### ###############################################################################
check_sanity_of_repository () {
local func="${FUNCNAME[0]}"
local __customer_base_dir="$working_directory/${workspace_dir}" local __customer_base_dir="$working_directory/${workspace_dir}"
__customer_base_dir="${__customer_base_dir}/${customer_id}" __customer_base_dir="${__customer_base_dir}/${customer_id}"
@ -86,38 +92,136 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
readonly zgroup=1 readonly zgroup=1
readonly zone=1 readonly zone=1
readonly customer_base_dir="${__customer_base_dir}/${zgroup}/${zone}" 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="
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" 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="
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" 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="
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" 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="
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 psa_sysconfig_dir="${psa_base_ini_dir}/sysconfig"
# 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 psa_atbqt_dir="${psa_base_ini_dir}/ATBQT"
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="${psa_atbqt_dir}/ATBQT.ini"
if [ -f "$atbqt_ini" ]; then
log_debug "$func:${LINENO}: ATBTQT.ini="
log_debug "$func:${LINENO}: $atbqt_ini"
else
log_fatal "$func:${LINENO}: $atbqt_ini does not exist"
fi
readonly ismasmgr_ismasmgr_ini="${psa_ismasmgr_dir}/ISMASMgr.ini"
if [ -f "$ismasmgr_ismasmgr_ini" ]; then
log_debug "$func:${LINENO}: ismasmgr_ismasmgr.ini="
log_debug "$func:${LINENO}: $ismasmgr_ismasmgr_ini"
else
log_fatal "$func:${LINENO}: $ismasmgr_ismasmgr_ini does not exist"
fi
readonly sysconfig_ismasmgr_ini="${psa_sysconfig_dir}/ISMASMgr.ini"
if [ -f "$sysconfig_ismasmgr_ini" ]; then
log_debug "$func:${LINENO}: sysconfig_ismasmgr.ini="
log_debug "$func:${LINENO}: $sysconfig_ismasmgr_ini"
else
log_fatal "$func:${LINENO}: $sysconfig_ismasmgr_ini does not exist"
fi
readonly sysconfig_sysconfig_ini="${psa_sysconfig_dir}/sysconfig.ini"
if [ -f "$sysconfig_sysconfig_ini" ]; then
log_debug "$func:${LINENO}: sysconfig_sysconfig.ini="
log_debug "$func:${LINENO}: $sysconfig_sysconfig_ini"
else
log_fatal "$func:${LINENO}: $sysconfig_sysconfig_ini does not exist"
fi
readonly sysconfig_sysctrl_ini="${psa_sysconfig_dir}/SystemControl.ini"
if [ -f "$sysconfig_sysctrl_ini" ]; then
log_debug "$func:${LINENO}: sysconfig_systemcontrol.ini="
log_debug "$func:${LINENO}: $sysconfig_sysctrl_ini"
else
log_fatal "$func:${LINENO}: $sysconfig_sysctrl_ini does not exist"
fi
readonly emp_conf="${psa_config_dir}/emp.conf" 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="
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" 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="
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" 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="
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" 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_commands="
log_debug "$func:${LINENO}: $opkg_cmds_file" log_debug "$func:${LINENO}: $opkg_cmds_file"
else
log_fatal "$func:${LINENO}: $opkg_cmds_file does not exist"
fi
log_debug "$func:${LINENO}: sanity of ${customer_repository_path} OK"
# FIXME: die "ini"-files fehlen noch
return 0 return 0
} }
# read_config UpdateController.conf # read_config UpdateController.conf

View File

@ -207,6 +207,7 @@ if ! [ -z "$config_filename" ]; then
if read_config "$config_filename" ; then if read_config "$config_filename" ; then
# set -x # set -x
if clone_customer_repository $customer_repository_path ; then if clone_customer_repository $customer_repository_path ; then
check_sanity_of_repository
update update
fi fi
fi fi

View File

@ -36,17 +36,21 @@ copy () {
readarray -td' ' files <<< "$1" readarray -td' ' files <<< "$1"
for f in ${files[@]}; do for f in ${files[@]}; do
if grep -qE "^.*[.]conf.*$" <<< ${f}; then if [ "$f" = "update.conf" ] || [ "$f" = "current.conf" ]; then
continue
fi
if grep -qE "^.*[.]conf\s*$" <<< ${f}; then
local __f="${psa_config_dir}/${f}" local __f="${psa_config_dir}/${f}"
if ! cp ${__f} /etc/psa_config; then if ! cp ${__f} /etc/psa_config; then
log_error "$func:${LINENO}: cannot cp ${__f} /etc/psa_config" log_error "$func:${LINENO}: cannot cp ${__f} /etc/psa_config"
return 1 return 1
fi fi
log_info "$func:${LINENO}: copied $f to /etc/psa_config" log_info "$func:${LINENO}: copied $f to /etc/psa_config"
# elif grep -qE "^.*[.]ini.*$" <<< ${f}; then elif grep -qE "^.*[.]ini\s*$" <<< ${f}; then
# if ! cp ${f} $psa_ini; then # TODO
# return 1 set -x
# fi :
set +x
fi fi
done done
@ -56,46 +60,83 @@ copy () {
filter_system_files () { filter_system_files () {
local func="${FUNCNAME[0]}" local func="${FUNCNAME[0]}"
log_debug "$func:${LINENO} $1"
readarray -td' ' files <<< "$1" readarray -td' ' files <<< "$1"
local __system_files="" local __system_files=""
for f in ${files[@]}; do for f in ${files[@]}; do
case "$f" in if grep -qE "^.*[.](conf|ini)\s*$" <<< $f; then
("emp.conf"|"printer.conf"|"device.conf") if [ -z $__system_files ]; then
__system_files+="${f} " __system_files="${f}"
;; else
esac __system_files="$__system_files ${f}"
fi
fi
done done
log_debug "$func:${LINENO} system-files=$__system_files" log_debug "$func:${LINENO} system-files=$__system_files"
printf '%s' "$__system_files" printf '%s' "$__system_files"
} }
#
md5_of () {
printf '%s' "$(md5sum "$1" | cut -d' ' -f1)"
}
# Check if the fetched/merged files have the correct md5 and are # Check if the fetched/merged files have the correct md5 and are
# valid for the PSA. # valid for the PSA.
# #
check_md5_for_changed_conf_and_ini_files () { check_md5_for_changed_conf_and_ini_files () {
local func="${FUNCNAME[0]}" local func="${FUNCNAME[0]}"
local json_key="" local js_key="" # used by json-parser 'jq'
local md5sum_update_conf="" local md5sum_update_conf=""
local md5sum_repository="" local md5sum_repository=""
local readonly cut_md5="cut -d' ' -f1"
log_debug "$func:${LINENO} files=$1" log_debug "$func:${LINENO} files=$1"
if ! [ -z $1 ]; then if ! [ -z $1 ]; then
readarray -td' ' files <<< "$1" readarray -td' ' files <<< "$1"
for file in ${files[@]}; do for file in ${files[@]}; do
log_debug "$func:${LINENO} file=$file"
if [ "$file" = "emp.conf" ]; then if [ "$file" = "emp.conf" ]; then
json_key=".conf.szeged.zg1.z1.etc.psa_config.emp" js_key=".conf.szeged.zg[1].z[1].etc.psa_config.emp"
md5sum_update_conf=$(cat $update_conf | jq -r $json_key) md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
md5sum_repository="$(md5sum $emp_conf | awk '{ print $1}')" md5sum_repository="$(md5_of $emp_conf)"
elif [ "$file" = "printer.conf" ]; then elif [ "$file" = "printer.conf" ]; then
json_key=".conf.szeged.zg1.z1.etc.psa_config.printer" js_key=".conf.szeged.zg[1].z[1].etc.psa_config.printer"
md5sum_update_conf=$(cat $update_conf | jq -r $json_key) md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
md5sum_repository="$(md5sum $printer_conf | awk '{ print $1}')" md5sum_repository="$(md5_of $printer_conf)"
elif [ "$file" = "device.conf" ]; then elif [ "$file" = "device.conf" ]; then
json_key=".conf.szeged.zg1.z1.etc.psa_config.device" js_key=".conf.szeged.zg[1].z[1].etc.psa_config.device"
md5sum_update_conf=$(cat $update_conf | jq -r $json_key) md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
md5sum_repository="$(md5sum $device_conf | awk '{ print $1}')" md5sum_repository="$(md5_of $device_conf)"
elif [ "$file" = "ATBQT.ini" ]; then
js_key=".ini.szeged.zg[1].z[1].opt.app.ATBQT.ATBQT"
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
md5sum_repository="$(md5_of $atbqt_ini)"
elif [ "$file" = "sysconfig.ini" ]; then
js_key=".ini.szeged.zg[1].z[1].opt.app.sysconfig.sysconfig"
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
md5sum_repository=$(md5_of $sysconfig_sysconfig_ini)
elif [ "$file" = "SystemControl.ini" ]; then
js_key=".ini.szeged.zg[1].z[1].opt.app.sysconfig.SystemControl"
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
md5sum_repository=$(md5_of $sysconfig_sysctrl_ini)
elif [ "$file" = "ISMASMgr.ini" ]; then
js_key=".ini.szeged.zg[1].z[1].opt.app.ISMASMgr.ISMASMgr"
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
md5sum_repository=$(md5_of $ismasmgr_ismasmgr_ini)
if [ "$md5sum_repository" = "$md5sum_update_conf" ]; then
log_info "$func:${LINENO}: md5sum for $file ok"
else
local __r="repository: $md5sum_repository"
local __u="update.conf=$md5sum_update_conf"
local __m="$__r != $__u"
log_error "$func:${LINENO}: md5sum for $file wrong: $__m"
return 1
fi
js_key=".ini.szeged.zg[1].z[1].opt.app.sysconfig.ISMASMgr"
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
md5sum_repository=$(md5_of $sysconfig_ismasmgr_ini)
else else
continue continue
fi fi