-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·58 lines (51 loc) · 1.39 KB
/
bootstrap.sh
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
#!/bin/bash
#
# Deploy these scripts into personal binary directory
#
# Get current directory
#
# From: http://stackoverflow.com/questions/59895
#
_current_path() {
SOURCE="${BASH_SOURCE[0]}"
DIR="$( dirname "$SOURCE" )"
while [ -h "$SOURCE" ]
do
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
echo $DIR
}
dolink() {
[ -h "$2" ] && rm -v $2
ln -s -v $1 $2
}
deploy() {
path=$1
file=$(basename $path)
srcp=$(_current_path)'/'$path
dest=$LOCAL_BIN'/'$file
if [ -h $dest ]; then
cdst=$(realpath $dest 2>/dev/null)
if [ -s "$cdst" ]; then
[ "$cdst" != "$srcp" ] && echo "$dest is link to $cdst, not $srcp"
else
echo "$dest is broken, link it to $srcp"
dolink $srcp $dest
fi
elif [ -e $dest ]; then
echo "Unkown type $dest has already exited, leave it alone"
else
dolink $srcp $dest
fi
}
if [ ! -n "$LOCAL_BIN" ]; then
LOCAL_BIN=$HOME'/.local/bin'
fi
mkdir -p $LOCAL_BIN
for __script in $(find scripts/ -type f -name "*.sh" | grep -v "tests/" | grep -v ".repo/"); do
[ -x $__script ] && deploy $__script
done
echo "Deployment finished, please add '$LOCAL_BIN' to your \$PATH environmental variable."