5 Commits

19 changed files with 260 additions and 2397 deletions

1
.gitignore vendored
View File

@@ -1 +0,0 @@
workspace/

0
.gitmodules vendored
View File

42
SendUpdateCommand.sh Executable file → Normal file
View File

@@ -1,33 +1,17 @@
#!/bin/bash #!/bin/bash
fifo="" pipe=/tmp/testpipe
read_config() { if [[ ! -p $pipe ]]; then
fifo_dir=$(cat "$1" | jq -r .fifo_dir) echo "Reader not running"
if [ -z "$fifo_dir" ]; then exit 1
return 1 fi
fi
fifo=$(cat "$1" | jq -r .fifo) if [[ "$1" ]]; then
if [ -z "$fifo" ]; then echo "$1" >$pipe
return 1 else
fi echo "Hello from $$" >$pipe
fifo="${fifo_dir}/$fifo"
return 0
}
if [ $# -ne 1 ] ; then
echo "Usage: $0 filename"
exit 1
else
if read_config "$1" ; then
if [[ ! -p $fifo ]]; then
echo "Reader not running on $fifo"
exit 1
fi
echo "Reader running on $fifo: update"
echo "update" >$fifo
exit 0
fi
fi fi

247
UpdateController.sh Executable file
View File

@@ -0,0 +1,247 @@
#!/bin/bash
update_controller_pipe="/tmp/update_controller_pipe"
init () {
trap "rm -f $update_controller_pipe" EXIT
if [[ ! -p $update_controller_pipe ]]; then
mkfifo $update_controller_pipe
fi
}
read_config() {
# name der fifo laesst sich ueberschreiben
return 0
}
wait_for_trigger() {
if [[ "$1" -eq -1 ]]; then
# wait for external impulse
if read line <$update_controller_pipe; then
if [ "$line" == "quit" ] || [ "$line" == "update" ]; then
echo "$line"
fi
fi
else
sleep ${1}
echo "sleep"
fi
}
check_for_apism() {
return 0
}
check_for_updates() {
return 0
}
backup_previous_version() {
return 0
}
fetch_updates() {
return 0
}
check_updates() {
return 0
}
revert_updates() {
return 0
}
lock_before_installing_updates() {
return 0
}
do_update_dry_run() {
return 0
}
do_update() {
return 0
}
fallback_to_previous_version() {
return 0;
}
unlock_after_installing_updates() {
return 0;
}
cleanup_previous_version() {
return 0
}
send_reboot_message_to_system_controller() {
return 0
}
###############################################################################
#
# UPDATE CONTROLLER
#
###############################################################################
UpdateController() {
local trigger_reboot=false
local check_apism_count=0
local try_update_count=0
local try_lock_count=0
local try_unlock_count=0
local trigger_timeout=-1
# read config parameters
read_config
# By default (trigger_timeout==-1), UpdateController can only be triggered
# from some external source to perform an update.
while :
do
request=$(wait_for_trigger $trigger_timeout)
if [ ${request} = "quit" ]; then
$trigger_reboot = true
elif [ ${request} != "update" ]; then
continue
fi
if $trigger_reboot; then
echo "CRITICAL send message to reboot the PSA"
send_reboot_message_to_system_controller
fi
# Is APISM running, listening on the correct ports etc. ?
while :
do
if ! check_for_apism; then
var=$((var+1))
check_apism_count=$((check_apism_count+1))
if [[ "$check_apism_count" -eq 5 ]]; then
trigger_reboot=true
echo "ERROR APISM not working"
continue 2
fi
sleep 60s
else
# APISM up and working
check_apism_count=0
break
fi
done
# Are there new updates available ?
if ! check_for_updates; then
echo "DEBUG no updates available"
continue
fi
# Fetch new updates (using git)
while :
do
if ! fetch_updates; then
try_updates_count=$((try_updates_count+1))
if [[ "$try_updates_count" -eq 5 ]]; then
trigger_reboot=true
echo "ERROR fetching updates"
continue 2
fi
sleep 60s
else
# Fetched updates successfully
try_updates_count=0
break
fi
done
# Check the updates for:
# * correct MD5
# * compatibility with PSA
# ...
if ! check_updates; then
echo "ERROR check_updates"
revert_updates
trigger_reboot=true
continue
fi
# perform a dry-run and check if everything might work as expected.
if ! do_update_dry_run; then
echo "ERROR do_update_dry_run"
revert_updates
trigger_reboot=true
continue
fi
# Backup before any updates in case some previous test was wrong
if ! backup_previous_version; then
echo "ERROR backup_previous_version"
revert_updates
trigger_reboot=true
continue
fi
# Lock the PSA so all other tasks on the PSA are in sync with the update
while :
do
if ! lock_before_installing_updates; then
try_lock_count=$((try_lock_count+1))
if [[ "$try_lock_count" -eq 5 ]]; then
revert_updates
fallback_to_previous_version
trigger_reboot=true
echo "ERROR locking PSA"
continue 2
fi
sleep 60s
else
# Locked PSA successfully
try_lock_count=0
break
fi
done
# Actually do the update
if ! do_update; then
echo "ERROR do_update"
revert_updates
fallback_to_previous_version
trigger_reboot=true
continue
fi
while :
do
# If all went well, the PSA can return to normal operation
if ! unlock_after_installing_updates; then
try_unlock_count=$((try_unlock_count+1))
if [[ "$try_unlock_count" -eq 5 ]]; then
revert_updates
fallback_to_previous_version
trigger_reboot=true
echo "ERROR unlocking PSA"
continue 2
fi
sleep 60s
else
# Unlocked PSA successfully
try_unlock_count=0
break
fi
done
# Cleanup.
if ! cleanup_previous_version; then
echo "ERROR cleanup_previous_version"
fi
done
}
###############################################################################
# start the UpdateController
# UpdateController

View File

@@ -1,9 +0,0 @@
#! /bin/bash -
# set -x
if [ $# -eq 2 ]; then
test mkdir -p $1 && cd $1 && git clone $2
exit $?
fi
echo "Usage: ./${0##*/} <workspace-directory> <path-to-customer-repository>

View File

@@ -1,118 +0,0 @@
#! /bin/bash -
# set -x
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 [$*]"
exec {fd}< <(eval "$@")
local __result_code=$?
local ps_pid=$! # remember pid of process substitution
local __result=""
while read __tmp <&$fd; do
if ! [ -z "$__tmp" ]; then
__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
}
# exec_process_substitution 'opkg --noaction list'
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
}
assert_s () {
# if [ -z ${!1} ]; then
# log_fatal "$1 not set"
# fi
# log_debug "$1=${!1}"
:
}
assert_d () {
# if [ ! -d ${!1} ]; then
# log_fatal "$1 does not exist"
# fi
# log_debug "$1=${!1}"
:
}
assert_f () {
# if [ ! -f ${!1} ]; then
# log_fatal "$1 does not exist"
# fi
#log_debug "$1=${!1}"
:
}
assert_a () {
local readonly __m="${1}[@]"
local readonly __n=(${!__m})
local __len=${#__n[@]}
# if [ $__len -eq 0 ]; then
# log_fatal "$1 not set"
# fi
# log_debug "$1=$__n"
:
}
fi

View File

@@ -1,253 +0,0 @@
#!/bin/bash
# set -x
source ./log_helpers
source ./general_utils
# if [ ${git_helpers_sourced:-1} = "1" ]; then
# readonly git_helpers_sourced=${BASH_SOURCE[0]}
readonly repository_already_up_to_date=2
#
exec_git_command () {
local func="${FUNCNAME[0]}"
log_debug "$func:${LINENO} exec-ing [$*]"
local __git_result=$(exec_process_substitution $*)
log_debug "$func:${LINENO} result=$__git_result"
printf '%s' "$__git_result"
}
#
latest_commit () {
local func="${FUNCNAME[0]}"
# git reflog -> 46c5896 HEAD@{0}: commit: Made update_helpers executable
local c=$(git reflog | grep "HEAD@{0}" | cut -d" " -f1)
if ! [ -z "$c" ]; then
if grep -qE "^[[:xdigit:]]{6,}$" <<< $c; then
log_debug "$func:${LINENO} commit -> $c"
printf "%s\n" "$c"
else
log_crit "$func:${LINENO} wrong format for commit c=$c"
fi
else
log_crit "$func:${LINENO} 'git reflog' result empty"
fi
}
# fallback if something went wrong: revert to last valid commit
revert_to_commit_before_pull () {
local func="${FUNCNAME[0]}"
if ! [ -z "$commit_before_pull" ]; then
if grep -qE "^[[:xdigit:]]{6,}$" <<< $commit_before_pull; then
`git reset --hard "$commit_before_pull"`
if [ $? -eq 0 ]; then
log_info "$func: git reset --hard $commit_before_pull"
return 0
fi
log_crit "$func: 'git reset --hard $commit_before_pull' failed!"
fi
log_crit "$func: wrong format for commit_before_pull"
fi
log_crit "$func: empty commit_before_pull"
return 1
}
# revert_to_commit_before_pull
git_branch () {
# always relative to a git repository
echo $(git branch -a | grep '*' | awk '{ print $2 }')
}
git_customer_branch () {
if cd_customer_repository; then
customer_branch=$(git_branch)
cd_home;
echo $customer_branch
fi
}
# 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
log_fatal "$func:${LINENO} PD != WD ($PWD != $WORKING_DIRECTORY)"
fi
mkdir -p "./$WORKSPACE_DIR"
# check if the directory is empty. If so, clone the
# customer repository
if ! find ./$WORKSPACE_DIR -mindepth 1 -maxdepth 1 | read; then
log_info "$func:${LINENO} cloning ${1} into ${PWD}/${WORKSPACE_DIR}..."
if ! cd "./$WORKSPACE_DIR"; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} can not change to $WORKSPACE_DIR"
fi
if ! exec_git_command git clone "$1"; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} can not clone $1"
fi
########################## CLONING DONE ############################
log_debug "$func:${LINENO} cloning ${1} done"
# after cloning, cd into repository, and re-initialize,
# setting the work-tree as "/". This has the effect that
# a "git pull" will automatically fetched files in the
# corresponding sytem-folders.
####################### CD INTO REPOSITORY ##########################
if ! cd ${CUSTOMER_ID_BASE_DIR}; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} can not change to $CUSTOMER_ID_BASE_DIR"
fi
log_debug "$func:${LINENO} cd into $CUSTOMER_ID_BASE_DIR"
##################### CONFIGURE HOOKS DIRECTORY ######################
if ! exec_git_command git config core.hooksPath .githooks; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} can not configure hooks directory"
fi
###################### CHECKOUT LOCAL BRANCH #########################
if ! exec_git_command git checkout "$LOCAL_BRANCH"; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} can not checkout $LOCAL_BRANCH"
fi
log_debug "$func:${LINENO} checked out local branch $LOCAL_BRANCH"
######################## CONFIGURE WORKTREE ##########################
if ! exec_git_command git config core.worktree "/"; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} can not configure worktree '/'"
fi
log_debug "$func:${LINENO} configured worktree '/'"
########################### FETCH ALL #################################
if ! exec_git_command git fetch --all; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} can not fetch --all for $LOCAL_BRANCH"
fi
log_debug "$func:${LINENO} fetch repository"
########################## RE-INIT REPOSITORY ########################
if ! exec_git_command git reset --hard "$LOCAL_BRANCH"; then
update_psa_clone_error # message to ISMAS
log_fatal "$func:${LINENO} re-init of $LOCAL_BRANCH failed"
fi
log_debug "$func:${LINENO} reset --hard $LOCAL_BRANCH"
INITIAL_CLONE=true
log_debug "$func:${LINENO} re-init of ${1} done"
update_psa_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} $PWD $WORKSPACE_DIR/$CUSTOMER_ID"\
"wrong repository: $(ls -d './${WORKSPACE_DIR}/*')"
fi
local __m="./${WORKSPACE_DIR}/$CUSTOMER_ID exists"
log_info "$func:${LINENO} $__m, no clone necessary"
fi
cd_home
}
# clone_customer_repository ->
# https://git.mimbach49.de/GerhardHoffmann/customer_281.git
cd_customer_repository () {
local func="${FUNCNAME[0]}"
if [ "$PWD" != "$WORKING_DIRECTORY" ]; then
log_fatal "$func:${LINENO} PD != WD ($PWD != $WORKING_DIRECTORY)"
fi
if ! [[ -d "$CUSTOMER_ID_BASE_DIR" ]]; then
log_fatal "$func:${LINENO}: $CUSTOMER_ID_BASE_DIR does not exist!"
fi
if ! cd "$CUSTOMER_ID_BASE_DIR"; then
log_fatal "$func:${LINENO}: cannot cd to $CUSTOMER_ID_BASE_DIR !!!"
fi
log_debug "$func:${LINENO}: cd to $CUSTOMER_ID_BASE_DIR"
return 0
}
cd_home () {
if cd "$WORKING_DIRECTORY" &>/dev/null ; then
return 0
fi
return 1
}
pull_customer_repository () {
local func="${FUNCNAME[0]}"
if ! cd_customer_repository; then
return 1
fi
log_crit "$func:${LINENO}: executing 'git pull'..."
exec_git_command 'git pull'
# GIT_UPDATE_LOG updated by hook post-merge. it contains the names of the
# changed files or opkg-commands to execute.
# If 'git pull' has fetched new data, then there are lines starting with
# DOWNLOAD or EXECUTE.
if grep -qE "^[[:space:]]*(DOWNLOAD|EXECUTE)" "$GIT_UPDATE_LOG"; then
log_info "$func:${LINENO}: new data fetched from repository"
cd_home; return 0
fi
log_warn "$func:${LINENO}: no data fetched from repository"
cd_home; return 1
}
# pull_customer_repository customer_281
changed_file_names () {
local func="${FUNCNAME[0]}"
if cd_customer_repository ; then
local git_res=$(exec_git_command 'git diff --stat master@{1} master')
git_res=${git_res//[$'\r\n\t']/ }
log_debug "$func:${LINENO}: git_res=$git_res"
local file_names=""
for f in ${KNOWN_FILES[@]} ; do
if grep -qE "${f}" <<< "$git_res"; then
if ! [ -z $file_names ]; then
file_names="$f $file_names"
else
file_names="$f"
fi
log_debug "$func:${LINENO}: $f found in $git_res"
fi
done
cd_home; log_debug "$func:${LINENO}: file_names=$file_names" ;
printf '%s' "$file_names"
else
log_crit "$func:${LINENO}: cannot cd to $customer_repository "\
"while in $PWD"
fi
}
get_blob () { # get the blob of the file(name) passed as $1
# note: this can be used for any file in the filesystem
echo $(git hash-object $1)
}
get_commit_for_blob () {
blob=$(get_blob $1)
if [ ! -z $blob ]; then
# search for the blob in all commits for the file(name) $1
echo $(echo $(git log --all --pretty=format:%H -- $1) |
xargs -I{} sh -c "git ls-tree {} -- $1 |
grep -q $blob && echo {}")
fi
}

View File

@@ -1,33 +0,0 @@
#! /bin/bash -
# set -x
#
# echo "Usage: ./${0##*/} <tariff.config> <tariff.current>"
#
# tariff.config: a JSON-file representing the tariff which should be used
# (this tariff-file is generated by a web-based tool of
# Mobilisis)
# tariff.current: a file containing infos about the currently used tariff:
# VERSION: version of the tariff
# PROJECT: e.g. szeged
# ZONE: usually 1
# INFO: additional info for the tariff (optional)
# LOADED: date when tariff has been loaded
#
# This file will be used by the update_psa-script to send
# a message to ISMAS containing the current settings of the PSA.
#
if [ $# -eq 2 ]; then
if [ -f $1 ]; then
out="\"VERSION\":\"$(cat $1 | jq -r .version)\"",
out+="\"PROJECT\":\"$(cat $1 | jq -r .project)\"",
out+="\"ZONE\":$(cat $1 | jq -r .zone)",
out+="\"INFO\":\"$(cat $1 | jq -r .info)\"",
out+="\"LOADED\":\"$(date +%Y-%m-%dT%T)\""
echo $out > $2
exit $?
fi
fi
echo "Usage: ./${0##*/} <tariff.config> <tariff.current>"

View File

@@ -1,92 +0,0 @@
#!/bin/bash
# set -x
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
if ! [ -f "$log_file" ]; then
touch $log_file
fi
readonly DEBUG=0
readonly INFO=1
readonly WARN=2
readonly CRIT=3
readonly ERROR=4
readonly FATAL=5
readonly MAX_DEBUG_LEVEL=6
log_level=$INFO
FATAL_FAILURE=false
set_dbg_level () {
if [ $1 < $MAX_DEBUG_LEVEL ]; then
log_level=$1
fi
}
dbg_level () {
return $log_level
}
log_to_file() {
if [[ $(("$(wc -l < $log_file)")) -ge $((100000)) ]]; then
# remove first line
sed -e 1d -i $log_file
fi
local msg="$(date +'%Y-%m-%d_%T'): $*"
echo "$msg" >> $log_file
}
log() {
local msg="$(date +'%Y-%m-%d_%T'): $*"
echo "log:$msg" >&2
}
log_debug() {
log_to_file "DEBUG $*"
if [ $log_level -le $DEBUG ]; then
log "DEBUG $*"
fi
}
log_info() {
log_to_file "INFO $*"
if [ $log_level -le $INFO ]; then
log "INFO $*"
fi
}
log_warn() {
log_to_file "WARN $*"
if [ $log_level -le $WARN ]; then
log "WARN $*"
fi
}
log_crit() {
log_to_file "CRIT $*"
if [ $log_level -le $CRIT ]; then
log "CRIT $*"
fi
}
log_error() {
log_to_file "ERROR $*"
if [ $log_level -le $ERROR ]; then
log "ERROR $*"
fi
}
log_fatal() {
log_to_file "FATAL $*"
if [ $log_level -le $FATAL ]; then
log "FATAL $*"
log "exiting ..."
FATAL_FAILURE=true
exit 1
fi
}
###############################################################################
fi ### include guard

View File

@@ -1,36 +0,0 @@
# !/bin/bash -
source ./log_helpers
if [ "${news_from_ismas_sourced:-1}" = "1" ]; then # include only once
readonly news_from_ismas_sourced=${BASH_SOURCE[0]}
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

View File

@@ -1,455 +0,0 @@
# !/bin/bash -
source ./log_helpers
if [ "${news_to_ismas_sourced:-1}" = "1" ]; then # include only once
readonly news_to_ismas_sourced=${BASH_SOURCE[0]}
readonly APISM_DB_PORT=7777
readonly UPDATE_ISMAS_PROGRESS="U0010"
readonly UPDATE_SUCCEEDED="U0001" # update finished: 100%
readonly UPDATE_ACTIVATED="U0002" # reset TRG
readonly UPDATE_ISMAS_ERROR="U0003" # update error
# error codes
readonly RC_SUCCESS=0
readonly RC_NO_UPDATE_NECESSARY=1
readonly RC_GIT_CLONE_ERROR=2
readonly RC_GIT_PULL_ERROR=3
readonly RC_BACKUP_ERROR=4
readonly RC_HASH_VALUE_ERROR=5
readonly RC_HW_COMPATIBILITY_ERROR=6
readonly RC_COPY_ERROR=7
readonly RC_OPKG_COMMANDS_ERROR=8
readonly RC_CLEANUP_ERROR=9
PERCENT=1
###########################################################################
###########################################################################
update_psa_activated () {
PERCENT=$((PERCENT+1))
local params=("U0010" # event
$PERCENT
$RC_SUCCESS # resultcode
"activated" # step
"detected WAIT state" # step_result
"") # version
news_to_ismas ${params[*]}
return $?
}
update_psa_false_alarm () {
PERCENT=$((PERCENT+1))
local params=("U0003"
$PERCENT
$RC_NO_UPDATE_NECESSARY
"false_alarm"
"$1"
"")
news_to_ismas ${params[*]}
EXITCODE=$((EXITCODE+1))
test $EXITCODE -gt 125 && EXITCODE=125
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
return $EXITCODE
}
update_psa_activated_new_software () {
PERCENT=100
local params=("U0010"
$PERCENT
$RC_SUCCESS
"activated_new_software"
"<hier nochmal eine liste was alles installiert wurde>"
"<zugehoerige versionen>")
news_to_ismas ${params[*]}
return $?
}
###########################################################################
###########################################################################
update_psa_clone_customer_repository () {
PERCENT=10
local params=("U0010" # event
$PERCENT # percent
$RC_SUCCESS # resultcode
"clone_customer_repository" # step
"git cloned $CUSTOMER_REPOSITORY_PATH" # step_result
"") # version
news_to_ismas ${params[*]}
return $?
}
update_psa_pull_customer_repository () {
PERCENT=10
local params=("U0010" # event
$PERCENT # percent
0 # resultcode
"pull_customer_repository" # step
"git pulled $CUSTOMER_REPOSITORY_PATH" # step_result
"") # version
news_to_ismas ${params[*]}
return $?
}
update_psa_pull_error () {
PERCENT=10
local params=("U0003"
$PERCENT
$RC_GIT_PULL_ERROR
"pull_error"
"git failed to pull $CUSTOMER_REPOSITORY_PATH"
"")
news_to_ismas ${params[*]}
EXITCODE=$((EXITCODE+1))
test $EXITCODE -gt 125 && EXITCODE=125
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
return $EXITCODE
}
update_psa_clone_error () {
PERCENT=10
local params=("U0003"
$PERCENT
$RC_GIT_CLONE_ERROR
"clone_error"
"git failed to clone $CUSTOMER_REPOSITORY_PATH"
"")
news_to_ismas ${params[*]}
EXITCODE=$((EXITCODE+1))
test $EXITCODE -gt 125 && EXITCODE=125
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
return $EXITCODE
}
###########################################################################
###########################################################################
update_psa_backup () {
PERCENT=20
local params=("U0010"
$PERCENT
$RC_SUCCESS
"backup"
"backup of (hier noch alle dateien angeben)"
"")
news_to_ismas ${params[*]}
return $?
}
update_psa_backup_error () {
PERCENT=20
local params=("U0010"
$PERCENT
$RC_BACKUP_ERROR
"backup_error"
"backup of (hier noch alle dateien angeben) failed"
"")
news_to_ismas ${params[*]}
EXITCODE=$((EXITCODE+1))
test $EXITCODE -gt 125 && EXITCODE=125
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
return $EXITCODE
}
###########################################################################
###########################################################################
update_psa_report_changed_file_names () {
PERCENT=30
local params=("U0010"
$PERCENT
$RC_SUCCESS
"report_changed_file_names"
"changed filenames: [$@]"
"")
news_to_ismas ${params[*]}
return $?
}
###########################################################################
###########################################################################
update_psa_check_hash () {
PERCENT=40
local params=($1 # event
$PERCENT
$2 # resultcode
"check_hash" # step
"$3" # step_result
"")
news_to_ismas ${params[*]}
test $2 -eq $RC_SUCCESS && return $?
EXITCODE=$((EXITCODE+1))
test $EXITCODE -gt 125 && EXITCODE=125
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
return $EXITCODE
}
###########################################################################
###########################################################################
update_psa_check_hardware_compatibility () {
PERCENT=50
local params=($1 # event
$PERCENT
$2 # resultcode
"check_hardware_compatibility" # step
"$3" # step_result
"")
news_to_ismas ${params[*]}
test $2 -eq $RC_SUCCESS && return $?
EXITCODE=$((EXITCODE+1))
test $EXITCODE -gt 125 && EXITCODE=125
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
return $EXITCODE
}
###########################################################################
###########################################################################
# conf/ini files
update_psa_copy_conf_and_ini_files () {
PERCENT=60
local params=($1 # event
$PERCENT
$2 # resultcode
"copy_conf_and_ini_files" # step
"$3" # step_result
"")
news_to_ismas ${params[*]}
test $2 -eq $RC_SUCCESS && return $?
EXITCODE=$((EXITCODE+1))
test $EXITCODE -gt 125 && EXITCODE=125
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
return $EXITCODE
}
###########################################################################
###########################################################################
# exec opkg-commands (dry-run)
update_psa_install_opkg_packages_dry_run () {
PERCENT=70
# TODO
return 0
}
###########################################################################
###########################################################################
# exec opkg-commands
update_psa_install_opkg_packages () {
PERCENT=80
local params=($1 # event
$PERCENT
$2 # resultcode
"install_opkg_packages" # step
"$3" # step_result
"")
news_to_ismas ${params[*]}
test $2 -eq $RC_SUCCESS && return $?
EXITCODE=$((EXITCODE+1))
test $EXITCODE -gt 125 && EXITCODE=125
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
return $EXITCODE
}
###########################################################################
###########################################################################
# remove backup in case of success
update_psa_cleanup () {
PERCENT=90
local params=($1 # event
$PERCENT
$2 # resultcode
"cleanup" # step
"$3" # step_result
"")
news_to_ismas ${params[*]}
test $2 -eq $RC_SUCCESS && return $?
EXITCODE=$((EXITCODE+1))
test $EXITCODE -gt 125 && EXITCODE=125
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
return $EXITCODE
}
###########################################################################
###########################################################################
update_psa_update_succeeded () {
PERCENT=100
local params=($1 # event
$PERCENT
$2 # resultcode
"update_succeeded" # step
"$3" # step_result
"")
news_to_ismas ${params[*]}
test $2 -eq $RC_SUCCESS && return $?
EXITCODE=$((EXITCODE+1))
test $EXITCODE -gt 125 && EXITCODE=125
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
return $EXITCODE
}
###########################################################################
###########################################################################
update_psa_activate_update () {
PERCENT=100
local params=($1 # event
$PERCENT
$2 # resultcode
"activate_update" # step
"$3" # step_result
"")
news_to_ismas ${params[*]}
test $2 -eq $RC_SUCCESS && return $?
EXITCODE=$((EXITCODE+1))
test $EXITCODE -gt 125 && EXITCODE=125
log_debug "${FUNCNAME[0]}:${LINENO}: EXITCODE=$EXITCODE"
return $EXITCODE
}
# only for testing
set_updates_available () {
local params=("U0099" # event
$PERCENT # percent
0 # resultcode
"set_updates_available" # step
"" # step_result
"") # version
news_to_ismas ${params[*]}
return $?
}
set_update_active () {
reset_update_trigger
return $?
}
###########################################################################
###########################################################################
news_to_ismas () {
# $1: EVENT: U0001 update finished: 100%
# U0002 reset TRG
# U0003 error
# U0010 for update process
# $2: PERCENT : "only for ISMAS: 0-100%",
# $3: RESULTCODE : "only for ISMAS",
# 0: Success
# 1: no Update nessesary
# 2: Backup failed
# 3: Package error/ Wrong package
# 4: Install Error
# $4: STEP : "running step (only for us): update_psa...",
# $5: STEP_RESULT : "error and result text",
# $6: VERSION : "opkg and conf info; what will be updated"
#
local func="${FUNCNAME[0]}"
local p=("$@")
local data="#M=APISM#C=CMD_EVENT#J=
{
\"REASON\":\"SW_UP\",
\"TIMESTAMP\":\"$(date +%Y-%m-%dT%T.000%z)\",
\"EVENT_ID\":\"0\",
\"EVENT\":\"${p[0]}\",
\"EVENTSTATE\":1,
\"PARAMETER\": {
\"PERCENT\" : ${p[1]},
\"RESULTCODE\" : ${p[2]},
\"STEP\" : \"update_psa_${p[3]}\",
\"STEP_RESULT\" : \"${p[4]}\",
\"VERSION\" : \"$VERSION\"
}
}"
log_debug "$func:${LINENO}: data=$data"
echo $((echo "$data"; sleep 1) | nc localhost $APISM_DB_PORT)
}
#
# send current psa setting to ismas at end of update procedure
#
current_settings_to_ismas () {
local func="${FUNCNAME[0]}"
local p=("$@")
local data="#M=APISM#C=CMD_SENDVERSION#J=
{
\"VERSION_INFO\" : {
\"CREATED\":\"$(date +%Y-%m-%dT%T)\",
\"HASH\":\"$(compute_hash)\"
},
\"TARIFF\" : {
$(<$TC_PSA_TC_FILE)
},
\"HARDWARE\" : {
\"DEVICES\" : [
\"PTU5\", \"DC\", \"PRINTER\", \"BNA\"
]
},
\"OS\" : {
\"$(uname)\": \"$(uname -a)\"
},
\"CONFIG\" : {
\"PTU5\" : {
\"CPU_SERIAL\" : \"$(cat /proc/cpuinfo |
grep Serial |
sed -E -e 's/.*:\s*(.*)/\1/g')\"
},
\"DC\" : {
\"VERSION\" : \"$(compute_hash ${DC_PSA_DC_FILE})\",
\"MD5SUM\" : \"\"
},
\"PRINTER\" : {
},
\"BNA\" : {
}
},
\"SOFTWARE\": {
\"RAUC\" : \"$(rauc --version)\",
\"OPKG\" : \"$(opkg --version)\",
\"ATBQT\" : {
\"VERSION\" : \"$($ATBQT_ATB_SYS_BIN_FILE -v |
grep Version |
sed -E -e 's/.*:\s*(.*)/\1/g')\",
\"GIT_DESCRIBE\" : \"$($ATBQT_ATB_SYS_BIN_FILE -v |
grep git |
sed -E -e 's/.*:\s*(.*)/\1/g')\"
},
\"PLUGINS\" : {
$(get_plugins)
}
}
}"
log_debug "$func:${LINENO}: data=$data EXITCODE=$EXITCODE"
echo $((echo "$data"; sleep 1) | nc localhost $APISM_DB_PORT)
# if [ $EXITCODE -eq $RC_SUCCESS ]; then
update_psa_update_succeeded $UPDATE_SUCCEEDED \
$RC_SUCCESS "psa update succeeded" $VERSION
update_psa_update_succeeded $UPDATE_ACTIVATED \
$RC_SUCCESS "psa update activated" $VERSION
log_info "$func:${LINENO}: success"
# fi
}
fi

