Compare commits

...

14 Commits

10 changed files with 493 additions and 275 deletions

View File

@ -6,6 +6,24 @@ source ./log_helpers
if [ "${general_utils_sourced:-1}" = "1" ]; then # include only once
readonly general_utils_sourced=${BASH_SOURCE[0]}
# compare two strings
equal () {
case "$1" in
"$2")
return 0
;;
esac
return 1 # they don't match
}
# check if second string is contained in first string
contains () {
if grep -qE "$2" <<< $1; then
return 0
fi
return 1 # not contained
}
exec_process_substitution () {
local func="${FUNCNAME[0]}"
log_debug "$func:${LINENO} exec-ing [$*]"

View File

@ -57,21 +57,32 @@ revert_to_commit_before_pull () {
}
# revert_to_commit_before_pull
# clone the customer repository in ./UpdateController/workspace.
# clone the customer repository in ./workspace.
# this is done only once.
#
# Cloning into 'customer_281'...
# remote: Enumerating objects: 1087, done.
# remote: Counting objects: 100% (1087/1087), done.
# remote: Compressing objects: 100% (946/946), done.
# remote: Total 1087 (delta 404), reused 0 (delta 0), pack-reused 0
# Receiving objects: 100% (1087/1087), 103.27 KiB | 873.00 KiB/s, done.
# Resoving deltas: 100% (410/410), done.
#
clone_customer_repository () {
local func="${FUNCNAME[0]}"
if [ "$PWD" = "$working_directory" ]; then
if ! [[ -d "./$workspace_dir" ]]; then
{ mkdir -p ./$workspace_dir; }
if [ "$PWD" = "$WORKING_DIRECTORY" ]; 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
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
CLONE_CUSTOMER_REPOSITORY=true
log_debug "$func:${LINENO} cloning ${1} done"
cd - ; return 0
fi
@ -80,11 +91,11 @@ 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
log_fatal "$func:${LINENO} "\
"wrong repository: $(ls -d './${workspace_dir}/*')"
if ! [[ -d "./${WORKSPACE_DIR}/$CUSTOMER_ID" ]]; then
log_fatal "$func:${LINENO} $PWD $WORKSPACE_DIR/$CUSTOMER_ID"\
"wrong repository: $(ls -d './${WORKSPACE_DIR}/*')"
else
local __m="./${workspace_dir}/$customer_id exists"
local __m="./${WORKSPACE_DIR}/$CUSTOMER_ID exists"
log_debug "$func:${LINENO} $__m"
return 0
fi
@ -96,12 +107,10 @@ clone_customer_repository () {
# https://git.mimbach49.de/GerhardHoffmann/customer_281.git
cd_customer_repository () {
# has to be called in ./UpdateController
local func="${FUNCNAME[0]}"
current_dir=${PWD##*/}
current_dir="./${current_dir:-/}"
if [ "$current_dir" = "./UpdateController" ]; then
repository_dir="./workspace/${customer_id}"
# has to be called in WORKING_DIRECTORY
if [ "$PWD" = "${WORKING_DIRECTORY}" ]; then
repository_dir="./$WORKSPACE_DIR/$CUSTOMER_ID"
if ! [[ -d "$repository_dir" ]]; then
log_crit "$func:${LINENO}: $repository_dir does not exist!"
return 1
@ -126,7 +135,6 @@ cd_home () {
}
pull_customer_repository () {
# has to be called in ./UpdateController
local func="${FUNCNAME[0]}"
if ! cd_customer_repository ; then
@ -245,7 +253,7 @@ changed_file_names () {
git_res=${git_res//[$'\r\n\t']/ }
log_debug "$func:${LINENO}: git_res=$git_res"
local file_names=""
for f in ${known_files[@]} ; do
for f in ${KNOWN_FILES[@]} ; do
if grep -qE ".*\s+${f}\s+.*" <<< $git_res; then
if ! [ -z $file_names ]; then
file_names="$f $file_names"

View File

@ -35,8 +35,8 @@ if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
sed -e 1d -i $log_file
fi
local msg="$(date +'%Y-%m-%d_%T'): $*"
printf "log:$msg\n" >&2
printf "$msg\n" >> $log_file
echo "log:$msg" >&2
echo "$msg" >> $log_file
}
log_debug() {

35
news_from_ismas Executable file
View File

@ -0,0 +1,35 @@
# !/bin/bash -
source ./log_helpers
if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
readonly APISM_DIRECT_PORT=7778
updates_available () {
local func="${FUNCNAME[0]}"
local json_response="$((echo -n '#M=APISM #C=REQ_ISMASParameter #J={}';
sleep 1) | nc localhost $APISM_DIRECT_PORT)"
if [ $? -eq 0 ]; then
local trigger="$(echo $json_response | jq -r .Fileupload.TRG)"
log_debug "$func:${LINENO}: apism_trigger=\"$trigger\""
grep -qE "WAIT" <<< "$trigger" && return 0
else
log_error "$func:${LINENO}: apism request failed"
fi
return 1
}
update_status () {
local func="${FUNCNAME[0]}"
local json_response="$((echo -n '#M=APISM #C=REQ_ISMASParameter #J={}';
sleep 1) | nc localhost $APISM_DIRECT_PORT)"
local trigger=""
if [ $? -eq 0 ]; then
trigger="$(echo $json_response | jq -r .Fileupload.TRG)"
log_debug "$func:${LINENO}: apism_trigger=\"$trigger\""
else
log_error "$func:${LINENO}: apism request failed"
fi
echo "$trigger"
}
fi

128
news_to_ismas Executable file
View File

@ -0,0 +1,128 @@
# !/bin/bash -
source ./log_helpers
if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
readonly APISM_DB_PORT=7777
news_to_ismas () {
local data="#M=APISM#C=CMD_EVENT#J=
{
\"REASON\":\"SW_UP\",
\"Timestamp\":\"$(date +%Y-%m-%dT%T.000%z)\",
\"EVENT\":\"$1\",
\"EVENTSTATE\":1,
\"PARAMETER\":\"Testdaten\"
}"
echo $((echo "$data"; sleep 1) | nc localhost $APISM_DB_PORT)
}
# WAIT
update_psa_activated () {
news_to_ismas "U0010"
return $?
}
# git pull
update_psa_pull_customer_repository () {
# text im PARAMETER?
news_to_ismas "U0011" "git pull customer repository"
return $?
}
update_psa_backup () {
news_to_ismas "U0011" "backup before update steps"
return $?
}
update_psa_check_hash_values () {
news_to_ismas "U0011" "checking file integrity"
return $?
}
update_psa_check_hardware_compatibility () {
news_to_ismas "U0011" "check hardware compatiblity"
return $?
}
# conf/ini files
update_psa_copy_files () {
news_to_ismas "U0011" "copy conf/ini-files"
return $?
}
# exec opkg-commands (dry-run)
update_psa_install_packages_dry_run () {
news_to_ismas "U0011" "install opkg-packages (dry-run)"
return $?
}
# exec opkg-commands
update_psa_install_packages () {
news_to_ismas "U0011" "install opkg-packages"
return $?
}
# remove backup in case of success
update_psa_cleanup () {
news_to_ismas "U0011" "cleanup"
return $?
}
update_psa_finished () {
news_to_ismas "U0012"
return $?
}
# results
update_psa_succeeded () {
news_to_ismas "U0001" "updates installed"
return $?
}
reset_update_trigger () {
news_to_ismas "U0002" "updates activated"
return $?
}
update_psa_canceled_no_updates_available () {
# text im PARAMETER?
news_to_ismas "U0003" # "No updates available, but 'WAIT' active. Missing check-in?"
return $?
}
update_psa_backup_failed () {
news_to_ismas "U0003" # "Backup failed"
return $?
}
update_psa_wrong_hash_values () {
news_to_ismas "U0003" # "Wrong hash value for file <xxx>. Missing check-in?"
return $?
}
update_psa_hardware_not_compatible () {
news_to_ismas "U0003" "conf/ini-file <xxx> and psa hardware <yyy> not compatible"
return $?
}
update_psa_opkg_command_failure () {
news_to_ismas "U0003" "opkg-command <xxx> failed"
return $?
}
update_psa_failed () {
news_to_ismas "U0003" "Unknown error"
return $?
}
# only for testing
set_updates_available () {
news_to_ismas "U0099"
return $?
}
set_update_active () {
reset_update_trigger
return $?
}
fi

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]}"
readonly GIT_SSL_NO_VERIFY="$(cat "$1" | jq -r .GIT_SSL_NO_VERIFY)"
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 $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"
log_debug "$func:${LINENO}: customer-location=$CUSTOMER_LOCATION"
readonly workspace_dir="$(cat "$1" | jq -r .workspace_dir)"
if [ -z "$workspace_dir" ]; then
log_fatal "$func:${LINENO}: workspace_dir 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}: workspace_dir=$workspace_dir"
readonly CUSTOMER_ID="customer_$CUST_ID"
log_debug "$func:${LINENO}: CUSTOMER-ID=$CUSTOMER_ID"
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"
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"
fi
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"
@ -225,23 +255,29 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
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}/})
readonly KNOWN_CONF_FILES=(${CUSTOMER_LOCATION}/update.conf \
${CUSTOMER_LOCATION}/current.conf \
${device_conf##*${CUSTOMER_ID}/} \
${emp_conf##*${CUSTOMER_ID}/} \
${printer_conf##*${CUSTOMER_ID}/})
log_debug "$func:${LINENO}: conf/ini_files=$(echo ${known_files[@]})"
log_debug "$func:${LINENO}: sanity of ${customer_repository_path} OK"
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

View File

@ -1,181 +1,38 @@
#!/bin/bash
# set -x
source ./general_utils
source ./log_helpers
source ./git_helpers
# source ./update_helpers.sh
# source ./opkg_helpers.sh
source ./update_psa_helpers
source ./read_config
###############################################################################
# update_psa
#
# Implementing the UpdateController (see below). UpdateController is waiting
# for an external trigger by the DeviceController (DC). The trigger is sent via
# an UNIX-pipe (=fifo). When DC triggers UpdateController, it has to check if
# an update is possible, i.e. is has to lock the PSA for the update procedure.
# UpdateController will send back the update-result to DeviceController
# which unlocks the PSA to return to nomal operation.
#
# If UpdateController has been triggered, it checks out a predefined git-
# repository. As a sanity check it makes sure that there are some changes in
# the repository. In case there are no changes, it issues an error message
# to DC and returns to its wait-state.
#
# Otherwise it checks if the changed files are correct (using md5) and if
# the new files are valid for the PSA. If there is some problem, it issues an
# error message to DC, reverts the git-repository to its previous state and
# returns to its wait-state.
#
# Otherwise it makes a backup of the current state of the PSA, and if there
# are opkg-packages to install it runs a dry installation process using opkg.
# In case of error, it issues an error message to DC, deletes the backup,
# reverts # the git-repository to its previous state and returns to its
# wait-state.
#
# Otherwise, it copies all new files to their target locations and in case
# of opkg-packages, it installs the packages.
#
# In case of error it restores the previous state using the backup and
# reinstalls the previous opkg-package(s). It issues an error message to
# DC and returns to its wait-state.
#
# Otherwise the update went well, and it does some cleanup, sends a success
# message to DC and returns to its wait-state.
#
#! /bin/bash -
# Implementing update functionality for an PSA.
###############################################################################
#
# UPDATE PROCEDURE
# UPDATE PSA
# Usage:
# update_psa [ --? ]
# [ --help ]
# [ --wdir "working_directory" ]
# [ --file "config_file" ]
# [ --dbg ]
# [ --version ]
#
# ./update_psa --file $PWD/update_psa.conf --wdir $PWD
#
###############################################################################
update() {
local try_update_count=0
local func="${FUNCNAME[0]}"
# read config parameters
# read_config
log_debug "$func:${LINENO}: fetch/merge updates..."
# Fetch new updates (using git)
while :
do
local repository_is_already_up_to_date=""
if ! fetch_customer_updates repository_is_already_up_to_date; then
if [ "$repository_is_already_up_to_date" = "yes" ]; then
log_error "$func:${LINENO}: $customer_id is up-to-date"\
"-> no files to update -> no psa update"
exit 1
fi
try_updates_count=$((try_updates_count+1))
if [[ "$try_updates_count" -eq 5 ]]; then
log_error "$func:${LINENO}: fetch/merging failed" ; exit 1
fi
sleep 60s
else
# Fetched updates successfully
try_updates_count=0
break
fi
done
# TODO: backup implementieren
# Backup before any updates in case some previous test was wrong
if ! backup_previous_version; then
log_error "$func:${LINENO}: backup failed"
revert_customer_repository ; exit 1
fi
local changed_files=$(changed_file_names)
local conf_ini_files=$(filter_conf_ini_files "$changed_files")
# check if *.conf and/or *.ini-files have to md5-sum as denoted
# in update.conf
if ! check_md5_for_changed_conf_and_ini_files "$conf_ini_files" ; then
log_error "$func:${LINENO}: new customer files wrong"
revert_customer_repository ; exit 1
fi
# copy *.conf and/or *.ini-files to their corresponding system-directories
if ! copy $conf_ini_files; then
log_error "$func:${LINENO}: copy operation failed"
revert_customer_repository ; exit 1
fi
# check if the opkg-command-file has been changed during 'git pull'
if grep -qE ".*opkg_commands.*?" <<< $changed_files; then
# read opkg_cmds: each line respresents an opkg-command
readarray opkg_commands < <(cat $opkg_cmds_file)
for opkg_c in "${opkg_commands[@]}"; do
if grep -qE "^\s*[#]+.*$" <<< $opkg_c; then
continue # found comment line
fi
# package manipulation commands without package:
local cwp="update|upgrade|clean"
# informational commands without package:
cwp="${cwp}|list|list-installed|list-upgradable"
if grep -qE "^.*\s+($cwp)\s+.*$" <<< $opkg_c; then
local p=$(printf '%s' "$opkg_c" | awk '{ print $NF }')
local opkg_output=()
if ! exec_opkg_info "$p" opkg_output; then
log_error "$func:${LINENO}: opkg info $opkg_c failed"
revert_customer_repository ; exit 1
fi
if ! check_md5_for_opkg_packages opkg_output; then
log_error "$func:${LINENO}: "\
"wrong md5sum for opkg packages"
revert_customer_repository ; exit 1
fi
fi
# perform a dry-run and check if everything might work as expected.
if ! exec_opkg_noaction $opkg_c; then
log_error "$func:${LINENO}: "\
"opkg --noaction $opkg_c failed"
fi
# Actually execute the opkg command
if ! exec_opkg $opkg_c; then
log_error "$func:${LINENO}: exec_opkg $opkg_c failed"
fallback_to_previous_version
revert_customer_repository ; exit 1
fi
done
else
log_info "$func:${LINENO}: no opkg commnds to execute"
fi
# Cleanup.
if ! cleanup_previous_version; then
log_error "$func:${LINENO}: cleanup_previous_version failed"
fi
log_info "$func:${LINENO}: success"
if [ $# -eq 0 ]; then
# no parameters given -> nothing to do
exit 0
}
###############################################################################
fi
if [ -z $IFS ]; then
IFS=$'\n'
fi
readonly PROGRAM=`basename $0`
readonly VERSION="0.8.0"
config_filename=""
# parse commandline parameters
while test $# -gt 0; do
case $1 in
--file | --fil | --fi | --f | -file | -fil | -fi | -f )
__conf_file=yes
shift
CONFIGFILENAME="$1"
;;
--wdir | --wdi | --wd | --w | -wdir | -wdi | -wd | -w )
shift
WORKING_DIRECTORY="$1"
;;
--help | -hel | --he | --h | '--?' | -help | -hel | -he | -h | '-?' )
usage_and_exit 0
@ -183,6 +40,7 @@ while test $# -gt 0; do
--version | --versio | --versi | --vers | --ver | --ve | --v | \
-version | -versio | -versi | -vers | -ver | -ve | -v )
version
exit 0
;;
--dbg | --db | --d | -dbg | -db | -d )
set_dbg_level $DEBUG
@ -191,26 +49,34 @@ while test $# -gt 0; do
error "Unrecognized option: $1"
;;
*)
if [ "$__conf_file" = "yes" ]; then
config_filename="$1"
__conf_file=""
else
error "Unrecognized parameter string: $1"
fi
break
;;
esac
shift
done
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
source ./update_psa_impl
if read_config
then
if clone_customer_repository $CUSTOMER_REPOSITORY_PATH
then
check_sanity_of_repository
# reset_update_trigger
# set_updates_available
# sleep 10
# if updates_available
# then
# update_psa_started
# sleep 5
# update_psa_in_progress
# sleep 5
# update_status
# fi
update_psa
fi
else
error "config-file missing"
fi
exit $EXIT_CODE
###############################################################################

