-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup
executable file
·1366 lines (1356 loc) · 76.8 KB
/
Setup
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
# vim: filetype=sh:syntax=sh:tabstop=2:shiftwidth=2:expandtab
#
###### System properties (locked/read-only)
# script-source: https://raw.githubusercontent.com/rarioj/sdc/main/Setup
# script-version: 1.0.23.10d
# dosbox-variants: dosbox-x dosbox-staging dosbox
# library-file: Library.txt
# program-file: Program.txt
# markdown-file: README.md
# hypertext-file: index.html
#
###### Library properties (overridable in library configuration file)
## library-name: Library Name
## library-source: [url]
## library-version: x.y.z
# backup-directory: .backup
# script-export-file: 1
# script-include-text: -1
#
###### Program properties (overridable in program configuration file)
# asset-verify: 1
# thumbnail-file: Thumbnail.png
# thumbnail-source: Assets/coverart.jpg
# thumbnail-width: 250
#
###### Application properties (overridable in library or program configuration file)
# montage-file: Montage.png
# montage-grid: 5
# montage-width: 1000
#
###### DOSBox variant compatibility (overridable in library or program configuration file)
### 🟩 Fully supported
### 🟨 Runnable with issues
### 🟥 Unsupported, unplayable, or broken
### ⬜ Untested
# dosbox: [DOSBox](https://www.dosbox.com/) 🟩
# dosbox: [DOSBox Staging](https://dosbox-staging.github.io/) 🟩
# dosbox: [DOSBox-X](https://dosbox-x.com/) 🟩
#
# name: Simple DOSBox Client
# name: SDC
# info: A lightweight DOSBox client in one shell script
# tag: Script Version = ###script-version###
# tag: Type = Shell Script
# tag: Shell = POSIX Compliant
# tag: Interface = CLI
# tag: License = MIT
#
# text: ## What is *Simple DOSBox Client*?
# text: Ever want to relive your past gaming experience, but your modern computer can no longer run it?
# text:
# text: - *The good news is* — there is *DOSBox*. DOSBox is a free and open-source emulator which runs software for DOS-compatible disk operating systems.
# text: - *The not-so-good thing is* — setting up programs in DOSBox is not that simple — you would be tinkering with hardware configuration, downloading floppy or CD-ROM images, mounting them, installing the program, executing DOS commands, and so on.
# text:
# text: **Simple DOSBox Client (SDC)** aims to simplify these processes and, at the same time, manage your collection of DOS programs. All the actions needed for setting up a program in DOSBox, from downloading the asset files to finally running the program, can be organised into a single configuration file. You can compile all the configuration files into a collection of programs (library). **SDC** combines several utilities into a single shell script (the `Setup` script). It switches functionality based on the script's filename.
# text:
# text: ### `🎛️ Setup + 📚 Library.txt`
# text: The `Setup` script is the only script you will ever need to start building your retro gaming system. It will copy itself into other script files according to their intended roles. It pairs up with the `Library.txt` configuration file in the root directory of your library to deliver all the program configuration files; generate all program, category, and library documents; and build the directory structure of your library.
# text:
# text: ### `🚀 Launch + 📓 Program.txt`
# text: The `Launch` script and the `Program.txt` configuration file are the central core of a program. They are responsible for downloading assets, integrity checking, executing custom code, restoring from or loading a snapshot, generating a montage image of screen captures (located in the `System/capture` directory), and running the program. The `Launch` script will copy itself into other script files after the first execution:
# text:
# text: - **`🪲 Debug`** — It launches DOSBox without running the `[autoexec]` section of the `Program.txt` configuration file. The debug console is a clean-slate DOSBox terminal, so manually mount hard-disk drives and floppy or CD-ROM images as needed.
# text: - **`📷 Snapshot`** — It saves the entire content of the directory `System/drive` as a compressed file. Some programs require a snapshot of another program (e.g. certain games only run on *Windows 3.1x*).
# text: - **`🗑️ Uninstall`** — It uninstalls the program by removing the generated `System` directory, `Debug` script, `Snapshot` script, and itself.
# text:
# text: ## Host Requirements
# text: ### DOSBox Variant
# text: You require at least one variant (flavour) of DOSBox as the backend. Well-known **DOSBox** forks are **DOSBox Staging** and **DOSBox-X**. The script supports these three variants (the original and the two forks).
# text:
# text: - `dosbox` 📎 ┃ [Homepage](https://www.dosbox.com/) ┃ [Wikipedia](https://en.wikipedia.org/wiki/DOSBox) ┃ [Source](https://sourceforge.net/projects/dosbox/) ┃ [Homebrew](https://formulae.brew.sh/formula/dosbox)
# text: - **DOSBox** is the de facto standard for running DOS games. It was first released in 2002 when DOS technology was becoming obsolete.
# text: - `dosbox-staging` 📎 ┃ [Homepage](https://dosbox-staging.github.io/) ┃ [Source](https://github.com/dosbox-staging/dosbox-staging) ┃ [Homebrew](https://formulae.brew.sh/formula/dosbox-staging) ┃ [Snap](https://snapcraft.io/install/dosbox-staging/ubuntu)
# text: - **DOSBox Staging** aims to be a modern continuation of DOSBox, with better coding practices and more advanced features.
# text: - `dosbox-x` 📎 ┃ [Homepage](https://dosbox-x.com/) ┃ [Source](https://github.com/joncampbell123/dosbox-x) ┃ [Homebrew](https://formulae.brew.sh/formula/dosbox-x) ┃ [Snap](https://snapcraft.io/install/dosbox-x/ubuntu)
# text: - **DOSBox-X** aims to be compatible with all pre-2000 DOS and Windows 9x-based hardware scenarios. It offers a screen capture functionality that works well with the montage image generation feature (requires **ImageMagick**).
# text:
# text: If you have multiple DOSBox variants in the system, you can set the `SDC_DOSBOX` environment variable to enforce which DOSBox variant to use.
# text: ```shell
# text: # shell profile
# text: SDC_DOSBOX="dosbox-staging"
# text: export SDC_DOSBOX
# text:
# text: # direct invocation
# text: SDC_DOSBOX="dosbox-x" ./Launch
# text: ```
# text:
# text: ### Recommended Tools (Optional)
# text: - `imagemagick` 📎 ┃ [Homepage](https://imagemagick.org/) ┃ [Wikipedia](https://en.wikipedia.org/wiki/ImageMagick) ┃ [Source](https://github.com/imagemagick/imagemagick) ┃ [Homebrew](https://formulae.brew.sh/formula/imagemagick)
# text: - **ImageMagick** provides `mogrify` and `montage` commands. If installed, it will automatically generate a montage for all screen captures you made during the program run.
# text: - `mdcat` 📎 ┃ [Source](https://github.com/swsnr/mdcat) ┃ [Homebrew](https://formulae.brew.sh/formula/mdcat)
# text: - **`mdcat`** renders markdown format on your terminal. Hence, it works best with a terminal emulator that supports graphics rendering (such as [iTerm2](https://iterm2.com/), [Kitty](https://sw.kovidgoyal.net/kitty/), or [WezTerm](https://wezfurlong.org/wezterm/)).
# text: - `pandoc` 📎 ┃ [Homepage](https://pandoc.org/) ┃ [Wikipedia](https://en.wikipedia.org/wiki/Pandoc) ┃ [Source](https://hackage.haskell.org/package/pandoc) ┃ [Homebrew](https://formulae.brew.sh/formula/pandoc)
# text: - **Pandoc** allows converting markdown documents into HTML. You can browse the library/collection from a web browser.
# text: - `pngquant` 📎 ┃ [Homepage](https://pngquant.org/) ┃ [Source](https://github.com/kornelski/pngquant) ┃ [Homebrew](https://formulae.brew.sh/formula/pngquant)
# text: - The **`pngquant`** tool is a command-line utility and a library for the lossy compression of PNG images.
# section: DOSBox wrapper functions
{
sdc__dosbox__debug() {
"${sdc__dosbox__command}" -noautoexec -conf ./dosbox.conf >>./dosbox.logs 2>&1
}
sdc__dosbox__config() {
touch "./System/variant/dosbox.env"
if [ -f "${sdc__program__file}" ]; then
"${sdc__dosbox__command}" -noautoexec -exit -c "config -writeconf System/dosbox.conf" -c "exit" -conf "${sdc__program__file}" >>./System/dosbox.logs 2>&1
else
"${sdc__dosbox__command}" -noautoexec -exit -c "config -writeconf System/dosbox.conf" -c "exit" >>./System/dosbox.logs 2>&1
fi
}
sdc__dosbox__launch() {
"${sdc__dosbox__command}" -conf ./dosbox.conf >>./dosbox.logs 2>&1
}
sdc__dosbox__version() {
"${sdc__dosbox__command}" -version
}
}
# section: DOSBox Staging wrapper functions
{
sdc__dosbox_staging__debug() {
sdc__dosbox__debug
}
sdc__dosbox_staging__config() {
touch "./System/variant/staging.env"
if [ -f "${sdc__program__file}" ]; then
"${sdc__dosbox__command}" -noautoexec -exit -c "config -wcp System/dosbox.conf" -conf "${sdc__program__file}" >>./System/dosbox.logs 2>&1
else
"${sdc__dosbox__command}" -noautoexec -exit -c "config -wcp System/dosbox.conf" >>./System/dosbox.logs 2>&1
fi
}
sdc__dosbox_staging__launch() {
sdc__dosbox__launch
}
sdc__dosbox_staging__version() {
"${sdc__dosbox__command}" --version
}
}
# section: DOSBox-X wrapper functions
{
sdc__dosbox_x__debug() {
"${sdc__dosbox__command}" -noautoexec -set title="[ ${sdc__application__name} ]" -conf ./dosbox.conf >>./dosbox.logs 2>&1
}
sdc__dosbox_x__config() {
touch "./System/variant/x.env"
if [ -f "${sdc__program__file}" ]; then
"${sdc__dosbox__command}" -noautoexec -silent -exit -nolog -c "config -all -wcp ./System/dosbox.conf" -conf "${sdc__program__file}" >>./System/dosbox.logs 2>&1
else
"${sdc__dosbox__command}" -noautoexec -silent -exit -nolog -c "config -all -wcp ./System/dosbox.conf" >>./System/dosbox.logs 2>&1
fi
}
sdc__dosbox_x__launch() {
"${sdc__dosbox__command}" -set title="${sdc__application__name}" -conf ./dosbox.conf >>./dosbox.logs 2>&1
}
sdc__dosbox_x__version() {
"${sdc__dosbox__command}" -v
}
}
# section: Message printing functions
{
sdc__message__plain() {
printf '%s\n' "${*}"
}
sdc__message__action() {
printf '%s\n' "[#] ${*}"
}
sdc__message__info() {
printf '%s\n' "[i] ${*}"
}
sdc__message__item() {
printf '%s\n' " ┃ ${*}"
}
sdc__message__prompt() {
printf '%s\n' "[?] ${*} [Y/*]?"
printf '%s ' "[!] Press Y/y and ENTER to confirm:"
read -r __key </dev/tty
sdc__prompt__reply="$(echo "${__key}" | head -c 1 | tr '[:upper:]' '[:lower:]')"
unset __key
}
sdc__message__error() {
printf '%s\n' "[E] ${*}" >&2
printf '%s ' "[!] Press ENTER key to quit" >&2
read -r __key </dev/tty
unset __key
exit 1
}
}
# section: Configuration parsing functions
{
sdc__parse__key_value() {
if [ -z "${3}" ] || [ ! -f "${3}" ]; then
sdc__message__error "Missing third argument: configuration file <sdc__parse__key_value>"
fi
if [ -n "${1}" ] && [ -n "${2}" ]; then
__config="$(grep "^# ${1}: " "${3}" | sed "s/^# ${1}: //g")"
if [ -n "${4}" ] && [ -f "${4}" ] && [ "${4}" != "${3}" ]; then
__override="$(grep "^# ${1}: " "${4}" | sed "s/^# ${1}: //g")"
if [ -n "${__override}" ]; then
__config="${__override}"
fi
fi
__tmpfile="$(mktemp "${sdc__script__tmpdir}/sdc.XXXXXXXX")" || sdc__message__error "Temporary file creation failed <sdc__parse__key_value>"
echo "${__config}" >"${__tmpfile}"
while IFS= read -r __index; do
__key="${__index%% = *}"
__value="${__index#*= }"
if [ "$(command -v "sdc__callback__${2}")" = "sdc__callback__${2}" ]; then
if [ "${__key}" = "${__value}" ]; then
"sdc__callback__${2}" "${__key}"
else
"sdc__callback__${2}" "${__key}" "${__value}"
fi
else
sdc__message__error "Unimplemented callback function: sdc__callback__${2} <sdc__parse__key_value>"
fi
done <"${__tmpfile}"
fi
unset __config __override __tmpfile __index __key __value
}
sdc__parse__value() {
if [ -z "${3}" ] || [ ! -f "${3}" ]; then
sdc__message__error "Missing third argument: configuration file <sdc__parse__value>"
fi
if [ -n "${1}" ] && [ -n "${2}" ]; then
__config="$(grep "^# ${1}: " "${3}" | sed "s/^# ${1}: //g")"
if [ -n "${4}" ] && [ -f "${4}" ] && [ "${4}" != "${3}" ]; then
__override="$(grep "^# ${1}: " "${4}" | sed "s/^# ${1}: //g")"
if [ -n "${__override}" ]; then
__config="${__override}"
fi
fi
__tmpfile="$(mktemp "${sdc__script__tmpdir}/sdc.XXXXXXXX")" || sdc__message__error "Temporary file creation failed <sdc__parse__value>"
echo "${__config}" >"${__tmpfile}"
while IFS= read -r __index; do
if [ "$(command -v "sdc__callback__${2}")" = "sdc__callback__${2}" ]; then
"sdc__callback__${2}" "${__index}"
else
sdc__message__error "Unimplemented callback function: sdc__callback__${2} <sdc__parse__value>"
fi
done <"${__tmpfile}"
fi
unset __config __override __tmpfile __index
}
sdc__parse__text() {
if [ -z "${3}" ] || [ ! -f "${3}" ]; then
sdc__message__error "Missing third argument: configuration file <sdc__parse__text>"
fi
if [ -n "${1}" ] && [ -n "${2}" ]; then
__config="$(grep "^# ${1}:" "${3}" | sed "s/^# ${1}: //g;s/^# ${1}://g")"
if [ -n "${4}" ] && [ -f "${4}" ] && [ "${4}" != "${3}" ]; then
__override="$(grep "^# ${1}:" "${4}" | sed "s/^# ${1}: //g;s/^# ${1}://g")"
if [ -n "${__override}" ]; then
__config="${__override}"
fi
fi
if [ "$(command -v "sdc__callback__${2}")" = "sdc__callback__${2}" ]; then
"sdc__callback__${2}" "${__config}"
else
sdc__message__error "Unimplemented callback function: sdc__callback__${2} <sdc__parse__text>"
fi
fi
unset __config __override
}
}
# section: Configuration callback functions
{
sdc__callback__application() {
if [ -n "${1}" ] && [ "${sdc__application__slug}" = "${sdc__application__name}" ]; then
sdc__application__name="${1}"
sdc__application__slug=""
fi
}
sdc__callback__print() {
sdc__message__plain "${*}"
}
sdc__callback__reset_file() {
if [ -n "${1}" ]; then
__dirpath="$(dirname "${1}")"
if [ ! -d "${__dirpath}" ]; then
mkdir -p "${__dirpath}"
fi
if [ -f "${1}" ]; then
sdc__utility__remove_file "${1}"
fi
fi
unset __dirpath
}
sdc__callback__append_file() {
if [ -n "${1}" ]; then
if [ ! -f "${1}" ]; then
sdc__message__item "${1#./} [FILE]"
touch "${1}"
fi
if [ -n "${2}" ]; then
printf '%s\n' "${2}" >>"${1}"
else
printf '%s\n' "" >>"${1}"
fi
fi
}
sdc__callback__symbolic_link() {
if [ -n "${1}" ]; then
__dirpath="$(dirname "${1}")"
sdc__message__item "${1#./} [LINK]"
if [ ! -d "${__dirpath}" ]; then
mkdir -p "${__dirpath}"
fi
rm -f "${1}"
(
cd "${__dirpath}" || sdc__message__error "Inaccessible directory: ${__dirpath} <sdc__callback__symbolic_link>"
ln -sf "${2}" "$(basename "${1}")"
)
fi
unset __dirpath
}
sdc__callback__base64_decode() {
if [ -n "${1}" ]; then
__dirpath="$(dirname "${1}")"
if [ ! -d "${__dirpath}" ]; then
mkdir -p "${__dirpath}"
fi
if [ -f "${1}" ]; then
rm -f "${1}"
fi
if [ -n "${2}" ]; then
sdc__message__item "${1#./} [DECODE]"
printf '%s' "${2}" | base64 -d >"${1}"
fi
fi
unset __dirpath
}
sdc__callback__download_file() {
__download="n"
if [ ! -d "Assets" ]; then
mkdir "Assets"
fi
if [ -n "${1}" ] && [ -n "${2}" ] && [ ! -f "Assets/${1}" ]; then
if [ -n "${sdc__download__match}" ]; then
if [ "${sdc__download__match}" = "Assets/${1}" ] || [ "${sdc__download__match}" = "all" ]; then
__download="y"
fi
fi
if [ "${__download}" = "y" ]; then
sdc__message__item "Fetching Assets/${1} with curl ◄ ${2}"
if ! curl "${2}" -o "Assets/${1}" --progress-bar -f -L -S --retry 50 --retry-max-time 0 -C -; then
rm -f "Assets/${1}"
sdc__message__item "Fetching Assets/${1} with wget ◄ ${2}"
if ! wget "${2}" -O "Assets/${1}" --show-progress -t 50 -c; then
rm -f "Assets/${1}"
sdc__message__error "Failed to download asset file: ${2} <sdc__callback__download_file>"
fi
fi
fi
fi
unset __download
}
sdc__callback__verify_file() {
__verify="n"
if [ -n "${1}" ] && [ -n "${2}" ]; then
if [ -n "${sdc__download__match}" ]; then
if [ "${sdc__download__match}" = "Assets/${1}" ] || [ "${sdc__download__match}" = "all" ]; then
__verify="y"
fi
fi
if [ "${__verify}" = "y" ]; then
if [ -f "Assets/${1}" ]; then
sdc__message__item "Verifying ${1}"
__source="$(sdc__utility__sha256_checksum "Assets/${1}" | head -c 64 | tr '[:upper:]' '[:lower:]')"
__target="$(echo "${2}" | head -c 64 | tr '[:upper:]' '[:lower:]')"
if [ "${__source}" != "${__target}" ]; then
sdc__message__error "Checksum failed: Assets/${1} (${__source} != ${__target}) <sdc__callback__verify_file>"
fi
else
sdc__message__error "Unable to verify non-existant file: Assets/${1} <sdc__callback__verify_file>"
fi
fi
fi
unset __verify __source __target
}
sdc__callback__execute_code() {
if [ -n "${1}" ]; then
sdc__message__plain ""
sdc__message__plain "${1}"
sdc__message__plain ""
sdc__message__prompt "Execute the above command"
if echo "${sdc__prompt__reply}" | grep -iq "^y"; then
sdc__message__info "Executing command"
if ! sh -c "${1}"; then
sdc__utility__uninstall_program
sdc__message__error "Command execution failed: ${1} <sdc__callback__execute_code>"
fi
sdc__message__info "Command executed"
else
sdc__message__plain ""
sdc__utility__uninstall_program
sdc__message__info "Command cancelled"
exit 1
fi
unset sdc__prompt__reply
fi
}
sdc__callback__require_snapshot() {
if [ -n "${1}" ]; then
__file="${1}/Snapshot-${sdc__dosbox__variant}.tgz"
if [ -f "${__file}" ]; then
tar -zxvf "${__file}" --directory "System/drive"
else
sdc__utility__uninstall_program
sdc__message__error "Missing snapshot requirement: ${__file} <sdc__callback__require_snapshot>"
fi
fi
unset __file
}
sdc__callback__markdown_name() {
if [ -n "${1}" ] && [ "${1}" != "${sdc__application__name}" ]; then
if [ -n "${2}" ]; then
printf '%s' "「**${1}** (${2})」"
else
printf '%s' "「**${1}**」"
fi
fi
}
sdc__callback__markdown_divider() {
if [ -n "${1}" ]; then
if [ -n "${2}" ]; then
printf '%s' "┃ **${1}** ‣ ${2} "
else
printf '%s' "┃ **${1}** "
fi
fi
}
sdc__callback__markdown_quote() {
if [ -n "${1}" ]; then
if [ -n "${2}" ]; then
printf '%s\n' "> ❝ ${2} ❞ — *${1}*"
else
printf '%s\n' "> ❝ ${1} ❞"
fi
printf '%s\n' ">"
fi
}
sdc__callback__markdown_break() {
if [ -n "${1}" ]; then
if [ -n "${2}" ]; then
printf '%s' "<br>❝ ${2} ❞ — *${1}*<br>"
else
printf '%s' "<br>❝ ${1} ❞<br>"
fi
fi
}
}
# section: Utility/helper functions
{
sdc__utility__backup_file() {
if [ -n "${1}" ] && [ -f "${1}" ]; then
__dirpath="$(dirname "${1}")"
if [ -L "${__dirpath}" ]; then
sdc__message__item "${__dirpath#./} [LINK]"
printf '%s\n' "# link: ${__dirpath#./} = $(sdc__utility__relative_path "${__dirpath}")" >>"${sdc__backup__file}"
else
sdc__message__item "${1#./} [FILE]"
printf '%s\n' "#" >>"${sdc__backup__file}"
while IFS= read -r __index; do
if [ -n "${__index}" ]; then
printf '%s\n' "# file: ${1#./} = ${__index}" >>"${sdc__backup__file}"
else
printf '%s\n' "# file: ${1#./}" >>"${sdc__backup__file}"
fi
done <"${1}"
printf '%s\n' "#" >>"${sdc__backup__file}"
fi
fi
unset __dirpath __index
}
sdc__utility__copy_script() {
if [ -n "${1}" ] && [ -f "${1}" ]; then
__dirpath="$(dirname "${1}")"
if [ ! -f "${__dirpath}/${sdc__script__file}" ]; then
if [ -f "${__dirpath}/Launch" ]; then
rm -f "${__dirpath}/Launch"
sdc__message__item "${__dirpath#./}/Launch"
cp "${sdc__script__file}" "${__dirpath}/Launch"
fi
if [ -f "${__dirpath}/Debug" ]; then
rm -f "${__dirpath}/Debug"
sdc__message__item "${__dirpath#./}/Debug"
cp "${sdc__script__file}" "${__dirpath}/Debug"
fi
if [ -f "${__dirpath}/Snapshot" ]; then
rm -f "${__dirpath}/Snapshot"
sdc__message__item "${__dirpath#./}/Snapshot"
cp "${sdc__script__file}" "${__dirpath}/Snapshot"
fi
if [ -f "${__dirpath}/Uninstall" ]; then
rm -f "${__dirpath}/Uninstall"
sdc__message__item "${__dirpath#./}/Uninstall"
cp "${sdc__script__file}" "${__dirpath}/Uninstall"
fi
if [ ! -f "${__dirpath}/Launch" ]; then
sdc__message__item "${__dirpath#./}/Launch"
cp "${sdc__script__file}" "${__dirpath}/Launch"
fi
fi
fi
unset __dirpath
}
sdc__utility__remove_file() {
if [ -n "${1}" ] && [ -f "${1}" ]; then
sdc__message__item "${1#./} [DELETE]"
rm -f "${1}"
fi
}
sdc__utility__program_document() {
if [ -n "${1}" ] && [ -f "${1}" ]; then
__curpath="$(pwd)"
__dirpath="$(dirname "${1}")"
__verify="$(sdc__parse__value asset-verify print "Setup" "${1}")"
sdc__download__match=""
if [ "${sdc__download__asset}" = "cover" ] && [ -x "$(command -v mogrify)" ] && [ -x "$(command -v montage)" ]; then
sdc__download__match="$(sdc__parse__value thumbnail-source print "Setup" "${1}")"
elif [ "${sdc__download__asset}" = "all" ]; then
sdc__download__match="all"
fi
sdc__parse__value name application "${1}"
sdc__application__slug="${sdc__application__name}"
if [ -z "${sdc__program__count}" ]; then
sdc__program__count=0
fi
sdc__program__list="${sdc__program__list}┃ [${sdc__application__name}]($(sdc__utility__urlencode_string "${__dirpath}/${sdc__markdown__file}")) "
sdc__program__count=$((sdc__program__count + 1))
cd "${__dirpath}" || sdc__message__error "Inaccessible directory: ${__dirpath} <sdc__utility__program_document>"
sdc__message__action "Creating ${sdc__application__name} document"
sdc__parse__key_value asset download_file "${sdc__program__file}"
if [ "${__verify}" = "1" ]; then
sdc__parse__key_value check verify_file "${sdc__program__file}"
fi
sdc__utility__application_document
sdc__utility__convert_html
cd "${__curpath}" || sdc__message__error "Inaccessible directory: ${__curpath} <sdc__utility__program_document>"
unset sdc__download__match
__tfile="$(sdc__parse__value thumbnail-file print "Setup" "${1}")"
if [ -z "${sdc__thumbnail__count}" ]; then
sdc__thumbnail__count=0
fi
if [ -f "${__dirpath}/${__tfile}" ]; then
sdc__thumbnail__list="${sdc__thumbnail__list} \"${__dirpath}/${__tfile}\""
sdc__thumbnail__count=$((sdc__thumbnail__count + 1))
fi
fi
unset __curpath __dirpath __verify __tfile
}
sdc__utility__application_document() {
__config="${sdc__script__file}"
if [ "${sdc__script__file}" = "Setup" ]; then
__override="${sdc__library__file}"
else
__override="${sdc__program__file}"
fi
if [ -f "${sdc__markdown__file}" ]; then
rm -f "${sdc__markdown__file}"
fi
__tfile="$(sdc__parse__value thumbnail-file print "${__config}" "${__override}")"
__tsource="$(sdc__parse__value thumbnail-source print "${__config}" "${__override}")"
if [ -f "${__tfile}" ]; then
printf '%s\n\n' "![](${__tfile} \"application-thumbnail\")" >>"${sdc__markdown__file}"
elif [ -f "${__tsource}" ] && [ -x "$(command -v montage)" ]; then
__twidth="$(sdc__parse__value thumbnail-width print "${__config}" "${__override}")"
montage -background none -shadow -geometry +5+5 -resize "${__twidth}" "${__tsource}" "${__tfile}"
if [ -x "$(command -v pngquant)" ]; then
pngquant "${__tfile}" --output sdc-tmp.png && mv sdc-tmp.png "${__tfile}"
fi
if [ -f "${__tfile}" ]; then
printf '%s\n\n' "![](${__tfile} \"application-thumbnail\")" >>"${sdc__markdown__file}"
fi
fi
printf '%s\n\n' "# ${sdc__application__name}" >>"${sdc__markdown__file}"
__alias="$(sdc__parse__key_value name markdown_name "${__config}" "${__override}")"
if [ -n "${__alias}" ]; then
printf '%s\n\n' "${__alias}" >>"${sdc__markdown__file}"
fi
__info="$(sdc__parse__key_value info markdown_quote "${__config}" "${__override}")"
if [ -n "${__info}" ]; then
printf '%s\n\n' "${__info}" >>"${sdc__markdown__file}"
fi
__tag="$(sdc__parse__key_value tag markdown_divider "${__config}" "${__override}")"
if [ -n "${__tag}" ]; then
printf '%s\n\n' "📌 ${__tag}" >>"${sdc__markdown__file}"
fi
__dosbox="$(sdc__parse__key_value dosbox markdown_divider "${__config}" "${__override}")"
if [ -n "${__dosbox}" ]; then
printf '%s\n\n' "📦 ${__dosbox}" >>"${sdc__markdown__file}"
fi
__site="$(sdc__parse__key_value site markdown_divider "${__config}" "${__override}")"
if [ -n "${__site}" ]; then
printf '%s\n\n' "📎 ${__site}" >>"${sdc__markdown__file}"
fi
__include="$(sdc__parse__value script-include-text print "${__config}" "${__override}")"
if [ "${sdc__script__file}" = "Setup" ]; then
if [ "${__include}" = "-1" ]; then
__text="$(sdc__parse__text text print "${__config}")"
if [ -n "${__text}" ]; then
printf '%s\n\n' "${__text}" >>"${sdc__markdown__file}"
fi
fi
if [ -f "${__override}" ]; then
__text="$(sdc__parse__text text print "${__override}")"
if [ -n "${__text}" ]; then
printf '%s\n\n' "${__text}" >>"${sdc__markdown__file}"
fi
fi
if [ "${__include}" = "1" ]; then
__text="$(sdc__parse__text text print "${__config}")"
if [ -n "${__text}" ]; then
printf '%s\n\n' "${__text}" >>"${sdc__markdown__file}"
fi
fi
else
if [ -f "${__override}" ]; then
__text="$(sdc__parse__text text print "${__override}")"
if [ -n "${__text}" ]; then
printf '%s\n\n' "${__text}" >>"${sdc__markdown__file}"
fi
fi
fi
__code="$(sdc__parse__text code print "${__config}" "${__override}")"
if [ -n "${__code}" ]; then
{
printf '%s\n' '```shell'
printf '%s\n' "${__code}"
printf '%s\n\n' '```'
} >>"${sdc__markdown__file}"
fi
if [ "${sdc__script__file}" = "Setup" ] && [ -n "${sdc__category__list}" ] && [ -n "${sdc__program__list}" ]; then
__catlabel="Category"
__applabel="Program"
printf '%s\n\n' " " >>"${sdc__markdown__file}"
printf '%s\n\n' "---" >>"${sdc__markdown__file}"
if [ -n "${sdc__library__name}" ]; then
printf '%s\n\n' "### ▶ **###library-name###**" >>"${sdc__markdown__file}"
fi
if [ -n "${sdc__category__count}" ] && [ "${sdc__category__count}" -gt 1 ]; then
__catlabel="${sdc__category__count} Categories"
printf '%s\n' "#### 【${__catlabel}】" >>"${sdc__markdown__file}"
printf '%s\n\n' "🗂️ ${sdc__category__list}" >>"${sdc__markdown__file}"
fi
if [ -n "${sdc__program__count}" ] && [ "${sdc__program__count}" -gt 1 ]; then
__applabel="${sdc__program__count} Programs"
printf '%s\n' "#### 【${__applabel}】" >>"${sdc__markdown__file}"
printf '%s\n\n' "🔎 ${sdc__program__list}" >>"${sdc__markdown__file}"
fi
fi
__mfile="$(sdc__parse__value montage-file print "${__config}" "${__override}")"
if [ -f "${__mfile}" ]; then
printf '%s\n\n' "![](${__mfile} \"${sdc__application__name}\")" >>"${sdc__markdown__file}"
fi
printf '%s\n\n' "---" >>"${sdc__markdown__file}"
unset __config __override __tfile __tsource __twidth __alias __info __tag __dosbox __site __include __text __code __catlabel __applabel __mfile
}
sdc__utility__category_document() {
if [ -n "${1}" ] && [ -f "${1}" ]; then
sdc__parse__value name application "${1}"
sdc__application__slug="${sdc__application__name}"
__config="$(basename "${1}")"
__dirpath="$(dirname "${1}")"
__catpath="$(dirname "${__dirpath}")"
__apppath="$(sdc__utility__relative_path "${__dirpath}")"
if [ ! -f "${__catpath}/${sdc__markdown__file}" ]; then
__count="$(find -L "${__catpath}" -name "${__config}" | wc -l | xargs)"
sdc__message__item "${__catpath#./}"
printf '%s\n\n---\n\n' "# 🗂️ $(echo "${__catpath}" | sed "s/\.\///;s/\// ‣ /g") (${__count})" >>"${__catpath}/${sdc__markdown__file}"
fi
sdc__message__item "${__catpath#./} ◄ ${sdc__application__name}"
{
__tfile="$(sdc__parse__value thumbnail-file print "${sdc__script__file}" "${1}")"
__mfile="$(sdc__parse__value montage-file print "${sdc__script__file}" "${1}")"
__tag="$(sdc__parse__key_value tag markdown_divider "${1}")"
{
printf '%s\n' "| [${sdc__application__name}]($(sdc__utility__urlencode_string "${__apppath}/${sdc__markdown__file}")) | 📌 ${__tag} |"
printf '%s\n' "|:---:|:---|"
} >>"${__catpath}/${sdc__markdown__file}"
printf '%s' "| " >>"${__catpath}/${sdc__markdown__file}"
if [ -f "${__dirpath}/${__tfile}" ]; then
printf '%s' " [![${sdc__application__name}]($(sdc__utility__urlencode_string "${__apppath}/${__tfile}") \"${sdc__application__name}\")]($(sdc__utility__urlencode_string "${__apppath}/${sdc__markdown__file}")) " >>"${__catpath}/${sdc__markdown__file}"
elif [ -f "${__dirpath}/${__mfile}" ]; then
printf '%s' " [![${sdc__application__name}]($(sdc__utility__urlencode_string "${__apppath}/${__mfile}") \"${sdc__application__name}\")]($(sdc__utility__urlencode_string "${__apppath}/${sdc__markdown__file}")) " >>"${__catpath}/${sdc__markdown__file}"
fi
printf '%s' "<br> " >>"${__catpath}/${sdc__markdown__file}"
printf '%s' " | " >>"${__catpath}/${sdc__markdown__file}"
__info="$(sdc__parse__key_value info markdown_break "${1}")"
if [ -n "${__info}" ]; then
printf '%s' "${__info}" >>"${__catpath}/${sdc__markdown__file}"
fi
printf '%s\n\n---\n\n' " |" >>"${__catpath}/${sdc__markdown__file}"
}
fi
unset __config __dirpath __catpath __apppath __count __tfile __mfile __tag __info
}
sdc__utility__category_list() {
if [ -n "${1}" ] && [ -f "${1}" ]; then
__dirpath="$(dirname "${1}")"
if [ ! -f "${__dirpath}/${sdc__program__file}" ] && [ ! -f "${__dirpath}/Setup" ]; then
sdc__message__item "${__dirpath#./}"
(
cd "${__dirpath}" || sdc__message__error "Inaccessible directory: ${__dirpath} <sdc__utility__category_list>"
sdc__utility__convert_html
)
__count="$(find -L "${__dirpath}" -name "${sdc__program__file}" | wc -l | xargs)"
if [ -z "${sdc__category__count}" ]; then
sdc__category__count=0
fi
sdc__category__list="${sdc__category__list}┃ [$(echo "${__dirpath} (${__count})" | sed 's/\.\///;s/\// ‣ /g')]($(sdc__utility__urlencode_string "${1}"))"
sdc__category__count=$((sdc__category__count + 1))
fi
fi
unset __dirpath __count
}
sdc__utility__convert_html() {
if [ -x "$(command -v pandoc)" ]; then
{
printf '%s\n' "<html><head>"
printf '%s\n' '<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">'
printf '%s\n' '<style>[title~="application-thumbnail"] { float: right; padding: 0 0 2.5% 2.5%; } thead, tbody { border: none; }</style>'
printf '%s\n' "</head><body>"
} >"${sdc__hypertext__file}"
pandoc -f markdown -t html "${sdc__markdown__file}" | sed "s/${sdc__markdown__file}/${sdc__hypertext__file}/g" >>"${sdc__hypertext__file}"
{
printf '%s\n' "<p> </p>"
printf '%s\n' '<p style="text-align: right;"><small>'
printf '%s\n' "<strong>「Simple DOSBox Client v${sdc__script__version}」</strong>"
printf '%s\n' ' 💧 <a href="https://watercss.kognise.dev">water.css</a>'
printf '%s\n' "</small></p></body></html>"
} >>"${sdc__hypertext__file}"
fi
}
sdc__utility__urlencode_string() {
perl -MURI::Escape -e 'print uri_escape_utf8($ARGV[0], "^A-Za-z0-9\-\._~/");' "${1}"
}
sdc__utility__sha256_checksum() {
if [ -f "${1}" ]; then
if [ -x "$(command -v sha256sum)" ]; then
sha256sum "${1}"
elif [ -x "$(command -v shasum)" ]; then
shasum -a 256 "${1}"
else
sdc__message__error "Required command not found: sha256sum/shasum <sdc__utility__sha256_checksum>"
fi
fi
}
sdc__utility__relative_path() {
if [ -L "${1}" ]; then
readlink "${1}"
elif [ -d "${1}" ]; then
perl -MFile::Spec -e 'print File::Spec->abs2rel(@ARGV)' "${1}" "$(dirname "${1}")"
fi
}
sdc__utility__configure_dosbox() {
if [ -f "${sdc__program__file}" ] && [ -f "System/dosbox.conf" ] && [ -f "System/dosbox.orig" ]; then
__source="$(sdc__utility__sha256_checksum "${sdc__program__file}" | head -c 64 | tr '[:upper:]' '[:lower:]')"
__target="$(sdc__utility__sha256_checksum "System/dosbox.orig" | head -c 64 | tr '[:upper:]' '[:lower:]')"
if [ "${__source}" != "${__target}" ]; then
sdc__message__info "${sdc__program__file} changed"
rm -f "System/dosbox.conf"
rm -f "System/dosbox.orig"
fi
fi
if [ ! -f "System/dosbox.conf" ]; then
if [ -f "${sdc__program__file}" ]; then
cp "${sdc__program__file}" "System/dosbox.orig"
fi
if [ "$(command -v "sdc__${sdc__dosbox__variant}__config")" = "sdc__${sdc__dosbox__variant}__config" ]; then
"sdc__${sdc__dosbox__variant}__config"
else
sdc__message__error "Unimplemented DOSBox function: sdc__${sdc__dosbox__variant}__config <sdc__utility__configure_dosbox>"
fi
fi
unset __source __target
}
sdc__utility__uninstall_program() {
if [ -f "Debug" ]; then
rm -f "Debug"
fi
if [ -f "Snapshot" ]; then
rm -f "Snapshot"
fi
if [ -d "System" ]; then
rm -rf "System"
fi
if [ -f "Uninstall" ]; then
rm -f "Uninstall"
fi
}
}
# section: Script command functions
{
sdc__script__Setup() {
sdc__download__asset="${SDC_DOWNLOAD:-cover}"
sdc__library__file="$(sdc__parse__value library-file print "${sdc__script__file}")"
sdc__program__file="$(sdc__parse__value program-file print "${sdc__script__file}")"
sdc__markdown__file="$(sdc__parse__value markdown-file print "${sdc__script__file}")"
sdc__hypertext__file="$(sdc__parse__value hypertext-file print "${sdc__script__file}")"
sdc__message__action "Checking script"
{
__source="$(sdc__parse__value script-source print "${sdc__script__file}")"
__cversion="${sdc__script__version}"
if [ -n "${__source}" ] && [ -n "${__cversion}" ]; then
curl -s "${__source}" -o "${sdc__script__tmpdir}/${sdc__script__file}"
if [ -f "${sdc__script__tmpdir}/${sdc__script__file}" ]; then
__sversion="$(sdc__parse__value script-version print "${sdc__script__tmpdir}/${sdc__script__file}")"
if [ -n "${__sversion}" ]; then
__vcompare="$(printf '%s\n%s' "${__cversion}" "${__sversion}" | sort -rV | head -n1)"
if [ "${__cversion}" != "${__vcompare}" ]; then
sdc__message__item "Updating script from ${__cversion} to ${__sversion}"
cp "${sdc__script__tmpdir}/${sdc__script__file}" "${sdc__script__file}"
sdc__message__info "Script updated (please re-run ${sdc__script__file})"
exit 0
fi
fi
else
sdc__message__item "Warning: Unable to check latest script version"
fi
fi
}
sdc__message__action "Checking library"
{
if [ -f "${sdc__library__file}" ]; then
sdc__library__version="$(sdc__parse__value library-version print "${sdc__library__file}")"
sdc__library__name="$(sdc__parse__value library-name print "${sdc__library__file}")"
if [ -z "${sdc__library__name}" ]; then
sdc__library__name="${sdc__application__name}"
fi
__source="$(sdc__parse__value library-source print "${sdc__library__file}")"
__cversion="${sdc__library__version}"
if [ -n "${__source}" ] && [ -n "${__cversion}" ]; then
curl -s "${__source}" -o "${sdc__script__tmpdir}/${sdc__library__file}"
if [ -f "${sdc__script__tmpdir}/${sdc__library__file}" ]; then
__sversion="$(sdc__parse__value library-version print "${sdc__script__tmpdir}/${sdc__library__file}")"
if [ -n "${__sversion}" ]; then
__vcompare="$(printf '%s\n%s' "${__cversion}" "${__sversion}" | sort -rV | head -n1)"
if [ "${__cversion}" != "${__vcompare}" ]; then
sdc__message__item "Updating library from ${__cversion} to ${__sversion}"
cp "${sdc__script__tmpdir}/${sdc__library__file}" "${sdc__library__file}"
sdc__message__info "Library updated (please re-run ${sdc__script__file})"
exit 0
fi
fi
else
sdc__message__item "Warning: Unable to check latest library version"
fi
fi
fi
}
sdc__message__action "Backing-up files"
{
__bakpath="$(sdc__parse__value backup-directory print "${sdc__script__file}" "${sdc__library__file}")"
if [ "${__bakpath}" != "#" ]; then
if [ ! -d "${__bakpath}" ]; then
mkdir -p "${__bakpath}"
fi
sdc__backup__file="${__bakpath}/$(date -u +%Y%m%d%H%M%S).txt"
printf '%s\n#\n' "# vim: filetype=ini:syntax=dosini" >"${sdc__backup__file}"
__tmpfile="$(mktemp "${sdc__script__tmpdir}/sdc.XXXXXXXX")" || sdc__message__error "Temporary file creation failed <sdc__script__Setup>"
find -L . -name "${sdc__program__file}" -type f -exec dirname '{}' \; | sort >"${__tmpfile}"
while IFS= read -r __index; do
sdc__utility__backup_file "${__index}/${sdc__program__file}"
done <"${__tmpfile}"
fi
}
sdc__message__action "Exporting files"
{
__export="$(sdc__parse__value script-export-file print "${sdc__script__file}" "${sdc__library__file}")"
if [ "${__export}" = "1" ]; then
sdc__parse__key_value file reset_file "${sdc__script__file}"
sdc__parse__key_value file append_file "${sdc__script__file}"
sdc__parse__key_value link symbolic_link "${sdc__script__file}"
sdc__parse__key_value base64 base64_decode "${sdc__script__file}"
fi
if [ -f "${sdc__library__file}" ]; then
sdc__parse__key_value file reset_file "${sdc__library__file}"
sdc__parse__key_value file append_file "${sdc__library__file}"
sdc__parse__key_value link symbolic_link "${sdc__library__file}"
sdc__parse__key_value base64 base64_decode "${sdc__library__file}"
fi
}
sdc__message__action "Copying scripts"
{
__tmpfile="$(mktemp "${sdc__script__tmpdir}/sdc.XXXXXXXX")" || sdc__message__error "Temporary file creation failed <sdc__script__Setup>"
find . -name "${sdc__program__file}" -type f -exec dirname '{}' \; | sort >"${__tmpfile}"
while IFS= read -r __index; do
sdc__utility__copy_script "${__index}/${sdc__program__file}"
done <"${__tmpfile}"
}
sdc__message__action "Cleaning-up documents"
{
__tmpfile="$(mktemp "${sdc__script__tmpdir}/sdc.XXXXXXXX")" || sdc__message__error "Temporary file creation failed <sdc__script__Setup>"
find -L . -name "${sdc__markdown__file}" -type f -exec dirname '{}' \; | sort >"${__tmpfile}"
while IFS= read -r __index; do
sdc__utility__remove_file "${__index}/${sdc__markdown__file}"
done <"${__tmpfile}"
__tmpfile="$(mktemp "${sdc__script__tmpdir}/sdc.XXXXXXXX")" || sdc__message__error "Temporary file creation failed <sdc__script__Setup>"
find -L . -name "${sdc__hypertext__file}" -type f -exec dirname '{}' \; | sort >"${__tmpfile}"
while IFS= read -r __index; do
sdc__utility__remove_file "${__index}/${sdc__hypertext__file}"
done <"${__tmpfile}"
sdc__script__file="Launch"
__tmpfile="$(mktemp "${sdc__script__tmpdir}/sdc.XXXXXXXX")" || sdc__message__error "Temporary file creation failed <sdc__script__Setup>"
find . -name "${sdc__program__file}" -type f -exec dirname '{}' \; | sort >"${__tmpfile}"
while IFS= read -r __index; do
sdc__utility__program_document "${__index}/${sdc__program__file}"
done <"${__tmpfile}"
sdc__script__file="Setup"
}
sdc__message__action "Creating category documents"
{
__tmpfile="$(mktemp "${sdc__script__tmpdir}/sdc.XXXXXXXX")" || sdc__message__error "Temporary file creation failed <sdc__script__Setup>"
find -L . -name "${sdc__program__file}" -type f -exec dirname '{}' \; | sort >"${__tmpfile}"
while IFS= read -r __index; do
sdc__utility__category_document "${__index}/${sdc__program__file}"
done <"${__tmpfile}"
}
sdc__message__action "Creating library document"
{
__tmpfile="$(mktemp "${sdc__script__tmpdir}/sdc.XXXXXXXX")" || sdc__message__error "Temporary file creation failed <sdc__script__Setup>"
find . -name "${sdc__markdown__file}" -type f -exec dirname '{}' \; | sort >"${__tmpfile}"
while IFS= read -r __index; do
sdc__utility__category_list "${__index}/${sdc__markdown__file}"
done <"${__tmpfile}"
sdc__parse__value name application "${sdc__script__file}" "${sdc__library__file}"
__mfile="$(sdc__parse__value montage-file print "${sdc__script__file}" "${sdc__library__file}")"
__mgrid="$(sdc__parse__value montage-grid print "${sdc__script__file}" "${sdc__library__file}")"
__mwidth="$(sdc__parse__value montage-width print "${sdc__script__file}" "${sdc__library__file}")"
if [ "${__mgrid}" != "0" ] && [ -x "$(command -v mogrify)" ] && [ -x "$(command -v montage)" ] && [ -n "${sdc__thumbnail__count}" ] && [ "${sdc__thumbnail__count}" -gt 0 ]; then
sdc__message__action "Creating montage"
eval montage -background none -shadow -geometry +5+5 -tile "${__mgrid}" "${sdc__thumbnail__list}" "${__mfile}" &&
mogrify -resize "${__mwidth}" "${__mfile}"
if [ -x "$(command -v pngquant)" ]; then
pngquant "${__mfile}" --output sdc-tmp.png && mv sdc-tmp.png "${__mfile}"
fi
fi
sdc__utility__application_document
sed -i".sdc" "s/###script-version###/${sdc__script__version}/g" "${sdc__markdown__file}"
if [ -n "${sdc__library__version}" ]; then
sed -i".sdc" "s/###library-version###/${sdc__library__version}/g" "${sdc__markdown__file}"
fi
if [ -n "${sdc__library__name}" ]; then
sed -i".sdc" "s/###library-name###/${sdc__library__name}/g" "${sdc__markdown__file}"
fi
rm -f -- *.sdc
sdc__utility__convert_html
}
sdc__message__plain ""
if [ -f "${sdc__markdown__file}" ]; then
if [ -x "$(command -v mdcat)" ]; then
mdcat "${sdc__markdown__file}"
else
if [ -x "$(command -v pandoc)" ]; then
pandoc -f markdown -t plain "${sdc__markdown__file}"
else
cat "${sdc__markdown__file}"
fi
fi
fi
sdc__message__plain ""
sdc__message__info "Library setup completed"
unset __source __cversion __sversion __vcompare __bakpath __export __index __tmpfile __mfile __mgrid __mwidth
}
sdc__script__Launch() {
sdc__download__asset="all"
sdc__download__match="${sdc__download__asset}"
sdc__program__file="$(sdc__parse__value program-file print "${sdc__script__file}")"
sdc__markdown__file="$(sdc__parse__value markdown-file print "${sdc__script__file}")"
sdc__hypertext__file="$(sdc__parse__value hypertext-file print "${sdc__script__file}")"
if [ -f "${sdc__program__file}" ]; then
sdc__parse__value name application "${sdc__program__file}"
fi
if [ -f "${sdc__program__file}" ]; then
if [ -x "$(command -v mogrify)" ] && [ -x "$(command -v montage)" ] && [ -d "System/capture" ]; then
__count="$(find "System/capture" -name "*.png" | wc -l | sed "s/^ *//;s/ *$//")"
__mfile="$(sdc__parse__value montage-file print "${sdc__script__file}" "${sdc__program__file}")"
__mgrid="$(sdc__parse__value montage-grid print "${sdc__script__file}" "${sdc__program__file}")"
__mwidth="$(sdc__parse__value montage-width print "${sdc__script__file}" "${sdc__program__file}")"
if [ "${__mgrid}" != "0" ] && [ "${__count}" != "0" ]; then
sdc__message__action "Creating montage"
montage -background none -shadow -geometry +5+5 -tile "${__mgrid}" "System/capture/*.png" "${__mfile}" &&
mogrify -resize "${__mwidth}" "${__mfile}"
if [ -x "$(command -v pngquant)" ]; then
pngquant "${__mfile}" --output sdc-tmp.png && mv sdc-tmp.png "${__mfile}"
fi
fi
fi
sdc__message__action "Creating ${sdc__application__name} document"
sdc__utility__application_document
sdc__utility__convert_html
sdc__message__plain ""