Created
December 27, 2014 22:51
-
-
Save dkorolev/71f6d5edd5a0095a2bc8 to your computer and use it in GitHub Desktop.
github-install-v2.sh
This file contains 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/bash | |
# | |
# This script downloads the specified GitHub repository and installs it in current directory. | |
set -u -e | |
# Command-line parameters. | |
GITHUB_REPO=${1:-Bricks} | |
GITHUB_USER=${2:-KnowSheet} | |
GITHUB_BRANCH=${3:-master} | |
# The URL to fetch a .tar.gz from. | |
URL=https://github.com/$GITHUB_USER/$GITHUB_REPO/archive/$GITHUB_BRANCH.tar.gz | |
# A temporary directory, expected to be .gitignore-d. | |
TMPDIR=tmp | |
( | |
mkdir -p $TMPDIR | |
cd $TMPDIR | |
rm -rf $GITHUB_REPO $GITHUB_REPO-$GITHUB_BRANCH | |
echo -n "github.com/$GITHUB_USER/$GITHUB_REPO@$GITHUB_BRANCH: " | |
curl -s -L $URL | tar xfz - || (echo "Failed, please check whether $URL can be fetched."; exit 1) | |
mv $GITHUB_REPO-$GITHUB_BRANCH $GITHUB_REPO | |
echo -ne "\b\b\b, install: " | |
) | |
if [ -d $GITHUB_REPO ] ; then | |
if diff -r $GITHUB_REPO $TMPDIR/$GITHUB_REPO ; then | |
echo "Up to date." | |
else | |
echo "Conflict, please fix or reinstall." | |
echo "For a quick workaround, try renaming the current revision under another name:" | |
echo "mv ${GITHUB_REPO} ${TMPDIR}/$GITHUB_REPO-$(date +%Y%m%d-%H%M%S)" | |
echo "and then re-run the same command." | |
exit 1 | |
fi | |
else | |
mv $TMPDIR/$GITHUB_REPO . | |
echo "Installed." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment