Last active
January 29, 2020 10:36
-
-
Save aseifert/adb09dd06163663c70405547ad4641e0 to your computer and use it in GitHub Desktop.
quickly launch and set up EC2 instances
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
function ec-launch -d "launch new EC2 instance" | |
set -l name "" | |
set -l instancetype m5.4xlarge | |
set -l disksize 100 | |
set -l ami ami-02df9ea15c1778c9c # ubuntu 18.04 | |
set -l keyname alex-eu-west-1 | |
# parse arguments | |
getopts $argv | while read -l key value | |
switch $key | |
case _ | |
set name $value | |
case name | |
set name $value | |
case instancetype | |
set instancetype $value | |
case disksize | |
set disksize $value | |
case ami | |
set ami $value | |
case keyname | |
set keyname $value | |
case h help | |
_al_help >&2 | |
return | |
case v version | |
_al_version >&2 | |
return | |
end | |
end | |
if ! test -n "$name" | |
echo "name has to be set (--name or first arg)" ;and return | |
end | |
# launch instance and save IP | |
set -l IP \ | |
(fe2 launch --name $name --ami $ami --disksize $disksize --instancetype $instancetype --keyname $keyname | cut -d':' -f2 | tr -d ' ') | |
# add github keys | |
scp -o StrictHostKeyChecking=no ~/.ssh/github* ubuntu@$IP:~/.ssh | |
# set up server | |
set -l SETUP_FILE "https://gist.githubusercontent.com/aseifert/acdb016a9ef3ca93f0813534097938ef/raw/setup-linux.sh" | |
ssh ubuntu@$IP "curl -Lks $SETUP_FILE | /bin/bash" | |
# set up TMUX_HOME for auto-loading tmux session (via settings.fish) | |
ssh ubuntu@$IP "fish -c 'set -Ux TMUX_HOME $name'" | |
end | |
function ecc -d "connect to EC2 instance" | |
set -l name "" | |
set -l keyfile ~/.ssh/alex-eu-west-1.pem | |
set -l port 8888 | |
# parse arguments | |
getopts $argv | while read -l key value | |
switch $key | |
case _ | |
set name $value | |
case name | |
set name $value | |
case keyfile | |
set keyfile $value | |
case port | |
set port $value | |
end | |
end | |
# connect to instance | |
fe2 connect $name --keyfile $keyfile $port | |
end |
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
# git clone (using the github ssh key and skipping the host check) | |
GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no -i ~/.ssh/github" \ | |
git clone --bare [email protected]:aseifert/config.git $HOME/.cfg | |
function config { | |
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@ | |
} | |
mkdir -p .config-backup | |
config checkout | |
if [ $? = 0 ]; then | |
echo "Checked out config."; | |
else | |
echo "Backing up pre-existing dot files."; | |
config checkout 2>&1 | egrep "\s+\." | awk {'print $1'} | xargs -I{} mv {} .config-backup/{} | |
fi; | |
config checkout | |
config config status.showUntrackedFiles no |
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
#!/usr/bin/env bash | |
# print every command to shell | |
set -x | |
# create basic file infrastructure | |
mkdir -p ~/bin | |
mkdir -p ~/code | |
[[ -d /data ]] || sudo mkdir -p /data && sudo chown $(whoami) /data | |
# install dotfiles | |
# https://www.atlassian.com/git/tutorials/dotfiles | |
curl -Lks http://bit.ly/2y1lXX0 | /bin/bash | |
# add repos and update | |
sudo add-apt-repository -y ppa:deadsnakes/ppa | |
sudo apt-add-repository -y ppa:fish-shell/release-3 | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | |
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add - | |
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list | |
sudo apt-get update | |
# install ALL the things | |
DOCKER="docker-ce docker-ce-cli containerd.io" | |
MONGO="mongodb-org-tools mongodb-org-shell" | |
sudo apt-get install -y build-essential git python3.7 python3.7-dev fish jq tmux parallel $MONGO $DOCKER | |
sudo apt-get clean | |
# install miniconda | |
wget -nv https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh | |
bash ~/miniconda.sh -b -p ~/miniconda && rm ~/miniconda.sh | |
# silence gnu parallel citation message | |
echo "will cite" | parallel --citation | |
# install ripgrep | |
curl -LOs https://github.com/BurntSushi/ripgrep/releases/download/11.0.2/ripgrep_11.0.2_amd64.deb | |
sudo dpkg -i ripgrep_11.0.2_amd64.deb | |
rm ripgrep_11.0.2_amd64.deb | |
# install fd | |
curl -LOs https://github.com/sharkdp/fd/releases/download/v7.3.0/fd_7.3.0_amd64.deb | |
sudo dpkg -i fd_7.3.0_amd64.deb | |
rm fd_7.3.0_amd64.deb | |
# install bat | |
curl -LOs https://github.com/sharkdp/bat/releases/download/v0.11.0/bat_0.11.0_amd64.deb | |
sudo dpkg -i bat_0.11.0_amd64.deb | |
rm bat_0.11.0_amd64.deb | |
# install micro | |
curl https://getmic.ro | bash | |
chmod +x micro | |
mv micro ~/bin/ | |
# install lazydocker | |
curl https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash | |
# install lazygit | |
wget -O lazygit.tgz https://github.com/jesseduffield/lazygit/releases/download/v0.9/lazygit_0.9_Linux_x86_64.tar.gz | |
tar xvf lazygit.tgz | |
mv lazygit ~/bin/ | |
rm LICENSE README.md lazygit.tgz | |
# set up docker | |
sudo apt install -y gnupg2 pass # needed for docker login | |
sudo usermod -aG docker $USER | |
# remove ~/Library/ dir which contains dotfiles for Mac | |
rm -rf ~/Library/ | |
# since this is a new instance, we don't need the ~/.config-backup/ either | |
rm -rf ~/.config-backup/ | |
# install diff so fancy | |
# https://raw.githubusercontent.com/so-fancy/diff-so-fancy/master/third_party/build_fatpack/diff-so-fancy | |
# git config --global core.pager "diff-so-fancy | less --tabs=4 -RFX" | |
wget -O ~/bin/diff-so-fancy https://raw.githubusercontent.com/so-fancy/diff-so-fancy/master/third_party/build_fatpack/diff-so-fancy | |
chmod +x ~/bin/diff-so-fancy | |
# set up miniconda | |
fish -c 'set -Ux CONDA_ROOT ~/miniconda' | |
~/miniconda/condabin/conda update -y -n base -c defaults conda | |
~/miniconda/condabin/conda create -y -n py3 python=3.7 | |
~/miniconda/condabin/conda clean -y -a | |
# set up fish | |
curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish && fish -c fisher | |
sudo chsh -s $(which fish) $(whoami) | |
# set timezone | |
sudo timedatectl set-timezone Europe/Vienna | |
# set up projects to install | |
fish -c 'set -Ux CODE_DIR ~/code ;and \ | |
set -Ux GIT_GET_PROJECTS IWAtech/docsim aseifert/manz-ofai ;and \ | |
set -Ux PIP_GIT_PROJECTS IWAtech/apollonlp ;and \ | |
pip-git ;and git-get' | |
# set public IP address | |
fish -c 'set -Ux IP (dig +short myip.opendns.com @resolver1.opendns.com)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment