From d5ce061fa9b3996825bfdecf8e4d57c25285f43b Mon Sep 17 00:00:00 2001 From: Severin Kaderli Date: Thu, 20 Dec 2018 00:28:41 +0100 Subject: [PATCH] Add submodule_update.sh Signed-off-by: Severin Kaderli --- system/bin/submodule_update.sh | 52 ++++++++++++++++++++++++++++++++++ system/bin/utils.sh | 13 ++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100755 system/bin/submodule_update.sh diff --git a/system/bin/submodule_update.sh b/system/bin/submodule_update.sh new file mode 100755 index 0000000..b4fe521 --- /dev/null +++ b/system/bin/submodule_update.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# +# SCRIPT NAME: +# submodule_update.sh +# +# AUTHOR: +# Severin Kaderli +# +# DESCRIPTION: +# Updates the submodules in all Git repositories in this folder and creates a +# new commit and pushes it. Only when there are no staged changes pending. +# +# USAGE: +# ./submodule_update.sh +. utils.sh + +START_DIR=$(pwd) + +for dir in $(find . -name .git -type d -prune) +do + cd "$dir" || exit 1 + cd .. || exit 1 + print_section "Checking $(pwd)" + + if [ -z "$(git status --porcelain)" ] + then + print_log "No pending changes" + print_log "Updating submodules" + git pl > /dev/null 2>&1 + + # Check if any changes are available + if [ -z "$(git status --porcelain)" ] + then + print_log "No updates found" + else + print_log "Updates found" + print_log "Creating commit" + git a > /dev/null 2>&1 + git c -m "Update submodules" > /dev/null 2>&1 + print_log "Pushing commit" + git p > /dev/null 2>&1 + print_log "Commit was pushed" + fi + else + print_log "Pending changes. Ignoring" + fi + + echo -e "" + + cd "${START_DIR}" || exit 1 + +done diff --git a/system/bin/utils.sh b/system/bin/utils.sh index 85ad900..ed4e877 100755 --- a/system/bin/utils.sh +++ b/system/bin/utils.sh @@ -43,12 +43,23 @@ function print_header() { # Function to print a info message with the current time and to send # a notification using notify-send. -# USAGE: print_info TITLE MESSAGE +# USAGE: print_log TITLE MESSAGE function print_log() { notify-send "${1}" "${2}" echo -e "${YELLOW}[$(date "+%H:%M:%S")] ${1} ${2}${RESET}" } +# Prints a section title. +# USAGE: print_section TITLE +function print_section() { + echo -e "${YELLOW}${1}" + echo -e "----------------------------------------${RESET}" +} + +function print_log() { + echo -e "- $1" +} + # Creates the given directory in the home directory # USAGE: create_directory DIRECTORY function create_directory() {