Skip to content
Merged
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
119 changes: 102 additions & 17 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CHECK_MODE=false
INSTALL_MODE="copy"
CORTEX_CONFIG_HOME="${CORTEX_CONFIG_HOME:-${XDG_CONFIG_HOME:-$HOME/.config}/cortex-dots}"
PENDING_GHOSTTY_DIR="$CORTEX_CONFIG_HOME/pending/ghostty"
GHOSTTY_PROCESS_NAME="${CORTEX_DOTS_GHOSTTY_PROCESS_NAME:-ghostty}"

case "$(uname -s)" in
Darwin)
Expand Down Expand Up @@ -304,7 +305,7 @@ GHOSTTY_DEFER_WORKER_NEEDED=false
GHOSTTY_PENDING_LOCK_HELD=false

ghostty_is_running() {
ps -eo comm=,args= | awk '$1 == "ghostty" || $2 == "ghostty" || $2 ~ /\/ghostty$/ { found = 1 } END { exit found ? 0 : 1 }'
ps -eo comm=,args= | awk -v name="$GHOSTTY_PROCESS_NAME" '$1 == name || $2 == name || $2 ~ ("/" name "$") { found = 1 } END { exit found ? 0 : 1 }'
}

write_ghostty_apply_worker() {
Expand All @@ -325,6 +326,7 @@ TARGET_DIR="$HOME/.config/ghostty"
FONT_TARGET="$CUSTOM_FONT"
LOG_FILE="$GHOSTTY_APPLY_LOG"
LOCK_DIR="\$CONFIG_HOME/apply-pending-ghostty.lock"
GHOSTTY_PROCESS_NAME="$GHOSTTY_PROCESS_NAME"
STAMP="\$(date +%Y%m%d_%H%M%S).\$\$"

mkdir -p "\$(dirname "\$LOG_FILE")"
Expand All @@ -333,7 +335,7 @@ echo "pending: \$PENDING_DIR" >> "\$LOG_FILE"
echo "target: \$TARGET_DIR" >> "\$LOG_FILE"

ghostty_running() {
ps -eo comm=,args= | awk '\$1 == "ghostty" || \$2 == "ghostty" || \$2 ~ /\\/ghostty\$/ { found = 1 } END { exit found ? 0 : 1 }'
ps -eo comm=,args= | awk -v name="\$GHOSTTY_PROCESS_NAME" '\$1 == name || \$2 == name || \$2 ~ ("/" name "\$") { found = 1 } END { exit found ? 0 : 1 }'
}

acquire_lock() {
Expand Down Expand Up @@ -577,29 +579,102 @@ run_or_plan() {
fi
}

install_formula_if_missing() {
run_with_optional_sudo() {
if [[ "${EUID:-$(id -u)}" -eq 0 ]]; then
"$@"
elif command -v sudo &>/dev/null; then
sudo "$@"
else
return 127
fi
}

confirm_system_package_install() {
local package_name="$1"
local description="$2"

if [[ "${CORTEX_DOTS_INSTALL_PACKAGES:-false}" == true ]]; then
return 0
fi

if [[ ! -t 0 ]]; then
echo " ⚠️ $package_name no está instalado; se omite install porque stdin no es interactivo"
return 1
fi

read -p " ¿Instalar $package_name ($description) con el package manager del sistema? (y/N) " -n 1 -r
echo
[[ $REPLY =~ ^[Yy]$ ]]
}

install_package_if_missing() {
local command_name="$1"
local formula="$2"
local package_name="$2"
local description="$3"
local tap="${4:-}"

if ! command -v "$command_name" &>/dev/null; then
if [[ "$DRY_RUN" == true ]]; then
if command -v brew &>/dev/null; then
echo " → Would install $formula ($description) via Homebrew"
else
echo " → Would skip automatic install for $formula ($description); install with your $PLATFORM package manager"
fi
elif command -v brew &>/dev/null; then
echo " → Instalando $formula ($description)..."
[[ -z "$tap" ]] || brew tap "$tap"
brew install "$formula"
if command -v "$command_name" &>/dev/null; then
echo " ✓ $command_name ya instalado"
return
fi

if [[ "${CORTEX_DOTS_SKIP_PACKAGE_INSTALLS:-false}" == true ]]; then
echo " → Skipping automatic install for $package_name ($description) because CORTEX_DOTS_SKIP_PACKAGE_INSTALLS=true"
return
fi

if [[ "$DRY_RUN" == true ]]; then
if command -v brew &>/dev/null; then
echo " → Would install $package_name ($description) via Homebrew"
elif command -v apt-get &>/dev/null; then
echo " → Would install $package_name ($description) via apt-get"
elif command -v dnf &>/dev/null; then
echo " → Would install $package_name ($description) via dnf"
elif command -v pacman &>/dev/null; then
echo " → Would install $package_name ($description) via pacman"
else
echo " ⚠️ $command_name no está instalado; instalalo con el package manager de $PLATFORM"
echo " → Would skip automatic install for $package_name ($description); no supported package manager found"
fi
return
fi

if [[ "$PLATFORM" == "Linux" ]] && ! confirm_system_package_install "$package_name" "$description"; then
return
fi

echo " → Instalando $package_name ($description)..."
if command -v brew &>/dev/null; then
[[ -z "$tap" ]] || brew tap "$tap"
if brew install "$package_name"; then
return
fi
elif command -v apt-get &>/dev/null; then
if run_with_optional_sudo apt-get install -y "$package_name"; then
return
fi
elif command -v dnf &>/dev/null; then
if run_with_optional_sudo dnf install -y "$package_name"; then
return
fi
elif command -v pacman &>/dev/null; then
if run_with_optional_sudo pacman -S --needed --noconfirm "$package_name"; then
return
fi
else
echo " ✓ $command_name ya instalado"
echo " ⚠️ $command_name no está instalado; no encontré package manager soportado"
return
fi

echo " ⚠️ No se pudo instalar $package_name automáticamente; instalalo con el package manager de $PLATFORM"
}

install_formula_if_missing() {
local command_name="$1"
local formula="$2"
local description="$3"
local tap="${4:-}"

install_package_if_missing "$command_name" "$formula" "$description" "$tap"
}

install_starship_if_missing() {
Expand All @@ -608,6 +683,11 @@ install_starship_if_missing() {
return
fi

if [[ "${CORTEX_DOTS_SKIP_EXTERNAL_INSTALLS:-false}" == true ]]; then
echo " → Skipping starship install because CORTEX_DOTS_SKIP_EXTERNAL_INSTALLS=true"
return
fi

if [[ "$DRY_RUN" == true ]]; then
echo " → Would ask to install starship to $HOME/.local/bin via official installer"
return
Expand Down Expand Up @@ -823,6 +903,11 @@ install_ai_cli_if_requested() {
return
fi

if [[ "${CORTEX_DOTS_SKIP_EXTERNAL_INSTALLS:-false}" == true ]]; then
echo " → Skipping $display_name install because CORTEX_DOTS_SKIP_EXTERNAL_INSTALLS=true"
return
fi

if [[ "$DRY_RUN" == true ]]; then
echo " → Would ask to install $display_name from $install_url"
return
Expand Down
5 changes: 4 additions & 1 deletion scripts/test-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ poll_for() {
export HOME="$TMP_HOME/home"
export XDG_CONFIG_HOME="$TMP_HOME/config"
export CORTEX_CONFIG_HOME="$XDG_CONFIG_HOME/cortex-dots"
export CORTEX_DOTS_SKIP_PACKAGE_INSTALLS=true
export CORTEX_DOTS_SKIP_EXTERNAL_INSTALLS=true
export CORTEX_DOTS_GHOSTTY_PROCESS_NAME=cortex-dots-ghostty-test
mkdir -p "$HOME" "$XDG_CONFIG_HOME"
PENDING_DIR="$CORTEX_CONFIG_HOME/pending/ghostty"
GHOSTTY_DIR="$HOME/.config/ghostty"
Expand All @@ -89,7 +92,7 @@ if [[ "$SEED_STALE_OPPOSITE" == true ]]; then
fi
fi

(exec -a ghostty sleep 60) &
(exec -a "$CORTEX_DOTS_GHOSTTY_PROCESS_NAME" sleep 60) &
FAKE_GHOSTTY_PID="$!"

bash "$ROOT_DIR/install.sh" "${install_args[@]}"
Expand Down
Loading