commit 1ae7753fc298125003c2182a895342907d71a7b0
parent 421197b776866b084ee3b1bd5ea39be870b959e6
Author: Fred Großkopf <fred@kuandu.systems>
Date: Thu, 23 Apr 2026 18:30:00 +0200
Improves install.sh
Diffstat:
| M | install.sh | | | 49 | ++++++++++++++++++++++++++++++++++--------------- |
1 file changed, 34 insertions(+), 15 deletions(-)
diff --git a/install.sh b/install.sh
@@ -4,6 +4,25 @@ set -eu
SRC_DIR="$(cd "$(dirname "$0")" && pwd)"
DST_DIR="${1:-$HOME/bin}"
+INSTALL_SCRIPTS="gitpages-init.sh gitpages.sh mirror-git.sh"
+
+usage() {
+ cat << EOF
+Usage: $0 [DST_DIR] [SCRIPT...]
+
+Installs symlinks for git tools to DST_DIR (default: \$HOME/bin).
+
+Default scripts: $INSTALL_SCRIPTS
+
+Examples:
+ $0 # Install defaults to \$HOME/bin
+ $0 ~/bin # Defaults to ~/bin
+ $0 /usr/local/bin # Defaults to /usr/local/bin
+ $0 ~/bin gitpages.sh # Only gitpages.sh
+
+EOF
+ exit 0
+}
error() {
printf 'error: %s\n' "$1" >&2
@@ -19,7 +38,7 @@ print_next_steps() {
Next: make sure to update your path, e.g.:
-echo 'export PATH="$DST_DIR:\$PATH"' >> ~/.profile && source ~/.profile
+echo 'export PATH="\$DST_DIR:\$PATH"' >> ~/.profile && source ~/.profile
EOF
}
@@ -29,22 +48,18 @@ ensure_destination() {
[ -w "$DST_DIR" ] || error "$DST_DIR: not writable"
}
-check_source() {
- [ -n "$(ls "$SRC_DIR"/*.sh 2> /dev/null)" ] \
- || error "no *.sh files found in $SRC_DIR"
-}
-
install() {
- for src in "$SRC_DIR"/*.sh; do
- [ -f "$src" ] || continue
- name="$(basename "$src" .sh)"
- target="$DST_DIR/$name"
+ scripts="${*:-$INSTALL_SCRIPTS}"
+ for name in $scripts; do
+ src="$SRC_DIR/$name"
+ [ -f "$src" ] || error "missing: $src"
+ target="$DST_DIR/${name%.sh}"
if [ -L "$target" ]; then
rm "$target"
- info "Updated: $name"
+ info "Updated: ${name%.sh}"
else
- info "Created: $name"
+ info "Created: ${name%.sh}"
fi
ln -sf "$src" "$target"
@@ -56,9 +71,13 @@ install() {
}
main() {
- check_source
- ensure_destination
- install
+ case "${1:-}" in
+ --help | -h) usage ;;
+ -*) error "unknown option: $1 (try --help)" ;;
+ esac
+ ensure_destination "$DST_DIR"
+ shift # Consume DST_DIR if provided
+ install "$@"
}
main "$@"