#!/bin/sh
# SPDX-License-Identifier: ACSL
# SPDX-FileCopyrightText: © 2022 Antoine Le Gonidec <vv221@dotslashplay.it>
# SPDX-FileCopyrightText: © 2026 Christian Stalp
set -o errexit

###
# Stellaris expansions (main expansions):
# - Utopia
# - Apocalypse
# - MegaCorp
# - Federations
# - Nemesis
# - Overlord
# - Galactic Paragons
# - The Machine Age
# - Cosmic Storms
# - Biogenesis
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260117.1

PLAYIT_COMPATIBILITY_LEVEL='2.34'

GAME_ID='stellaris'
GAME_NAME='Stellaris'

EXPANSION_ID_UTOPIA='utopia'
EXPANSION_NAME_UTOPIA='Utopia'

EXPANSION_ID_APOCALYPSE='apocalypse'
EXPANSION_NAME_APOCALYPSE='Apocalypse'

EXPANSION_ID_MEGACORP='megacorp'
EXPANSION_NAME_MEGACORP='MegaCorp'

EXPANSION_ID_FEDERATIONS='federations'
EXPANSION_NAME_FEDERATIONS='Federations'

EXPANSION_ID_NEMESIS='nemesis'
EXPANSION_NAME_NEMESIS='Nemesis'

EXPANSION_ID_OVERLORD='overlord'
EXPANSION_NAME_OVERLORD='Overlord'

EXPANSION_ID_PARAGONS='galactic-paragons'
EXPANSION_NAME_PARAGONS='Galactic Paragons'

EXPANSION_ID_MACHINE='the-machine-age'
EXPANSION_NAME_MACHINE='The Machine Age'

EXPANSION_ID_STORMS='cosmic-storms'
EXPANSION_NAME_STORMS='Cosmic Storms'

EXPANSION_ID_BIOGENESIS='biogenesis'
EXPANSION_NAME_BIOGENESIS='Biogenesis'

## Utopia

ARCHIVE_BASE_UTOPIA_4_NAME='stellaris_utopia_4_2_4_87179.sh'
ARCHIVE_BASE_UTOPIA_4_MD5='625447ee9c7654e9ff07249b6e438400'
ARCHIVE_BASE_UTOPIA_4_SIZE='75007'
ARCHIVE_BASE_UTOPIA_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_UTOPIA_4_URL='https://www.gog.com/game/stellaris_utopia'

ARCHIVE_BASE_UTOPIA_3_NAME='stellaris_utopia_4_1_7_86266.sh'
ARCHIVE_BASE_UTOPIA_3_MD5='2e1bd4ff7aa51754c0037242f55badb3'
ARCHIVE_BASE_UTOPIA_3_SIZE='75007'
ARCHIVE_BASE_UTOPIA_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_UTOPIA_2_NAME='stellaris_utopia_4_0_23_84679.sh'
ARCHIVE_BASE_UTOPIA_2_MD5='36ca08b712639088b27300ef5d6348e0'
ARCHIVE_BASE_UTOPIA_2_SIZE='75007'
ARCHIVE_BASE_UTOPIA_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_UTOPIA_1_NAME='stellaris_utopia_3_14_1592653_81105.sh'
ARCHIVE_BASE_UTOPIA_1_MD5='ce44b8d0f9afa3e05927c914d1033341'
ARCHIVE_BASE_UTOPIA_1_SIZE='75007'
ARCHIVE_BASE_UTOPIA_1_VERSION='3.14.1592653-gog81105'

ARCHIVE_BASE_UTOPIA_0_NAME='stellaris_utopia_2_8_1_2_42827.sh'
ARCHIVE_BASE_UTOPIA_0_MD5='02057c1076c581e2ad87ac0aa1aee10f'
ARCHIVE_BASE_UTOPIA_0_SIZE='76000'
ARCHIVE_BASE_UTOPIA_0_VERSION='2.8.1.2-gog42827'

## Apocalypse

