Ciaran McCreesh wrote: > if [[ ${UID} -ne 0 ]]; then > > We've always told people not to do that. Capabilities required by > eselect modules should be tested by attempting to perform the action, > not by some arbitrary query done on UIDs or groups. Being UID 0 doesn't > mean you're allowed to do something, and not being UID 0 doesn't mean > you're not allowed to do something. > I've always used EUID for the root check, eg: if ((EUID)); then echo "You must be root to run this script" >&2 exit 1 fi
This won't get round capabilities (so error status should still be checked and the script bail with appropriate output, if it can't do something it's supposed to) but it's sufficient for root privilege check, and is better than UID which requires login as root. This doesn't, of course, deal with non-root users, eg where users in group portage are allowed to carry out a task. You can check for that kind of thing with a writeable test, eg: [[ -w $PORTDIR ]] || die 'Write access to portage dir required" While none of this stops you from needing to check errors, it does make it nicer for users, imo, if scripts check early on for broader permissions where it's appropriate. Wrt signalling die, the correct way for a script to terminate on signal is something like this code, taken from a SIG_INT handler: trap INT kill -INT $$ This ensures the parent process is correctly notified. So IOW just kill self with the appropriate signal, ensuring any traps are cleared. -- [EMAIL PROTECTED] mailing list