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}"
|
|
|
|
: "${MODS_FILE:=}"
|
|
|
|
: "${REMOVE_OLD_MODS_DEPTH:=1} "
|
|
|
|
: "${REMOVE_OLD_MODS_INCLUDE:=*.jar}"
|
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
|
2021-04-28 21:29:47 +00:00
|
|
|
removeOldMods /data/mods
|
|
|
|
removeOldMods /data/plugins
|
2022-01-06 03:38:51 +00:00
|
|
|
rm -f "$sum_file"
|
2018-10-12 22:11:57 +00:00
|
|
|
fi
|
|
|
|
|
2021-12-07 03:40:00 +00:00
|
|
|
# If packwiz url passed, bootstrap packwiz and update mods before other modpack processing
|
|
|
|
if [[ "${PACKWIZ_URL}" ]]; then
|
|
|
|
# Ensure we have the latest packwiz bootstrap installer
|
2022-01-22 16:36:52 +00:00
|
|
|
latestPackwiz=$(curl -fsSL https://api.github.com/repos/packwiz/packwiz-installer-bootstrap/releases/latest)
|
2021-12-07 03:40:00 +00:00
|
|
|
if [[ -z "${latestPackwiz}" ]]; then
|
|
|
|
log "WARNING: Could not retrieve Packwiz bootstrap installer release information"
|
|
|
|
else
|
2022-02-05 18:38:33 +00:00
|
|
|
isDebugging && log "Latest packwiz ${latestPackwiz}"
|
2021-12-07 03:40:00 +00:00
|
|
|
latestPackwizVer=$(echo ${latestPackwiz} | jq --raw-output '.tag_name')
|
|
|
|
latestPackwizUrl=$(echo ${latestPackwiz} | jq --raw-output '.assets[] | select(.name | match("packwiz-installer-bootstrap.jar")) | .url')
|
|
|
|
: "${PACKWIZ_JAR:=packwiz-installer-bootstrap_${latestPackwizVer}.jar}"
|
|
|
|
if [[ ! -e $PACKWIZ_JAR ]]; then
|
|
|
|
log "Downloading Packwiz ${latestPackwizVer}"
|
|
|
|
curl -H "Accept:application/octet-stream" -o "$PACKWIZ_JAR" -fsSL ${latestPackwizUrl}
|
|
|
|
ln -sf "${PACKWIZ_JAR}" packwiz-installer-bootstrap.jar
|
|
|
|
fi
|
|
|
|
fi
|
2022-06-17 14:21:41 +00:00
|
|
|
if [[ ! -f packwiz-installer-bootstrap.jar ]]; then
|
2021-12-07 03:40:00 +00:00
|
|
|
log "ERROR: Packwiz not available or could not be downloaded from Github!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-04-24 20:51:12 +00:00
|
|
|
log "Running packwiz against URL: ${PACKWIZ_URL}"
|
|
|
|
java -jar packwiz-installer-bootstrap.jar -g -s server "${PACKWIZ_URL}"
|
2022-06-17 14:21:41 +00:00
|
|
|
#if bootstrap download fails, download installer manually - then run without updating
|
|
|
|
returnVal=$?
|
|
|
|
if [[ $returnVal ]]; then
|
|
|
|
latestPackwizInstaller=$(curl -fsSL https://api.github.com/repos/packwiz/packwiz-installer/releases/latest)
|
|
|
|
latestPackwizInstallerVer=$(echo ${latestPackwizInstaller} | jq --raw-output '.tag_name')
|
|
|
|
latestPackwizInstallerUrl=$(echo ${latestPackwizInstaller} | jq --raw-output '.assets[] | select(.name | match("packwiz-installer.jar")) | .url')
|
|
|
|
log "Packwiz couldn't update - Downloading Packwiz Installer ${latestPackwizInstallerVer}"
|
|
|
|
curl -H "Accept:application/octet-stream" -o "packwiz-installer.jar" -fsSL ${latestPackwizInstallerUrl}
|
|
|
|
java -jar packwiz-installer-bootstrap.jar -g -bootstrap-no-update -s server "${PACKWIZ_URL}"
|
|
|
|
fi
|
2021-12-07 03:40:00 +00:00
|
|
|
fi
|
|
|
|
|
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
|
2021-05-06 21:27:30 +00:00
|
|
|
mkdir -p /data/plugins
|
|
|
|
if ! unzip -o -d /data/plugins /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
|
|
|
|
mkdir -p /data/mods
|
|
|
|
if ! unzip -o -d /data/mods /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
|
2017-11-01 05:42:44 +00:00
|
|
|
|
2021-10-17 03:09:56 +00:00
|
|
|
elif [[ "$MODS" ]]; then
|
2022-01-17 02:49:15 +00:00
|
|
|
if [ "$FAMILY" = "SPIGOT" ]; then
|
2020-12-12 21:22:07 +00:00
|
|
|
out_dir=/data/plugins
|
|
|
|
else
|
|
|
|
out_dir=/data/mods
|
|
|
|
fi
|
|
|
|
mkdir -p "$out_dir"
|
|
|
|
|
2020-08-03 00:57:12 +00:00
|
|
|
for i in ${MODS//,/ }
|
|
|
|
do
|
2021-10-10 14:33:17 +00:00
|
|
|
if isURL "$i"; then
|
2020-12-12 21:22:07 +00:00
|
|
|
log "Downloading mod/plugin $i ..."
|
2022-02-06 23:46:17 +00:00
|
|
|
if ! get --skip-up-to-date -o "${out_dir}" "$i"; then
|
2021-10-10 14:33:17 +00:00
|
|
|
log "ERROR: failed to download from $i into $out_dir"
|
|
|
|
exit 2
|
2018-10-12 22:11:57 +00:00
|
|
|
fi
|
2021-05-13 01:41:28 +00:00
|
|
|
elif [[ -f "$i" && "$i" =~ .*\.jar ]]; then
|
2021-05-06 21:27:30 +00:00
|
|
|
log "Copying plugin located at $i ..."
|
|
|
|
out_file=$(basename "$i")
|
|
|
|
if ! cp "$i" "${out_dir}/$out_file"; then
|
|
|
|
log "ERROR: failed to copy from $i into $out_dir"
|
|
|
|
exit 2
|
|
|
|
fi
|
2021-05-13 01:41:28 +00:00
|
|
|
elif [[ -d "$i" ]]; then
|
|
|
|
log "Copying plugin jars from $i ..."
|
|
|
|
cp "$i"/*.jar "${out_dir}"
|
2020-08-03 00:57:12 +00:00
|
|
|
else
|
2021-05-13 01:41:28 +00:00
|
|
|
log "ERROR Invalid URL or path given in MODS: $i"
|
2020-12-12 21:22:07 +00:00
|
|
|
exit 2
|
2020-08-03 00:57:12 +00:00
|
|
|
fi
|
|
|
|
done
|
2018-10-12 22:11:57 +00:00
|
|
|
|
2021-10-17 03:09:56 +00:00
|
|
|
elif [[ "$MODS_FILE" ]]; then
|
2021-10-15 23:42:44 +00:00
|
|
|
if [ ! -f "$MODS_FILE" ]; then
|
|
|
|
log "ERROR: given MODS_FILE file does not exist"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2022-01-17 02:49:15 +00:00
|
|
|
if [ "$FAMILY" = "SPIGOT" ]; then
|
2021-10-15 23:42:44 +00:00
|
|
|
out_dir=/data/plugins
|
|
|
|
else
|
|
|
|
out_dir=/data/mods
|
|
|
|
fi
|
|
|
|
mkdir -p "$out_dir"
|
|
|
|
|
|
|
|
args=(
|
|
|
|
-o "${out_dir}"
|
|
|
|
--log-progress-each
|
2022-02-06 23:46:17 +00:00
|
|
|
--skip-up-to-date
|
2021-10-15 23:42:44 +00:00
|
|
|
--uris-file "${MODS_FILE}"
|
|
|
|
)
|
|
|
|
if isTrue "${REMOVE_OLD_MODS}"; then
|
|
|
|
args+=(
|
|
|
|
--prune-others "${REMOVE_OLD_MODS_INCLUDE}"
|
|
|
|
--prune-depth "${REMOVE_OLD_MODS_DEPTH}"
|
|
|
|
)
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! get "${args[@]}" ; then
|
|
|
|
log "ERROR: failed to retrieve one or more mods"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-02-08 13:11:01 +00:00
|
|
|
if [[ "$MANIFEST" ]]; then
|
2019-11-21 19:50:06 +00:00
|
|
|
if [[ -e "$MANIFEST" ]]; then
|
|
|
|
EFFECTIVE_MANIFEST_FILE=$MANIFEST
|
|
|
|
elif isURL "$MANIFEST"; then
|
|
|
|
EFFECTIVE_MANIFEST_FILE=/tmp/manifest.json
|
2020-12-12 21:22:07 +00:00
|
|
|
EFFECTIVE_MANIFEST_URL=$(curl -Ls -o /dev/null -w %{effective_url} $MANIFEST)
|
2019-11-21 19:50:06 +00:00
|
|
|
curl -Ls -o $EFFECTIVE_MANIFEST_FILE "$EFFECTIVE_MANIFEST_URL"
|
|
|
|
else
|
2020-03-06 15:52:17 +00:00
|
|
|
log "MANIFEST='$MANIFEST' is not a valid manifest url or location"
|
2019-11-21 19:50:06 +00:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "X$EFFECTIVE_MANIFEST_FILE" in
|
2019-02-08 13:11:01 +00:00
|
|
|
X*.json)
|
2019-11-21 19:50:06 +00:00
|
|
|
if [ -f "${EFFECTIVE_MANIFEST_FILE}" ]; then
|
2019-02-15 03:04:09 +00:00
|
|
|
MOD_DIR=${FTB_BASE_DIR:-/data}/mods
|
2019-02-15 03:18:16 +00:00
|
|
|
if [ ! -d "$MOD_DIR" ]
|
|
|
|
then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Creating mods dir $MOD_DIR"
|
2019-02-15 03:18:16 +00:00
|
|
|
mkdir -p "$MOD_DIR"
|
|
|
|
fi
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Starting manifest download..."
|
2019-11-21 19:50:06 +00:00
|
|
|
cat "${EFFECTIVE_MANIFEST_FILE}" | jq -r '.files[] | (.projectID|tostring) + " " + (.fileID|tostring)'| while read -r p f
|
2019-02-08 13:11:01 +00:00
|
|
|
do
|
2019-02-08 16:31:40 +00:00
|
|
|
if [ ! -f $MOD_DIR/${p}_${f}.jar ]
|
|
|
|
then
|
2020-12-12 21:22:07 +00:00
|
|
|
redirect_url="$(curl -Ls -o /dev/null -w %{effective_url} ${CURSE_URL_BASE}/${p})"
|
2019-08-02 16:28:35 +00:00
|
|
|
url="$redirect_url/download/${f}/file"
|
2020-03-06 15:52:17 +00:00
|
|
|
log Downloading curseforge mod $url
|
2019-02-08 16:31:40 +00:00
|
|
|
# Manifest usually doesn't have mod names. Using id should be fine, tho
|
|
|
|
curl -sSL "${url}" -o $MOD_DIR/${p}_${f}.jar
|
|
|
|
fi
|
2019-02-08 13:11:01 +00:00
|
|
|
done
|
|
|
|
else
|
2021-10-15 23:42:44 +00:00
|
|
|
log "Could not find manifest file, insufficient privileges, or malformed path."
|
2019-02-08 13:11:01 +00:00
|
|
|
fi
|
2019-02-08 13:18:18 +00:00
|
|
|
;;
|
2019-02-08 13:11:01 +00:00
|
|
|
*)
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Invalid manifest file for modpack. Please make sure it is a .json file."
|
2019-02-08 13:11:01 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2022-06-27 14:08:21 +00:00
|
|
|
function genericPacks() {
|
|
|
|
: "${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-06-27 14:08:21 +00:00
|
|
|
# recalculate the actual base directory of content
|
|
|
|
base_dir=$(find "$base_dir" -maxdepth 3 -type d \( -name mods -o -name plugins -o -name config \) -printf '%h' -quit)
|
|
|
|
if [[ ! $base_dir ]]; then
|
|
|
|
log "ERROR: Unable to find content base of generic packs ${GENERIC_PACKS}. Directories:"
|
|
|
|
find $original_base_dir -maxdepth 3 -type d -printf ' - %P\n'
|
|
|
|
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
|
|
|
|
|
|
|
|
log "Saving generic pack(s) checksum"
|
|
|
|
sha1sum "${packFiles[@]}" > "${sum_file}"
|
|
|
|
isDebugging && cat "$sum_file"
|
|
|
|
fi
|
2019-09-29 16:45:21 +00:00
|
|
|
fi
|
2022-06-27 14:08:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function modrinthProjects() {
|
|
|
|
: "${MODRINTH_PROJECTS:=}"
|
|
|
|
: "${MODRINTH_DOWNLOAD_OPTIONAL_DEPENDENCIES:=true}"
|
|
|
|
: "${MODRINTH_ALLOWED_VERSION_TYPE:=release}"
|
|
|
|
|
|
|
|
if [[ $MODRINTH_PROJECTS ]] && isFamily HYBRID FABRIC; then
|
|
|
|
if [[ ${FAMILY^^} = HYBRID ]]; then
|
|
|
|
loader=forge
|
|
|
|
else
|
|
|
|
loader="${FAMILY,,}"
|
|
|
|
fi
|
|
|
|
mc-image-helper modrinth \
|
|
|
|
--output-directory=/data \
|
|
|
|
--projects="${MODRINTH_PROJECTS}" \
|
|
|
|
--game-version="${VANILLA_VERSION}" \
|
|
|
|
--loader="$loader" \
|
|
|
|
--download-optional-dependencies="$MODRINTH_DOWNLOAD_OPTIONAL_DEPENDENCIES" \
|
|
|
|
--allowed-version-type="$MODRINTH_ALLOWED_VERSION_TYPE"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
genericPacks
|
|
|
|
|
|
|
|
modrinthProjects
|
2019-09-29 16:45:21 +00:00
|
|
|
|
2021-10-25 01:23:21 +00:00
|
|
|
exec "${SCRIPTS:-/}start-setupModconfig" "$@"
|