ARCHIVE_BASE_APOCALYPSE_4_NAME='stellaris_apocalypse_4_2_4_87179.sh'
ARCHIVE_BASE_APOCALYPSE_4_MD5='f687ee431aaae83977e38d67fee7a2af'
ARCHIVE_BASE_APOCALYPSE_4_SIZE='37877'
ARCHIVE_BASE_APOCALYPSE_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_APOCALYPSE_4_URL='https://www.gog.com/game/stellaris_apocalypse'

ARCHIVE_BASE_APOCALYPSE_3_NAME='stellaris_apocalypse_4_1_7_86266.sh'
ARCHIVE_BASE_APOCALYPSE_3_MD5='a90f4847dbb8019b661e3272b681624e'
ARCHIVE_BASE_APOCALYPSE_3_SIZE='37877'
ARCHIVE_BASE_APOCALYPSE_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_APOCALYPSE_2_NAME='stellaris_apocalypse_4_0_23_84679.sh'
ARCHIVE_BASE_APOCALYPSE_2_MD5='657e28499f3f9c7e7e46446b1f45bab0'
ARCHIVE_BASE_APOCALYPSE_2_SIZE='37877'
ARCHIVE_BASE_APOCALYPSE_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_APOCALYPSE_1_NAME='stellaris_apocalypse_3_14_1592653_81105.sh'
ARCHIVE_BASE_APOCALYPSE_1_MD5='7f21a52edafc0c8a80e97a947dc5afa6'
ARCHIVE_BASE_APOCALYPSE_1_SIZE='37877'
ARCHIVE_BASE_APOCALYPSE_1_VERSION='3.14.1592653-gog81105'

ARCHIVE_BASE_APOCALYPSE_0_NAME='stellaris_apocalypse_2_8_1_2_42827.sh'
ARCHIVE_BASE_APOCALYPSE_0_MD5='3b4bfaaaa89b80694173fcc8b7fe09dd'
ARCHIVE_BASE_APOCALYPSE_0_SIZE='39000'
ARCHIVE_BASE_APOCALYPSE_0_VERSION='2.8.1.2-gog42827'

## MegaCorp

ARCHIVE_BASE_MEGACORP_4_NAME='stellaris_megacorp_4_2_4_87179.sh'
ARCHIVE_BASE_MEGACORP_4_MD5='88c646602c264278c5e7c0bfcab495f6'
ARCHIVE_BASE_MEGACORP_4_SIZE='90404'
ARCHIVE_BASE_MEGACORP_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_MEGACORP_4_URL='https://www.gog.com/game/stellaris_megacorp'

ARCHIVE_BASE_MEGACORP_3_NAME='stellaris_megacorp_4_1_7_86266.sh'
ARCHIVE_BASE_MEGACORP_3_MD5='84550d6dd8bbdf1ad9f613029e25513a'
ARCHIVE_BASE_MEGACORP_3_SIZE='90404'
ARCHIVE_BASE_MEGACORP_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_MEGACORP_2_NAME='stellaris_megacorp_4_0_23_84679.sh'
ARCHIVE_BASE_MEGACORP_2_MD5='8e6ad615e3fa7a902e05f54c4e54564e'
ARCHIVE_BASE_MEGACORP_2_SIZE='90404'
ARCHIVE_BASE_MEGACORP_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_MEGACORP_1_NAME='stellaris_megacorp_3_14_1592653_81105.sh'
ARCHIVE_BASE_MEGACORP_1_MD5='897bda9d1e5eda534a4913245e3af69b'
ARCHIVE_BASE_MEGACORP_1_SIZE='90404'
ARCHIVE_BASE_MEGACORP_1_VERSION='3.14.1592653-gog81105'

ARCHIVE_BASE_MEGACORP_0_NAME='stellaris_megacorp_2_8_1_2_42827.sh'
ARCHIVE_BASE_MEGACORP_0_MD5='2cd753517129dae46b0e92ca2d50dcb9'
ARCHIVE_BASE_MEGACORP_0_SIZE='140000'
ARCHIVE_BASE_MEGACORP_0_VERSION='2.8.1.2-gog42827'

## Federations

ARCHIVE_BASE_FEDERATIONS_4_NAME='stellaris_federations_4_2_4_87179.sh'
ARCHIVE_BASE_FEDERATIONS_4_MD5='15f692a0b49ade066fd48cb0622c0266'
ARCHIVE_BASE_FEDERATIONS_4_SIZE='14433'
ARCHIVE_BASE_FEDERATIONS_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_FEDERATIONS_4_URL='https://www.gog.com/game/stellaris_federations'

ARCHIVE_BASE_FEDERATIONS_3_NAME='stellaris_federations_4_1_7_86266.sh'
ARCHIVE_BASE_FEDERATIONS_3_MD5='e66ebe87313965d25ae63721636e3bad'
ARCHIVE_BASE_FEDERATIONS_3_SIZE='14433'
ARCHIVE_BASE_FEDERATIONS_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_FEDERATIONS_2_NAME='stellaris_federations_4_0_23_84679.sh'
ARCHIVE_BASE_FEDERATIONS_2_MD5='432adf7d8b2491d1810d1fc7182f7806'
ARCHIVE_BASE_FEDERATIONS_2_SIZE='14433'
ARCHIVE_BASE_FEDERATIONS_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_FEDERATIONS_1_NAME='stellaris_federations_3_14_1592653_81105.sh'
ARCHIVE_BASE_FEDERATIONS_1_MD5='ce2828f957f35b1ce114c1bf66fa65c2'
ARCHIVE_BASE_FEDERATIONS_1_SIZE='14433'
ARCHIVE_BASE_FEDERATIONS_1_VERSION='3.14.1592653-gog81105'

ARCHIVE_BASE_FEDERATIONS_0_NAME='stellaris_federations_2_7_1_38218.sh'
ARCHIVE_BASE_FEDERATIONS_0_MD5='371a88b8771ed4c58144a00494285c46'
ARCHIVE_BASE_FEDERATIONS_0_SIZE='15000'
ARCHIVE_BASE_FEDERATIONS_0_VERSION='2.7.1-gog38218'

## Nemesis

ARCHIVE_BASE_NEMESIS_4_NAME='stellaris_nemesis_4_2_4_87179.sh'
ARCHIVE_BASE_NEMESIS_4_MD5='760f25250f362339d379aec1d66d69f0'
ARCHIVE_BASE_NEMESIS_4_SIZE='38539'
ARCHIVE_BASE_NEMESIS_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_NEMESIS_4_URL='https://www.gog.com/game/stellaris_nemesis'

ARCHIVE_BASE_NEMESIS_3_NAME='stellaris_nemesis_4_1_7_86266.sh'
ARCHIVE_BASE_NEMESIS_3_MD5='9a7e29858a771521a8e6b792191df98f'
ARCHIVE_BASE_NEMESIS_3_SIZE='38539'
ARCHIVE_BASE_NEMESIS_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_NEMESIS_2_NAME='stellaris_nemesis_4_0_23_84679.sh'
ARCHIVE_BASE_NEMESIS_2_MD5='dad4d0666016994358fcacb23c64e018'
ARCHIVE_BASE_NEMESIS_2_SIZE='38539'
ARCHIVE_BASE_NEMESIS_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_NEMESIS_1_NAME='stellaris_nemesis_3_14_1592653_81105.sh'
ARCHIVE_BASE_NEMESIS_1_MD5='7d686008bc3b604c55578cb7b72b711b'
ARCHIVE_BASE_NEMESIS_1_SIZE='38539'
ARCHIVE_BASE_NEMESIS_1_VERSION='3.14.1592653-gog81105'

## Overlord

ARCHIVE_BASE_OVERLORD_4_NAME='stellaris_overlord_4_2_4_87179.sh'
ARCHIVE_BASE_OVERLORD_4_MD5='0799f8fdcb6801ecb0951c6e33051fe6'
ARCHIVE_BASE_OVERLORD_4_SIZE='99860'
ARCHIVE_BASE_OVERLORD_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_OVERLORD_4_URL='https://www.gog.com/game/stellaris_overlord'

