diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2018-07-24 18:40:18 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2018-07-24 18:40:18 +0900 |
commit | 7e05a8b13a137f60600a3694c7a9091752cd7162 (patch) | |
tree | 5306f82a4f0e296fd0b506152714a1d3bfb0a15f /debian/_buildscripts/local/update_repositories.sh | |
parent | 5b6ed350a0623e238e99866dc86d4d88a6904564 (diff) | |
download | tde-packaging-7e05a8b13a137f60600a3694c7a9091752cd7162.tar.gz tde-packaging-7e05a8b13a137f60600a3694c7a9091752cd7162.zip |
DEB/UBU build scripts.
1) added support for Devuan distros
2) added more command line options for update_repositories.sh
3) bug fixes and improved user feedback
4) added link inside ubuntu distro
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 | 103 |
1 files changed, 69 insertions, 34 deletions
diff --git a/debian/_buildscripts/local/update_repositories.sh b/debian/_buildscripts/local/update_repositories.sh index a9d2fef12..5c0f5aa45 100755 --- a/debian/_buildscripts/local/update_repositories.sh +++ b/debian/_buildscripts/local/update_repositories.sh @@ -1,5 +1,34 @@ #!/bin/bash +# 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" +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" + elif [ "$arg" = "-v" ]; then # display and log git command output (Verbose) + bool_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 + # '-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++)) + OVERRIDE_DEFAULT_REPO_BRANCH="${!idx}" + fi +done + # Load common code . ./internals/_build_common.sh init_common @@ -12,11 +41,13 @@ UPDATE_LOCK_FILENAME="/var/lock/TDE_update_repo_lock" # Lock file for incremen # $1 - module folder # $2 - operation type # $3 - branch to update +# $4 - new branch flag (only for reporting) function _do_update() { local MOD_PATH=$1 local OP_TYPE=$2 local BRANCH=$3 + local NEW_BRANCH=$4 local RESULT="" case "$OP_TYPE" in @@ -29,17 +60,18 @@ function _do_update() git reset --hard HEAD &>/dev/null git clean -dxff &>/dev/null fi - # Make sure the local branch exists and is a tracking branch + # 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 - 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 + # 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 @@ -53,7 +85,11 @@ function _do_update() RESULT="${CLightRed}[ FAIL ]" fi else - RESULT="[ OK ]" + if [[ "$NEW_BRANCH" = "y" ]]; then + RESULT="${CLightGreen}[ UPDATE ]" + else + RESULT="[ OK ]" + fi fi else RESULT="${CLightRed}[ FAIL ]" @@ -67,6 +103,8 @@ function _do_update() "switch-to") cd "$MOD_PATH" &>/dev/null eval git checkout \"$BRANCH\" $OPT_VERBOSE_LOG + 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 ]" else @@ -88,42 +126,37 @@ function _do_update() # $1 - module folder # $2 - operation type # $3 - branch to update +# $4 - new branch flag (only for reporting) function _update_module() { local MOD_PATH=$1 local OP_TYPE=$2 local BRANCH=$3 + # Current module _do_update "$@" # Submodules + local NEW_BRANCH="n" 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 + NEW_BRANCH="n" cd "$MOD_PATH" &>/dev/null if [[ -z "`git config --get submodule.$SUBMOD_PATH.url`" ]]; then + NEW_BRANCH="y" # if a submodule is missing, need to report "update" status eval git submodule init -- \"$SUBMOD_PATH\" $OPT_VERBOSE_LOG fi if [[ ! -e "$MOD_PATH/$SUBMOD_PATH/.git" ]]; then + NEW_BRANCH="y" # if a submodule is incomplete, need to report "update" status eval git submodule update -- \"$SUBMOD_PATH\" $OPT_VERBOSE_LOG fi - _update_module "$MOD_PATH/$SUBMOD_PATH" "$OP_TYPE" "$BRANCH" + _update_module "$MOD_PATH/$SUBMOD_PATH" "$OP_TYPE" "$BRANCH" "$NEW_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 @@ -151,22 +184,24 @@ 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" +if [[ "$bool_SWITCH_ONLY" != 'y' ]]; then + # Branch update + 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" "n" - # 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" + # Update TDE packaging repository + _update_module "$TDE_DIR/$CFG_GIT_DIR/tde-packaging" "update" "$branch" "n" - echo_and_tee "" "$LOG_UPDATE_REPO_FILENAME" -done + echo_and_tee "" "$LOG_UPDATE_REPO_FILENAME" + done +fi # Switch to specified branch if necessary if [[ "$DEFAULT_REPO_BRANCH" != "$_LAST_BRANCH" ]]; then @@ -175,10 +210,10 @@ if [[ "$DEFAULT_REPO_BRANCH" != "$_LAST_BRANCH" ]]; then echo_and_tee "${CLightCyan}---------------------------------------${CNone}" "$LOG_UPDATE_REPO_FILENAME" # Switch TDE main repository - _update_module "$REPO_TDE" "switch-to" "$DEFAULT_REPO_BRANCH" + _update_module "$REPO_TDE" "switch-to" "$DEFAULT_REPO_BRANCH" "n" # Switch TDE packaging repository - _update_module "$TDE_DIR/$CFG_GIT_DIR/tde-packaging" "switch-to" "$DEFAULT_REPO_BRANCH" + _update_module "$TDE_DIR/$CFG_GIT_DIR/tde-packaging" "switch-to" "$DEFAULT_REPO_BRANCH" "n" echo_and_tee "" "$LOG_UPDATE_REPO_FILENAME" fi |