Compare commits

..

No commits in common. "master" and "szeged_preview_20230607" have entirely different histories.

10 changed files with 280 additions and 334 deletions

View File

@ -115,12 +115,4 @@ if [ "${general_utils_sourced:-1}" = "1" ]; then # include only once
# log_debug "$1=$__n" # log_debug "$1=$__n"
: :
} }
empty_file () {
if [[ -f "$1" ]]; then
echo -n "" > $1
else
log_error "$1 does not exist"
fi
}
fi fi

View File

@ -57,18 +57,6 @@ revert_to_commit_before_pull () {
} }
# revert_to_commit_before_pull # 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. # clone the customer repository in ./workspace.
# this is done only once. # this is done only once.
# #
@ -82,106 +70,99 @@ git_customer_branch () {
# #
clone_customer_repository () { clone_customer_repository () {
local func="${FUNCNAME[0]}" local func="${FUNCNAME[0]}"
if [ "$PWD" != "$WORKING_DIRECTORY" ]; then if [ "$PWD" = "$WORKING_DIRECTORY" ]; then
log_fatal "$func:${LINENO} PD != WD ($PWD != $WORKING_DIRECTORY)"
fi
mkdir -p "./$WORKSPACE_DIR" mkdir -p "./$WORKSPACE_DIR"
# check if the directory is empty. If so, clone the # check if the directory is empty. If so, clone the
# customer repository # customer repository
if ! find ./$WORKSPACE_DIR -mindepth 1 -maxdepth 1 | read; then if ! find ./$WORKSPACE_DIR -mindepth 1 -maxdepth 1 | read; then
log_info "$func:${LINENO} cloning ${1} into ${PWD}/${WORKSPACE_DIR}..." log_debug "$func:${LINENO} cloning ${1} ..."
if ! cd "./$WORKSPACE_DIR"; then if cd "./$WORKSPACE_DIR"
update_psa_clone_error # message to ISMAS then
log_fatal "$func:${LINENO} can not change to $WORKSPACE_DIR" $(exec_git_command git clone "$1")
fi if [ $? -eq 0 ]; then
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" log_debug "$func:${LINENO} cloning ${1} done"
GIT_CLONE_EXECUTED=1
rm -f $GIT_PULL_TMP
rm -f $OPKG_CMDS_TMP
# after cloning, cd into repository, and re-initialize, # after cloning, cd into repository, and re-initialize,
# setting the work-tree as "/". This has the effect that # setting the work-tree as "/". This has the effect that
# a "git pull" will automatically fetched files in the # a "git pull" will automatically fetched files in the
# corresponding sytem-folders. # corresponding sytem-folders.
####################### CD INTO REPOSITORY ########################## if cd ${CUSTOMER_ID_BASE_DIR}; then
if ! cd ${CUSTOMER_ID_BASE_DIR}; then # local res=$(exec_git_command git --git-dir=.git --work-tree=/ init)
update_psa_clone_error # message to ISMAS exec_git_command git checkout "$LOCAL_BRANCH"
log_fatal "$func:${LINENO} can not change to $CUSTOMER_ID_BASE_DIR" if [[ $? -eq 0 ]]; then
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" log_debug "$func:${LINENO} checked out local branch $LOCAL_BRANCH"
######################## CONFIGURE WORKTREE ########################## exec_git_command git config core.worktree "/"
if ! exec_git_command git config core.worktree "/"; then if [[ $? -eq 0 ]]; then
update_psa_clone_error # message to ISMAS log_debug "$func:${LINENO} configured worktree"
log_fatal "$func:${LINENO} can not configure worktree '/'" exec_git_command git fetch --all
fi if [[ $? -eq 0 ]]; then
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" log_debug "$func:${LINENO} fetch repository"
########################## RE-INIT REPOSITORY ######################## exec_git_command git reset --hard "$LOCAL_BRANCH"
if ! exec_git_command git reset --hard "$LOCAL_BRANCH"; then if [[ $? -eq 0 ]]; 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" log_debug "$func:${LINENO} reset --hard $LOCAL_BRANCH"
INITIAL_CLONE=true # re-initialized. copy post-merge (a hook called
# when 'git pull' is executed and changed data
# are received).
if cp ".githooks/post-merge" ".git/hooks"; then
log_debug "$func:${LINENO} copied post-merge to .git/hooks"
CLONE_CUSTOMER_REPOSITORY=true
log_debug "$func:${LINENO} re-init of ${1} done" log_debug "$func:${LINENO} re-init of ${1} done"
update_psa_clone_customer_repository cd_home; return 0
fi
fi
fi
fi
fi
fi
fi
cd_home; return 1
fi
else else
# the directory is not empty, so we assume the # the directory is not empty, so we assume the
# customer-repository has been cloned already # customer-repository has been cloned already
if ! [[ -d "./${WORKSPACE_DIR}/$CUSTOMER_ID" ]]; then if ! [[ -d "./${WORKSPACE_DIR}/$CUSTOMER_ID" ]]; then
log_fatal "$func:${LINENO} $PWD $WORKSPACE_DIR/$CUSTOMER_ID"\ log_fatal "$func:${LINENO} $PWD $WORKSPACE_DIR/$CUSTOMER_ID"\
"wrong repository: $(ls -d './${WORKSPACE_DIR}/*')" "wrong repository: $(ls -d './${WORKSPACE_DIR}/*')"
fi else
local __m="./${WORKSPACE_DIR}/$CUSTOMER_ID exists" local __m="./${WORKSPACE_DIR}/$CUSTOMER_ID exists"
log_info "$func:${LINENO} $__m, no clone necessary" log_debug "$func:${LINENO} $__m"
return 0
fi
fi
fi fi
cd_home update_psa_clone_error # message to ISMAS
return $?
log_info "$func:${LINENO} nach cd_home $PWD"
} }
# clone_customer_repository -> # clone_customer_repository ->
# https://git.mimbach49.de/GerhardHoffmann/customer_281.git # https://git.mimbach49.de/GerhardHoffmann/customer_281.git
cd_customer_repository () { cd_customer_repository () {
local func="${FUNCNAME[0]}" local func="${FUNCNAME[0]}"
# has to be called in WORKING_DIRECTORY
if [ "$PWD" != "$WORKING_DIRECTORY" ]; then cd "$WORKING_DIRECTORY"
log_fatal "$func:${LINENO} PD != WD ($PWD != $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
fi fi
if ! [[ -d "$CUSTOMER_ID_BASE_DIR" ]]; then if ! { cd $repository_dir; } ; then
log_fatal "$func:${LINENO}: $CUSTOMER_ID_BASE_DIR does not exist!" log_crit "$func:${LINENO}: cannot cd to $repository_dir!"
return 1
fi fi
if ! cd "$CUSTOMER_ID_BASE_DIR"; then log_debug "$func:${LINENO}: cd to $repository_dir!"
log_fatal "$func:${LINENO}: cannot cd to $CUSTOMER_ID_BASE_DIR !!!"
fi
log_debug "$func:${LINENO}: cd to $CUSTOMER_ID_BASE_DIR"
return 0 return 0
fi
return 1
} }
cd_home () { cd_home () {
if cd "$WORKING_DIRECTORY" &>/dev/null ; then if cd - &>/dev/null ; then
return 0 return 0
fi fi
return 1 return 1
@ -194,19 +175,26 @@ pull_customer_repository () {
return 1 return 1
fi fi
log_crit "$func:${LINENO}: executing 'git pull'..." #local commit_before_pull=$(latest_commit)
#if [ -z $commit_before_pull ]; then
# log_warn "$func:${LINENO}: commit_before_pull empty"
# cd_home ; return 1
#fi
#log_debug "$func:${LINENO}: commit_before_pull=$commit_before_pull"
rm -f "$OPKG_CMDS_TMP"
rm -f "$GIT_PULL_TMP"
log_debug "$func:${LINENO}: executing 'git pull'..."
exec_git_command 'git pull' exec_git_command 'git pull'
# GIT_UPDATE_LOG updated by hook post-merge. it contains the names of the # GIT_PULL_TMP created by hook post-merge. it contains the names of the
# changed files or opkg-commands to execute. # changed files.
# If 'git pull' has fetched new data, then there are lines starting with if [[ -f $GIT_PULL_TMP ]]; then
# 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 cd_home; return 0
fi fi
log_warn "$func:${LINENO}: no data fetched from repository" log_warn "$func:${LINENO}: no data fetched form repository"
cd_home; return 1 cd_home; return 1
} }
# pull_customer_repository customer_281 # pull_customer_repository customer_281
@ -236,20 +224,4 @@ changed_file_names () {
"while in $PWD" "while in $PWD"
fi fi
} }
# 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,6 +1,10 @@
#!/bin/bash #!/bin/bash
# set -x # set -x
RED='\e[0;31m'
GREEN='\e[0;32m'
NC='\e[0m' # No Color
if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
readonly log_helpers_sourced=${BASH_SOURCE[0]} readonly log_helpers_sourced=${BASH_SOURCE[0]}
@ -17,8 +21,7 @@ if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
readonly FATAL=5 readonly FATAL=5
readonly MAX_DEBUG_LEVEL=6 readonly MAX_DEBUG_LEVEL=6
log_level=$INFO log_level=0
FATAL_FAILURE=false
set_dbg_level () { set_dbg_level () {
if [ $1 < $MAX_DEBUG_LEVEL ]; then if [ $1 < $MAX_DEBUG_LEVEL ]; then
@ -30,61 +33,50 @@ if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
return $log_level return $log_level
} }
log_to_file() { log() {
if [[ $(("$(wc -l < $log_file)")) -ge $((100000)) ]]; then if [[ $(("$(wc -l < $log_file)")) -ge $((100000)) ]]; then
# remove first line # remove first line
sed -e 1d -i $log_file sed -e 1d -i $log_file
fi fi
local msg="$(date +'%Y-%m-%d_%T'): $*" local msg="$(date +'%Y-%m-%d_%T'): $*"
echo "log:$msg" >&2
echo "$msg" >> $log_file echo "$msg" >> $log_file
} }
log() {
local msg="$(date +'%Y-%m-%d_%T'): $*"
echo "log:$msg" >&2
}
log_debug() { log_debug() {
log_to_file "DEBUG $*" if [ $log_level = $DEBUG ]; then
if [ $log_level -le $DEBUG ]; then
log "DEBUG $*" log "DEBUG $*"
fi fi
} }
log_info() { log_info() {
log_to_file "INFO $*"
if [ $log_level -le $INFO ]; then if [ $log_level -le $INFO ]; then
log "INFO $*" log "${GREEN}INFO $*"
fi fi
} }
log_warn() { log_warn() {
log_to_file "WARN $*"
if [ $log_level -le $WARN ]; then if [ $log_level -le $WARN ]; then
log "WARN $*" log "${RED}WARN $*"
fi fi
} }
log_crit() { log_crit() {
log_to_file "CRIT $*"
if [ $log_level -le $CRIT ]; then if [ $log_level -le $CRIT ]; then
log "CRIT $*" log "${RED}CRIT $*"
fi fi
} }
log_error() { log_error() {
log_to_file "ERROR $*"
if [ $log_level -le $ERROR ]; then if [ $log_level -le $ERROR ]; then
log "ERROR $*" log "${RED}ERROR $*"
fi fi
} }
log_fatal() { log_fatal() {
log_to_file "FATAL $*"
if [ $log_level -le $FATAL ]; then if [ $log_level -le $FATAL ]; then
log "FATAL $*" log "${RED}FATAL $*"
log "exiting ..." log "${RED}exiting ..."
FATAL_FAILURE=true
exit 1 exit 1
fi fi
} }

View File

@ -2,34 +2,19 @@
source ./log_helpers source ./log_helpers
if [ "${news_from_ismas_sourced:-1}" = "1" ]; then # include only once if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
readonly news_from_ismas_sourced=${BASH_SOURCE[0]}
readonly APISM_DIRECT_PORT=7778 readonly APISM_DIRECT_PORT=7778
updates_available () { updates_available () {
local func="${FUNCNAME[0]}" local func="${FUNCNAME[0]}"
local json_response="$((echo -n '#M=APISM #C=REQ_ISMASParameter #J={}'; local json_response="$((echo -n '#M=APISM #C=REQ_ISMASParameter #J={}';
sleep 5) | nc localhost $APISM_DIRECT_PORT)" sleep 1) | nc localhost $APISM_DIRECT_PORT)"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
local trigger="$(echo $json_response | jq -r .Fileupload.TRG)" local trigger="$(echo $json_response | jq -r .Fileupload.TRG)"
local ismas_device_id="$(echo $json_response | jq -r .Dev_ID.Device_ID)" log_debug "$func:${LINENO}: apism_trigger=\"$trigger\""
local machine_nr=$(cat "/etc/machine_nr") grep -qE "WAIT" <<< "$trigger" && return 0
log_info "$func:${LINENO}: json_response=$json_response"
log_info "$func:${LINENO}: apism_trigger=<$trigger> device_id=<$ismas_device_id> machine_nr=<$machine_nr>"
if [ ! -z "$ismas_device_id" -a "$ismas_device_id" != " " ]; then
if [ ! -z "$machine_nr" -a "$machine_nr" != " " ]; then
if [ "$ismas_device_id" != "$machine_nr" ]; then
log_error "$func:${LINENO}: ISMAS DEVICE ID <$ismas_deviceId> != LOCAL_MACHINE_NUMBER <$machine_nr>"
return 1
fi
fi
fi
if grep -qE "WAIT" <<< "$trigger"; then
log_info "$func:${LINENO}: FOUND WAIT TRIGGER"
return 0
fi
else else
log_error "$func:${LINENO}: APISM REQUEST FAILED" log_error "$func:${LINENO}: apism request failed"
fi fi
return 1 return 1
} }
@ -37,11 +22,11 @@ if [ "${news_from_ismas_sourced:-1}" = "1" ]; then # include only once
update_status () { update_status () {
local func="${FUNCNAME[0]}" local func="${FUNCNAME[0]}"
local json_response="$((echo -n '#M=APISM #C=REQ_ISMASParameter #J={}'; local json_response="$((echo -n '#M=APISM #C=REQ_ISMASParameter #J={}';
sleep 5) | nc localhost $APISM_DIRECT_PORT)" sleep 1) | nc localhost $APISM_DIRECT_PORT)"
local trigger="" local trigger=""
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
trigger="$(echo $json_response | jq -r .Fileupload.TRG)" trigger="$(echo $json_response | jq -r .Fileupload.TRG)"
log_info "$func:${LINENO}: apism_trigger=<$trigger>" log_debug "$func:${LINENO}: apism_trigger=\"$trigger\""
else else
log_error "$func:${LINENO}: apism request failed" log_error "$func:${LINENO}: apism request failed"
fi fi

View File

@ -2,8 +2,7 @@
source ./log_helpers source ./log_helpers
if [ "${news_to_ismas_sourced:-1}" = "1" ]; then # include only once 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 APISM_DB_PORT=7777
readonly UPDATE_ISMAS_PROGRESS="U0010" readonly UPDATE_ISMAS_PROGRESS="U0010"
@ -71,18 +70,6 @@ if [ "${news_to_ismas_sourced:-1}" = "1" ]; then # include only once
########################################################################### ###########################################################################
########################################################################### ###########################################################################
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 () { update_psa_pull_customer_repository () {
PERCENT=10 PERCENT=10
local params=("U0010" # event local params=("U0010" # event
@ -395,7 +382,8 @@ if [ "${news_to_ismas_sourced:-1}" = "1" ]; then # include only once
\"CREATED\":\"$(date +%Y-%m-%dT%T)\", \"CREATED\":\"$(date +%Y-%m-%dT%T)\",
\"HASH\":\"$(compute_hash)\" \"HASH\":\"$(compute_hash)\"
}, },
\"TARIFF\" : { \"TARIFF\": {
$(<$TC_PSA_TC_FILE)
}, },
\"HARDWARE\" : { \"HARDWARE\" : {
\"DEVICES\" : [ \"DEVICES\" : [
@ -424,10 +412,10 @@ if [ "${news_to_ismas_sourced:-1}" = "1" ]; then # include only once
\"RAUC\" : \"$(rauc --version)\", \"RAUC\" : \"$(rauc --version)\",
\"OPKG\" : \"$(opkg --version)\", \"OPKG\" : \"$(opkg --version)\",
\"ATBQT\" : { \"ATBQT\" : {
\"VERSION\" : \"$(/opt/app/ATBAPP/ATBQT -v | \"VERSION\" : \"$($ATBQT_ATB_SYS_BIN_FILE -v |
grep Version | grep Version |
sed -E -e 's/.*:\s*(.*)/\1/g')\", sed -E -e 's/.*:\s*(.*)/\1/g')\",
\"GIT_DESCRIBE\" : \"$(/opt/app/ATBAPP/ATBQT -v | \"GIT_DESCRIBE\" : \"$($ATBQT_ATB_SYS_BIN_FILE -v |
grep git | grep git |
sed -E -e 's/.*:\s*(.*)/\1/g')\" sed -E -e 's/.*:\s*(.*)/\1/g')\"
}, },