ARCHIVE_BASE_OVERLORD_3_NAME='stellaris_overlord_4_1_7_86266.sh'
ARCHIVE_BASE_OVERLORD_3_MD5='38622d832b353aee6dbb9956b5e145fc'
ARCHIVE_BASE_OVERLORD_3_SIZE='99860'
ARCHIVE_BASE_OVERLORD_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_OVERLORD_2_NAME='stellaris_overlord_4_0_23_84679.sh'
ARCHIVE_BASE_OVERLORD_2_MD5='9a854138d0831c661965036719252902'
ARCHIVE_BASE_OVERLORD_2_SIZE='99860'
ARCHIVE_BASE_OVERLORD_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_OVERLORD_1_NAME='stellaris_overlord_3_14_1592653_81105.sh'
ARCHIVE_BASE_OVERLORD_1_MD5='b556024c88c3d9dec03c8e5945de49b4'
ARCHIVE_BASE_OVERLORD_1_SIZE='99860'
ARCHIVE_BASE_OVERLORD_1_VERSION='3.14.1592653-gog81105'

## Galactic Paragons

ARCHIVE_BASE_PARAGONS_4_NAME='stellaris_galactic_paragons_4_2_4_87179.sh'
ARCHIVE_BASE_PARAGONS_4_MD5='f2416e5a508f0bc06b4d1ff71610bc29'
ARCHIVE_BASE_PARAGONS_4_SIZE='832'
ARCHIVE_BASE_PARAGONS_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_PARAGONS_4_URL='https://www.gog.com/game/stellaris_galactic_paragons'

ARCHIVE_BASE_PARAGONS_3_NAME='stellaris_galactic_paragons_4_1_7_86266.sh'
ARCHIVE_BASE_PARAGONS_3_MD5='e246e9d897591d9e7b549991cad29721'
ARCHIVE_BASE_PARAGONS_3_SIZE='832'
ARCHIVE_BASE_PARAGONS_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_PARAGONS_2_NAME='stellaris_galactic_paragons_4_0_23_84679.sh'
ARCHIVE_BASE_PARAGONS_2_MD5='c32dc8e5ece651f47c1e585b4ea98e5c'
ARCHIVE_BASE_PARAGONS_2_SIZE='832'
ARCHIVE_BASE_PARAGONS_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_PARAGONS_1_NAME='stellaris_galactic_paragons_3_14_1592653_81105.sh'
ARCHIVE_BASE_PARAGONS_1_MD5='b3a00f45cec93aea1ff6a2a0108935a5'
ARCHIVE_BASE_PARAGONS_1_SIZE='832'
ARCHIVE_BASE_PARAGONS_1_VERSION='3.14.1592653-gog81105'

## The Machine Age

ARCHIVE_BASE_MACHINE_4_NAME='stellaris_the_machine_age_4_2_4_87179.sh'
ARCHIVE_BASE_MACHINE_4_MD5='1bb9bb74e4750787492d446224772a11'
ARCHIVE_BASE_MACHINE_4_SIZE='100390'
ARCHIVE_BASE_MACHINE_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_MACHINE_4_URL='https://www.gog.com/game/stellaris_the_machine_age'

ARCHIVE_BASE_MACHINE_3_NAME='stellaris_the_machine_age_4_1_7_86266.sh'
ARCHIVE_BASE_MACHINE_3_MD5='4877f30296d1be2b5a323e9f0e996f10'
ARCHIVE_BASE_MACHINE_3_SIZE='100390'
ARCHIVE_BASE_MACHINE_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_MACHINE_2_NAME='stellaris_the_machine_age_4_0_23_84679.sh'
ARCHIVE_BASE_MACHINE_2_MD5='bd0a016b3974fa441665e2dcf89bb700'
ARCHIVE_BASE_MACHINE_2_SIZE='100390'
ARCHIVE_BASE_MACHINE_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_MACHINE_1_NAME='stellaris_the_machine_age_3_14_1592653_81105.sh'
ARCHIVE_BASE_MACHINE_1_MD5='07b714aa18a9c9ff40f5fbf03cf59e2d'
ARCHIVE_BASE_MACHINE_1_SIZE='100390'
ARCHIVE_BASE_MACHINE_1_VERSION='3.14.1592653-gog81105'

## Cosmic Storms

