-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
56 lines (51 loc) · 2.18 KB
/
Copy pathinstall.sh
File metadata and controls
56 lines (51 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env bash
# install.sh — install git-commit-lock.{sh,ps1} into ~/.local/bin.
#
# Prefers a symlink; if symlinking fails (e.g. Windows without Developer Mode —
# the MSYS flag below makes `ln -s` fail loudly there instead of silently
# copying), falls back to copying the script, which works identically because
# both scripts are self-contained. Idempotent: re-run any time (e.g. after
# moving the repo, or to refresh copies after updating the clone). Logs each
# file it installs (mode, old + new target).
set -euo pipefail
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DEST="${HOME}/.local/bin"
if [ -e "$DEST" ] && [ ! -d "$DEST" ]; then
echo "install.sh: $DEST exists but is not a directory - move it aside, then re-run." >&2
exit 1
fi
mkdir -p "$DEST"
export MSYS=winsymlinks:nativestrict # real symlinks on Windows Git-Bash (or fail, never copy)
copied=0
for f in git-commit-lock.sh git-commit-lock.ps1; do
src="$REPO/$f"
dst="$DEST/$f"
[ -f "$src" ] || { echo "install.sh: missing $src" >&2; exit 1; }
if [ -L "$dst" ]; then
prev="$(readlink "$dst" 2>/dev/null || echo '(unreadable symlink)')"
elif [ -d "$dst" ]; then
echo "install.sh: $dst exists and is a directory - remove it, then re-run." >&2
exit 1
elif [ -e "$dst" ]; then
prev='(regular file - replaced)'
else
prev='(none)'
fi
rm -f "$dst" # clear any previous symlink or copy so both lanes start clean
if ln -s "$src" "$dst" 2>/dev/null; then
printf 'linked %s\n was: %s\n now: %s\n' "$dst" "$prev" "$src"
else
cp "$src" "$dst" || { echo "install.sh: could not link or copy $f into $DEST" >&2; exit 1; }
chmod a+x "$dst"
copied=1
printf 'copied %s (symlinks unavailable)\n was: %s\n now: copy of %s\n' "$dst" "$prev" "$src"
fi
done
case ":${PATH}:" in
*":${DEST}:"*) : ;;
*) echo "install.sh: NOTE — $DEST is not on PATH; add it so 'git-commit-lock.sh' resolves." >&2 ;;
esac
echo "git-commit-lock installed to $DEST."
if [ "$copied" -eq 1 ]; then
echo "install.sh: NOTE — installed as copies, which don't track the repo; re-run install.sh after updating the clone." >&2
fi