Botspot / pi-apps

Raspberry Pi App Store for Open Source Projects
GNU General Public License v3.0
2.04k stars 206 forks source link

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

Open janAkali opened 1 year ago

janAkali commented 1 year ago

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[bot] commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago
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 commented 1 year ago

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

theofficialgman commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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[bot] commented 1 year ago

A zipfile was found in the body of your issue. The sha1sum of the zip was: 1f96a6f62d289b6744b7486f5eabbfa518e55855 The contents can be previewed below:

Forge/description

Forge is a "Rules Engine" for the most popular card game Magic: the Gathering.
It is a snapshot version which is updated regularly, just reinstall the app to update it.

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 now 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: bash -c ~/MTG-Forge/forge.sh
Start with Mobile  UI in terminal: bash -c ~/MTG-Forge/forge-mobile.sh

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

Forge/credits

Script Created By ArcharGelod

Forge/website

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

Forge/uninstall

#!/bin/bash

#remove game
rm -rf "$HOME/MTG-Forge"

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

#Allow packages required by this app to be uninstalled
purge_packages || exit 1

Forge/install

#!/bin/bash

game_folder="$HOME/MTG-Forge"
snapshot_server="https://downloads.cardforge.org/dailysnapshots"
VERSION=$(curl "$snapshot_server/version.txt")
archive_name="forge-gui-desktop-${VERSION}.tar.bz2"

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

#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

#check if folder already exists (unlikely, but just in case)
if [[ -d "$game_folder" ]]; then
  printf "\nFound existing MTG-Forge directory in $HOME !!!\nIt will be moved to /tmp/MTG-Forge-old !!!\n"
  mv    "$game_folder" /tmp/MTG-Forge-old || error 'Failed to move MTG-Forge directory to /tmp/ !'
fi

mkdir   "$game_folder"
tar -xvf "/tmp/forge-gui-desktop-${VERSION}.tar.bz2" --directory="$game_folder" || error 'Failed to extract snapshot archive!'

#fix adventure shell script by copying the default forge.sh 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"

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

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

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 commented 1 year ago

@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

https://github.com/Botspot/pi-apps/blob/97bcb5208a9d6bfd1b9f27a701e51ea3bfa74e7f/apps/Minecraft%20Java%20Prism%20Launcher/install-64#L16-L29

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 commented 2 months ago

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

janAkali commented 2 months ago

@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