source: src-sh/pc-sysinstall/backend/functions-users.sh @ 00f1c03

releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 00f1c03 was 00f1c03, checked in by ericbsd <ericturgeon.bsd@…>, 8 months ago

Adding GDM autologing code for GhostBSD

  • Property mode set to 100755
File size: 5.8 KB
Line 
1#!/bin/sh
2#-
3# Copyright (c) 2010 iXsystems, Inc.  All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9#    notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11#    notice, this list of conditions and the following disclaimer in the
12#    documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24# SUCH DAMAGE.
25#
26# $FreeBSD: head/usr.sbin/pc-sysinstall/backend/functions-users.sh 220059 2011-03-27 16:57:54Z jpaetzel $
27
28# Functions which runs commands on the system
29
30. ${BACKEND}/functions.sh
31. ${BACKEND}/functions-parse.sh
32
33
34# Function which checks and sets up auto-login for a user if specified
35check_autologin()
36{
37  get_value_from_cfg autoLoginUser
38  if [ -n "${VAL}"  -a "${INSTALLTYPE}" = "PCBSD" ]
39  then
40    AUTOU="${VAL}"
41    # Add the auto-login user line
42    sed -i.bak "s/AutoLoginUser=/AutoLoginUser=${AUTOU}/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc
43
44    # Add the auto-login user line
45    sed -i.bak "s/AutoLoginEnable=false/AutoLoginEnable=true/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc
46  elif [ -a "${INSTALLTYPE}" = "GhostBSD" ]
47  then
48    if [ -n "${VAL}" ]
49    then
50      AUTOU="${VAL}"
51      # Adding the auto-login user line
52      sed -i "" "/default_user/s/ghostbsd/${AUTOU}/g" ${FSMNT}/usr/local/etc/gdm/custom.conf
53    else
54      # Remmoving the auto-login & ghostbsd user line
55      sed -i "" "/AutomaticLoginEnable/s/true/false/g" ${FSMNT}/usr/local/etc/gdm/custom.conf
56      ( echo 'g/AutomaticLogin=ghostbsd/d' ; echo 'wq' ) | ex -s ${FSMNT}/etc/rc.conf
57    fi
58  fi
59};
60
61# Function which actually runs the adduser command on the filesystem
62add_user()
63{
64 ARGS="${1}"
65
66 if [ -e "${FSMNT}/.tmpPass" ]
67 then
68   # Add a user with a supplied password
69   run_chroot_cmd "cat /.tmpPass | pw useradd ${ARGS}"
70   rc_halt "rm ${FSMNT}/.tmpPass"
71 else
72   # Add a user with no password
73   run_chroot_cmd "cat /.tmpPass | pw useradd ${ARGS}"
74 fi
75
76};
77
78# Function which reads in the config, and adds any users specified
79setup_users()
80{
81
82  # First check integrity of /home && /usr/home
83  if [ ! -e "${FSMNT}/home" ] ; then
84        run_chroot_cmd "ln -s /usr/home /home"
85  fi
86  if [ ! -d "${FSMNT}/usr/home" ] ; then
87        run_chroot_cmd "mkdir /usr/home"
88  fi
89
90  # We are ready to start setting up the users, lets read the config
91  while read line
92  do
93
94    echo $line | grep -q "^userName=" 2>/dev/null
95    if [ $? -eq 0 ]
96    then
97      get_value_from_string "${line}"
98      USERNAME="$VAL"
99    fi
100
101    echo $line | grep -q "^userComment=" 2>/dev/null
102    if [ $? -eq 0 ]
103    then
104      get_value_from_string "${line}"
105      USERCOMMENT="$VAL"
106    fi
107
108    echo $line | grep -q "^userPass=" 2>/dev/null
109    if [ $? -eq 0 ]
110    then
111      get_value_from_string "${line}"
112      USERPASS="$VAL"
113    fi
114
115    echo $line | grep -q "^userEncPass=" 2>/dev/null
116    if [ $? -eq 0 ]
117    then
118      get_value_from_string "${line}"
119      USERENCPASS="$VAL"
120    fi
121
122    echo $line | grep -q "^userShell=" 2>/dev/null
123    if [ $? -eq 0 ]
124    then
125      get_value_from_string "${line}"
126      strip_white_space "$VAL"
127      USERSHELL="$VAL"
128    fi
129
130    echo $line | grep -q "^userHome=" 2>/dev/null
131    if [ $? -eq 0 ]
132    then
133      get_value_from_string "${line}"
134      USERHOME="$VAL"
135    fi
136
137    echo $line | grep -q "^userGroups=" 2>/dev/null
138    if [ $? -eq 0 ]
139    then
140      get_value_from_string "${line}"
141      USERGROUPS="$VAL"
142    fi
143
144
145    echo $line | grep -q "^commitUser" 2>/dev/null
146    if [ $? -eq 0 ]
147    then
148      # Found our flag to commit this user, lets check and do it
149      if [ -n "${USERNAME}" ]
150      then
151
152        # Now add this user to the system, by building our args list
153        ARGS="-n ${USERNAME}"
154
155        if [ -n "${USERCOMMENT}" ]
156        then
157          ARGS="${ARGS} -c \"${USERCOMMENT}\""
158        fi
159         
160        if [ -n "${USERPASS}" ]
161        then
162          ARGS="${ARGS} -h 0"
163          echo "${USERPASS}" >${FSMNT}/.tmpPass
164        elif [ -n "${USERENCPASS}" ] 
165        then
166          ARGS="${ARGS} -H 0"
167          echo "${USERENCPASS}" >${FSMNT}/.tmpPass
168        else
169          ARGS="${ARGS} -h -"
170          rm ${FSMNT}/.tmpPass 2>/dev/null 2>/dev/null
171        fi
172
173        if [ -n "${USERSHELL}" ]
174        then
175          ARGS="${ARGS} -s \"${USERSHELL}\""
176        else
177          ARGS="${ARGS} -s \"/nonexistant\""
178        fi
179         
180        if [ -n "${USERHOME}" ]
181        then
182          ARGS="${ARGS} -m -d \"${USERHOME}\""
183        fi
184
185        if [ -n "${USERGROUPS}" ]
186        then
187          ARGS="${ARGS} -G \"${USERGROUPS}\""
188        fi
189
190        add_user "${ARGS}"
191
192        # Unset our vars before looking for any more users
193        unset USERNAME USERCOMMENT USERPASS USERENCPASS USERSHELL USERHOME USERGROUPS
194      else
195        exit_err "ERROR: commitUser was called without any userName= entry!!!" 
196      fi
197    fi
198
199  done <${CFGF}
200
201
202  # Check if we need to enable a user to auto-login to the desktop
203  check_autologin
204
205};
Note: See TracBrowser for help on using the repository browser.