Update scripts to keep SOUL.md idempotent. Add release upgrade framework.
This commit is contained in:
118
install.sh
118
install.sh
@@ -3,6 +3,8 @@ set -euo pipefail
|
||||
|
||||
SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TARGET_DIR="${MOSAIC_HOME:-$HOME/.config/mosaic}"
|
||||
INSTALL_MODE="${MOSAIC_INSTALL_MODE:-prompt}" # prompt|keep|overwrite
|
||||
PRESERVE_PATHS=("SOUL.md" "memory")
|
||||
|
||||
# Colors (disabled if not a terminal)
|
||||
if [[ -t 1 ]]; then
|
||||
@@ -17,17 +19,125 @@ warn() { echo -e " ${YELLOW}⚠${RESET} $1" >&2; }
|
||||
fail() { echo -e " ${RED}✗${RESET} $1" >&2; }
|
||||
step() { echo -e "\n${BOLD}$1${RESET}"; }
|
||||
|
||||
is_existing_install() {
|
||||
[[ -d "$TARGET_DIR" ]] || return 1
|
||||
[[ -f "$TARGET_DIR/bin/mosaic" || -f "$TARGET_DIR/AGENTS.md" || -f "$TARGET_DIR/SOUL.md" ]]
|
||||
}
|
||||
|
||||
select_install_mode() {
|
||||
case "$INSTALL_MODE" in
|
||||
keep|overwrite|prompt) ;;
|
||||
*)
|
||||
fail "Invalid MOSAIC_INSTALL_MODE='$INSTALL_MODE'. Use: prompt, keep, overwrite."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if ! is_existing_install; then
|
||||
INSTALL_MODE="overwrite"
|
||||
return
|
||||
fi
|
||||
|
||||
case "$INSTALL_MODE" in
|
||||
keep|overwrite)
|
||||
;;
|
||||
prompt)
|
||||
if [[ -t 0 ]]; then
|
||||
echo ""
|
||||
echo "Existing Mosaic install detected at: $TARGET_DIR"
|
||||
echo "Choose reinstall mode:"
|
||||
echo " 1) keep Keep local files (SOUL.md, memory/) while updating framework"
|
||||
echo " 2) overwrite Replace everything in $TARGET_DIR"
|
||||
echo " 3) cancel Abort install"
|
||||
printf "Selection [1/2/3] (default: 1): "
|
||||
read -r selection
|
||||
|
||||
case "${selection:-1}" in
|
||||
1|k|K|keep|KEEP) INSTALL_MODE="keep" ;;
|
||||
2|o|O|overwrite|OVERWRITE) INSTALL_MODE="overwrite" ;;
|
||||
3|c|C|cancel|CANCEL|n|N|no|NO)
|
||||
fail "Install cancelled."
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
warn "Unrecognized selection '$selection'; defaulting to keep."
|
||||
INSTALL_MODE="keep"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
warn "Existing install detected without interactive input; defaulting to keep local files."
|
||||
INSTALL_MODE="keep"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
sync_framework() {
|
||||
local source_real target_real
|
||||
source_real="$(cd "$SOURCE_DIR" && pwd -P)"
|
||||
target_real="$(mkdir -p "$TARGET_DIR" && cd "$TARGET_DIR" && pwd -P)"
|
||||
|
||||
if [[ "$source_real" == "$target_real" ]]; then
|
||||
warn "Source and target are the same directory; skipping file sync."
|
||||
return
|
||||
fi
|
||||
|
||||
if command -v rsync >/dev/null 2>&1; then
|
||||
local rsync_args=(-a --delete --exclude ".git")
|
||||
|
||||
if [[ "$INSTALL_MODE" == "keep" ]]; then
|
||||
local path
|
||||
for path in "${PRESERVE_PATHS[@]}"; do
|
||||
rsync_args+=(--exclude "$path")
|
||||
done
|
||||
fi
|
||||
|
||||
rsync "${rsync_args[@]}" "$SOURCE_DIR/" "$TARGET_DIR/"
|
||||
return
|
||||
fi
|
||||
|
||||
local preserve_tmp=""
|
||||
if [[ "$INSTALL_MODE" == "keep" ]]; then
|
||||
preserve_tmp="$(mktemp -d "${TMPDIR:-/tmp}/mosaic-preserve-XXXXXX")"
|
||||
local path
|
||||
for path in "${PRESERVE_PATHS[@]}"; do
|
||||
if [[ -e "$TARGET_DIR/$path" ]]; then
|
||||
mkdir -p "$preserve_tmp/$(dirname "$path")"
|
||||
cp -R "$TARGET_DIR/$path" "$preserve_tmp/$path"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
find "$TARGET_DIR" -mindepth 1 -maxdepth 1 ! -name ".git" -exec rm -rf {} +
|
||||
cp -R "$SOURCE_DIR"/. "$TARGET_DIR"/
|
||||
rm -rf "$TARGET_DIR/.git"
|
||||
|
||||
if [[ -n "$preserve_tmp" ]]; then
|
||||
local path
|
||||
for path in "${PRESERVE_PATHS[@]}"; do
|
||||
if [[ -e "$preserve_tmp/$path" ]]; then
|
||||
rm -rf "$TARGET_DIR/$path"
|
||||
mkdir -p "$TARGET_DIR/$(dirname "$path")"
|
||||
cp -R "$preserve_tmp/$path" "$TARGET_DIR/$path"
|
||||
fi
|
||||
done
|
||||
rm -rf "$preserve_tmp"
|
||||
fi
|
||||
}
|
||||
|
||||
step "Installing Mosaic framework"
|
||||
|
||||
mkdir -p "$TARGET_DIR"
|
||||
select_install_mode
|
||||
|
||||
if command -v rsync >/dev/null 2>&1; then
|
||||
rsync -a --delete "$SOURCE_DIR/" "$TARGET_DIR/"
|
||||
if [[ "$INSTALL_MODE" == "keep" ]]; then
|
||||
ok "Install mode: keep local SOUL.md/memory while updating framework"
|
||||
else
|
||||
rm -rf "$TARGET_DIR"/*
|
||||
cp -R "$SOURCE_DIR"/* "$TARGET_DIR"/
|
||||
ok "Install mode: overwrite existing files"
|
||||
fi
|
||||
|
||||
sync_framework
|
||||
|
||||
chmod +x "$TARGET_DIR"/bin/*
|
||||
chmod +x "$TARGET_DIR"/install.sh
|
||||
|
||||
|
||||
Reference in New Issue
Block a user