-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·59 lines (54 loc) · 1.11 KB
/
install
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
#!/bin/sh
set -e
set -u
if [ "$#" != "1" ]; then
echo "Usage: $0 DIRECTORY"
exit 1
fi
DIRECTORY="$1"
LINK_CMD="ln -i -s"
safe_link(){
if [ -L "$2" ] && [ ! -e "$2" ]; then
# Remove existing dead symlink.
rm -f "$2"
fi
if [ -L "$2" ]; then
curr="$(readlink -n "$2")"
if [ "$curr" = "$1" ]; then
# do nothing
true
else
echo "Changing symbolic link from:"
echo "$curr"
echo "To:"
echo "$1"
$LINK_CMD -f "$1" "$2"
fi
else
printf "Creating link: %s\n" "$2"
$LINK_CMD "$1" "$2"
fi
unset curr
}
cd "$(dirname "$0")"
# if [ ! "$0" = "./$(basename "$0")" ]; then
# echo "Execute from base directory"
# exit 1
# fi
echo "Install in $DIRECTORY:"
echo "Continue? [Y]"
read -r _
mkdir -p "$DIRECTORY"
find . -type f -executable | while read -r f; do
echo "$f"
if [ ! "$f" = "$(basename "$0")" ] && [ -x "$f" ] ; then
safe_link "$(realpath "$f")" "$DIRECTORY/$(basename "$f")"
else
printf "Not installing %s\n" "$f"
fi
done
for f in "$DIRECTORY"/* ; do
if [ -h "$f" ] && [ ! -f "$(readlink -f "$f")" ]; then
trash "$f"
fi
done