DEB build scripts: update to update_repositories script.

- reduced number of operation with server
- added separate fetch phase
- improve user feedback by reusing same line for modules with no
changes, resulting in a clear view of modules that have been updated or
have issues.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/3/head
Michele Calgaro 6 years ago
parent 157dd9198b
commit 6f0a8c144b
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -2,29 +2,29 @@
# Check command line arguments and set options
# Run before loading configuration, to allow branch overriding
bool_INCREMENTAL="n"
bool_VERBOSE_LOG="n"
bool_SWITCH_ONLY="n"
flag_INCREMENTAL="n"
flag_VERBOSE_LOG="n"
flag_SWITCH_ONLY="n"
OVERRIDE_DEFAULT_REPO_BRANCH=""
for ((idx=1; idx<=$#; idx++)); do
arg="${!idx}"
if [ "$arg" = "-i" ]; then # continue from last updated module (Incremental)
bool_INCREMENTAL="y"
flag_INCREMENTAL="y"
elif [ "$arg" = "-v" ]; then # display and log git command output (Verbose)
bool_VERBOSE_LOG="y"
flag_VERBOSE_LOG="y"
elif [ "$arg" = "-ub" ]; then # branches to update (Update Branches)
((idx++))
OVERRIDE_UPDATE_BRANCHES="${!idx}"
[[ -z "$OVERRIDE_DEFAULT_REPO_BRANCH" ]] && OVERRIDE_DEFAULT_REPO_BRANCH="${!idx}"
elif [ "$arg" = "-db" ]; then # default branch after update (Default Branch)
((idx++))
if [[ "$bool_SWITCH_ONLY" != 'y' ]]; then
if [[ "$flag_SWITCH_ONLY" != 'y' ]]; then
# '-db' is only used if no '-so' argument is specified. If '-so <branch>'
# is given, '-db <branch> is ignored
OVERRIDE_DEFAULT_REPO_BRANCH="${!idx}"
fi
elif [ "$arg" = "-so" ]; then # switch branch only (Switch Only)
bool_SWITCH_ONLY="y" && ((idx++))
flag_SWITCH_ONLY="y" && ((idx++))
OVERRIDE_DEFAULT_REPO_BRANCH="${!idx}"
fi
done
@ -35,6 +35,21 @@ init_common
UPDATE_LOCK_FILENAME="/var/lock/TDE_update_repo_lock" # Lock file for incremental update
declare -A RESULT_STRINGS=(
[OK]="[ OK ]"
[FAIL]="[ FAIL ]"
[UPDATE]="[ UPDATE ]"
[SKIP]="[ SKIP ]"
[INV-OP]="[ INV-OP ]"
)
declare -A COLOR_STRINGS=(
[OK]="${CNone}"
[FAIL]="${CLightRed}"
[UPDATE]="${CLightGreen}"
[SKIP]="${CBrown}"
[INV-OP]="${CLightPurple}"
)
#----------------------------
# Update a given module from the upstream repo
# Parameters:
@ -49,57 +64,65 @@ function _do_update()
local BRANCH=$3
local NEW_BRANCH=$4
local RESULT=""
local LINE_CTRL_SUFFIX=""
case "$OP_TYPE" in
"update")
case "$OP_TYPE" in
"fetch")
if [[ -z `grep "^$BRANCH - $MOD_PATH$" "$UPDATE_LOCK_FILENAME"` ]]; then
cd "$MOD_PATH" &>/dev/null
eval git fetch --all --prune $OPT_VERBOSE_LOG
if [ $? -eq 0 ]; then
# Clean up any possible uncommitted changes
if [[ ! -z "`git status --porcelain $GIT_IGNORE_SUBMODULES`" ]]; then
git reset --hard HEAD &>/dev/null
git clean -dxff &>/dev/null
fi
# Make sure the local branch exists
if [[ -z `git branch | grep -E "\b$BRANCH\b"` ]]; then
NEW_BRANCH="y"
eval git checkout -b \"$BRANCH\" \"origin/$BRANCH\" $OPT_VERBOSE_LOG
else
eval git checkout \"$BRANCH\" $OPT_VERBOSE_LOG
fi
# Make sure the local branch is a tracking branch
if [[ -z `git config branch."$BRANCH".remote` ]]; then
NEW_BRANCH="y"
git branch -u "origin/$BRANCH" &>/dev/null #$
git reset --hard "origin/$BRANCH" &>/dev/null
fi
# Update
eval git reset --hard HEAD $OPT_VERBOSE_LOG
eval git clean -dxff $OPT_VERBOSE_LOG
eval git fetch $OPT_VERBOSE_LOG
for _remote in `git remote`; do
eval git remote prune $_remote $OPT_VERBOSE_LOG
done
if [[ $(git rev-parse HEAD) != $(git rev-parse "origin/$BRANCH") ]]; then
eval git pull --rebase $GIT_NO_RECURSE_SUBMODULES $OPT_VERBOSE_LOG
if [[ `git rev-parse HEAD` == `git rev-parse "origin/$BRANCH"` ]]; then
RESULT="${CLightGreen}[ UPDATE ]"
else
RESULT="${CLightRed}[ FAIL ]"
fi
RESULT="OK"
else
RESULT="FAIL"
fi
echo "$BRANCH - $MOD_PATH" >> "$UPDATE_LOCK_FILENAME"
else
RESULT="SKIP"
fi
;;
"update")
cd "$MOD_PATH" &>/dev/null
if [ $? -eq 0 ]; then
# Clean up any possible uncommitted changes
if [[ ! -z "`git status --porcelain $GIT_IGNORE_SUBMODULES`" ]]; then
git reset --hard HEAD &>/dev/null
git clean -dxff &>/dev/null
fi
# Make sure the local branch exists
if [[ -z `git branch | grep -E "\b$BRANCH\b"` ]]; then
NEW_BRANCH="y"
eval git checkout -b \"$BRANCH\" \"origin/$BRANCH\" $OPT_VERBOSE_LOG
else
eval git checkout \"$BRANCH\" $OPT_VERBOSE_LOG
fi
# Make sure the local branch is a tracking branch
if [[ -z `git config branch."$BRANCH".remote` ]]; then
NEW_BRANCH="y"
git branch -u "origin/$BRANCH" &>/dev/null #$
git reset --hard "origin/$BRANCH" &>/dev/null
fi
# Update
eval git reset --hard HEAD $OPT_VERBOSE_LOG
eval git clean -dxff $OPT_VERBOSE_LOG
if [[ $(git rev-parse HEAD) != $(git rev-parse "origin/$BRANCH") ]]; then
eval git pull --rebase $GIT_NO_RECURSE_SUBMODULES $OPT_VERBOSE_LOG
if [[ `git rev-parse HEAD` == `git rev-parse "origin/$BRANCH"` ]]; then
RESULT="UPDATE"
else
if [[ "$NEW_BRANCH" = "y" ]]; then
RESULT="${CLightGreen}[ UPDATE ]"
else
RESULT="[ OK ]"
fi
RESULT="FAIL"
fi
else
RESULT="${CLightRed}[ FAIL ]"
if [[ "$NEW_BRANCH" = "y" ]]; then
RESULT="UPDATE"
else
RESULT="OK"
fi
fi
echo "$BRANCH - $MOD_PATH" >> "$UPDATE_LOCK_FILENAME"
else
RESULT="${CBrown}[ SKIP ]"
RESULT="FAIL"
fi
;;
@ -109,18 +132,22 @@ function _do_update()
eval git reset --hard HEAD $OPT_VERBOSE_LOG
eval git clean -dxff $OPT_VERBOSE_LOG
if [[ ! -z `git branch -v | grep -E "^\*\s+$BRANCH"` ]]; then
RESULT="[ OK ]"
RESULT="OK"
else
RESULT="${CLightRed}[ FAIL ]"
RESULT="FAIL"
fi
;;
*)
RESULT="[ INV-OP ]"
RESULT="INV-OP"
;;
esac
echo_and_tee "$RESULT $MOD_PATH${CNone}" "$LOG_UPDATE_REPO_FILENAME"
if [ "$RESULT" != "OK" -o "$flag_VERBOSE_LOG" = "y" ]; then
LINE_CTRL_SUFFIX="\n"
fi
echo -ne "\033[2K\r${COLOR_STRINGS[$RESULT]}${RESULT_STRINGS[$RESULT]} $MOD_PATH${CNone}$LINE_CTRL_SUFFIX"
echo "${RESULT_STRINGS[$RESULT]} $MOD_PATH" >> "$LOG_UPDATE_REPO_FILENAME"
}
#----------------------------
@ -160,14 +187,14 @@ function _update_module()
}
#----------------------------
if [ "$bool_INCREMENTAL" = "y" ]; then
[ ! -f "$UPDATE_LOCK_FILENAME" ] && bool_INCREMENTAL="n"
if [ "$flag_INCREMENTAL" = "y" ]; then
[ ! -f "$UPDATE_LOCK_FILENAME" ] && flag_INCREMENTAL="n"
else
[ -f "$UPDATE_LOCK_FILENAME" ] && rm "$UPDATE_LOCK_FILENAME"
fi
OPT_VERBOSE_LOG="&>/dev/null"
if [[ "$bool_VERBOSE_LOG" = "y" ]]; then
if [[ "$flag_VERBOSE_LOG" = "y" ]]; then
OPT_VERBOSE_LOG=" |& tee -a \"$LOG_UPDATE_REPO_FILENAME\""
fi
@ -183,16 +210,30 @@ if [[ -n "`git pull --help |grep -- '--\[no-\]recurse-submodules'`" ]]; then
fi
# Start update
if [ "$bool_INCREMENTAL" != "y" ]; then
if [ "$flag_INCREMENTAL" != "y" ]; then
echo "TDE repositories update started" > "$UPDATE_LOCK_FILENAME"
fi
_LAST_BRANCH=""
if [[ "$bool_SWITCH_ONLY" != 'y' ]]; then
if [[ "$flag_SWITCH_ONLY" != "y" ]]; then
# Fetch all remotes first
echo_and_tee "${CLightCyan}---------------------------------------${CNone}" "$LOG_UPDATE_REPO_FILENAME" "y"
echo_and_tee "${CLightCyan} Fetching remotes ${CNone}" "$LOG_UPDATE_REPO_FILENAME"
echo_and_tee "${CLightCyan}---------------------------------------${CNone}" "$LOG_UPDATE_REPO_FILENAME"
# Fetch TDE main repository
_update_module "$REPO_TDE" "fetch"
# Fetch TDE packaging repository
_update_module "$TDE_DIR/$CFG_GIT_DIR/tde-packaging" "fetch"
echo -e "\033[2K"
echo "" >> "$LOG_UPDATE_REPO_FILENAME"
# Branch update
for branch in "${BRANCHES[@]}"; do
_LAST_BRANCH="$branch"
echo_and_tee "${CLightCyan}---------------------------------------${CNone}" "$LOG_UPDATE_REPO_FILENAME" "y"
echo_and_tee "${CLightCyan}---------------------------------------${CNone}" "$LOG_UPDATE_REPO_FILENAME"
echo_and_tee "${CLightCyan} Updating branch ${CYellow}$branch ${CNone}" "$LOG_UPDATE_REPO_FILENAME"
echo_and_tee "${CLightCyan}---------------------------------------${CNone}" "$LOG_UPDATE_REPO_FILENAME"
@ -202,13 +243,14 @@ if [[ "$bool_SWITCH_ONLY" != 'y' ]]; then
# Update TDE packaging repository
_update_module "$TDE_DIR/$CFG_GIT_DIR/tde-packaging" "update" "$branch" "n"
echo_and_tee "" "$LOG_UPDATE_REPO_FILENAME"
echo -e "\033[2K"
echo "" >> "$LOG_UPDATE_REPO_FILENAME"
done
fi
# Switch to specified branch if necessary
if [[ "$DEFAULT_REPO_BRANCH" != "$_LAST_BRANCH" ]]; then
echo_and_tee "${CLightCyan}---------------------------------------${CNone}" "$LOG_UPDATE_REPO_FILENAME" "y"
echo_and_tee "${CLightCyan}---------------------------------------${CNone}" "$LOG_UPDATE_REPO_FILENAME" "$flag_SWITCH_ONLY"
echo_and_tee "${CLightCyan} Switching to branch ${CYellow}$DEFAULT_REPO_BRANCH ${CNone}" "$LOG_UPDATE_REPO_FILENAME"
echo_and_tee "${CLightCyan}---------------------------------------${CNone}" "$LOG_UPDATE_REPO_FILENAME"
@ -218,7 +260,8 @@ if [[ "$DEFAULT_REPO_BRANCH" != "$_LAST_BRANCH" ]]; then
# Switch TDE packaging repository
_update_module "$TDE_DIR/$CFG_GIT_DIR/tde-packaging" "switch-to" "$DEFAULT_REPO_BRANCH" "n"
echo_and_tee "" "$LOG_UPDATE_REPO_FILENAME"
echo -e "\033[2K"
echo "" >> "$LOG_UPDATE_REPO_FILENAME"
fi
# Update completed

Loading…
Cancel
Save