Overlay: validated manifest with dest record, ownership checks, clean reinstall
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QKxGW1raAWaqeU8WdHsMsp
This commit is contained in:
@@ -10,26 +10,48 @@ SRC=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
|
|||||||
DEST="${OMARCHY_PATH:?OMARCHY_PATH must point at the target Omarchy install}"
|
DEST="${OMARCHY_PATH:?OMARCHY_PATH must point at the target Omarchy install}"
|
||||||
MANIFEST="$HOME/.local/state/omarchycn/overlay-manifest"
|
MANIFEST="$HOME/.local/state/omarchycn/overlay-manifest"
|
||||||
|
|
||||||
run_dest() {
|
run_in() {
|
||||||
if [[ -w $DEST ]]; then
|
local root="$1"
|
||||||
|
shift
|
||||||
|
if [[ -w $root ]]; then
|
||||||
"$@"
|
"$@"
|
||||||
else
|
else
|
||||||
sudo "$@"
|
sudo "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
valid_entry() {
|
||||||
|
[[ $1 == "cn" || $1 =~ ^bin/(omarchycn|omarchy-cn-[a-z0-9-]+)$ ]]
|
||||||
|
}
|
||||||
|
|
||||||
uninstall() {
|
uninstall() {
|
||||||
if [[ ! -f $MANIFEST ]]; then
|
if [[ ! -f $MANIFEST ]]; then
|
||||||
echo "No overlay manifest at $MANIFEST" >&2
|
echo "No overlay manifest at $MANIFEST" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local dest="" rel=""
|
||||||
|
dest=$(grep -m1 '^dest=' "$MANIFEST" | cut -d= -f2-)
|
||||||
|
if [[ -z $dest || ! -d $dest ]]; then
|
||||||
|
echo "Manifest has no valid dest= record" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
while IFS= read -r rel; do
|
while IFS= read -r rel; do
|
||||||
[[ $rel == source=* ]] && continue
|
[[ $rel == source=* || $rel == dest=* ]] && continue
|
||||||
run_dest rm -f "$DEST/$rel"
|
if ! valid_entry "$rel"; then
|
||||||
|
echo "Refusing suspicious manifest entry: $rel" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ $rel == "cn" ]]; then
|
||||||
|
run_in "$dest" rm -rf "$dest/cn"
|
||||||
|
else
|
||||||
|
run_in "$dest" rm -f "$dest/$rel"
|
||||||
|
fi
|
||||||
done < "$MANIFEST"
|
done < "$MANIFEST"
|
||||||
run_dest rm -rf "$DEST/cn"
|
|
||||||
rm -f "$MANIFEST"
|
rm -f "$MANIFEST"
|
||||||
echo "OmarchyCN overlay removed from $DEST"
|
echo "OmarchyCN overlay removed from $dest"
|
||||||
}
|
}
|
||||||
|
|
||||||
install() {
|
install() {
|
||||||
@@ -42,20 +64,41 @@ install() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "${MANIFEST%/*}"
|
# Reinstall: remove the previous overlay first so upgrades leave no residue
|
||||||
echo "source=$SRC" > "$MANIFEST"
|
if [[ -f $MANIFEST ]]; then
|
||||||
|
uninstall
|
||||||
|
fi
|
||||||
|
|
||||||
run_dest mkdir -p "$DEST/cn"
|
if [[ -e $DEST/cn ]]; then
|
||||||
run_dest cp -r "$SRC/cn/." "$DEST/cn/"
|
echo "Refusing to take over unmanaged $DEST/cn" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
local f rel
|
local f rel entries=()
|
||||||
for f in "$SRC/bin/omarchycn" "$SRC"/bin/omarchy-cn-*; do
|
for f in "$SRC/bin/omarchycn" "$SRC"/bin/omarchy-cn-*; do
|
||||||
rel="bin/${f##*/}"
|
rel="bin/${f##*/}"
|
||||||
run_dest cp "$f" "$DEST/$rel"
|
if [[ -e $DEST/$rel ]]; then
|
||||||
echo "$rel" >> "$MANIFEST"
|
echo "Refusing to overwrite unmanaged $DEST/$rel" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
entries+=("$rel")
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "OmarchyCN overlay installed into $DEST ($(grep -c '^bin/' "$MANIFEST") commands)"
|
mkdir -p "${MANIFEST%/*}"
|
||||||
|
{
|
||||||
|
echo "source=$SRC"
|
||||||
|
echo "dest=$DEST"
|
||||||
|
echo "cn"
|
||||||
|
printf '%s\n' "${entries[@]}"
|
||||||
|
} > "$MANIFEST.tmp"
|
||||||
|
|
||||||
|
run_in "$DEST" cp -r "$SRC/cn" "$DEST/cn"
|
||||||
|
for rel in "${entries[@]}"; do
|
||||||
|
run_in "$DEST" cp "$SRC/$rel" "$DEST/$rel"
|
||||||
|
done
|
||||||
|
|
||||||
|
mv "$MANIFEST.tmp" "$MANIFEST"
|
||||||
|
echo "OmarchyCN overlay installed into $DEST (${#entries[@]} commands)"
|
||||||
echo "Verify: omarchy cn version"
|
echo "Verify: omarchy cn version"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user