# Defines common function and variables used by the scripts function git_clone_or_update() { local url="$1" local destination="$2" local branch="$3" if [[ ! -e "${destination}/.git" ]]; then git clone $([ "${branch}x" != "x" ] && echo "--depth 1 -b ${branch}" || echo "") "$url" "$destination" else cd "$destination" git pull if [[ ! -z "$branch" ]]; then git checkout "${branch}" fi fi } function get_git_hash() { local url="$1" local branch="$2" local commit_id="" # List remote git branches and get the commit id of the branch commit_id="$(git ls-remote -h "$url" |grep "$branch" | cut -d$'\t' -f 1)" # If that doesn't work use the branch instead of the commit id if [[ -z "${commit_id}" ]]; then echo "${branch}" else echo "${commit_id:0:7}" fi } function with_sudo() { echo "Checking sudo $@" if [[ $(whoami) != "root" ]]; then sudo "$@" else "$@" fi }