#!/usr/bin/env bash usage() { cat << EOF usage: ${0##*/} [command] -h | --help Print this help message. -n | --no-push Do not push submodule changes to upstream. EOF } checkParameters() { while [ -n "$1" ]; do case $1 in -h | --help) usage exit 0 ;; -n | --no-push) noPush=true ;; *) printf '%s: invalid option %s\n' "${0##*/}" "$1" exit 1 ;; esac shift done } updateSubmodules() { git submodule update --remote --merge gitStatus=$(git status --porcelain) grep -q "sadedot" <(echo "$gitStatus") || return if [[ -n $noPush && $noPush = true ]]; then git commit -m "Update sadedot submodule" sadedot git push fi } runScript() { lastFolder=$PWD sadedotParentFolder=$(pwd -P | awk '{ sub(/\/sadedot.*/, ""); print }') cd "$sadedotParentFolder" || { echo "Couldn't cd into '$sadedotParentFolder'." 1>&2 && exit 1; } checkParameters "$@" updateSubmodules cd "$lastFolder" || { echo "Couldn't cd into '$lastFolder'." 1>&2 && exit 1; } } runScript