429
429
fi
430
430
# Take our best shot at making this playable.
431
431
cd " $destdir "
432
+ inferred_basegame=
433
+ basegamespat=" id1\|hipnotic\|rogue\|quoth\|copper\|ad\|alkaline"
432
434
# Try to get rid of any extra directories generated in archive-creation,
433
435
# as well as other files we don't want.
434
436
while true
@@ -444,23 +446,59 @@ then
444
446
then
445
447
break
446
448
fi
449
+ # If any directory looks like a "basegame", and it contains known Quake
450
+ # content directories, move its contents up and infer the basegame. And
451
+ # keep looping. (If "id1", don't infer basegame though.)
452
+ did_move=false
453
+ dirs_here=$( find -maxdepth 1 -type d | grep -v ' ^\.$' | grep -oP ' ^\./\K.+' )
454
+ basegames_here=$( echo " $dirs_here " | grep " ^\($basegamespat \)$" )
455
+ for dir in $basegames_here
456
+ do
457
+ subdirs=$( find $dir -maxdepth 1 -type d | grep -v " ^$dir $" | grep -oP " ^$dir /\K.+" )
458
+ echo " $knowndirs " | grep -qwi " $subdirs "
459
+ if [[ $? -eq 0 ]]
460
+ then
461
+ if [[ $dir != " id1" ]]
462
+ then
463
+ if [[ $inferred_basegame != " " && $inferred_basegame != $dir ]]
464
+ then
465
+ rm -rf " $destdir "
466
+ message " archive seems to indicate both $inferred_basegame and $dir as basegame"
467
+ exit 1
468
+ fi
469
+ inferred_basegame=$dir
470
+ fi
471
+ mv $dir /* .
472
+ if [[ $? -ne 0 ]]
473
+ then
474
+ rm -rf " $destdir "
475
+ message " failed in organizing the extracted archive contents"
476
+ exit 1
477
+ fi
478
+ rm -rf $dir
479
+ did_move=true
480
+ fi
481
+ done
482
+ if [[ $did_move == " true" ]]
483
+ then
484
+ continue
485
+ fi
447
486
# If there is only one directory here, and it's not a known Quake
448
487
# content directory, then it's packaging cruft. Move its contents up
449
488
# and keep looping.
450
- dirshere=$( find -maxdepth 1 -type d | grep -v ' ^\.$' )
451
- if [[ " $dirshere " != " " && $( echo " $dirshere " | wc -l) -eq 1 ]]
489
+ if [[ " $dirs_here " != " " && $( echo " $dirs_here " | wc -l) -eq 1 ]]
452
490
then
453
- echo " $knowndirs " | grep -qwi " $dirshere "
491
+ echo " $knowndirs " | grep -qwi " $dirs_here "
454
492
if [[ $? -ne 0 ]]
455
493
then
456
- mv " $dirshere " /* .
494
+ mv " $dirs_here " /* .
457
495
if [[ $? -ne 0 ]]
458
496
then
459
497
rm -rf " $destdir "
460
498
message " failed in organizing the extracted archive contents"
461
499
exit 1
462
500
fi
463
- rm -rf " $dirshere "
501
+ rm -rf " $dirs_here "
464
502
continue
465
503
fi
466
504
fi
@@ -704,6 +742,60 @@ then
704
742
fi
705
743
fi
706
744
fi
745
+ # If we didn't get basegame_args from a gamedir-specific conf, see if we can
746
+ # infer it from the way the archive was organized.
747
+ if [[ $calc_basegame_args == " true" && $inferred_basegame != " " ]]
748
+ then
749
+ if [[ $( is_standalone_gamedir " $mod " ) == " true" ]]
750
+ then
751
+ message " archive appears to depend on $inferred_basegame but also contains paks/progs"
752
+ exit 1
753
+ fi
754
+ calc_basegame_args=false
755
+ if [[ $inferred_basegame == " quoth" ]]
756
+ then
757
+ basegame_args=-quoth
758
+ else
759
+ if [[ $inferred_basegame == " hipnotic" ]]
760
+ then
761
+ basegame_args=-hipnotic
762
+ else
763
+ if [[ $inferred_basegame == " rogue" ]]
764
+ then
765
+ basegame_args=-rogue
766
+ else
767
+ if [[ $inferred_basegame == " ad" ]]
768
+ if [[ -n " $ad_basegame_args " ]]
769
+ then
770
+ basegame_args=$ad_basegame_args
771
+ else
772
+ basegame_error=" ad"
773
+ fi
774
+ then
775
+ if [[ $inferred_basegame == " copper" ]]
776
+ then
777
+ if [[ -n " $copper_basegame_args " ]]
778
+ then
779
+ basegame_args=$copper_basegame_args
780
+ else
781
+ basegame_error=" copper"
782
+ fi
783
+ else
784
+ if [[ $inferred_basegame == " alkaline" ]]
785
+ then
786
+ if [[ -n " $alkaline_basegame_args " ]]
787
+ then
788
+ basegame_args=$alkaline_basegame_args
789
+ else
790
+ basegame_error=" alkaline"
791
+ fi
792
+ fi
793
+ fi
794
+ fi
795
+ fi
796
+ fi
797
+ fi
798
+ fi
707
799
# For a non-standalone mod where basegame_args was not explicitly set in a
708
800
# gamedir-specific conf, see if we can figure out any required basegame from
709
801
# grepping docs. Arcane Dimensions is somewhat different; we assume AD if
0 commit comments