-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathdf-lnp-installer.sh
executable file
·1778 lines (1371 loc) · 49.9 KB
/
df-lnp-installer.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/sh
# Function declarations.
ask_for_preferred_install_dir () {
# Suggest either the default INSTALL_DIR or a known installation location, as set in config file.
echo ""
echo -n "Where should Dwarf Fortress be installed? [$INSTALL_DIR]: "
# Get the user's preferred installation location.
read PREFERRED_DIR
# If the user entered a preferred directory, use that,
# otherwise use the install directory.
if [ -n "$PREFERRED_DIR" ]; then
# Use sed and custom ; delimeter to replace the first instance of ~ with the user's home directory.
INSTALL_DIR=$(echo "$PREFERRED_DIR" | sed "s;~;$HOME;")
fi
}
backup_df_directory () {
if [ -z "$INSTALL_DIR" ]; then
exit_with_error "Script failure: INSTALL_DIR not defined."
fi
mkdir -p "$BACKUP_DIR"
if [ "$?" != "0" ]; then
# Clean up after ourself.
# Nothing to do.
exit_with_error "Creating $BACKUP_DIR failed."
fi
# Copy the old install to the backup directory.
cp -r "$INSTALL_DIR" "$BACKUP_DIR"
if [ "$?" != "0" ]; then
# Clean up after ourself.
rm -r "$BACKUP_DIR"
exit_with_error "Backing up old DF installation failed."
fi
}
build_dwarf_therapist () {
if [ -z "$DOWNLOAD_DIR" ]; then
exit_with_error "Script failure. DOWNLOAD_DIR undefined."
fi
local DWARF_THERAPIST_HG_DIR="$DOWNLOAD_DIR/dwarftherapist"
# Choose the good qmake version depending of the Qt version used
if [ "$USE_QT5" = "1" ]; then
QMAKE=$(find_qmake_qt5)
else
QMAKE=$(find_qmake_qt4)
fi
# qmake-qt5 requires that the working directory is the same as the
# hg source directory. Change directories into that location.
cd "$DWARF_THERAPIST_HG_DIR"
# Create the makefile.
$QMAKE
# Quit if qmake failed.
if [ "$?" != "0" ]; then
# Clean up after ourself.
# Nothing to do; that's qmake's job.
exit_with_error "Compiling Dwarf Therapist failed. See QMake output above for details."
fi
# Build from the new Makefile.
make
# Quit if building failed.
if [ "$?" != "0" ]; then
# Clean up after ourself.
# Nothing to do; that's Make's job.
exit_with_error "Compiling Dwarf Therapist failed. See Make output above for details."
fi
# Back up to the previously used working directory (which should be the df-lnp-installer dir).
cd -
}
# One-off bugfixes that either require multiple packages to be installed first
# or have other non-trivial consequences.
bugfix_all () {
fix_cla_missing_mouse_png
fix_jolly_bastion_missing_graphics_dir
fix_jolly_bastion_missing_mouse_png
fix_phoebus_missing_mouse_png
fix_phoebus_gfx_font_ttf_name
fix_obsidian_gfx_font_ttf_name
fix_soundsense_missing_gamelog
fix_vanilla_df_openal_issue
fix_vanilla_df_ancient_libstdcpp
fix_vanilla_df_lnp_settings_not_applied_by_default
}
find_python2 () {
for name in "python" "python2"; do
# If the executable exists...
# and its -V output is "Python 2.x.x"...
# then return that executable name.
if [ -n "$(which $name)" ] && [ "$($name -V 2<&1 | cut -d' ' -f 2 | cut -d . -f 1)" = "2" ]; then
echo $name
break
fi
done
}
find_qmake_qt4 () {
for name in "qmake" "qmake-qt4"; do
# If the executable exists...
# and its -query QT_VERSION output is "4"...
# then return that executable name.
if [ -n "$(which $name 2> /dev/null)" ] && [ "$($name -query QT_VERSION | cut -d . -f 1)" = "4" ]; then
echo $name
break
fi
done
}
find_qmake_qt5 () {
for name in "qmake" "qmake-qt5"; do
# If the executable exists...
# and its -query QT_VERSION output is "5"...
# then return that executable name.
if [ -n "$(which $name)" ] && [ "$($name -query QT_VERSION | cut -d . -f 1)" = "5" ]; then
#echo $name
echo "qmake-qt5"
break
fi
done
}
check_dependencies () {
echo "Checking for dependencies..."
local MISSING_DEPS=""
# file
if [ -z "$(which file)" ]; then
MISSING_DEPS="${MISSING_DEPS}file "
fi
# WGET
if [ -z "$(which wget)" ]; then
MISSING_DEPS="${MISSING_DEPS}wget "
fi
# sha1sum
if [ -z "$(which sha1sum)" ]; then
MISSING_DEPS="${MISSING_DEPS}sha1sum "
fi
# sed
if [ -z "$(which sed)" ]; then
MISSING_DEPS="${MISSING_DEPS}sed "
fi
# Tar
if [ -z "$(which tar)" ]; then
MISSING_DEPS="${MISSING_DEPS}tar "
fi
# Unzip
if [ -z "$(which unzip)" ]; then
MISSING_DEPS="${MISSING_DEPS}unzip "
fi
# Unrar
if [ -z "$(which unrar)" ]; then
MISSING_DEPS="${MISSING_DEPS}unrar "
fi
# Patch
if [ -z "$(which patch)" ]; then
MISSING_DEPS="${MISSING_DEPS}patch "
fi
# xterm for LNP
if [ -z "$(which xterm)" ]; then
MISSING_DEPS="${MISSING_DEPS}xterm "
fi
# Mercurial (required for DwarfTherapist)
if [ -z "$(which hg)" ]; then
MISSING_DEPS="${MISSING_DEPS}hg "
fi
# make (required for DwarfTherapist)
if [ -z "$(which make)" ]; then
MISSING_DEPS="${MISSING_DEPS}make "
fi
# g++ (required for DwarfTherapist)
if [ -z "$(which g++)" ]; then
MISSING_DEPS="${MISSING_DEPS}g++ "
fi
# gcc (required for DwarfTherapist)
if [ -z "$(which gcc)" ]; then
MISSING_DEPS="${MISSING_DEPS}gcc "
fi
# Check for QT Libraries (required for Dwarf Therapist)
# First Qt5 libraries.
if [ -z "$(which qtchooser)" ]; then
MISSING_DEPS_QT5="${MISSING_DEPS_QT5}qtchooser "
fi
if [ -z "$(/sbin/ldconfig -p | grep -P '^\tlibQt5Core.so')" ]; then
MISSING_DEPS_QT5="${MISSING_DEPS_QT5}libQt5Core "
fi
if [ -z "$(/sbin/ldconfig -p | grep -P '^\tlibQt5Gui.so')" ]; then
MISSING_DEPS_QT5="${MISSING_DEPS_QT5}libQt5Gui "
fi
if [ -z "$(/sbin/ldconfig -p | grep -P '^\tlibQt5Script.so')" ]; then
MISSING_DEPS_QT5="${MISSING_DEPS_QT5}libQt5Script "
fi
# qmake (required for DwarfTherapist)
if [ -z "$(find_qmake_qt5)" ]; then
MISSING_DEPS_QT5="${MISSING_DEPS_QT5}qmake_qt5 "
fi
# If Qt5 libraries are missing, check Qt4
if [ -n "$MISSING_DEPS_QT5" ]; then
if [ -z "$(/sbin/ldconfig -p | grep -P '^\tlibQtCore.so')" ]; then
MISSING_DEPS="${MISSING_DEPS}libQtCore "
fi
if [ -z "$(/sbin/ldconfig -p | grep -P '^\tlibQtGui.so')" ]; then
MISSING_DEPS="${MISSING_DEPS}libQtGui "
fi
if [ -z "$(/sbin/ldconfig -p | grep -P '^\tlibQtNetwork.so')" ]; then
MISSING_DEPS="${MISSING_DEPS}libQtNetwork "
fi
if [ -z "$(/sbin/ldconfig -p | grep -P '^\tlibQtScript.so')" ]; then
MISSING_DEPS="${MISSING_DEPS}libQtScript "
fi
# qmake (required for DwarfTherapist)
if [ -z "$(find_qmake_qt4)" ]; then
MISSING_DEPS="${MISSING_DEPS}qmake_qt4 "
fi
fi
# java runtime environment (required for LNP, Chromafort, and DF Announcement Filter)
if [ -z "$(which java)" ]; then
MISSING_DEPS="${MISSING_DEPS}java "
fi
# Check for libSDL base; must be 32-bit.
local LIBSDL_BASE_SO="$(/sbin/ldconfig -p | grep -P '^\tlibSDL-1.2.so.0' | sed 's/[^>]*> //')"
local LIBSDL_32_BIT_FILENAME="$(file -L $LIBSDL_BASE_SO | grep "32-bit" | cut -d: -f1)"
if [ -z "$LIBSDL_32_BIT_FILENAME" ]; then
MISSING_DEPS="${MISSING_DEPS}libSDL-1.2_(32-bit) "
fi
# Check for libSDL image; must be 32-bit.
local LIBSDL_IMAGE_SO="$(/sbin/ldconfig -p | grep -P '^\tlibSDL_image-1.2.so.0' | sed 's/[^>]*> //')"
local LIBSDL_IMAGE_32_BIT_FILENAME="$(file -L $LIBSDL_IMAGE_SO | grep "32-bit" | cut -d: -f1)"
if [ -z "$LIBSDL_IMAGE_32_BIT_FILENAME" ]; then
MISSING_DEPS="${MISSING_DEPS}libSDL_image-1.2_(32-bit) "
fi
# Check for libSDL ttf; must be 32-bit.
local LIBSDL_TTF_SO="$(/sbin/ldconfig -p | grep -P '^\tlibSDL_ttf-2.0.so.0' | sed 's/[^>]*> //')"
local LIBSDL_TTF_32_BIT_FILENAME="$(file -L $LIBSDL_TTF_SO | grep "32-bit" | cut -d: -f1)"
if [ -z "$LIBSDL_TTF_32_BIT_FILENAME" ]; then
MISSING_DEPS="${MISSING_DEPS}libSDL_ttf-2.0_(32-bit) "
fi
# Check for OpenAL; must be 32-bit.
local OPENAL_SO="$(/sbin/ldconfig -p | grep -P '^\tlibopenal.so.1' | sed 's/^[>]*> //')"
local OPENAL_SO_32_BIT_FILENAME="$(file -L $OPENAL_SO | grep "32-bit" | cut -d: -f1)"
if [ -z "$OPENAL_SO_32_BIT_FILENAME" ]; then
MISSING_DEPS="${MISSING_DEPS}libOpenAL_1_(32-bit) "
fi
# Check for libGLU; must be 32-bit.
local LIBGLU_SO="$(/sbin/ldconfig -p | grep -P '^\tlibGLU.so.1' | sed 's/^[>]*> //')"
local LIBGLU_SO_32_BIT_FILENAME="$(file -L $LIBGLU_SO | grep "32-bit" | cut -d: -f1)"
if [ -z "$LIBGLU_SO_32_BIT_FILENAME" ]; then
MISSING_DEPS="${MISSING_DEPS}libGLU_(32-bit) "
fi
# Check for libgtk-x11; must be 32-bit.
local LIBGTK_SO="$(/sbin/ldconfig -p | grep -P '^\tlibgtk-x11-2.0.so.0' | sed 's/^[>]*> //')"
local LIBGTK_SO_32_BIT_FILENAME="$(file -L $LIBGTK_SO | grep "32-bit" | cut -d: -f1)"
if [ -z "$LIBGTK_SO_32_BIT_FILENAME" ]; then
MISSING_DEPS="${MISSING_DEPS}libGTK-x11_(32-bit) "
fi
# Check for libjpeg62; must be 32-bit (required for Stonesense).
local LIBJPEG62_SO="$(/sbin/ldconfig -p | grep -P '^\tlibjpeg.so.62' | sed 's/^[>]*> //')"
local LIBJPEG62_SO_32_BIT_FILENAME="$(file -L $LIBJPEG62_SO | grep "32-bit" | cut -d: -f1)"
if [ -z "$LIBJPEG62_SO_32_BIT_FILENAME" ]; then
MISSING_DEPS="${MISSING_DEPS}libJPEG62_(32-bit) "
fi
# python2 (required for Quickfort)
if [ -z "$(find_python2)" ]; then
MISSING_DEPS="${MISSING_DEPS}python2.x "
fi
# git (required for Quickfort)
if [ -z "$(which git)" ]; then
MISSING_DEPS="${MISSING_DEPS}git "
fi
######
# Warning if MISSING_DEPS_QT5 are missing (if Qt5 libraries are missing).
######
if [ -n "$MISSING_DEPS_QT5" ]; then
echo ""
echo "Your computer is missing the following Qt5 development programs and libraries required for the latest version of Dwarf Therapist:"
echo "\t$MISSING_DEPS_QT5"
echo ""
echo "If you want to use the latest version of Dwarf Therapist, please install these missing libraries."
echo "Continuing with older, Qt4 version of Dwarf Therapist.,,"
USE_QT5=0
else
# We can use Qt5
USE_QT5=1
fi
######
# Error if the $MISSING_DEPS string contains a value (aka there are missing dependencies).
######
if [ -n "$MISSING_DEPS" ]; then
# Clean up after ourself.
# Nothing to do.
exit_with_error "Your computer is missing the following programs or libraries: $MISSING_DEPS. Install them using your distribution's package manager or use --skip-deps to override."
fi
}
check_install_dir_is_empty () {
local LS_OUTPUT="$(ls -A "$INSTALL_DIR")"
# Verify it's empty.
if [ -n "$LS_OUTPUT" ]; then
# Clean up after ourself.
# Nothing to do.
exit_with_error "Cannot install. $INSTALL_DIR must be an empty or nonexistant folder. If this is an existing DF installation, use --upgrade."
fi
}
check_install_dir_contains_df_install () {
if [ ! -d "$INSTALL_DIR/df_linux" ]; then
exit_with_error "Cannot upgrade. $INSTALL_DIR does not contain a df_linux folder."
fi
if [ ! -d "$INSTALL_DIR/LNP" ]; then
exit_with_error "Cannot upgrade. $INSTALL_DIR does not contain an LNP folder."
fi
}
check_ptrace_protection () {
local PTRACE_PROTECTION_FILE="/proc/sys/kernel/yama/ptrace_scope"
# Determine if the kernel has ptrace protection compiled in.
if [ -e $PTRACE_PROTECTION_FILE ]; then
local PTRACE_PROTECTION="$(cat $PTRACE_PROTECTION_FILE)"
else
local PTRACE_PROTECTION="0"
fi
if [ "$PTRACE_PROTECTION" = "1" ]; then
echo ""
echo "Your system has ptrace protection enabled. DwarfTherapist will not operate properly."
echo "After installation has completed, run:"
echo "sudo setcap cap_sys_ptrace=ep $INSTALL_DIR/LNP/utilities/dwarf_therapist/DwarfTherapist"
echo ""
echo "See https://github.com/andrewd18/df-lnp-installer/wiki/Dwarf-Therapist-Cannot-Connect-to-Dwarf-Fortress for more information."
fi
}
checksum_all () {
# Check for file validity.
sha1sum -c sha1sums
# Quit if one or more of the files fails its checksum.
if [ "$?" != "0" ]; then
# Clean up after ourself.
# Nothing to do.
exit_with_error "One or more file failed its checksum. Delete the erroring file from the ./downloads directory and try again."
fi
}
copy_dest_dir_to_install_dir () {
if [ -z "$DEST_DIR" ]; then
exit_with_error "Script failure. DEST_DIR not defined."
fi
if [ -z "$INSTALL_DIR" ]; then
exit_with_error "Script failure. INSTALL_DIR not defined."
fi
echo "Copying files from $DEST_DIR to $INSTALL_DIR."
# Make the $INSTALL_DIR if it doesn't exist.
mkdir -p "$INSTALL_DIR"
# Perform the copy.
cp -r "$DEST_DIR/"* "$INSTALL_DIR"
if [ "$?" != "0" ]; then
# Multi-line equivalent of exit_with_error.
echo ""
echo "Woah, something went wrong while copying $DEST_DIR to $INSTALL_DIR."
echo ""
echo "It's likely that $INSTALL_DIR is now a giant mess. You will need to clean this up manually."
if [ "$UPGRADE" = "1" ]; then
echo "Your working DF install was backed up to $BACKUP_DIR."
fi
exit 1
fi
}
create_backup_dir () {
mkdir -p "$BACKUP_DIR"
}
create_download_dir () {
mkdir -p "$DOWNLOAD_DIR"
}
create_dest_dir () {
mkdir -p "$DEST_DIR"
}
create_df_lnp_desktop_file () {
local LAUNCHER_DIR="$HOME/.local/share/applications"
local LAUNCHER_FILENAME="dwarf_fortress_lazy_newb_pack.desktop"
local LAUNCHER_FULL_PATH="$LAUNCHER_DIR/$LAUNCHER_FILENAME"
local STARTLNP="$INSTALL_DIR/startlnp"
local LOGO="$INSTALL_DIR/DF_LNP_Logo_128.png"
# Delete any existing, out of date launcher.
if [ -e "$LAUNCHER_FULL_PATH" ]; then
rm "$LAUNCHER_FULL_PATH"
fi
# Create the launcher directory if it doesn't exist.
mkdir -p "$LAUNCHER_DIR"
# Install the unedited launcher file.
# Assume the desktop (KDE, Gnome, etc.) follows freedesktop.org guidelines
# and does not require a separate program (like kbuildsyscoca4) to detect a
# new desktop file.
install --mode=644 "$LAUNCHER_FILENAME" "$LAUNCHER_DIR/"
# Quit if extracting failed.
if [ "$?" != "0" ]; then
# Let the install command handle the error cleanup here.
exit_with_error "Installing DF LNP menu item failed."
fi
# Edit the dwarf_fortress_lazy_newb_pack.desktop file and replace the exec and icon lines.
sed -i "s;Exec=path_to_startlnp;Exec=$STARTLNP;g" "$LAUNCHER_FULL_PATH"
sed -i "s;Icon=path_to_icon;Icon=$LOGO;g" "$LAUNCHER_FULL_PATH"
# Quit if extracting failed.
if [ "$?" != "0" ]; then
# Clean up after ourself.
rm "$LAUNCHER_FULL_PATH"
exit_with_error "Updating DF LNP menu item paths failed."
fi
}
delete_backup_dir () {
rm -r "$BACKUP_DIR"
}
delete_download_dir () {
rm -r "$DOWNLOAD_DIR"
}
delete_dest_dir () {
rm -r "$DEST_DIR"
}
download_all () {
if [ -z "$DOWNLOAD_DIR" ]; then
exit_with_error "Script failure. DOWNLOAD_DIR undefined."
fi
# Apps and utilities
download_file "http://www.bay12games.com/dwarves/df_34_11_linux.tar.bz2"
download_file "http://dethware.org/dfhack/download/dfhack-0.34.11-r3-Linux.tar.gz"
download_dffi_file "http://dffd.wimbli.com/download.php?id=7248&f=Utility_Plugins_v0.44-Windows-0.34.11.r3.zip.zip"
download_file "http://df.zweistein.cz/soundsense/soundSense_42_186.zip"
download_file "http://drone.io/bitbucket.org/Dricus/lazy-newbpack/files/target/lazy-newbpack-linux-0.5.3-SNAPSHOT-20130822-1652.tar.bz2"
download_dffi_file "http://dffd.wimbli.com/download.php?id=2182&f=Chromafort.zip"
download_dffi_file "http://dffd.wimbli.com/download.php?id=7905&f=DFAnnouncementFilter.zip"
download_dffi_file "http://dffd.wimbli.com/download.php?id=7889&f=Dwarf+Therapist.pdf"
download_dffi_file "http://dffd.wimbli.com/download.php?id=8185&f=blueprints.zip"
# Graphics packs.
download_dffi_file "http://dffd.wimbli.com/download.php?id=2430&f=Phoebus_34_11v01.zip"
download_dffi_file "http://dffd.wimbli.com/download.php?id=5945&f=CLA_graphic_set_v15-STANDALONE.rar"
download_dffi_file "http://dffd.wimbli.com/download.php?id=7362&f=Ironhand16+upgrade+0.73.4.zip"
download_file "http://www.alexanderocias.com/jollybastion/JollyBastion34-10v5.zip"
download_dffi_file "http://dffd.wimbli.com/download.php?id=7025&f=Mayday+34.11.zip"
download_dffi_file "http://dffd.wimbli.com/download.php?id=7728&f=%5B16x16%5D+Obsidian+%28v.0.8%29.zip"
download_dffi_file "http://dffd.wimbli.com/download.php?id=7867&f=%5B16x16%5D+Spacefox+34.11v1.0.zip"
# Special cases.
# Download Splintermind Attributes HG repo
download_dwarf_therapist
# Download quickfort repo.
download_quickfort
}
download_dffi_file () {
if [ -z "$1" ]; then
exit_with_error "Script failure. download_dffi_file requires a URL argument."
fi
# If the user passed in --override-user-agent, then use a recent Mozilla browser UA string.
# See https://developer.mozilla.org/en-US/docs/Gecko_user_agent_string_reference
# Otherwise fall back to wget default by using a blank value.
if [ "$OVERRIDE_USER_AGENT" = "1" ]; then
local USER_AGENT_STRING="-U Mozilla/5.0"
fi
# -nc is "no clobber" for not overwriting files we already have.
# --directory-prefix drops the files into the download folder.
# --content-disposition asks DFFI for the actual name of the file, not the php link.
# Sadly, simply asking for the filename counts as a "download" so this script will be
# inflating people's DFFI download counts. Oh well.
local WGET_OPTIONS="-nc --directory-prefix=$DOWNLOAD_DIR --content-disposition $USER_AGENT_STRING"
# NOTE: When calling wget, don't wrap $WGET_OPTIONS in quotes; wget doesn't like it.
wget $WGET_OPTIONS "$1"
# Quit if downloading failed.
if [ "$?" != "0" ]; then
# Clean up after ourself.
# Nothing to do; wget will recover.
exit_with_error "Downloading $1 failed. Consider using --override-user-agent."
fi
}
download_file () {
if [ -z "$1" ]; then
exit_with_error "Script failure. download_file requires a URL argument."
fi
# If the user passed in --override-user-agent, then use a recent Mozilla browser UA string.
# See https://developer.mozilla.org/en-US/docs/Gecko_user_agent_string_reference
# Otherwise fall back to wget default by using a blank value.
if [ "$OVERRIDE_USER_AGENT" = "1" ]; then
local USER_AGENT_STRING="-U Mozilla/5.0"
fi
# -nc is "no clobber" for not overwriting files we already have.
# --directory-prefix drops the files into the download folder.
local WGET_OPTIONS="-nc --directory-prefix=$DOWNLOAD_DIR $USER_AGENT_STRING"
# NOTE: When calling wget, don't wrap $WGET_OPTIONS in quotes; wget doesn't like it.
wget $WGET_OPTIONS "$1"
# Quit if downloading failed.
if [ "$?" != "0" ]; then
# Clean up after ourself.
# Nothing to do; wget will recover.
exit_with_error "Downloading $1 failed. Consider using --override-user-agent."
fi
}
download_dwarf_therapist () {
if [ "$USE_QT5" = "0" ]; then
# If the user doesn't want the Qt5 version of DwarfTherapist,
# use the old version from the hg repository
local DWARF_THERAPIST_HG_DIR="$DOWNLOAD_DIR/dwarftherapist"
local SPLINTERMIND_REPO_URL="https://code.google.com/r/splintermind-attributes/"
# WORKAROUND:
# Force a checkout of revision 20.5 because 20.6 uses Qt5.
# Resolves issue #23.
local REV_20_5="4ef8173a7a94"
# Check for and fix the issue I had in 0.2.0 where I used the wrong upstream URL.
# Get the current upstream url. If the directory doesn't exist the var will contain "".
local CURRENT_UPSTREAM_URL="$(hg paths --cwd $DWARF_THERAPIST_HG_DIR | grep default | cut -d" " -f3)"
if [ "$CURRENT_UPSTREAM_URL" != "$SPLINTERMIND_REPO_URL" ]; then
# Inform the user (assuming they're paying attention)
echo "Dwarf Therapist repo is missing or has wrong upstream URL; recloning."
# Bomb the directory, if it even existed in the first place.
if [ -d "$DWARF_THERAPIST_HG_DIR" ]; then
rm -r "$DWARF_THERAPIST_HG_DIR"
fi
# Reclone.
hg clone -r "$REV_20_5" "$SPLINTERMIND_REPO_URL" "$DWARF_THERAPIST_HG_DIR"
else
# URL is good; just get the latest changes.
hg update -r "$REV_20_5" --cwd "$DWARF_THERAPIST_HG_DIR"
fi
else
# If the latest version can be used, use the new git repository
local DWARF_THERAPIST_DIR="$DOWNLOAD_DIR/dwarftherapist"
local SPLINTERMIND_REPO_URL="https://github.com/splintermind/Dwarf-Therapist"
if [ -d "$DWARF_THERAPIST_DIR" ]; then
(cd "$DWARF_THERAPIST_DIR" && git pull)
else
mkdir -p "$DWARF_THERAPIST_DIR"
git clone "$SPLINTERMIND_REPO_URL" "$DWARF_THERAPIST_DIR"
fi
fi
# Quit if downloading failed.
if [ "$?" != "0" ]; then
# Clean up after ourself.
# Nothing to do; that's hg's job.
exit_with_error "Cloning / updating Dwarf Therapist HG repository failed."
fi
}
download_quickfort () {
local QUICKFORT_DIR="$DOWNLOAD_DIR/quickfort"
local QUICKFORT_REPO_URL="https://github.com/joelpt/quickfort.git"
if [ -d "$QUICKFORT_DIR" ]; then
# This needs to be one unified command or else git doesn't know where the working directory is.
( cd "$QUICKFORT_DIR" && git pull )
else
mkdir -p "$QUICKFORT_DIR"
git clone "$QUICKFORT_REPO_URL" "$QUICKFORT_DIR"
fi
}
exit_with_error () {
echo ""
echo "df-lnp-installer.sh: $1 Exiting."
exit 1
}
fix_cla_missing_mouse_png () {
local CLA_FOLDER="$DEST_DIR/LNP/graphics/[16x16] CLA v15"
local VANILLA_GFX_FOLDER="$DEST_DIR/LNP/graphics/[16x16] ASCII Default 0.34.11"
cp "$VANILLA_GFX_FOLDER/data/art/mouse.png" "$CLA_FOLDER/data/art/mouse.png"
if [ "$?" != "0" ]; then
# Clean up after ourself.
if [ -e "$CLA_FOLDER/data/art/mouse.png" ]; then
rm "$CLA_FOLDER/data/art/mouse.png"
fi
exit_with_error "Applying CLA Missing Mouse patch failed."
fi
}
fix_jolly_bastion_missing_graphics_dir () {
local JB_FOLDER="$DEST_DIR/LNP/graphics/[12x12] Jolly Bastion 34.10v5"
mkdir -p "$JB_FOLDER/raw/graphics"
}
fix_jolly_bastion_missing_mouse_png () {
local JB_FOLDER="$DEST_DIR/LNP/graphics/[12x12] Jolly Bastion 34.10v5"
local VANILLA_GFX_FOLDER="$DEST_DIR/LNP/graphics/[16x16] ASCII Default 0.34.11"
cp "$VANILLA_GFX_FOLDER/data/art/mouse.png" "$JB_FOLDER/data/art/mouse.png"
if [ "$?" != "0" ]; then
# Clean up after ourself.
if [ -e "$JB_FOLDER/data/art/mouse.png" ]; then
rm "$JB_FOLDER/data/art/mouse.png"
fi
exit_with_error "Applying Jolly Bastion Missing Mouse patch failed."
fi
}
fix_obsidian_gfx_font_ttf_name () {
local OBSIDIAN_FOLDER="$DEST_DIR/LNP/graphics/[16x16] Obsidian 0.8a"
if [ -e "$OBSIDIAN_FOLDER/data/art/font.TTF" ]; then
mv "$OBSIDIAN_FOLDER/data/art/font.TTF" "$OBSIDIAN_FOLDER/data/art/font.ttf"
fi
}
fix_phoebus_missing_mouse_png () {
# Resolves GitHub issue #6.
local PHOEBUS_FOLDER="$DEST_DIR/LNP/graphics/[16x16] Phoebus 34.11v01"
local VANILLA_GFX_FOLDER="$DEST_DIR/LNP/graphics/[16x16] ASCII Default 0.34.11"
cp "$VANILLA_GFX_FOLDER/data/art/mouse.png" "$PHOEBUS_FOLDER/data/art/mouse.png"
if [ "$?" != "0" ]; then
# Clean up after ourself.
if [ -e "$PHOEBUS_FOLDER/data/art/mouse.png" ]; then
rm "$PHOEBUS_FOLDER/data/art/mouse.png"
fi
exit_with_error "Applying Phoebus Missing Mouse patch failed."
fi
}
fix_phoebus_gfx_font_ttf_name () {
local PHOEBUS_FOLDER="$DEST_DIR/LNP/graphics/[16x16] Phoebus 34.11v01"
if [ -e "$PHOEBUS_FOLDER/data/art/font.TTF" ]; then
mv "$PHOEBUS_FOLDER/data/art/font.TTF" "$PHOEBUS_FOLDER/data/art/font.ttf"
fi
}
fix_soundsense_missing_gamelog () {
# SoundSense comes preconfigured to expect gamelog.txt to be in ../
# however this is not the case for the LNP.
#
# This modifies the configuration.xml file so users don't get an annoying
# pop-up on start looking for gamelog.txt.
#
# NOTE: gamelog.txt doesn't exist until DF creates it, and due to LNP start order,
# DF often starts after soundsense does. So instead of reworking the LNP start order,
# I just manually create a blank one using touch.
local GAMELOG_FILE_TMP="$DEST_DIR/df_linux/gamelog.txt"
local GAMELOG_FILE_INSTALLED="$INSTALL_DIR/df_linux/gamelog.txt"
# Create the gamelog.txt file.
touch "$GAMELOG_FILE_TMP"
# Get the XML configuration file.
local SS_CONFIG_FILE="$DEST_DIR/LNP/utilities/soundsense/configuration.xml"
local FIND_LINE_WITH="\<gamelog"
local TEXT_TO_REPLACE="path=\"../gamelog.txt\""
local REPLACE_WITH="path=\"$GAMELOG_FILE_INSTALLED\""
# substitute "foo" with "bar" ONLY for lines which contain "baz"
# sed '/baz/s/foo/bar/g'
# NOTE: Like in ask_for_preferred_install_dir, use custom ; delimeter so as not to
# screw up sed with file paths.
sed -ibak "/$FIND_LINE_WITH/s;$TEXT_TO_REPLACE;$REPLACE_WITH;g" "$SS_CONFIG_FILE"
# Quit if replacement failed.
if [ "$?" != "0" ]; then
# Clean up after ourself.
# TODO: Install a clean configuration.xml file from the downloads folder?
exit_with_error "Modifying soundsense configuration.xml file failed."
fi
}
fix_vanilla_df_openal_issue () {
# See http://dwarffortresswiki.org/index.php/DF2012:Installation
# The filename variables will be empty strings if no file exists.
# Otherwise they will contain the filename of the associated 32-bit library.
local OPENAL_SO="$(/sbin/ldconfig -p | grep -P '^\tlibopenal.so.1')"
local OPENAL_SO_32_BIT_FILENAME="$(file -L $OPENAL_SO | grep "32-bit" | cut -d: -f1)"
local LIBSNDFILE_SO="$(/sbin/ldconfig -p | grep -P '^\tlibsndfile.so.1')"
local LIBSNDFILE_SO_32_BIT_FILENAME="$(file -L $LIBSNDFILE_SO | grep "32-bit" | cut -d: -f1)"
local VANILLA_DF_LIBS_DIR="$DEST_DIR/df_linux/libs"
# If the file given by the filename string exists, link it.
if [ -e "$OPENAL_SO_32_BIT_FILENAME" ]; then
ln -s "$OPENAL_SO_32_BIT_FILENAME" "$VANILLA_DF_LIBS_DIR/libopenal.so"
fi
if [ -e "$LIBSNDFILE_SO_32_BIT_FILENAME" ]; then
ln -s "$LIBSNDFILE_SO_32_BIT_FILENAME" "$VANILLA_DF_LIBS_DIR/libsndfile.so"
fi
}
fix_vanilla_df_ancient_libstdcpp () {
# There are cases, particularly on newer distros (see Arch Linux), where libstdc++ 3.4 isn't available.
# This function simply renames the static libstdc++ included with DF to .old,
# thus forcing DF to use the system library.
local VANILLA_DF_LIBS_DIR="$DEST_DIR/df_linux/libs"
# If the file given by the filename string exists and is a normal file (not a symlink), rename it.
if [ -f "$VANILLA_DF_LIBS_DIR/libstdc++.so" ]; then
mv "$VANILLA_DF_LIBS_DIR/libstdc++.so.6" "$VANILLA_DF_LIBS_DIR/libstdc++.so.6.old"
fi
}
fix_vanilla_df_lnp_settings_not_applied_by_default () {
# The df-lnp-installer will set up the appropriate "[16x16] ASCII Default" folder
# in $INSTALL_DIR/LNP/graphics/ but the LNP settings don't get applied to the df_linux/data folder
# until the user clicks LNP -> Graphics Tab -> ASCII Default -> Install Graphics.
#
# This method "fixes" that by applying the expected LNP settings to the df_linux folder right from the get-go.
local LNP_PATCH_DIR="./patches/ascii_default_gfx"
local DF_FOLDER="$DEST_DIR/df_linux"
patch -d "$DF_FOLDER/data/init/" < "$LNP_PATCH_DIR/init_lnp_defaults.patch"
patch -d "$DF_FOLDER/data/init/" < "$LNP_PATCH_DIR/dinit_lnp_defaults.patch"
}
install_all () {
if [ -z "$DEST_DIR" ]; then
exit_with_error "Script failure. DEST_DIR undefined."
fi
# Install in dependency-fulfilling order.
install_lnp
install_lnp_yaml
install_vanilla_df
install_dfhack
install_falconne_dfhack_plugins
install_phoebus_gfx_pack
install_cla_graphics_pack
install_ironhand_gfx_pack
install_mayday_gfx_pack
install_obsidian_gfx_pack
install_spacefox_gfx_pack
install_vanilla_df_gfx_pack
install_jolly_bastion_gfx_pack
install_soundsense_app
build_dwarf_therapist
install_dwarf_therapist
install_quickfort
install_chromafort
install_df_announcement_filter
# Must come after install_vanilla_df
install_lnp_embark_profiles
install_df_lnp_logo
}
install_chromafort () {
local CHROMAFORT_ZIP="$DOWNLOAD_DIR/Chromafort.zip"
local CHROMAFORT_TEMP_FOLDER="./chromafort_unzip"
mkdir -p "$CHROMAFORT_TEMP_FOLDER"
unzip -d "$CHROMAFORT_TEMP_FOLDER" "$CHROMAFORT_ZIP"
# Quit if extracting failed.
if [ "$?" != "0" ]; then
# Clean up after ourself.
if [ -e "$CHROMAFORT_TEMP_FOLDER" ]; then
rm -r "$CHROMAFORT_TEMP_FOLDER"
fi
exit_with_error "Unzipping Chromafort failed."
fi
local UTILITIES_FOLDER="$DEST_DIR/LNP/utilities"
mkdir -p "$UTILITIES_FOLDER/chromafort"
# Copy program and all documentation.
cp "$CHROMAFORT_TEMP_FOLDER/Chromafort/"* "$UTILITIES_FOLDER/chromafort/"
# Quit if copying failed.
if [ "$?" != "0" ]; then
exit_with_error "Installing Chromafort failed."
fi
rm -r "$CHROMAFORT_TEMP_FOLDER"
}
install_cla_graphics_pack () {
local GFX_PACK="$DOWNLOAD_DIR/CLA_graphic_set_v15-STANDALONE.rar"
local GFX_PREFIX="CLA"
local INSTALL_GFX_DIR="$DEST_DIR/LNP/graphics/[16x16] CLA v15"
local LNP_PATCH_DIR="./patches/cla_gfx"
install_gfx_pack "$GFX_PACK" "$GFX_PREFIX" "$INSTALL_GFX_DIR" "$LNP_PATCH_DIR"
}
install_df_announcement_filter () {
local DFAF_ZIP="$DOWNLOAD_DIR/DFAnnouncementFilter.zip"
local DFAF_TEMP_FOLDER="./df_announcement_filter_unzip"
mkdir -p "$DFAF_TEMP_FOLDER"
unzip -d "$DFAF_TEMP_FOLDER" "$DFAF_ZIP"
# Quit if extracting failed.
if [ "$?" != "0" ]; then
# Clean up after ourself.
if [ -e "$DFAF_TEMP_FOLDER" ]; then
rm -r "$DFAF_TEMP_FOLDER"
fi
exit_with_error "Unzipping DF Announcement Filter failed."
fi
local UTILITIES_FOLDER="$DEST_DIR/LNP/utilities"
mkdir -p "$UTILITIES_FOLDER/df_announcement_filter"
# Copy program and all documentation.
cp "$DFAF_TEMP_FOLDER/"* "$UTILITIES_FOLDER/df_announcement_filter/"
# Quit if copying failed.
if [ "$?" != "0" ]; then
exit_with_error "Installing DF Announcement Filter failed."
fi
rm -r "$DFAF_TEMP_FOLDER"
}
install_df_lnp_logo () {
local LOGO="./DF_LNP_Logo_128.png"
install --mode=644 "$LOGO" "$DEST_DIR/"
# Quit if extracting failed.
if [ "$?" != "0" ]; then
# Let the install command handle the error cleanup here.
exit_with_error "Installing DF LNP Logo failed."
fi
}
install_dfhack () {
local DF_HACK_TARBALL="$DOWNLOAD_DIR/dfhack-0.34.11-r3-Linux.tar.gz"
# Extract to the installation/df_linux directory.
tar --directory "$DEST_DIR/df_linux" -xzvf "$DF_HACK_TARBALL"
# Quit if extracting failed.
if [ "$?" != "0" ]; then
# Clean up after ourself.
# Remove folders.
if [ -d "$DEST_DIR/df_linux/hack" ]; then
rm -r "$DEST_DIR/df_linux/hack"
fi
if [ -d "$DEST_DIR/df_linux/stonesense" ]; then
rm -r "$DEST_DIR/df_linux/stonesense"
fi
# Remove executables.
if [ -e "$DEST_DIR/df_linux/dfhack" ]; then
rm "$DEST_DIR/df_linux/dfhack"
fi
if [ -e "$DEST_DIR/df_linux/dfhack-run" ]; then
rm "$DEST_DIR/df_linux/dfhack-run"
fi
if [ -e "$DEST_DIR/df_linux/dfhack-init.example" ]; then
rm "$DEST_DIR/df_linux/dfhack-init.example"
fi