Created
December 27, 2014 21:17
-
-
Save dkorolev/2b0afff187fdb6ed5cc9 to your computer and use it in GitHub Desktop.
github-install.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 master branch of some GitHub repository and installs it in current directory. | |
GITHUB_REPO=${1:-Bricks} | |
GITHUB_USER=${2:-KnowSheet} | |
GITHUB_BRANCH=${3:-master} | |
TMPDIR=tmp | |
URL=https://github.com/$GITHUB_USER/$GITHUB_REPO/archive/$GITHUB_BRANCH | |
NAME=$GITHUB_REPO-$GITHUB_BRANCH | |
mkdir -p $TMPDIR | |
( | |
cd $TMPDIR; | |
rm -rf $NAME $NAME.zip $GITHUB_REPO; | |
echo -n "github.com/$GITHUB_USER/$GITHUB_REPO@$GITHUB_BRANCH: " | |
echo -n "download..." | |
curl -s -L $URL.zip >$NAME.zip || (echo -e "\b\b\b failed."; exit 1); | |
echo -ne "\b\b\b, unpack..." | |
unzip -q $NAME.zip || (echo -e "\b\b\b failed."; exit 1); | |
rm $NAME.zip; | |
mv $NAME $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 reinstall." | |
echo "mv ${GITHUB_REPO} .$GITHUB_REPO."`date +%Y%m%d-%H%M%S`", then re-run the same command should be safe." | |
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