Page 1 of 1

Removing hostname check from scripts?

Posted: Fri Mar 05, 2021 4:03 pm
by edr
A number of scripts check for the specific hostname "MiSTer" and will refuse to run if the hostname is not the default.

Problem: some (many) people prefer to change the hostname for a number of good reasons. Such as multiple MiSTers on the same network - iss nice for the shell prompt to tell you which one you're connected to. Or custom scripts or automation based on the specific hostname. Or just liking to see "mst1" or "chocolate-dunky-clown-patrol4923" at the shell prompt.

Suggestion: remove all hostname checks from scripts. If someone's idea of a good time is to randomly copy scripts from a MiSTer system to some other Linux server and try to run them, why not let them? Seems like fun things might happen for them, and they wouldn't have any reason or claim to surprise.

Alternate suggestion: if a check must be included, use something different that doesn't depend on hostname, such as:
- Presence of file /MiSTer.version
- Kernel uname string containing 'socfpga'
- Presence of /dev/MiSTer_cmd
- Presence of any of a few dozen MiSTer items in /sys/
- Presence of any of many MiSTer items in /media/fat (MiSTer, MiSTer.ini etc)

I can do a PR if the project would be open to this change.

Some examples of current scripts:

fast_USB_polling_on.sh

Code: Select all

os.uname()[1] != "MiSTer":
    print ("This script must be run on a MiSTer system.")
ssh_on.sh

Code: Select all

if [ "$(uname -n)" != "MiSTer" ]
then
        echo "This script must be run"
        echo "on a MiSTer system."

Re: Removing hostname check from scripts?

Posted: Fri Mar 05, 2021 8:07 pm
by ash2fpga
I ran into this on my second mister since I renamed it to avoid conflicts on my network. I look forward to an update to the scripts. :)

Re: Removing hostname check from scripts?

Posted: Fri Mar 05, 2021 10:41 pm
by aberu
This is a good find.

os.uname() outputs the following:

Code: Select all

posix.uname_result(sysname='Linux', nodename='MiSTer', release='4.19.0-socfpga-r1', version='#9 SMP Tue Sep 8 22:13:28 CST 2020', machine='armv7l')
So yes, this is inappropriate since the hostname changes, it's no longer checking to see if it's a MiSTer or not. Maybe just check to see if the MiSTer file is there?

Code: Select all

from pathlib import Path

if Path('/media/fat/MiSTer').is_file():
    print ("This is a MiSTer FPGA")
else:
    print ("This is not a MiSTer FPGA")
Something similar to that might work just a copy pasted example though.

Re: Removing hostname check from scripts?

Posted: Sat Mar 06, 2021 1:17 am
by edr
@aberu thanks, I can do a PR soon for various scripts to use that kind of check instead of hostname.

Re: Removing hostname check from scripts?

Posted: Tue Mar 30, 2021 6:24 pm
by mrchrister
just ran into this issue with a newly setup MiSTer. couldn't turn on USB fast polling until i changed

Code: Select all

os.uname()[1] != "MiSTer":
    print ("This script must be run on a MiSTer system.")
to

Code: Select all

os.uname()[1] != "mister":
    print ("This script must be run on a MiSTer system.")

Re: Removing hostname check from scripts?

Posted: Fri Apr 02, 2021 6:17 pm
by Mellified
Checking uname is a terrible idea period. If you have multiple MiSTers on the name network you'll want to change the hostname to use Samba and FTP, which breaks all these scripts.

Re: Removing hostname check from scripts?

Posted: Fri Apr 02, 2021 8:32 pm
by guddler
Why wouldn’t you just call ‘hostname’ (with backticks that my iPad doesn’t seem to have!)?

Re: Removing hostname check from scripts?

Posted: Fri Apr 16, 2021 6:30 pm
by aberu
mrchrister wrote: Tue Mar 30, 2021 6:24 pm just ran into this issue with a newly setup MiSTer. couldn't turn on USB fast polling until i changed

Code: Select all

os.uname()[1] != "MiSTer":
    print ("This script must be run on a MiSTer system.")
to

Code: Select all

os.uname()[1] != "mister":
    print ("This script must be run on a MiSTer system.")
Were you running the script from an NTFS formatted storage device or something like that? Interesting.

Does platform.uname do the same thing for your script? --> https://docs.python.org/3/library/platf ... form.uname