Compare commits

..

7 Commits

6 changed files with 254 additions and 82 deletions

View File

@ -3,47 +3,61 @@
source ./log_helpers
exec_process_substitution () {
local func="${FUNCNAME[0]}"
log_debug "$func:${LINENO} exec-ing [$*]"
if [ "${general_utils_sourced:-1}" = "1" ]; then # include only once
readonly general_utils_sourced=${BASH_SOURCE[0]}
exec {fd}< <(eval "$@")
exec_process_substitution () {
local func="${FUNCNAME[0]}"
log_debug "$func:${LINENO} exec-ing [$*]"
local __result_code=$?
local ps_pid=$! # remember pid of process substitution
exec {fd}< <(eval "$@")
local __result=""
while read __tmp <&$fd; do
if ! [ -z "$__tmp" ]; then
__result="${__result}$__tmp"
local __result_code=$?
local ps_pid=$! # remember pid of process substitution
local __result=""
while read __tmp <&$fd; do
if ! [ -z "$__tmp" ]; then
__result="${__result}$__tmp"
fi
done
exec {fd}>&- # close fd (i.e. process substitution)
wait $ps_pid # wait for the subshell to finish
__result=${__result//[$'\r\n\t']/ } # remove \r\n\t from __result
log_debug "$func:${LINENO} result=$__result"
printf '%s' "$__result"
return $__result_code
}
usage () {
echo "Usage: $PROGRAM [--file config] [--?] [--help] [--version] [--dbg]"
# UpdateController.conf"
}
usage_and_exit () {
usage
exit $1
}
version () {
echo "$PROGRAM version $VERSION"
}
error () {
echo "$@" 1>&2
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
done
exec {fd}>&- # close fd (i.e. process substitution)
wait $ps_pid # wait for the subshell to finish
__result=${__result//[$'\r\n\t']/ } # remove \r\n\t from __result
log_debug "$func:${LINENO} result=$__result"
printf '%s' "$__result"
return $__result_code
}
usage () {
echo "Usage: $PROGRAM [--file config] [--?] [--help] [--version] [--dbg]"
# UpdateController.conf"
}
usage_and_exit () {
usage
exit $1
}
version () {
echo "$PROGRAM version $VERSION"
}
error () {
echo "$@" 1>&2
usage_and_exit 1
}
}
fi

View File

@ -62,14 +62,14 @@ revert_to_commit_before_pull () {
clone_customer_repository () {
local func="${FUNCNAME[0]}"
if [ "$PWD" = "$working_directory" ]; then
if ! [[ -d $workspace_dir ]]; then
if ! [[ -d "./$workspace_dir" ]]; then
{ mkdir -p ./$workspace_dir; }
fi
# check if the directory is empty. If so, clone the
# customer repository
if ! find ./$workspace_dir -mindepth 1 -maxdepth 1 | read; then
log_debug "$func:${LINENO} cloning ${1} ..."
if { cd ./$workspace_dir ; }; then
if { cd "./$workspace_dir" ; }; then
$(exec_git_command git clone "$1")
if [ $? -eq 0 ]; then
log_debug "$func:${LINENO} cloning ${1} done"
@ -80,7 +80,7 @@ clone_customer_repository () {
else
# the directory is not empty, so we assume the
# customer-repository has been cloned already
if ! [[ -d ./${workspace_dir}/$customer_id ]]; then
if ! [[ -d "./${workspace_dir}/$customer_id" ]]; then
log_fatal "$func:${LINENO} "\
"wrong repository: $(ls -d './${workspace_dir}/*')"
else
@ -147,12 +147,22 @@ pull_customer_repository () {
return 1
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']/ }
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."
read $1 <<< 'yes'
cd_home ; return 1
@ -237,6 +247,8 @@ changed_file_names () {
local file_names=""
local known_files=(update.conf current.conf emp.conf)
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
if grep -qE ".*/${f}\s+.*" <<< $git_res; then
if ! [ -z $file_names ]; then

View File

@ -1,7 +1,7 @@
#!/bin/bash
# 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_file=/var/log/update_controller.log

View File

@ -29,7 +29,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
fi
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
log_fatal "$func:${LINENO}: customer_location not set in $1"
fi
@ -57,9 +57,15 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
__zone_groups[$zg]=$__n_zones
done
log_debug "$func:${LINENO}: reading ${1} 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}"
@ -86,38 +92,136 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
readonly zgroup=1
readonly zone=1
readonly customer_base_dir="${__customer_base_dir}/${zgroup}/${zone}"
log_debug "$func:${LINENO}: customer-base-dir="
log_debug "$func:${LINENO}: $customer_base_dir"
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"
log_debug "$func:${LINENO}: psa_config_dir="
log_debug "$func:${LINENO}: $psa_config_dir"
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"
log_debug "$func:${LINENO}: psa_update_dir="
log_debug "$func:${LINENO}: $psa_update_dir"
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"
log_debug "$func:${LINENO}: psa_base_ini_dir="
log_debug "$func:${LINENO}: $psa_base_ini_dir"
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 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"
log_debug "$func:${LINENO}: emp.conf="
log_debug "$func:${LINENO}: $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"
log_debug "$func:${LINENO}: device.conf="
log_debug "$func:${LINENO}: $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"
log_debug "$func:${LINENO}: printer.conf="
log_debug "$func:${LINENO}: $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"
log_debug "$func:${LINENO}: opkg_commands="
log_debug "$func:${LINENO}: $opkg_cmds_file"
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
log_debug "$func:${LINENO}: sanity of ${customer_repository_path} OK"
# FIXME: die "ini"-files fehlen noch
return 0
}
# read_config UpdateController.conf

View File

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

View File

@ -36,17 +36,21 @@ copy () {
readarray -td' ' files <<< "$1"
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}"
if ! cp ${__f} /etc/psa_config; then
log_error "$func:${LINENO}: cannot cp ${__f} /etc/psa_config"
return 1
fi
log_info "$func:${LINENO}: copied $f to /etc/psa_config"
# elif grep -qE "^.*[.]ini.*$" <<< ${f}; then
# if ! cp ${f} $psa_ini; then
# return 1
# fi
elif grep -qE "^.*[.]ini\s*$" <<< ${f}; then
# TODO
set -x
:
set +x
fi
done
@ -56,46 +60,83 @@ copy () {
filter_system_files () {
local func="${FUNCNAME[0]}"
log_debug "$func:${LINENO} $1"
readarray -td' ' files <<< "$1"
local __system_files=""
for f in ${files[@]}; do
case "$f" in
("emp.conf"|"printer.conf"|"device.conf")
__system_files+="${f} "
;;
esac
if grep -qE "^.*[.](conf|ini)\s*$" <<< $f; then
if [ -z $__system_files ]; then
__system_files="${f}"
else
__system_files="$__system_files ${f}"
fi
fi
done
log_debug "$func:${LINENO} system-files=$__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
# valid for the PSA.
#
check_md5_for_changed_conf_and_ini_files () {
local func="${FUNCNAME[0]}"
local json_key=""
local js_key="" # used by json-parser 'jq'
local md5sum_update_conf=""
local md5sum_repository=""
local readonly cut_md5="cut -d' ' -f1"
log_debug "$func:${LINENO} files=$1"
if ! [ -z $1 ]; then
readarray -td' ' files <<< "$1"
for file in ${files[@]}; do
log_debug "$func:${LINENO} file=$file"
if [ "$file" = "emp.conf" ]; then
json_key=".conf.szeged.zg1.z1.etc.psa_config.emp"
md5sum_update_conf=$(cat $update_conf | jq -r $json_key)
md5sum_repository="$(md5sum $emp_conf | awk '{ print $1}')"
js_key=".conf.szeged.zg[1].z[1].etc.psa_config.emp"
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
md5sum_repository="$(md5_of $emp_conf)"
elif [ "$file" = "printer.conf" ]; then
json_key=".conf.szeged.zg1.z1.etc.psa_config.printer"
md5sum_update_conf=$(cat $update_conf | jq -r $json_key)
md5sum_repository="$(md5sum $printer_conf | awk '{ print $1}')"
js_key=".conf.szeged.zg[1].z[1].etc.psa_config.printer"
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
md5sum_repository="$(md5_of $printer_conf)"
elif [ "$file" = "device.conf" ]; then
json_key=".conf.szeged.zg1.z1.etc.psa_config.device"
md5sum_update_conf=$(cat $update_conf | jq -r $json_key)
md5sum_repository="$(md5sum $device_conf | awk '{ print $1}')"
js_key=".conf.szeged.zg[1].z[1].etc.psa_config.device"
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
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
continue
fi