Skip to content

Commit

Permalink
Work around the fact that the usermod doesn't always have -a
Browse files Browse the repository at this point in the history
Fixes #382: Don't remove supplemental groups on install.
  • Loading branch information
Marco van Wieringen committed Dec 23, 2014
1 parent 423c64e commit 59fa771
Showing 1 changed file with 45 additions and 16 deletions.
61 changes: 45 additions & 16 deletions scripts/bareos-config-lib.sh.in
Expand Up @@ -194,23 +194,46 @@ get_database_utility_path()
setup_sd_user()
{
#
# guaranties that storage-daemon user and group exists
# Guaranties that storage-daemon user and group exists
# and storage-daemon user belongs to the required groups.
#
# normally, storage-daemon user
# is already installed by the package preinstall script.
#

#
# See what secondary groups exist for the sd user to be added to.
#
ADD_GROUPS=""
for sec_group in ${SEC_GROUPS}; do
cnt=`getent group ${sec_group} | wc -l`
if [ ${cnt} -gt 0 ]; then
[ -z "${ADD_GROUPS}" ] && ADD_GROUPS="-G ${sec_group}" || ADD_GROUPS="${ADD_GROUPS},${sec_group}"
fi
done
getent passwd ${STORAGE_DAEMON_USER} > /dev/null
if [ $? = 0 ]; then
#
# Build a list of all groups the user is already in.
#
CUR_ADD_GROUPS=`id -Gn ${STORAGE_DAEMON_USER}`
for sec_group in ${CUR_ADD_GROUPS}
do
[ -z "${USERMOD_CMDLINE}" ] && USERMOD_CMDLINE="usermod -G ${sec_group}" || USERMOD_CMDLINE="${USERMOD_CMDLINE},${sec_group}"
done

#
# See what secondary groups exist for the SD user to be added to.
#
for sec_group in ${SEC_GROUPS}; do
cnt=`getent group ${sec_group} | wc -l`
if [ ${cnt} -gt 0 ]; then
found=0
for group in ${CUR_ADD_GROUPS}
do
if [ ${group} = ${sec_group} ]; then
found=1
fi
done

if [ ${found} = 0 ]; then
[ -z "${ADD_GROUPS}" ] && ADD_GROUPS="${sec_group}" || ADD_GROUPS="${ADD_GROUPS} ${sec_group}"
[ -z "${USERMOD_CMDLINE}" ] && USERMOD_CMDLINE="usermod -G ${sec_group}" || USERMOD_CMDLINE="${USERMOD_CMDLINE},${sec_group}"
fi
fi
done
fi

getent group ${STORAGE_DAEMON_GROUP} > /dev/null || groupadd -r ${STORAGE_DAEMON_GROUP}

Expand All @@ -219,19 +242,25 @@ setup_sd_user()
#
if [ "${STORAGE_DAEMON_USER}" != "root" ]; then
getent passwd ${STORAGE_DAEMON_USER} > /dev/null
if [ $? -ne 0 ]; then
# create a new storage_daemon_user
if [ $? != 0 ]; then
#
# Create a new storage_daemon_user
#
useradd -r --comment "bareos" --home ${WORKING_DIR} -g ${STORAGE_DAEMON_GROUP} ${ADD_GROUPS} --shell /bin/false ${STORAGE_DAEMON_USER}
fi

# if the user has already created before,
# make sure the correct primary group is set otherwise fix it.
#
# If the user was already created before,
# Make sure the correct primary group is set otherwise fix it.
#
if [ "`id -gn ${STORAGE_DAEMON_USER}`" != "${STORAGE_DAEMON_GROUP}" ]; then
usermod -g ${STORAGE_DAEMON_GROUP} ${STORAGE_DAEMON_USER}
fi

#
# add the storage_daemon_user to additional groups (if defined)
[ "${ADD_GROUPS}" ] && usermod -a ${ADD_GROUPS} ${STORAGE_DAEMON_USER}
#
[ -n "${ADD_GROUPS}" ] && ${USERMOD_CMDLINE} ${STORAGE_DAEMON_USER}
fi
}

Expand Down Expand Up @@ -552,7 +581,7 @@ translate_sql_files()
mkdir -p `dirname $dest_file`
get_translated_sql_file ${SOURCE_DIR}/$i > $dest_file
# in case of errors, remove file
if [ $? -ne 0 ]; then
if [ $? != 0 ]; then
rm -f $dest_file
fi
done
Expand Down

0 comments on commit 59fa771

Please sign in to comment.