My second attempt to handle stdin and also return proper exit code and avoid one shell running is

#!/bin/sh
# use gainroot to become root and relaunch itself and remember tty
if [ `id -u` != 0 ] ; then
#if not already root, call itself as root
TTY=`tty`
[ "$TTY" = "not a tty" ] && unset TTY
sudo gainroot <<EOF
if [ -z "$TTY" ] ; then exec $0 $* ; else exec <$TTY $0 $* ; fi
EOF
exit $?
fi
# real script follows


Similar thing can be done with stdout if you do not want to see 'Root shell enabled' output of gainroot script. If someone has some optimization or know better way how to shuffle input and output redirection in shell without using output of tty command, let me know.

Frantisek
_______________________________________________
maemo-developers mailing list
[email protected]
https://maemo.org/mailman/listinfo/maemo-developers

Reply via email to