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

Consider following POSIX standards when installing .sh scripts #5454

Open
jonahbeckford opened this issue Feb 24, 2023 · 0 comments
Open

Consider following POSIX standards when installing .sh scripts #5454

jonahbeckford opened this issue Feb 24, 2023 · 0 comments

Comments

@jonahbeckford
Copy link
Contributor

jonahbeckford commented Feb 24, 2023

I'd like to get your thoughts on doing the following for all .sh scripts installed into the build/ tree and into the OPAM_SWITCH_PREFIX tree:

  • convert them to LF endings if CRLF. CR is not part of the POSIX standard, and some Windows shells (ie. MSYS2 dash.exe) are purist in adhering to POSIX standard. This avoids the need to have a .gitattributes file (ex. https://github.com/diskuv/dkml-installer-ocaml/blob/main/.gitattributes#L22) when checking out a project using git on Windows.
  • If and only if the script has a shebang from the following list:
    • #!/bin/bash
    • #!/bin/sh
    • #!/usr/bin/env sh
    • #!/usr/bin/env bash
      replace the shebang with the output of command -v sh or command -v bash or follow the POSIX search algorithm on getconf PATH

The POSIX standard for installing scripts is at https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html#tag_20_117_16. The detection of the correct shell can be done at compile time (ex. opam$ ./configure --bash-shell /bin/bash --posix-shell /bin/sh) or be an opam global variable ... not sure. But the default of /bin/bash and /bin/sh will almost always work.

This:

I realize this may not be backwards compatible as proposed; perhaps there is a way to make it backwards compatible. For example, instead of "all .sh scripts" it could be an explicit .opam field like build_scripts: [ "configure" ].

Personally, if there was an opam global variable I'd set it to the full path to the MSYS2 dash.exe (that is the portable shell for MSYS2) and the full path to MSYS bash.exe so whatever weirdness a Diskuv OCaml Windows user has in their PATH (ex. Cygwin, Git Bash, Chocolatey, etc), the opam installed scripts just work.

@jonahbeckford jonahbeckford changed the title opam-installer: Consider following POSIX standards when installing .sh scripts Consider following POSIX standards when installing .sh scripts Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants