summaryrefslogtreecommitdiffstats
path: root/server/modules/local_accounts/opt/openslx/scripts/systemd-create_users
diff options
context:
space:
mode:
Diffstat (limited to 'server/modules/local_accounts/opt/openslx/scripts/systemd-create_users')
-rwxr-xr-xserver/modules/local_accounts/opt/openslx/scripts/systemd-create_users57
1 files changed, 57 insertions, 0 deletions
diff --git a/server/modules/local_accounts/opt/openslx/scripts/systemd-create_users b/server/modules/local_accounts/opt/openslx/scripts/systemd-create_users
new file mode 100755
index 00000000..3ac554b5
--- /dev/null
+++ b/server/modules/local_accounts/opt/openslx/scripts/systemd-create_users
@@ -0,0 +1,57 @@
+#!/bin/ash
+
+. /opt/openslx/config || { echo "Could not source config!"; exit 23; }
+
+create_user(){
+# generate the new lines that will be merged into the /etc/{passwd,shadow,group} files
+ unset IFS
+ if useradd -s /bin/bash -m $1 -K UID_MIN=1000 -K GID_MIN=1000; then # if the users doesn't exists, create him without the password
+ if [ -n "$2" ]; then
+ sed -i "s#^$1:[^:]*:#$1:$2:#" "/etc/shadow" # set the password in the /etc/shadow file
+ fi
+ else
+ echo 'user $1 already exists'
+ if [ -n "$2" ] && [ $(grep ^$1: /etc/shadow | cut -d ':' -f2) != $2 ]; then # if the user already exists, check if the password has changed
+ echo "changing password to the new one"
+ sed -i "s#^$1:[^:]*:#$1:$2:#" "/etc/shadow" # set the password in the /etc/shadow file
+ fi
+ fi
+}
+
+mount | grep "/home" > /dev/null
+if [ $? -eq 0 ]; then
+ # check if the /home partition exists
+ echo "/home partition found"
+ if useradd -s /bin/bash -m openslx -K UID_MIN=1000 -K GID_MIN=1000; then # try to create the 'openslx' user, will fail if it already exists
+ echo "user openslx created"
+ sed -i "s#^openslx:[^:]*:#openslx:$OPENSLX_PASS:#" "/etc/shadow" # set the password in the /etc/shadow file
+ fi
+
+ for line in $SLX_USERS; do # create the accounts specified in the SLX_USERS config.
+ IFS=,
+ set $line
+ create_user $1 $2
+ done
+
+ for file in passwd shadow group; do
+ #backup files before patching to save slxbox state
+ echo "Backing up /etc/$file at /home/openslx/.$file.backup"
+ cp /etc/$file /home/openslx/.$file.backup
+
+ # apply patch of users created by the admin in the last session.
+ if [ -e /home/openslx/.$file.patch ]; then
+ patch /etc/$file < /home/openslx/.$file.patch
+ fi
+ done
+else # if no /home partition was found, will create the user but won't do the patch and backup.
+ echo "No /home partition found on hdd. Creating non permanent users from slxbox."
+ if useradd -s /bin/bash -m openslx -K UID_MIN=1000 -K GID_MIN=1000; then # try to create the 'openslx' user, will fail if it already exists
+ echo "user openslx created"
+ sed -i "s#^openslx:[^:]*:#openslx:$OPENSLX_PASS:#" "/etc/shadow" # set the password in the /etc/shadow file
+ fi
+ for line in $SLX_USERS; do # create the accounts specified in the SLX_USERS config.
+ IFS=,
+ set $line
+ create_user $1 $2
+ done
+fi \ No newline at end of file