View File

@@ -1,283 +0,0 @@
#!/bin/bash
# set -x
compute_md5 () {
exec {fd}< <(md5sum "$1") # open fd readable for P.S.
cs_pid=$! # remember pid of P.S.
md5=""
while read t <&$fd; do
if ! [ -z "$t" ]; then
t=($t) # md5sum returns two values:
# the hash plus the filename
md5="${md5}$t"
fi
done
exec {fd}>&- # close fd (i.e. process substitution)
wait $cs_pid # wait for the subshell to finish
echo $md5
}
md5_for_ini_files() {
ini_directory="$1"
ini_files=("ISMASMgr.ini" "sysconfig.ini" "SystemControl.ini")
local data="\"ini\": {"$'\n'
for f in "${ini_files[@]}"; do
ini_file=${ini_directory}/$f
md5=`compute_md5 $ini_file`
data+="\"$ini_file\":\"$md5\","
done
if [[ "$data" =~ ^.*,$ ]]; then
data=${data%?}
fi
data+="},"
echo $data
}
md5_for_conf_files() {
conf_directory="$1"
conf_files=("emp.conf" "printer.conf" "device.conf")
local data="\"conf\": {"$'\n'
for f in "${conf_files[@]}"; do
conf_file=${conf_directory}/$f
md5=`compute_md5 $conf_file`
data+="\"$conf_file\":\"$md5\","
done
if [[ "$data" =~ ^.*,$ ]]; then
data=${data%?}
fi
data+="},"
echo $data
}
write_config() {
local path="$1"
if [ "${path: -1}" == "/" ]; then # remove trailing '/'
path=${path%?}
fi
local data="{ "$'\n'
data+=`md5_for_ini_files "$path/opt/app/sysconfig"`
data+=`md5_for_conf_files "$path/etc/psa_config"`
data+="
\"opkg\" : {"
local cnt=0
for package_name in $(opkg list-installed); # list names of installed packages
do
if ! grep -q "^[a-zA-Z]" <<< $package_name; then
continue
fi
if [ -z "$package_name" ]; then
continue
fi
cnt=$((cnt+1))
printf "%3d:%s\n" "$cnt" "$package_name"
# Format of package info:
#
# Package: openssh-scp
# Version: 7.8p1+git-r0
# Depends: libc6 (>= 2.28), update-alternatives-opkg
# Status: install ok installed
# Section: console/network
# Architecture: cortexa9t2hf-neon
# Maintainer: Poky <poky@yoctoproject.org>
# MD5Sum: dfffcbb088cd5f180be5e9ee2ad030fe
# Size: 32700
# Filename: openssh-scp_7.8p1+git-r0_cortexa9t2hf-neon.ipk
# Source: openssh_7.8p1+git.bb
# Description: A suite of security-related network....
# Installed-Size: 58920
# Installed-Time: 1654699615
#
# process substitution (P.S):
# run 'opkg info' synchronously to parent script
exec {fd}< <(opkg info "$package_name") # open fd readable for P.S.
cs_pid=$! # remember pid of P.S.
while read package_info_line <&$fd; do
if [[ $package_info_line == Package* ]]; then
package=(${package_info_line// / })
package="\"${package[1]}\": {"
elif [[ $package_info_line == MD5Sum* ]]; then
md5sum=(${package_info_line// / })
md5sum="\"${md5sum[0]%?}\": \"${md5sum[1]}\","
elif [[ $package_info_line == Filename* ]]; then
filename=(${package_info_line// / })
filename="\"${filename[0]%?}\": \"${filename[1]}\","
elif [[ $package_info_line == Installed-Time* ]]; then
installed_time=(${package_info_line// / })
installed_time="\"${installed_time[0]%?}\": \"${installed_time[1]}\"
},"
fi
done
exec {fd}>&- # close fd (i.e. process substitution)
wait $cs_pid # wait for the subshell to finish
# use 8 spaces
data="$data
$package
$md5sum
$filename
$installed_time"
# break
done
if [[ "$data" =~ ^.*,$ ]]; then
data=${data%?}
fi
data="$data
}
}"
echo "$data" > "${path}/$2"
# echo $(cat "/tmp/test.txt" | jq -C --indent 4 '.') > /tmp/test2.txt
}
# write_config "/home/root/szeged/customer_281/szeged/1/1/" "test.txt"
# Download opkg-package. After the download, extract data.tar.gz to
# access e.g. atbqt.
download_opkg_package () {
case "$1" in
atbqt) # hier weitere packete eintragen
;;
*)
printf "ERROR $1 has wrong format\n" >&2
return 1
;;
esac
exec {fdd}< <(opkg --download-only download "$1") # open fd readable for P.S.
cs_pid=$! # remember pid of P.S.
opkg_result=""
while read result <&$fdd; do
if ! [ -z "$result" ]; then
opkg_result+="$result"
fi
done
exec {fdd}>&- # close fd (i.e. process substitution)
wait $cs_pid # wait for the subshell to finish
if [ -z "$opkg_result" ]; then
printf "ERROR empty opkg_result\n" >&2
return 1
fi
if ! grep -qF "$1" <<< $opkg_result; then
printf "ERROR opkg_result [$opkg_result] does not contain $1\n" >&2
return 1
fi
if ! grep -qF "$2" <<< $opkg_result; then
printf "ERROR opkg_result [$opkg_result] does not contain $2\n" >&2
return 1
fi
# printf "%s\n" $opkg_result
return 0
}
# download_opkg_package "atbqt" "atbqt_1.0.0-r1_cortexa9t2hf-neon.ipk"
ar_extract_opkg_package_data () {
return 0
cp $1 "/tmp"
# mv $1 "/tmp"
cd /tmp
# ar -x $1
#if [ $? ne 0 ]; then
data_file="data.tar.xz"
if ! [ -f "$data_file" ]; then
printf "ERROR %s does not exist\n" "$data_file" >&2
return 1
fi
cd -
return 0
tar -qxvf $data_file
echo $pwd
}
# ar_extract_opkg_package_data "atbqt_1.0.0-r1_cortexa9t2hf-neon.ipk"
tar_extract_opkg_package_data () {
exec {ftar}< <(tar -xvf "$2" -C "$1") # use process substitution
cs_pid=$!
exec {ftar}>&-
wait $cs_pid
binary="$1/$3"
if ! [ -f "$binary" ]; then
printf "ERROR %s does not exist\n" "$binary" >&2
return 1
fi
return 0
}
# tar_extract_opkg_package_data "/tmp" "data.tar.xz" "opt/app/ATBAPP/ATBQT"
read_atbqt_version () {
version=$(/tmp/opt/app/ATBAPP/ATBQT -v)
version=(${version// / })
# ATB APP: Version: 20221220_1038_00318q git describe: 4.5.2-65-gf1799aa3_00318/Nexobility_dev
# printf "%s\n" "${version[@]}"
if [ ${#version[@]} -lt 7 ]; then
printf "ERROR %s has wrong format\n" "${version[@]}" >&2
return 1
fi
echo "${version[3]} ${version[6]}"
}
# xxx=`read_atbqt_version`
# echo $xxx
# set -x
check_atbqt_version () {
if ! `download_opkg_package "$1" "$2"`; then
return 1
fi
if ! `ar_extract_opkg_package_data "$2"`; then
return 1
fi
if ! `tar_extract_opkg_package_data "/tmp" "data.tar.xz" "opt/app/ATBAPP/ATBQT"`; then
return 1
fi
version=`read_atbqt_version`
version=(${version// / })
if [ "${version[0]}" = "$3" ] && [ "${version[1]}" = "$4" ]; then
return 0
fi
return 1
}
# check_atbqt_version "atbqt" \
# "atbqt_1.0.0-r1_cortexa9t2hf-neon.ipk" \
# "20221220_1038_00318q" \
# "4.5.2-65-gf1799aa3_00318/Nexobility_dev"

View File

@@ -1,405 +0,0 @@
#! /bin/bash -
# set -x
source ./log_helpers
source ./general_utils
if [ ${read_config_sourced:-1} = "1" ]; then # include only once
readonly read_config_sourced=${BASH_SOURCE[0]}
readonly MAJOR="0"
readonly MINOR="1"
readonly PATCH="0"
readonly DATEFLAGS="+%Y.%m.%dT%H.%M.%S"
readonly STRIPCOMMENTS='sed -e s/#.*$//g'
readonly STRIPWHITESPACE='sed -E -e s/^[[:space:]]*$//g'
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
# name of file containing the logs following a 'git pull':
# basically, there are two kinds of entries:
readonly GIT_UPDATE_LOG=/opt/app/tools/atbupdate/update_log.csv
readonly PROGRAM=`basename $0`
readonly WORKSPACE_DIR=workspace
EXITCODE=$RC_SUCCESS
INITIAL_CLONE=false
APISM_RUNNING=0
# read config file (JSON syntax)
read_config() {
local func="${FUNCNAME[0]}"
CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'}
if ! [ -f "$CONFIGFILENAME" ]; then
log_fatal "$func:${LINENO}: $CONFIGFILENAME not found"
fi
log_debug "$func:${LINENO}: CONFIGFILENAME=$CONFIGFILENAME"
log_debug "$func:${LINENO}: WORKING_DIRECTORY=$WORKING_DIRECTORY"
local readonly cf="$CONFIGFILENAME"
readonly GIT_SSL_NO_VERIFY="$(cat "$cf" | jq -r .GIT_SSL_NO_VERIFY)"
assert_s GIT_SSL_NO_VERIFY
readonly CUSTOMER_LOCATION=$(cat "$cf" | jq -r .customer_location)
assert_s CUSTOMER_LOCATION
readonly CUSTOMER_ID="$(cat "$cf" | jq -r .customer_id)"
assert_s CUSTOMER_ID
readonly CUSTOMER_REPOSITORY_PATH="$(cat "$cf" |
jq -r .cust_repository_path)"
assert_s CUSTOMER_REPOSITORY_PATH
local __customer_id_base_dir="$WORKING_DIRECTORY/${WORKSPACE_DIR}"
readonly CUSTOMER_ID_BASE_DIR="${__customer_id_base_dir}/${CUSTOMER_ID}"
local __number_of_zone_groups=$(cat "$cf" |
jq -r .zg[0] |
sed -E -e 's/[[:space:]]*//g')
# TODO: was ist hier falsch
# __n_of_zgroups=$(echo "$__n_of_zgrps" | ${STRIPWHITESPACE} )
# log_debug "$func:${LINENO}: #n of zone_groups: $__number_of_zone_groups"
local __zone_groups=($__number_of_zone_groups)
for zg in `seq 1 $__number_of_zone_groups`; do
local __n_zones=$(cat "$cf" |
jq -r .zg[$zg].z |
sed -E -e 's/[][,[:space:]]*//g') # rm ][ as well
__zone_groups[$zg]=$__n_zones
done
readonly ZONE_GROUPS=(${__zone_groups[@]})
assert_a ZONE_GROUPS
# TODO
# TODO: falls mehrere gruppen/zonen auftauchen hier anpassen
# TODO
# Zone aus /etc/zone_nr auslesen
#
readonly ZONE_GROUP=1
local __zone=1
readonly ZONE_FILE="$(cat "$cf" | jq -r .zone)"
if [ -f "$ZONE_FILE" ]; then
__zone=$(cat "$ZONE_FILE")
__zone=$((__zone))
fi
readonly ZONE=$__zone
readonly LOCAL_BRANCH="$(cat "$cf" | jq -r .local_branches[$ZONE])"
if [ -z "$WORKING_DIRECTORY" ]; then
log_fatal "${func}:${LINENO}: empty WORKING_DIRECTORY"
fi
if ! cd "$WORKING_DIRECTORY"; then
log_fatal "${func}:${LINENO}: cannot cd to $WORKING_DIRECTORY"
fi
log_debug "${func}:${LINENO}: cd to $WORKING_DIRECTORY"
return 0
}
###############################################################################
########################## parsing with jq finished ###########################
###############################################################################
compute_hash () {
if cd_customer_repository; then
local hash=""
if [[ -z "$1" ]]; then
hash=$(git log -n 1 --pretty=format:%H)
else
hash=$(git hash-object "$1")
fi
cd_home ; echo ${hash:0:10} # return the first 10 hex characters
return 0
fi
return 1
}
compute_version () {
VERSION="$MAJOR.$MINOR.$PATCH+$CUSTOMER_LOCATION-$(compute_hash)"
cd_home; return 0
return 1
}
check_sanity_of_repository () {
local func="${FUNCNAME[0]}"
if [ "$PWD" != "$WORKING_DIRECTORY" ]; then
log_fatal "$func:${LINENO} PD != WD ($PWD != $WORKING_DIRECTORY)"
fi
assert_d CUSTOMER_ID_BASE_DIR
CUSTOMER_LOCATION_DIR="$CUSTOMER_ID_BASE_DIR"
#CUSTOMER_LOCATION_DIR="${CUSTOMER_ID_BASE_DIR}/${CUSTOMER_LOCATION}"
#CUST_LOC_DIR=$CUSTOMER_LOCATION_DIR
assert_d CUSTOMER_LOCATION_DIR
# readonly zone_groups=(${__zone_groups[@]})
# by now (03.03.2023) there is only one zone group.
#readonly local __zgroup=1
#local __number_of_zone_groups=${ZONE_GROUPS[0]}
#local __zindex=1
#local __customer_base_dirs=("placeholder")
#for __zg in `seq 1 $__number_of_zone_groups`; do
# local __n_of_zones=${ZONE_GROUPS[$__zindex]}
# log_debug "$func:${LINENO}: zgroup $__zg has $__n_of_zones zones"
# for (( j=1; j<=$__n_of_zones; ++j)); do
# __customer_base_dirs+=("${CUSTOMER_LOCATION_DIR}/$__zgroup/$j")
# log_debug "$func:${LINENO}: zone $j"
# ((++__zindex))
# done
#done
# for szeged:
# placeholder
# /home/root/szeged/UpdateController/workspace/customer_281/szeged/1/1
# /home/root/szeged/UpdateController/workspace/customer_281/szeged/1/2
# /home/root/szeged/UpdateController/workspace/customer_281/szeged/1/3
# readonly CUST_BASE_DIRS=(${__customer_base_dirs[@]})
# assert_a CUST_BASE_DIRS
readonly CUST_BASE_DIR="$CUSTOMER_ID_BASE_DIR"
#readonly CUST_BASE_DIR="${CUST_BASE_DIRS[$ZONE]}"
#assert_d CUST_BASE_DIR
readonly ETC_SYS_DIR="/etc"
readonly ATB_SYS_DIR="/etc/atb"
readonly DC_SYS_DIR="/etc/dc"
readonly TARIFF_SYS_DIR="/etc/psa_tariff"
readonly OPKG_SYS_DIR="/etc/psa_update"
readonly CONF_SYS_DIR="/etc/psa_config"
readonly OPT_SYS_DIR="/opt"
readonly APP_SYS_DIR="/opt/app"
readonly SYSCONFIG_SYS_DIR="/opt/app/sysconfig"
readonly ATBAPP_SYS_DIR="/opt/app/ATBAPP"
readonly ISMASMGR_SYS_DIR="/opt/app/ISMASMgr"
readonly ETC_PSA_DIR=${CUST_BASE_DIR}${ETC_SYS_DIR}
readonly ATB_PSA_DIR=${CUST_BASE_DIR}${ATB_SYS_DIR}
readonly DC_PSA_DIR=${CUST_BASE_DIR}${DC_SYS_DIR}
readonly TARIFF_PSA_DIR=${CUST_BASE_DIR}${TARIFF_SYS_DIR}
readonly OPKG_PSA_DIR=${CUST_BASE_DIR}${OPKG_SYS_DIR}
readonly CONF_PSA_DIR=${CUST_BASE_DIR}${CONF_SYS_DIR}
readonly OPT_PSA_DIR=${CUST_BASE_DIR}${OPT_SYS_DIR}
readonly APP_PSA_DIR=${CUST_BASE_DIR}${APP_SYS_DIR}
readonly ATBAPP_PSA_DIR=${CUST_BASE_DIR}${ATBAPP_SYS_DIR}
readonly SYSCONFIG_PSA_DIR=${CUST_BASE_DIR}${SYSCONFIG_SYS_DIR}
readonly ISMASMGR_PSA_DIR=${CUST_BASE_DIR}${ISMASMGR_SYS_DIR}
readonly ATBQT_BIN="ATBQT"
readonly ATBQT_INI="ATBQT.ini"
readonly ISMASMGR_INI="ISMASMgr.ini"
readonly SYSCONF_INI="sysconfig.ini"
readonly SYSCTRL_INI="SystemControl.ini"
readonly TARIFF_CURRENT="tariff.current"
readonly DC="dc2c.bin"
readonly TARIFF_SUMMER="summer_tariff.json"
readonly TARIFF_WINTER="winter_tariff.json"
readonly DC_SYS_DC_FILE="${DC_SYS_DIR}/$DC"
readonly ATBQT_ATB_SYS_BIN_FILE="${ATBAPP_SYS_DIR}/$ATBQT_BIN"
readonly ATBQT_ATB_SYS_INI_FILE="${ATB_SYS_DIR}/$ATBQT_INI"
readonly ATBQT_APP_SYS_INI_FILE="${ATBAPP_SYS_DIR}/$ATBQT_INI"
readonly ATBQT_ETC_SYS_INI_FILE="${ETC_SYS_DIR}/$ATBQT_INI"
readonly ISMASMGRATB_SYS_INI_FILE="${ATB_SYS_DIR}/$ISMASMGR_INI"
readonly ISMASMGRAPP_SYS_INI_FILE="${ISMASMGR_SYS_DIR}/$ISMASMGR_INI"
readonly ISMASMGRETC_SYS_INI_FILE="${ETC_SYS_DIR}/$ISMASMGR_INI"
readonly ISMASMGRSCF_SYS_INI_FILE="${SYSCONFIG_SYS_DIR}/$ISMASMGR_INI"
readonly SYSCONF_ETC_SYS_INI_FILE="${ETC_SYS_DIR}/$SYSCONF_INI"
readonly SYSCONF_ATB_SYS_INI_FILE="${ATB_SYS_DIR}/$SYSCONF_INI"
readonly SYSCONF_SCF_SYS_INI_FILE="${SYSCONFIG_SYS_DIR}/$SYSCONF_INI"
readonly SYSCTRL_ETC_SYS_INI_FILE="${ETC_SYS_DIR}/$SYSCTRL_INI"
readonly SYSCTRL_ATB_SYS_INI_FILE="${ATB_SYS_DIR}/$SYSCTRL_INI"
readonly SYSCTRL_SCF_SYS_INI_FILE="${SYSCONFIG_SYS_DIR}/$SYSCTRL_INI"
# readonly ZONE_FILE="$ETC_SYS_DIR/zone_nr"
readonly CUST_ID_FILE="$ETC_SYS_DIR/cust_nr"
readonly TC_SYS_TC_FILE="${ATBAPP_SYS_DIR}/$TARIFF_CURRENT"
readonly OPKG_CMDS_SYS_FILE="${OPKG_SYS_DIR}/opkg_commands"
readonly DC2C_SYS_SERIAL_JSON="${CONF_SYS_DIR}/DC2C_serial.json"
readonly DC2C_SYS_CASH_JSON="${CONF_SYS_DIR}/DC2C_cash.json"
readonly DC2C_SYS_CONF_JSON="${CONF_SYS_DIR}/DC2C_conf.json"
readonly DC_PSA_DC_FILE="${DC_PSA_DIR}/$DC"
readonly TARIFF_SYS_SUMMER="${TARIFF_SYS_DIR}${TARIFF_SUMMER}"
readonly TARIFF_SYS_WINTER="${TARIFF_SYS_DIR}${TARIFF_WINTER}"
readonly ATBQT_ATB_PSA_INI_FILE="${ATB_PSA_DIR}/$ATBQT_INI"
readonly ATBQT_APP_PSA_INI_FILE="${ATBAPP_PSA_DIR}/$ATBQT_INI"
readonly ATBQT_ETC_PSA_INI_FILE="${ETC_PSA_DIR}/$ATBQT_INI"
readonly ISMASMGRATB_PSA_INI_FILE="${ATB_PSA_DIR}/$ISMASMGR_INI"
readonly ISMASMGRAPP_PSA_INI_FILE="${ISMASMGR_PSA_DIR}/$ISMASMGR_INI"
readonly ISMASMGRETC_PSA_INI_FILE="${ETC_PSA_DIR}/$ISMASMGR_INI"
readonly ISMASMGRSCF_PSA_INI_FILE="${SYSCONFIG_PSA_DIR}/$ISMASMGR_INI"
readonly SYSCONF_ETC_PSA_INI_FILE="${ETC_PSA_DIR}/$SYSCONF_INI"
readonly SYSCONF_ATB_PSA_INI_FILE="${ATB_PSA_DIR}/$SYSCONF_INI"
readonly SYSCONF_SCF_PSA_INI_FILE="${SYSCONFIG_PSA_DIR}/$SYSCONF_INI"
readonly SYSCTRL_ETC_PSA_INI_FILE="${ETC_PSA_DIR}/$SYSCTRL_INI"
readonly SYSCTRL_ATB_PSA_INI_FILE="${ATB_PSA_DIR}/$SYSCTRL_INI"
readonly SYSCTRL_SCF_PSA_INI_FILE="${SYSCONFIG_PSA_DIR}/$SYSCTRL_INI"
readonly OPKG_CMDS_PSA_FILE="${OPKG_PSA_DIR}/opkg_commands"
readonly TC_PSA_TC_FILE="${ATBAPP_PSA_DIR}/$TARIFF_CURRENT"
# readonly PSA_UPDATE_CONF="${CUSTOMER_LOCATION_DIR}/update.conf"
readonly DC2C_PSA_SERIAL_JSON="${CONF_PSA_DIR}/DC2C_serial.json"
readonly DC2C_PSA_CASH_JSON="${CONF_PSA_DIR}/DC2C_cash.json"
readonly DC2C_PSA_CONF_JSON="${CONF_PSA_DIR}/DC2C_conf.json"
assert_d ETC_SYS_DIR
assert_d ATB_SYS_DIR
assert_d DC_SYS_DIR
assert_d TARIFF_SYS_DIR
assert_d OPKG_SYS_DIR
assert_d CONF_SYS_DIR
assert_d OPT_SYS_DIR
assert_d APP_SYS_DIR
assert_d ATBAPP_SYS_DIR
assert_d SYSCONFIG_SYS_DIR
assert_d ISMASMGR_SYS_DIR
assert_d ETC_PSA_DIR
assert_d ATB_PSA_DIR
assert_d DC_PSA_DIR
assert_d TARIFF_PSA_DIR
assert_d OPKG_PSA_DIR
assert_d CONF_PSA_DIR
assert_d OPT_PSA_DIR
assert_d APP_PSA_DIR
assert_d ATBAPP_PSA_DIR
assert_d SYSCONFIG_PSA_DIR
assert_d ISMASMGR_PSA_DIR
assert_f DC_SYS_DC_FILE
assert_f ZONE_FILE
assert_f CUST_ID_FILE
assert_f ATBQT_ATB_SYS_BIN_FILE
assert_f ATBQT_ATB_SYS_INI_FILE
assert_f ATBQT_APP_SYS_INI_FILE
assert_f ATBQT_ETC_SYS_INI_FILE
assert_f ISMASMGRATB_SYS_INI_FILE
assert_f ISMASMGRAPP_SYS_INI_FILE
assert_f ISMASMGRETC_SYS_INI_FILE
assert_f ISMASMGRSCF_SYS_INI_FILE
assert_f SYSCONF_ETC_SYS_INI_FILE
assert_f SYSCONF_ATB_SYS_INI_FILE
assert_f SYSCONF_SCF_SYS_INI_FILE
assert_f SYSCTRL_ETC_SYS_INI_FILE
assert_f SYSCTRL_ATB_SYS_INI_FILE
assert_f SYSCTRL_SCF_SYS_INI_FILE
assert_f TC_SYS_TC_FILE
assert_f OPKG_CMDS_SYS_FILE
assert_f DC2C_SYS_CONF_JSON
assert_f DC2C_SYS_SERIAL_JSON
assert_f DC2C_SYS_CASH_JSON
assert_f DC_PSA_DC_FILE
assert_f ATBQT_ATB_PSA_INI_FILE
assert_f ATBQT_APP_PSA_INI_FILE
assert_f ATBQT_ETC_PSA_INI_FILE
assert_f ISMASMGRATB_PSA_INI_FILE
assert_f ISMASMGRAPP_PSA_INI_FILE
assert_f ISMASMGRETC_PSA_INI_FILE
assert_f ISMASMGRSCF_PSA_INI_FILE
assert_f SYSCONF_ETC_PSA_INI_FILE
assert_f SYSCONF_ATB_PSA_INI_FILE
assert_f SYSCONF_SCF_PSA_INI_FILE
assert_f SYSCTRL_ETC_PSA_INI_FILE
assert_f SYSCTRL_ATB_PSA_INI_FILE
assert_f SYSCTRL_SCF_PSA_INI_FILE
assert_f TC_PSA_TC_FILE
# assert_f PSA_UPDATE_CONF
assert_f OPKG_CMDS_PSA_FILE
assert_f DC2C_PSA_CONF_JSON
assert_f DC2C_PSA_SERIAL_JSON
assert_f DC2C_PSA_CASH_JSON
assert_f OPKG_CMDS_PSA_FILE
readonly KNOWN_SYS_DIRS=($ETC_SYS_DIR
$ATB_SYS_DIR
$DC_SYS_DIR
$TARIFF_SYS_DIR
$OPKG_SYS_DIR
$CONF_SYS_DIR
$OPT_SYS_DIR
$APP_SYS_DIR
$ATBAPP_SYS_DIR
$SYSCONFIG_SYS_DIR)
readonly KNOWN_PSA_DIRS=($ETC_PSA_DIR
$ATB_PSA_DIR
$DC_PSA_DIR
$TARIFF_PSA_DIR
$OPKG_PSA_DIR
$CONF_PSA_DIR
$OPT_PSA_DIR
$APP_PSA_DIR
$ATBAPP_PSA_DIR
$SYSCONFIG_PSA_DIR)
local DC2C_PRINT_JSON=()
for i in {1..32}; do # up to 32 print-json-files
local __f=${CONF_PSA_DIR}/DC2C_print$(printf "%02d" $i).json
readonly DC2C_PRINT$(printf "%02d" $i)_JSON=$__f
assert_f DC2C_PRINT$(printf "%02d" $i)_JSON
DC2C_PRINT_JSON+=($__f)
done
local TARIFF_FILES_JSON=()
for i in {1..32}; do # up to 32 tariff-json-files
local __f=${TARIFF_PSA_DIR}/tariff$(printf "%02d" $i).json
readonly TARIFF$(printf "%02d" $i)_JSON=$__f
assert_f TARIFF$(printf "%02d" $i)_JSON
TARIFF_FILES_JSON+=($__f)
done
readonly KNOWN_CONF_FILES=(${DC2C_PRINT_JSON[@]##*${CUSTOMER_ID}/} \
${DC2C_PSA_CONF_JSON##*${CUSTOMER_ID}/} \
${DC2C_PSA_CASH_JSON##*${CUSTOMER_ID}/} \
${DC2C_PSA_SERIAL_JSON##*${CUSTOMER_ID}/})
readonly KNOWN_TARIFF_FILES=(${TARIFF_FILES_JSON[@]##*${CUSTOMER_ID}/})
readonly KNOWN_INI_FILES=(${ATBAPP_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${ISMASMGRATB_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${ISMASMGRAPP_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${ISMASMGRETC_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${ISMASMGRSCF_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${SYSCONF_ETC_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${SYSCONF_ATB_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${SYSCONF_SCF_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${SYSCTRL_ETC_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${SYSCTRL_ATB_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${SYSCTRL_SCF_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${ATBQT_ATB_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${ATBQT_APP_PSA_INI_FILE##*${CUSTOMER_ID}/} \
${ATBQT_ETC_PSA_INI_FILE##*${CUSTOMER_ID}/})
readonly KNOWN_FILES=(${KNOWN_CONF_FILES[@]} \
${KNOWN_INI_FILES[@]} \
${KNOWN_TARIFF_FILES[@]} \
${DC_PSA_DC_FILE##*${CUSTOMER_ID}/} \
${OPKG_CMDS_PSA_FILE##*${CUSTOMER_ID}/})
# log_debug "known json/ini/hex_files ->"
# for (( i=0; i < ${#KNOWN_FILES[@]}; ++i )); do
# tab=$'\t'
# log_debug "$tab$tab ${KNOWN_FILES[$i]}"
# done
log_debug "sanity of ${CUSTOMER_REPOSITORY_PATH} OK"
# compute version string for current (i.e. previous) version
compute_version
return 0
}
fi

View File

@@ -1,11 +0,0 @@
#M=GH_APP
#C=REQ_ISMASParameter
#J={}
{
"DEV_ID": {
"Device_Type": "2020",
"Custom_ID": 999,
"Device_ID": 1
},
"REQ_ISMASParameter_#1": {}
}

View File

@@ -1,43 +0,0 @@
#!/bin/bash
# set -x
source ./log_helpers
source ./git_helpers
extract_changed_files () {
local func="${FUNCNAME[0]}"
local files=$(changed_files)
local updated_files=""
if [ -z $files ]; then
log_crit "$func:${LINENO} no changed files!"
else
if grep -qE "update.conf" <<< $files ; then
updated_files="${updated_files} update.conf"
if grep -qE "printer.conf" <<< $files ; then
updated_files="${updated_files} printer.conf"
fi
if grep -qE "emp.conf" <<< $files ; then
updated_files="${updated_files} emp.conf"
fi
if grep -qE "device.conf" <<< $files ; then
updated_files="${updated_files} device.conf"
fi
else
log_crit "$func:${LINENO} NO new revision of update.conf"
fi
fi
log_debug "$func:${LINENO} new revisions for $updated_files"
printf "$updated_files"
}
check_md5sum () {
local func="${FUNCNAME[0]}"
fn="/workspace/customer_281/szeged/1/1/etc/psa_config"
}

View File

@@ -1,81 +0,0 @@
#! /bin/bash -
# Implementing update functionality for an PSA.
###############################################################################
#
# UPDATE PSA
# Usage:
# update_psa [ --? ]
# [ -m ]
# [ --help ]
# [ --wdir "working_directory" ]
# [ --file "config_file" ]
# [ --dbg ]
# [ --version ]
#
# ./update_psa --file $PWD/update_psa.conf --wdir $PWD
#
###############################################################################
# if [ $# -eq 0 ]; then
# no parameters given -> nothing to do
# exit 0
#fi
if [ -z $IFS ]; then
IFS=$'\n'
fi
MAINTENANCE="NO"
WORKING_DIRECTORY=${PWD}
# parse commandline parameters
while test $# -gt 0; do
case $1 in
--maintenance | -m )
MAINTENANCE="YES"
;;
--file | --fil | --fi | --f | -file | -fil | -fi | -f )
shift
CONFIGFILENAME="$1"
;;
--zone | --zon | --zo | --z | -zone | -zon | -zo | -z )
shift
ZONE="$1"
;;
--wdir | --wdi | --wd | --w | -wdir | -wdi | -wd | -w )
shift
if [ "$1" = "." ]; then
WORKING_DIRECTORY="$PWD"
else
WORKING_DIRECTORY="$1"
fi
;;
--help | -hel | --he | --h | '--?' | -help | -hel | -he | -h | '-?' )
usage_and_exit 0
;;
--version | --versio | --versi | --vers | --ver | --ve | --v | \
-version | -versio | -versi | -vers | -ver | -ve | -v )
version
exit 0
;;
--dbg | --db | --d | -dbg | -db | -d )
shift
set_dbg_level $DEBUG
;;
-*)
error "Unrecognized option: $1"
;;
*)
break
;;
esac
shift
done
source ./update_psa_impl
if read_config; then
update_psa
exit 0
fi
exit 1
###############################################################################

View File

@@ -1,33 +0,0 @@
{
"" : "use git without certificates",
"GIT_SSL_NO_VERIFY" : 1,
"" : "explicit location of customer-project",
"customer_location" : "szeged",
"" : "unique customer identifier",
"customer_id" : "customer_281",
"" : "zone file for PSA",
"zone" : "/etc/zone_nr",
"" : "local branches",
"local_branches" : ["master",
"zg1/zone1", "zg1/zone2", "zg1/zone3", "zg1/zone4"],
"" : "customer number of PSA",
"customer_id_" : "/etc/cust_nr",
"" : "machine id of PSA",
"machine_nr" : "/etc/mach_nr",
"" : "each location can have multiple",
"" : "zone-groups and/or zones",
"" : "0-index used as size of following array",
"" : ".zg[0]: #n of zones_groups",
"" : ".zg[1].z[0]: #n of zones in zg[1]",
"zg" : [ 1, { "z" : [ 4, 1, 2, 4] } ],
"" : "url of customer repository",
"cust_repository_path" : "https://git.mimbach49.de/GerhardHoffmann/customer_281.git"
}

View File

@@ -1,435 +0,0 @@
#!/bin/bash
# if [ ${git_helpers_sourced:-1} = "1" ]; then
# readonly git_helpers_sourced=${BASH_SOURCE[0]}
#else
# return 0
#fi
source ./general_utils
exec_opkg_command () {
local func="${FUNCNAME[0]}"
log_debug "$func:${LINENO} exec-ing [$*]"
local __result=$(exec_process_substitution $*)
local __result_code=$?
log_debug "$func:${LINENO} result=$__result"
printf '%s' "$__result"
return $__result_code
}
# Fetch/merge updates from predefined repository using git.
#
fetch_customer_updates() {
if ! pull_customer_repository; then
return 1
fi
return 0
}
copy () {
local func="${FUNCNAME[0]}"
local copy_necessary=0
readarray -td' ' files <<< "$1"
for f in ${files[@]}; do
log_debug "$func:${LINENO}: $f"
# $f is determined by git
if [[ "$f" =~ .*update[.]conf.* ]]; then
continue
fi
# TODO: szeged darf nicht sein
# local readonlt __cl=$CUSTOMER_LOCATION
# local readonly __q="'"
# xxx='$('"echo $f | sed -E -e ${__q}s=(.*$__cl/[0-9]/[0-9])(.*)(/.*)=\2=g$__q"')'
# echo $xxx
# eval "echo $xxx"
local readonly __sysdir=$(echo $f |
sed -E -e s'=(.*szeged/[0-9]/[0-9])(.*)(/.*)=\2=g')
# TODO: kuerzen
copy_necessary=1
PERCENT=$((PERCENT+1))
test $PERCENT -gt 100 && PERCENT=100
local readonly __f=${f##*/}
local readonly __m="${CUSTOMER_ID_BASE_DIR}/${f}"
local __p="${__sysdir}/${__f}"
# echo "TEST -> $sysdir/$__f"
# TODO: das kopieren in die system-verzeichnisse muss noch getestet
# werden. stimmt noch nicht so ganz.
#if grep -qE "^.*$DC\s*$" <<< ${f}; then
# __p="${DC_SYS_DIR}/${__f}"
# log_debug "$func:${LINENO}: __m=$__m"
#elif grep -qE "^.*tariff[0-9][0-9][.]json\s*$" <<< ${f}; then
# __p="${TARIFF_SYS_DIR}/${__f}"
#elif grep -qE "^.*[.]json\s*$" <<< ${f}; then
# __p="${CONF_SYS_DIR}/${__f}"
# log_debug "$func:${LINENO}: __m=$__m"
#elif grep -qE "^.*[.]ini\s*$" <<< ${f}; then
# if [ "$__f" = "$ATBQT_INI" ]; then
# log_debug "$func:${LINENO}: __m=$__m $ATB_SYS_DIR/$__f ${f%/*}"
# if grep -qE "$ATB_SYS_DIR" <<< "${f%/*}"; then
# __p="$ATB_SYS_DIR/${__f}"
# else
# __p="$ATBAPP_SYS_DIR/${__f}"
# fi
# elif [ "$__f" = "$SYSTEM_CONTROL_INI" ]; then
# if grep -qE "$ATB_SYS_DIR" <<< "${f%/*}"; then
# __p="$ATB_SYS_DIR/${__f}"
# else
# __p="$SYSCONFIG_SYS_DIR/${__f}"
# fi
# elif [ "$__f" = "$SYS_CONFIG_INI" ]; then
# if grep -qE "$ATB_SYS_DIR" <<< "${f%/*}"; then
# __p="$ATB_SYS_DIR/${__f}"
# else
# __p="$SYSCONFIG_SYS_DIR/${__f}"
# fi
# elif [ "$__f" = "$ISMASMGR_INI" ]; then
# if grep -qE "$ISMASMGR_SYS_DIR" <<< "${f%/*}"; then
# __p="$ISMASMGR_SYS_DIR/${__f}"
# elif grep -qE "$ATB_SYS_DIR" <<< "${f%/*}"; then
# __p="$ATB_SYS_DIR/${__f}"
# else
# __p="$SYSCONFIG_SYS_DIR/${__f}"
# fi
# fi
#fi
echo "XXX-- __p=$__p"
if [ ! -z "$__p" ]; then
if cp "$__m" "$__p"; then
log_info "$func:${LINENO}: cp $__m $__p ok"
update_psa_copy_conf_and_ini_files $UPDATE_ISMAS_PROGRESS \
$RC_SUCCESS "cp $__m $__p ok"
else
log_error "$func:${LINENO}: cp $__m $__p failed: error-code=$?"
update_psa_copy_conf_and_ini_files \
$UPDATE_ISMAS_ERROR $RC_COPY_ERROR "cp $__m $__p failed"
return $?
fi
else
log_error "$func:${LINENO}: __p still empty"
update_psa_copy_conf_and_ini_files \
$UPDATE_ISMAS_ERROR $RC_COPY_ERROR "__p still empty"
EXITCODE=$((EXITCODE+1))
return $EXITCODE
fi
done
if [ $copy_necessary -eq 0 ]; then
update_psa_copy_conf_and_ini_files $UPDATE_ISMAS_PROGRESS $RC_SUCCESS \
"no copy of json/ini-files necessary"
log_debug "$func:${LINENO}: no copy of conf/ini-files necessary"
else
log_debug "$func:${LINENO}: copied *conf/*ini-files to system-dirs"
fi
return 0
}
filter_changed_files () {
local func="${FUNCNAME[0]}"
log_debug "$func:${LINENO} $1"
readarray -td' ' files <<< "$1"
local __system_files=""
for f in ${files[@]}; do
log_debug "$func:${LINENO} $f"
if grep -qE "^.*[.]($2)\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_json_and_ini_files () {
local func="${FUNCNAME[0]}"
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"
local readonly __cl=$CUSTOMER_LOCATION
for file in ${files[@]}; do
# .../szeged/1/1...
log_debug "$func:${LINENO} checking file=${file}..."
local __fs=${file##*.}
js_key=""
case $file in
*.ini | *.json | *.hex)
local __key_suffix=$(echo $file |
sed -E -e 's=(.*[0-9]/[0-9])([^.]+)(.*)=\2=g' -e 's=/=.=g')
js_key=".$__fs.$__cl.zg[$ZONE_GROUP].z[$ZONE]$__key_suffix"
md5sum_update_conf=$(cat $PSA_UPDATE_CONF | jq -r $js_key)
md5sum_repository="$(md5_of $CUSTOMER_ID_BASE_DIR/$file)"
;;
*)
log_crit "$func:${LINENO} unknown file=${file}"
;;
esac
test -z $js_key && continue
PERCENT=$((PERCENT+1))
test $PERCENT -gt 100 && PERCENT=100
if [ "$md5sum_repository" = "$md5sum_update_conf" ]; then
log_info "$func:${LINENO}: md5sum for $file ok"
update_psa_check_hash $UPDATE_ISMAS_PROGRESS $RC_SUCCESS \
"md5sum -|$md5sum_repository|- 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"
update_psa_check_hash $UPDATE_ISMAS_ERROR $RC_HASH_VALUE_ERROR \
"md5sum -|$md5sum_repository|- for $file wrong"
return $?
fi
done
else
log_debug "$func:${LINENO} no changed conf-/ini-files"
fi
return 0
}
check_hardware_compatibility () {
local func="${FUNCNAME[0]}"
# RC_HW_COMPATIBILITY_ERROR=6
update_psa_check_hardware_compatibility $UPDATE_ISMAS_PROGRESS \
$RC_SUCCESS "TODO: hardware compatibility"
return $?
}
check_md5_for_opkg_packages () {
local func="${FUNCNAME[0]}"
local -n opkg_output_ref=$1
local package=""
local md5sum_opkg_info=""
local filename=""
for line in ${opkg_output_ref[@]}; do
log_info "$func:${LINENO}: line=$line"
if grep -qE "^\s*Package\s*:.*?$" <<< "$line"; then
package=${line#*:* }
elif grep -qE "^\s*MD5Sum\s*:.*?$" <<< "$line"; then
md5sum_opkg_info=${line#*:* }
elif grep -qE "^\s*Filename\s*:.*?$" <<< "$line"; then
filename=${line#*:* }
fi
done
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
log_info "$func:${LINENO}: md5 $md5sum_repo OK for $package"
return 0
else
log_error "$func:${LINENO}: md5sum_repo [$md5sum_repo] "\
"!= md5sum_opkg_info [$md5sum_opkg_info] for $package"
fi
else
log_error "$func:${LINENO}: md5sum_repo empty"
fi
return 1
}
# In case the new checked-out files are not correct, revert the git
# repository to its previous state.
#
revert_customer_repository () {
local func="${FUNCNAME[0]}"
# TODO
return 0
}
# Backup before the update-process.
#
backup_previous_version () {
local func="${FUNCNAME[0]}"
# TODO
return 0
}
exec_opkg_info () {
local func="${FUNCNAME[0]}"
log_info "$func:${LINENO}: executing info $1"
opkg_result=$(exec_opkg_command "opkg info $1")
if [ $? -eq 0 ]; then
# make sure the keywords start with '\n'
opkg_result=$(sed -E -e "s/(^.*)(Package)(.*$)/\n\2\3/g"\
-e "s/(^.*)(Version)(.*$)/\1\n\2\3/g"\
-e "s/(^.*)(Depends)(.*$)/\1\n\2\3/g"\
-e "s/(^.*)(Status)(.*$)/\1\n\2\3/g"\
-e "s/(^.*)(Architecture)(.*$)/\1\n\2\3/g"\
-e "s/(^.*)(Maintainer)(.*$)/\1\n\2\3/g"\
-e "s/(^.*)(MD5Sum)(.*$)/\1\n\2\3/g"\
-e "s/(^.*)(Filename)(.*$)/\1\n\2\3/g"\
-e "s/(^.*)(Source)(.*$)/\1\n\2\3/g"\
-e "s/(^.*)(Description)(.*$)/\1\n\2\3/g"\
-e "s/(^.*)(Installed-Size)(.*$)/\1\n\2\3/g"\
-e "s/(^.*)(Section)(.*$)/\1\n\2\3/g"\
-e "s/(^.*[^-])(Size)(.*$)/\1\n\2\3/g"\
-e "s/(^.*)(Installed-Time)(.*$)/\1\n\2\3/g"
<<< "$opkg_result")
local -n output_ref=$2
readarray -d $'\n' output_ref < <(printf '%s' "$opkg_result")
if [ $? -ne 0 ]; then
log_error "$func:${LINENO}: readarray finished with error"
return 1
fi
log_info "$func:${LINENO}: ... done"
# log_info "$func:${LINENO}: opkg_result=${output_ref[@]}"
return 0
fi
log_error "$func:${LINENO}: executing info $1"
return 1
}
# Try to install new opkg-packages (in case the are some
# in the new git-checkout).
#
exec_opkg_noaction() {
local func="${FUNCNAME[0]}"
local opkg_command_no_action="opkg --noaction $1"
log_debug "$func:${LINENO}: executing $opkg_command_no_action"
local __opkg_result=$(exec_opkg_command "opkg --noaction $1")
if [ $? -eq 0 ]; then
log_info "$func:${LINENO}: opkg_result=$__opkg_result"
return 0
fi
log_error "$func:${LINENO}: error executing opkg --noaction $1"
return 1
}
# Install the new packages using opkg.
#
exec_opkg () {
local func="${FUNCNAME[0]}"
log_debug "$func:${LINENO}: executing $1"
local __opkg_result=$(exec_opkg_command "opkg $1")
if [ $? -eq 0 ]; then
log_info "$func:${LINENO}: opkg_result=$__opkg_result"
return 0
fi
log_error "$func:${LINENO}: error executing $1"
return 1
}
# In case there was some error, re-install the previous package(s)
# and use the backup to restore any conf/ini-files.
#
fallback_to_previous_version() {
local func="${FUNCNAME[0]}"
# TODO
return 0;
}
# If all went well, then execute all necessary cleanup steps.
#
cleanup_previous_version() {
local func="${FUNCNAME[0]}"
# TODO
return 0
}
check_for_running_apism () {
local func="${FUNCNAME[0]}"
if nc localhost 7778
then
APISM_RUNNING=1
log_info "$func:${LINENO}: APISM is running..."
return 0
fi
log_fatal "$func:${LINENO}: !!! APISM NOT RUNNING !!!"
}
check_default_route () {
local func="${FUNCNAME[0]}"
if ip route | head -n 1 | grep -q '^default'
then
log_info "$func:${LINENO}: default route set"
return 0
fi
log_fatal "$func:${LINENO}: !!! NO DEFAULT ROUTE SET !!!"
}
check_route_to_repository () {
local func="${FUNCNAME[0]}"
# ip_address=$1, e.g. git.mimbach.de (185.191.219.134)
# 185.191.219.134 via 192.168.5.254 ...
if test "$#" -eq 1 && ip route get "$1" | head -n 1 | grep -q "^$1"
then
log_info "$func:${LINENO}: route to repository available"
return 0
fi
log_fatal "$func:${LINENO}: !!! NO ROUTE TO REPO SET !!!"
}
get_customer_id () {
echo $(cat CUST_ID_FILE)
}
get_zone_nr () {
echo $(cat ZONE_FILE)
}
get_plugins () {
local __plugins=""
for __f in /opt/app/ATBAPP/plugins/*; do
local plugin=$__f
plugins+="
\"${plugin##*/}\": {
"
plugins+=$(strings $__f |
grep -A4 \"Interface\": |
grep \"Version\" |
sed -E -e 's/^\s*/\n/g')
# remove trailing ',' which is already contained in returned value
plugins=${plugins/%,}
plugins+="
},"
done
printf '%s' ${plugins/%,}
}
# get_plugins

View File

@@ -1,80 +0,0 @@
# !/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
trap collect_current_configuration EXIT
collect_current_configuration () {
local func="${FUNCNAME[0]}"
$FATAL_FAILURE && return 1
# TODO: eventuell muss die version neu berechnet werden
current_settings_to_ismas
#for line in $(cat $PSA_UPDATE_CONF |\
# jq -r .conf.szeged.zg[$ZONE_GROUP].z[$ZONE].etc.psa_config)
#do
# conf_file="$(echo $line |
# sed -E -ne 's/^[^{}]\s+\"(DC2C_[[:alnum:]]+)\".*$/\1/gp')"
# if ! [ -z $conf_file ]; then
# local v=$(cat "$psa_config_dir/${conf_file}.json" | jq -r .version)
# echo "$conf_file.json version=$v"
# fi
#done
}
update_psa() {
update_psa_activated # message to ISMAS
local func="${FUNCNAME[0]}"
check_default_route
check_route_to_repository "185.191.219.134" # git.mimbach.de
# even for a git clone a running APISM is needed
check_for_running_apism
# an initial clone of the customer-repository (e.g. customer_281) is
# always possible, even without a ISMAS-WAIT-button
clone_customer_repository ${CUSTOMER_REPOSITORY_PATH}
check_sanity_of_repository
$INITIAL_CLONE && return 0
if [ "$MAINTENANCE" = "NO" ]; then
log_info "update_psa:${LINENO}: MAINTENANCE OFF. Checking for updates..."
# someone must have activated the WAIT-button in ISMAS.
# Request the status of this button in updates_available().
if ! updates_available; then
update_psa_false_alarm "update requested, but no WAIT state detected !!!"
log_fatal "update_psa:${LINENO}: update requested, but no WAIT state detected !!!"
fi
else
# simulate an activated WAIT-button
set_updates_available
while :
do
sleep 5
updates_available && break
done
fi
log_debug "$func:${LINENO}: fetch/merge updates..."
# Fetch new updates (using git). but only when repository has already been
# cloned.
if ! fetch_customer_updates; then
log_error "$func:${LINENO}: fetch no data for $customer_id"\
"-> no files to update -> no psa update"
update_psa_false_alarm \
"update request, but no change in $CUSTOMER_REPOSITORY_PATH"
# TODO
fi
update_psa_pull_customer_repository # message to ISMAS
}