Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rom3r4/9d0123d4970fcd2dd7c25d745344d18d to your computer and use it in GitHub Desktop.
Save rom3r4/9d0123d4970fcd2dd7c25d745344d18d to your computer and use it in GitHub Desktop.
Git-Downloader for private repo
#!/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"

Git Downloader for private

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment