Skip to content

Instantly share code, notes, and snippets.

@apiology
Last active February 7, 2025 22:11
Show Gist options
  • Save apiology/797cf72f9f1e52b6337c6863570a73b8 to your computer and use it in GitHub Desktop.
Save apiology/797cf72f9f1e52b6337c6863570a73b8 to your computer and use it in GitHub Desktop.
# to iterate on this:
# 1) hit edit in gist
# 2) change
# 3) hit raw link and copy
# 4) target_url=
# 5) curl -i https://git.io/ -F "url=${target_url:?}" | grep ^Location: | cut -d: -f2-
# ^ above no longer works - if using macos you can probably copy and paste between machines tho
set -xe
cd
# if sudo -v # ensure this is a non-work computer before uncommenting this
# then
# if ! sudo grep $(whoami) /etc/sudoers
# then
# sudo sh -c "echo $(whoami) ALL=NOPASSWD:ALL >> /etc/sudoers"
# fi
# fi
if [ "$(uname -s)" == Darwin ] && ! type brew
then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
if [ $(uname -n) != "${target_hostname:?}" ]
then
if [ "$(uname -s)" == Darwin ]
then
# ensure this is a non-work computer before uncommenting this
# sudo scutil --set HostName "${target_hostname:?}"
# sudo scutil --set ComputerName "${target_hostname:?}"
# sudo scutil --set LocalHostName "${target_hostname:?}"
# dscacheutil -flushcache
# sudo shutdown -r now
true
elif [ "$(uname -s)" == Linux ]
then
sudo hostnamectl set-hostname "${target_hostname:?}"
fi
fi
mkdir -p ~/.ssh
if ! grep 'Host apiology.github.com' ~/.ssh/config
then
cat >> ~/.ssh/config <<EOF
Host apiology.github.com
Hostname github.com
User git
IdentityFile ~/.ssh/$(hostname)-apiology-github
EOF
fi
if [ ! -f ~/.ssh/$(hostname)-apiology-github ]
then
ssh-keygen -N '' -f ~/.ssh/$(hostname)-apiology-github
fi
set +e
ssh -o StrictHostKeyChecking=no apiology.github.com
if [ $? == 255 ]
then
set -e
cat ~/.ssh/$(hostname)-apiology-github.pub
if [ "$(uname -s)" == Darwin ]
then
cat ~/.ssh/$(hostname)-apiology-github.pub | pbcopy
open https://github.com/settings/ssh/new
elif ! [ -z ${DISPLAY} ]
then
sudo apt-get update -y && sudo apt-get install -y xsel
cat ~/.ssh/$(hostname)-apiology-github.pub | xsel -i -b
cat ~/.ssh/$(hostname)-apiology-github.pub
xdg-open https://github.com/settings/ssh/new
fi
read -p "Copy and paste this key into https://github.com/settings/ssh/new under apiology, then press [enter]: "
fi
set -e
if [ ! -f install.sh ]
then
if [ ! -d homedir ]
then
if ! type git >/dev/null 2>&1
then
sudo apt-get update && sudo apt-get install -y git
fi
git clone apiology.github.com:apiology/homedir
fi
( cd homedir && git pull && ./move-in-place.sh )
fi
git pull
./install.sh
echo done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment