Followed the RC-Script guide (http://www.gentoo.org/doc/rc-scripts.html), but when I came to the custom commandline options, I noticed a strange behavior. When I put opts="${opts} foo" in my script and provide a foo() function (as said in the guide), a call to the script (called script for this example) with an unknown parameter gives this as result (look at the "Usage" section): * ERROR: wrong args. ( star / star ) * Usage: script {foo|foo} * script without arguments for full help Two times "foo", but "start", "stop", "restart" are gone (but do work!).
could you perhaps post your script ? :)
I could do that, but it is a generic problem ;) Just something like: !/sbin/runscript opts="${opts} foo" start() { echo "start" } foo() { echo "foo" } will cause the strange behavior when you call it with a unknow commandline parameter.
The missing # in front of !/sbin/runscript is a copy-paste mistake by me, but I can edit my message I believe. In the script is it there though ;)
Seems like I have fixed whatever the problem was already. Try baselayout-1.8.0 (masked) and let me know, thanks. -------------------------snip--------------------------- nosferatu tmp # /etc/init.d/foo start start nosferatu tmp # /etc/init.d/foo stop nosferatu tmp # /etc/init.d/foo stop * ERROR: "foo" has not yet been started. nosferatu tmp # /etc/init.d/foo foo foo nosferatu tmp # /etc/init.d/foo start start nosferatu tmp # /etc/init.d/foo foo foo nosferatu tmp # cat /etc/init.d/foo #!/sbin/runscript opts="${opts} foo" start() { echo "start" } foo() { echo "foo" } nosferatu tmp # -------------------------snip---------------------------
But what happens if you run your script with: "/etc/init.d/foo testing123" (without making any changes to your script!!)? According to me you have to get (as part of the output): "Usage: foo (foo|foo}" and not "Usage: foo (start|stop|restart|foo}"
i use baselayout on my machines and i get the same results as him he isnt saying that {start,stop,foo} dont work, hes saying the help is wrong root@rux0r root # ./test f * ERROR: wrong args. ( f / f ) * Usage: test {foo|foo} * test without arguments for full help
*** i guess at this point in runscript.sh: source ${myscript} if [ -z "${opts}" ] then opts="start stop restart" fi *** change it to: opts="start stop restart" source ${myscript} *** unless this breaks current scripts, in which case this would be better: source ${myscript} for defo in start stop restart ; do for o in ${opt} ; do if [ "${o}" == "${defo}" ] ; then defo= break fi done [ -n "${defo}" ] && opt="${defo} ${opt}" done
First solution works for me, but the second one not. It gives the same result as without your "patch": pieter root # ./foo f * ERROR: wrong args. ( f / f ) * Usage: foo {foo|foo} * foo without arguments for full help but as you are not sure if the first solution is 100% correct, I'll wait for Martin to say something about this ;)
Whoops .. long day ? :P change: myline="Usage: ${myservice} {$*" to: myline="Usage: ${myservice} {${opts}" ---------------------------------snip------------------------------ nosferatu tmp # /etc/init.d/acpid lksjd * ERROR: wrong args. ( lksjd / lksjd ) * Usage: acpid {start stop restart} * acpid without arguments for full help nosferatu tmp # ---------------------------------snip------------------------------
that didnt work for me martin, same results as original report as for my comment about breaking scripts, it would 'break' a script if the user had defined opts in their script as 'opts="start stop restart food"' as for the second one, it should be 'opts' and not 'opt' :x
Created attachment 2840 [details] /sbin/runscript.sh This should be the fixed one.
ok, have to be $* and not $opts, else the ' ' do not get converted to '|'.
works great, nice fix :)
Thanks! Now its working like it should be (I guess ;)).
Commited to CVS, should make next baselayout.