Skip to content
Merged

Dev #39

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/auth-sudo.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh

##################################################################################
##### Function to authenticate sudo early
Expand Down
61 changes: 29 additions & 32 deletions scripts/check-env.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh

# shellcheck disable=SC2034

Expand All @@ -9,20 +9,27 @@ check_env() {

print_step "Check the environment for necessary tools and permissions"
start_spinner "Checking..."

{
local req_message
local pm_message
local priv_message

# Check for required commands
REQUIREMENTS="curl sudo"
for req in $REQUIREMENTS; do
if ! command_exists "$req"; then
req_message="$(msg_err "Missing required command: $req")"
exit 1
fi
done
pm_message
priv_message
continue=true

# Determine privilege escalation method
if [ "$(id -u)" -eq 0 ]; then
# Running as root
SUDO_CMD=""
priv_message="$(msg_ok "Running as root, sudo is not needed.")"
elif command_exists sudo; then
SUDO_CMD="sudo"
priv_message="$(msg_ok "Using ${BOLD}${ITALIC}${MAGENTA}sudo${RC} for privilege escalation.")"
elif command_exists doas && [ -f "/etc/doas.conf" ]; then
SUDO_CMD="doas"
priv_message="$(msg_ok "Using ${BOLD}${ITALIC}${MAGENTA}doas${RC} for privilege escalation.")"
else
priv_message="$(msg_err "No suitable privilege escalation tool found (sudo/doas).")"
continue=false
fi

# Determine the package manager to use
PACKAGEMANAGER="apt-get dnf yum pacman zypper apk"
Expand All @@ -36,25 +43,15 @@ check_env() {

if [ -z "$PACKAGER" ]; then
pm_message="$(msg_err "No supported package manager found.")"
exit 1
continue=false
fi

# Determine privilege escalation method
if [ "$(id -u)" -eq 0 ]; then
# Running as root
SUDO_CMD=""
priv_message="$(msg_ok "Running as root, sudo is not needed.")"
elif command_exists sudo; then
SUDO_CMD="sudo"
priv_message="$(msg_ok "Using ${BOLD}${ITALIC}${MAGENTA}sudo${RC} for privilege escalation.")"
elif command_exists doas && [ -f "/etc/doas.conf" ]; then
SUDO_CMD="doas"
priv_message="$(msg_ok "Using doas for privilege escalation.")"
else
priv_message="$(msg_err "No suitable privilege escalation tool found (sudo/doas).")"
exit 1
fi
} >> "$LOG_FILE" 2>&1

stop_spinner "$req_message" "$pm_message" "$priv_message"
} >> "${LOG_FILE:-/dev/null}" 2>&1

stop_spinner "$pm_message" "$priv_message"

if [ "$continue" = false ]; then
exit 1
fi
}
2 changes: 1 addition & 1 deletion scripts/command-exists.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh

##################################################################################
##### Function to check if a command exists
Expand Down
14 changes: 7 additions & 7 deletions scripts/conf-zsh-env.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh

# shellcheck disable=SC1091

Expand All @@ -10,12 +10,12 @@ conf_zsh_env() {
print_step "Configure zsh environment"
start_spinner "Configuring..."

{
local message
local zshenv_path
local os_id
local os_like
message=""
zshenv_path=""
os_id=""
os_like=""

{
# zsh's global config dir varies:
# Debian/Arch/Alpine use /etc/zsh,
# RHEL/Fedora-family use /etc/zshenv
Expand All @@ -42,7 +42,7 @@ conf_zsh_env() {
fi
EOF
message="$(msg_ok "Zsh environment configured successfully!")"
} >> "$LOG_FILE" 2>&1
} >> "${LOG_FILE:-/dev/null}" 2>&1

stop_spinner "$message"
}
16 changes: 10 additions & 6 deletions scripts/head.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh

##################################################################################
##### Head
Expand All @@ -10,11 +10,15 @@ head() {
# Define and format output using printf to control line width (80 characters)
if [ -f /etc/os-release ]; then
# shellcheck source=/dev/null
. /etc/os-release
os_name="${ID^}" # e.g. "Ubuntu" or "Debian"
desc="${PRETTY_NAME}" # e.g. "Debian GNU/Linux 12 (bookworm)"
version="${VERSION_ID}" # e.g. "12"
codename="${VERSION_CODENAME}" # e.g. "bookworm"
eval "$(
. /etc/os-release
rest="${ID#?}"
first="${ID%"$rest"}"
printf 'os_name=%s\n' "\"$(printf '%s' "$first" | tr '[:lower:]' '[:upper:]')$rest\""
printf 'desc=%s\n' "\"$PRETTY_NAME\""
printf 'version=%s\n' "\"$VERSION_ID\""
printf 'codename=%s\n' "\"$VERSION_CODENAME\""
)"
else
os_name="Unknown"
desc="Unknown"
Expand Down
86 changes: 49 additions & 37 deletions scripts/install-deps.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
#!/usr/bin/env bash
#!/bin/sh

# shellcheck disable=SC2086

pkg_installed() {
case "$PACKAGER" in
apt-get) dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -q "install ok installed" ;;
dnf|yum|zypper) rpm -q "$1" >/dev/null 2>&1 ;;
pacman) pacman -Q "$1" >/dev/null 2>&1 ;;
apk) apk info -e "$1" >/dev/null 2>&1 ;;
*) return 1 ;;
esac
}

install_pkg() {
case "$PACKAGER" in
apt-get) $SUDO_CMD env DEBIAN_FRONTEND=noninteractive apt-get install -y "$@" ;;
dnf|yum) $SUDO_CMD "$PACKAGER" install -y "$@" ;;
pacman) $SUDO_CMD pacman -S --noconfirm --needed "$@" ;;
zypper) $SUDO_CMD zypper --non-interactive install "$@" ;;
apk) $SUDO_CMD apk add "$@" ;;
*) printf 'Unsupported package manager: %s\n' "$PACKAGER"; return 1 ;;
esac
}

##################################################################################
##### Function to install dependencies
##################################################################################
Expand All @@ -10,42 +31,33 @@ install_deps() {
DEPENDENCIES="stow curl tree wget unzip fontconfig ca-certificates jq"

print_step "Install dependencies"
start_spinner "Installing..."

{
printf "\n##### Function to install dependencies #####\n"

local message
local install_status

case "$PACKAGER" in
pacman)
${SUDO_CMD} pacman-key --init
${SUDO_CMD} "${PACKAGER}" -Sy --needed --noconfirm archlinux-keyring
${SUDO_CMD} "${PACKAGER}" -Syu --needed --noconfirm ${DEPENDENCIES}
;;
dnf | yum | zypper | apt | apt-get)
${SUDO_CMD} "${PACKAGER}" install -y ${DEPENDENCIES}
;;
apk)
${SUDO_CMD} "${PACKAGER}" add ${DEPENDENCIES}
;;
*)
${SUDO_CMD} "${PACKAGER}" install -yq ${DEPENDENCIES}
;;
esac
install_status=$?

if [ "$install_status" -eq 0 ]; then
message="$(msg_ok "Dependencies installed!")"
else
message="$(msg_err "Something went wrong while installing dependencies! Check ${BOLD}${LOG_FILE}${RC} for details.")"

for dep in $DEPENDENCIES; do
start_spinner "Installing..."

message=""
install_status=0

{
if pkg_installed "$dep"; then
message="$(msg_skip "$dep")"
printf "\n--- %s skipped (already installed) ---\n" "$dep"
elif install_pkg "$dep"; then
message="$(msg_install_ok "$dep")"
printf "\n--- %s installed ---\n" "$dep"
else
install_status=$?
message="$(msg_err "Something went wrong while installing ${BOLD}${ITALIC}${MAGENTA}$dep${RC} pkg! Check ${BOLD}${LOG_FILE}${RC} for details.")"
printf "\n--- %s FAILED (exit %s) ---\n" "$dep" "$install_status"
fi
} >> "${LOG_FILE:-/dev/null}" 2>&1

