17 Commits

Author SHA1 Message Date
c229f7072c added (commented) line for 'update_psa testing' 2022-06-16 15:52:44 +02:00
7a35039dad update_psa: when called with an argument, skip test for available
updates, executing 'git pull' in any case.
2022-06-16 15:49:34 +02:00
42fb74a041 deactivate some debug output 2022-06-16 15:49:00 +02:00
d69f767002 deactivate output 2022-06-16 15:48:11 +02:00
7c2d78e6db return 0 as exit code 2023-03-31 12:17:08 +02:00
9dd7eb7a3c Activate colored output 2023-03-31 09:45:57 +02:00
87be571e43 Remove GIT_PULL_TMP and OPKG_CMDS_TMP when cloning 2023-03-31 09:05:21 +02:00
2045dcedf5 Change to passed working directory 2023-03-30 14:56:49 +02:00
9d6bb99963 Set working directory to PWD 2023-03-30 14:55:13 +02:00
8b5cda7f73 After clone: fetch the reposiry again, follwed by a git reset --hard.
The effect is that git crates all diretories and files in /etc and /opt.
2023-03-30 13:59:38 +02:00
52271bef21 do not assert missing files. git will create them in <clone> 2023-03-30 13:40:53 +02:00
f080f34bb3 Added GIT_CLONE_EXECUTE 2022-06-12 13:10:48 +02:00
6f8ba186dd Set GIT_CLONE_EXECUTED to show that git clone was run 2022-06-12 13:10:16 +02:00
0541206033 Use of GIT_CLONE_EXECUTED to check if clone was running 2022-06-12 13:07:57 +02:00
b3eed36db8 added local branches 2022-06-12 13:06:31 +02:00
966a779065 create workspace in any case 2022-06-09 21:18:38 +02:00
da3c9abbf5 reusing customer_281 2022-06-09 21:17:18 +02:00
7 changed files with 121 additions and 83 deletions

View File

@@ -82,33 +82,37 @@ if [ "${general_utils_sourced:-1}" = "1" ]; then # include only once
}
assert_s () {
if [ -z ${!1} ]; then
log_fatal "$1 not set"
fi
log_debug "$1=${!1}"
# 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}"
# 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}"
# 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"
# if [ $__len -eq 0 ]; then
# log_fatal "$1 not set"
# fi
# log_debug "$1=$__n"
:
}
fi

View File

@@ -71,9 +71,7 @@ revert_to_commit_before_pull () {
clone_customer_repository () {
local func="${FUNCNAME[0]}"
if [ "$PWD" = "$WORKING_DIRECTORY" ]; then
if ! [[ -d "./$WORKSPACE_DIR" ]]; then
{ mkdir -p ./$WORKSPACE_DIR; }
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
@@ -83,13 +81,27 @@ clone_customer_repository () {
$(exec_git_command git clone "$1")
if [ $? -eq 0 ]; then
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,
# setting the work-tree as "/". This has the effect that
# a "git pull" will automatically fetched files in the
# corresponding sytem-folders.
if cd ${CUSTOMER_ID_BASE_DIR}; then
local res=$(exec_git_command git --git-dir=.git --work-tree=/ init)
if ! [[ -z $res ]]; then
# local res=$(exec_git_command git --git-dir=.git --work-tree=/ init)
exec_git_command git checkout "$LOCAL_BRANCH"
if [[ $? -eq 0 ]]; then
log_debug "$func:${LINENO} checked out local branch $LOCAL_BRANCH"
exec_git_command git config core.worktree "/"
if [[ $? -eq 0 ]]; then
log_debug "$func:${LINENO} configured worktree"
exec_git_command git fetch --all
if [[ $? -eq 0 ]]; then
log_debug "$func:${LINENO} fetch repository"
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).
@@ -102,6 +114,9 @@ clone_customer_repository () {
fi
fi
fi
fi
fi
fi
cd_home; return 1
fi
else

View File

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

View File

@@ -28,6 +28,8 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
readonly PROGRAM=`basename $0`
readonly WORKSPACE_DIR=workspace
GIT_CLONE_EXECUTED=0
EXITCODE=$RC_SUCCESS
CLONE_CUSTOMER_REPOSITORY=false
@@ -35,17 +37,13 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
read_config() {
local func="${FUNCNAME[0]}"
WORKING_DIRECTORY=${WORKING_DIRECTORY:-$UPDATEPSAHOME}
WORKING_DIRECTORY=${PWD}
CONFIGFILENAME=${CONFIGFILENAME:-'update_psa.conf'}
if ! [ -f "$CONFIGFILENAME" ]; then
log_fatal "$func:${LINENO}: $CONFIGFILENAME not found"
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}: WORKING_DIRECTORY=$WORKING_DIRECTORY"
@@ -92,6 +90,16 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
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
readonly ZONE=1
readonly LOCAL_BRANCH="$(cat "$cf" | jq -r .local_branches[$ZONE])"
return 0
}
###############################################################################
@@ -151,13 +159,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
# readonly CUST_BASE_DIRS=(${__customer_base_dirs[@]})
# assert_a CUST_BASE_DIRS
# TODO
# TODO: falls mehrere gruppen/zonen auftauchen hier anpassen
# TODO
# Zone aus /etc/zone_nr auslesen
#
readonly ZONE_GROUP=1
readonly ZONE=1
readonly CUST_BASE_DIR="$CUSTOMER_ID_BASE_DIR"
#readonly CUST_BASE_DIR="${CUST_BASE_DIRS[$ZONE]}"
#assert_d CUST_BASE_DIR
@@ -377,11 +379,11 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
${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 "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

View File

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

View File

@@ -6,11 +6,15 @@
"customer_location" : "szeged",
"" : "unique customer identifier",
"customer_id" : "customer_szeged_281",
"customer_id" : "customer_281",
"" : "zone file for PSA",
"zone" : "/etc/zone_nr",
"" : "local branches",
"local_branches" : ["master",
"zg1/zone1", "zg1/zone2", "zg1/zone3"],
"" : "customer number of PSA",
"customer_id_" : "/etc/cust_nr",
@@ -25,5 +29,5 @@
"zg" : [ 1, { "z" : [ 3, 1, 2, 3] } ],
"" : "url of customer repository",
"cust_repository_path" : "https://git.mimbach49.de/GerhardHoffmann/customer_szeged_281"
"cust_repository_path" : "https://git.mimbach49.de/GerhardHoffmann/customer_281.git"
}

View File

@@ -28,11 +28,13 @@ collect_current_configuration () {
#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 $?
exit $EXITCODE
fi
fi
update_psa_activated # message to ISMAS
@@ -41,7 +43,9 @@ update_psa() {
log_debug "$func:${LINENO}: fetch/merge updates..."
# Fetch new updates (using git)
# Fetch new updates (using git). but only when repository has already been
# cloned.
if [ $GIT_CLONE_EXECUTED -eq 0 ]; then
if ! fetch_customer_updates; then
log_error "$func:${LINENO}: fetch no data for $customer_id"\
"-> no files to update -> no psa update"
@@ -49,6 +53,7 @@ update_psa() {
"update request, but no change in $CUSTOMER_REPOSITORY_PATH"
# TODO
fi
fi
update_psa_pull_customer_repository # message to ISMAS