Skip to content

Instantly share code, notes, and snippets.

@andsens
Last active December 27, 2023 12:47
Show Gist options
  • Star 78 You must be signed in to star a gist
  • Fork 31 You must be signed in to fork a gist
  • Save andsens/2913223 to your computer and use it in GitHub Desktop.
Save andsens/2913223 to your computer and use it in GitHub Desktop.
Script that can set up an entire user account with homeshick automatically
#!/bin/bash -ex
# Paste this into ssh
# curl -sL https://gist.github.com/andsens/2913223/raw/bootstrap_homeshick.sh | tar -xzO | /bin/bash -ex
# When forking, you can get the URL from the raw (<>) button.
### Set some command variables depending on whether we are root or not ###
# This assumes you use a debian derivate, replace with yum, pacman etc.
aptget='sudo apt-get'
chsh='sudo chsh'
if [ `whoami` = 'root' ]; then
aptget='apt-get'
chsh='chsh'
fi
### Install git and some other tools we'd like to use ###
$aptget update
$aptget install -y zsh tmux vim git
### Install homeshick ###
git clone git://github.com/andsens/homeshick.git $HOME/.homesick/repos/homeshick
source $HOME/.homesick/repos/homeshick/homeshick.sh
### Trust github ###
mkdir -p .ssh
cat <<EOF >> .ssh/known_hosts
|1|6WX8FDwncDK8tfyfkLLbvyepVRw=|15RHFpHg3GHML7eJqvNL/yVYChI= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
|1|cccEMXs7ur0u/JXs4NQYv4A9Xb8=|Pddv+wa776NKeZ4v1yMn1cZWt4s= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
EOF
### Set SSH_AUTH_SOCK etc. ###
eval `ssh-agent -s`
### Deploy private dotfiles ###
cat > .dotfiles-deploy-key <<EOF
-----BEGIN RSA PRIVATE KEY-----
MII.............................................................
................................................................
.....................==
-----END RSA PRIVATE KEY-----
EOF
chmod 600 .dotfiles-deploy-key
ssh-add .dotfiles-deploy-key
homeshick --batch clone git@github.com:username/dotfiles
ssh-add -D
rm .dotfiles-deploy-key
### Clone public repos ###
homeshick clone --batch robbyrussell/oh-my-zsh
### Link it all to $HOME ###
homeshick link --force
### Set default shell to your favorite shell ###
$chsh --shell /bin/zsh `whoami`
echo "Log in again to start your proper shell"
@brandonparsons
Copy link

How exactly are you supposed to put the private key in there? Just commit it to the github repo because the only thing it is exposing is read-only access to an already public repository?

@andsens
Copy link
Author

andsens commented Jan 6, 2014

The private key is supposed to be the deployment key for a private dotfiles repo. The gist itself is supposed to be secret (so that the key is not exposed to the public). Secret gists still have a URL you can access publicly though.
Once you have deployed your dotfiles, it is assumed that you have agent forwarding enabled when pulling.

Did that answer the question?

@ngaloppo
Copy link

@andsens if the gist is private, how will you get to it in the first place?

@steveej
Copy link

steveej commented Jan 30, 2018

@ngaloppo Private means it's not publicly listed but publicly accessible if you know the URL. This makes it way too dangerous for containing a secret IMHO. It's probably most practical to keep a password-protected deployment key on an external storage.

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