2 # These functions are included by various different installers.
4 # We assume that the following variables are defined in the main script:
5 # amanda_user: the amanda account username
6 # amanda_group: the amanda account's group
7 # amandahomedir: a directory to use as amanda's home
8 # deb_uid: sepecific uid amanda_user should get on deb style systems.
9 # dist: used on linux for the distro.
10 # LOGFILE: a log file we append to
11 # os: Linux, Darwin, SunOS, `uname`...
12 # SYSCONFDIR: location of system config files (ie, /etc)
13 # LOGDIR: logging directory for amanda
15 # These variables are defined, but null to allow checking names
18 # PreInstall Functions
23 # Create the amanda user with a specific uid on deb systems
24 if [ ${dist} = "Debian" -o ${dist} = "Ubuntu" ] ; then
25 uid_flag="-u ${deb_uid}"
29 logger "Checking for user: ${amanda_user}"
30 # we want the output of id, but if the user doesn't exist,
31 # sterr output just confuses things
32 ID=`id ${amanda_user} 2> /dev/null | sed 's/uid=\([0-9]*\).*/\1/'`
33 if [ "${ID}x" = "x" ] ; then
34 logger "Adding ${amanda_user}."
35 log_output_of useradd -c "Amanda" \
39 -s /bin/bash ${amanda_user} || \
40 { logger "WARNING: Could not create user ${amanda_user}. Installation will fail." ; return 1 ; }
42 if [ "$os" = "Linux"] && [ ${dist} != "SuSE" ]; then
43 # Lock the amanda account until admin sets password
44 log_output_of passwd -l ${amanda_user} || { \
45 logger "${warning_user_passwd}"; }
47 if [ "$os" = "SunOS" ]; then
49 5.8|5.9) log_output_of passwd -l ${amanda_user};;
50 5.10) # Special login-lock, while allowing execution.
51 log_ouptut_of passwd -N ${amanda_user} || { \
52 logger "${warning_user_passwd}"; }
57 logger "${info_create_user_success}"
59 # The user already existed
60 logger "${info_user_params}"
69 # Try to add the group, detect via return code if it already exists.
70 # This works on linux and solaris...
71 log_output_of groupadd ${1}
72 # return of 0 means group was added; 9 means group existed.
73 if [ $? = "0" ] || [ $? = "9" ]; then
74 logger "Adding ${amanda_user} to ${1}"
76 Linux) um_flags="-a -G";;
77 # Solaris does not have -a flag.
78 SunOS) um_flags="-G `groups ${amanda_user}`";;
80 # So far, all linux distros have usermod
81 log_output_of usermod -a -G ${1} ${amanda_user} || \
82 { logger "${error_group_member}" ; return 1 ; }
84 logger "Error: groupadd failed in an unexpected way."
90 # Check parameters of ${amanda_user}'s account.
91 # $1= user field $2= value to check
92 # group, shell, homedir, UID are valid for $1.
93 # group: checks the system group file for ${amanda_user}'s
94 # membership in the group named $2.
95 # shell: confirms the passwd file's shell field for
96 # ${amanda_user} is $2
97 # homedir: confirm the passwd file's homedir field for
98 # ${amanda_user} is $2
99 # UID: confirm that ${amanda_user}'s UID is $2.
101 # Extra information about the failed check is written to the log.
108 if [ ! $# -eq 2 ]; then
109 echo "check_user(): Wrong number of parameters"
112 logger "Verify ${amanda_user}'s $1 = $2 "
115 # Check if the group exists, disregarding membership.
116 if `grep "^${2}" ${SYSCONFDIR}/group > /dev/null` ; then
117 # Assume the user exists, and check the user's primary group.
118 GROUP=`id ${amanda_user} 2> /dev/null | sed 's/.*gid=[0-9]*(\([^ ()]*\))/\1/'`
119 if [ ! "x${GROUP}" = "x${2}" ] ; then
120 logger "${amanda_user} not a member of ${2}"
124 logger "User group '${2}' does not exist"
129 # Check if a supplementary group exists.
130 SUP_MEM=`awk -F: "\$1 ~ ${2} { print \$4; }" 2> /dev/null`
131 if [ -n "$SUP_MEM" ] ; then
132 # Check if our user is a member.
133 if echo "${SUP_MEM}"|grep "${amanda_user}" &> /dev/null ; then
136 logger "${amanda_user} is not a member of supplemental group ${2}."
140 logger "Supplemental group ${2} does not exist"
145 SHELL=`grep "^${amanda_user}" ${SYSCONFDIR}/passwd | cut -d: -f7`
146 wanted_shell=$2; export wanted_shell
147 if [ ! "x${SHELL}" = "x${2}" ] ; then
148 logger "${warning_user_shell}"
153 HOMEDIR=`grep "^${amanda_user}" ${SYSCONFDIR}/passwd | cut -d: -f6`
154 if [ ! "x${HOMEDIR}" = "x${2}" ] ; then
155 logger "${warning_user_homedir}"
160 # Debian systems must use a specific UID
161 ID=`id ${amanda_user} 2> /dev/null | sed 's/uid=\([0-9]*\).*/\1/'`
162 if [ ! "${ID}" -eq "${2}" ] ; then
163 checked_uid=${2}; export checked_uid
164 logger "${warning_user_uid_debian}"
169 echo "check_user(): unknown user parameter."
178 # Checks that the homedir has correct permissions and belongs to correct
179 # user. Uses $amanda_user and $amanda_group.
180 if [ -d ${AMANDAHOMEDIR} ] ; then
181 OWNER_GROUP=`ls -dl ${AMANDAHOMEDIR} | awk '{ print $3" "$4; }'`
182 [ "$OWNER_GROUP" = "${amanda_user} ${amanda_group}" ] || \
183 logger "${warning_homedir_owner}"
186 logger "homedir ${AMANDAHOMEDIR} does not exist."
192 # Creates the homedir, if necessary, and fixes ownership.
193 if [ ! -d ${AMANDAHOMEDIR} ] ; then
194 logger "Creating ${AMANDAHOMEDIR}"
195 log_output_of mkdir -p -m 0750 ${AMANDAHOMEDIR} ||
196 { logger "WARNING: Could not create ${AMANDAHOMEDIR}" ; return 1 ; }
198 log_output_of chown -R ${amanda_user}:${amanda_group} ${AMANDAHOMEDIR} ||
199 { logger "WARNING: Could not chown ${AMANDAHOMEDIR}" ; return 1 ; }
203 if [ -d ${LOGDIR} ] || [ -f ${LOGDIR} ] ; then
204 logger "Found existing ${LOGDIR}"
205 log_output_of mv ${LOGDIR} ${LOGDIR}.save || \
206 { logger "WARNING: Could not backup existing log directory: ${LOGDIR}" ; return 1 ; }
208 logger "Creating ${LOGDIR}."
209 log_output_of mkdir -p -m 0750 ${LOGDIR} || \
210 { logger "WARNING: Could not create ${LOGDIR}" ; return 1 ; }
211 if [ -d ${LOGDIR}.save ] || [ -f ${LOGDIR}.save ] ; then
212 # Move the saved log into the logdir.
213 log_output_of mv ${LOGDIR}.save ${LOGDIR}
215 log_output_of chown -R ${amanda_user}:${amanda_group} ${LOGDIR} || \
216 { logger "WARNING: Could not chown ${LOGDIR}" ; return 1 ; }
219 # Info, Warning, and Error strings used by the installer
221 info_create_user_success="The '${amanda_user}' user account has been successfully created.
222 Furthermore, the account has been automatically locked for you for security
223 purposes. Once a password for the '${amanda_user}' account has been set,
224 the user can be unlocked by issuing the following command as root.:
226 # passwd -u ${amanda_user}
228 If this is not a new installation of Amanda and you have pre-existing Amanda
229 configurations in ${SYSCONFDIR}/amanda you should ensure that 'dumpuser'
230 is set to '${amanda_user}' in those configurations. Additionally, you
231 should ensure that ${AMANDAHOMEDIR}/.amandahosts on your client systems
232 is properly configured to allow connections for the user '${amanda_user}'."
234 warning_user_password="!!! WARNING! WARNING! WARNING! WARNING! WARNING! !!!
236 !!! The '${amanda_user}' user account for this system has been !!!
237 !!! created, however the user has no password set. For !!!
238 !!! security purposes this account is normally locked after !!!
239 !!! creation. Unfortunately, when locking this account an !!!
240 !!! error occurred. To ensure the security of your system, !!!
241 !!! you should set a password for the user account !!!
242 !!! '${amanda_user}' immediately! To set such a password, !!!
243 !!! please issue the following command: !!!
245 !!! # passwd ${amanda_user} !!!
247 !!! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! !!!"
249 info_user_params="The Amanda backup software is configured to operate as the user
250 '${amanda_user}'. This user exists on your system and has not been modified.
251 To ensure that Amanda functions properly, please see that the following
252 parameters are set for that user:
254 HOME: ${AMANDAHOMEDIR}
255 Default group: ${amanda_group}"
257 error_group_member="!!! Nonfatal ERROR. Nonfatal ERROR. !!!
258 !!! user '${amanda_user}' is not part of the '${amanda_group}' group, !!!
259 !!! Amanda will not run until '${amanda_user}' is a member of '${amanda_group}'. !!!
260 !!! Nonfatal ERROR. Nonfatal ERROR. Nonfatal Error. !!!"
262 warning_user_shell="WARNING: The user '${amanda_user}' has a non-default shell.
263 the default shell is ${wanted_shell}. Other shells have not been tested."
265 warning_user_homedir="!!! WARNING! WARNING! WARNING! WARNING! WARNING! !!!
266 !!! The user '${amanda_user}' must have its home directory set to !!!
267 !!! '${AMANDAHOMEDIR}' Please correct before using Amanda !!!
268 !!! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! !!!"
270 warning_user_uid_debian="!!! WARNING! WARNING! WARNING! WARNING! WARNING! !!!
271 !!! Debian packages were built assuming that ${amanda_user} !!!
272 !!! uid = ${checked_uid}. The uid of ${amanda_user} is different !!!
273 !!! different on this system. Files owned by ${checked_uid} must !!!
274 !!! be chowned to ${amanda_user}. !!!
275 !!! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! !!!"
277 warning_homedir_owner="!!! Please ensure that the directory '${AMANDAHOMEDIR}' is owned by !!!
278 !!! the user '${amanda_user}' and group '${amanda_group}'. !!!"
280 # --------------- End included Functions -----------------