Skip to content

Instantly share code, notes, and snippets.

@Vaviloff
Last active October 14, 2025 10:42
Show Gist options
  • Select an option

  • Save Vaviloff/9ee6b0c68393a98a0e9c715ba4063fe3 to your computer and use it in GitHub Desktop.

Select an option

Save Vaviloff/9ee6b0c68393a98a0e9c715ba4063fe3 to your computer and use it in GitHub Desktop.
#!/bin/bash
# https://gist.github.com/Vaviloff/9ee6b0c68393a98a0e9c715ba4063fe3
# Development box setup script
# Run as root - sets up system for a user $user
user="${1:-vaviloff}"
set -e # Exit on any error
# Set non-interactive mode to prevent prompts
export DEBIAN_FRONTEND=noninteractive
echo "=== Starting Linux Development Box Setup ==="
# Update system
echo "Updating system packages..."
apt update -qq
# Install zsh and other useful software
echo "Installing essential development tools..."
apt install -yq zsh build-essential curl git wget htop rsync tmux mc pv ca-certificates sudo
# Create user '$user' if it doesn't exist
if ! id "$user" &>/dev/null; then
echo "Creating user '$user'..."
useradd -m -s /bin/bash $user
password=$(openssl rand -base64 12)
echo "$user:$password" | chpasswd
echo "User '$user' created with password: $password"
else
echo "User '$user' already exists"
fi
# Add $user to sudoers
echo "Adding $user to sudoers..."
usermod -aG sudo $user
# Set up SSH keys for $user from GitHub
echo "Setting up SSH keys for $user..."
sudo -u $user bash << EOF
cd /home/$user
export HOME=/home/$user
# Create .ssh directory with proper permissions
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# Download public keys from GitHub
curl -fsSL https://github.com/$user.keys -o ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
echo "SSH keys downloaded from GitHub for $user"
EOF
# Set up zsh for $user user
echo "Setting up zsh for $user..."
# Change shell for $user
chsh -s $(which zsh) $user
# Install Oh My Zsh for $user user (run as $user)
sudo -u $user bash << EOF
cd /home/$user
export HOME=/home/$user
# Install Oh My Zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
if [ ! -f ~/.zshrc ]; then
echo "Oh My Zsh installation failed"
exit 1
fi
# Add custom configurations to .zshrc
if [ -f ~/.zshrc ] && ! grep -q "alias dcc='docker compose'" ~/.zshrc; then
echo "Appending custom Zsh configuration..."
cat << 'ZSH_CUSTOM' >> ~/.zshrc
# Custom key bindings and options
bindkey '^U' backward-kill-line
unsetopt nomatch
alias dcc='docker compose'
ZSH_CUSTOM
fi
# Add vim configuration
if ! grep -q "\" Move lines with Alt up/down\"" ~/.vimrc 2>/dev/null; then
echo "Appending custom Vim configuration..."
cat << 'VIMEOF' >> .vimrc
" Usual stuff
set nocompatible
set background=dark
set backspace=2
syntax on
set tabstop=2
set shiftwidth=2
set expandtab
" Move lines with Alt up/down
nnoremap <A-Down> :m .+1<CR>==
nnoremap <A-Up> :m .-2<CR>==
vnoremap <A-Down> :m '>+1<CR>gv=gv
vnoremap <A-Up> :m '<-2<CR>gv=gv
VIMEOF
fi
EOF
echo "Oh My Zsh installed and configured for $user"
# Install Docker
echo "Installing Docker..."
# Remove old docker packages
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do
apt-get remove -yq $pkg 2>/dev/null || true
done
# Add Docker GPG key
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
# Add Docker repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker
apt-get update -qq
apt-get install -yq docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Add $user to docker group
echo "Adding $user to docker group..."
usermod -aG docker $user
# Start and enable Docker service
systemctl start docker
systemctl enable docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment