-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
194 lines (160 loc) · 4.88 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash
set -e
INSTALL_PATH="$INSTALL_PATH"
BIN_PATH="$BIN_PATH"
MAIN_CLASS="net.kozakcuu.wxapkg.WechatAppletPackage"
ORIGIN_DIR="$(pwd)"
FROM_SOURCE="$FROM_SOURCE"
# It will be updated in every release
DEFAULT_BINARY_ADDRESS='https://github.com/JohnKozak/libwxapkg/releases/download/v1.0/libwxapkg-1.0.jar'
# Check curl
[ -z "$(command -v curl 2> /dev/null)" ] && {
echo "Installation require curl."
echo "Please install it before continue."
exit 1
}
# Prepare install path
[ -z "$INSTALL_PATH" ] && {
INSTALL_PATH="$HOME/.local/lib/java"
_USE_DEFAULT_INSTALL_PATH="true"
}
# Prepare bin path
[ -z "$BIN_PATH" ] && {
BIN_PATH="$HOME/.local/bin"
_USE_DEFAULT_BIN_PATH="true"
}
# Print out the install settings
print_install_settings() {
echo "Executable will be install into '$BIN_PATH'."
[ b"$_USE_DEFAULT_BIN_PATH" = b'true' ] && {
echo "- If you didn't add it to your PATH you can do it later."
echo "- Or you can change the executable file install path by giving BIN_PATH variable."
}
echo "Jar lib will be install into '$INSTALL_PATH'."
[ b"$_USE_DEFAULT_INSTALL_PATH" = b'true' ] && {
echo "- Or you can change the executable file install path by giving INSTALL_PATH variable."
}
}
# Prepare work dir and add delete hook
prepare_work_dir() {
local workdir="$(pwd)"
mkdir -p "$INSTALL_PATH" 2> /dev/null || :
[ -d "$INSTALL_PATH" ] || {
echo "Could not create install path $INSTALL_PATH" 1>&2
exit 1
}
local tmpdirname="tmp-$(date +%y%m%d%H%M%S)"
local tmpdir="/tmp/$tmpdirname"
mkdir -p "$tmpdir" || {
echo "Could not create temporal directory in /tmp, try use '$HOME/.tmp'."
tmpdir="$HOME/.tmp/$tmpdirname"
mkdir -p "$tmpdir" || {
echo "Could not create temp dir '$tmpdir' for install." 1>&2
exit 1
}
}
cd "$tmpdir"
WORK_DIR="$tmpdir"
_clean_on_exit() {
rm -rf "$WORK_DIR"
}
trap "_clean_on_exit" SIGTERM SIGINT SIGKILL EXIT
}
prepare_bin_dir() {
[ -d "$BIN_PATH" ] && return 0
mkdir -p "$BIN_PATH" || {
echo "Could not create bin directory '$BIN_PATH'."
exit 1
}
}
build_command_unwxapkg() {
local binname="$BIN_PATH/unwxapkg"
cat > "$binname" \
<<EOF
#!/bin/bash
set -e
INSTALL_PATH="$INSTALL_PATH"
java -cp "\$INSTALL_PATH/*" "$MAIN_CLASS" \$@
EOF
# END SCRIPT
chmod +x "$binname"
}
install_from_source() {
echo "Start installing from source."
# Check javac
[ -z "$(command -v javac 2> /dev/null)" ] && {
echo "Install from source could not run because lack of 'javac' command for compile the source."
echo "Install it before continue."
exit 1
}
# Prepare install
print_install_settings
prepare_work_dir
# Start install
curl -# -L -O https://github.com/JohnKozak/libwxapkg/archive/refs/heads/master.zip
unzip "master.zip"
cd "libwxapkg-master"
chmod +x ./mvnw
# Use the temporal dir to place the maven2 stuff
./mvnw "-Dmaven.repo.local=$WORK_DIR/maven2" clean package
echo "Try removing old jar file."
find "$INSTALL_PATH" -name 'libwxapkg*.jar' -exec rm -v -rf {} \; 1>&2
echo "Copy new jar file."
find . -name 'libwxapkg*.jar' -exec cp -v {} "$INSTALL_PATH" \; 1>&2
cd "$ORIGIN_DIR"
# Prepare executables
prepare_bin_dir
build_command_unwxapkg
# Finished.
echo "Install finished."
exit 0
}
install_from_binary_default() {
echo "Start install from default binary."
# Prepare install
print_install_settings
prepare_work_dir
curl -# -L -O $DEFAULT_BINARY_ADDRESS
find . -name 'libwxapkg*.jar' -exec cp -v {} "$INSTALL_PATH" \;
cd "$ORIGIN_DIR"
# Prepare executables
prepare_bin_dir
build_command_unwxapkg
echo "Install finished." 1>&2
exit 0
}
install_from_binary_auto() {
echo "Trying to download the latest version."
# Check jq
[ -z "$(command -v jq 2> /dev/null)" ] && {
echo "Latest version detection could not run because lack of command 'jq'"
echo "Install it before continue."
exit 1
}
# Prepare install
print_install_settings
prepare_work_dir
local release_api_url='https://api.github.com/repos/JohnKozak/libwxapkg/releases'
local jarurl="$(curl -sSL -H 'application/vnd.github+json' $release_api_url | jq -rM '.[0].assets|.[0].browser_download_url')"
[ -z "$jarurl" ] && {
echo "Could not get jar url from repo."
exit 1
}
curl -O -L -# "$jarurl"
find . -name 'libwxapkg*.jar' -exec cp -v {} "$INSTALL_PATH" \;
cd "$ORIGIN_DIR"
# Prepare executables
prepare_bin_dir
build_command_unwxapkg
echo "Install finished." 1>&2
exit 0
}
if [ s'true' == s"$FROM_SOURCE" ]
then
install_from_source
elif [ -z "$(command -v jq 2> /dev/null)" ]
then
install_from_binary_default
else
install_from_binary_auto
fi