diff --git a/scripts/update.sh b/scripts/update.sh old mode 100644 new mode 100755 index be2756b..de1fc54 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -1,6 +1,31 @@ #!/bin/bash +# If repo isn't out of date, abort update +if [[ -z "$(git remote show origin | grep "out of date")" ]]; then + exit 0 +fi + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +last_hash=$( git rev-parse HEAD ) + +recent_hashes=$( git log --format=format:%H | grep -B 100 $last_hash) + +# Resets the repo to last state git reset --hard + +# Pulls new commits git pull + +# Downloads or updates repo submodules git submodule update --init --recursive + +# Removes untracked files and directories git clean -fd --force + +# Runs patch scripts to ensure machine state +# is up to date +while IFS= read -r hash; do + short_hash=$( echo $hash | cut -c -7 ) + /usr/bin/bash "$SCRIPT_DIR"/../patches/*-"$short_hash".sh 2>/dev/null +done <<< "$recent_hashes"