124 lines
3.3 KiB
Bash
Executable File
124 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Set the Omarchy package channel.
|
|
# omarchy:args=<stable|rc|dev|edge>
|
|
# omarchy:requires-sudo=true
|
|
|
|
set -euo pipefail
|
|
|
|
usage() { echo "Usage: omarchy-channel-set [stable|rc|dev|edge]"; }
|
|
fail() { echo "Error: $*" >&2; exit 1; }
|
|
|
|
confirm_edge() {
|
|
cat <<'WARNING'
|
|
|
|
Edge links Omarchy directly to a mutable source checkout.
|
|
|
|
This disables package-based protections for the Omarchy code path, including
|
|
normal package updates and package-backed snapshot restores. You'll be
|
|
responsible for pulling, fixing, and restoring that checkout yourself.
|
|
|
|
WARNING
|
|
|
|
if omarchy-cmd-present gum; then
|
|
gum confirm --default=false "Enable Edge anyway?"
|
|
else
|
|
local answer=""
|
|
read -r -p "Enable Edge anyway? [y/N] " answer
|
|
[[ $answer == "y" || $answer == "Y" || $answer == "yes" || $answer == "YES" ]]
|
|
fi
|
|
}
|
|
|
|
choose_edge_checkout() {
|
|
local default_path="$HOME/Work/omarchy"
|
|
local path="${OMARCHY_EDGE_PATH:-}"
|
|
|
|
if [[ -z $path ]]; then
|
|
if omarchy-cmd-present gum; then
|
|
path=$(gum input --value "$default_path" --placeholder "$default_path" --header "Where should Edge checkout live? Existing non-checkout paths will not be overwritten.") || exit 1
|
|
else
|
|
read -r -p "Edge checkout path [$default_path]: " path
|
|
fi
|
|
fi
|
|
|
|
path="${path:-$default_path}"
|
|
case "$path" in
|
|
"~") path="$HOME" ;;
|
|
"~/"*) path="$HOME/${path#~/}" ;;
|
|
/*) ;;
|
|
*) path="$PWD/$path" ;;
|
|
esac
|
|
|
|
if [[ -e $path && ! -d $path/.git ]]; then
|
|
fail "$path already exists and is not a git checkout. Choose an empty path or an existing Omarchy checkout."
|
|
fi
|
|
|
|
if [[ -d $path/.git && ( ! -d $path/bin || ! -d $path/default || ! -d $path/shell ) ]]; then
|
|
fail "$path is a git checkout, but it does not look like Omarchy."
|
|
fi
|
|
|
|
printf '%s\n' "$path"
|
|
}
|
|
|
|
sync_edge_checkout() {
|
|
local checkout="$1"
|
|
|
|
if [[ -d $checkout/.git ]]; then
|
|
echo "Updating Edge checkout at $checkout"
|
|
git -C "$checkout" fetch origin quattro
|
|
git -C "$checkout" checkout quattro 2>/dev/null || git -C "$checkout" checkout --track origin/quattro
|
|
git -C "$checkout" pull --ff-only origin quattro
|
|
else
|
|
mkdir -p "$(dirname -- "$checkout")"
|
|
git clone --branch quattro --single-branch https://github.com/basecamp/omarchy.git "$checkout"
|
|
fi
|
|
|
|
omarchy-dev-link "$checkout"
|
|
}
|
|
|
|
(( $# > 0 )) || { usage; exit 1; }
|
|
|
|
edge_checkout=""
|
|
channel="$1"
|
|
|
|
case "$channel" in
|
|
stable)
|
|
pacman_channel=stable
|
|
packages=(omarchy omarchy-settings)
|
|
;;
|
|
rc)
|
|
pacman_channel=rc
|
|
packages=(omarchy-dev omarchy-settings-dev)
|
|
;;
|
|
dev)
|
|
pacman_channel=edge
|
|
packages=(omarchy-dev omarchy-settings-dev)
|
|
;;
|
|
edge|source)
|
|
confirm_edge || { echo "Cancelled."; exit 0; }
|
|
edge_checkout=$(choose_edge_checkout)
|
|
pacman_channel=edge
|
|
packages=(omarchy-dev omarchy-settings-dev)
|
|
;;
|
|
*)
|
|
echo "Unknown channel: $channel" >&2
|
|
usage >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
omarchy-refresh-pacman "$pacman_channel"
|
|
# --ask 4 accepts omarchy <-> omarchy-dev replacement prompts without file overwrites.
|
|
sudo env OMARCHY_UPDATE_PACMAN=1 pacman -S --needed --noconfirm --ask 4 "${packages[@]}"
|
|
|
|
if [[ -z $edge_checkout ]] && omarchy-cmd-present omarchy-dev-unlink; then
|
|
omarchy-dev-unlink
|
|
export OMARCHY_PATH=/usr/share/omarchy
|
|
fi
|
|
|
|
omarchy-update -y
|
|
|
|
if [[ -n $edge_checkout ]]; then
|
|
sync_edge_checkout "$edge_checkout"
|
|
fi
|