phyver / GameShell

a game to learn (or teach) how to use standard commands in a Unix shell
GNU General Public License v3.0
2.18k stars 139 forks source link

Use standard paths #123

Closed mpoquet closed 1 year ago

mpoquet commented 2 years ago

Context

Hi and first of all, thanks for your work on GameShell!

While I was investigating this project to determine whether we can use for teaching purposes at our university, I was not able to run it on my machine (log below), which runs a NixOS linux.

NixOS does not put executable files in /bin nor /usr/bin but keep them in separate directories and sets $PATH accordingly. The modifications of this PR made GameShell run on my machine by avoiding the use of absolute paths for external executable files.

Log of failed first execution (before modifications)

/tmp/gameshell/scripts/rm: line 34: /bin/rm: No such file or directory
Error: a least one base function is not working properly.
Aborting!

Modifications done

  1. env is used instead of absolute paths in shabangs. env is the standard tool to look for the location of executable files ; env essentially traverses $PATH to look for the first matching executable. env is located in /usr/bin/env on all systems I know (including NixOS, that ony has two executable files accessible from a common absolute path: /bin/sh for booting shenanigans and /usr/bin/env to find other executables).
    • env -S is used to give the -f argument to awk. the option may not be available on all systems but should work on any recent linux (GNU coreutils 8.30+, released on 2018-07-01), recent macOS and freebsd.
  2. keep a copy of PATH before its modification by GameShell, so that we can run real commands from the user-given PATH.
  3. in rm's wrapper script, run rm with a specific PATH (the user-given PATH) instead of calling it from an absolute location.

Tests done

  1. I successfully could create a gameshell archive by running utils/archive.sh with no arguments.
  2. I successfully ran the new archive and did missions 1 and 2.

I did this on two setups:

phyver commented 1 year ago

Sorry it took so long. I usually work on GameShell while I'm using it for teaching, and that's ... now.

This PR looks good. I'm probably going to keep the #!/usr/bin/awk -f shebang for now (commit 994257d), for POSIX conformity, but this should be a problem for NixOS as all the awk scripts are called by invoking awk explicitly.

Can you confirm it works without commit 994257d?

mpoquet commented 1 year ago

Hi, I can confirm that all awk scripts are called by invoking awk explicitly, it should work on NixOS :).

phyver commented 1 year ago

Perfect. I merged the relevant commits : d7258941 and 3af84956c2.