Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MTG Forge - script to install App from official ftp server #2264

Open
3 tasks done
janAkali opened this issue Feb 17, 2023 · 13 comments · May be fixed by #2640
Open
3 tasks done

MTG Forge - script to install App from official ftp server #2264

janAkali opened this issue Feb 17, 2023 · 13 comments · May be fixed by #2640

Comments

@janAkali
Copy link

janAkali commented Feb 17, 2023

What is the name of the app?

Forge

(Optional) Where is the app hosted?

https://downloads.cardforge.org/dailysnapshots/
https://github.com/Card-Forge/forge

About the app

Unofficial MTG Game/Rules Engine
Runs on Java VM, so this game supports both 32 and 64-bit architectures.
Snapshot version, because releases are quickly outdated. Snapshots aren't automatic, they're tested before uploads.

Upload file or Add PR Link

Forge.zip

Confirmations

@github-actions
Copy link
Contributor

Hello there 👋
Thanks for submitting your first issue to the Pi-Apps project! We'll try to get back to you as soon as possible.
In the meantime, we encourage you join our Discord server, where you can ask any questions you might have.

@theofficialgman
Copy link
Collaborator

multiple issues with this app request

game_folder="$HOME/MTG-Forge"
snapshot_server="https://downloads.cardforge.org/dailysnapshots"
VERSION=$(curl "$snapshot_server/version.txt")

this downloads the latest snapshot at install time but the users install will be outdated once the next snapshot comes output. please move checking for a version to an auto update script and hardcode the version in the install script. the auto update will update the version as necessary.

#install_packages sed openjdk-17-jre || exit 1

why this this commented out? also openjdk-17 is not available on all OSs that we support. search pi-apps for temurin and you will find multiple scripts that use their jres and add the apt repo as necessary

#test for aria2, because wget can be very slow
if command -v aria2c; then
  aria2c -x 6 -k 1M -c "$snapshot_server/$archive_name" -d /tmp || error 'Failed to download latest snapshot!'
else
  wget -c "$snapshot_server/$archive_name" --directory-prefix /tmp || error 'Failed to download latest snapshot!'
fi

pi-apps automatically overrides wget in scripts with aria2c, please remove this

@theofficialgman
Copy link
Collaborator

game_folder="$HOME/MTG-Forge"

please avoid installing programs into the users home directory.

if it is desired that the user have write permissions into the program folder, then place it in ~/.local/share, otherwise place it in root owned /usr/local/share and change the .desktop files into /usr/local/share/applications as well.

@janAkali
Copy link
Author

janAkali commented Feb 18, 2023

please move checking for a version to an auto update script and hardcode the version in the install script. the auto update will update the version as necessary.

Fixed - I added auto-update script that changes version string variable

#install_packages sed openjdk-17-jre || exit 1
why this this commented out?

Sorry. I temporary edited it out for testing. And in the last moment forgot to revert it.

also openjdk-17 is not available on all OSs that we support. search pi-apps for temurin and you will find multiple scripts that use their jres and add the apt repo as necessary

Fixed (needs testing) - I used part of "Minecraft Java Prism Launcher" script to check for OS version and add repo if needed.

#test for aria2, because wget can be very slow
pi-apps automatically overrides wget in scripts with aria2c, please remove this

I removed this part.

game_folder="$HOME/MTG-Forge"
please avoid installing programs into the users home directory.

Fixed - I've set game_folder to "$HOME/.local/usr/share/mtg-forge"
User should have write access to folder for modding purposes, for example - forge/wiki/Create-Enemies

and change the .desktop files into /usr/local/share/applications as well.

Fixed

Forge.zip

@janAkali janAkali reopened this Feb 18, 2023
@theofficialgman
Copy link
Collaborator

Fixed - I've set game_folder to "$HOME/.local/usr/share/mtg-forge" User should have write access to folder for modding purposes, for example - forge/wiki/Create-Enemies

and change the .desktop files into /usr/local/share/applications as well.

no you misunderstood what I meant. only use the root owned /usr/local/share/applications if you place the app in /usr/local/share. your previous locations for the .desktop files were correct with the gamefiles in ~/.local/share

also, and this is detrimental to inclusion in pi-apps, https://downloads.cardforge.org/dailysnapshots/ does not include previous days snapshots. so this app will break every day. github releases for this app also only include one version, older versions are deleted. this is not suitable for pi-apps, we need old versions to be cached as we only update apps weekly and users are not expected to always have the latest app versions on their local pi-apps installs.

I suggest you create an issue upstream to solve one or both of those issues. for now this is blocked.

@janAkali
Copy link
Author

janAkali commented Feb 19, 2023

github releases for this app also only include one version, older versions are deleted.

I don't believe this is true, the only available release right now is actually the very first release of Forge on Github. Earlier versions were published on slightly magic forums. But releases are rare, maybe twice a year?

I suggest you create an issue upstream

Here's the Issue I opened.

In the meantime I made this repo - forge-snapshot-archive, with a simple workflow, that downloads snapshots daily and publishes them as releases.
And I rewrote install/update scripts to use it.
Or, it is too janky for pi-apps? = )

Forge.zip

@janAkali
Copy link
Author

janAkali commented Mar 4, 2023

Sorry for the delay. It seems Forge won't make previous snapshots available.
But, at least, releases are gonna be, well, released more often. That, I think, should be enough for most users.

I updated script to install stable version of forge from official repo releases page.
I also added a simple cleanup trap to the install script.

Forge.zip

@theofficialgman
Copy link
Collaborator

In the meantime I made this repo - forge-snapshot-archive, with a simple workflow, that downloads snapshots daily and publishes them as releases. And I rewrote install/update scripts to use it. Or, it is too janky for pi-apps? = )

sorry for the long time without a response. I saw your issue you made upstream and appreciate the dialog you had there.

it looks like upstream is going to do better about publishing stable releases to their github so I would prefer that those be used. while your forge-sanpshot-archive repo could be used, yes its a bit too janky for me to include since neither pi-apps nor the app maintainer controls it. I think the daily snapshots might be too unstable for general users on pi-apps anyway.

@github-actions

This comment was marked as outdated.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2023

A zipfile was found in the body of an issue comment.
The sha1sum of the zip was: 95ae56d0c22eb05903a8dec76840cedbfa2dae9a
The contents can be previewed below:

apps/Forge/description

Forge is a "Rules Engine" for the most popular card game Magic: the Gathering.

Forge creates a unique experience by combining an enormous card library with some RPG elements in Quest mode (comparable to the 'Shandalar', the late 90's PC Game) and Planar Conquest on the mobile version. 
Forge also includes a Graphical Map Based game mode called "Adventure Mode", which is more akin to 'Shandalar.' (Only in Mobile UI version)

Start Forge with Desktop UI: Menu -> Games -> MTG Forge
Start Forge with Mobile  UI: Menu -> Games -> MTG Forge Adventure
Start with Desktop UI in terminal: ~/.local/share/mtg-forge/forge.sh
Start with Mobile  UI in terminal: ~/.local/share/mtg-forge/forge-mobile.sh
Start Simulation mode in terminal: ~/.local/share/mtg-forge/forge.sh sim

Forge is open source software released under the GNU Public License and not related in any way with Wizards of the Coast.

apps/Forge/credits

Script created by ArcharGelod

apps/Forge/website

https://github.com/Card-Forge/forge/wiki

apps/Forge/uninstall

#!/bin/bash

purge_packages || exit 1
remove_repofile_if_unused /etc/apt/sources.list.d/adoptium.list

#remove game folder
rm -rf "$HOME/.local/share/mtg-forge"

#remove desktop menu entries
rm -f "$HOME/.local/share/applications/Forge.desktop"
rm -f "$HOME/.local/share/applications/Forge-Adventure.desktop"

apps/Forge/install

#!/bin/bash
version=forge-1.6.55
subversion=${version/forge-} #bash trick to remove "forge-" from string

game_folder="$HOME/.local/share/mtg-forge"
repo_url="https://github.com/card-forge/forge/releases/download/${version}"
archive_name="forge-gui-desktop-${subversion}.tar.bz2"

#cleanup
trap "rm -f /tmp/$archive_name; exit" EXIT

status "Installing Java 17"
# first check if lsb_release has an upstream option -u
# if not, check if there is an upstream-release file
# if not, check if there is a lsb-release.diverted file
# if not, assume that this is not a ubuntu derivative
if lsb_release -a -u &>/dev/null; then
  # This is a Ubuntu Derivative, checking the upstream-release version info
  __os_id="$(lsb_release -s -i -u)"
  __os_desc="$(lsb_release -s -d -u)"
  __os_release="$(lsb_release -s -r -u)"
  __os_codename="$(lsb_release -s -c -u)"
elif [ -f /etc/upstream-release/lsb-release ]; then
  # ubuntu 22.04+ linux mint no longer includes the lsb_release -u option
  # add a parser for the /etc/upstream-release/lsb-release file
  source /etc/upstream-release/lsb-release
  __os_id="$DISTRIB_ID"
  __os_desc="$DISTRIB_DESCRIPTION"
  __os_release="$DISTRIB_RELEASE"
  __os_codename="$DISTRIB_CODENAME"
  unset DISTRIB_ID DISTRIB_DESCRIPTION DISTRIB_RELEASE DISTRIB_CODENAME
elif [ -f /etc/lsb-release.diverted ]; then
  # ubuntu 22.04+ popOS no longer includes the /etc/upstream-release/lsb-release or the lsb_release -u option
  # add a parser for the new /etc/lsb-release.diverted file
  source /etc/lsb-release.diverted
  __os_id="$DISTRIB_ID"
  __os_desc="$DISTRIB_DESCRIPTION"
  __os_release="$DISTRIB_RELEASE"
  __os_codename="$DISTRIB_CODENAME"
  unset DISTRIB_ID DISTRIB_DESCRIPTION DISTRIB_RELEASE DISTRIB_CODENAME
else
  __os_id="$(lsb_release -s -i)"
  __os_desc="$(lsb_release -s -d)"
  __os_release="$(lsb_release -s -r)"
  __os_codename="$(lsb_release -s -c)"
fi

case "$__os_id" in
# Raspbian is not reported as a derivative of Debian (no /etc/upstream-release/lsb-release file)
Raspbian | Debian)
  case "$__os_codename" in
  bullseye | buster)
    install_packages lsb-release sed wget apt-transport-https gnupg || error "Failed to install dependencies"
    hash -r

    status "Adding Adoptium repository:"

    echo "- public key -> keyring"
    rm -f /tmp/adoptium-public-key /tmp/adoptium-archive-keyring.gpg
    wget -O /tmp/adoptium-public-key https://adoptium.jfrog.io/artifactory/api/security/keypair/default-gpg-key/public
    gpg --no-default-keyring --keyring /tmp/adoptium-keyring.gpg --import /tmp/adoptium-public-key
    rm -f /tmp/adoptium-public-key

    echo " - keyring -> GPG key"
    gpg --no-default-keyring --keyring /tmp/adoptium-keyring.gpg --export --output /tmp/adoptium-archive-keyring.gpg
    rm -f /tmp/adoptium-keyring.gpg

    echo " - Moving GPG key to /usr/share/keyrings"
    sudo mv -f /tmp/adoptium-archive-keyring.gpg /usr/share/keyrings

    echo " - Creating /etc/apt/sources.list.d/adoptium.list"
    echo "deb [signed-by=/usr/share/keyrings/adoptium-archive-keyring.gpg] https://adoptium.jfrog.io/artifactory/deb $__os_codename main" | sudo tee /etc/apt/sources.list.d/adoptium.list >/dev/null

    echo " - Installing temurin-17-jre"
    #try to install temurin and adoptopenjdk java versions; if it fails, remove repository to avoid breaking user's system
    (install_packages temurin-17-jre)
    if [ $? != 0 ]; then
      anything_installed_from_repo "https://adoptium.jfrog.io/artifactory/deb"
      if [ $? != 0 ]; then
        # nothing installed from repo, this check is to prevent removing repos which other pi-apps scripts or the user have used successfully
        # safe to remove
        sudo rm -f /etc/apt/sources.list.d/adoptium.list /usr/share/keyrings/adoptium-archive-keyring.gpg
      fi
      warning "Failed to install temurin packages. Adoptium repository has been removed." && warning "It is up to you to download and install a working java 17 version." && echo "" && warning "Continuing the install without them."
    fi
    ;;
  bookworm | sid)
    warning "You are running Debian $__os_codename which is an unstable repo, you may not have Java 17 installed by this script."
    package_available openjdk-17-jre
    if [[ $? == "0" ]]; then
      install_packages openjdk-17-jre || warning "Failed to install install a working java 17. You will have to install one yourself. Continuing the install without them."
    fi
    ;;
  *)
    error "Debian version ($__os_codename) is too old, update to debian Buster or newer"
    ;;
  esac
  ;;
Kali)
  install_packages sed wget apt-transport-https gnupg || error "Failed to install dependencies"
  hash -r

  status "Adding Adoptium repository:"

  echo "- public key -> keyring"
  rm -f /tmp/adoptium-public-key /tmp/adoptium-archive-keyring.gpg
  wget -O /tmp/adoptium-public-key https://adoptium.jfrog.io/artifactory/api/security/keypair/default-gpg-key/public
  gpg --no-default-keyring --keyring /tmp/adoptium-keyring.gpg --import /tmp/adoptium-public-key
  rm -f /tmp/adoptium-public-key

  echo " - keyring -> GPG key"
  gpg --no-default-keyring --keyring /tmp/adoptium-keyring.gpg --export --output /tmp/adoptium-archive-keyring.gpg
  rm -f /tmp/adoptium-keyring.gpg

  echo " - Moving GPG key to /usr/share/keyrings"
  sudo mv -f /tmp/adoptium-archive-keyring.gpg /usr/share/keyrings

  echo " - Creating /etc/apt/sources.list.d/adoptium.list"
  echo "deb [signed-by=/usr/share/keyrings/adoptium-archive-keyring.gpg] https://adoptium.jfrog.io/artifactory/deb buster main" | sudo tee /etc/apt/sources.list.d/adoptium.list >/dev/null

  echo " - Installing temurin-17-jre"
  #try to install temurin and adoptopenjdk java versions; if it fails, remove repository to avoid breaking user's system
  (install_packages temurin-17-jre)
  if [ $? != 0 ]; then
    anything_installed_from_repo "https://adoptium.jfrog.io/artifactory/deb"
    if [ $? != 0 ]; then
      # nothing installed from repo, this check is to prevent removing repos which other pi-apps scripts or the user have used successfully
      # safe to remove
      sudo rm -f /etc/apt/sources.list.d/adoptium.list /usr/share/keyrings/adoptium-archive-keyring.gpg
    fi
    warning "Failed to install temurin packages. Adoptium repository has been removed." && warning "It is up to you to download and install a working java version." && echo "" && warning "Continuing the install without them."
  fi
  ;;
Ubuntu)
  # ubuntu default repositories now include openjdk-8 openjdk-11 and openjdk-17
  install_packages openjdk-17-jre || error "Failed to install java 17"
  ;;
*)
  error "$__os_id appears to be an unsupported OS"
  ;;
esac

status "Downloading snapshot archive."
[[ -f "/tmp/$archive_name" ]] && rm -f "/tmp/$archive_name"
wget "$repo_url/$archive_name" --directory-prefix /tmp || error 'Failed to download latest release!'

# check if folder already exists (unlikely, but just in case)
if [[ -d "$game_folder" ]]; then
  warning "Found existing Forge directory in $game_folder !!!" && echo "It will be moved to /tmp/mtg-forge-old !!!"
  mv 	"$game_folder" /tmp/MTG-Forge-old || error "Failed to move $game_folder directory to /tmp/ !!! Please, move or delete it yourself and then try installing again."
fi

mkdir	"$game_folder"

status "Extracting the game archive."
tar -xvf "/tmp/forge-gui-desktop-${subversion}.tar.bz2" --directory="$game_folder" || error 'Failed to extract the game archive!'

# add $@ after .jar to pass cli arguments in bash script
status "Fixing currently broken cli simulation mode"
sed -i 's|\$SHAREDPARAMS$|& '\$\@'|' "$game_folder/forge.sh"

# replace broken forge-adventure.sh script with a copy of working forge.sh script
status "Fixing currently broken adventure shell script."
jarname="$(find "$game_folder" -name 'forge-gui-mobile*.jar' | xargs basename)"
cp "$game_folder/forge.sh" "$game_folder/forge-mobile.sh"
sed -i "s|forge-gui-desktop-.*-jar-with-dependencies.jar|$jarname|" "$game_folder/forge-mobile.sh"

# create desktop menu entries
echo "[Desktop Entry]
Type=Application
Name=MTG Forge
GenericName=Forge
Comment=Rules Engine for MTG card game.
Path=$game_folder
Exec=$game_folder/forge.sh
Icon=$game_folder/res/skins/default/hd_logo.png
Terminal=false
Categories=Game;Java;
Keywords=MTG;Forge;Adventure;Card;Game;Magic
StartupNotify=true" > "$HOME/.local/share/applications/Forge.desktop"

echo "[Desktop Entry]
Type=Application
Name=MTG Forge Adventure
GenericName=Forge-mobile
Comment=Mobile UI version of Forge with the Adventure mode.
Path=$game_folder
Exec=$game_folder/forge-mobile.sh
Icon=$game_folder/res/skins/default/adv_logo.png
Terminal=false
Categories=Game;Java;
Keywords=MTG;Forge;Adventure;Card;Game;Magic
StartupNotify=true" > "$HOME/.local/share/applications/Forge-Adventure.desktop"

.github/workflows/updates/Forge.sh

#!/bin/bash

webVer=$(get_release card-forge/forge)

source $GITHUB_WORKSPACE/.github/workflows/update_github_script.sh

@theofficialgman
Copy link
Collaborator

theofficialgman commented Aug 5, 2023

@Archargelod upstream has been publishing to their github releases for a few stable releases now. I think those can be used.

also, installing java-17 has been greatly simplified with new functions added to pi-apps api
refer to the other pi-apps scripts for what to do

status "Installing Java 8 and 17"
case "$__os_id" in
# Raspbian is not reported as a derivative of Debian (no /etc/upstream-release/lsb-release file)
Raspbian | Debian | Kali)
adoptium_installer || exit 1
install_packages temurin-8-jre temurin-17-jre || exit 1
;;
Ubuntu)
install_packages openjdk-8-jre openjdk-17-jre || exit 1
;;
*)
error "$__os_id appears to be an unsupported OS"
;;
esac

also upstream needs to correct their .sh files to respect the JAVA_HOME variable if it is present. they directly call java which will be whatever the last version of java that is installed is.

@theofficialgman
Copy link
Collaborator

Please see the above comment and update the zip with the requested changes

@theofficialgman theofficialgman added changes requested and removed Upstream Bug something isn't working that can only be fixed upstream labels Aug 27, 2024
@janAkali
Copy link
Author

@theofficialgman
It should be more convenient to use pull requests, so we can move discussion here: #2640
And here is the upstream PR for "JAVA_HOME": Card-Forge/forge/pull/6008

@theofficialgman theofficialgman linked a pull request Aug 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants