Tiny Core Linux

General TC => Programming & Scripting - Unofficial => Topic started by: sbp on August 02, 2014, 08:45:48 AM

Title: don't run as root - problem
Post by: sbp on August 02, 2014, 08:45:48 AM
Hi I'm trying to write a script (called do_rebootstuff.sh) that is started from the bootlocal.sh.

So the content of bootlocal.sh is:
Code: [Select]
#!/bin/sh
# put other system startup commands here
home/tc/www/cgi-bin/do_rebootstuff.sh

And the content of do-rebootstuff.sh is:
Code: [Select]
CONFIG=/usr/local/sbin/config.cfg
#Read from config file.
. /$CONFIG

#Logic that will skip loading wifi firmware if wifi is not used
if [ $WIFI = on ]; then
tce-load -i /mnt/mmcblk0p2/tce/optional/firmware-ralinkwifi.tcz
tce-load -i /mnt/mmcblk0p2/tce/optional/firmware-rtlwifi.tcz
tce-load -i /mnt/mmcblk0p2/tce/optional/firmware-atheros.tcz
else
exit
fi

The problem is that it reads the config file OK, but when trying to execute:
tce-load -i /mnt/mmcblk0p2/tce/optional/firmware-ralinkwifi.tcz
tce-load -i /mnt/mmcblk0p2/tce/optional/firmware-rtlwifi.tcz
tce-load -i /mnt/mmcblk0p2/tce/optional/firmware-atheros.tcz

Code: [Select]
Don't run this as root.
Don't run this as root.
Don't run this as root.
tc@piCorePlayer:~$

So it seems like starting the do_rebootstuff.sh from bootlocal.sh results in starting everything as root and therefore I can't load the tcz extensions  - how can I manage this?

Thanks
Steen
Title: Re: don't run as root - problem
Post by: gerald_clark on August 02, 2014, 09:07:37 AM
Look at how /usr/bin/tce-setup uses su to run tce-load.
Actually, why bother?
The loop mounted extensions only use a few bytes of RAM.
Your script probably uses up more RAM then mounting them all would.
Title: Re: don't run as root - problem
Post by: Greg Erskine on August 04, 2014, 12:10:53 AM
hi Steen,

Would it be easier to manipulate onboot.lst when you set wifi "on" or "off"? That way you can skip all of the wifi extensions not just the firmware extensions. Obviously, it would require a reboot.

In your first code segment, I would put a "/" before the home directory. Relative paths make it more difficult to test scripts.

In the second bit of code, I think (not tested) the else and exit statements are not required and the paths to the extensions are not required as they are the default locations.

regards
Title: Re: don't run as root - problem
Post by: Greg Erskine on August 04, 2014, 12:15:37 AM
Look at how /usr/bin/tce-setup uses su to run tce-load.
Actually, why bother?
The loop mounted extensions only use a few bytes of RAM.
Your script probably uses up more RAM then mounting them all would.

Hi gerald_clark,

I think people are concerned about boot times. I don't mind if it takes 53 seconds to boot, but there are people that reckon this is 40 seconds to slow.

regards
Title: Re: don't run as root - problem
Post by: gerald_clark on August 04, 2014, 12:40:13 AM
Loading 3 firmware extensions doesn't take 40 seconds.
Title: Re: don't run as root - problem
Post by: bmarkus on August 04, 2014, 01:53:12 AM
Do not put config.cfg to /usr/local/sbin, it is not compliant to generic LINUX rules. Use /usr/local/etc instead.
Title: Re: don't run as root - problem
Post by: Greg Erskine on August 04, 2014, 02:41:36 AM
Loading 3 firmware extensions doesn't take 40 seconds.

I think you misread what I said.