forked from GrimKriegor/TES3MP-deploy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtes3mp-deploy.sh
executable file
·1041 lines (896 loc) · 30.5 KB
/
tes3mp-deploy.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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
set -e
VERSION="2.21.3"
TES3MP_STABLE_VERSION="0.8.1"
TES3MP_STABLE_VERSION_FILE="0.47.0\n68954091c54d0596037c4fb54d2812313b7582a1"
TES3MP_FORGE_VERSION="2.4.0"
HELP_TEXT_HEADER="\
TES3MP-deploy ($VERSION)
Grim Kriegor <[email protected]>
Licensed under the GNU GPLv3 free license
"
HELP_TEXT_BODY="\
Usage $0 MODE [OPTIONS]
Modes of operation:
-i, --install Prepare and install TES3MP and its dependencies
-u, --upgrade Upgrade TES3MP
-a, --auto-upgrade Automatically upgrade TES3MP if there are changes on the remote repository
-r, --rebuild Simply rebuild TES3MP
-y, --script-upgrade Upgrade the TES3MP-deploy script
-p, --make-package Make a portable package for easy distribution
-m, --build-master Build the master server
-h, --help This help text
Options:
-s, --server-only Only build the server
-c, --cores N Use N cores for building TES3MP and its dependencies
-v, --version ID Checkout and build a specific TES3MP commit or branch
-V, --version-string STRING Set the version string for compatibility
-C, --container [ARCH] Run inside a container, optionally specify container architecture
Peculiar options:
--skip-pkgs Skip package installation
--cmake-local Tell CMake to look in /usr/local/ for libraries
--handle-corescripts Handle CoreScripts, pulls and branch switches
--handle-version-file Handle version file by overwritting it with a persistent one
Please report bugs in the GitHub issue page or directly on the TES3MP Discord.
https://github.com/MWMadness/TES3MP-deploy
"
SCRIPT_DIR="$(dirname $(readlink -f $0))"
echo -e "$HELP_TEXT_HEADER"
# Run in container
function run_in_container() {
# Check if Docker is installed
if ! which docker 2>&1 >/dev/null; then
echo -e "Please install Docker before proceeding."
exit 1
fi
# Clean script arguments
SCRIPT_ARGUMENTS=$(echo "$@" | sed 's/-C//;s/--container//')
# Defaults
CONTAINER_IMAGE="docker.io/grimkriegor/tes3mp-forge:$TES3MP_FORGE_VERSION"
CONTAINER_FOLDER_NAME="container"
CONTAINER_DEFAULT_ARGS="--skip-pkgs --cmake-local"
CONTAINER_PLATFORM_CMD="--arch amd64"
# Architecture specifics
case $CONTAINER_ARCHITECTURE in
armhf )
CONTAINER_IS_EMULATED="true"
CONTAINER_ARCH="arm"
CONTAINER_VARIANT="v7"
;;
esac
# Emulated container specifics
if [ $CONTAINER_IS_EMULATED ]; then
CONTAINER_FOLDER_NAME="$CONTAINER_FOLDER_NAME-$CONTAINER_ARCHITECTURE"
CONTAINER_DEFAULT_ARGS=$(echo $CONTAINER_DEFAULT_ARGS | sed 's/--cmake-local//')
CONTAINER_PLATFORM_CMD="--arch $CONTAINER_ARCH --variant $CONTAINER_VARIANT"
echo -e "\nEmulating $CONTAINER_ARCHITECTURE on $(uname -m)"
fi
# Update container image
eval $(which docker) pull "$CONTAINER_PLATFORM_CMD" "$CONTAINER_IMAGE"
# Run through container
echo -e "\n[!] Now running inside the TES3MP-forge container [!]\n"
mkdir -p "$SCRIPT_DIR/$CONTAINER_FOLDER_NAME"
eval $(which docker) run --rm -it \
-v "$SCRIPT_DIR/tes3mp-deploy.sh":"/deploy/tes3mp-deploy.sh" \
-v "$SCRIPT_DIR/$CONTAINER_FOLDER_NAME":"/build" \
$CONTAINER_PLATFORM_CMD \
--entrypoint "/bin/bash" \
"$CONTAINER_IMAGE" \
/deploy/tes3mp-deploy.sh "$CONTAINER_DEFAULT_ARGS" "$SCRIPT_ARGUMENTS"
exit 0
}
# Parse arguments
SCRIPT_ARGS="$@"
if [ $# -eq 0 ]; then
echo -e "$HELP_TEXT_BODY"
echo -e "No parameter specified."
exit 1
else
while [ $# -ne 0 ]; do
case $1 in
# Help text
-h | --help )
echo -e "$HELP_TEXT_BODY"
exit 1
;;
# Install dependencies and build TES3MP
-i | --install )
INSTALL=true
REBUILD=true
;;
# Check if there are updates, prompt to rebuild if so
-u | --upgrade )
UPGRADE=true
;;
# Upgrade automatically if there are changes in the upstream code
-a | --auto-upgrade )
UPGRADE=true
AUTO_UPGRADE=true
;;
# Rebuild tes3mp
-r | --rebuild )
REBUILD=true
;;
# Upgrade the script
-y | --script-upgrade )
SCRIPT_UPGRADE=true
;;
# Make package
-p | --make-package )
MAKE_PACKAGE=true
;;
# Define installation as server only
-s | --server-only )
SERVER_ONLY=true
touch .serveronly
;;
# Build specific commit
-v | --version | --branch | --commit )
if [[ "$2" =~ ^-.* || "$2" == "" ]]; then
echo -e "\nYou must specify a valid commit hash or branch name"
exit 1
else
BUILD_COMMIT=true
TARGET_COMMIT="$2"
shift
fi
;;
# Custom version string for compatibility
-V | --version-string )
if [[ "$2" =~ ^-.* || "$2" == "" ]]; then
echo -e "\nYou must specify a valid version string"
exit 1
else
CHANGE_VERSION_STRING=true
TARGET_VERSION_STRING="$2"
shift
fi
;;
# Number of CPU threads to use in compilation
-c | --cores )
if [[ "$2" =~ ^-.* || "$2" == "" ]]; then
ARG_CORES=""
else
ARG_CORES=$2
shift
fi
;;
# Build master server
-m | --build-master )
BUILD_MASTER=true
touch .buildmaster
;;
# Run in container
-C | --container )
if [[ "$2" =~ ^-.* || "$2" =~ "" ]]; then
CONTAINER_ARCHITECTURE="$2"
shift
fi
RUN_IN_CONTAINER=true
;;
# Skip package installation
--skip-pkgs )
SKIP_PACKAGE_INSTALL=true
;;
# Tell cmake to look for dependencies on /usr/local/
--cmake-local )
CMAKE_LOCAL=true
;;
# Handle CoreScripts
--handle-corescripts )
HANDLE_CORESCRIPTS=true
;;
# Handle version file
--handle-version-file )
HANDLE_VERSION_FILE=true
;;
esac
shift
done
fi
# Run in container
if [ $RUN_IN_CONTAINER ]; then
run_in_container "$SCRIPT_ARGS"
fi
# Exit if no operation is specified
if [[ ! $INSTALL && ! $UPGRADE && ! $REBUILD && ! $SCRIPT_UPGRADE && ! $MAKE_PACKAGE ]]; then
echo -e "\nNo operation specified, exiting."
exit 1
fi
# Number of CPU cores used for compilation
if [[ "$ARG_CORES" == "" || "$ARG_CORES" == "0" ]]; then
CORES="$(cat /proc/cpuinfo | awk '/^processor/{print $3}' | wc -l)"
else
CORES="$ARG_CORES"
fi
# Distro identification
DISTRO="$(lsb_release -si | awk '{print tolower($0)}')"
DISTROCODE="$(lsb_release -sc | awk '{print tolower($0)}')"
# Folder hierarchy
BASE="$(pwd)"
SCRIPT_BASE="$(dirname $0)"
CODE="$BASE/code"
DEVELOPMENT="$BASE/build"
KEEPERS="$BASE/keepers"
DEPENDENCIES="$BASE/dependencies"
PACKAGE_TMP="$BASE/package"
EXTRA="$BASE/extra"
# Dependency locations
RAKNET_LOCATION="$DEPENDENCIES"/raknet
# Check if this is a server only install
if [ -f "$BASE"/.serveronly ]; then
SERVER_ONLY=true
fi
# Check if master server is supposed to be built
if [ -f "$BASE"/.buildmaster ]; then
BUILD_MASTER=true
fi
# Check if there is a persistent version file
if [ -f "$KEEPERS"/version ]; then
HANDLE_VERSION_FILE=true
fi
if [ $CMAKE_LOCAL ]; then
export PATH=/usr/local/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib:"$LD_LIBRARY_PATH"
fi
# Upgrade the TES3MP-deploy script
if [ $SCRIPT_UPGRADE ]; then
SCRIPT_OLD_VERSION=$(cat "$SCRIPT_BASE"/tes3mp-deploy.sh | grep ^VERSION= | cut -d'"' -f2)
if [ -d "$SCRIPT_BASE"/.git ]; then
echo -e "\n>>Upgrading the TES3MP-deploy git repository"
cd "$SCRIPT_BASE"
git stash
git pull
cd "$BASE"
else
echo -e "\n>>Downloading TES3MP-deploy from GitHub"
mv "$0" "$SCRIPT_BASE"/.tes3mp-deploy.sh.bkp
wget --no-verbose -O "$SCRIPT_BASE"/tes3mp-deploy.sh https://raw.githubusercontent.com/MWMadness/TES3MP-deploy/master/tes3mp-deploy.sh
chmod +x "$SCRIPT_BASE"/tes3mp-deploy.sh
fi
SCRIPT_NEW_VERSION=$(cat "$SCRIPT_BASE"/tes3mp-deploy.sh | grep ^VERSION= | cut -d'"' -f2)
if [ "$SCRIPT_NEW_VERSION" == "" ]; then
echo -e "\nThere was a problem downloading the script, exiting."
exit 1
fi
if [ "$SCRIPT_OLD_VERSION" != "$SCRIPT_NEW_VERSION" ]; then
echo -e "\nScript upgraded from ($SCRIPT_OLD_VERSION) to ($SCRIPT_NEW_VERSION)"
echo -e "\nReloading...\n"
SCRIPT_ARGS_TRUNC="$(echo "$SCRIPT_ARGS" | sed 's/--script-upgrade//g;s/-y//g')"
eval $(which bash) "$0 $SCRIPT_ARGS_TRUNC"
exit 0
else
echo -e "\nScript already at the latest avaliable version ($SCRIPT_OLD_VERSION)"
fi
fi
# Install mode
if [ $INSTALL ]; then
# Create folder hierarchy
echo -e ">> Creating folder hierarchy"
mkdir -p "$DEVELOPMENT" "$KEEPERS" "$DEPENDENCIES"
# Check distro and install dependencies
if [ ! $SKIP_PACKAGE_INSTALL ]; then
echo -e "\n>> Checking which GNU/Linux distro is installed"
case $DISTRO in
"debian" | "devuan" )
echo -e "You seem to be running Debian or Devuan"
sudo apt-get update
sudo apt-get install \
unzip \
wget \
git \
cmake \
libopenal-dev \
qt5-default \
qtbase5-dev \
qtbase5-dev-tools \
qttools5-dev-tools \
libqt5opengl5-dev \
libopenthreads-dev \
libopenscenegraph-dev \
libsdl2-dev \
libboost-filesystem-dev \
libboost-thread-dev \
libboost-program-options-dev \
libboost-system-dev \
libavcodec-dev \
libavformat-dev \
libavutil-dev \
libswscale-dev \
libswresample-dev \
libmygui-dev \
libunshield-dev \
libyaml-cpp-dev \
cmake \
build-essential \
g++ \
libncurses5-dev \
luajit \
libluajit-5.1-dev \
liblua5.1-0-dev
if [ $DISTROCODE == "stretch" ]; then
sudo apt-get -y install libbullet-dev/stretch-backports
else
sudo apt-get -y install libbullet-dev
fi
sudo sed -i "s_# deb-src_deb-src_g" /etc/apt/sources.list
;;
"arch" | "parabola" | "manjarolinux" | "endeavouros" )
echo -e "You seem to be running either Arch Linux, Parabola GNU/Linux-libre, Manjaro, or EndeavourOS"
sudo pacman -Sy --needed unzip \
wget \
git \
cmake \
boost \
openal \
openscenegraph \
mygui \
bullet-dp \
qt5-base \
ffmpeg \
sdl2 \
unshield \
libxkbcommon-x11 \
ncurses \
yaml-cpp \
luajit
if [ ! -d "/usr/share/licenses/gcc-libs-multilib/" ]; then
sudo pacman -S --needed gcc-libs
fi
;;
"ubuntu" | "linuxmint" | "elementary" )
echo -e "You seem to be running Ubuntu, Mint or elementary OS"
echo -e "
The OpenMW PPA repository needs to be enabled
https://wiki.openmw.org/index.php?title=Development_Environment_Setup#Ubuntu
Type YES if you want the script to do it automatically
If you already have it enabled or want to do it manually,
press ENTER to continue"
read INPUT
if [ "$INPUT" == "YES" ]; then
echo -e "\nEnabling the OpenMW PPA repository..."
sudo add-apt-repository ppa:openmw/openmw
echo -e "Done!"
fi
sudo apt-get update
sudo apt-get install \
unzip \
wget \
git \
cmake \
libopenal-dev \
qt5-default \
qtbase5-dev \
qtbase5-dev-tools \
qttools5-dev-tools \
libqt5opengl5-dev \
libopenthreads-dev \
libopenscenegraph-dev \
libsdl2-dev \
libboost-filesystem-dev \
libboost-thread-dev \
libboost-program-options-dev \
libboost-system-dev \
libbullet-dev \
libavcodec-dev \
libavformat-dev \
libavutil-dev \
libswscale-dev \
libswresample-dev \
libmygui-dev \
libunshield-dev \
libyaml-cpp-dev \
cmake \
build-essential \
g++ \
libncurses5-dev \
luajit \
libluajit-5.1-dev \
liblua5.1-0-dev
sudo sed -i "s_# deb-src_deb-src_g" /etc/apt/sources.list
;;
"fedora" )
echo -e "You seem to be running Fedora"
echo -e "
Fedora users are required to enable the RPMFusion FREE and NON-FREE repositories
https://wiki.openmw.org/index.php?title=Development_Environment_Setup#Fedora_Workstation
Type YES if you want the script to do it automatically
If you already have it enabled or want to do it manually,
press ENTER to continue"
read INPUT
if [ "$INPUT" == "YES" ]; then
echo -e "\nEnabling RPMFusion..."
su -c 'dnf install \
http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm \
http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm'
echo -e "Done!"
fi
sudo dnf --refresh groupinstall development-tools
sudo dnf --refresh install \
unzip \
wget \
cmake \
openal-devel \
OpenSceneGraph-qt-devel \
SDL2-devel \
qt5-devel \
boost-filesystem \
git \
boost-thread \
boost-program-options \
boost-system \
ffmpeg-devel \
ffmpeg-libs \
bullet-devel \
gcc-c++ \
mygui-devel \
unshield-devel \
tinyxml-devel \
cmake \
ncurses-c++-libs \
ncurses-devel \
luajit-devel
;;
*)
echo -e "Your GNU/Linux distro is not supported yet, press ENTER to continue without installing dependency packages"
read
;;
esac
fi
# Truncate target_commit when it points to stable
if [ "$TARGET_COMMIT" == "stable" ]; then
TARGET_COMMIT="$TES3MP_STABLE_VERSION"
fi
# Pull software via git
echo -e "\n>> Downloading software"
! [ -e "$CODE" ] && git clone -b saint-master-merge https://github.com/MWMadness/S3-MP.git "$CODE"
# ! [ -e "$CODE" ] && git clone -b "${TARGET_COMMIT:-master}" https://github.com/MWMadness/S3-MP.git "$CODE"
! [ -e "$DEPENDENCIES"/raknet ] && git clone https://github.com/MWMadness/CrabNet "$DEPENDENCIES"/raknet
# ! [ -e "$KEEPERS"/CoreScripts ] && git clone -b "${TARGET_COMMIT:-master}" https://github.com/MWMadness/CoreScripts.git "$KEEPERS"/CoreScripts
! [ -e "$KEEPERS"/CoreScripts ] && git clone -b saint-master-merge https://github.com/MWMadness/CoreScripts.git "$KEEPERS"/CoreScripts
# Copy static server and client configs
echo -e "\n>> Copying server and client configs to their permanent place"
cp "$CODE"/files/tes3mp/tes3mp-{client,server}-default.cfg "$KEEPERS"
# Set home variable in tes3mp-server-default.cfg
echo -e "\n>> Autoconfiguring"
sed -i "s|home = .*|home = $KEEPERS/CoreScripts|g" "${KEEPERS}"/tes3mp-server-default.cfg
# Dirty hacks
echo -e "\n>> Applying some dirty hacks"
sed -i "s|tes3mp.lua,chat_parser.lua|serverCore.lua|g" "${KEEPERS}"/tes3mp-server-default.cfg #Fixes server scripts
# Build RakNet
echo -e "\n>> Building RakNet"
cd "$DEPENDENCIES"/raknet
git checkout af1a20b48e50ef2d19f0699133140bb15847b370
mkdir -p "$DEPENDENCIES"/raknet/build
cd "$DEPENDENCIES"/raknet/build
rm -f CMakeCache.txt
cmake -DCMAKE_BUILD_TYPE=Release -DRAKNET_ENABLE_DLL=OFF -DRAKNET_ENABLE_SAMPLES=OFF -DRAKNET_ENABLE_STATIC=ON -DRAKNET_GENERATE_INCLUDE_ONLY_DIR=ON ..
make -j$CORES
ln -sf "$DEPENDENCIES"/raknet/include/RakNet "$DEPENDENCIES"/raknet/include/raknet #Stop being so case sensitive
cd "$BASE"
# Build the stable branch if no target commit is specified
if [ ! $BUILD_COMMIT ]; then
echo -e "\n>> Switching to the STABLE branch."
BUILD_COMMIT=true
TARGET_COMMIT="stable"
# Switch to the stable branch on CoreScripts as well
cd "$KEEPERS"/CoreScripts
git stash
git pull
git checkout "$TES3MP_STABLE_VERSION"
cd "$BASE"
# Handle version file
HANDLE_VERSION_FILE=true
fi
fi
# Check the remote repository for changes
if [ $UPGRADE ]; then
# Check if there are changes in the git remote
echo -e "\n>> Checking the git repository for changes"
cd "$CODE"
git remote update
if [ "$(git rev-parse @)" != "$(git rev-parse @{u})" ]; then
echo -e "\nNEW CHANGES on the git repository"
GIT_CHANGES=true
else
echo -e "\nNo changes on the git repository"
fi
cd "$BASE"
# Check if there are changes in the CoreScripts git remote
if [ $HANDLE_CORESCRIPTS ]; then
echo -e "\n>> Checking the CoreScripts git repository for changes"
cd "$KEEPERS"/CoreScripts
git remote update
if [ "$(git rev-parse @)" != "$(git rev-parse @{u})" ]; then
echo -e "\nNEW CHANGES on the CoreScripts git repository"
GIT_CHANGES_CORESCRIPTS=true
else
echo -e "\nNo changes on the CoreScripts git repository"
fi
cd "$BASE"
fi
# Automatically upgrade if there are git changes
if [ $AUTO_UPGRADE ]; then
if [ $GIT_CHANGES ]; then
REBUILD="YES"
UPGRADE="YES"
elif [ $GIT_CHANGES_CORESCRIPTS ]; then
UPGRADE="YES"
else
echo -e "\nNo new commits, exiting."
exit 0
fi
else
echo -e "\nDo you wish to rebuild TES3MP? (type YES to continue)"
read REBUILD_PROMPT
if [ "$REBUILD_PROMPT" == "YES" ]; then
REBUILD="YES"
UPGRADE="YES"
else
if [ $HANDLE_CORESCRIPTS ]; then
echo -e "\nUpgrade CoreScripts at least? (type YES to upgrade)"
read CORESCRIPTS_UPGRADE_PROMPT
if [ "$CORESCRIPTS_UPGRADE_PROMPT" == "YES" ]; then
UPGRADE="YES"
fi
fi
fi
fi
fi
# CoreScripts handling (hack, please make me more elegant later :( )
if [ $HANDLE_CORESCRIPTS ]; then
if [ $UPGRADE ]; then
echo -e "\n>> Pulling CoreScripts code changes from git"
cd "$KEEPERS"/CoreScripts
git stash
git pull
cd "$BASE"
fi
if [ $BUILD_COMMIT ]; then
cd "$KEEPERS"/CoreScripts
if [[ "$TARGET_COMMIT" == "" || "$TARGET_COMMIT" == "latest" ]]; then
echo -e "\nChecking out the latest CoreScripts commit."
git stash
git pull
git checkout master
elif [ "$TARGET_COMMIT" == "stable" ]; then
echo -e "\nChecking out the CoreScripts stable branch. \"$TES3MP_STABLE_VERSION\""
git stash
git pull
git checkout "$TES3MP_STABLE_VERSION"
else
echo -e "\nChecking out CoreScripts $TARGET_COMMIT"
git stash
git pull
git checkout "$TARGET_COMMIT"
fi
cd "$BASE"
fi
fi
# Rebuild TES3MP
if [ $REBUILD ]; then
# Switch to a specific commit
if [ $BUILD_COMMIT ]; then
cd "$CODE"
if [[ "$TARGET_COMMIT" == "" || "$TARGET_COMMIT" == "latest" ]]; then
echo -e "\nChecking out the latest commit."
git stash
git pull
git checkout master
elif [ "$TARGET_COMMIT" == "stable" ]; then
echo -e "\nChecking out the stable branch. \"$TES3MP_STABLE_VERSION\""
git stash
git pull
git checkout "$TES3MP_STABLE_VERSION"
if [ $HANDLE_VERSION_FILE ]; then
echo -e "\n>> Creating persistent version file"
echo -e $TES3MP_STABLE_VERSION_FILE > "$KEEPERS"/version
fi
else
echo -e "\nChecking out $TARGET_COMMIT"
git stash
git pull
git checkout "$TARGET_COMMIT"
fi
cd "$BASE"
if [ $HANDLE_VERSION_FILE ]; then
echo -e "\n(!) VERSION FILE OVERRIDE DETECTED (!)\nIf this was not intended, remove $KEEPERS/version"
fi
fi
# Change version string
if [ $CHANGE_VERSION_STRING ]; then
cd "$CODE"
if [[ "$TARGET_VERSION_STRING" == "" || "$TARGET_VERSION_STRING" == "latest" ]]; then
echo -e "\nUsing the upstream version string"
git stash
cd "$KEEPERS"/CoreScripts
git stash
cd "$CODE"
else
echo -e "\nUsing \"$TARGET_VERSION_STRING\" as version string"
sed -i "s|#define TES3MP_VERSION .*|#define TES3MP_VERSION \"$TARGET_VERSION_STRING\"|g" ./components/openmw-mp/Version.hpp
sed -i "s| local expectedVersionPrefix = .*| local expectedVersionPrefix = \"$TARGET_VERSION_STRING\"|g" "$KEEPERS"/CoreScripts/scripts/serverCore.lua
fi
cd "$BASE"
fi
# Pull code changes from the git repository
if [ "$UPGRADE" == "YES" ]; then
echo -e "\n>> Pulling code changes from git"
cd "$CODE"
git stash
git pull
cd "$BASE"
fi
echo -e "\n>> Doing a clean build of TES3MP"
rm -r "$DEVELOPMENT"
mkdir -p "$DEVELOPMENT"
cd "$DEVELOPMENT"
CMAKE_PARAMS="-Wno-dev \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_OPENCS=OFF \
-DCMAKE_CXX_STANDARD=14 \
-DCMAKE_CXX_FLAGS=\"-std=c++14\" \
-DDESIRED_QT_VERSION=5 \
-DRakNet_INCLUDES="${RAKNET_LOCATION}"/include \
-DRakNet_LIBRARY_DEBUG="${RAKNET_LOCATION}"/build/lib/libRakNetLibStatic.a \
-DRakNet_LIBRARY_RELEASE="${RAKNET_LOCATION}"/build/lib/libRakNetLibStatic.a"
if [ $SERVER_ONLY ]; then
CMAKE_PARAMS="$CMAKE_PARAMS \
-DBUILD_OPENMW_MP=ON \
-DBUILD_OPENCS=OFF \
-DBUILD_BROWSER=OFF \
-DBUILD_BSATOOL=OFF \
-DBUILD_ESMTOOL=OFF \
-DBUILD_ESSIMPORTER=OFF \
-DBUILD_LAUNCHER=OFF \
-DBUILD_MWINIIMPORTER=OFF \
-DBUILD_MYGUI_PLUGIN=OFF \
-DBUILD_OPENMW=OFF \
-DBUILD_NIFTEST=OFF \
-DBUILD_WIZARD=OFF"
fi
if [ $BUILD_MASTER ]; then
CMAKE_PARAMS="$CMAKE_PARAMS \
-DBUILD_MASTER=ON"
fi
if [ $CMAKE_LOCAL ]; then
CMAKE_PARAMS="$CMAKE_PARAMS \
-DCMAKE_LIBRARY_PATH=/usr/local/lib64"
fi
echo -e "\n\n$CMAKE_PARAMS\n\n"
cmake "$CODE" $CMAKE_PARAMS || true
set -o pipefail # so that the "tee" below would not make build always return success
make -j $CORES 2>&1 | tee "${BASE}"/build.log
cd "$BASE"
# Create symlinks for the config files inside the new build folder
echo -e "\n>> Creating symlinks of the config files in the build folder"
for file in "$KEEPERS"/*.cfg
do
FILEPATH=$file
FILENAME=$(basename $file)
mv "$DEVELOPMENT/$FILENAME" "$DEVELOPMENT/$FILENAME.bkp" 2> /dev/null
ln -sf "../keepers/$FILENAME" "$DEVELOPMENT/"
done
# Create symlinks for resources inside the config folder
echo -e "\n>> Creating symlinks for resources inside the config folder"
ln -sf ../"$(basename $DEVELOPMENT)"/resources "$KEEPERS"/resources 2> /dev/null
# Create useful shortcuts on the base directory
echo -e "\n>> Creating useful shortcuts on the base directory"
if [ $SERVER_ONLY ]; then
SHORTCUTS=( "tes3mp-server" )
else
SHORTCUTS=( "tes3mp" "tes3mp-browser" "tes3mp-server" )
fi
for i in ${SHORTCUTS[@]}; do
printf "#!/bin/bash\n\ncd build/\n./$i\ncd .." > "$i".sh
chmod +x "$i".sh
done
# Handle version file
if [ $HANDLE_VERSION_FILE ]; then
echo -e "\n>> Linking persistent version file"
rm "$DEVELOPMENT"/resources/version
ln -sf "$KEEPERS"/version "$DEVELOPMENT"/resources/version
fi
# Copy creditation files
echo -e "\n>> Copying creditation files"
cp "$CODE"/AUTHORS.md "$DEVELOPMENT"
cp "$CODE"/tes3mp-credits.md "$DEVELOPMENT"
# All done
echo -e "\n\n\nAll done! Press any key to exit.\nMay Vehk bestow his blessing upon your Muatra."
fi
# Make portable package
if [ $MAKE_PACKAGE ]; then
echo -e "\n>> Creating TES3MP package"
PACKAGE_BINARIES=( \
"tes3mp" \
"tes3mp-browser" \
"tes3mp-server" \
"openmw-launcher" \
"openmw-wizard" \
"openmw-essimporter" \
"openmw-iniimporter" \
"bsatool" \
"esmtool" \
)
LIBRARIES_OPENMW=( \
"libboost_thread.so" \
"libboost_system.so" \
"libboost_filesystem.so" \
"libboost_program_options.so" \
"libboost_iostreams.so" \
"libBulletCollision.so" \
"libbz2.so" \
"libLinearMath.so" \
"libMyGUIEngine.so" \
"libOpenThreads.so" \
"libosgAnimation.so" \
"libosgDB.so" \
"libosgFX.so" \
"libosgGA.so" \
"libosgParticle.so" \
"libosg.so" \
"libosgText.so" \
"libosgUtil.so" \
"libosgViewer.so" \
"libosgWidget.so" \
"libosgShadow.so" \
"libSDL2" \
"libts.so" \
"libtxc_dxtn.so" \
"libunshield.so" \
"libuuid.so" \
"osgPlugins" \
)
LIBRARIES_TES3MP=( \
"libRakNetLibStatic.a" \
"libtinfo.so" \
"liblua5.1.so" \
)
LIBRARIES_EXTRA=( \
"libpng16.so" \
)
LIBRARIES_SERVER=( \
"libboost_system.so" \
"libboost_filesystem.so" \
"libboost_program_options.so" \
"libboost_iostreams.so" \
"liblua5.1.so" \
)
# Exit if tes3mp hasn't been compiled yet
if [[ ! -f "$DEVELOPMENT"/tes3mp && ! -f "$DEVELOPMENT"/tes3mp-server ]]; then
echo -e "\nTES3MP has to be built before packaging"
exit 1
fi
# Copy the entire build folder for packaging
cp -r "$DEVELOPMENT" "$PACKAGE_TMP"
# Copy the license file
cp -f "$CODE"/LICENSE "$PACKAGE_TMP"/LICENSE
# Copy the source code
SOURCE_TMP="$BASE/TES3MP"
cp -r "$CODE" "$SOURCE_TMP"
rm -r "$SOURCE_TMP/.git"
tar cvf "$PACKAGE_TMP/source.tar.gz" -C "$BASE" "$(basename $SOURCE_TMP)"
rm -r "$SOURCE_TMP"
# Copy the persistent version file as well
if [ $HANDLE_VERSION_FILE ]; then
rm -f "$PACKAGE_TMP"/resources/version
cp -fn "$KEEPERS"/version "$PACKAGE_TMP"/resources/version
fi
cd "$PACKAGE_TMP"
# Cleanup unneeded files
echo -e "\nCleaning up unneeded files"
find "$PACKAGE_TMP" -type d -name "CMakeFiles" -exec rm -rf "{}" \; || true
#find "$PACKAGE_TMP" -type d -name ".git" -exec rm -rf "{}" \; || true
find "$PACKAGE_TMP" -type l -exec rm -f "{}" \; || true
rm -f "$PACKAGE_TMP"/{Make*,CMake*,*cmake}
rm -f "$PACKAGE_TMP"/{*.bkp,*.desktop,*.xml}
rm -rf "$PACKAGE_TMP"/{apps,components,docs,extern,files,try-compile,_deps}
# Copy useful files
echo -e "\nCopying useful files"
cp -r "$KEEPERS"/CoreScripts "$PACKAGE_TMP"/server
cp -r "$KEEPERS"/*.cfg "$PACKAGE_TMP"
sed -i "s|home = .*|home = ./server|g" "$PACKAGE_TMP"/tes3mp-server-default.cfg
# Copy whatever extra files are currently present
if [ -d "$EXTRA" ]; then
echo -e "\nCopying some extra files"
cp -rf --preserve=links "$EXTRA"/* "$PACKAGE_TMP"/
fi
# List and copy all libs
mkdir -p lib
echo -e "\nCopying needed libraries"
LIBRARIES=("${LIBRARIES_OPENMW[@]}" "${LIBRARIES_TES3MP[@]}" "${LIBRARIES_EXTRA[@]}")
if [ $SERVER_ONLY ]; then LIBRARIES=("${LIBRARIES_SERVER[@]}"); fi
for LIB in "${LIBRARIES[@]}"; do
find /lib /usr/lib /usr/local/lib /usr/local/lib64 "$DEPENDENCIES" -name "$LIB*" -exec cp -r --preserve=links "{}" ./lib \; 2> /dev/null || true
echo -ne "$LIB\033[0K\r"
done
# Make sure all symlinks are relative
echo -e "\nMaking sure all symlinks are relative"
find ./lib -type l | while read LINK; do
LINK_BASENAME="$(basename $LINK)"
LINK_TARGET="$(readlink -f $LINK)"
LINK_TARGET_BASENAME="$(basename $LINK_TARGET)"
ln -sf ./"$LINK_TARGET_BASENAME" ./lib/"$LINK_BASENAME"
echo -ne "$LINK\033[0K\r"
done
# Package info
PACKAGE_PREFIX="tes3mp"
if [ $SERVER_ONLY ]; then
PACKAGE_PREFIX="$PACKAGE_PREFIX-server"
fi
PACKAGE_ARCH=$(uname -m)
PACKAGE_SYSTEM=$(uname -o | sed 's,/,+,g')
PACKAGE_DISTRO="$DISTRO"
PACKAGE_VERSION=$(cat "$CODE"/components/openmw-mp/Version.hpp | grep TES3MP_VERSION | awk -F'"' '{print $2}')
PACKAGE_COMMIT=$(git --git-dir=$CODE/.git rev-parse @ | head -c10)
PACKAGE_COMMIT_SCRIPTS=$(git --git-dir=$KEEPERS/CoreScripts/.git rev-parse @ | head -c10)
PACKAGE_NAME="$PACKAGE_PREFIX-$PACKAGE_SYSTEM-$PACKAGE_ARCH-release-$PACKAGE_VERSION-$PACKAGE_COMMIT-$PACKAGE_COMMIT_SCRIPTS"
PACKAGE_DATE="$(date +"%Y-%m-%d")"
echo -e "TES3MP $PACKAGE_VERSION ($PACKAGE_COMMIT $PACKAGE_COMMIT_SCRIPTS) built on $PACKAGE_SYSTEM $PACKAGE_ARCH ($PACKAGE_DISTRO) on $PACKAGE_DATE by $USER ($HOSTNAME)" > "$PACKAGE_TMP"/tes3mp-package-info.txt
# Create pre-launch script
cat << 'EOF' > tes3mp-prelaunch
#!/bin/bash
ARGS="$*"
GAMEDIR="$(cd "$(dirname "$0")"; pwd -P)"
TES3MP_HOME="$HOME/.config/openmw"
# If there are config files in the home directory, load those
# Otherwise check the package/installation directory and load those
# Otherwise copy them to the home directory
if [[ "$ARGS" = 'tes3mp-server' ]]; then
if [[ -f "$TES3MP_HOME"/tes3mp-server.cfg ]]; then
echo -e "Loading server config from the home directory"
LOADING_FROM_HOME=true
elif [[ -f "$GAMEDIR"/tes3mp-server-default.cfg ]]; then
echo -e "Loading server config from the package directory"
else
echo -e "Server config not found in home and package directory, trying to copy from .example"
cp -f tes3mp-server-default.cfg.example "$TES3MP_HOME"/tes3mp-server.cfg
LOADING_FROM_HOME=true
fi
if [[ $LOADING_FROM_HOME ]]; then
if [[ -d "$TES3MP_HOME"/server ]]; then
echo -e "Loading CoreScripts folder from the home directory"
else
echo -e "CoreScripts folder not found in home directory, copying from package directory"
cp -rf "$GAMEDIR"/server/ "$TES3MP_HOME"/
sed -i "s|home = .*|home = $TES3MP_HOME/server |g" "$TES3MP_HOME"/tes3mp-server.cfg
fi
fi
else
if [[ -f $TES3MP_HOME/tes3mp-client.cfg ]]; then
echo -e "Loading client config from the home directory"
elif [[ -f tes3mp-client-default.cfg ]]; then