#!/bin/sh # ╭───────────────╮ # │ env functions │ # ╰───────────────╯ # ───────────────────────────────────< ANSI color codes >─────────────────────────────────── RED='\033[0;31m' CYAN='\033[0;36m' YELLOW='\033[0;33m' LIGHT_GREEN='\033[0;92m' BOLD='\033[1m' NC='\033[0m' # No Color echo_error() { printf "${BOLD}${RED}ERROR: ${NC}${RED}%s${NC}\n" "$1" >&2 } echo_info() { printf "${BOLD}${CYAN}INFO: ${NC}${CYAN}%s${NC}\n" "$1" } echo_warning() { printf "${BOLD}${YELLOW}WARNING: ${NC}${YELLOW}%s${NC}\n" "$1" } echo_note() { printf "${BOLD}${LIGHT_GREEN}NOTE: ${NC}${LIGHT_GREEN}%s${NC}\n" "$1" } command_exists() { command -v "$@" >/dev/null 2>&1 } # ─────────────< Check if the user is root and set sudo variable if necessary >───────────── check_root() { if [ "$(id -u)" -ne 0 ]; then if command_exists sudo; then echo_info "User is not root. Using sudo for privileged operations." _sudo="sudo" else echo_error "No sudo found and you're not root! Can't install packages." return 1 fi else echo_info "Root access confirmed." _sudo="" fi } # ──────────────────────< Check if the given command exists silently >────────────────────── command_exists() { command -v "$@" >/dev/null 2>&1 } _cd() { cd "$1" || echo_error "Could not cd into $1!" } # ─< Distribution detection and installation >──────────────────────────────────────── # checks for variable dist={debian,ubuntu,fedora,arch,suse} get_packager() { if [ -e /etc/os-release ]; then echo_info "Detecting distribution..." . /etc/os-release # ─< Convert $ID and $ID_LIKE to lowercase >────────────────────────────────────────────── ID=$(printf "%s" "$ID" | tr '[:upper:]' '[:lower:]') ID_LIKE=$(printf "%s" "$ID_LIKE" | tr '[:upper:]' '[:lower:]') case "$ID" in ubuntu | pop | linuxmint | elementary) dist="ubuntu" ;; debian | kali | zorin | parrot | deepin | raspbian | devuan) dist="debian" ;; fedora | nobara | rhel | centos) dist="fedora" ;; arch | manjaro | garuda | endeavour | artix) dist="arch" ;; opensuse*) dist="suse" ;; *) if [ "${ID_LIKE#*debian}" != "$ID_LIKE" ]; then dist="debian" echo_note "Detected Debian-based distribution" elif [ "${ID_LIKE#*ubuntu}" != "$ID_LIKE" ]; then dist="ubuntu" echo_note "Detected Ubuntu-based distribution" elif [ "${ID_LIKE#*arch}" != "$ID_LIKE" ]; then dist="arch" echo_note "Detected Arch-based distribution" elif [ "${ID_LIKE#*fedora}" != "$ID_LIKE" ]; then dist="fedora" echo_note "Detected Fedora-based distribution" elif [ "${ID_LIKE#*suse}" != "$ID_LIKE" ]; then dist="suse" echo_note "Detected SUSE-based distribution" else echo_error "Unsupported distribution: $ID" echo_note "Please report this issue with your distribution details" exit 1 fi ;; esac else echo_error "Unable to detect distribution. /etc/os-release not found." exit 1 fi } # ╭────────────────────────────────────╮ # │ insert your scripts/functions here │ # ╰────────────────────────────────────╯ # ─────────────────────────────────────< dependencies >───────────────────────────────────── deps_common="git curl tar" deps_arch="$deps_common gtk4 libadwaita" deps_deb="$deps_common libgtk-4-dev libadwaita-1-dev" deps_fedora="$deps_common gtk4-devel zig libadwaita-devel" deps_suse="$deps_common gtk4-tools libadwaita-devel pkgconf-pkg-config zig" checkDeps="" checkDeps() { get_packager case "$dist" in debian | ubuntu) pkg="apt-get" echo "Detected packagemanager ${RED}${pkg}" echo_info "Updating sources.." $_sudo apt-get update echo_info "Checking dependencies now.." sleep 3 for dep in $deps_deb; do if ! command_exists $dep; then echo_info "Installing $dep.." $_sudo apt-get install "$dep" --assume-yes /dev/null 2>&1 $_sudo ln -rs ./zig/zig /bin/zig } cloneGhostty() { if [ ! "$checkDeps" = "done" ]; then echo_error "Dependencies are not installed, aborting now!" exit 1 fi # buildDir=$(mktemp -d) buildDir="$HOME/.local/ghostty-build" if [ -d "$buildDir" ] && [ -n "$(ls -A "$buildDir")" ]; then echo_warning "Ghostty build directory already exists at ${buildDir}, do you want to remove it? (y/n)" read -r removeBuildDir ─────────────────────────────── main() { if check_root; then checkDeps || ErrorExit "Step 1/3" checkZig || ErrorExit "Step 2/3" cloneGhostty || ErrorExit "Step 3/3" else echo_error "Something went terribly wrong!" fi } main