This script makes it possible to download a private repo (tarball) I had to dig a bit to figure it out.
Take this as a reference or use, whatever you want.
#!/bin/bash | |
CF=~/.git-dprz.sh | |
function info { | |
cat <<- INFO | |
-- Script for downloading PRIVATE(!) git-repos as tar-archive on old systems (like Debian Etch) | |
-- That only have old git - binaries | |
-- | |
-- You need a to create a token, to let it work on, see also: | |
-- https://help.github.com/articles/creating-an-access-token-for-command-line-use/ | |
INFO | |
} | |
function setVariablesAndWrite { | |
echo "GIT-User ?" | |
read GIT_USER | |
echo "GIT-Api-Token ? " | |
read GIT_API_TOKEN | |
echo "GIT-Repo" | |
read GIT_REPO | |
echo "DEST-Dir ? (Where to copy the repo (full-path) -> This also replaces the repo-name)" | |
read DEST_DIR | |
touch $CF | |
echo "#!/bin/bash" > $CF | |
echo "GIT_USER=${GIT_USER}" >> $CF | |
echo "GIT_API_TOKEN=${GIT_API_TOKEN}" >> $CF | |
echo "GIT_REPO=${GIT_REPO}" >> $CF | |
echo "DEST_DIR=${DEST_DIR}" >> $CF | |
# securing it against all odds | |
chown root:root $CF | |
chmod 400 $CF | |
} | |
function createDestDir { | |
if [ ! -d $DEST_DIR ] | |
then | |
mkdir -p $DEST_DIR | |
fi | |
} | |
function rewriteAndCleanupRepo { | |
cd $TMP_DEST_DIR | |
CREATED_LOCAL_REPO_DIR=$(ls | head -n1) | |
cd $CREATED_LOCAL_REPO_DIR | |
mv * .. | |
mv .[!.]* .. | |
cd $TMP_DEST_DIR | |
rm -fR $CREATED_LOCAL_REPO_DIR | |
} | |
function backupDestDir { | |
if [ -d $DEST_DIR ] | |
then | |
rm -fR $DEST_DIR".lastbackup" | |
mv $DEST_DIR $DEST_DIR".lastbackup" | |
fi | |
} | |
info | |
if [ -f $CF ] | |
then | |
# Security option | |
chmod 400 $CF | |
. $CF | |
else | |
setVariablesAndWrite | |
fi | |
TMP_DEST_DIR=$(mktemp -t -p /usr/src -d) | |
curl --insecure -H "Authorization: token ${GIT_API_TOKEN}" -L https://api.github.com/repos/${GIT_USER}/${GIT_REPO}/tarball > $TMP_DEST_DIR/$GIT_REPO.tar.gz | |
echo "Download Successful:"$? | |
cd $TMP_DEST_DIR | |
tar xzvf $GIT_REPO.tar.gz >/dev/null 2>&1 | |
echo "TAR Success :"$? | |
rm -fR $GIT_REPO.tar.gz | |
rewriteAndCleanupRepo | |
createDestDir | |
backupDestDir | |
mv $TMP_DEST_DIR $DEST_DIR | |
echo "New Version is now available under: $DEST_DIR" |