GLYCAM-Web / website

A bare-bones repo to contain public website stuff and issues related to the GLYCAM Web Django apps.
4 stars 0 forks source link

Normalization of all bash scripts #143

Open Pshepp opened 1 year ago

Pshepp commented 1 year ago

We need to normalize all of our bash scripts. This includes:

Bug Description: A recent bug caused by this was the gems/tests/run_tests.sh script having a #!/bin/sh shabang which caused it to not have the bash source command available to it. Furthermore, inconsistencies increases brain usage which is bad and makes scripts that would grab all specific files etc. to run tools on them more difficult.

Additional context Think of different shells as kinda like different programming langauges. They are not all interchangeable, so we gotta keep that in mind. If we just stick to bash shells that use the baseline commands/progs we should be good. Getting a collection of all our scripts without shabangs would be good for someones first issue, actually changing them and ensuring the shabangs are correct is dependent on the devs skill level

Information regarding shabangs:

Information Regarding exit vs. return

gitoliver commented 1 year ago

What should everything be

!/bin/bash?

!/usr/bin/env bash?

Pshepp commented 1 year ago

as with most code bits, it depends lolol. These SO posts have a good starting point to understanding, and not just the top comments have decent info:

I would say just using the following would be fine. Now, as one of the dudes in the 2nd link said on different linoox systems it wont work depending on how people have stuff installed but meh.......

#!/bin/bash

We can also use the following, but it is less secure iirc but idk how much of this being less secure is bs.....

#!usr/bin/env bash

@thecoulter plz weigh in

Pshepp commented 1 year ago

did some edits to the issue bit so i dont have to create a whole other issue. Gonna also be putting this info in glyvemind

Lachele commented 1 year ago

How about for Python and the various environments? It is typical to have several python versions on any given system. If you specify /path/to/this/python you might cause issues.

The use of /bin/bash is problematic for Mac users.

I can probably be convinced otherwise, but I think we should prefer /usr/bin/env unless a certain file is used almost exclusively inside a container and it is a high security risk (and if so, can we make it not be?).

Pshepp commented 1 year ago

yea i was thinking about us properly using conda for our python stuff instead of using a python venv but ngl unsure how useful that would be and how nice it would play with out stack plus wanted to do that in another ticket once we get the bash scripts normalized. That way our conda could force the python version and handle what pip does, but again im not super confident that this will play nice with our current stack (https://stackoverflow.com/questions/73846871/how-to-exchange-data-between-two-different-python-processes-of-different-conda-e is an example of something annoying we would probably have to do with conda). The biggest problem about not normalizing python versions is that some versions of python change how the code itself works. Think back to when we switched from python-3.7 to python-3.9 and some of the lines that messed with strings ended up being invalid when run with python-3.9 thus having a set normalized python version that is what we strive to always use would be nice to just reduce logical overhead that would have to float in devs brains which is something that cannot be understated.

Bash on mac should be easy enough. I am pretty sure that it is already within the OS and if it isnt one can use homebrew aka running brew install bash and im willing to bet u can specifiy a bash version with that.

Using #!/usr/bin/env bash for the shabang doesnt reveal horrifying vulns and after thinking about it it would probably be better for portability sake so i am game with it

Lachele commented 1 year ago

For Mac, there is a built-in bash, but it's an old version of bash. Yao ran into this. The version answering at /bin/bash was too old to run some of our scripts. And, while he could install another bash, he couldn't change the version answering at /bin/bash. So, unless there is a strong reason not to use /usr/bin/env, I think that is he way that is best for us to go.