Compare commits
No commits in common. "ef4d27eb91b08b3dba8f5a1ff58d404e00b246a4" and "8f50f62a527de0f976e9ea71c69515b7232f39c1" have entirely different histories.
ef4d27eb91
...
8f50f62a52
159
git_helpers
159
git_helpers
@ -82,104 +82,92 @@ git_customer_branch () {
|
||||
#
|
||||
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} ..."
|
||||
if ! cd "./$WORKSPACE_DIR"; then
|
||||
update_psa_clone_error # message to ISMAS
|
||||
log_fatal "$func:${LINENO} can not change to $WORKSPACE_DIR"
|
||||
if [ "$PWD" = "$WORKING_DIRECTORY" ]; then
|
||||
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_debug "$func:${LINENO} cloning ${1} ..."
|
||||
if cd "./$WORKSPACE_DIR"
|
||||
then
|
||||
exec_git_command git clone "$1"
|
||||
if [ $? -eq 0 ]; then
|
||||
log_debug "$func:${LINENO} cloning ${1} done"
|
||||
GIT_CLONE_EXECUTED=1
|
||||
# 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
|
||||
# configure hooks directory
|
||||
exec_git_command git config core.hooksPath .githooks
|
||||
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"
|
||||
CLONE_CUSTOMER_REPOSITORY=true
|
||||
log_debug "$func:${LINENO} re-init of ${1} done"
|
||||
cd_home; return 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
cd_home; return 1
|
||||
fi
|
||||
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}/*')"
|
||||
else
|
||||
local __m="./${WORKSPACE_DIR}/$CUSTOMER_ID exists"
|
||||
log_debug "$func:${LINENO} $__m"
|
||||
return 0
|
||||
fi
|
||||
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
|
||||
update_psa_clone_error # message to ISMAS
|
||||
return $?
|
||||
}
|
||||
# clone_customer_repository ->
|
||||
# https://git.mimbach49.de/GerhardHoffmann/customer_281.git
|
||||
|
||||
cd_customer_repository () {
|
||||
local func="${FUNCNAME[0]}"
|
||||
# has to be called in WORKING_DIRECTORY
|
||||
cd "$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
|
||||
|
||||
if ! { cd $repository_dir; } ; then
|
||||
log_crit "$func:${LINENO}: cannot cd to $repository_dir!"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "$PWD" != "$WORKING_DIRECTORY" ]; then
|
||||
log_fatal "$func:${LINENO} PD != WD ($PWD != $WORKING_DIRECTORY)"
|
||||
log_debug "$func:${LINENO}: cd to $repository_dir!"
|
||||
return 0
|
||||
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
|
||||
return 1
|
||||
}
|
||||
|
||||
cd_home () {
|
||||
if cd "$WORKING_DIRECTORY" &>/dev/null ; then
|
||||
if cd - &>/dev/null ; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
@ -199,7 +187,8 @@ pull_customer_repository () {
|
||||
# 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
|
||||
grep -E -q "^[[:space:]]*(DOWNLOAD|EXECUTE)" "$GIT_UPDATE_LOG"
|
||||
if [ $? -eq 0 ]; then
|
||||
log_info "$func:${LINENO}: new data fetched from repository"
|
||||
cd_home; return 0
|
||||
fi
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
source ./log_helpers
|
||||
|
||||
if [ "${news_to_ismas_sourced:-1}" = "1" ]; then # include only once
|
||||
readonly news_to_ismas_sourced=${BASH_SOURCE[0]}
|
||||
if [ ${news_to_ismas_sourced:-1} = "1" ]; then # include only once
|
||||
|
||||
readonly APISM_DB_PORT=7777
|
||||
readonly UPDATE_ISMAS_PROGRESS="U0010"
|
||||
@ -70,18 +69,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 () {
|
||||
PERCENT=10
|
||||
@ -395,8 +382,8 @@ if [ "${news_to_ismas_sourced:-1}" = "1" ]; then # include only once
|
||||
\"CREATED\":\"$(date +%Y-%m-%dT%T)\",
|
||||
\"HASH\":\"$(compute_hash)\"
|
||||
},
|
||||
\"TARIFF\" : {
|
||||
$(<$TC_PSA_TC_FILE)
|
||||
\"TARIFF\": {
|
||||
$(<$TC_PSA_TC_FILE)
|
||||
},
|
||||
\"HARDWARE\" : {
|
||||
\"DEVICES\" : [
|
||||
|
27
read_config
27
read_config
@ -30,7 +30,9 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
||||
readonly WORKSPACE_DIR=workspace
|
||||
|
||||
EXITCODE=$RC_SUCCESS
|
||||
INITIAL_CLONE=false
|
||||
CLONE_CUSTOMER_REPOSITORY=false
|
||||
|
||||
GIT_CLONE_EXECUTED=0
|
||||
APISM_RUNNING=0
|
||||
|
||||
# read config file (JSON syntax)
|
||||
@ -88,23 +90,10 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
||||
# 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 ZONE=1
|
||||
|
||||
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
|
||||
}
|
||||
###############################################################################
|
||||
@ -132,10 +121,6 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
||||
|
||||
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
|
||||
|
||||
@ -222,7 +207,7 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
||||
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 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"
|
||||
|
42
update_psa
42
update_psa
@ -70,9 +70,43 @@ done
|
||||
|
||||
source ./update_psa_impl
|
||||
|
||||
if read_config; then
|
||||
update_psa
|
||||
exit 0
|
||||
if [ -z "$WORKING_DIRECTORY" ]; then
|
||||
log_fatal "update_psa:${LINENO}: empty WORKING_DIRECTORY"
|
||||
fi
|
||||
exit 1
|
||||
|
||||
if ! cd "$WORKING_DIRECTORY"; then
|
||||
log_fatal "update_psa:${LINENO}: cannot cd to $WORKING_DIRECTORY"
|
||||
fi
|
||||
|
||||
log_info "update_psa:${LINENO}: cd to $WORKING_DIRECTORY"
|
||||
|
||||
if read_config; then
|
||||
check_default_route
|
||||
check_route_to_repository "185.191.219.134" # git.mimbach.de
|
||||
check_for_running_apism
|
||||
if clone_customer_repository ${CUSTOMER_REPOSITORY_PATH}; then
|
||||
check_sanity_of_repository
|
||||
|
||||
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
|
||||
# updates available
|
||||
update_psa
|
||||
fi
|
||||
fi
|
||||
exit 0
|
||||
###############################################################################
|
||||
|
117
update_psa_impl
117
update_psa_impl
@ -32,36 +32,8 @@ collect_current_configuration () {
|
||||
|
||||
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..."
|
||||
|
||||
@ -78,5 +50,92 @@ update_psa() {
|
||||
fi
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user