Mercurial > hg > aboriginal
changeset 601:df62eeaccb27
Gentoo's portage needs getent, which neither busybox nor toybox implements, so implement a shell script version.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 29 Jan 2009 00:00:46 -0600 |
parents | 62affc4225e4 |
children | 8de4598dfe46 |
files | sources/native/bin/getent |
diffstat | 1 files changed, 31 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sources/native/bin/getent Thu Jan 29 00:00:46 2009 -0600 @@ -0,0 +1,31 @@ +#!/bin/sh + +# Copyright 2009 Rob Landley <rob@landley.net>, licensed under GPLv2. + +isnum() +{ + [ ! -z "$(echo $1 | grep '^[0-9]*$')" ] +} + +nocomments() +{ + sed 's/\([^#]*\)#.*/\1/' /etc/$1 +} + +# The world's cheesiest getent implementation + +case "$1" in + passwd|group) + isnum "$2" && + grep -m 1 "[^:]*:[^:]*:$2:" /etc/$1 || + grep -m 1 "^$2:" /etc/$1 + ;; + + hosts|networks|protocols) + nocomments $1 | grep -m 1 -w "$2" + ;; + + services) + nocomments $1 | (isnum "$2" && grep -m 1 "[ ]$2/" || grep -m 1 -w "$2") + ;; +esac