--Boundary-00=_MVNgJlst5O6nZ7l
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
My friend Mark is working on a project called Gentoo From Scratch (faking a
gentoo stage 1 environment by getting gentoo's portage to run on top of a
uClibc/busybox base system), and it turns out portage needs "getent", which is
a horrible gnu extension that ain't in SUSv4.
Here's a small shell script that more or less implements it. FYI.
Rob
--Boundary-00=_MVNgJlst5O6nZ7l
Content-Type: application/x-shellscript;
name="getent"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="getent"
#!/bin/sh
# Copyright 2009 Rob Landley <[email protected]>, 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
--Boundary-00=_MVNgJlst5O6nZ7l--
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox