Last active
January 19, 2021 16:14
-
-
Save callaginn/04075da7f9ea9e691fc8034fbd56e205 to your computer and use it in GitHub Desktop.
Capture Setup Info / Generate an SSH Key for Pulling Private Setup Repo
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 | |
# Simple Alert Function | |
alert () { | |
tput bold; tput setaf 11; echo "$1"; tput sgr0; | |
} | |
# ============================================================================== | |
# START SETUP | |
# Creates new SSH key, copies it to Github, and clones private config repo. | |
# ============================================================================== | |
# Might as well ask for password up-front, right? | |
sudo -v | |
# Keep-alive: update existing sudo time stamp if set, otherwise do nothing. | |
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & | |
# Include configuration file | |
test -f ~/.setup && . $_ | |
# NOTE: Homebrew automatically installs XCode, without any prompts. Git requires this. | |
if [[ ! $(which brew) ]]; then | |
alert "Installing Homebrew..." | |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" | |
brew cleanup | |
brew doctor | |
fi | |
if [[ ! -d ~/.ssh ]]; then | |
ssh_title="$(scutil --get ComputerName) ($(date +'%Y-%m-%d'))" | |
alert "Creating New SSH Key" | |
ssh-keygen -f ~/.ssh/$ssh_file -t rsa -b 4096 -C $git_email -P "" | |
echo -e "Host *\n AddKeysToAgent yes\n UseKeychain yes\n IdentityFile ~/.ssh/$ssh_file" >> ~/.ssh/config | |
ssh-add -K ~/.ssh/$ssh_file | |
alert "Adding SSH Key to GitHub" | |
curl -u "$github_user:$github_pwd" --data '{"title": "'"$ssh_title"'", "key":"'"$(cat ~/.ssh/id_rsa.pub)"'"}' https://api.github.com/user/keys | |
alert "Testing your connection to Github" | |
ssh -T git@github.com | |
alert "Uploading SSH Key to Your Webhost" | |
cat ~/.ssh/$ssh_file.pub | ssh $ssh_user@$ssh_host "test -d ~/.ssh || mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys" | |
fi | |
if [[ ! -d $sites/config ]]; then | |
alert "Cloning Config Repo" | |
test ! -d $sites && sudo mkdir $_ && sudo chown -R $USER $_ | |
git clone "$setup_repo" $sites/config | |
fi | |
echo | |
alert "Please run the following scripts to finish the initial setup:" | |
echo "$install/bash-config.sh" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script sets up an SSH key, which is copied to both GitHub and your webhost. It also does some basic git configuration and allows you to pull down a private setup repo to a custom location.
Requirements
macOS High Sierra -- it might work on Sierra, but not tested
How To Install
setup.sh
script on your desktop. This will save a~/.setup
file with the configuration data on your clipboard. Any missing info will be requested during the setup process.Known Issues
• This script asks for your password twice, since I haven't decided which password retrieval method to use.
• The web server asks for your password. I've discovered the ssh command will not let you include a password. Technically, though, the server section doesn't have to be included in this gist...so we could likely install sshpass after brew is installed.