chrislo27 / PolyrhythmMania

A game that faithfully recreates the Polyrhythm minigame from Rhythm Tengoku (リズム天国), with a built-in level editor
https://polyrhythmmania.rhre.dev
GNU General Public License v3.0
237 stars 18 forks source link

[Bug]: The play_linux.sh script in the release zip is malformed, and doesn't run without prior tampering #23

Closed ZaptorZap closed 3 years ago

ZaptorZap commented 3 years ago

Version

v1.0.1-20210830a

Operating System

Linux

Problem Description

Upon attempting to load play_linux.sh right after extracting the release found here, I was greeted by two separate yet closely related issues. First, the shell script does not hold the executable mode bit, which can be added by running chmod +x play_linux.sh. After adding this flag, the shell script will still fail to load with the reasoning being limited down to the choice of Windows-specific line endings, according to fish. This shell even goes on to suggest its own workaround, that being the standalone utility named dos2unix, which explains the discrepancy in more detail through its manpage:

In DOS/Windows text files a line break, also known as newline, is a combination of two characters: a Carriage Return (CR) followed by a Line Feed (LF). In Unix text files a line break is a single character: the Line Feed (LF).

Since every shell I have available to myself(that being fish, bash, and dash/sh) expects the latter, this shell script does not work on any of them.

Steps to Reproduce Problem

(assuming you're on fish, although realistically the steps would be the same on bash or dash. the output would be different, however)

  1. Download the platform agnostic zip release, as instructed by the readme: wget https://github.com/chrislo27/PolyrhythmMania/releases/download/v1.0.1/PolyrhythmMania_v1.0.1.zip
  2. Extract the downloaded .zip file: unzip PolyrhythmMania_v1.0.1.zip
  3. Change into the extracted directory: cd PolyrhythmMania_platform_agnostic/ 3.1. Attempting to run the shell script from this step (with ./play_linux.sh) would cause the following error: fish: The file “./play_linux.sh” is not executable by this user
  4. Set the executable mode bit: chmod +x play_linux.sh 4.1. Attempting to run the shell script from this step (with ./play_linux.sh) will now cause the following error:
    Failed to execute process './play_linux.sh'. Reason:
    The file uses windows line endings (\r\n). Run dos2unix or similar to fix it.

Relevant log output

No response

(Optional) Other useful information

If you're curious how the error looks on bash or dash, here's the output. Ignore the claims that the file just doesn't exist. It really does! I tried with test -e and absolute paths and stuff.

In bash:

bash: ./play_linux.sh: /bin/bash^M: bad interpreter: No such file or directory

In dash:

dash: 7: /home/zaptorzap/Downloads/PolyrhythmMania_platform_agnostic/play_linux.sh: not found

If you don't have the time to spin up a real Unix machine just to make what's pretty much a text file, here's the script I eventually used to launch the game with. It should have +x set, and it definitely uses the right line breaks. Here's the portable shell script as well, since it suffers the same problem.

If you ask me personally, at least as a Debian 11 user, I don't see what the point of the read -n1 "Press any key to continue..." line is, as that read command is seemingly skipped on bash/dash(sh). fish displays an error citing: `Press any key to continue...': not a valid identifier and removing the line entirely still plays the game as normal, exiting gracefully through the menu. For completionist sake I removed the line in these regular and portable shell scripts, should you choose to use these instead. (you can't complain about the file size reductions!) image image

chrislo27 commented 3 years ago

Thanks for checking this. Indeed I messed up the shell scripts when preparing for portable mode and resaved them on Windows which explains the wrong newlines.

This is my bad and I should have checked first — I don't even have an excuse because I have a Ubuntu VM that I can spin up easily! I will reupload the v1.0.1 release with your scripts and make sure they're correct with respect to line endings going forward. And yes the read command is not necessary, mostly a leftover from an older project.