#!/bin/sh # env.lat — bootstrap Anton Volnuhin's dotfiles # Usage: sh -c "$(curl -fsSL http://env.lat)" # or: sh -c "$(curl -fsSL http://env.lat)" -- --yes Green='\033[0;32m' Yellow='\033[0;33m' Blue='\033[0;34m' Gray='\033[38;5;7m' NC='\033[0m' # Parse flags ASSUME_YES=0 for arg in "$@"; do case "$arg" in --yes) ASSUME_YES=1 ;; esac done # Detect sudo/doas if [ "$(id -u)" -eq 0 ]; then SUDO="" elif command -v doas >/dev/null 2>&1 && [ -f /etc/doas.conf ]; then SUDO="doas" elif command -v sudo >/dev/null 2>&1; then SUDO="sudo" else SUDO=""; fi pad() { while IFS= read -r line; do case "$line" in "##ENVLAT_END##") cat; return ;; *) printf " ${Gray}%s${NC}\n" "$line" ;; esac done } OS="$(uname -s)" # Banner if [ "$ASSUME_YES" -eq 0 ] && [ -t 0 ] && [ -t 1 ]; then printf "\n${Green}############################################################################### ## ## ## Ready to install Anton Volnuhin's env ## ## ## ## Press ${Yellow}Enter${Green} to continue, ${Yellow}Ctrl-C${Green} to abort ## ## email: anton@volnuhin.com ## ## ## ###############################################################################${NC}\n\n" read dummy fi # Install prerequisites printf "\n--> ${Blue}Installing prerequisites${NC}\n" if [ "$OS" = "FreeBSD" ]; then { $SUDO pkg update && $SUDO pkg upgrade --yes && $SUDO pkg install --yes git chezmoi bash; } 2>&1 | pad elif [ "$OS" = "OpenBSD" ]; then $SUDO pkg_add git chezmoi bash 2>&1 | pad else if ! command -v git >/dev/null 2>&1; then if command -v apt-get >/dev/null 2>&1; then { sudo apt-get update && sudo apt-get install -y git; } 2>&1 | pad elif command -v dnf >/dev/null 2>&1; then sudo dnf install -y git 2>&1 | pad elif command -v pacman >/dev/null 2>&1; then sudo pacman -Sy --noconfirm git 2>&1 | pad fi fi fi # Run chezmoi — ENVLAT tells the dotfiles script a real terminal is behind the pipe printf "\n--> ${Blue}Installing dotfiles via chezmoi${NC}\n" export ENVLAT=1 if [ "$OS" = "FreeBSD" ] || [ "$OS" = "OpenBSD" ]; then chezmoi init --apply https://gitea.setia.cloud/anton/dotfiles.git 2>&1 | pad else sh -c "$(curl -fsLS get.chezmoi.io)" -- -b $HOME/.local/bin init --apply https://gitea.setia.cloud/anton/dotfiles.git 2>&1 | pad fi