Files
linux-toolkit/scripts/update.sh

40 lines
989 B
Bash
Executable File

#!/bin/bash
# Only begin update process if necessary
if [[ -z "$(git remote show origin | grep "out of date")" ]]; then
exit 0
fi
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
TOOLKIT_DIR="$SCRIPT_DIR"/..
# Load color script
. "$SCRIPT_DIR"/util/color.sh
last_hash=$( git rev-parse HEAD )
recent_hashes=$( git log --format=format:%H | grep -B 100 $last_hash)
print_info Resetting repo and pulling latest commits...
# 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
# matches toolkit state
while IFS= read -r hash; do
short_hash=$( echo "$hash" | cut -c -7 )
print_info Running patch script \'"$short_hash"\'
. "$SCRIPT_DIR"/../patches/*-"$short_hash".sh 2>/dev/null
done <<< "$recent_hashes"
print_info Update complete