Skip to content

Instantly share code, notes, and snippets.

@simonrenoult
Last active May 6, 2020 12:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonrenoult/35dc4e82c6715d7ae77fb57f9b2fd524 to your computer and use it in GitHub Desktop.
Save simonrenoult/35dc4e82c6715d7ae77fb57f9b2fd524 to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
# Warning! This script is a work in progress.
#
# The sript is buggy since logout/restarts are needed between some steps (zsh or docker I guess)
# but it's a good reminder of what needs to be done to setup a new machine.
main () {
install_prerequisites
install_and_configure_zsh
copy_ssh_keys
install_and_configure_git
copy_dotfiles
install_and_configure_nodejs
install_applications
}
install_prerequisites () {
start_task "prerequisites"
sudo apt install -y \
build-essential \
curl \
software-properties-common
end_task "prerequisites"
}
install_and_configure_zsh () {
start_task "zsh"
add_task_section "zsh" "Downloading zsh..."
sudo apt install -y zsh
add_task_section "zsh" "Downloading oh-my-zsh..."
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
end_task "zsh"
}
copy_ssh_keys () {
start_task "ssh" "Retrieving ssh keys and moving them to $HOME/.ssh"
add_task_section "ssh" "Path to ssh key:"
read path_to_ssh_keys
mkdir -p $HOME/.ssh
cp -r $path_to_ssh_keys/* $HOME/.ssh/
if [ $? -eq 0 ]; then
echo "Keys were successfully copied!"
else
echo "Error: keys were not copied. Exiting"
fi
add_task_section "ssh" "Fixing ssh permissions..."
chmod 700 $HOME/.ssh
chmod 600 $HOME/.ssh/*
chmod 644 $HOME/.ssh/*.pub
ssh-add
end_task "ssh"
}
install_and_configure_git () {
start_task "git"
add_task_section "git" "Downloading git..."
sudo apt install -y git
add_task_section "git" "Email to use for git:"
read git_email
git config --global user.email "${git_email}"
add_task_section "git" "Name to use for git:"
read git_name
git config --global user.name "${git_name}"
add_task_section "git" "Adding user-level gitignore..."
git config --global core.excludesfile "$HOME/.gitignore"
echo ".idea" >> $HOME/.gitignore
echo "node_modules" >> $HOME/.gitignore
add_task_section "git" "Adding diff-so-fancy..."
git clone https://github.com/so-fancy/diff-so-fancy.git $HOME/bin/diff-so-fancy
git config --global core.pager "diff-so-fancy | less --tabs=4 -RFX"
end_task "git"
}
copy_dotfiles () {
start_task "dotfiles"
add_task_section "dotfiles" "Pulling dotfiles..."
git clone git@github.com:simonrenoult/dotfiles.git $HOME/projects/dotfiles
add_task_section "dotfiles" "Creating .zshrc from dotfiles/main.sh..."
ln -s $HOME/projects/dotfiles/main.sh $HOME/.zshrc
end_task "dotfiles"
}
install_and_configure_nodejs () {
start_task "nodejs"
add_task_section "nodejs" "Installing nvm..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
echo "Careful, nvm automatically adds stuff to .zshrc"
echo "Remove these lines manully if you don't need them."
echo
nvm install --lts
end_task "nodejs"
}
install_applications () {
start_task "applications"
sudo apt install -y \
autojump \
gimp \
gnome-tweaks \
htop \
httpie \
libreoffice \
terminator \
tldr \
vim \
vlc
sudo snap install \
bitwarden \
postman \
spotify
sudo snap install --classic intellij-idea-ultimate
sudo snap install --classic kubectl
sudo snap install --classic sublime-text
# docker
sudo apt install docker.io
sudo systemctl enable --now docker
sudo usermod -aG docker SOMEUSERNAME
docker --version
docker run hello-world
end_task "applications"
}
start_task () {
local task_name="${1}"
local task_description="${2}"
echo
echo "> $task_name": "$task_description"
echo
}
end_task () {
local task_name="${1}"
echo
echo "> $task_name: done!"
echo
}
add_task_section () {
local task_name="${1}"
local task_section="${2}"
echo
echo "> $task_name: $task_section"
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment