forked from workcraft/workcraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dist.sh
executable file
·130 lines (104 loc) · 2.88 KB
/
dist.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash -e
plugin_dirs="*Plugin/"
core_dir="WorkcraftCore"
dist_dir="dist"
allplatforms="windows linux osx"
platforms="all"
bname="$(basename $0)"
tag="$(git describe --tags)"
usage() {
cat <<EOF
$bname: create a distribution for Workcraft as workcraft-tag-platform archive
Usage: $bname [platforms] [-t TAG] [-h]
platforms: distribution platforms to build
$allplatforms all (default: all)
-t, --tag TAG: user-defined tag (git tag is used by default)
-f, --force: force removal of output dir
-h, --help: print this help
EOF
}
err() {
echo "Error: $@" >&2
exit 1
}
# Process parameters
force=false
for param in "$@"; do
case "$param" in
-h | --help)
usage
exit 0 ;;
-f | --force)
force=true
shift ;;
-t | --tag)
tag="$2"
shift 2 ;;
esac
done
if [ ! -e "$core_dir/build" ]; then
err "You need to run './gradlew assemble' first"
fi
if [ -z "$@" ] || [ "$@" = "all" ]; then
platforms="$allplatforms"
else
platforms="$@"
fi
for platform in $platforms; do
if [ "$platform" = "osx" ]; then
dist_rootdir="Workcraft.app"
else
dist_rootdir="workcraft"
fi
dist_name="workcraft-${tag}-${platform}"
dist_path="$dist_dir/$platform/$dist_rootdir"
template_dir="dist-template/$platform"
echo "Building ${dist_name}..."
if [ ! -d "$template_dir" ]; then
err "Template directory not found: $template_dir"
fi
if [ -e "$dist_path" ]; then
if $force; then
rm -rf "$dist_path"
else
err "Distribution directory already exists: $dist_path"
fi
fi
mkdir -p $dist_path
cp -r $template_dir/* $dist_path/
# Set Resources as the distribution path on OS X
if [ "$platform" = "osx" ]; then
# Update Info.plist with version tag (OS X `sed -i` requires backup extension, e.g. `sed -i.bak`)
sed -i.bak "s/__VERSION__/$tag/" ${dist_path}/Contents/Info.plist
rm -f ${dist_path}/Contents/Info.plist.bak
dist_path=$dist_path/Contents/Resources
fi
mkdir -p $dist_path/bin
cp $core_dir/build/libs/*.jar $dist_path/bin/
for d in $plugin_dirs; do
# Skip private plugins (their name strart with underscore)
case "$d" in
_*)
echo " - skipping private plugin $d"
;;
*)
cp $d/build/libs/*.jar $dist_path/bin/
;;
esac
done
for d in doc/*; do
if [ "$d" != "doc/README.md" ]; then
cp -r $d $dist_path/
fi
done
cd $dist_dir/$platform
case $platform in
windows)
7z a -r ${dist_name}.zip $dist_rootdir >/dev/null
;;
linux | osx)
tar -czf ${dist_name}.tar.gz $dist_rootdir
;;
esac
cd ../..
done