View File

@ -2,12 +2,6 @@
"c1" : "use git without certificates",
"GIT_SSL_NO_VERIFY" : 1,
"c2" : "start in working_directory",
"working_directory" : "/home/root/szeged/UpdateController",
"c3" : "directory for customer repository",
"workspace_dir" : "workspace",
"c4" : "explicit location of customer-project",
"customer_location" : "szeged",

View File

@ -42,9 +42,9 @@ copy () {
fi
if grep -qE "^.*[.]conf\s*$" <<< ${f}; then
local __f=${f#*etc/}
if ! cp "${customer_id_base_dir}/${f}" "/etc/${__f}"; then
if ! cp "${CUSTOMER_ID_BASE_DIR}/${f}" "/etc/${__f}"; then
log_error "$func:${LINENO}: cannot "\
"cp ${customer_id_base_dir}/${f} /etc/${__f}"
"cp ${CUSTOMER_ID_BASE_DIR}/${f} /etc/${__f}"
return 1
fi
log_info "$func:${LINENO}: copied $f to /etc/${__f}"
@ -52,10 +52,10 @@ copy () {
# TODO: die anderen system-verzeichnisse werden gebraucht
local __f=${f#*opt/app/ATBAPP/}
if [ "$__f" = "ATBQT.ini" ]; then
if ! cp "${customer_id_base_dir}/${f}" /opt/app/ATBAPP/${__f}
if ! cp "${CUSTOMER_ID_BASE_DIR}/${f}" /opt/app/ATBAPP/${__f}
then
log_error "$func:${LINENO}: cannot "\
"cp ${customer_id_base_dir}/${f} /opt/app/ATBAPP/${__f}"
"cp ${CUSTOMER_ID_BASE_DIR}/${f} /opt/app/ATBAPP/${__f}"
return 1
fi
fi
@ -107,35 +107,35 @@ check_md5_for_changed_conf_and_ini_files () {
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_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository="$(md5_of $emp_conf)"
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_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository="$(md5_of $printer_conf)"
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_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.ATBAPP.ATBQT"
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
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_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_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository=$(md5_of $sysconfig_sysctrl_ini)
elif [[ "$file" =~ .*ISMASMgr/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_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository=$(md5_of $ismasmgr_ismasmgr_ini)
elif [[ "$file" =~ .*sysconfig/ISMASMgr[.]ini.* ]]; then
js_key=".ini.szeged.zg[1].z[1].opt.app.sysconfig.ISMASMgr"
md5sum_update_conf=$(cat $update_conf | jq -r $js_key)
md5sum_update_conf=$(cat $UPDATE_CONF | jq -r $js_key)
md5sum_repository=$(md5_of $sysconfig_ismasmgr_ini)
else
continue
@ -174,7 +174,7 @@ check_md5_for_opkg_packages () {
fi
done
local __update_conf="${customer_location_dir}/update.conf"
local __update_conf="${CUSTOMER_LOCATION_DIR}/update.conf"
md5sum_repo=$(cat $__update_conf | jq -r .opkg.${package}.MD5Sum)
if ! [ -z $md5sum_repo ]; then
if [ "$md5sum_opkg_info" = "$md5sum_repo" ]; then
@ -294,3 +294,13 @@ cleanup_previous_version() {
local func="${FUNCNAME[0]}"
return 0
}
check_for_apism () {
nc localhost 7778
if [ $? -eq 0 ]
then
return 0
fi
return 1
}

123
update_psa_impl Executable file
View File

@ -0,0 +1,123 @@
# !/bin/bash -
source ./general_utils
source ./log_helpers
source ./git_helpers
source ./update_psa_helpers
source ./read_config
source ./news_to_ismas
source ./news_from_ismas
update_psa() {
local try_update_count=0
local func="${FUNCNAME[0]}"
# read config parameters
# read_config
log_debug "$func:${LINENO}: fetch/merge updates..."
# Fetch new updates (using git)
while :
do
local repository_is_already_up_to_date=""
if ! fetch_customer_updates repository_is_already_up_to_date; then
if [ "$repository_is_already_up_to_date" = "yes" ]; then
log_error "$func:${LINENO}: $customer_id is up-to-date"\
"-> no files to update -> no psa update"
exit 1
fi
try_updates_count=$((try_updates_count+1))
if [[ "$try_updates_count" -eq 5 ]]; then
log_error "$func:${LINENO}: fetch/merging failed" ; exit 1
fi
sleep 60s
else
# Fetched updates successfully
try_updates_count=0
break
fi
done
# TODO: backup implementieren
# Backup before any updates in case some previous test was wrong
if ! backup_previous_version; then
log_error "$func:${LINENO}: backup failed"
revert_customer_repository ; exit 1
fi
# TODO: use CLONE_CUSTOMER_REPOSITORY=true
# d.h. wird das rep geklont, also neu angelegt, dann sind eigentlich alle
# dateinen zu ueberpruefen
local changed_files=$(changed_file_names)
local conf_ini_files=$(filter_conf_ini_files "$changed_files")
# check if *.conf and/or *.ini-files have to md5-sum as denoted
# in update.conf
if ! check_md5_for_changed_conf_and_ini_files "$conf_ini_files" ; then
log_error "$func:${LINENO}: new customer files wrong"
revert_customer_repository ; exit 1
fi
# copy *.conf and/or *.ini-files to their corresponding system-directories
if ! copy $conf_ini_files; then
log_error "$func:${LINENO}: copy operation failed"
revert_customer_repository ; exit 1
fi
# check if the opkg-command-file has been changed during 'git pull'
if grep -qE ".*opkg_commands.*?" <<< $changed_files; then
# read opkg_cmds: each line respresents an opkg-command
readarray opkg_commands < <(cat $opkg_cmds_file)
for opkg_c in "${opkg_commands[@]}"; do
if grep -qE "^\s*[#]+.*$" <<< $opkg_c; then
continue # found comment line
fi
# package manipulation commands without package:
local cwp="update|upgrade|clean"
# informational commands without package:
cwp="${cwp}|list|list-installed|list-upgradable"
if grep -qE "^.*\s+($cwp)\s+.*$" <<< $opkg_c; then
local p=$(printf '%s' "$opkg_c" | awk '{ print $NF }')
local opkg_output=()
if ! exec_opkg_info "$p" opkg_output; then
log_error "$func:${LINENO}: opkg info $opkg_c failed"
revert_customer_repository ; exit 1
fi
if ! check_md5_for_opkg_packages opkg_output; then
log_error "$func:${LINENO}: "\
"wrong md5sum for opkg packages"
revert_customer_repository ; exit 1
fi
fi
# perform a dry-run and check if everything might work as expected.
if ! exec_opkg_noaction $opkg_c; then
log_error "$func:${LINENO}: "\
"opkg --noaction $opkg_c failed"
fi
# Actually execute the opkg command
if ! exec_opkg $opkg_c; then
log_error "$func:${LINENO}: exec_opkg $opkg_c failed"
fallback_to_previous_version
revert_customer_repository ; exit 1
fi
done
else
log_info "$func:${LINENO}: no opkg commnds to execute"
fi
# Cleanup.
if ! cleanup_previous_version; then
log_error "$func:${LINENO}: cleanup_previous_version failed"
fi
log_info "$func:${LINENO}: success"
exit 0
}