View File

@ -22,21 +22,22 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
readonly UPDATEPSABEGIN=./.updatepsa/begin readonly UPDATEPSABEGIN=./.updatepsa/begin
readonly UPDATEPSAEND=./.updatepsa/end readonly UPDATEPSAEND=./.updatepsa/end
# name of file containing the logs following a 'git pull': readonly OPKG_CMDS_TMP=/tmp/opkg_commands
# basically, there are two kinds of entries: readonly GIT_PULL_TMP=/tmp/git_pull
readonly GIT_UPDATE_LOG=/opt/app/tools/atbupdate/update_log.csv
readonly PROGRAM=`basename $0` readonly PROGRAM=`basename $0`
readonly WORKSPACE_DIR=workspace readonly WORKSPACE_DIR=workspace
GIT_CLONE_EXECUTED=0
EXITCODE=$RC_SUCCESS EXITCODE=$RC_SUCCESS
INITIAL_CLONE=false CLONE_CUSTOMER_REPOSITORY=false
APISM_RUNNING=0
# read config file (JSON syntax) # read config file (JSON syntax)
read_config() { read_config() {
local func="${FUNCNAME[0]}" local func="${FUNCNAME[0]}"
WORKING_DIRECTORY=${PWD}
CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'} CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'}
if ! [ -f "$CONFIGFILENAME" ]; then if ! [ -f "$CONFIGFILENAME" ]; then
@ -48,6 +49,13 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
local readonly cf="$CONFIGFILENAME" local readonly cf="$CONFIGFILENAME"
### TODO: wieso wird hier in das verzeichnis gewechselt
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)" readonly GIT_SSL_NO_VERIFY="$(cat "$cf" | jq -r .GIT_SSL_NO_VERIFY)"
assert_s GIT_SSL_NO_VERIFY assert_s GIT_SSL_NO_VERIFY
@ -88,23 +96,10 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
# Zone aus /etc/zone_nr auslesen # Zone aus /etc/zone_nr auslesen
# #
readonly ZONE_GROUP=1 readonly ZONE_GROUP=1
local __zone=1 readonly 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])" 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 return 0
} }
############################################################################### ###############################################################################
@ -133,10 +128,6 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
check_sanity_of_repository () { check_sanity_of_repository () {
local func="${FUNCNAME[0]}" 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 assert_d CUSTOMER_ID_BASE_DIR
CUSTOMER_LOCATION_DIR="$CUSTOMER_ID_BASE_DIR" CUSTOMER_LOCATION_DIR="$CUSTOMER_ID_BASE_DIR"
@ -168,6 +159,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
# readonly CUST_BASE_DIRS=(${__customer_base_dirs[@]}) # readonly CUST_BASE_DIRS=(${__customer_base_dirs[@]})
# assert_a CUST_BASE_DIRS # assert_a CUST_BASE_DIRS
readonly CUST_BASE_DIR="$CUSTOMER_ID_BASE_DIR" readonly CUST_BASE_DIR="$CUSTOMER_ID_BASE_DIR"
#readonly CUST_BASE_DIR="${CUST_BASE_DIRS[$ZONE]}" #readonly CUST_BASE_DIR="${CUST_BASE_DIRS[$ZONE]}"
#assert_d CUST_BASE_DIR #assert_d CUST_BASE_DIR
@ -201,7 +193,10 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
readonly ISMASMGR_INI="ISMASMgr.ini" readonly ISMASMGR_INI="ISMASMgr.ini"
readonly SYSCONF_INI="sysconfig.ini" readonly SYSCONF_INI="sysconfig.ini"
readonly SYSCTRL_INI="SystemControl.ini" readonly SYSCTRL_INI="SystemControl.ini"
readonly DC="dc2c.bin" readonly TARIFF_CURRENT="tariff.current"
readonly DC="dc2c.hex"
readonly TARIFF_SUMMER="summer_tariff.json"
readonly TARIFF_WINTER="winter_tariff.json"
readonly DC_SYS_DC_FILE="${DC_SYS_DIR}/$DC" readonly DC_SYS_DC_FILE="${DC_SYS_DIR}/$DC"
readonly ATBQT_ATB_SYS_BIN_FILE="${ATBAPP_SYS_DIR}/$ATBQT_BIN" readonly ATBQT_ATB_SYS_BIN_FILE="${ATBAPP_SYS_DIR}/$ATBQT_BIN"
@ -218,13 +213,16 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
readonly SYSCTRL_ETC_SYS_INI_FILE="${ETC_SYS_DIR}/$SYSCTRL_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_ATB_SYS_INI_FILE="${ATB_SYS_DIR}/$SYSCTRL_INI"
readonly SYSCTRL_SCF_SYS_INI_FILE="${SYSCONFIG_SYS_DIR}/$SYSCTRL_INI" readonly SYSCTRL_SCF_SYS_INI_FILE="${SYSCONFIG_SYS_DIR}/$SYSCTRL_INI"
# readonly ZONE_FILE="$ETC_SYS_DIR/zone_nr" readonly ZONE_FILE="$ETC_SYS_DIR/zone_nr"
readonly CUST_ID_FILE="$ETC_SYS_DIR/cust_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 OPKG_CMDS_SYS_FILE="${OPKG_SYS_DIR}/opkg_commands"
readonly DC2C_SYS_SERIAL_JSON="${CONF_SYS_DIR}/DC2C_serial.json" 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_CASH_JSON="${CONF_SYS_DIR}/DC2C_cash.json"
readonly DC2C_SYS_CONF_JSON="${CONF_SYS_DIR}/DC2C_conf.json" readonly DC2C_SYS_CONF_JSON="${CONF_SYS_DIR}/DC2C_conf.json"
readonly DC_PSA_DC_FILE="${DC_PSA_DIR}/$DC" 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_ATB_PSA_INI_FILE="${ATB_PSA_DIR}/$ATBQT_INI"
readonly ATBQT_APP_PSA_INI_FILE="${ATBAPP_PSA_DIR}/$ATBQT_INI" readonly ATBQT_APP_PSA_INI_FILE="${ATBAPP_PSA_DIR}/$ATBQT_INI"
@ -240,6 +238,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
readonly SYSCTRL_ATB_PSA_INI_FILE="${ATB_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 SYSCTRL_SCF_PSA_INI_FILE="${SYSCONFIG_PSA_DIR}/$SYSCTRL_INI"
readonly OPKG_CMDS_PSA_FILE="${OPKG_PSA_DIR}/opkg_commands" 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 PSA_UPDATE_CONF="${CUSTOMER_LOCATION_DIR}/update.conf"
readonly DC2C_PSA_SERIAL_JSON="${CONF_PSA_DIR}/DC2C_serial.json" 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_CASH_JSON="${CONF_PSA_DIR}/DC2C_cash.json"
@ -286,6 +285,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
assert_f SYSCTRL_ETC_SYS_INI_FILE assert_f SYSCTRL_ETC_SYS_INI_FILE
assert_f SYSCTRL_ATB_SYS_INI_FILE assert_f SYSCTRL_ATB_SYS_INI_FILE
assert_f SYSCTRL_SCF_SYS_INI_FILE assert_f SYSCTRL_SCF_SYS_INI_FILE
assert_f TC_SYS_TC_FILE
assert_f OPKG_CMDS_SYS_FILE assert_f OPKG_CMDS_SYS_FILE
assert_f DC2C_SYS_CONF_JSON assert_f DC2C_SYS_CONF_JSON
assert_f DC2C_SYS_SERIAL_JSON assert_f DC2C_SYS_SERIAL_JSON
@ -305,6 +305,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
assert_f SYSCTRL_ETC_PSA_INI_FILE assert_f SYSCTRL_ETC_PSA_INI_FILE
assert_f SYSCTRL_ATB_PSA_INI_FILE assert_f SYSCTRL_ATB_PSA_INI_FILE
assert_f SYSCTRL_SCF_PSA_INI_FILE assert_f SYSCTRL_SCF_PSA_INI_FILE
assert_f TC_PSA_TC_FILE
# assert_f PSA_UPDATE_CONF # assert_f PSA_UPDATE_CONF
assert_f OPKG_CMDS_PSA_FILE assert_f OPKG_CMDS_PSA_FILE
assert_f DC2C_PSA_CONF_JSON assert_f DC2C_PSA_CONF_JSON

View File

@ -5,7 +5,6 @@
# UPDATE PSA # UPDATE PSA
# Usage: # Usage:
# update_psa [ --? ] # update_psa [ --? ]
# [ -m ]
# [ --help ] # [ --help ]
# [ --wdir "working_directory" ] # [ --wdir "working_directory" ]
# [ --file "config_file" ] # [ --file "config_file" ]
@ -24,15 +23,9 @@ if [ -z $IFS ]; then
IFS=$'\n' IFS=$'\n'
fi fi
MAINTENANCE="NO"
WORKING_DIRECTORY=${PWD}
# parse commandline parameters # parse commandline parameters
while test $# -gt 0; do while test $# -gt 0; do
case $1 in case $1 in
--maintenance | -m )
MAINTENANCE="YES"
;;
--file | --fil | --fi | --f | -file | -fil | -fi | -f ) --file | --fil | --fi | --f | -file | -fil | -fi | -f )
shift shift
CONFIGFILENAME="$1" CONFIGFILENAME="$1"
@ -43,11 +36,7 @@ while test $# -gt 0; do
;; ;;
--wdir | --wdi | --wd | --w | -wdir | -wdi | -wd | -w ) --wdir | --wdi | --wd | --w | -wdir | -wdi | -wd | -w )
shift shift
if [ "$1" = "." ]; then
WORKING_DIRECTORY="$PWD"
else
WORKING_DIRECTORY="$1" WORKING_DIRECTORY="$1"
fi
;; ;;
--help | -hel | --he | --h | '--?' | -help | -hel | -he | -h | '-?' ) --help | -hel | --he | --h | '--?' | -help | -hel | -he | -h | '-?' )
usage_and_exit 0 usage_and_exit 0
@ -58,7 +47,6 @@ while test $# -gt 0; do
exit 0 exit 0
;; ;;
--dbg | --db | --d | -dbg | -db | -d ) --dbg | --db | --d | -dbg | -db | -d )
shift
set_dbg_level $DEBUG set_dbg_level $DEBUG
;; ;;
-*) -*)
@ -71,23 +59,28 @@ while test $# -gt 0; do
shift shift
done done
if [ -z "$WORKING_DIRECTORY" ]; then if cd "$WORKING_DIRECTORY"; then
echo "WORKING_DIRECTORY empty. exiting..." source ./update_psa_impl
exit 1
fi
if [ ! -d "$WORKING_DIRECTORY" ]; then if read_config
echo "WORKING_DIRECTORY $WORKING_DIRECTORY does not exist! exiting..." then
exit 1 if clone_customer_repository ${CUSTOMER_REPOSITORY_PATH}
fi then
check_sanity_of_repository
cd "$WORKING_DIRECTORY" #set_updates_available
#while :
#do
# sleep 5
# updates_available && break
#done
source ./update_psa_impl # update_psa "testing"
if read_config; then
update_psa update_psa
fi
fi
exit 0 exit 0
fi fi
exit 1
exit -1
############################################################################### ###############################################################################

View File

@ -13,20 +13,20 @@
"" : "local branches", "" : "local branches",
"local_branches" : ["master", "local_branches" : ["master",
"zg1/zone1", "zg1/zone2", "zg1/zone3", "zg1/zone4"], "zg1/zone1", "zg1/zone2", "zg1/zone3"],
"" : "customer number of PSA", "" : "customer number of PSA",
"customer_id_" : "/etc/cust_nr", "customer_id_" : "/etc/cust_nr",
"" : "machine id of PSA", "" : "machine id of PSA",
"machine_nr" : "/etc/machine_nr", "machine_nr" : "/etc/mach_nr",
"" : "each location can have multiple", "" : "each location can have multiple",
"" : "zone-groups and/or zones", "" : "zone-groups and/or zones",
"" : "0-index used as size of following array", "" : "0-index used as size of following array",
"" : ".zg[0]: #n of zones_groups", "" : ".zg[0]: #n of zones_groups",
"" : ".zg[1].z[0]: #n of zones in zg[1]", "" : ".zg[1].z[0]: #n of zones in zg[1]",
"zg" : [ 1, { "z" : [ 4, 1, 2, 4] } ], "zg" : [ 1, { "z" : [ 3, 1, 2, 3] } ],
"" : "url of customer repository", "" : "url of customer repository",
"cust_repository_path" : "https://git.mimbach49.de/GerhardHoffmann/customer_281.git" "cust_repository_path" : "https://git.mimbach49.de/GerhardHoffmann/customer_281.git"

View File

@ -24,12 +24,9 @@ exec_opkg_command () {
# Fetch/merge updates from predefined repository using git. # Fetch/merge updates from predefined repository using git.
# #
fetch_customer_updates() { fetch_customer_updates() {
local func="${FUNCNAME[0]}"
if ! pull_customer_repository; then if ! pull_customer_repository; then
log_warn "$func:${LINENO} NO pull_customer_repository"
return 1 return 1
fi fi
log_debug "$func:${LINENO} pull_customer_repository SUCCESS"
return 0 return 0
} }
@ -376,37 +373,8 @@ cleanup_previous_version() {
return 0 return 0
} }
check_for_running_apism () { check_for_apism () {
local func="${FUNCNAME[0]}" nc localhost 7778
if nc localhost 7777
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 () { get_customer_id () {

View File

@ -13,8 +13,6 @@ trap collect_current_configuration EXIT
collect_current_configuration () { collect_current_configuration () {
local func="${FUNCNAME[0]}" local func="${FUNCNAME[0]}"
$FATAL_FAILURE && return 1
# TODO: eventuell muss die version neu berechnet werden # TODO: eventuell muss die version neu berechnet werden
current_settings_to_ismas current_settings_to_ismas
@ -30,63 +28,120 @@ collect_current_configuration () {
#done #done
} }
update_psa() { update_psa() { # calling with a parameter is used for testing
if [ $# -eq 0 ]; then
if ! updates_available; then # check for false alarm
update_psa_false_alarm "update requested, but no WAIT state detected"
exit $EXITCODE
fi
fi
update_psa_activated # message to ISMAS update_psa_activated # message to ISMAS
local func="${FUNCNAME[0]}" local func="${FUNCNAME[0]}"
check_default_route log_debug "$func:${LINENO}: fetch/merge updates..."
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
local ismas_requests=0
if [ "$MAINTENANCE" = "NO" ]; then
log_info "${func}:${LINENO}: MAINTENANCE OFF. Checking for updates..."
# someone must have activated the WAIT-button in ISMAS.
# Request the status of this button in updates_available().
while [ $ismas_requests -le 3 ]; do
ismas_requests=$(( $ismas_requests + 1 ))
updates_available && break
update_psa_false_alarm "update requested, but no WAIT state detected <$ismas_requests>"
done
if [ $ismas_requests -gt 3 ]; then
log_fatal "update_psa:${LINENO}: update requested, but no WAIT state detected !!!"
fi
else
log_info "${func}:${LINENO}: MAINTENANCE ON. Emulate ISMAS updates..."
# simulate an activated WAIT-button in ISMAS
set_updates_available
while [ $ismas_requests -le 10 ]; do
sleep 5
updates_available && break
ismas_requests=$(( $ismas_requests + 1 ))
log_info "${func}:${LINENO}: updates_requested <$ismas_requests>"
done
if [ $ismas_requests -gt 10 ]; then
log_fatal "${func}:${LINENO}: NO ISMAS UPDATES AVAILABLE"
fi
fi
log_debug "$func:${LINENO}: before fetch/merge updates..."
# Fetch new updates (using git). but only when repository has already been # Fetch new updates (using git). but only when repository has already been
# cloned. # cloned.
if [ $GIT_CLONE_EXECUTED -eq 0 ]; then
if ! fetch_customer_updates; then 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_psa_false_alarm \
"update request, but no change in $CUSTOMER_REPOSITORY_PATH" "update request, but no change in $CUSTOMER_REPOSITORY_PATH"
log_fatal "$func:${LINENO}: fetch no data for $customer_id"\ # TODO
"-> no files to update -> no psa update" fi
else
log_debug "$func:${LINENO}: after successful fetch_customer_repository..."
fi fi
update_psa_pull_customer_repository # message to ISMAS update_psa_pull_customer_repository # message to ISMAS
# no backup necessary as saved in git-repo
# local changed_files=$(changed_file_names)
if [[ -f "$GIT_PULL_TMP" ]]; then
# TODO
if ! check_hardware_compatibility "$files_to_copy" ; then
local __r=$?
log_error "$func:${LINENO}: json/ini-files not fit for PSA"
revert_customer_repository
exit $__r
fi
fi
if [[ -f "$OPKG_CMDS_TMP" ]]; then
local commands="$(cat ${OPKG_CMDS_TMP} | tr '\n' '; ')"
log_info "$func:${LINENO}: executed opkg commands"
update_psa_install_opkg_packages $UPDATE_ISMAS_PROGRESS \
$RC_SUCCESS "$commands"
else
log_info "$func:${LINENO}: no opkg commands to execute"
update_psa_install_opkg_packages $UPDATE_ISMAS_PROGRESS \
$RC_SUCCESS "no opkg commands to execute"
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_PSA_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 commands to execute"
# update_psa_install_opkg_packages $UPDATE_ISMAS_PROGRESS \
# $RC_SUCCESS "no opkg commands to execute"
#fi
# Cleanup.
#if ! cleanup_previous_version; then
# log_error "$func:${LINENO}: cleanup_previous_version failed"
#fi
# compute version string for current (i.e. new) version
compute_version
update_psa_cleanup $UPDATE_ISMAS_PROGRESS \
$RC_SUCCESS "cleanup after psa update"
# TODO
exit 0
} }