ARCHIVE_BASE_STORMS_4_NAME='stellaris_cosmic_storms_4_2_4_87179.sh'
ARCHIVE_BASE_STORMS_4_MD5='cfc4c99dcf8fedabc594902c400c430a'
ARCHIVE_BASE_STORMS_4_SIZE='829'
ARCHIVE_BASE_STORMS_4_VERSION='4.2.4-gog87179'
ARCHIVE_BASE_STORMS_4_URL='https://www.gog.com/game/stellaris_cosmic_storms'

ARCHIVE_BASE_STORMS_3_NAME='stellaris_cosmic_storms_4_1_7_86266.sh'
ARCHIVE_BASE_STORMS_3_MD5='49216dcae8261a3f7f6fbc2a59bd3400'
ARCHIVE_BASE_STORMS_3_SIZE='829'
ARCHIVE_BASE_STORMS_3_VERSION='4.1.7-gog86266'

ARCHIVE_BASE_STORMS_2_NAME='stellaris_cosmic_storms_4_0_23_84679.sh'
ARCHIVE_BASE_STORMS_2_MD5='b34dac8b2fb7970f171a5ec9a07232e1'
ARCHIVE_BASE_STORMS_2_SIZE='829'
ARCHIVE_BASE_STORMS_2_VERSION='4.0.23-gog84679'

ARCHIVE_BASE_STORMS_1_NAME='stellaris_cosmic_storms_3_14_1592653_81105.sh'
ARCHIVE_BASE_STORMS_1_MD5='672c8bb0d4992b1e76f827fe351fb69a'
ARCHIVE_BASE_STORMS_1_SIZE='829'
ARCHIVE_BASE_STORMS_1_VERSION='3.14.1592653-gog81105'

## Biogenesis

ARCHIVE_BASE_BIOGENESIS_4_NAME='stellaris_biogenesis_4_2_4_87179.sh'
ARCHIVE_BASE_BIOGENESIS_4_MD5='f8ce9051a98a7b2413285721194a7556'
ARCHIVE_BASE_BIOGENESIS_4_SIZE='88020'
ARCHIVE_BASE_BIOGENESIS_4_VERSION='4.2.4-gog87179.sh'
ARCHIVE_BASE_BIOGENESIS_4_URL='https://www.gog.com/game/stellaris_biogenesis'

CONTENT_PATH_DEFAULT='data/noarch/game'
CONTENT_GAME_MAIN_FILES='
dlc'

PKG_PARENT_ID="$GAME_ID"

PKG_MAIN_DEPENDENCIES_SIBLINGS='
PKG_PARENT'

# Load common functions.

## Scan library paths used by ./play.it ≥ 2.35.
if [ -z "$PLAYIT_LIB2" ]; then
	for playit_lib_dir in \
		"$PWD" \
		"${HOME}/.local/lib/play.it" \
		'/usr/local/lib/play.it' \
		'/usr/lib/play.it'
	do
		playit_lib_path="${playit_lib_dir}/libplayit.sh.2"
		if [ -e "$playit_lib_path" ]; then
			PLAYIT_LIB2="$playit_lib_path"
			break
		fi
	done
fi
## Scan library paths used by ./play.it < 2.35.
## This can go away when PLAYIT_COMPATIBILITY_LEVEL is bumped to 2.35 or higher.
if [ -z "$PLAYIT_LIB2" ]; then
	for playit_lib_dir in \
		"$PWD" \
		"${XDG_DATA_HOME:="${HOME}/.local/share"}/play.it" \
		'/usr/local/share/games/play.it' \
		'/usr/local/share/play.it' \
		'/usr/share/games/play.it' \
		'/usr/share/play.it'
	do
		playit_lib_path="${playit_lib_dir}/libplayit2.sh"
		if [ -e "$playit_lib_path" ]; then
			PLAYIT_LIB2="$playit_lib_path"
			break
		fi
	done
fi
## Error out if the library can not be found.
if [ -z "$PLAYIT_LIB2" ]; then
	printf '\n\033[1;31mError:\033[0m\n'
	printf 'libplayit2.sh not found.\n'
	exit 1
fi
# shellcheck source=libplayit2.sh
. "$PLAYIT_LIB2"

# Run default initialisation actions.

initialization_default "$@"

# Extract game data.

archive_extraction_default

# Include game data.

content_inclusion_default

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
