Packages:userscript

From NAS-4220

Revision as of 09:25, 18 March 2008 by Skara (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

the original german forum the english thread

Contents

Introducion

At bootup the NAS gets it's data from internal flashmemory this means almost any changes done by the user is lost. Therefor script will run different scripts at every NAS-boottime, so all your modifications will last even after poweroff. It's done also with intention to give users without unix/linux/bsd-knowledge (eg windowsuser) the posibility to do everything via network shares. No telnet/ssh is needed. The script is modular and indented to be community supported. I won't give you the scripts (oh, maybe i will) but am willing to correct errors on "userscript". So please report any failures here and i'll try to fix it.

To not reinvent the wheel it would be great if anybody using my package could publish it here. Even snipplets may be useful.

Content

init - is started at NAS-Boot and does ...
init.us - ... enable starting this. It runs after all other bootstuff is done, so your mods will be the last who come and not overriden by the flashcontent
example/* - some examples (see below), more to come from community
scripts/ - here your scripts have to be placed. pure textfiles are enough (they will get execute-bit automaticaly). Two conditions: it must be bash-scripts (including "#!/bin/sh") and the name must end with ".sh" eg "proftpd.sh"
config/ - it's indented to contain your config-files, which will be writen to the NAS (look at included proftp-script)

Scripts

link-script (example)

linkhddapp.sh / linkroot.sh - symlinks of /usr/hddapp/ and / respectively are created in userscript/hddapp/ and userscript/root/ respectively - this was useful while creating the script. it's also useful for doing your own scripts! So you can look at the whole filesystem and crap some config-file or so.
At hddapp/etc there are different config (samba, proftpd, ldp (printer), mt-daap (bonjour/itunes)).

unlinkhddapp.sh / unlinkroot.sh - guess what?! right, it removes the symlinks ;)

proftpd (example)

proftpd.sh - overrides the config of the ftpserver with content of userscript/config/proftpd.conf and restarts the server (proftpd).
Needs one of the conf-file out of userscript/example/config/ to be placed at userscript/config/ - ATTENTION! Depending on your hdd-configuration (Raid, JBOD) you need to fetch ide1, ide2 or md1 and rename it to proftp.conf.
Don't forget it's only an example-config fitting on my nas! Look into the conf (it's well-commended i guess) and take your own conf (hddapp/etc/proftpd.conf) to adapt it to your needs! The changes in the example show you some tweaks concerning proftpd.

Set $PATH (example)

path.sh - sets the PATH-variable for the user root. userscript/example/config/path needs to be placed at userscript/config/ and adapted. Further pathes needs to be separated by :
With this new programs can be executed even if they aren't located at "normale" places. In this example userscript/bin/ is inserted.

Extended crontab

Using cron for own stuff.

Necessary:

  1. a valid cron-argument (search for 'crontab') placed at config/cron.

It makes sense to run bashscripts instead of multiple commands at once. Eg. (creates /tmp/test.tmp at 03:00 and deletes it at 20:10):

   10 3 * * *        root    touch /tmp/test.tmp
   10 20 * * *        root    rm /tmp/test.tmp
  1. place following into scripts/cron.sh :
   #!/bin/sh
   #
   # edit crontab
   #
   # requires a cron-compatible command at userscript/config/cron
   
   USD=/usr/userscript
   
   if [ -e $USD/config/cron ]; then
   	crontab -l > /tmp/crontab.tmp
   	cat $USD/config/cron >> /tmp/crontab.tmp
   	crontab /tmp/crontab.tmp
   	rm -f /tmp/crontab.tmp
   fi
In other languages