Last active
July 23, 2016 17:15
-
-
Save gerardroche/d8df308db6f0fec015add3e275d2dc89 to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
set -e | |
unset CDPATH | |
unset IFS | |
show_usage() { | |
cat <<USAGE | |
Usage: $(basename $0) --build <number> | |
USAGE | |
} | |
extract_bz2() { | |
if [ ! -f "$1" ]; then | |
echo >&2 "file does not exist: $1" | |
exit 1 | |
fi | |
if [ -e "$2" ]; then | |
echo >&2 "destination already exists: $2" | |
exit 1 | |
fi | |
mkdir -p "$2" | |
tar -x -j --strip-components 1 -f "$1" -C "$2" | |
} | |
test "$#" = 0 && show_usage && exit 0 | |
BUILD= | |
while test "$#" != 0; do | |
case "$1" in | |
--help|-h) show_usage; exit 0 ;; | |
--build) BUILD="$2"; shift ;; | |
--) shift; break ;; # standard end of options list | |
-*) echo >&2 "$(basename "$0"): unknown option '$1'"; exit 1 ;; | |
*) echo >&2 "$(basename "$0"): unknown argument '$1'"; exit 1 ;; | |
esac | |
shift | |
done | |
if test -z "$BUILD"; then | |
echo >&2 "$(basename "$0"): --build <number> is required" | |
exit 1 | |
fi | |
# TODO auto download and verify build if it isn't already downloaded | |
PACKAGE_PATH="$HOME/Downloads/sublime-builds/sublime_text_3_build_${BUILD}_x64.tar.bz2" | |
DESTINATION_PATH="$HOME/sublime_text_${BUILD}" | |
echo "VERBOSE => package: $PACKAGE_PATH" | |
echo "VERBOSE => destination: $DESTINATION_PATH" | |
if test ! -d "$DESTINATION_PATH"; then | |
if test ! -f "$PACKAGE_PATH"; then | |
echo >&2 "$(basename "$0"): no build package found" | |
exit 1 | |
fi | |
echo "VERBOSE => extracting '$PACKAGE_PATH' -> '$DESTINATION_PATH' ..." | |
extract_bz2 "$PACKAGE_PATH" "$DESTINATION_PATH" | |
fi | |
rm -v "$HOME/sublime_text_3" | |
ln -sv "sublime_text_$BUILD" "$HOME/sublime_text_3" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment