From 6f74091fb690a335eaf32be056acd721386b9a6d Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Wed, 20 May 2026 20:03:12 -0400 Subject: [PATCH] Make install.sh mode-aware with OMARCHY_INSTALL_MODE Three modes the installer now branches on: iso-chroot Running inside the new system's chroot from the ISO build. pacman is configured by archinstall; systemd isn't running, so service enables skip --now. online-package Running on an existing Arch where the omarchy-* packages are already installed. Skip base.sh and the bootstrap preflight steps; only the per-host runtime ops in config/login/post-install need to run. online-git boot.sh path: clone into $HOME/.local/share/omarchy and bootstrap everything from scratch. install.sh derives OMARCHY_PATH from its own location, so the same script works whether it's at /usr/share/omarchy/install.sh (package mode) or $HOME/.local/share/omarchy/install.sh (git mode). install_mode_is helper replaces direct ${OMARCHY_CHROOT_INSTALL:-} / ${OMARCHY_ONLINE_INSTALL:-} checks in chroot.sh, finished.sh, errors.sh, mise-work.sh, preflight/pacman.sh. Legacy vars still work through export_legacy_mode_flags, which sets OMARCHY_CHROOT_INSTALL=1 / OMARCHY_ONLINE_INSTALL=true based on the canonical mode for any caller that hasn't been updated. bin/omarchy-install-mode prints the current mode for scripts/users that need to introspect. Smoke-tested all four entry paths (explicit mode, both legacy shims, auto-detection from OMARCHY_PATH); each resolves correctly and the legacy flags are exported in matching modes. --- bin/omarchy-install-mode | 11 +++++++++ install.sh | 14 ++++++++---- install/config/mise-work.sh | 2 +- install/helpers/all.sh | 1 + install/helpers/chroot.sh | 4 ++-- install/helpers/errors.sh | 4 ++-- install/helpers/mode.sh | 38 ++++++++++++++++++++++++++++++++ install/packaging/all.sh | 7 +++++- install/post-install/finished.sh | 2 +- install/preflight/all.sh | 18 ++++++++++++--- install/preflight/pacman.sh | 2 +- install/preflight/show-env.sh | 2 +- 12 files changed, 89 insertions(+), 16 deletions(-) create mode 100755 bin/omarchy-install-mode create mode 100644 install/helpers/mode.sh diff --git a/bin/omarchy-install-mode b/bin/omarchy-install-mode new file mode 100755 index 00000000..bff86aa3 --- /dev/null +++ b/bin/omarchy-install-mode @@ -0,0 +1,11 @@ +#!/bin/bash + +# omarchy:summary=Print the install mode the installer was last invoked with +# omarchy:group=install + +# Used by scripts that need to branch on whether Omarchy was bootstrapped +# via ISO (iso-chroot), pacman install (online-package), or boot.sh +# (online-git). The current install.sh sets this; persisted state lives in +# /var/lib/omarchy/install-mode if Chunk 6+ chooses to record it. For now +# we echo whatever is in the current env. +echo "${OMARCHY_INSTALL_MODE:-unknown}" diff --git a/install.sh b/install.sh index 5b1b6bdd..30516250 100644 --- a/install.sh +++ b/install.sh @@ -1,15 +1,21 @@ #!/bin/bash -# Exit immediately if a command exits with a non-zero status set -eEo pipefail -# Define Omarchy locations -export OMARCHY_PATH="$HOME/.local/share/omarchy" +# Derive OMARCHY_PATH from the script location so install.sh works the same +# whether it's run from /usr/share/omarchy/install.sh (package mode) or +# $HOME/.local/share/omarchy/install.sh (git mode). An explicit OMARCHY_PATH +# in the caller env still wins. +_OMARCHY_INSTALLER_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +export OMARCHY_PATH="${OMARCHY_PATH:-$_OMARCHY_INSTALLER_DIR}" export OMARCHY_INSTALL="$OMARCHY_PATH/install" export OMARCHY_INSTALL_LOG_FILE="/var/log/omarchy-install.log" export PATH="$OMARCHY_PATH/bin:$PATH" -# Install +source "$OMARCHY_INSTALL/helpers/mode.sh" +detect_install_mode +export_legacy_mode_flags + source "$OMARCHY_INSTALL/helpers/all.sh" source "$OMARCHY_INSTALL/preflight/all.sh" source "$OMARCHY_INSTALL/packaging/all.sh" diff --git a/install/config/mise-work.sh b/install/config/mise-work.sh index e919dee9..2dfcc0c2 100644 --- a/install/config/mise-work.sh +++ b/install/config/mise-work.sh @@ -10,7 +10,7 @@ EOF mise trust ~/Work/.mise.toml -if [[ -n ${OMARCHY_CHROOT_INSTALL:-} ]]; then +if install_mode_is iso-chroot; 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/') diff --git a/install/helpers/all.sh b/install/helpers/all.sh index 0fc48100..ddac8d01 100644 --- a/install/helpers/all.sh +++ b/install/helpers/all.sh @@ -1,3 +1,4 @@ +source $OMARCHY_INSTALL/helpers/mode.sh source $OMARCHY_INSTALL/helpers/chroot.sh source $OMARCHY_INSTALL/helpers/presentation.sh source $OMARCHY_INSTALL/helpers/errors.sh diff --git a/install/helpers/chroot.sh b/install/helpers/chroot.sh index 35473a06..ad98802b 100644 --- a/install/helpers/chroot.sh +++ b/install/helpers/chroot.sh @@ -1,6 +1,6 @@ -# Starting the installer with OMARCHY_CHROOT_INSTALL=1 will put it into chroot mode +# In iso-chroot mode systemd isn't running, so skip --now and just enable. chrootable_systemctl_enable() { - if [[ -n ${OMARCHY_CHROOT_INSTALL:-} ]]; then + if install_mode_is iso-chroot; then sudo systemctl enable $1 else sudo systemctl enable --now $1 diff --git a/install/helpers/errors.sh b/install/helpers/errors.sh index d6683917..04ab15df 100644 --- a/install/helpers/errors.sh +++ b/install/helpers/errors.sh @@ -104,8 +104,8 @@ catch_errors() { while true; do options=() - # If online install, show retry first - if [[ -n ${OMARCHY_ONLINE_INSTALL:-} ]]; then + # Retry only makes sense for online flows (git clone or package install). + if install_mode_is online-git || install_mode_is online-package; then options+=("Retry installation") fi diff --git a/install/helpers/mode.sh b/install/helpers/mode.sh new file mode 100644 index 00000000..0c3502d8 --- /dev/null +++ b/install/helpers/mode.sh @@ -0,0 +1,38 @@ +# OMARCHY_INSTALL_MODE is one of: iso-chroot, online-package, online-git +# Back-compat shims honor the older OMARCHY_CHROOT_INSTALL and +# OMARCHY_ONLINE_INSTALL flags during transition. + +detect_install_mode() { + if [[ -n ${OMARCHY_INSTALL_MODE:-} ]]; then + return + fi + + if [[ -n ${OMARCHY_CHROOT_INSTALL:-} ]]; then + export OMARCHY_INSTALL_MODE=iso-chroot + elif [[ -n ${OMARCHY_ONLINE_INSTALL:-} ]]; then + export OMARCHY_INSTALL_MODE=online-git + elif [[ ${OMARCHY_PATH:-} == /usr/share/omarchy ]]; then + export OMARCHY_INSTALL_MODE=online-package + else + export OMARCHY_INSTALL_MODE=online-git + fi +} + +install_mode_is() { + [[ ${OMARCHY_INSTALL_MODE:-} == "$1" ]] +} + +# Sets OMARCHY_CHROOT_INSTALL=1 and OMARCHY_ONLINE_INSTALL=true so callers +# that still check the legacy vars keep working through the transition. +export_legacy_mode_flags() { + case ${OMARCHY_INSTALL_MODE:-} in + iso-chroot) + export OMARCHY_CHROOT_INSTALL=1 + ;; + online-git) + export OMARCHY_ONLINE_INSTALL=true + ;; + esac +} + +export -f install_mode_is diff --git a/install/packaging/all.sh b/install/packaging/all.sh index 5c32107e..766bce17 100644 --- a/install/packaging/all.sh +++ b/install/packaging/all.sh @@ -1,4 +1,9 @@ -run_logged $OMARCHY_INSTALL/packaging/base.sh +# online-package mode has omarchy + omarchy-base.packages already installed +# via pacman, so skip the base package install. +if ! install_mode_is online-package; then + run_logged $OMARCHY_INSTALL/packaging/base.sh +fi + run_logged $OMARCHY_INSTALL/packaging/fonts.sh run_logged $OMARCHY_INSTALL/packaging/nvim.sh run_logged $OMARCHY_INSTALL/packaging/icons.sh diff --git a/install/post-install/finished.sh b/install/post-install/finished.sh index 7d9b3ca1..612c469a 100644 --- a/install/post-install/finished.sh +++ b/install/post-install/finished.sh @@ -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 install_mode_is iso-chroot; then touch /var/tmp/omarchy-install-completed exit 0 else diff --git a/install/preflight/all.sh b/install/preflight/all.sh index 88354659..ccd1a801 100644 --- a/install/preflight/all.sh +++ b/install/preflight/all.sh @@ -1,7 +1,19 @@ source $OMARCHY_INSTALL/preflight/guard.sh source $OMARCHY_INSTALL/preflight/begin.sh run_logged $OMARCHY_INSTALL/preflight/show-env.sh -run_logged $OMARCHY_INSTALL/preflight/pacman.sh + +# online-git is the only mode that bootstraps pacman config; iso-chroot has +# archinstall do it; online-package starts with pacman already configured. +if install_mode_is online-git; then + run_logged $OMARCHY_INSTALL/preflight/pacman.sh +fi + run_logged $OMARCHY_INSTALL/preflight/migrations.sh -run_logged $OMARCHY_INSTALL/preflight/first-run-mode.sh -run_logged $OMARCHY_INSTALL/preflight/disable-mkinitcpio.sh + +# first-run-mode and disable-mkinitcpio are only meaningful when we're +# bringing a system up from scratch (boot.sh or ISO). online-package mode +# is bolting Omarchy onto an existing Arch install — neither applies. +if ! install_mode_is online-package; then + run_logged $OMARCHY_INSTALL/preflight/first-run-mode.sh + run_logged $OMARCHY_INSTALL/preflight/disable-mkinitcpio.sh +fi diff --git a/install/preflight/pacman.sh b/install/preflight/pacman.sh index cfe84943..d65a9645 100644 --- a/install/preflight/pacman.sh +++ b/install/preflight/pacman.sh @@ -1,4 +1,4 @@ -if [[ -n ${OMARCHY_ONLINE_INSTALL:-} ]]; then +if install_mode_is online-git; then # Install build tools omarchy-pkg-add base-devel diff --git a/install/preflight/show-env.sh b/install/preflight/show-env.sh index 1a9319d6..d0fc6a0b 100644 --- a/install/preflight/show-env.sh +++ b/install/preflight/show-env.sh @@ -1,6 +1,6 @@ # Show installation environment variables gum log --level info "Installation Environment:" -env | grep -E "^(OMARCHY_CHROOT_INSTALL|OMARCHY_ONLINE_INSTALL|OMARCHY_USER_NAME|OMARCHY_USER_EMAIL|USER|HOME|OMARCHY_REPO|OMARCHY_REF|OMARCHY_PATH)=" | sort | while IFS= read -r var; do +env | grep -E "^(OMARCHY_INSTALL_MODE|OMARCHY_CHROOT_INSTALL|OMARCHY_ONLINE_INSTALL|OMARCHY_USER_NAME|OMARCHY_USER_EMAIL|USER|HOME|OMARCHY_REPO|OMARCHY_REF|OMARCHY_PATH)=" | sort | while IFS= read -r var; do gum log --level info " $var" done