Compare commits
15 Commits
szeged_pre
...
515c77bed4
Author | SHA1 | Date | |
---|---|---|---|
515c77bed4 | |||
f2617d8151 | |||
4f9c6155e1 | |||
33511a5bcb | |||
bd0d07f56f | |||
b8bc61daea | |||
27cd99f96a | |||
729778043a | |||
31e1aad762 | |||
f8c091ad0c | |||
e5e6c4c1cd | |||
95a9307631 | |||
fc1c2221b1 | |||
9b1549306d | |||
a8f691741b |
81
git_helpers
81
git_helpers
@@ -57,6 +57,18 @@ 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.
|
||||
# this is done only once.
|
||||
#
|
||||
@@ -78,18 +90,17 @@ clone_customer_repository () {
|
||||
log_debug "$func:${LINENO} cloning ${1} ..."
|
||||
if cd "./$WORKSPACE_DIR"
|
||||
then
|
||||
$(exec_git_command git clone "$1")
|
||||
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)
|
||||
# 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"
|
||||
@@ -102,19 +113,13 @@ clone_customer_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).
|
||||
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
|
||||
CLONE_CUSTOMER_REPOSITORY=true
|
||||
log_debug "$func:${LINENO} re-init of ${1} done"
|
||||
cd_home; return 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
cd_home; return 1
|
||||
@@ -175,26 +180,20 @@ pull_customer_repository () {
|
||||
return 1
|
||||
fi
|
||||
|
||||
#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'..."
|
||||
log_crit "$func:${LINENO}: executing 'git pull'..."
|
||||
exec_git_command 'git pull'
|
||||
|
||||
# GIT_PULL_TMP created by hook post-merge. it contains the names of the
|
||||
# changed files.
|
||||
if [[ -f $GIT_PULL_TMP ]]; then
|
||||
# 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.
|
||||
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
|
||||
|
||||
log_warn "$func:${LINENO}: no data fetched form repository"
|
||||
|
||||
log_warn "$func:${LINENO}: no data fetched from repository"
|
||||
cd_home; return 1
|
||||
}
|
||||
# pull_customer_repository customer_281
|
||||
@@ -224,4 +223,20 @@ changed_file_names () {
|
||||
"while in $PWD"
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
34
log_helpers
34
log_helpers
@@ -1,10 +1,6 @@
|
||||
#!/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]}
|
||||
|
||||
@@ -21,7 +17,7 @@ if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
|
||||
readonly FATAL=5
|
||||
readonly MAX_DEBUG_LEVEL=6
|
||||
|
||||
log_level=0
|
||||
log_level=$INFO
|
||||
|
||||
set_dbg_level () {
|
||||
if [ $1 < $MAX_DEBUG_LEVEL ]; then
|
||||
@@ -33,50 +29,60 @@ if [ "${log_helpers_sourced:-1}" = "1" ]; then # include only once
|
||||
return $log_level
|
||||
}
|
||||
|
||||
log() {
|
||||
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 "log:$msg" >&2
|
||||
echo "$msg" >> $log_file
|
||||
}
|
||||
|
||||
log() {
|
||||
local msg="$(date +'%Y-%m-%d_%T'): $*"
|
||||
echo "log:$msg" >&2
|
||||
}
|
||||
|
||||
log_debug() {
|
||||
if [ $log_level = $DEBUG ]; then
|
||||
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 "${GREEN}INFO $*"
|
||||
log "INFO $*"
|
||||
fi
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
log_to_file "WARN $*"
|
||||
if [ $log_level -le $WARN ]; then
|
||||
log "${RED}WARN $*"
|
||||
log "WARN $*"
|
||||
fi
|
||||
}
|
||||
|
||||
log_crit() {
|
||||
log_to_file "CRIT $*"
|
||||
if [ $log_level -le $CRIT ]; then
|
||||
log "${RED}CRIT $*"
|
||||
log "CRIT $*"
|
||||
fi
|
||||
}
|
||||
|
||||
log_error() {
|
||||
log_to_file "ERROR $*"
|
||||
if [ $log_level -le $ERROR ]; then
|
||||
log "${RED}ERROR $*"
|
||||
log "ERROR $*"
|
||||
fi
|
||||
}
|
||||
|
||||
log_fatal() {
|
||||
log_to_file "FATAL $*"
|
||||
if [ $log_level -le $FATAL ]; then
|
||||
log "${RED}FATAL $*"
|
||||
log "${RED}exiting ..."
|
||||
log "FATAL $*"
|
||||
log "exiting ..."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
10
read_config
10
read_config
@@ -22,17 +22,19 @@ if [ ${read_config_sourced:-1} = "1" ]; then # include only once
|
||||
readonly UPDATEPSABEGIN=./.updatepsa/begin
|
||||
readonly UPDATEPSAEND=./.updatepsa/end
|
||||
|
||||
readonly OPKG_CMDS_TMP=/tmp/opkg_commands
|
||||
readonly GIT_PULL_TMP=/tmp/git_pull
|
||||
# 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
|
||||
|
||||
GIT_CLONE_EXECUTED=0
|
||||
|
||||
EXITCODE=$RC_SUCCESS
|
||||
CLONE_CUSTOMER_REPOSITORY=false
|
||||
|
||||
GIT_CLONE_EXECUTED=0
|
||||
APISM_RUNNING=0
|
||||
|
||||
# read config file (JSON syntax)
|
||||
read_config() {
|
||||
local func="${FUNCNAME[0]}"
|
||||
|
19
update_psa
19
update_psa
@@ -64,18 +64,21 @@ if cd "$WORKING_DIRECTORY"; then
|
||||
|
||||
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
|
||||
then
|
||||
check_sanity_of_repository
|
||||
|
||||
#set_updates_available
|
||||
#while :
|
||||
#do
|
||||
# sleep 5
|
||||
# updates_available && break
|
||||
#done
|
||||
set_updates_available
|
||||
while :
|
||||
do
|
||||
sleep 5
|
||||
updates_available && break
|
||||
done
|
||||
|
||||
# update_psa "testing"
|
||||
#update_psa "testing"
|
||||
update_psa
|
||||
fi
|
||||
fi
|
||||
|
@@ -373,8 +373,37 @@ cleanup_previous_version() {
|
||||
return 0
|
||||
}
|
||||
|
||||
check_for_apism () {
|
||||
nc localhost 7778
|
||||
check_for_running_apism () {
|
||||
local func="${FUNCNAME[0]}"
|
||||
if nc localhost 7778
|
||||
then
|
||||
APISM_RUNNING=1
|
||||
log_debug "$func:${LINENO}: APISM 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_debug "$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_debug "$func:${LINENO}: route to repository available"
|
||||
return 0
|
||||
fi
|
||||
log_fatal "$func:${LINENO}: !!! NO ROUTE TO REPO SET !!!"
|
||||
}
|
||||
|
||||
get_customer_id () {
|
||||
|
Reference in New Issue
Block a user