Removing hostname check from scripts?

Discussion of developmental aspects of the MiSTer Project.
edr
Posts: 104
Joined: Mon Jan 04, 2021 3:35 am
Has thanked: 34 times
Been thanked: 23 times

Removing hostname check from scripts?

Unread post 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."
ash2fpga
Posts: 237
Joined: Tue May 26, 2020 6:20 pm
Has thanked: 62 times
Been thanked: 28 times

Re: Removing hostname check from scripts?

Unread post 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. :)
User avatar
aberu
Core Developer
Posts: 1144
Joined: Tue Jun 09, 2020 8:34 pm
Location: Longmont, CO
Has thanked: 244 times
Been thanked: 388 times
Contact:

Re: Removing hostname check from scripts?

Unread post 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.
birdybro~
edr
Posts: 104
Joined: Mon Jan 04, 2021 3:35 am
Has thanked: 34 times
Been thanked: 23 times

Re: Removing hostname check from scripts?

Unread post by edr »

@aberu thanks, I can do a PR soon for various scripts to use that kind of check instead of hostname.
User avatar
mrchrister
Posts: 231
Joined: Tue Mar 30, 2021 6:23 pm
Location: Canada
Has thanked: 16 times
Been thanked: 79 times

Re: Removing hostname check from scripts?

Unread post 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.")
User avatar
Mellified
Posts: 145
Joined: Sat Aug 22, 2020 8:38 pm
Been thanked: 51 times

Re: Removing hostname check from scripts?

Unread post 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.
guddler
Posts: 56
Joined: Sun Aug 09, 2020 8:37 pm
Has thanked: 3 times
Been thanked: 5 times

Re: Removing hostname check from scripts?

Unread post by guddler »

Why wouldn’t you just call ‘hostname’ (with backticks that my iPad doesn’t seem to have!)?
User avatar
aberu
Core Developer
Posts: 1144
Joined: Tue Jun 09, 2020 8:34 pm
Location: Longmont, CO
Has thanked: 244 times
Been thanked: 388 times
Contact:

Re: Removing hostname check from scripts?

Unread post 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
birdybro~
Post Reply