diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2018-07-11 23:38:32 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2018-07-11 23:38:32 +0900 |
commit | eeaccbeddbaa2974406eb20cbb7beca3fb4a59f0 (patch) | |
tree | 510e0eea682ebf69263b187287873956394b5e7b /debian/_buildscripts/local/update_repositories.sh | |
parent | 02dbbffa606c3c52833bbaf3dc5c5a050f295dbf (diff) | |
download | tde-packaging-eeaccbeddbaa2974406eb20cbb7beca3fb4a59f0.tar.gz tde-packaging-eeaccbeddbaa2974406eb20cbb7beca3fb4a59f0.zip |
DEB build scripts: several enhancements as follow:
- major rework of update_repositories.sh script, which now supports
multiple branches and provide better feedback to user.
- added support for pre-built extra dependency packages. A user can now
use Slavek Banko's binary packages instead of building the extra
dependency locally. This removes a quite tedious process during the
setup of the building environment.
- bug fixes and more user friendly folder names.
- improved README to cover the complete process until TDE installation.
Special thanks to Gregory Guy <zadig83@laposte.net> for testing and
feedback done so far.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'debian/_buildscripts/local/update_repositories.sh')
-rwxr-xr-x | debian/_buildscripts/local/update_repositories.sh | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/debian/_buildscripts/local/update_repositories.sh b/debian/_buildscripts/local/update_repositories.sh new file mode 100755 index 000000000..a9d2fef12 --- /dev/null +++ b/debian/_buildscripts/local/update_repositories.sh @@ -0,0 +1,188 @@ +#!/bin/bash + +# Load common code +. ./internals/_build_common.sh +init_common + +UPDATE_LOCK_FILENAME="/var/lock/TDE_update_repo_lock" # Lock file for incremental update + +#---------------------------- +# Update a given module from the upstream repo +# Parameters: +# $1 - module folder +# $2 - operation type +# $3 - branch to update +function _do_update() +{ + local MOD_PATH=$1 + local OP_TYPE=$2 + local BRANCH=$3 + local RESULT="" + + case "$OP_TYPE" in + "update") + if [[ -z `grep "^$BRANCH - $MOD_PATH$" "$UPDATE_LOCK_FILENAME"` ]]; then + 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 and is a tracking branch + if [[ -z `git branch | grep -E "\b$BRANCH\b"` ]]; then + eval git checkout -b \"$BRANCH\" \"origin/$BRANCH\" $OPT_VERBOSE_LOG + else + eval git checkout \"$BRANCH\" $OPT_VERBOSE_LOG + fi + if [[ ! -z `git branch -v | grep -E "^\*\s+$BRANCH"` ]]; then + if [[ -z `git branch -vv | grep "origin/$BRANCH"` ]]; then + git branch -u "origin/$BRANCH" &>/dev/null #$ + git reset --hard "origin/$BRANCH" &>/dev/null + fi + fi + # Update + eval git reset --hard HEAD $OPT_VERBOSE_LOG + eval git clean -dxff $OPT_VERBOSE_LOG + eval git fetch $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="${CLightGreen}[ UPDATE ]" + else + RESULT="${CLightRed}[ FAIL ]" + fi + else + RESULT="[ OK ]" + fi + else + RESULT="${CLightRed}[ FAIL ]" + fi + echo "$BRANCH - $MOD_PATH" >> "$UPDATE_LOCK_FILENAME" + else + RESULT="${CBrown}[ SKIP ]" + fi + ;; + + "switch-to") + cd "$MOD_PATH" &>/dev/null + eval git checkout \"$BRANCH\" $OPT_VERBOSE_LOG + if [[ ! -z `git branch -v | grep -E "^\*\s+$BRANCH"` ]]; then + RESULT="[ OK ]" + else + RESULT="${CLightRed}[ FAIL ]" + fi + ;; + + *) + RESULT="[ INV-OP ]" + ;; + esac + + echo_and_tee "$RESULT $MOD_PATH${CNone}" "$LOG_UPDATE_REPO_FILENAME" +} + +#---------------------------- +# Update a given module and all submodules from the upstream repo +# Parameters: +# $1 - module folder +# $2 - operation type +# $3 - branch to update +function _update_module() +{ + local MOD_PATH=$1 + local OP_TYPE=$2 + local BRANCH=$3 + # Current module + _do_update "$@" + # Submodules + local SUBMOD_LIST="$MOD_PATH/.gitmodules" + if [[ -e "$SUBMOD_LIST" ]]; then + sed -n "s|^\[submodule \"\([^\"]*\)\"\]$|\1|p" <$SUBMOD_LIST |\ + while read -r SUBMOD_PATH; do + cd "$MOD_PATH" &>/dev/null + if [[ -z "`git config --get submodule.$SUBMOD_PATH.url`" ]]; then + eval git submodule init -- \"$SUBMOD_PATH\" $OPT_VERBOSE_LOG + fi + if [[ ! -e "$MOD_PATH/$SUBMOD_PATH/.git" ]]; then + eval git submodule update -- \"$SUBMOD_PATH\" $OPT_VERBOSE_LOG + fi + _update_module "$MOD_PATH/$SUBMOD_PATH" "$OP_TYPE" "$BRANCH" + done + fi +} + +#---------------------------- +# Check command line arguments and set options +bool_INCREMENTAL="n" +bool_VERBOSE_LOG="n" +for arg in $@; do + if [ "$arg" = "-i" ]; then # continue from last updated module (Incremental) + bool_INCREMENTAL="y" + elif [ "$arg" = "-v" ]; then # display and log git command output + bool_VERBOSE_LOG="y" + fi +done + +if [ "$bool_INCREMENTAL" = "y" ]; then + [ ! -f "$UPDATE_LOCK_FILENAME" ] && bool_INCREMENTAL="n" +else + [ -f "$UPDATE_LOCK_FILENAME" ] && rm "$UPDATE_LOCK_FILENAME" +fi + +OPT_VERBOSE_LOG="&>/dev/null" +if [[ "$bool_VERBOSE_LOG" = "y" ]]; then + OPT_VERBOSE_LOG=" |& tee -a \"$LOG_UPDATE_REPO_FILENAME\"" +fi + +#---------------------------- +# Check git abilities +GIT_IGNORE_SUBMODULES="" +if [[ -n "`git status --help 2>/dev/null|grep -- '--ignore-submodules'`" ]]; then + GIT_IGNORE_SUBMODULES="--ignore-submodules" +fi +GIT_NO_RECURSE_SUBMODULES="" +if [[ -n "`git pull --help |grep -- '--\[no-\]recurse-submodules'`" ]]; then + GIT_NO_RECURSE_SUBMODULES="--no-recurse-submodules" +fi + +# Start update +if [ "$bool_INCREMENTAL" != "y" ]; then + echo "TDE repositories update started" > "$UPDATE_LOCK_FILENAME" +fi + +# Branch update +_LAST_BRANCH="" +for branch in "${BRANCHES[@]}"; do + _LAST_BRANCH="$branch" + echo_and_tee "${CLightCyan}---------------------------------------${CNone}" "$LOG_UPDATE_REPO_FILENAME" "y" + echo_and_tee "${CLightCyan} Updating branch ${CYellow}$branch ${CNone}" "$LOG_UPDATE_REPO_FILENAME" + echo_and_tee "${CLightCyan}---------------------------------------${CNone}" "$LOG_UPDATE_REPO_FILENAME" + + # Update TDE main repository + _update_module "$REPO_TDE" "update" "$branch" + + # Update TDE packaging repository + _update_module "$TDE_DIR/$CFG_GIT_DIR/tde-packaging" "update" "$branch" + + echo_and_tee "" "$LOG_UPDATE_REPO_FILENAME" +done + +# 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} Switching to branch ${CYellow}$DEFAULT_REPO_BRANCH ${CNone}" "$LOG_UPDATE_REPO_FILENAME" + echo_and_tee "${CLightCyan}---------------------------------------${CNone}" "$LOG_UPDATE_REPO_FILENAME" + + # Switch TDE main repository + _update_module "$REPO_TDE" "switch-to" "$DEFAULT_REPO_BRANCH" + + # Switch TDE packaging repository + _update_module "$TDE_DIR/$CFG_GIT_DIR/tde-packaging" "switch-to" "$DEFAULT_REPO_BRANCH" + + echo_and_tee "" "$LOG_UPDATE_REPO_FILENAME" +fi + +# Update completed +[ -f "$UPDATE_LOCK_FILENAME" ] && rm "$UPDATE_LOCK_FILENAME" +cd $SCRIPT_DIR |