-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·295 lines (273 loc) · 8.87 KB
/
build.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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/bash
# Configure the environment
workdir=`pwd`
declare -a target
target=( "AppImage" "script" "zip" )
declare -a arch
arch=( "x64" "ia32" )
declare -a os
os=( "linux" "mac" "win" )
alias npm=$(which pnpm || which yarn || which npm)
get_args(){
while [[ "$1" ]];do
case $1 in
"--help" | "-h")
printf "\n"
printf "\e[1;44mUsage: ./build.sh [--help] [--clean] [--version] [--target=<target>] [--os=<os>]\e[1;m\n"
printf "\n"
printf "\e[1;44mOptions:\e[1;m\n"
printf "\n"
printf "\e[1;44m -h,--help\e[1;m\t\t\tShow this help\n"
printf "\e[1;44m -c,--clean\e[1;m\t\t\tClean the build directory\n"
printf "\e[1;44m -V,--version\e[1;m\t\t\tShow the version\n"
printf "\e[1;44m -D,--build-dir=<dir>\e[1;m\t\tBuild the binaries in the specified directory (default: ${workdir})\n"
printf "\e[1;44m -t,--target=<target>\e[1;m\t\tBuild the specified target (default: all)\n"
printf "\t\t\t\tSupported targets: $(for i in "${target[@]}";do [[ "${i}" != "${target[0]}" ]] && printf ", " ;printf "${i}";done)\n"
printf "\e[1;44m -s,--os=<os>\e[1;m\t\t\tBuild the specified os (default: all)\n"
printf "\t\t\t\tSupported os: $(for i in "${os[@]}";do [[ "${i}" != "${os[0]}" ]] && printf ", " ;printf "${i}";done)\n"
printf "\e[1;44m -m,--arch=<arch>\e[1;m\t\tBuild the specified architecture (default: all)\n"
printf "\t\t\t\tSupported architecture: $(for i in "${arch[@]}";do [[ "${i}" != "${arch[0]}" ]] && printf ", " ;printf "${i}";done)\n"
printf "\e[1;44m -d,--debug\e[1;m\t\t\tBuild the debug version\n"
printf "\e[1;44m -u,--update\e[1;m\t\t\tUpdate the binaries\n"
printf "\n"
exit 0
;;
"--clean" | "-c")
update=true
clean=true
;;
"--target="* | "-t="* | "-t" | "--target")
# check if the target is included in the list
# if contain "=", target_name=${1#*=}, else target_name=${2}
[[ "${1}" == *"="* ]] && target_name=${1#*=} || target_name=${2}
if [[ "${target_name}" == "all" ]];then
target=( "${target[@]}" )
else
for i in "${target[@]}";do
if [[ "${i}" == "${target_name}" ]];then
target=( "${target[@]}" )
break
fi
done
fi
if [[ "${target_name}" == "" ]];then
printf "\e[1;41mError: --target=<target> or -t <target> is missing\e[1;m\n"
exit 1
fi
if [[ "${target[@]}" =~ "${target_name}" ]];then
target=( "${target_name}" )
else
printf "\e[1;41mError: target ${target_name} is not supported\e[1;m\n"
exit 1
fi
;;
"--os="* | "-s="* | "-s" | "--os")
# check if the os is included in the list
# if contain "=", os_name=${1#*=}, else os_name=${2}
[[ "${1}" == *"="* ]] && os_name=${1#*=} || os_name=${2}
if [[ "${os_name}" == "all" ]];then
os=( "${os[@]}" )
else
for i in "${os[@]}";do
if [[ "${i}" == "${os_name}" ]];then
os=( "${os[@]}" )
break
fi
done
fi
if [[ "${os_name}" == "" ]];then
printf "\e[1;41mError: --os=<os> or -s <os> is missing\e[1;m\n"
exit 1
fi
if [[ "${os[@]}" =~ "${os_name}" ]];then
os=( "${os_name}" )
else
printf "\e[1;41mError: os ${os_name} is not supported\e[1;m\n"
exit 1
fi
;;
"--arch="* | "-m="* | "-m" | "--arch")
# check if the arch is included in the list
# if contain "=", arch_name=${1#*=}, else arch_name=${2}
[[ "${1}" == *"="* ]] && arch_name=${1#*=} || arch_name=${2}
if [[ "${arch_name}" == "all" ]];then
arch=( "${arch[@]}" )
else
for i in "${arch[@]}";do
if [[ "${i}" == "${arch_name}" ]];then
arch=( "${arch[@]}" )
break
fi
done
fi
if [[ "${arch_name}" == "" ]];then
printf "\e[1;41mError: --arch=<arch> or -m <arch> is missing\e[1;m\n"
exit 1
fi
#convert x86_64 to x64; i686, i386, pentium4 to ia32
case ${arch_name} in
"x86_64"*)
arch_name="x64"
;;
"i"*"86" | "pentium4")
arch_name="ia32"
;;
*)
printf "\e[1;41mError: arch ${arch_name} is not supported\e[1;m\n"
exit 1
;;
esac
if [[ "${arch[@]}" =~ "${arch_name}" ]];then
arch=( "${arch_name}" )
else
printf "\e[1;41mError: arch ${arch_name} is not supported\e[1;m\n"
exit 1
fi
;;
"--debug" | "-d")
node_args="debug"
;;
"--update" | "-u")
update=true
;;
"--build-dir="*)
workdir=( "${1#*=}" )
;;
"-D" | "--build-dir")
workdir=$2
shift
;;
"--version" | "-V")
printf "Current binaries version:\t$(npm neu version | grep 'Neutralinojs bin')\n\t\t\t\t$(npm neu version | grep 'Neutralinojs cli')\n"
printf "Current app version:\t\t$(cat ${workdir}/neutralino.config.json | grep '"version":' | sed 's/ "version": "//g' | sed 's/",//g')\n"
exit 0
;;
esac
shift;
done
}
cd ${workdir}
get_args "$@"
# Copy Folders to ./out
cp -r ./resources/fonts ./out/resources/
cp -r ./resources/icons ./out/resources/
cp -r ./resources/res ./out/resources/
if [[ ! "$(ls -A ./bin)" ]];then
# running for the first time
printf "\e[1;44mRunning for the first time\e[1;m\n"
update=true
fi
# Check if update variable is true then run `neu update`
if [[ "${update}" == true ]];then
printf "\e[1;44mUpdating the binaries...\e[1;m\n"
npm install
npm neu update
npm update
fi
printf "\e[1;44mCompiling the source...\e[1;m\n"
node ./index.js ${node_args}
cd out
# else
cp -r ../bin .
cp -r ../resources/js/neutralino.js ./resources/js/
# fi
printf "\e[1;44mBuilding the binaries...\e[1;m\n"
neu build
cd dist/hpvn/
mv ../../resources/res/pack.png .
cp ../../../resources/scripts/*.{sh,bat,cfg} .
chmod +x *.sh *.bat
for i in "${os[@]}"; do
[ "${i}" = "win" ] && bat=*"bat" || bat=""
for m in "${arch[@]}";do
# if is mac and is 32bit, then skip
if [[ "${i}" == "mac" && "${m}" == "ia32" ]];then
continue
fi
# copy binaries from ../../bin to ., rename to hpvn-<os>_<arch>
cp ../../bin/neutralino-${i}_${m}${bat:+".exe"} ./hpvn-${i}_${m}${bat:+".exe"}
[ "$bat" ] && cp ../../bin/WebView2Loader.dll .
for x in "${target[@]}"; do
if [ "${x}" = "AppImage" ]; then
if [[ "macwin" = *"${i}"* ]]; then
continue
fi
current_dir=$(pwd)
cd ../build/
if [ ! -d "HappyVietnam.AppDir" ]; then
mkdir "HappyVietnam.AppDir"
fi
# convert x64 to x86_64, ia32 to i686
machine=${m//x64/x86_64}
machine=${machine//ia32/i686}
if [ -f "../build/Happy_Vietnam_Installer-${machine}.AppImage" ]; then
printf "\e[1;44mRemove old AppImage\e[1;m\n"
rm "../build/Happy_Vietnam_Installer-${machine}.AppImage"
fi
printf "\e[1;44mBuilding AppImage...\e[1;m\n"
cd "HappyVietnam.AppDir"
cat << EOF > AppRun
#!/bin/sh
cd "\$(dirname "\$0")"
exec ./hpvn-${i}_${m}
EOF
cp ../../hpvn/hpvn-${i}_${m} ../../hpvn/*.sh ../../hpvn/resources.neu ../../hpvn/pack.png ../../../resources/icons/appIcon.png .
chmod +x hpvn-${i}_${m}
chmod +x AppRun
cat << EOF > HappyVietnam.desktop
[Desktop Entry]
Name=Happy Vietnam Installer
Comment=Bộ cài đặt Gói tài nguyên và Bản đồ Happy Vietnam Minecraft
Icon=appIcon
Terminal=false
Type=Application
Categories=Education;
X-AppImage-Version=1.0
X-AppImage-Name=HappyVietnam
X-AppImage-Arch=${machine}
EOF
cd ../
[[ ! -f ../appimagetool-${machine}.AppImage ]] && curl -L -o ../appimagetool-${machine}.AppImage https://github.com/AppImage/AppImageKit/releases/latest/download/appimagetool-${machine}.AppImage
chmod +x ../appimagetool-${machine}.AppImage
ARCH=${machine} ../appimagetool-${machine}.AppImage $(pwd)/HappyVietnam.AppDir # --mksquashfs-opt -quiet
rm -rf HappyVietnam.AppDir
cd ${current_dir}
fi
if [ "${x}" = "script" ]; then
# if os is win or os is mac and arch is ia32 then skip
if ([ "${i}" = "mac" ] && [ "${m}" = "ia32" ]) || [ "${i}" = "win" ] ; then
continue
fi
printf "\e[1;44mCreate script for ${i} ${m}\e[1;m\n"
tar -zcvf hpvn-${i}_${m}.tar.gz *.sh *.cfg *.json resources.neu hpvn-${i}_${m} pack.png
fname="../build/hpvn-${i}_${m}$([ "${i}" = "mac" ] && printf ".command")"
rm -f $fname
cat ../../../script.sh | sed -e "s/\${arch}/${m}/g" | sed -e "s/\${os}/${i}/g" > $fname
cat hpvn-${i}_${m}.tar.gz >> $fname
chmod +x $fname
rm -f hpvn-${i}_${m}.tar.gz
fi
if [ "${x}" = "zip" ]; then
printf "\e[1;44mCreate zip archive for ${i} ${m}\e[1;m\n"
fname="../build/hpvn-${i}_${m}.zip"
rm -f $fname
zip -9 $fname *.${bat:-"sh"} *.cfg *.json resources.neu hpvn-${i}_${m}${bat:+".exe"} pack.png ${bat:+"WebView2Loader.dll"}
fi
done
done
done
# clean
if [ "${clean}" = true ]; then
printf "\e[1;44mCleaning...\e[1;m\n"
rm -rf ./*
rm -rf ../*.AppImage
rm -rf ../../resources/res
rm -rf ../../resources/fonts
rm -rf ../../resources/iconscurrent_dir
rm -rf ../../resources/index.html
rm -rf ../../resources/styles.css
rm -rf ../../bin
fi
printf "\e[1;44mBuilds are bundled in ${workdir}/out/dist/build\e[1;m\n"
printf "\e[1;44mDone!\e[1;m\n"
cd ${workdir}