-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·73 lines (60 loc) · 1.52 KB
/
install
File metadata and controls
executable file
·73 lines (60 loc) · 1.52 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
set -euo pipefail
# TARGET_DIR="$HOME/.local/bin"
TARGET_DIR="$HOME/CustomPath"
mkdir -p "$TARGET_DIR"
UNLINK=false
if [[ "${1:-}" == "-u" ]]; then
UNLINK=true
fi
# Remove extension
strip_ext() {
filename=$(basename "$1")
echo "${filename%%.*}"
}
find . -type f | while read -r src; do
# Ignore anything inside dotfolders or dotfiles
case "$src" in
*/.*) continue ;;
esac
# Allowed extensions only
case "$src" in
*.py|*.sh) ;; # allowed
*) continue ;; # skip everything else
esac
base=$(basename "$src")
# Skip installer & README
case "$base" in
install|Install.sh|README.md)
continue
;;
esac
# Strip extension for the link target
name_no_ext=$(strip_ext "$src")
dest="$TARGET_DIR/$name_no_ext"
if [[ "$UNLINK" == true ]]; then
if [[ -L "$dest" ]]; then
rm "$dest"
echo "Unlinked: $dest"
else
echo "SKIP: '$dest' is not a symlink." >&2
fi
continue
fi
# If symlink exists → skip
if [[ -L "$dest" ]]; then
continue
fi
# If a real file exists → error
if [[ -e "$dest" ]]; then
echo "ERROR: '$dest' exists and is NOT a symlink. Skipping." >&2
continue
fi
# Ensure the source file is executable
if [[ ! -x "$src" ]]; then
chmod +x "$src"
fi
# Create the symlink
ln -s "$(realpath "$src")" "$dest"
echo "Linked: $dest → $src"
done