2017-11-01 05:42:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-12-12 03:12:44 +00:00
|
|
|
set -e -o pipefail
|
2019-09-29 16:45:21 +00:00
|
|
|
|
2021-10-15 23:42:44 +00:00
|
|
|
: "${REMOVE_OLD_MODS:=false}"
|
2023-06-10 17:51:49 +00:00
|
|
|
: "${MODS:=}"
|
|
|
|
: "${MODS_OUT_DIR:=/data/mods}"
|
2021-10-15 23:42:44 +00:00
|
|
|
: "${MODS_FILE:=}"
|
2023-06-10 17:51:49 +00:00
|
|
|
: "${PLUGINS:=}"
|
|
|
|
: "${PLUGINS_OUT_DIR:=/data/plugins}"
|
|
|
|
: "${PLUGINS_FILE:=}"
|
2021-10-15 23:42:44 +00:00
|
|
|
: "${REMOVE_OLD_MODS_DEPTH:=1} "
|
2022-07-30 02:28:04 +00:00
|
|
|
: "${REMOVE_OLD_MODS_INCLUDE:=*.jar,*-version.json}"
|
2022-01-06 03:38:51 +00:00
|
|
|
sum_file=/data/.generic_pack.sum
|
2021-10-15 23:42:44 +00:00
|
|
|
|
2021-10-10 14:33:17 +00:00
|
|
|
# shellcheck source=start-utils
|
2021-10-25 01:23:21 +00:00
|
|
|
. "${SCRIPTS:-/}start-utils"
|
2021-10-17 03:09:56 +00:00
|
|
|
isDebugging && set -x
|
2019-09-29 16:45:21 +00:00
|
|
|
|
2019-02-08 13:11:01 +00:00
|
|
|
# CURSE_URL_BASE used in manifest downloads below
|
|
|
|
CURSE_URL_BASE=${CURSE_URL_BASE:-https://minecraft.curseforge.com/projects}
|
|
|
|
|
2018-10-12 22:11:57 +00:00
|
|
|
# Remove old mods/plugins
|
2021-10-15 23:42:44 +00:00
|
|
|
if isTrue "${REMOVE_OLD_MODS}" && [ -z "${MODS_FILE}" ]; then
|
2023-06-11 16:00:39 +00:00
|
|
|
removeOldMods "$MODS_OUT_DIR"
|
|
|
|
removeOldMods "$PLUGINS_OUT_DIR"
|
2022-01-06 03:38:51 +00:00
|
|
|
rm -f "$sum_file"
|
2018-10-12 22:11:57 +00:00
|
|
|
fi
|
|
|
|
|
2022-09-10 17:58:32 +00:00
|
|
|
function handlePackwiz() {
|
|
|
|
# If packwiz url passed, bootstrap packwiz and update mods before other modpack processing
|
|
|
|
if [[ "${PACKWIZ_URL:-}" ]]; then
|
|
|
|
if ! packwizInstaller=$(mc-image-helper maven-download \
|
|
|
|
--maven-repo=https://maven.packwiz.infra.link/repository/release/ \
|
|
|
|
--group=link.infra.packwiz --artifact=packwiz-installer --classifier=dist \
|
|
|
|
--skip-existing); then
|
|
|
|
log "ERROR: failed to get packwiz installer"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
log "Running packwiz installer against URL: ${PACKWIZ_URL}"
|
2022-09-15 16:43:11 +00:00
|
|
|
if ! java -cp "${packwizInstaller}" link.infra.packwiz.installer.Main -s server "${PACKWIZ_URL}"; then
|
2022-09-10 17:58:32 +00:00
|
|
|
log "ERROR failed to run packwiz installer"
|
|
|
|
exit 1
|
2021-12-07 03:40:00 +00:00
|
|
|
fi
|
|
|
|
fi
|
2022-09-10 17:58:32 +00:00
|
|
|
}
|
2021-12-07 03:40:00 +00:00
|
|
|
|
2023-06-10 17:51:49 +00:00
|
|
|
function handleModpackZip() {
|
2017-11-01 05:42:44 +00:00
|
|
|
# If supplied with a URL for a modpack (simple zip of jars), download it and unpack
|
|
|
|
if [[ "$MODPACK" ]]; then
|
2020-08-03 00:57:12 +00:00
|
|
|
if isURL "${MODPACK}"; then
|
2021-04-28 21:44:39 +00:00
|
|
|
log "Downloading mod/plugin pack"
|
2021-10-17 03:09:56 +00:00
|
|
|
if ! get -o /tmp/modpack.zip "${MODPACK}"; then
|
|
|
|
log "ERROR: failed to download from ${MODPACK}"
|
2017-11-01 05:42:44 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
2021-05-06 21:27:30 +00:00
|
|
|
elif [[ "$MODPACK" =~ .*\.zip ]]; then
|
2021-10-17 03:09:56 +00:00
|
|
|
if ! cp "$MODPACK" /tmp/modpack.zip; then
|
2021-05-06 21:27:30 +00:00
|
|
|
log "ERROR: failed to copy from $MODPACK"
|
|
|
|
exit 2
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
2020-08-03 00:57:12 +00:00
|
|
|
else
|
2021-05-06 21:27:30 +00:00
|
|
|
log "ERROR Invalid URL or Path given for MODPACK: $MODPACK"
|
2020-08-03 00:57:12 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2021-05-06 21:27:30 +00:00
|
|
|
|
2022-01-17 02:49:15 +00:00
|
|
|
if [ "$FAMILY" = "SPIGOT" ]; then
|
2023-06-11 16:00:39 +00:00
|
|
|
mkdir -p "$PLUGINS_OUT_DIR"
|
|
|
|
if ! unzip -o -d "$PLUGINS_OUT_DIR" /tmp/modpack.zip; then
|
2021-10-17 03:09:56 +00:00
|
|
|
log "ERROR: failed to unzip the modpack from ${MODPACK}"
|
2021-05-06 21:27:30 +00:00
|
|
|
fi
|
|
|
|
else
|
2023-06-11 16:00:39 +00:00
|
|
|
mkdir -p "$MODS_OUT_DIR"
|
|
|
|
if ! unzip -o -d "$MODS_OUT_DIR" /tmp/modpack.zip; then
|
2021-10-17 03:09:56 +00:00
|
|
|
log "ERROR: failed to unzip the modpack from ${MODPACK}"
|
2021-05-06 21:27:30 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
rm -f /tmp/modpack.zip
|
2023-06-10 17:51:49 +00:00
|
|
|
fi
|
|
|
|
}
|
2017-11-01 05:42:44 +00:00
|
|
|
|
2023-06-10 17:51:49 +00:00
|
|
|
function handleListings() {
|
2023-06-11 16:00:39 +00:00
|
|
|
if usesMods && usesPlugins; then
|
|
|
|
if [[ "$MODS" ]]; then
|
|
|
|
mkdir -p "$MODS_OUT_DIR"
|
|
|
|
mc-image-helper mcopy \
|
|
|
|
--glob=*.jar \
|
|
|
|
--scope=var-list \
|
|
|
|
--to="$MODS_OUT_DIR" \
|
|
|
|
"$MODS"
|
|
|
|
fi
|
|
|
|
if [[ "$PLUGINS" ]]; then
|
|
|
|
mkdir -p "$PLUGINS_OUT_DIR"
|
|
|
|
mc-image-helper mcopy \
|
|
|
|
--glob=*.jar \
|
|
|
|
--scope=var-list \
|
|
|
|
--to="$PLUGINS_OUT_DIR" \
|
|
|
|
"$PLUGINS"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$MODS_FILE" ]]; then
|
|
|
|
mkdir -p "$MODS_OUT_DIR"
|
|
|
|
mc-image-helper mcopy \
|
|
|
|
--file-is-listing \
|
|
|
|
--scope=file-list \
|
|
|
|
--to="$MODS_OUT_DIR" \
|
|
|
|
"$MODS_FILE"
|
|
|
|
fi
|
|
|
|
if [[ "$PLUGINS_FILE" ]]; then
|
|
|
|
mkdir -p "$PLUGINS_OUT_DIR"
|
|
|
|
mc-image-helper mcopy \
|
|
|
|
--file-is-listing \
|
|
|
|
--scope=file-list \
|
|
|
|
--to="$PLUGINS_OUT_DIR" \
|
|
|
|
"$PLUGINS_FILE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
elif usesPlugins || usesMods; then
|
|
|
|
outDir="$MODS_OUT_DIR"
|
2023-06-10 17:51:49 +00:00
|
|
|
if usesPlugins; then
|
2023-06-11 16:00:39 +00:00
|
|
|
outDir="$PLUGINS_OUT_DIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$MODS" || "$PLUGINS" ]]; then
|
|
|
|
mkdir -p "$outDir"
|
2023-06-10 17:51:49 +00:00
|
|
|
mc-image-helper mcopy \
|
|
|
|
--glob=*.jar \
|
|
|
|
--scope=var-list \
|
2023-06-11 16:00:39 +00:00
|
|
|
--to="$outDir" \
|
|
|
|
"$MODS" "$PLUGINS"
|
2020-08-03 00:57:12 +00:00
|
|
|
fi
|
2021-10-15 23:42:44 +00:00
|
|
|
|
2023-06-11 16:00:39 +00:00
|
|
|
if [[ "$MODS_FILE" || "$PLUGINS_FILE" ]]; then
|
|
|
|
mkdir -p "$outDir"
|
2023-06-10 17:51:49 +00:00
|
|
|
mc-image-helper mcopy \
|
|
|
|
--file-is-listing \
|
|
|
|
--scope=file-list \
|
2023-06-11 16:00:39 +00:00
|
|
|
--to="$outDir" \
|
|
|
|
"$MODS_FILE" "$PLUGINS_FILE"
|
2023-06-10 17:51:49 +00:00
|
|
|
fi
|
2023-06-11 16:00:39 +00:00
|
|
|
|
2021-10-15 23:42:44 +00:00
|
|
|
fi
|
2022-09-10 17:58:32 +00:00
|
|
|
}
|
2021-10-15 23:42:44 +00:00
|
|
|
|
2023-03-05 14:55:19 +00:00
|
|
|
function handleGenericPacks() {
|
2022-06-27 14:08:21 +00:00
|
|
|
: "${GENERIC_PACKS:=${GENERIC_PACK}}"
|
|
|
|
: "${GENERIC_PACKS_PREFIX:=}"
|
|
|
|
: "${GENERIC_PACKS_SUFFIX:=}"
|
|
|
|
|
|
|
|
if [[ "${GENERIC_PACKS}" ]]; then
|
|
|
|
IFS=',' read -ra packs <<< "${GENERIC_PACKS}"
|
2019-09-29 16:45:21 +00:00
|
|
|
|
2022-06-27 14:08:21 +00:00
|
|
|
packFiles=()
|
|
|
|
for packEntry in "${packs[@]}"; do
|
|
|
|
pack="${GENERIC_PACKS_PREFIX}${packEntry}${GENERIC_PACKS_SUFFIX}"
|
|
|
|
if isURL "${pack}"; then
|
|
|
|
mkdir -p /data/packs
|
|
|
|
log "Downloading generic pack from $pack"
|
|
|
|
if ! outfile=$(get -o /data/packs --output-filename --skip-up-to-date "$pack"); then
|
|
|
|
log "ERROR: failed to download $pack"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
packFiles+=("$outfile")
|
|
|
|
else
|
|
|
|
packFiles+=("$pack")
|
|
|
|
fi
|
2021-10-25 01:23:21 +00:00
|
|
|
done
|
2021-10-20 20:36:02 +00:00
|
|
|
|
2022-06-27 14:08:21 +00:00
|
|
|
isDebugging && [ -f "$sum_file}" ] && cat "$sum_file"
|
2021-10-20 20:36:02 +00:00
|
|
|
|
2022-06-27 14:08:21 +00:00
|
|
|
log "Checking if generic packs are up to date"
|
|
|
|
if isTrue "${SKIP_GENERIC_PACK_UPDATE_CHECK:-false}" && [ -f "$sum_file" ]; then
|
|
|
|
log "Skipping generic pack update check"
|
|
|
|
elif isTrue "${FORCE_GENERIC_PACK_UPDATE}" || ! checkSum "${sum_file}"; then
|
|
|
|
log "Generic pack(s) are out of date. Re-applying..."
|
2021-10-20 20:36:02 +00:00
|
|
|
|
2022-06-27 14:08:21 +00:00
|
|
|
original_base_dir=/data/.tmp/generic_pack_base
|
|
|
|
base_dir=$original_base_dir
|
|
|
|
rm -rf "${base_dir}"
|
|
|
|
mkdir -p "${base_dir}"
|
|
|
|
for pack in "${packFiles[@]}"; do
|
|
|
|
isDebugging && ls -l "${pack}"
|
|
|
|
extract "${pack}" "${base_dir}"
|
|
|
|
done
|
2021-10-20 20:36:02 +00:00
|
|
|
|
2022-10-08 23:25:42 +00:00
|
|
|
# Remove any eula file since container manages it
|
|
|
|
rm -f "${base_dir}/eula.txt"
|
|
|
|
|
2022-06-27 14:08:21 +00:00
|
|
|
# recalculate the actual base directory of content
|
2022-07-21 01:24:05 +00:00
|
|
|
if ! base_dir=$(mc-image-helper find \
|
|
|
|
--max-depth=3 --type=directory --name=mods,plugins,config \
|
|
|
|
--only-shallowest --fail-no-matches --format '%h' \
|
|
|
|
"$base_dir"); then
|
2022-06-27 14:08:21 +00:00
|
|
|
log "ERROR: Unable to find content base of generic packs ${GENERIC_PACKS}. Directories:"
|
2022-07-21 01:24:05 +00:00
|
|
|
mc-image-helper find --name=* --max-depth=3 --type=directory --format '- %P' "$original_base_dir"
|
2022-06-27 14:08:21 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2021-10-25 01:23:21 +00:00
|
|
|
|
2022-06-27 14:08:21 +00:00
|
|
|
if [ -f /data/manifest.txt ]; then
|
|
|
|
log "Manifest exists from older generic pack, cleaning up ..."
|
|
|
|
while read -r f; do
|
|
|
|
rm -rf "/data/${f}"
|
|
|
|
done < /data/manifest.txt
|
|
|
|
# prune empty dirs
|
|
|
|
find /data -mindepth 1 -depth -type d -empty -delete
|
|
|
|
rm -f /data/manifest.txt
|
|
|
|
fi
|
|
|
|
|
|
|
|
log "Writing generic pack manifest ... "
|
|
|
|
find "${base_dir}" -type f -printf "%P\n" > /data/manifest.txt
|
|
|
|
|
|
|
|
log "Applying generic pack ..."
|
|
|
|
cp -R -f "${base_dir}"/* /data
|
|
|
|
rm -rf $original_base_dir
|
|
|
|
|
2022-11-10 13:05:47 +00:00
|
|
|
if isTrue "${SKIP_GENERIC_PACK_CHECKSUM:-false}"; then
|
|
|
|
log "Skipping generic pack(s) checksum"
|
|
|
|
else
|
|
|
|
log "Saving generic pack(s) checksum"
|
|
|
|
sha1sum "${packFiles[@]}" > "${sum_file}"
|
|
|
|
if isDebugging; then
|
|
|
|
cat "$sum_file"
|
|
|
|
fi
|
2022-09-03 15:11:58 +00:00
|
|
|
fi
|
2022-06-27 14:08:21 +00:00
|
|
|
fi
|
2019-09-29 16:45:21 +00:00
|
|
|
fi
|
2022-06-27 14:08:21 +00:00
|
|
|
}
|
|
|
|
|
2023-03-05 14:55:19 +00:00
|
|
|
function handleModrinthProjects() {
|
2022-06-27 14:08:21 +00:00
|
|
|
: "${MODRINTH_PROJECTS:=}"
|
|
|
|
: "${MODRINTH_ALLOWED_VERSION_TYPE:=release}"
|
2023-09-09 13:37:46 +00:00
|
|
|
: "${MODRINTH_DOWNLOAD_DEPENDENCIES:=none}"
|
|
|
|
if [[ -v MODRINTH_DOWNLOAD_OPTIONAL_DEPENDENCIES ]]; then
|
|
|
|
log "WARNING The variable MODRINTH_DOWNLOAD_OPTIONAL_DEPENDENCIES is removed."
|
|
|
|
log " Use MODRINTH_DOWNLOAD_DEPENDENCIES=optional instead"
|
|
|
|
fi
|
2022-06-27 14:08:21 +00:00
|
|
|
|
2023-01-02 19:29:20 +00:00
|
|
|
if [[ $MODRINTH_PROJECTS ]] && isFamily HYBRID FORGE FABRIC SPIGOT; then
|
2022-09-05 23:21:11 +00:00
|
|
|
if isFamily HYBRID FORGE; then
|
2022-06-27 14:08:21 +00:00
|
|
|
loader=forge
|
2023-03-18 03:15:01 +00:00
|
|
|
elif isFamily FABRIC; then
|
2023-03-05 14:55:19 +00:00
|
|
|
loader=fabric
|
2022-06-27 14:08:21 +00:00
|
|
|
else
|
2023-03-05 14:55:19 +00:00
|
|
|
# we're left with Bukkit/Spigot down-lines where plugins seem to be
|
|
|
|
loader="${TYPE,,}"
|
2022-06-27 14:08:21 +00:00
|
|
|
fi
|
|
|
|
mc-image-helper modrinth \
|
|
|
|
--output-directory=/data \
|
|
|
|
--projects="${MODRINTH_PROJECTS}" \
|
2023-06-17 18:00:22 +00:00
|
|
|
--game-version="${VERSION}" \
|
2022-06-27 14:08:21 +00:00
|
|
|
--loader="$loader" \
|
2023-09-09 13:37:46 +00:00
|
|
|
--download-dependencies="$MODRINTH_DOWNLOAD_DEPENDENCIES" \
|
2022-06-27 14:08:21 +00:00
|
|
|
--allowed-version-type="$MODRINTH_ALLOWED_VERSION_TYPE"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-08-06 20:12:29 +00:00
|
|
|
function handleCurseForgeFiles() {
|
|
|
|
args=()
|
|
|
|
if usesMods && ! usesPlugins; then
|
|
|
|
args+=(--default-category mc-mods)
|
|
|
|
elif usesPlugins && ! usesMods; then
|
|
|
|
args+=(--default-category bukkit-plugins)
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "${TYPE,,}" in
|
|
|
|
forge|fabric|quilt)
|
|
|
|
args+=(--mod-loader "$TYPE")
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
# since we want CURSEFORGE_FILES to expand
|
|
|
|
mc-image-helper curseforge-files \
|
|
|
|
"${args[@]}" \
|
|
|
|
${CURSEFORGE_FILES}
|
|
|
|
}
|
|
|
|
|
2022-09-10 17:58:32 +00:00
|
|
|
handlePackwiz
|
|
|
|
|
2023-06-10 17:51:49 +00:00
|
|
|
handleModpackZip
|
|
|
|
|
|
|
|
handleListings
|
2022-09-10 17:58:32 +00:00
|
|
|
|
2023-08-06 20:12:29 +00:00
|
|
|
if [[ $MANIFEST ]]; then
|
|
|
|
log "ERROR: MANIFEST is no longer supported."
|
|
|
|
log " Use MOD_PLATFORM=AUTO_CURSEFORGE and CF_MODPACK_MANIFEST instead"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $MODS_FORGEAPI_KEY || $MODS_FORGEAPI_FILE || $MODS_FORGEAPI_PROJECTIDS ]]; then
|
|
|
|
log "ERROR the MODS_FORGEAPI_FILE / MODS_FORGEAPI_PROJECTIDS feature is no longer supported"
|
|
|
|
log " Use CURSEFORGE_FILES instead."
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-09-10 17:58:32 +00:00
|
|
|
|
2023-03-05 14:55:19 +00:00
|
|
|
handleGenericPacks
|
2022-06-27 14:08:21 +00:00
|
|
|
|
2023-03-05 14:55:19 +00:00
|
|
|
handleModrinthProjects
|
2019-09-29 16:45:21 +00:00
|
|
|
|
2023-08-06 20:12:29 +00:00
|
|
|
if usesMods || usesPlugins; then
|
|
|
|
handleCurseForgeFiles
|
|
|
|
fi
|
|
|
|
|
2021-10-25 01:23:21 +00:00
|
|
|
exec "${SCRIPTS:-/}start-setupModconfig" "$@"
|