Skip to content

Instantly share code, notes, and snippets.

@diginfo
Last active November 18, 2021 04:25
Show Gist options
  • Save diginfo/62fa8ccc4277d80d9bbb4aee89d9e900 to your computer and use it in GitHub Desktop.
Save diginfo/62fa8ccc4277d80d9bbb4aee89d9e900 to your computer and use it in GitHub Desktop.
#!/bin/bash
## bash <(curl -Ls https://gist.github.com/diginfo/62fa8ccc4277d80d9bbb4aee89d9e900/raw/)
##
## Requires private key with repo-name.key:i.e. pure3-bin.key, pure3.key
_ROOT="/usr/share/dis";
echo "This will clone the repository into your current folder.";
echo "You require a deploy key file in order to proceed.";
echo "If you are a DIS ADMIN you can use pure-keygen to generate the keys";
if [ ! $2 ]; then
read -e -p "Enter REPO ID > " -i "pure3-bin" REPO;
read -e -p "Path to private key > " -i "./user@$REPO.pri" SRC;
else
REPO="$1";
SRC="$2"
fi
if [ ! -f "$SRC" ]; then
echo "ERROR: $SRC key not found."
echo "pure-deploy.sh [repoid] [private.key]"
echo "i.e. pure-deploy.sh pure3-bin ./user@pure3-bin.pri"
exit 1;
else
echo "Cloning $REPO using $SRC..."
fi
## Install Git & gh (github cli) if Not installed
if [ ! -f "/usr/bin/git" ]; then
apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0
apt-add-repository https://cli.github.com/packages
update
sudo apt install git gh
fi
## SSH COPY PATHS
TGT="/etc/ssh/$REPO"
CONFIG="/etc/ssh/ssh_config"
#TGT="/usr/share/dev/keys/test/$REPO"
#CONFIG="/usr/share/dev/keys/test/ssh_config"
## Copy key to /etc/ssh
cp -rp $SRC $TGT;
chmod 600 $TGT;
## add to /etc/ssh/ssh_config
echo "adding config..."
cat <<EOF >>$CONFIG
## GITHUB - $REPO ##
#######################
Host github.com
Hostname github.com
IdentityFile $TGT
User git
IdentitiesOnly yes
EOF
## Add github.com to known hosts
ssh-keyscan github.com >> ~/.ssh/known_hosts
## 210825 - Silence SSH Info & Warnings
echo "" >> $CONFIG;
echo "## Silence Info & Warnings" >> $CONFIG;
echo "Host *" >> $CONFIG;
echo " LogLevel error" >> $CONFIG;
## Create dis toot folder
if [ ! -d "$_ROOT" ];then
mkdir -p $_ROOT
fi
## clone repo
cd $_ROOT;
git clone git@github.com:diginfo/$REPO.git
cd $REPO;
## add remote if .git folder
if [ ! -d ".git" ]; then
echo "This is not a repo folder, cannot set remote."
else
git remote set-url origin "git@$REPO.github.com:diginfo/$REPO.git";
git remote set-url origin "" --push
fi
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
read -p "Delete $SRC Key Y/N? " -n 1 -r
echo
if [[ $REPLY =~ ^[Nn]$ ]]; then
exit 0
else
echo "DELETING $SRC";
fi
#cat $CONFIG;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment