Fix code-review findings: 10-known.sh value-match bug (proven live), bootstrap.sh symlink race + missing sources + accidental exit-on-eval, fx.sh misleading picker text + FX_AUTO short-circuit
This commit is contained in:
+30
-8
@@ -11,15 +11,37 @@
|
||||
# them in every new shell, add the same eval line to your rc file.
|
||||
|
||||
_base="https://huggingface.co/spaces/Daveswo/self-healing-autopoietic-shell/raw/main"
|
||||
_dir="${TMPDIR:-/tmp}/self-healing-shell-$$"
|
||||
mkdir -p "$_dir/sources.d" 2>/dev/null
|
||||
# mktemp -d, not `mkdir -p .../self-healing-shell-$$`: a PID-based name
|
||||
# under shared, world-writable /tmp is guessable, and `mkdir -p` follows
|
||||
# a pre-existing symlink at that path without complaint -- an attacker
|
||||
# who plants one before this runs gets the curl-fetched files written
|
||||
# through it. mktemp -d always creates a fresh, unpredictable directory
|
||||
# or fails outright; it never silently reuses an existing path.
|
||||
_dir="$(mktemp -d "${TMPDIR:-/tmp}/self-healing-shell-XXXXXX" 2>/dev/null)"
|
||||
|
||||
_fetch_ok=1
|
||||
curl -fsSL "$_base/src/f.sh" -o "$_dir/f.sh" || _fetch_ok=0
|
||||
curl -fsSL "$_base/contrib/fx/fx.sh" -o "$_dir/fx.sh" || _fetch_ok=0
|
||||
for s in 10-known.sh 20-history.sh 30-selfdiag.sh 40-pathfuzzy.sh 50-thefuck.sh 90-team-shared.sh; do
|
||||
curl -fsSL "$_base/contrib/fx/sources.d/$s" -o "$_dir/sources.d/$s" || _fetch_ok=0
|
||||
done
|
||||
# This runs via `eval` inline in your live interactive shell -- never
|
||||
# `exit`/`return` on failure here, that would close your terminal, not
|
||||
# just abort the script. Fall through to the same "skip the rest"
|
||||
# if/else the original script already used.
|
||||
if [ -z "$_dir" ] || [ ! -d "$_dir" ]; then
|
||||
echo "bootstrap: mktemp -d failed" >&2
|
||||
_fetch_ok=0
|
||||
else
|
||||
mkdir -p "$_dir/sources.d" 2>/dev/null
|
||||
# The directory has to outlive this script -- FX_SOURCES_DIR keeps
|
||||
# pointing into it for the rest of the shell session -- so it can't
|
||||
# be removed right after sourcing. Clean it up when the shell
|
||||
# itself exits instead, so repeated bootstrapping doesn't
|
||||
# accumulate copies in /tmp.
|
||||
trap 'rm -rf "$_dir"' EXIT
|
||||
|
||||
_fetch_ok=1
|
||||
curl -fsSL "$_base/src/f.sh" -o "$_dir/f.sh" || _fetch_ok=0
|
||||
curl -fsSL "$_base/contrib/fx/fx.sh" -o "$_dir/fx.sh" || _fetch_ok=0
|
||||
for s in 10-known.sh 20-history.sh 30-selfdiag.sh 40-pathfuzzy.sh 50-thefuck.sh 70-local-llm.sh 80-remote-api.sh 90-team-shared.sh; do
|
||||
curl -fsSL "$_base/contrib/fx/sources.d/$s" -o "$_dir/sources.d/$s" || _fetch_ok=0
|
||||
done
|
||||
fi
|
||||
|
||||
if [ "$_fetch_ok" != 1 ]; then
|
||||
echo "bootstrap: fetch failed, check your connection" >&2
|
||||
|
||||
Reference in New Issue
Block a user