2016-07-21 14:58:46 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
USER="$1"
|
2016-07-21 19:29:32 +02:00
|
|
|
HDIR="{{ r_connector_usershome }}$USER"
|
2016-10-21 18:55:31 +02:00
|
|
|
# We use logger to log directly to syslog
|
|
|
|
LOG_PREFIX="r-connector rusersadd:"
|
|
|
|
# 0: allowed
|
|
|
|
# 1: not allowed
|
|
|
|
ALLOW_LOCAL_USERS=1
|
|
|
|
RPROFILE_FILE='{{ r_connector_rprofile_path }}/{{ r_connector_rprofile_filename }}'
|
2016-07-21 14:58:46 +02:00
|
|
|
|
|
|
|
if [ -d $HDIR ] ; then
|
2017-03-29 17:30:12 +02:00
|
|
|
if id -u $USER >/dev/null 2>&1
|
|
|
|
then
|
|
|
|
logger "$LOG_PREFIX user $HDIR directory exists. Touching the userconfig.csv file to ensure that it exists with the correct permissions"
|
|
|
|
sudo /usr/bin/touch ${HDIR}/{{ r_connector_userconfig }}
|
|
|
|
sudo /bin/chown ${USER}:{{ smartgears_user }} $HDIR/{{ r_connector_userconfig }}
|
|
|
|
sudo /usr/bin/setfacl -m u:${USER}:rw,g:{{ smartgears_user }}:rw $HDIR/{{ r_connector_userconfig }}
|
|
|
|
sudo /bin/ln -s $RPROFILE_FILE $HDIR/{{ r_connector_rprofile_filename }}
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
logger "$LOG_PREFIX user $HDIR directory exists but the user not. Aborting."
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-07-21 14:58:46 +02:00
|
|
|
else
|
2016-07-21 19:29:32 +02:00
|
|
|
if id -u $USER >/dev/null 2>&1
|
|
|
|
then
|
2016-10-21 18:55:31 +02:00
|
|
|
logger "$LOG_PREFIX ldap user $USER first login"
|
2016-10-20 20:10:56 +02:00
|
|
|
sudo /bin/mkdir -p $HDIR
|
|
|
|
sudo /bin/chown -R $USER $HDIR
|
2016-10-21 18:55:31 +02:00
|
|
|
sudo /bin/chmod g-wr,o-rwx $HDIR
|
2016-07-21 19:29:32 +02:00
|
|
|
sudo /usr/bin/touch $HDIR/{{ r_connector_userconfig }}
|
|
|
|
sudo /bin/chmod 660 $HDIR/{{ r_connector_userconfig }}
|
2017-02-16 12:34:24 +01:00
|
|
|
sudo /bin/chown $USER:{{ smartgears_user }} $HDIR/{{ r_connector_userconfig }}
|
|
|
|
sudo /usr/bin/setfacl -m u:${USER}:rw,g:{{ smartgears_user }}:rw $HDIR/{{ r_connector_userconfig }}
|
2016-10-21 18:55:31 +02:00
|
|
|
sudo /bin/chgrp {{ smartgears_user }} $HDIR
|
|
|
|
sudo /bin/ln -s $RPROFILE_FILE $HDIR/{{ r_connector_rprofile_filename }}
|
2016-07-21 19:29:32 +02:00
|
|
|
exit 0
|
|
|
|
else
|
2016-10-21 18:55:31 +02:00
|
|
|
logger "$LOG_PREFIX user $USER does not exist locally and is not an ldap user"
|
|
|
|
if [ $ALLOW_LOCAL_USERS -eq 1 ] ; then
|
|
|
|
logger "$LOG_PREFIX non ldap users not allowed, refusing to create the user."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
logger "$LOG_PREFIX non ldap users allowed, adding the user $USER locally"
|
|
|
|
sudo /usr/sbin/useradd -m -s /bin/false -g {{ smartgears_user }} $USER
|
|
|
|
sudo /bin/chmod g+ws $HDIR
|
|
|
|
sudo /usr/bin/touch $HDIR/{{ r_connector_userconfig }}
|
|
|
|
sudo /bin/chmod 660 $HDIR/{{ r_connector_userconfig }}
|
2017-02-16 12:34:24 +01:00
|
|
|
sudo /usr/bin/setfacl -m g:{{ smartgears_user }}:rw $HDIR/{{ r_connector_userconfig }}
|
2016-10-21 18:55:31 +02:00
|
|
|
sudo /bin/chgrp -R {{ smartgears_user }} $HDIR
|
|
|
|
sudo /bin/ln -s $RPROFILE_FILE $HDIR/{{ r_connector_rprofile_filename }}
|
|
|
|
exit 0
|
|
|
|
fi
|
2016-07-21 19:29:32 +02:00
|
|
|
fi
|
2016-07-21 14:58:46 +02:00
|
|
|
fi
|