view sources/root-filesystem/bin/getent @ 1205:2b3f347dd225

Move sources/native-root to sources/root-filesystem (mostly to make tab completion work better when navigating the source).
author Rob Landley <rob@landley.net>
date Fri, 13 Aug 2010 16:34:07 -0500
parents sources/native-root/bin/getent@2d5e356580b9
children
line wrap: on
line source

#!/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