-
-
Save govindkailas/095874ad49703194ad0ed3370824af23 to your computer and use it in GitHub Desktop.
Self-updating bash script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
VERSION="0.0.2" | |
SCRIPT_URL='https://gist.github.com/cubedtear/54434fc66439fc4e04e28bd658189701/raw' | |
SCRIPT_DESCRIPTION="" | |
SCRIPT_LOCATION="${BASH_SOURCE[@]}" | |
rm -f updater.sh | |
function update() | |
{ | |
TMP_FILE=$(mktemp -p "" "XXXXX.sh") | |
curl -s -L "$SCRIPT_URL" > "$TMP_FILE" | |
NEW_VER=$(grep "^VERSION" "$TMP_FILE" | awk -F'[="]' '{print $3}') | |
ABS_SCRIPT_PATH=$(readlink -f "$SCRIPT_LOCATION") | |
if [ "$VERSION" \< "$NEW_VER" ] | |
then | |
printf "Updating script \e[31;1m%s\e[0m -> \e[32;1m%s\e[0m\n" "$VERSION" "$NEW_VER" | |
echo "cp \"$TMP_FILE\" \"$ABS_SCRIPT_PATH\"" > updater.sh | |
echo "rm -f \"$TMP_FILE\"" >> updater.sh | |
echo "echo Running script again: `basename ${BASH_SOURCE[@]}` $@" >> updater.sh | |
echo "exec \"$ABS_SCRIPT_PATH\" \"$@\"" >> updater.sh | |
chmod +x updater.sh | |
chmod +x "$TMP_FILE" | |
exec updater.sh | |
else | |
rm -f "$TMP_FILE" | |
fi | |
} | |
update "$@" | |
echo "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment