Skip to content

install.sh: Python-shebang sed crashes on macOS (BSD sed), unlike the config_template sed a few lines later #64

Description

@frigusgulo

Summary

install.sh's Python-shebang normalization step crashes on macOS (BSD sed) because it's missing the OS-specific -i handling that the rest of the script already uses elsewhere.

Where

# Check python
if which python3 > /dev/null 2>&1; then
    sed -i 's/\#\!\/usr\/bin\/env python$/\#\!\/usr\/bin\/env python3/g' ./scripts/*.py
elif which python > /dev/null 2>&1; then
    sed -i 's/\#\!\/usr\/bin\/env python3$/\#\!\/usr\/bin\/env python/g' ./scripts/*.py
else
    printf "${YELLOW}warning:${NC} no python or python3, please install one of them before using py scripts\n"
fi

Note that further down the same script, the config_template sed does branch correctly:

if [ "$SYS" == "Darwin" ]; then
    sed -i '' "/Table directory/s#Default#$work_dir/table/#" $install_dir/config_template
else
    sed -i    "/Table directory/s#Default#$work_dir/table/#" $install_dir/config_template
fi

but the shebang-fixup sed -i a few lines earlier never got the same treatment.

Repro

On macOS:

$ echo '#!/usr/bin/env python' > testshebang.py
$ sed -i 's/\#\!\/usr\/bin\/env python$/\#\!\/usr\/bin\/env python3/g' testshebang.py
sed: 2: "testshebang.py": undefined label 'estshebang.py'
$ echo $?
1
$ cat testshebang.py
#!/usr/bin/env python   # unchanged — sed never ran

BSD sed -i requires an explicit (even empty) backup-suffix argument (sed -i ''); without it, the next argument is consumed as the suffix and the following argument is mis-parsed as the sed command itself.

Observed impact

Ran install.sh on macOS today against current master (b7451a8) — the shebang sed for ./scripts/*.py fails with:

sed: 1: "./scripts/kin2csv.py": invalid command code .

install.sh doesn't check this command's exit status, so installation continues and prints "installation successfully completed" — the failure is silent. In this run the scripts already had #!/usr/bin/env python3 shebangs so nothing was functionally broken, but any script whose shebang genuinely needs normalizing would silently keep the wrong interpreter on macOS.

Suggested fix

Mirror the existing $SYS/$OS-branching pattern already used for the config_template sed a few lines later, e.g.:

if [ "$SYS" == "Darwin" ]; then
    sed -i '' 's/.../.../g' ./scripts/*.py
else
    sed -i    's/.../.../g' ./scripts/*.py
fi

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions