I was wondering if it was possible to externalize the header to gain root access and then include it somehow, or better create a standalone script that establishes root access and exec that at the start of any script needing root acccess...but seeing as this gains root first, then relaunches itself....that may not be possible because of the recursive nature.?
#!/bin/sh # use gainroot to become root and relaunch itself if [ `id -u` != 0 ] ; then #if not already root, call itself as root exec sudo gainroot <<EOF exec $0 $* EOF exit $? fi # real script follows
#!/bin/sh if [ `id -u` != 0 ] ; then exec sudo gainroot <<E exec $0 $* E ; fi
#!/bin/sh [ `id -u` != 0 ] && exec sudo gainroot <<E exec $0 $* E