refactor(install): move program files to ~/.local/share/floppy-utils
Installs the core script + lib/ under XDG_DATA_HOME/floppy-utils and generates thin wrappers in ~/.local/bin. Updates floppy resolver, install.sh, README, and adds early returns in check-deps logging helpers.
This commit is contained in:
parent
34aeb7bc0d
commit
6742e41e3d
@ -61,6 +61,8 @@ floppy-utils/
|
||||
|
||||
There is no daemon. Scripts use `sudo` when not root for `dd`, `blockdev`, `losetup`, and mount operations.
|
||||
|
||||
After `install.sh`, the main script lives at `~/.local/share/floppy-utils/floppy`; `~/.local/bin/floppy` is a wrapper that finds it.
|
||||
|
||||
---
|
||||
|
||||
## Requirements
|
||||
@ -124,6 +126,8 @@ sudo ./check-deps.sh --install
|
||||
./install.sh
|
||||
```
|
||||
|
||||
This installs the library to `~/.local/share/floppy-utils/` (including `lib/common.sh`) and places small wrapper scripts in `~/.local/bin/`. You can still run `./src/floppy` directly from a git checkout.
|
||||
|
||||
Ensure `~/.local/bin` is in your shell `PATH` (add to `~/.bashrc` or `~/.zshrc` if needed):
|
||||
|
||||
```bash
|
||||
|
||||
@ -35,11 +35,15 @@ while [[ $# -gt 0 ]]; do
|
||||
done
|
||||
|
||||
log() {
|
||||
[[ "$QUIET" -eq 0 ]] && echo "$@"
|
||||
if [[ "$QUIET" -eq 0 ]]; then
|
||||
echo "$@"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
warn() {
|
||||
echo "check-deps.sh: $*" >&2
|
||||
return 0
|
||||
}
|
||||
|
||||
die() {
|
||||
|
||||
34
install.sh
34
install.sh
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
# Install floppy-utils scripts to ~/.local/bin
|
||||
# Install floppy-utils: program files in ~/.local/share, wrappers in ~/.local/bin
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
@ -12,12 +12,34 @@ if [[ -x "$ROOT/check-deps.sh" ]]; then
|
||||
fi
|
||||
|
||||
SRC="$ROOT/src"
|
||||
SHARE="${XDG_DATA_HOME:-$HOME/.local/share}/floppy-utils"
|
||||
DEST="${HOME}/.local/bin"
|
||||
|
||||
mkdir -p "$DEST"
|
||||
for cmd in floppy floppy-make floppy-attach floppy-burn; do
|
||||
install -m 755 "$SRC/$cmd" "$DEST/$cmd"
|
||||
done
|
||||
mkdir -p "$SHARE/lib" "$DEST"
|
||||
install -m 755 "$SRC/floppy" "$SHARE/floppy"
|
||||
install -m 644 "$SRC/lib/common.sh" "$SHARE/lib/common.sh"
|
||||
|
||||
echo "Installed to $DEST"
|
||||
install_wrapper() {
|
||||
local name="$1"
|
||||
shift
|
||||
local launcher="$SHARE/floppy"
|
||||
local args_quoted=""
|
||||
local arg
|
||||
for arg in "$@"; do
|
||||
args_quoted+="$(printf '%q' "$arg") "
|
||||
done
|
||||
cat >"$DEST/$name" <<EOF
|
||||
#!/usr/bin/env bash
|
||||
exec $(printf '%q' "$launcher") ${args_quoted}"\$@"
|
||||
EOF
|
||||
chmod 755 "$DEST/$name"
|
||||
}
|
||||
|
||||
install_wrapper floppy
|
||||
install_wrapper floppy-make make
|
||||
install_wrapper floppy-attach attach
|
||||
install_wrapper floppy-burn burn
|
||||
|
||||
echo "Installed program files: $SHARE"
|
||||
echo "Installed commands: $DEST/floppy, floppy-make, floppy-attach, floppy-burn"
|
||||
echo "Ensure \$HOME/.local/bin is on your PATH, then run: floppy help"
|
||||
22
src/floppy
22
src/floppy
@ -1,7 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
FLOPPY_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
floppy_resolve_script_dir() {
|
||||
local dir share
|
||||
dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
if [[ -f "$dir/lib/common.sh" ]]; then
|
||||
printf '%s\n' "$dir"
|
||||
return 0
|
||||
fi
|
||||
share="${XDG_DATA_HOME:-${HOME:-}/.local/share}/floppy-utils"
|
||||
if [[ -f "$share/lib/common.sh" ]]; then
|
||||
printf '%s\n' "$share"
|
||||
return 0
|
||||
fi
|
||||
if [[ -f "/usr/local/share/floppy-utils/lib/common.sh" ]]; then
|
||||
printf '%s\n' "/usr/local/share/floppy-utils"
|
||||
return 0
|
||||
fi
|
||||
echo "floppy: cannot find lib/common.sh — run install.sh from the floppy-utils tree" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
FLOPPY_SCRIPT_DIR="$(floppy_resolve_script_dir)"
|
||||
# shellcheck source=lib/common.sh
|
||||
source "$FLOPPY_SCRIPT_DIR/lib/common.sh"
|
||||
floppy_load_config
|
||||
|
||||
Loading…
Reference in New Issue
Block a user