On Wed, Jul 06, 2011 at 19:19:03 +0300, Georgios M. Zarkadas wrote: > This is a solution to bug #571086 (now closed) which keeps /etc/login.defs as > the only place to set PATH, by computing the set there value on the fly using > only grep and coreutils (both essential packages and thus guaranteed to be > always present).
There's no need to call external programs for the parsing: pathkey=ENV_PATH if [ "$(id -u)" -eq 0 ] then pathkey=ENV_SUPATH fi ifs=${IFS+_$IFS} unset IFS while read -r key val do case "$key" in "$pathkey") # the "PATH=" prefix is optional PATH=${val#PATH=} export PATH ;; UMASK) # may want to handle this too umask "$val" ;; esac done < /etc/login.defs [ -z "$ifs" ] || IFS=${ifs#?} unset ifs pathkey key val The uid check could also be changed, to avoid a subshell and to help with the case where 'id' isn't found in $PATH: if [ -f /proc/1/environ ] then if [ -r /proc/1/environ ] then pathkey=ENV_SUPATH fi elif [ "$(id -u)" -eq 0 ] then pathkey=ENV_SUPATH fi or (with non-bash still using a subshell): if [ "${EUID:-$(id -u)}" -eq 0 ] -- Michael
signature.asc
Description: Digital signature