forked from OpenKnowledgeButton/OpenKnowledgeButton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakelinks.sh
executable file
·67 lines (53 loc) · 1.2 KB
/
makelinks.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
59
60
61
62
63
64
65
66
#!/bin/bash
command=$1
set -eu
cd "$(dirname "$0")"
paths=(
"BabelExt.js"
"extension.js"
"icon16.png"
"icon48.png"
"icon128.png"
"modules"
"vendor/fancy-settings/source"
"vendor/jquery"
)
extensions=("Chrome" "Firefox/data" "Opera" "Safari.safariextension")
makelink() {
local path="$1"
for extension in "${extensions[@]}"; do
pathbasename="${path##*/}"
pathdirname=""
if [ "$pathbasename" != "$path" ]; then
pathdirname="${path%/*}/"
fi
if [ "$extension" == "Opera" ]; then
if [[ "$pathbasename" == *.user.js || "$pathbasename" == *.css ]]; then
dest="./${extension}/includes/${pathdirname}"
else
dest="./${extension}/modules/${pathdirname}"
fi
else
dest="./${extension}/${pathdirname}"
fi
echo "Re-linking: ${dest}${pathbasename}"
rm -f "${dest}${pathbasename}"
if [ "$command" != "clean" ]; then
mkdir -p "$dest"
ln "./lib/${path}" "$dest"
fi
done
}
traverse() {
local path="$1"
if [ -d "./lib/$path" ]; then
for subpath in ./lib/$path/*; do
traverse "${subpath/#.\/lib\//}"
done
else
makelink "$path"
fi
}
for path in "${paths[@]}"; do
traverse "$path"
done