The officially official Devuan Forum!

You are not logged in.

#1 2022-04-17 14:17:58

Altoid
Member
Registered: 2017-05-07
Posts: 1,415  

[SOLVED] Script $PATH question

Hello:

Still playing around with my new My Book Live thingy, trying to set up a solution to the lack of a shutdown command in this PowerPC 44x processor.
This is the OpenWRT installed on the unit:

~# uname -a
Linux_book 5.4.179 #0 Wed Feb 16 20:29:10 2022 ppc GNU/Linux
~# 

I wrote a script to shut down the board gracefully:

root@OpenWrt:/usr/bin# cat closebook.sh
#!/bin/sh
# script to stop drive and shut down MBL
# gives ~15s from blue led <on> to unplug unit
PATH=/bin:/sbin

sync && wait && hdparm -Y /dev/sda && wait && halt
root@OpenWrt:/usr/bin# 

The script is executable:

root@OpenWrt:~# ls -l /usr/bin/closebook.sh
-rwxr-xr-x    1 root     root           166 Apr 17 08:40 /usr/bin/closebook.sh
root@OpenWrt:~# 

Once the front LED goes from green to blue, you have to physically disconnect power to the board within ~15s, otherwise a watchdog will sense the new situation and proceed to reboot the board.

For the time being, I call the /usr/bin/closebook.sh from ~/ with another script:

root@OpenWrt:~# cat shutdown 
#!/bin/sh
sh -c '/usr/bin/closebook.sh'
root@OpenWrt:~# 

The script is executable:

root@OpenWrt:~# ls -l shutdown
-rwxr--r--    1 root     root            40 Apr 17 10:07 shutdown
root@OpenWrt:~# 

It works as intended and have not had an instance where the plug was pulled late or where the watchdog reboot caused any issues.
Unsurprisingly, not shutting down in this manner will always cause dmesg to print this:

[    0.907630] EXT4-fs (sda2): warning: mounting unchecked fs, running e2fsck is recommended
[    5.802598] EXT4-fs (sda1): warning: mounting unchecked fs, running e2fsck is recommended

The main problem is that while /dev/sda1 but can be unmounted to run e2fsck, /dev/sda2 holds the rootfs and cannot be unmounted:

root@OpenWrt:~# blkid
--- snip ---
/dev/sda2: LABEL="rootfs" UUID="ff313567-e9f1-5a5d-9895-3ba130b4a864" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="228c756a-02"
--- snip ---
root@OpenWrt:~# 

But I digress ...

The thing is that to run the script I have to do it with ./, otherwise it is not found:

root@OpenWrt:~# shutdown
-ash: shutdown: not found
root@OpenWrt:~# 

This even though I am running it as root and it is located in what would be home directory:

root@OpenWrt:~# ls
shutdown
root@OpenWrt:~# 

The system's $PATH:

root@OpenWrt:~# $PATH
-ash: /usr/sbin:/usr/bin:/sbin:/bin: not found
root@OpenWrt:~# 

I'm sure it is a $PATH issue ...

What am I doing wrong?

Thanks in advance,

A.

Offline

#2 2022-04-17 14:34:19

hevidevi
Member
Registered: 2021-09-17
Posts: 230  

Re: [SOLVED] Script $PATH question

not sure here bit maybe in your closebook.sh script you should not declare the PATH=/bin:/sbin if you are going to call closebook.sh from another script that is not on its path.

You shouldnt need to export/declare a path in the script at all if your shell env/path is setup properly.

Last edited by hevidevi (2022-04-17 14:37:41)

Offline

#3 2022-04-17 16:56:08

Altoid
Member
Registered: 2017-05-07
Posts: 1,415  

Re: [SOLVED] Script $PATH question

Hello:

hevidevi wrote:

... maybe in your closebook.sh script you should not declare the PATH=/bin:/sbin ...

I put it in just in case the system path has some issue.
Belt and suspenders thing.

But that would not seem to be the problem because the script is found and the executables in it are run properly.

What is not being found is the script that calls closebook.sh unless I run it as ./shutdown.

I just realised that the /root folder is not in the system PATH variable:

root@OpenWrt:~# $PATH
-ash: /usr/sbin:/usr/bin:/sbin:/bin: not found
root@OpenWrt:~# 

This one:

root@OpenWrt:~# ls
shutdown
root@OpenWrt:~# 

Which you can see here:

root@OpenWrt:/# ls
bin         dev         lib         mnt         proc        # root #        srv         tmp         var
boot        etc         lost+found  overlay     rom         sbin        sys         usr         www
root@OpenWrt:/# 

No idea as to how to follow up.
Surely it is not a good idea to have the root folder in the path.

Thanks for your input.

Best,

A.

Offline

#4 2022-04-17 19:03:25

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: [SOLVED] Script $PATH question

# mv /usr/bin/closebook.sh /usr/bin/shutdown

Brianna Ghey — Rest In Power

Offline

#5 2022-04-17 20:21:16

Altoid
Member
Registered: 2017-05-07
Posts: 1,415  

Re: [SOLVED] Script $PATH question

Hello:

Head_on_a_Stick wrote:
# mv /usr/bin/closebook.sh /usr/bin/shutdown

Perfect.  8^)
Thank you very much.

Could you tell me what I was doing wrong?
Was it having script to call another one?

Thanks in advance,

A.

Offline

#6 2022-04-18 12:22:58

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: [SOLVED] Script $PATH question

You could have moved /root/shutdown to /usr/bin/ instead or you could have added /root/ to PATH (which is a fantastically bad idea) but just placing the actual script itself at /usr/bin/shutdown seems more sensible. Strictly speaking non-packaged executables should go under /usr/local/bin/ but whatever.

Last edited by Head_on_a_Stick (2022-04-18 12:23:13)


Brianna Ghey — Rest In Power

Offline

#7 2022-04-18 12:42:25

hevidevi
Member
Registered: 2021-09-17
Posts: 230  

Re: [SOLVED] Script $PATH question

have you found a way to create a regular user on this OpenWrt drive?

Offline

#8 2022-04-18 16:36:38

Altoid
Member
Registered: 2017-05-07
Posts: 1,415  

Re: [SOLVED] Script $PATH question

Hello:

Head_on_a_Stick wrote:

... could have moved /root/shutdown to /usr/bin/ ...

Originally I had it in /usr/local/bin.
As I could not get it to work unless I used ./, I moved it.
I did not want to get into fussing with PATH.
I still have to find where it is set ...  8^|

Head_on_a_Stick wrote:

... could have added /root/ to PATH ...

Hmm ...
I may have a thing for abusing cat ...
But I do know that is not a thing to do.

Head_on_a_Stick wrote:

... placing the actual script itself at /usr/bin/shutdown seems more sensible.

OK.
It works well as it is but I'll move it to its proper place later today.

Thanks for your input.

Best,

A.

Offline

#9 2022-04-18 17:13:18

Altoid
Member
Registered: 2017-05-07
Posts: 1,415  

Re: [SOLVED] Script $PATH question

Hello:

hevidevi wrote:

... a way to create a regular user on this OpenWrt ...

Yes.

It is not as straight forward as in a regular distribution because the tools are not installed by default.
In these router firmwares such as OpenWRT (an OS by any other name), space is at a premium.

So if it is not needed, it is not in the image to install.
And if you need it, make sure it is not in BusyBox before you install it.

That said, first you have to install at least these files from the OpenWRT repository:

To manage groups in your system.

shadow-groups
shadow-groupadd
shadow-groupdel

To manage users in your system:

shadow-useradd
shadow-userdel
shadow-usermod

You may also want to install sudo to put your user in /etc/sudoers.d/ with strict premissions for specific tasks that require elevated privileges.

You then proceed more or less as would be usual in a regular distributions.
Some things you'll have to do by hand.

There are quite a few more shadow-* files available but I still have to see what they are about.
eg: shadow-login, shadow-logout.d, shadow-passwd, etc. 

Unfortunately, the wiki pages about OpenWRT packages are all but empty.

Check this page: https://openwrt.org/docs/guide-user/base-system/users

groucho@OpenWrt:~$ whoami
groucho
groucho@OpenWrt:~$
groucho@OpenWrt:~$ groups
adm ftp users network ntp groucho
groucho@OpenWrt:~$ 

Edit: keep in mind that a regular user ie: not root can only log in via ssh.

I think there may be a file in the repository that would add something to the UI to be able to add another user.
Can't recall if it was OpenWRT or the WD software.

If you find anything interesting, please let let me know.

Best,

A.

Last edited by Altoid (2022-04-18 23:19:02)

Offline

#10 2022-04-19 10:03:24

hevidevi
Member
Registered: 2021-09-17
Posts: 230  

Re: [SOLVED] Script $PATH question

Thanks for the info Altoid, think of giving this a try myself.

Offline

#11 2022-04-19 10:15:38

Altoid
Member
Registered: 2017-05-07
Posts: 1,415  

Re: [SOLVED] Script $PATH question

Hello:

hevidevi wrote:

Thanks ...

You're welcome.

hevidevi wrote:

... a try myself.

Obviously, the use you can give it depends on the hardware you run it on.
eg: I use a MyBook Live which has a SATA HD instead of firmware.

As this would be OT/non Devuan, feel free to contact me.

Best,

A.

Offline

#12 2022-04-19 13:54:51

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: [SOLVED] Script $PATH question

Altoid wrote:

Originally I had it in /usr/local/bin.
As I could not get it to work unless I used ./, I moved it.

/usr/local/bin/ is not in your user's PATH so any executables placed there will not be found unless the full path is given.

No idea where OpenWRT sets PATH though, perhaps ask on their forums instead? You would probably get a better response there. Failing that check /etc/profile & /etc/profile.d/*.


Brianna Ghey — Rest In Power

Offline

#13 2022-04-19 14:22:02

Altoid
Member
Registered: 2017-05-07
Posts: 1,415  

Re: [SOLVED] Script $PATH question

Hello:

Head_on_a_Stick wrote:

/usr/local/bin/ is not in your user's PATH ...

Yes. v

Altoid wrote:

I did not want to get into fussing with PATH.
I still have to find where it is set ...  8^|

Head_on_a_Stick wrote:

No idea ...

It is not in the *.img and editing /etc/*preinit did not work.
You have to create /etc/profile.d and populate it accordingly.

Thanks for your input.

Best,

A.

Offline

Board footer