if [ "$install_status" -ne 0 ]; then
stop_spinner "$message"
exit 1
fi
} >> "$LOG_FILE" 2>&1

stop_spinner "$message"

if [ "$install_status" -ne 0 ]; then
exit 1
fi
stop_spinner "$message"

done
}
12 changes: 6 additions & 6 deletions scripts/install-eza.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh

##################################################################################
##### Function to install eza
Expand All @@ -8,11 +8,11 @@ install_eza() {
print_step "Install eza"
start_spinner "Installing..."

message=""

{
printf "\n##### Function to install eza #####\n"

local message

if command_exists eza; then
message="$(msg_skip "eza")"
printf "Installation skipped - eza is already present!\n"
Expand All @@ -23,12 +23,12 @@ install_eza() {
${SUDO_CMD} chown root:root eza
${SUDO_CMD} mv eza /usr/local/bin/eza
if verify_installed eza; then
message="$(msg_ok "Successfully installed ${BOLD}eza${RC}.")"
message="$(msg_install_ok "eza")"
else
message="$(msg_err "Installation of ${BOLD}eza${RC} could not be verified! Check ${BOLD}${LOG_FILE}${RC} for details.")"
message="$(msg_install_err "eza")"
fi
fi
} >> "$LOG_FILE" 2>&1
} >> "${LOG_FILE:-/dev/null}" 2>&1

stop_spinner "$message"
}
14 changes: 7 additions & 7 deletions scripts/install-fd.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh

##################################################################################
##### Function to install fd
Expand All @@ -11,28 +11,28 @@ install_fd() {
print_step "Install fd"
start_spinner "Installing..."

message=""

{
printf "\n##### Function to install fd #####\n"

local message

if command_exists fd; then
message="$(msg_skip "fd")"
printf "Installation skipped - fd is already present!\n"
else
local fd_version
fd_version
fd_version=$(curl -s https://api.github.com/repos/sharkdp/fd/releases/latest | jq -r '.tag_name')
cd /tmp || exit
wget -c "https://github.com/sharkdp/fd/releases/download/${fd_version}/fd-${fd_version}-x86_64-unknown-linux-musl.tar.gz" -O - | tar xz
${SUDO_CMD} mv fd-*/fd /usr/local/bin/fd
${SUDO_CMD} chmod +x /usr/local/bin/fd
if verify_installed fd; then
message="$(msg_ok "Successfully installed ${BOLD}fd${RC}.")"
message="$(msg_install_ok "fd")"
else
message="$(msg_err "Installation of ${BOLD}fd${RC} could not be verified! Check ${BOLD}${LOG_FILE}${RC} for details.")"
message="$(msg_install_err "fd")"
fi
fi
} >> "$LOG_FILE" 2>&1
} >> "${LOG_FILE:-/dev/null}" 2>&1

stop_spinner "$message"
}
15 changes: 7 additions & 8 deletions scripts/install-fzf.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh

##################################################################################
##### Function to install fzf
Expand All @@ -8,12 +8,11 @@ install_fzf() {
print_step "Install fzf"
start_spinner "Installing..."

message=""

{
printf "\n##### Function to install fzf #####\n"

local clone_message
local message

if command_exists fzf; then
message="$(msg_skip "fzf")"
printf "Installation skipped - fzf is already present!\n"
Expand All @@ -23,12 +22,12 @@ install_fzf() {
mkdir -p "$HOME/.local/bin"
ln -sf "$HOME/.fzf/bin/fzf" "$HOME/.local/bin/fzf"
if verify_installed fzf; then
message="$(msg_ok "Successfully installed ${BOLD}fzf${RC}.")"
message="$(msg_install_ok "fzf")"
else
message="$(msg_err "Installation of ${BOLD}fzf${RC} could not be verified! Check ${BOLD}${LOG_FILE}${RC} for details.")"
message="$(msg_install_err "fzf")"
fi
fi
} >> "$LOG_FILE" 2>&1
} >> "${LOG_FILE:-/dev/null}" 2>&1

stop_spinner "$clone_message" "$message"
stop_spinner "$message"
}
Loading
Loading