Magellan Linux

Diff of /trunk/mage/usr/lib/mage/museradd

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1273 by niro, Wed Apr 27 09:45:07 2011 UTC revision 2751 by niro, Thu Aug 14 12:07:06 2014 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/museradd,v 1.4 2005-06-01 15:48:43 niro Exp $  # $Id$
3    
4  # include all needed files  # include all needed files
5  [ -f /etc/mage.rc.global ] && source /etc/mage.rc.global  [ -f /etc/mage.rc.global ] && source /etc/mage.rc.global
# Line 31  busybox_fix_user_opts() Line 31  busybox_fix_user_opts()
31   -G) shift; shift; continue;; # will be parsed through fix_group_opts   -G) shift; shift; continue;; # will be parsed through fix_group_opts
32   -u) shift; [[ $1 -lt 100 ]] && FIXED_USER_OPTS+=" -S"; FIXED_USER_OPTS+=" -u $1" ;;   -u) shift; [[ $1 -lt 100 ]] && FIXED_USER_OPTS+=" -S"; FIXED_USER_OPTS+=" -u $1" ;;
33   -r) FIXED_USER_OPTS+=" -S" ;;   -r) FIXED_USER_OPTS+=" -S" ;;
34     -M) FIXED_USER_OPTS+=" -H" ;;
35     -l) continue ;; # just ignore this switch, adduser does not support it
36   *) FIXED_USER_OPTS+=" $1" ;;   *) FIXED_USER_OPTS+=" $1" ;;
37   esac   esac
38   shift   shift
# Line 55  busybox_fix_group_opts() Line 57  busybox_fix_group_opts()
57   echo "${FIXED_GROUP_OPTS}"   echo "${FIXED_GROUP_OPTS}"
58  }  }
59    
60    fix_usermod_opts()
61    {
62     local i
63     local FIXED_USERMOD_OPTS
64    
65     for i in $*
66     do
67     case $1 in
68     -M) : ;; # usermod does not support the -M switch
69     -l) : ;; # usermod -l has not the same meaning like the -l switch of useradd
70     *) FIXED_USERMOD_OPTS+=" $1" ;;
71     esac
72     shift
73     done
74    
75     echo "${FIXED_USERMOD_OPTS}"
76    }
77    
78    if [[ ! -z ${MROOT} ]] && [[ ${MROOT} != / ]]
79    then
80     chroot="chroot ${MROOT} "
81    else
82     chroot=""
83    fi
84    
85  while getopts "o:-" opt ; do  while getopts "o:-" opt ; do
86   case "${opt}" in   case "${opt}" in
87   o)   o)
# Line 84  USER_TO_ADD="$1" Line 111  USER_TO_ADD="$1"
111  # busybox support needed?  # busybox support needed?
112  if need_busybox_support adduser  if need_busybox_support adduser
113  then  then
114   echo "     Adding user '${USER_TO_ADD}' ..."   echo -n "     Adding user '${USER_TO_ADD}'"
115   adduser -D $(busybox_fix_user_opts ${USER_OPTS}) "${USER_TO_ADD}"   [[ ! -z ${chroot} ]] && echo -n " into MROOT='${MROOT}'"
116     echo " ..."
117     ${chroot} adduser -S -D $(busybox_fix_user_opts ${USER_OPTS}) "${USER_TO_ADD}"
118   for grp in $(busybox_fix_group_opts ${USER_OPTS})   for grp in $(busybox_fix_group_opts ${USER_OPTS})
119   do   do
120   addgroup "${USER_TO_ADD}" "${grp}"   ${chroot} addgroup "${USER_TO_ADD}" "${grp}"
121   done   done
122    
123  # normal systems  # normal systems
124  else  else
  #start nscd to cache passwd  
  $(which nscd) -i passwd  
125   # get the info   # get the info
126   my_user="$(getent passwd ${USER_TO_ADD})"   my_user="$(${chroot} getent passwd ${USER_TO_ADD})"
127    
128   if [ -z "${my_user}" ]   if [ -z "${my_user}" ]
129   then   then
130   echo "     Adding user '${USER_TO_ADD}' ..."   echo -n "     Adding user '${USER_TO_ADD}'"
131   useradd ${USER_OPTS} "${USER_TO_ADD}"   [[ ! -z ${chroot} ]] && echo -n " into MROOT='${MROOT}'"
132     echo " ..."
133     ${chroot} useradd -r ${USER_OPTS} "${USER_TO_ADD}"
134   else   else
135   echo "     Modifing user '${USER_TO_ADD}' ..."   echo -n "     Modifing user '${USER_TO_ADD}'"
136   usermod ${USER_OPTS} "${USER_TO_ADD}"   [[ ! -z ${chroot} ]] && echo -n " in MROOT='${MROOT}'"
137     echo " ..."
138     ${chroot} usermod $(fix_usermod_opts ${USER_OPTS}) "${USER_TO_ADD}"
139   fi   fi
140  fi  fi

Legend:
Removed from v.1273  
changed lines
  Added in v.2751