# HG changeset patch # User Rob Landley # Date 1233208846 21600 # Node ID df62eeaccb27e176038d3f763fa89ef5200845e2 # Parent 62affc4225e4bc3411da46ab97e7f12b47812c8f Gentoo's portage needs getent, which neither busybox nor toybox implements, so implement a shell script version. diff -r 62affc4225e4 -r df62eeaccb27 sources/native/bin/getent --- /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 , 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