diff --git a/AGENTS.md b/AGENTS.md index bd66cd3..83ce66d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,14 +2,14 @@ ## Project Overview -Ubuntu Server Bootstrap is an opinionated bash script for provisioning Ubuntu 22+ servers with development and DevOps tools. It installs Docker CE, Docker Compose v2, Zsh with Prezto, and a curated set of CLI tools (ripgrep, fd, fzf, ag, tig, htop, byobu, neovim, etc.). +Ubuntu Server Bootstrap is an opinionated bash script for provisioning Ubuntu 22+ servers with development and DevOps tools. It installs Docker CE, Docker Compose v2, Zsh with Prezto, and a curated set of CLI tools (ripgrep, fd, fzf, ag, tig, htop, byobu, neovim, lazygit, etc.). Supports CLI flags (e.g. `--nvim-deb`, `--help`). **Supported Ubuntu LTS versions:** 22.04, 24.04 (x86_64 only) ## Project Structure ``` -bootstrap.sh # Main provisioning script (~393 lines) +bootstrap.sh # Main provisioning script (~660 lines) run-tests.sh # Test runner - builds Docker images per Ubuntu version Dockerfile # Container definition for testing .github/workflows/ci.yaml # GitHub Actions CI (matrix: 22.04, 24.04) @@ -25,8 +25,9 @@ Dockerfile # Container definition for testing - Error/debug/SIGINT trap handlers are defined for logging context - Variables use `SCREAMING_SNAKE_CASE` and `${VAR}` interpolation (not `$VAR`) - Functions are documented with usage, arguments, return values, and examples -- Utility functions: `log()`, `logError()`, `runCmdAndLog()`, `currentDate()` +- Utility functions: `log()`, `logError()`, `runCmdAndLog()`, `currentDate()`, `usage()` - GitHub API helpers: `getLatestReleaseForRepo()`, `downloadBinaryLatestRelease()` +- CLI argument parsing via `while`/`case` loop (`--nvim-deb`, `--help`) ### Installation Pattern diff --git a/README.md b/README.md index 7e9779b..2839d70 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Ubuntu Server Bootstrap -A slightly opinionated and straightforward script to setup base Ubuntu 18+ servers environment with: +A slightly opinionated and straightforward script to setup base Ubuntu 22+ servers environment with: - Docker CE - [Docker Compose v2](https://github.com/docker/compose) @@ -8,22 +8,23 @@ A slightly opinionated and straightforward script to setup base Ubuntu 18+ serve - ZSH with [Prezto](https://github.com/sorin-ionescu/prezto) - Symlinks `python3` to `python` if `python` command is not found - Tools: + - `build-essential`: Essential build tools (gcc, make, etc.) - [`byobu`](https://ubuntu.com/server/docs/tools-byobu): Enhancement to multiplexers like `screen` or `tmux` - `curl` - [`fd-find`](https://github.com/sharkdp/fd): A simple, fast and user-friendly alternative to 'find' - [`fzf`](https://github.com/junegunn/fzf): A command-line fuzzy finder - `git` - `htop`: Better `top` - - `neovim` + - [`lazygit`](https://github.com/jesseduffield/lazygit): A simple terminal UI for git commands + - [`neovim`](https://neovim.io/): Hyperextensible Vim-based text editor (set as default `vi`/`vim`) - [`ripgrep`](https://github.com/BurntSushi/ripgrep): Recursively searches directories for a regex pattern while respecting your gitignore - [`silversearcher-ag`](https://github.com/ggreer/the_silver_searcher): A code-searching tool similar to ack, but faster + - [SpeedTest CLI](https://github.com/sivel/speedtest-cli) - [`tig`](https://jonas.github.io/tig/): CLI Git client - `unzip` - `vim` - `wget` - `zip` - - [SpaceVim](https://spacevim.org/) - - [SpeedTest CLI](https://github.com/sivel/speedtest-cli) > **This script is intended to be run as `root`**. > @@ -31,7 +32,6 @@ A slightly opinionated and straightforward script to setup base Ubuntu 18+ serve It's tested with the following Ubuntu LTS versions: -- `20.04` - `22.04` - `24.04` @@ -51,6 +51,26 @@ Or with `curl` if already installed: curl -s https://raw.githubusercontent.com/yorch/ubuntu-server-bootstrap/main/bootstrap.sh | bash ``` +### Options + +To see all available options: + +```bash +bash bootstrap.sh --help +``` + +| Flag | Description | +|------|-------------| +| `--nvim-deb` | Install NeoVim from GitHub releases `.deb` package (default: PPA unstable) | +| `--help` | Show usage information and exit | + +To use flags, download the script first: + +```bash +wget -q -O bootstrap.sh https://raw.githubusercontent.com/yorch/ubuntu-server-bootstrap/main/bootstrap.sh +bash bootstrap.sh --nvim-deb +``` + This will take a few minutes, after its done, you might want to restart the box in case there is a newer kernel installed that just got installed. At the minimum, you should log out and log in again so `zsh` gets activated on your session. diff --git a/bootstrap.sh b/bootstrap.sh index 11aeeef..956e40f 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -35,6 +35,7 @@ USR_BIN_DIR=/usr/local/bin # -f, --fail Fail silently (no output at all) on HTTP errors CURL_CMD="curl -sSLf" +NVIM_USE_DEB=false SPINNER_PID="" UBUNTU_SUPPORTED_VERSIONS=( @@ -42,6 +43,27 @@ UBUNTU_SUPPORTED_VERSIONS=( "24.04" ) +############################################################################### +# Usage +############################################################################### + +# Print usage information and available options +# Usage: usage +# Arguments: none +# Returns: 0 +# Example: usage +function usage() { + echo "Usage: $(basename "${0}") [OPTIONS]" + echo + echo "Bootstrap an Ubuntu server with development and DevOps tools." + echo + echo "Options:" + echo " --nvim-deb Install NeoVim from GitHub releases .deb package" + echo " (default: install from PPA unstable)" + echo " --help Show this help message and exit" + echo +} + ############################################################################### # Utils ############################################################################### @@ -293,6 +315,7 @@ function stepSetLocales() { function stepInstallTools() { logStep "Installing tools..." runCmdAndLog ${APT_INSTALL} \ + build-essential \ byobu \ curl \ fd-find \ @@ -384,6 +407,35 @@ function stepInstallDockerSwitch() { fi } +# Install LazyGit TUI from GitHub releases +# Usage: stepInstallLazyGit +# Arguments: none +# Returns: 0 on success, non-zero on error +# Example: stepInstallLazyGit +function stepInstallLazyGit() { + local LAZYGIT_BIN="${USR_BIN_DIR}/lazygit" + local LAZYGIT_REPO="jesseduffield/lazygit" + local LAZYGIT_TMP_FILE="/tmp/lazygit.tar.gz" + if ! [ -e "${LAZYGIT_BIN}" ]; then + logStep "Installing LazyGit..." + local LAZYGIT_VERSION + LAZYGIT_VERSION=$(getLatestReleaseForRepo "${LAZYGIT_REPO}") + # Remove v prefix from version string + LAZYGIT_VERSION="${LAZYGIT_VERSION#v}" + local LAZYGIT_ASSET="lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz" + downloadLatestReleaseArtifact \ + "${LAZYGIT_REPO}" \ + "${LAZYGIT_ASSET}" \ + "${LAZYGIT_TMP_FILE}" + runCmdAndLog tar xf "${LAZYGIT_TMP_FILE}" -C /tmp lazygit + runCmdAndLog install /tmp/lazygit -D -t "${USR_BIN_DIR}/" + runCmdAndLog rm -rf "${LAZYGIT_TMP_FILE}" /tmp/lazygit + log "LazyGit installed." + else + logStep "LazyGit already installed." + fi +} + # Install NeoVim and set it as the default vi/vim editor # Usage: stepInstallNeoVim # Arguments: none @@ -392,10 +444,21 @@ function stepInstallDockerSwitch() { function stepInstallNeoVim() { if ! [ -e "$(command -v nvim)" ]; then logStep "Installing NeoVim..." - # Adds repo for latest neovim version - runCmdAndLog add-apt-repository -y ppa:neovim-ppa/unstable - runCmdAndLog ${APT_CMD} update - runCmdAndLog ${APT_INSTALL} neovim + if [ "${NVIM_USE_DEB}" = true ]; then + # Install from GitHub releases .deb package + local NVIM_TMP_FILE="/tmp/nvim.deb" + downloadLatestReleaseArtifact \ + "neovim/neovim-releases" \ + "nvim-linux-x86_64.deb" \ + "${NVIM_TMP_FILE}" + runCmdAndLog ${APT_INSTALL} "${NVIM_TMP_FILE}" + runCmdAndLog rm -f "${NVIM_TMP_FILE}" + else + # Install from PPA (default) + runCmdAndLog add-apt-repository -y ppa:neovim-ppa/unstable + runCmdAndLog ${APT_CMD} update + runCmdAndLog ${APT_INSTALL} neovim + fi # Set neovim as default vim local NVIM_BIN NVIM_BIN="$(command -v nvim)" @@ -537,6 +600,25 @@ if [ "$(uname -m)" != "x86_64" ]; then exit 1 fi +# Parse command-line arguments +while [ $# -gt 0 ]; do + case "${1}" in + --nvim-deb) + NVIM_USE_DEB=true + ;; + --help) + usage + exit 0 + ;; + *) + logError "Unknown option: ${1}" + usage + exit 1 + ;; + esac + shift +done + STEPS=( stepUpgradePackages stepSetTimezone @@ -545,6 +627,7 @@ STEPS=( stepInstallDocker stepInstallDockerCompose stepInstallDockerSwitch + stepInstallLazyGit stepInstallNeoVim stepInstallSpeedTest stepSetupPython