11 Commits

6 changed files with 87 additions and 63 deletions

View File

@@ -82,33 +82,37 @@ if [ "${general_utils_sourced:-1}" = "1" ]; then # include only once
} }
assert_s () { assert_s () {
if [ -z ${!1} ]; then # if [ -z ${!1} ]; then
log_fatal "$1 not set" # log_fatal "$1 not set"
fi # fi
log_debug "$1=${!1}" # log_debug "$1=${!1}"
:
} }
assert_d () { assert_d () {
if [ ! -d ${!1} ]; then # if [ ! -d ${!1} ]; then
log_fatal "$1 does not exist" # log_fatal "$1 does not exist"
fi # fi
log_debug "$1=${!1}" # log_debug "$1=${!1}"
:
} }
assert_f () { assert_f () {
if [ ! -f ${!1} ]; then # if [ ! -f ${!1} ]; then
log_fatal "$1 does not exist" # log_fatal "$1 does not exist"
fi # fi
log_debug "$1=${!1}" #log_debug "$1=${!1}"
:
} }
assert_a () { assert_a () {
local readonly __m="${1}[@]" local readonly __m="${1}[@]"
local readonly __n=(${!__m}) local readonly __n=(${!__m})
local __len=${#__n[@]} local __len=${#__n[@]}
if [ $__len -eq 0 ]; then # if [ $__len -eq 0 ]; then
log_fatal "$1 not set" # log_fatal "$1 not set"
fi # fi
log_debug "$1=$__n" # log_debug "$1=$__n"
:
} }
fi fi

View File

@@ -82,6 +82,8 @@ clone_customer_repository () {
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
log_debug "$func:${LINENO} cloning ${1} done" log_debug "$func:${LINENO} cloning ${1} done"
GIT_CLONE_EXECUTED=1 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
@@ -89,18 +91,30 @@ clone_customer_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) # local res=$(exec_git_command git --git-dir=.git --work-tree=/ init)
exec_git_command git checkout "$LOCAL_BRANCH" exec_git_command git checkout "$LOCAL_BRANCH"
exec_git_command git config core.worktree "/"
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
# re-initialized. copy post-merge (a hook called log_debug "$func:${LINENO} checked out local branch $LOCAL_BRANCH"
# when 'git pull' is executed and changed data exec_git_command git config core.worktree "/"
# are received). if [[ $? -eq 0 ]]; then
if cp ".githooks/post-merge" ".git/hooks"; then log_debug "$func:${LINENO} configured worktree"
log_debug "$func:${LINENO} copied post-merge to .git/hooks" exec_git_command git fetch --all
CLONE_CUSTOMER_REPOSITORY=true if [[ $? -eq 0 ]]; then
log_debug "$func:${LINENO} re-init of ${1} done" log_debug "$func:${LINENO} fetch repository"
cd_home; return 0 exec_git_command git reset --hard "$LOCAL_BRANCH"
if [[ $? -eq 0 ]]; then
log_debug "$func:${LINENO} reset --hard $LOCAL_BRANCH"
# 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"
cd_home; return 0
fi
fi
fi
fi fi
fi fi
fi fi
fi fi
cd_home; return 1 cd_home; return 1

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]}
@@ -47,32 +51,32 @@ if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
log_info() { log_info() {
if [ $log_level -le $INFO ]; then if [ $log_level -le $INFO ]; then
log "INFO $*" log "${GREEN}INFO $*"
fi fi
} }
log_warn() { log_warn() {
if [ $log_level -le $WARN ]; then if [ $log_level -le $WARN ]; then
log "WARN $*" log "${RED}WARN $*"
fi fi
} }
log_crit() { log_crit() {
if [ $log_level -le $CRIT ]; then if [ $log_level -le $CRIT ]; then
log "CRIT $*" log "${RED}CRIT $*"
fi fi
} }
log_error() { log_error() {
if [ $log_level -le $ERROR ]; then if [ $log_level -le $ERROR ]; then
log "ERROR $*" log "${RED}ERROR $*"
fi fi
} }
log_fatal() { log_fatal() {
if [ $log_level -le $FATAL ]; then if [ $log_level -le $FATAL ]; then
log "FATAL $*" log "${RED}FATAL $*"
log "exiting ..." log "${RED}exiting ..."
exit 1 exit 1
fi fi
} }

View File

@@ -37,17 +37,13 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
read_config() { read_config() {
local func="${FUNCNAME[0]}" local func="${FUNCNAME[0]}"
WORKING_DIRECTORY=${WORKING_DIRECTORY:-$UPDATEPSAHOME} WORKING_DIRECTORY=${PWD}
CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'} CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'}
if ! [ -f "$CONFIGFILENAME" ]; then if ! [ -f "$CONFIGFILENAME" ]; then
log_fatal "$func:${LINENO}: $CONFIGFILENAME not found" log_fatal "$func:${LINENO}: $CONFIGFILENAME not found"
fi fi
if ! [ -d "$WORKING_DIRECTORY" ]; then
log_fatal "$func:${LINENO}: $WORKING_DIRECTORY not found"
fi
log_debug "$func:${LINENO}: CONFIGFILENAME=$CONFIGFILENAME" log_debug "$func:${LINENO}: CONFIGFILENAME=$CONFIGFILENAME"
log_debug "$func:${LINENO}: WORKING_DIRECTORY=$WORKING_DIRECTORY" log_debug "$func:${LINENO}: WORKING_DIRECTORY=$WORKING_DIRECTORY"
@@ -383,11 +379,11 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
${DC_PSA_DC_FILE##*${CUSTOMER_ID}/} \ ${DC_PSA_DC_FILE##*${CUSTOMER_ID}/} \
${OPKG_CMDS_PSA_FILE##*${CUSTOMER_ID}/}) ${OPKG_CMDS_PSA_FILE##*${CUSTOMER_ID}/})
log_debug "known json/ini/hex_files ->" # log_debug "known json/ini/hex_files ->"
for (( i=0; i < ${#KNOWN_FILES[@]}; ++i )); do # for (( i=0; i < ${#KNOWN_FILES[@]}; ++i )); do
tab=$'\t' # tab=$'\t'
log_debug "$tab$tab ${KNOWN_FILES[$i]}" # log_debug "$tab$tab ${KNOWN_FILES[$i]}"
done # done
log_debug "sanity of ${CUSTOMER_REPOSITORY_PATH} OK" log_debug "sanity of ${CUSTOMER_REPOSITORY_PATH} OK"
# compute version string for current (i.e. previous) version # compute version string for current (i.e. previous) version

View File

@@ -14,10 +14,10 @@
# ./update_psa --file $PWD/update_psa.conf --wdir $PWD # ./update_psa --file $PWD/update_psa.conf --wdir $PWD
# #
############################################################################### ###############################################################################
if [ $# -eq 0 ]; then # if [ $# -eq 0 ]; then
# no parameters given -> nothing to do # no parameters given -> nothing to do
exit 0 # exit 0
fi #fi
if [ -z $IFS ]; then if [ -z $IFS ]; then
IFS=$'\n' IFS=$'\n'
@@ -59,24 +59,28 @@ while test $# -gt 0; do
shift shift
done done
source ./update_psa_impl if cd "$WORKING_DIRECTORY"; then
source ./update_psa_impl
if read_config if read_config
then
if clone_customer_repository $CUSTOMER_REPOSITORY_PATH
then then
check_sanity_of_repository if clone_customer_repository ${CUSTOMER_REPOSITORY_PATH}
then
check_sanity_of_repository
#set_updates_available #set_updates_available
#while : #while :
#do #do
# sleep 5 # sleep 5
# updates_available && break # updates_available && break
#done #done
update_psa # update_psa "testing"
update_psa
fi
fi fi
exit 0
fi fi
exit $EXIT_CODE exit -1
############################################################################### ###############################################################################

View File

@@ -28,11 +28,13 @@ collect_current_configuration () {
#done #done
} }
update_psa() { update_psa() { # calling with a parameter is used for testing
if ! updates_available; then # check for false alarm if [ $# -eq 0 ]; then
update_psa_false_alarm "update requested, but no WAIT state detected" if ! updates_available; then # check for false alarm
exit $? update_psa_false_alarm "update requested, but no WAIT state detected"
exit $EXITCODE
fi
fi fi
update_psa_activated # message to ISMAS update_psa_activated # message to ISMAS