Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: Linux Startup Script  (Read 7395 times)

Swanny

  • Ensign
  • *
  • Posts: 35
    • View Profile
Linux Startup Script
« on: August 28, 2012, 07:05:02 AM »

An updated start script for Linux which;
  • Changes into the install directory
  • Uses the XDG specifications for configuration and save locations creating directory as required
  • Uses the system Java

The first thing I do when updating Starfarer is to delete the included JRE for two reasons. First, in the Starfarer Linux zip file all the file (not directory) permissions under the jre_linux directory are "-rwxr--rwx" world writeable and executable for some reason which is a bit of a security risk. Second, most Linux distributions include Java and provide easy updates (even with Oracles nuisance distribution restrictions). I understand it's for ease of plug and play but none of the other Java based games I have include a JRE in the download and don't really have any users stuck in their forums.

Code
#!/bin/bash

#      _                           _
#  ___| |_ __ _ _ __ ___  ___  ___| |_ ___  _ __
# / __| __/ _` | '__/ __|/ _ \/ __| __/ _ \| '__|
# \__ \ || (_| | |  \__ \  __/ (__| || (_) | |
# |___/\__\__,_|_|  |___/\___|\___|\__\___/|_|
#

XDGDIR=${XDG_CONFIG_HOME:-$HOME/.config}
GAMEDIR="${XDGDIR}/starsector"
INSTDIR="`dirname $0`" ; cd "${INSTDIR}" ; INSTDIR="`pwd`"

[[ ! -d "${XDGDIR}" ]] && mkdir -m 0755 "${XDGDIR}"
[[ ! -d "${GAMEDIR}" ]] && mkdir -m 0755 "${GAMEDIR}"
[[ ! -d "${GAMEDIR}/saves" ]] && mkdir -m 0755 "${GAMEDIR}/saves"
[[ ! -d "${GAMEDIR}/screenshots" ]] && mkdir -m 0755 "${GAMEDIR}/screenshots"
[[ ! -d "${GAMEDIR}/mods" ]] && mkdir -m 0755 "${GAMEDIR}/mods"

JARPATH="janino.jar:commons-compiler.jar:commons-compiler-jdk.jar:starfarer.api.jar:starfarer_obf.jar:jogg-0.0.7.jar:jorbis-0.0.15.jar:json.jar:lwjgl.jar:jinput.jar:log4j-1.2.9.jar:lwjgl_util.jar:fs.sound_obf.jar:fs.common_obf.jar:xstream-1.4.10.jar"

java \
-server -XX:CompilerThreadPriority=1 \
-Djava.library.path="${INSTDIR}/native/linux" \
-Xms1536m -Xmx1536m -Xss2048k \
-classpath "${JARPATH}" \
-Dcom.fs.starfarer.settings.paths.saves="${GAMEDIR}/saves" \
-Dcom.fs.starfarer.settings.paths.screenshots="${GAMEDIR}/screenshots" \
-Dcom.fs.starfarer.settings.paths.mods="${GAMEDIR}/mods" \
-Dcom.fs.starfarer.settings.paths.logs="${GAMEDIR}" \
com.fs.starfarer.StarfarerLauncher

exit 0

This was originally appended here Separation between game data / user data topic but lost.

UPDATE 7 Feb 2013: Updated script for Starfarer to Starsector name change. Note that if you'd used the earlier starfarer version, the full path to the saved game continue is also saved in a separate .java/.userPrefs/com/fs/starfarer/prefs.xml file so you'll need so correct the path at <entry key="continue" value="path"/> from starfarer to starsector.
UPDATE 5 Nov 2014: Updated initial memory allocation pool to 1024M (maximum memory allocation pool was already 1024M) as default in 0.65.1a release.
UPDATE 15 Dec 2015: Added thread stack size to 1024K as default in 0.7.1a release.
UPDATE 27 Apr 2017: Note that as of 0.8a release if the system Java is not 7 then edit data/config/settings.json and change allowAnyJavaVersion to true.
UPDATE 4 Jun 2017: Increase memory allocations to 1536K as default in 0.8.1a release.
UPDATE 17 Nov 2018: Updated XStream jar version used in 0.9.0a release.
UPDATE 28 Mar 2021: Increase thread stack size to 2048K as default in 0.95a release.
UPDATE 27 Jan 2023: Removed "-XX:+CompilerThreadHintNoPreempt" option as depreciated in newer Java versions and only affected Solaris systems anyway.
UPDATE 22 May 2023: Ignored "-XX:MaxPermSize=128m" option added in 0.96a release as this option was removed with Java 8.

If you're trying to use Java 11 or newer (I didn't need to add any parameters for Java 8), use the workarounds from forum post Upgrading JRE, Obfuscator and starsector-fixes by necauqua. This was for Starsector 0.95a so some of the issues may be fixed in newer Starsector releases.
« Last Edit: May 23, 2023, 05:16:59 AM by Swanny »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Linux Startup Script
« Reply #1 on: August 28, 2012, 09:05:36 AM »

First, in the Starfarer Linux zip file all the file (not directory) permissions under the jre_linux directory are "-rwxr--rwx" world writeable and executable for some reason which is a bit of a security risk.

Thanks for pointing that out - added to the todo list. Done.


Interesting point about not shipping with a JRE. For me, it's a question of "what will work most of the time, and generate the least support requests". It also seems like a good idea to ship with the version of the JRE that the game was actually tested with. Still, definitely something to consider.
« Last Edit: August 28, 2012, 09:49:15 AM by Alex »
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: Linux Startup Script
« Reply #2 on: August 28, 2012, 11:27:48 AM »

Just FYI, Starfarer seems to be incompatible with Java 7, so if/when your distro upgrades you'll run into problems.

It also seems like a good idea to ship with the version of the JRE that the game was actually tested with. Still, definitely something to consider.
Will the bundled JRE be updated at some point? I believe the currently included one is 15 versions out of date. ;)
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Linux Startup Script
« Reply #3 on: August 28, 2012, 11:42:22 AM »

Just FYI, Starfarer seems to be incompatible with Java 7, so if/when your distro upgrades you'll run into problems.

Really? Do you remember what the error was? (Just curious, really - will have to deal with it one way or another, so no big deal if not.) Shouldn't be much trouble to get it running, though I'm surprised that it wouldn't "just work".

Will the bundled JRE be updated at some point? I believe the currently included one is 15 versions out of date. ;)

Yeah... Java 7 ought to offer a decent performance boost, so it's something we'll definitely look at. Just have to be careful to make sure it still works with Java 6 on OS X.
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: Linux Startup Script
« Reply #4 on: August 28, 2012, 11:49:38 AM »

Spoiler
[close]


This
link might be helpful. :)
Logged

736b

  • Lieutenant
  • **
  • Posts: 87
    • View Profile
Re: Linux Startup Script
« Reply #5 on: August 28, 2012, 11:53:18 AM »

Just FYI, Starfarer seems to be incompatible with Java 7, so if/when your distro upgrades you'll run into problems.

It's working fine here with IcedTea 7 on Debian, though.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Linux Startup Script
« Reply #6 on: August 28, 2012, 12:21:01 PM »

Spoiler
[close]


This
link might be helpful. :)

Ah, thanks - ought to be preemptively fixed (by telling it to use the legacy version of mergesort, but still.)
Logged

Swanny

  • Ensign
  • *
  • Posts: 35
    • View Profile
Re: Linux Startup Script
« Reply #7 on: February 07, 2013, 09:29:44 AM »

Just an update to this script since it hasn't been included in the last two releases and name change.

Code
#!/bin/bash

#      _                           _
#  ___| |_ __ _ _ __ ___  ___  ___| |_ ___  _ __
# / __| __/ _` | '__/ __|/ _ \/ __| __/ _ \| '__|
# \__ \ || (_| | |  \__ \  __/ (__| || (_) | |
# |___/\__\__,_|_|  |___/\___|\___|\__\___/|_|
#

XDGDIR=${XDG_CONFIG_HOME:-$HOME/.config}
GAMEDIR="${XDGDIR}/starsector"
INSTDIR="`dirname $0`" ; cd "${INSTDIR}" ; INSTDIR="`pwd`"

[[ ! -d "${XDGDIR}" ]] && mkdir -m 0755 "${XDGDIR}"
[[ ! -d "${GAMEDIR}" ]] && mkdir -m 0755 "${GAMEDIR}"
[[ ! -d "${GAMEDIR}/saves" ]] && mkdir -m 0755 "${GAMEDIR}/saves"
[[ ! -d "${GAMEDIR}/screenshots" ]] && mkdir -m 0755 "${GAMEDIR}/screenshots"
[[ ! -d "${GAMEDIR}/mods" ]] && mkdir -m 0755 "${GAMEDIR}/mods"

JARPATH="janino.jar:commons-compiler.jar:commons-compiler-jdk.jar:starfarer.api.jar:starfarer_obf.jar:jogg-0.0.7.jar:jorbis-0.0.15.jar:json.jar:lwjgl.jar:jinput.jar:log4j-1.2.9.jar:lwjgl_util.jar:fs.sound_obf.jar:fs.common_obf.jar:xstream-1.4.2.jar"

java \
-server -XX:CompilerThreadPriority=1 \
-XX:+CompilerThreadHintNoPreempt \
-Djava.library.path="${INSTDIR}/native/linux" \
-Xms512m -Xmx1024m \
-classpath "${JARPATH}" \
-Dcom.fs.starfarer.settings.paths.saves="${GAMEDIR}/saves" \
-Dcom.fs.starfarer.settings.paths.screenshots="${GAMEDIR}/screenshots" \
-Dcom.fs.starfarer.settings.paths.mods="${GAMEDIR}/mods" \
-Dcom.fs.starfarer.settings.paths.logs="${GAMEDIR}" \
com.fs.starfarer.StarfarerLauncher

exit 0

EDIT: Note that if you'd used the starfarer version, the full path to the saved game continue is also saved in a separate .java/.userPrefs/com/fs/starfarer/prefs.xml file so you'll need so correct the path at <entry key="continue" value="path"/> from starfarer to starsector.
« Last Edit: February 07, 2013, 06:29:56 PM by Swanny »
Logged

Trylobot

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1170
    • View Profile
    • Github profile
Re: Linux Startup Script
« Reply #8 on: October 23, 2014, 07:11:35 AM »

This thread helped me get it running the fastest; thanks for this.
Logged

MightyChristian

  • Ensign
  • *
  • Posts: 31
  • soli Deo gloria
    • View Profile
Re: Linux Startup Script
« Reply #9 on: January 21, 2023, 08:29:07 AM »

An updated start script for Linux which;
  • Changes into the install directory
  • Uses the XDG specifications for configuration and save locations creating directory as required
  • Uses the system Java

The first thing I do when updating Starfarer is to delete the included JRE for two reasons. First, in the Starfarer Linux zip file all the file (not directory) permissions under the jre_linux directory are "-rwxr--rwx" world writeable and executable for some reason which is a bit of a security risk. Second, most Linux distributions include Java and provide easy updates (even with Oracles nuisance distribution restrictions). I understand it's for ease of plug and play but none of the other Java based games I have include a JRE in the download and don't really have any users stuck in their forums.

Code
#!/bin/bash

#      _                           _
#  ___| |_ __ _ _ __ ___  ___  ___| |_ ___  _ __
# / __| __/ _` | '__/ __|/ _ \/ __| __/ _ \| '__|
# \__ \ || (_| | |  \__ \  __/ (__| || (_) | |
# |___/\__\__,_|_|  |___/\___|\___|\__\___/|_|
#

XDGDIR=${XDG_CONFIG_HOME:-$HOME/.config}
GAMEDIR="${XDGDIR}/starsector"
INSTDIR="`dirname $0`" ; cd "${INSTDIR}" ; INSTDIR="`pwd`"

[[ ! -d "${XDGDIR}" ]] && mkdir -m 0755 "${XDGDIR}"
[[ ! -d "${GAMEDIR}" ]] && mkdir -m 0755 "${GAMEDIR}"
[[ ! -d "${GAMEDIR}/saves" ]] && mkdir -m 0755 "${GAMEDIR}/saves"
[[ ! -d "${GAMEDIR}/screenshots" ]] && mkdir -m 0755 "${GAMEDIR}/screenshots"
[[ ! -d "${GAMEDIR}/mods" ]] && mkdir -m 0755 "${GAMEDIR}/mods"

JARPATH="janino.jar:commons-compiler.jar:commons-compiler-jdk.jar:starfarer.api.jar:starfarer_obf.jar:jogg-0.0.7.jar:jorbis-0.0.15.jar:json.jar:lwjgl.jar:jinput.jar:log4j-1.2.9.jar:lwjgl_util.jar:fs.sound_obf.jar:fs.common_obf.jar:xstream-1.4.10.jar"

java \
-server -XX:CompilerThreadPriority=1 \
-XX:+CompilerThreadHintNoPreempt \
-Djava.library.path="${INSTDIR}/native/linux" \
-Xms1536m -Xmx1536m -Xss2048k \
-classpath "${JARPATH}" \
-Dcom.fs.starfarer.settings.paths.saves="${GAMEDIR}/saves" \
-Dcom.fs.starfarer.settings.paths.screenshots="${GAMEDIR}/screenshots" \
-Dcom.fs.starfarer.settings.paths.mods="${GAMEDIR}/mods" \
-Dcom.fs.starfarer.settings.paths.logs="${GAMEDIR}" \
com.fs.starfarer.StarfarerLauncher

exit 0

This was originally appended here Separation between game data / user data topic but lost.

UPDATE 7 Feb 2013: Updated script for Starfarer to Starsector name change. Note that if you'd used the earlier starfarer version, the full path to the saved game continue is also saved in a separate .java/.userPrefs/com/fs/starfarer/prefs.xml file so you'll need so correct the path at <entry key="continue" value="path"/> from starfarer to starsector.
UPDATE 5 Nov 2014: Updated initial memory allocation pool to 1024M (maximum memory allocation pool was already 1024M) as default in 0.65.1a release.
UPDATE 15 Dec 2015: Added thread stack size to 1024K as default in 0.7.1a release.
UPDATE 27 Apr 2017: Note that as of 0.8a release if the system Java is not 7 then edit data/config/settings.json and change allowAnyJavaVersion to true.
UPDATE 4 Jun 2017: Increase memory allocations to 1536K as default in 0.8.1a release.
UPDATE 17 Nov 2018: Updated XStream jar version used in 0.9.0a release.
UPDATE 28 Mar 2021: Increase thread stack size to 2048K as default in 0.9.5a release.

I got the error:
Unrecognized VM option 'CompilerThreadHintNoPreempt'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

any suggestions?
Logged
Soli Deo gloria.
And have a nice day :D

(PS: My profile icon was taken from a meme edited into a christian meme and then cropped to his face which I then added the words repent to. Just to satisfy your curiosity.)

Swanny

  • Ensign
  • *
  • Posts: 35
    • View Profile
Re: Linux Startup Script
« Reply #10 on: January 27, 2023, 05:52:14 AM »

What version of Java do you have installed?

The CompilerThreadHintNoPreempt option actually only appears to affect Solaris systems and was due to be depreciated by JDK-8196807 perhaps with Java 11. You can safely just remove that line.
Logged