diff --git a/scripts/start-setupModpack b/scripts/start-setupModpack index e51de5afed0..5662c536f04 100755 --- a/scripts/start-setupModpack +++ b/scripts/start-setupModpack @@ -25,20 +25,7 @@ fi # 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 - if [[ "${GH_TOKEN:-}" ]]; then - # User has provided a Personal Access Token to mitigate rate-limiting issues - oAuthScopes="undefined" - oAuthScopes=$(curl -sv -H "Authorization: token $GH_TOKEN" https://api.github.com/users/codertocat -I | grep x-oauth-scopes) - if [[ ! "$oAuthScopes" =~ ^x-oauth-scopes:[[:space:]]*$ ]]; then - # Don't use what you don't have to... - log "ERROR: GH_TOKEN has permissions it doesn't need. Recreate or update this personal access token and disable ALL scopes." - exit 1 - else - latestPackwiz=$(curl -fsSL -H "Authorization: token $GH_TOKEN" https://api.github.com/repos/packwiz/packwiz-installer-bootstrap/releases/latest) - fi - else - latestPackwiz=$(curl -fsSL https://api.github.com/repos/packwiz/packwiz-installer-bootstrap/releases/latest) - fi + latestPackwiz=$(get_from_gh "https://api.github.com/repos/packwiz/packwiz-installer-bootstrap/releases/latest") if [[ -z "${latestPackwiz}" ]]; then log "WARNING: Could not retrieve Packwiz bootstrap installer release information" else @@ -59,11 +46,11 @@ if [[ "${PACKWIZ_URL:-}" ]]; then #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) + latestPackwizInstaller=$(get_from_gh "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}" + get_from_gh "${latestPackwizInstallerUrl}" -H "Accept:application/octet-stream" -o "packwiz-installer.jar" java -jar "${PACKWIZ_BOOTSTRAP_JAR}" -g -bootstrap-no-update -s server "${PACKWIZ_URL}" fi fi diff --git a/scripts/start-utils b/scripts/start-utils index a4102f9acba..932fd70d423 100755 --- a/scripts/start-utils +++ b/scripts/start-utils @@ -1,5 +1,23 @@ #!/bin/bash +function get_from_gh() { + if [[ "${GH_TOKEN:-}" ]]; then + # User has provided a Personal Access Token to mitigate rate-limiting issues + if [[ -z "${oAuthScopes}" ]]; then + oAuthScopes=$(curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/codertocat -I | grep x-oauth-scopes) + fi + if [[ ! "$oAuthScopes" =~ ^x-oauth-scopes:[[:space:]]*$ ]]; then + # Don't use what you don't have to... + log "ERROR: GH_TOKEN has permissions it doesn't need. Recreate or update this personal access token and disable ALL scopes." + exit 1 + else + echo $(curl -fsSL -H "Authorization: token $GH_TOKEN" ${@:2} $1) + fi + else + echo $(curl -fsSL ${@:2} $1) + fi +} + function join_by() { local d=$1 shift @@ -291,7 +309,7 @@ function checkSum() { # Get distro distro=$(getDistro) - + if [ "${distro}" == "debian" ] && sha1sum -c "${sum_file}" --status 2> /dev/null; then return 0 elif [ "${distro}" == "ubuntu" ] && sha1sum -c "${sum_file}" --status 2> /dev/null; then