Compare commits
No commits in common. "54ad30752ec61c6ec53c6df5cfc819d11cafd864" and "7d9fc7cb2300f13bbf3ab1fce743fb35eb394fd4" have entirely different histories.
54ad30752e
...
7d9fc7cb23
@ -3,10 +3,7 @@
|
||||
|
||||
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]}"
|
||||
log_debug "$func:${LINENO} exec-ing [$*]"
|
||||
|
||||
@ -30,34 +27,23 @@ if [ "${general_utils_sourced:-1}" = "1" ]; then # include only once
|
||||
log_debug "$func:${LINENO} result=$__result"
|
||||
printf '%s' "$__result"
|
||||
return $__result_code
|
||||
}
|
||||
}
|
||||
|
||||
usage () {
|
||||
usage () {
|
||||
echo "Usage: $PROGRAM [--file config] [--?] [--help] [--version] [--dbg]"
|
||||
# UpdateController.conf"
|
||||
}
|
||||
}
|
||||
|
||||
usage_and_exit () {
|
||||
usage_and_exit () {
|
||||
usage
|
||||
exit $1
|
||||
}
|
||||
}
|
||||
|
||||
version () {
|
||||
version () {
|
||||
echo "$PROGRAM version $VERSION"
|
||||
}
|
||||
}
|
||||
|
||||
error () {
|
||||
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
|
||||
}
|
||||
fi
|
||||
}
|
||||
|
22
git_helpers
22
git_helpers
@ -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,22 +147,12 @@ pull_customer_repository () {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 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.
|
||||
# [...]
|
||||
# see 'man -Pless\ +/parameter/pattern/string/bash'
|
||||
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
|
||||
@ -247,8 +237,6 @@ 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
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
# set -x
|
||||
|
||||
if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
|
||||
if [ ${log_helpers_sourced:-1} = "1" ]; then # include ony once
|
||||
readonly log_helpers_sourced=${BASH_SOURCE[0]}
|
||||
|
||||
readonly log_file=/var/log/update_controller.log
|
||||
|
108
read_config
108
read_config
@ -29,7 +29,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
||||
fi
|
||||
log_debug "$func:${LINENO}: workspace_dir=$working_dir"
|
||||
|
||||
readonly customer_location=$(cat "$1" | jq -r .customer_location)
|
||||
local 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,15 +57,9 @@ 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}"
|
||||
@ -92,136 +86,38 @@ 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}"
|
||||
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 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"
|
||||
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
|
||||
|
||||
log_debug "$func:${LINENO}: sanity of ${customer_repository_path} OK"
|
||||
|
||||
# FIXME: die "ini"-files fehlen noch
|
||||
return 0
|
||||
}
|
||||
# read_config UpdateController.conf
|
||||
|
@ -207,7 +207,6 @@ 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
|
||||
|
@ -36,21 +36,17 @@ copy () {
|
||||
|
||||
readarray -td' ' files <<< "$1"
|
||||
for f in ${files[@]}; do
|
||||
if [ "$f" = "update.conf" ] || [ "$f" = "current.conf" ]; then
|
||||
continue
|
||||
fi
|
||||
if grep -qE "^.*[.]conf\s*$" <<< ${f}; then
|
||||
if grep -qE "^.*[.]conf.*$" <<< ${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\s*$" <<< ${f}; then
|
||||
# TODO
|
||||
set -x
|
||||
:
|
||||
set +x
|
||||
# elif grep -qE "^.*[.]ini.*$" <<< ${f}; then
|
||||
# if ! cp ${f} $psa_ini; then
|
||||
# return 1
|
||||
# fi
|
||||
fi
|
||||
done
|
||||
|
||||
@ -60,83 +56,46 @@ 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
|
||||
if grep -qE "^.*[.](conf|ini)\s*$" <<< $f; then
|
||||
if [ -z $__system_files ]; then
|
||||
__system_files="${f}"
|
||||
else
|
||||
__system_files="$__system_files ${f}"
|
||||
fi
|
||||
fi
|
||||
case "$f" in
|
||||
("emp.conf"|"printer.conf"|"device.conf")
|
||||
__system_files+="${f} "
|
||||
;;
|
||||
esac
|
||||
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 js_key="" # used by json-parser 'jq'
|
||||
local json_key=""
|
||||
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
|
||||
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)"
|
||||
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}')"
|
||||
elif [ "$file" = "printer.conf" ]; then
|
||||
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)"
|
||||
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}')"
|
||||
elif [ "$file" = "device.conf" ]; then
|
||||
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)
|
||||
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}')"
|
||||
else
|
||||
continue
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user