Use consistent bash5 style for conditionals and quoting

This commit is contained in:
David Heinemeier Hansson
2026-02-21 10:18:47 +01:00
parent d2acf3b6ba
commit 7514ae7dcf
113 changed files with 289 additions and 287 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
# Set identification from install inputs
if [[ -n "${OMARCHY_USER_NAME//[[:space:]]/}" ]]; then
if [[ -n ${OMARCHY_USER_NAME//[[:space:]]/} ]]; then
git config --global user.name "$OMARCHY_USER_NAME"
fi
if [[ -n "${OMARCHY_USER_EMAIL//[[:space:]]/}" ]]; then
if [[ -n ${OMARCHY_USER_EMAIL//[[:space:]]/} ]]; then
git config --global user.email "$OMARCHY_USER_EMAIL"
fi
@@ -1,10 +1,10 @@
# Detect MacBook models that need SPI keyboard modules
product_name="$(cat /sys/class/dmi/id/product_name 2>/dev/null)"
if [[ "$product_name" =~ MacBook[89],1|MacBook1[02],1|MacBookPro13,[123]|MacBookPro14,[123] ]]; then
if [[ $product_name =~ MacBook[89],1|MacBook1[02],1|MacBookPro13,[123]|MacBookPro14,[123] ]]; then
echo "Detected MacBook with SPI keyboard"
omarchy-pkg-add macbook12-spi-driver-dkms
if [[ "$product_name" == "MacBook8,1" ]]; then
if [[ $product_name == "MacBook8,1" ]]; then
echo "MODULES=(applespi spi_pxa2xx_platform spi_pxa2xx_pci)" | sudo tee /etc/mkinitcpio.conf.d/macbook_spi_modules.conf >/dev/null
else
echo "MODULES=(applespi intel_lpss_pci spi_pxa2xx_platform)" | sudo tee /etc/mkinitcpio.conf.d/macbook_spi_modules.conf >/dev/null
@@ -2,12 +2,12 @@
# This prevents NVMe drives from failing to wake from sleep properly
MACBOOK_MODEL=$(cat /sys/class/dmi/id/product_name 2>/dev/null || true)
if [[ "$MACBOOK_MODEL" =~ MacBook(8,1|9,1|10,1)|MacBookPro13,[123]|MacBookPro14,[123] ]]; then
if [[ $MACBOOK_MODEL =~ MacBook(8,1|9,1|10,1)|MacBookPro13,[123]|MacBookPro14,[123] ]]; then
echo "Detected MacBook model: $MACBOOK_MODEL"
NVME_DEVICE="/sys/bus/pci/devices/0000:01:00.0/d3cold_allowed"
if [[ -f "$NVME_DEVICE" ]]; then
if [[ -f $NVME_DEVICE ]]; then
echo "Applying NVMe suspend fix..."
cat <<EOF | sudo tee /etc/systemd/system/omarchy-nvme-suspend-fix.service >/dev/null
@@ -7,7 +7,7 @@ if omarchy-hw-asus-rog; then
# Unmute the Master control on the ALC285 card (often muted by default)
card=$(aplay -l 2>/dev/null | grep -i "ALC285" | head -1 | sed 's/card \([0-9]*\).*/\1/')
if [[ -n "$card" ]]; then
if [[ -n $card ]]; then
amixer -c "$card" set Master 80% unmute 2>/dev/null
fi
fi
@@ -2,17 +2,17 @@
# Module list derived from Chris McLeod's manual install instructions
# https://chrismcleod.dev/blog/installing-arch-linux-with-secure-boot-on-a-microsoft-surface-laptop-studio/
product_name="$(cat /sys/class/dmi/id/product_name 2>/dev/null)"
if [[ "$product_name" =~ Surface ]]; then
if [[ $product_name =~ Surface ]]; then
echo "Detected Surface Device"
# Modules already exist in the rootfs for the default kernel.
if [[ "$product_name" != "Surface Laptop 3" ]]; then
if [[ $product_name != "Surface Laptop 3" ]]; then
echo "Untested Surface Device: $product_name, additional modules may be required for your device."
fi
echo "Attempting to autodetect required pinctrl module"
pinctrl_module=$(lsmod | grep pinctrl_ | cut -f 1 -d" ")
if [[ -z "$pinctrl_module" ]]; then
if [[ -z $pinctrl_module ]]; then
echo "Failed to autodetect pinctrl module."
else
echo "Detected pinctrl module: $pinctrl_module"
+2 -2
View File
@@ -2,9 +2,9 @@
# Check if we have an Intel GPU at all
if INTEL_GPU=$(lspci | grep -iE 'vga|3d|display' | grep -i 'intel'); then
# HD Graphics and newer uses intel-media-driver
if [[ "${INTEL_GPU,,}" =~ "hd graphics"|"xe"|"iris" ]]; then
if [[ ${INTEL_GPU,,} =~ "hd graphics"|"xe"|"iris" ]]; then
omarchy-pkg-add intel-media-driver
elif [[ "${INTEL_GPU,,}" =~ "gma" ]]; then
elif [[ ${INTEL_GPU,,} =~ "gma" ]]; then
# Older generations from 2008 to ~2014-2017 use libva-intel-driver
omarchy-pkg-add libva-intel-driver
fi
@@ -4,11 +4,11 @@
legacy_drivers=("radeon")
for card in /sys/class/drm/card*; do
if [[ -e "$card/device/driver" ]]; then
if [[ -e $card/device/driver ]]; then
driver=$(basename "$(readlink -f "$card/device/driver")")
for legacy in "${legacy_drivers[@]}"; do
if [[ "$driver" == "$legacy" ]]; then
if [[ $driver == $legacy ]]; then
omarchy-install-terminal alacritty
exit 0
fi
+4 -4
View File
@@ -1,6 +1,6 @@
NVIDIA="$(lspci | grep -i 'nvidia')"
if [ -n "$NVIDIA" ]; then
if [[ -n $NVIDIA ]]; then
# Check which kernel is installed and set appropriate headers package
KERNEL_HEADERS="$(pacman -Qqs '^linux(-zen|-lts|-hardened)?$' | head -1)-headers"
@@ -14,7 +14,7 @@ if [ -n "$NVIDIA" ]; then
GPU_ARCH="maxwell_pascal_volta"
fi
# Bail if no supported GPU
if [ -z "${PACKAGES+x}" ]; then
if [[ -z ${PACKAGES+x} ]]; then
echo "No compatible driver for your NVIDIA GPU. See: https://wiki.archlinux.org/title/NVIDIA"
exit 0
fi
@@ -32,7 +32,7 @@ MODULES+=(nvidia nvidia_modeset nvidia_uvm nvidia_drm)
EOF
# Add NVIDIA environment variables based on GPU architecture
if [ "$GPU_ARCH" = "turing_plus" ]; then
if [[ $GPU_ARCH = "turing_plus" ]]; then
# Turing+ (RTX 20xx, GTX 16xx, and newer) with GSP firmware support
cat >>"$HOME/.config/hypr/envs.conf" <<'EOF'
@@ -41,7 +41,7 @@ env = NVD_BACKEND,direct
env = LIBVA_DRIVER_NAME,nvidia
env = __GLX_VENDOR_LIBRARY_NAME,nvidia
EOF
elif [ "$GPU_ARCH" = "maxwell_pascal_volta" ]; then
elif [[ $GPU_ARCH = "maxwell_pascal_volta" ]]; then
# Maxwell/Pascal/Volta (GTX 9xx/10xx, GT 10xx, Quadro P/M/GV, MX series, Titan X/Xp/V) lack GSP firmware
cat >>"$HOME/.config/hypr/envs.conf" <<'EOF'
@@ -1,13 +1,13 @@
# First check that wireless-regdb is there
if [ -f "/etc/conf.d/wireless-regdom" ]; then
if [[ -f "/etc/conf.d/wireless-regdom" ]]; then
unset WIRELESS_REGDOM
. /etc/conf.d/wireless-regdom
fi
# If the region is already set, we're done
if [ ! -n "${WIRELESS_REGDOM}" ]; then
if [[ ! -n ${WIRELESS_REGDOM} ]]; then
# Get the current timezone
if [ -e "/etc/localtime" ]; then
if [[ -e "/etc/localtime" ]]; then
TIMEZONE=$(readlink -f /etc/localtime)
TIMEZONE=${TIMEZONE#/usr/share/zoneinfo/}
@@ -15,12 +15,12 @@ if [ ! -n "${WIRELESS_REGDOM}" ]; then
COUNTRY="${TIMEZONE%%/*}"
# If we don't have a two letter country, get it from the timezone table
if [[ ! "$COUNTRY" =~ ^[A-Z]{2}$ ]] && [ -f "/usr/share/zoneinfo/zone.tab" ]; then
if [[ ! $COUNTRY =~ ^[A-Z]{2}$ ]] && [[ -f /usr/share/zoneinfo/zone.tab ]]; then
COUNTRY=$(awk -v tz="$TIMEZONE" '$3 == tz {print $1; exit}' /usr/share/zoneinfo/zone.tab)
fi
# Check if we have a two letter country code
if [[ "$COUNTRY" =~ ^[A-Z]{2}$ ]]; then
if [[ $COUNTRY =~ ^[A-Z]{2}$ ]]; then
# Append it to the wireless-regdom conf file that is used at boot
echo "WIRELESS_REGDOM=\"$COUNTRY\"" | sudo tee -a /etc/conf.d/wireless-regdom >/dev/null
+1 -1
View File
@@ -15,6 +15,6 @@ for vendor in "${!VULKAN_DRIVERS[@]}"; do
fi
done
if [ ${#PACKAGES[@]} -gt 0 ]; then
if (( ${#PACKAGES[@]} > 0 )); then
omarchy-pkg-add "${PACKAGES[@]}"
fi
+1 -1
View File
@@ -10,7 +10,7 @@ EOF
mise trust ~/Work/.mise.toml
if [[ -n "${OMARCHY_CHROOT_INSTALL:-}" ]]; then
if [[ -n ${OMARCHY_CHROOT_INSTALL:-} ]]; then
NODE_TARBALL=$(find /opt/packages -name "node-v*-linux-x64.tar.gz" -type f 2>/dev/null | head -n1)
NODE_VERSION=$(basename "$NODE_TARBALL" | sed 's/node-v\(.*\)-linux-x64.tar.gz/\1/')
+1 -1
View File
@@ -1,7 +1,7 @@
if omarchy-battery-present; then
mapfile -t profiles < <(omarchy-powerprofiles-list)
if [[ ${#profiles[@]} -gt 1 ]]; then
if (( ${#profiles[@]} > 1 )); then
# Default AC profile:
# 3 profiles → performance
+1 -1
View File
@@ -1,6 +1,6 @@
# Starting the installer with OMARCHY_CHROOT_INSTALL=1 will put it into chroot mode
chrootable_systemctl_enable() {
if [ -n "${OMARCHY_CHROOT_INSTALL:-}" ]; then
if [[ -n ${OMARCHY_CHROOT_INSTALL:-} ]]; then
sudo systemctl enable $1
else
sudo systemctl enable --now $1
+4 -4
View File
@@ -25,7 +25,7 @@ show_cursor() {
# Display truncated log lines from the install log
show_log_tail() {
if [[ -f $OMARCHY_INSTALL_LOG_FILE ]]; then
local log_lines=$(($TERM_HEIGHT - $LOGO_HEIGHT - 35))
local log_lines=$((TERM_HEIGHT - LOGO_HEIGHT - 35))
local max_line_width=$((LOGO_WIDTH - 4))
tail -n $log_lines "$OMARCHY_INSTALL_LOG_FILE" | while IFS= read -r line; do
@@ -67,7 +67,7 @@ save_original_outputs() {
# Restore stdout and stderr to original (saved in FD 3 and 4)
# This ensures output goes to screen, not log file
restore_outputs() {
if [ -e /proc/self/fd/3 ] && [ -e /proc/self/fd/4 ]; then
if [[ -e /proc/self/fd/3 ]] && [[ -e /proc/self/fd/4 ]]; then
exec 1>&3 2>&4
fi
}
@@ -75,7 +75,7 @@ restore_outputs() {
# Error handler
catch_errors() {
# Prevent recursive error handling
if [[ $ERROR_HANDLING == true ]]; then
if [[ $ERROR_HANDLING == "true" ]]; then
return
else
ERROR_HANDLING=true
@@ -147,7 +147,7 @@ exit_handler() {
local exit_code=$?
# Only run if we're exiting with an error and haven't already handled it
if [[ $exit_code -ne 0 && $ERROR_HANDLING != true ]]; then
if (( exit_code != 0 )) && [[ $ERROR_HANDLING != "true" ]]; then
catch_errors
else
stop_log_output
+8 -8
View File
@@ -24,12 +24,12 @@ start_log_output() {
line="${current_lines[i]:-}"
# Truncate if needed
if [ ${#line} -gt $max_line_width ]; then
if (( ${#line} > max_line_width )); then
line="${line:0:$max_line_width}..."
fi
# Add clear line escape and formatted output for each line
if [ -n "$line" ]; then
if [[ -n $line ]]; then
output+="${ANSI_CLEAR_LINE}${ANSI_GRAY}${PADDING_LEFT_SPACES}${line}${ANSI_RESET}\n"
else
output+="${ANSI_CLEAR_LINE}${PADDING_LEFT_SPACES}\n"
@@ -45,7 +45,7 @@ start_log_output() {
}
stop_log_output() {
if [ -n "${monitor_pid:-}" ]; then
if [[ -n ${monitor_pid:-} ]]; then
kill $monitor_pid 2>/dev/null || true
wait $monitor_pid 2>/dev/null || true
unset monitor_pid
@@ -72,11 +72,11 @@ stop_install_log() {
echo "" >>"$OMARCHY_INSTALL_LOG_FILE"
echo "=== Installation Time Summary ===" >>"$OMARCHY_INSTALL_LOG_FILE"
if [ -f "/var/log/archinstall/install.log" ]; then
if [[ -f "/var/log/archinstall/install.log" ]]; then
ARCHINSTALL_START=$(grep -m1 '^\[' /var/log/archinstall/install.log 2>/dev/null | sed 's/^\[\([^]]*\)\].*/\1/' || true)
ARCHINSTALL_END=$(grep 'Installation completed without any errors' /var/log/archinstall/install.log 2>/dev/null | sed 's/^\[\([^]]*\)\].*/\1/' || true)
if [ -n "$ARCHINSTALL_START" ] && [ -n "$ARCHINSTALL_END" ]; then
if [[ -n $ARCHINSTALL_START ]] && [[ -n $ARCHINSTALL_END ]]; then
ARCH_START_EPOCH=$(date -d "$ARCHINSTALL_START" +%s)
ARCH_END_EPOCH=$(date -d "$ARCHINSTALL_END" +%s)
ARCH_DURATION=$((ARCH_END_EPOCH - ARCH_START_EPOCH))
@@ -88,7 +88,7 @@ stop_install_log() {
fi
fi
if [ -n "$OMARCHY_START_TIME" ]; then
if [[ -n $OMARCHY_START_TIME ]]; then
OMARCHY_START_EPOCH=$(date -d "$OMARCHY_START_TIME" +%s)
OMARCHY_END_EPOCH=$(date -d "$OMARCHY_END_TIME" +%s)
OMARCHY_DURATION=$((OMARCHY_END_EPOCH - OMARCHY_START_EPOCH))
@@ -98,7 +98,7 @@ stop_install_log() {
echo "Omarchy: ${OMARCHY_MINS}m ${OMARCHY_SECS}s" >>"$OMARCHY_INSTALL_LOG_FILE"
if [ -n "$ARCH_DURATION" ]; then
if [[ -n $ARCH_DURATION ]]; then
TOTAL_DURATION=$((ARCH_DURATION + OMARCHY_DURATION))
TOTAL_MINS=$((TOTAL_DURATION / 60))
TOTAL_SECS=$((TOTAL_DURATION % 60))
@@ -123,7 +123,7 @@ run_logged() {
local exit_code=$?
if [ $exit_code -eq 0 ]; then
if (( exit_code == 0 )); then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Completed: $script" >>"$OMARCHY_INSTALL_LOG_FILE"
unset CURRENT_SCRIPT
else
+3 -3
View File
@@ -4,10 +4,10 @@ if ! command -v gum &>/dev/null; then
fi
# Get terminal size from /dev/tty (works in all scenarios: direct, sourced, or piped)
if [ -e /dev/tty ]; then
if [[ -e /dev/tty ]]; then
TERM_SIZE=$(stty size 2>/dev/null </dev/tty)
if [ -n "$TERM_SIZE" ]; then
if [[ -n $TERM_SIZE ]]; then
export TERM_HEIGHT=$(echo "$TERM_SIZE" | cut -d' ' -f1)
export TERM_WIDTH=$(echo "$TERM_SIZE" | cut -d' ' -f2)
else
@@ -25,7 +25,7 @@ export LOGO_PATH="$OMARCHY_PATH/logo.txt"
export LOGO_WIDTH=$(awk '{ if (length > max) max = length } END { print max+0 }' "$LOGO_PATH" 2>/dev/null || echo 0)
export LOGO_HEIGHT=$(wc -l <"$LOGO_PATH" 2>/dev/null || echo 0)
export PADDING_LEFT=$((($TERM_WIDTH - $LOGO_WIDTH) / 2))
export PADDING_LEFT=$(((TERM_WIDTH - LOGO_WIDTH) / 2))
export PADDING_LEFT_SPACES=$(printf "%*s" $PADDING_LEFT "")
# Tokyo Night theme for gum confirm
+4 -4
View File
@@ -38,7 +38,7 @@ EOF
fi
# Remove the original config file if it's not /boot/limine.conf
if [[ "$limine_config" != "/boot/limine.conf" ]] && [[ -f "$limine_config" ]]; then
if [[ $limine_config != "/boot/limine.conf" ]] && [[ -f $limine_config ]]; then
sudo rm "$limine_config"
fi
@@ -73,11 +73,11 @@ fi
echo "Re-enabling mkinitcpio hooks..."
# Restore the specific mkinitcpio pacman hooks
if [ -f /usr/share/libalpm/hooks/90-mkinitcpio-install.hook.disabled ]; then
if [[ -f /usr/share/libalpm/hooks/90-mkinitcpio-install.hook.disabled ]]; then
sudo mv /usr/share/libalpm/hooks/90-mkinitcpio-install.hook.disabled /usr/share/libalpm/hooks/90-mkinitcpio-install.hook
fi
if [ -f /usr/share/libalpm/hooks/60-mkinitcpio-remove.hook.disabled ]; then
if [[ -f /usr/share/libalpm/hooks/60-mkinitcpio-remove.hook.disabled ]]; then
sudo mv /usr/share/libalpm/hooks/60-mkinitcpio-remove.hook.disabled /usr/share/libalpm/hooks/60-mkinitcpio-remove.hook
fi
@@ -99,7 +99,7 @@ fi
#
# uki_file=$(find /boot/EFI/Linux/ -name "omarchy*.efi" -printf "%f\n" 2>/dev/null | head -1)
#
# if [[ -n "$uki_file" ]]; then
# if [[ -n $uki_file ]]; then
# sudo efibootmgr --create \
# --disk "$(findmnt -n -o SOURCE /boot | sed 's/p\?[0-9]*$//')" \
# --part "$(findmnt -n -o SOURCE /boot | grep -o 'p\?[0-9]*$' | sed 's/^p//')" \
+1 -1
View File
@@ -1,4 +1,4 @@
if [ "$(plymouth-set-default-theme)" != "omarchy" ]; then
if [[ $(plymouth-set-default-theme) != "omarchy" ]]; then
sudo cp -r "$HOME/.local/share/omarchy/default/plymouth" /usr/share/plymouth/themes/omarchy/
sudo plymouth-set-default-theme omarchy
fi
+1 -1
View File
@@ -1,6 +1,6 @@
sudo mkdir -p /etc/sddm.conf.d
if [ ! -f /etc/sddm.conf.d/autologin.conf ]; then
if [[ ! -f /etc/sddm.conf.d/autologin.conf ]]; then
cat <<EOF | sudo tee /etc/sddm.conf.d/autologin.conf
[Autologin]
User=$USER
+2 -2
View File
@@ -13,7 +13,7 @@ echo
if [[ -f $OMARCHY_INSTALL_LOG_FILE ]] && grep -q "Total:" "$OMARCHY_INSTALL_LOG_FILE" 2>/dev/null; then
echo
TOTAL_TIME=$(tail -n 20 "$OMARCHY_INSTALL_LOG_FILE" | grep "^Total:" | sed 's/^Total:[[:space:]]*//')
if [ -n "$TOTAL_TIME" ]; then
if [[ -n $TOTAL_TIME ]]; then
echo_in_style "Installed in $TOTAL_TIME"
fi
else
@@ -29,7 +29,7 @@ if gum confirm --padding "0 0 0 $((PADDING_LEFT + 32))" --show-help=false --defa
# Clear screen to hide any shutdown messages
clear
if [[ -n "${OMARCHY_CHROOT_INSTALL:-}" ]]; then
if [[ -n ${OMARCHY_CHROOT_INSTALL:-} ]]; then
touch /var/tmp/omarchy-install-completed
exit 0
else
+2 -2
View File
@@ -4,11 +4,11 @@
echo "Temporarily disabling mkinitcpio hooks during installation..."
# Move the specific mkinitcpio pacman hooks out of the way if they exist
if [ -f /usr/share/libalpm/hooks/90-mkinitcpio-install.hook ]; then
if [[ -f /usr/share/libalpm/hooks/90-mkinitcpio-install.hook ]]; then
sudo mv /usr/share/libalpm/hooks/90-mkinitcpio-install.hook /usr/share/libalpm/hooks/90-mkinitcpio-install.hook.disabled
fi
if [ -f /usr/share/libalpm/hooks/60-mkinitcpio-remove.hook ]; then
if [[ -f /usr/share/libalpm/hooks/60-mkinitcpio-remove.hook ]]; then
sudo mv /usr/share/libalpm/hooks/60-mkinitcpio-remove.hook /usr/share/libalpm/hooks/60-mkinitcpio-remove.hook.disabled
fi
+4 -4
View File
@@ -11,18 +11,18 @@ fi
# Must not be an Arch derivative distro
for marker in /etc/cachyos-release /etc/eos-release /etc/garuda-release /etc/manjaro-release; do
if [[ -f "$marker" ]]; then
if [[ -f $marker ]]; then
abort "Vanilla Arch"
fi
done
# Must not be running as root
if [ "$EUID" -eq 0 ]; then
if (( EUID == 0 )); then
abort "Running as root (not user)"
fi
# Must be x86 only to fully work
if [ "$(uname -m)" != "x86_64" ]; then
if [[ $(uname -m) != "x86_64" ]]; then
abort "x86_64 CPU"
fi
@@ -40,7 +40,7 @@ fi
command -v limine &>/dev/null || abort "Limine bootloader"
# Must have btrfs root filesystem
[ "$(findmnt -n -o FSTYPE /)" = "btrfs" ] || abort "Btrfs root filesystem"
[[ $(findmnt -n -o FSTYPE /) = "btrfs" ]] || abort "Btrfs root filesystem"
# Cleared all guards
echo "Guards: OK"