binutils: update to 2.43.1
[openadk.git] / package / base-files / src / etc / functions.sh
blob8b2b3d66588f244bafab16772987d44013bf052d
1 # newline
2 N="
5 append() {
6 local var="$1"
7 local value="$2"
8 local sep="${3:- }"
10 eval "export -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
13 load_modules() {
14 if [ -d /lib/modules/$(uname -r) ]; then
15 (sed "s,^[^#][^[:space:]]*,insmod /lib/modules/$(uname -r)/&.ko," $* | sh 2>&- || :)
19 user_exists() {
20 grep -q "^$1:" $IPKG_INSTROOT/etc/passwd 2>&-
23 group_exists() {
24 grep -q "^$1:" $IPKG_INSTROOT/etc/group 2>&-
27 service_exists() {
28 grep -q "^$1[[:space:]]*$2" $IPKG_INSTROOT/etc/services 2>&-
31 rcconf_exists() {
32 grep -q "^#*$1=" $IPKG_INSTROOT/etc/rc.conf 2>&-
35 add_user() {
36 user_exists $1 || {
37 echo "adding user $1 to /etc/passwd"
38 echo "$1:x:$2:${3:-$2}:$1:${4:-/tmp}:${5:-/bin/false}" \
39 >>$IPKG_INSTROOT/etc/passwd
43 add_group() {
44 group_exists $1 || {
45 echo "adding group $1 to /etc/group"
46 echo "$1:x:$2:$3" >>$IPKG_INSTROOT/etc/group
50 add_service() {
51 service_exists $1 $2 || {
52 echo "adding service $1 to /etc/services"
53 printf '%s\t%s\n' "$1" "$2" >>$IPKG_INSTROOT/etc/services
57 add_rcconf() {
58 rcconf_exists $1 || {
59 echo "adding service $1 to /etc/rc.conf"
60 printf '%s="%s"\n' "${1}" "${2:-NO}" \
61 >>$IPKG_INSTROOT/etc/rc.conf
65 get_next_uid() {
66 uid=1
67 while grep "^[^:]*:[^:]*:$uid:" $IPKG_INSTROOT/etc/passwd \
68 >/dev/null 2>&1; do
69 uid=$(($uid+1))
70 done
71 echo $uid
74 get_next_gid() {
75 gid=1
76 while grep "^[^:]*:[^:]*:$gid:" $IPKG_INSTROOT/etc/group \
77 >/dev/null 2>&1; do
78 gid=$(($gid+1))
79 done
80 echo $gid