| 1 | #!/bin/bash |
| 2 | # Author: Steven Shiau <steven _at_ clonezilla org>, Ceasar Sun <ceasar _at_ nchc org tw> |
| 3 | # License: GPL |
| 4 | # Description: Get the common users name (not system related users name) |
| 5 | |
| 6 | export LC_ALL=C |
| 7 | |
| 8 | #uid_tmp="$(mktemp /tmp/uid_tmp.XXXXXX)" |
| 9 | # We can get the minum UID of YP from /var/yp/Makefile |
| 10 | #grep -E "^MINUID=" /var/yp/Makefile 2>/dev/null > $uid_tmp |
| 11 | #. $uid_tmp |
| 12 | #[ -f $uid_tmp ] && rm -f $uid_tmp |
| 13 | |
| 14 | MINUID="$(LC_ALL=C grep -E '^UID_MIN\s+[0-9]+' /etc/login.defs | sed -e 's/^UID_MIN//')" |
| 15 | |
| 16 | # If we can not find minum UID of YP from /var/yp/Makefile, we use specific rules. |
| 17 | if [ -z "$MINUID" ]; then |
| 18 | if [ -e /etc/debian_version ]; then |
| 19 | # For Debian, the common users uid start from 1000 |
| 20 | MINUID="1000" |
| 21 | elif [ -e /etc/SuSE-release ]; then |
| 22 | # SuSE |
| 23 | # the common users uid start from 1000 |
| 24 | MINUID="1000" |
| 25 | else |
| 26 | # For RH-like, the common users uid start from 500 |
| 27 | MINUID="500" |
| 28 | fi |
| 29 | fi |
| 30 | |
| 31 | users="$(awk -F":" "\$3 >= $MINUID {print \$1}" /etc/passwd)" |
| 32 | |
| 33 | # Remove account "nobody" from the list if it exists, we need nobody as local account. Since some services are started with nobody, and it is started before nis/yp is started. |
| 34 | users="$(echo $users | sed -e "s/nobody//g")" |
| 35 | |
| 36 | # if not found, return 1 |
| 37 | [ -z "$users" ] && exit 1 |
| 38 | |
| 39 | echo $users |
| 40 | exit 0 |