Last active
April 21, 2024 00:38
-
-
Save georgeyjm/9433a5d0eb678227306baaf52f3d7a6c to your computer and use it in GitHub Desktop.
Ubuntu Server Basic Setup
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 | |
function main() { | |
# Create Non-Root User | |
# read -rp "Create a new non-root user? [y/N] " flag_create_user | |
# if [[ $createUser == [nN] ]]; then | |
# username=$(whoami) | |
# updateUserAccount "${username}" | |
# elif [[ $createUser == [yY] ]]; then | |
# read -rp "Enter the username of the new user account: " username | |
# addUserAccount "${username}" | |
# else | |
# echo 'Invalid choice!' | |
# exit 1 | |
# fi | |
# Configuration | |
read -rp "Prepare server for web hosting? [y/N] " flag_install_web | |
read -rp "Prepare server for Python development? [y/N] " flag_install_python | |
# if [[ $flag_install_web != [nN] ]] | |
# Change SSH Port | |
read -ep "SSH Port: " -i "7394" ssh_port | |
sudo sed -i '/#Port 22/c\Port {{ ssh_port }}' /etc/ssh/sshd_config | |
echo "Starting..." | |
sudo apt update && sudo apt upgrade -y | |
sudo apt install -y git curl ca-certificates python3 python3-dev | |
setup_firewall | |
install_zsh | |
install_ftp | |
if [[ $flag_install_web == [yY] ]]; then | |
install_caddy | |
install_docker | |
fi | |
if [[ $flag_install_python == [yY] ]]; then | |
install_micromamba | |
fi | |
sudo apt install -y htop exa jq unzip | |
# Bat | |
# TODO: automate installation of bat | |
# Zoxide and fzf | |
curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash | |
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf | |
~/.fzf/install | |
# Vim-Plug | |
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ | |
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim | |
# Antidote | |
git clone --depth=1 https://github.com/mattmc3/antidote.git ${HOME}/.antidote | |
# Dotbot | |
git clone https://github.com/georgeyjm/dotfiles ${HOME}/.dotfiles | |
chmod +x ${HOME}/.dotfiles/install | |
${HOME}/.dotfiles/install | |
vim +'PlugInstall --sync' +qa | |
echo "Done!" | |
} | |
function install_zsh() { | |
# Oh My Zsh | |
# This installation will exit the current shell and therefore the setup process | |
# TODO: find a workaround | |
sudo apt install -y zsh | |
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" | |
} | |
function setup_firewall() { | |
sudo ufw allow OpenSSH | |
sudo ufw allow ${ssh_port}/tcp | |
if [[ $flag_install_web == [yY] ]]; then | |
sudo ufw allow http | |
sudo ufw allow https | |
fi | |
sudo ufw enable | |
} | |
function install_ftp() { | |
sudo apt install -y vsftpd | |
sudo systemctl start vsftpd | |
sudo systemctl enable vsftpd | |
} | |
function install_caddy() { | |
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https | |
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg | |
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list | |
sudo apt update | |
sudo apt install -y caddy | |
# Setup web directory | |
sudo mkdir -p /srv/www/html | |
sudo chown -R $(whoami) /srv/www | |
} | |
function install_docker() { | |
sudo install -m 0755 -d /etc/apt/keyrings | |
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc | |
sudo chmod a+r /etc/apt/keyrings/docker.asc | |
echo \ | |
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ | |
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ | |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
sudo apt update | |
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | |
} | |
function install_micromamba() { | |
# "${SHELL}" <(curl -L micro.mamba.pm/install.sh) | |
"/bin/zsh" <(curl -L micro.mamba.pm/install.sh) | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment