diff options
author | Jonathan Bauer | 2015-04-07 17:43:23 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-04-07 17:43:23 +0200 |
commit | b1074927e6848d7370c6d4a1b11b7149d6660a77 (patch) | |
tree | 89dfef802d48522d297632cb77fe13825707ff3e /server/modules/local_accounts/opt/openslx/scripts/systemd-local_accounts | |
parent | [pam-common-share] rudimentary nfs-support for common share (diff) | |
parent | [hdd-boot] michi's werk (diff) | |
download | tm-scripts-mergetest.tar.gz tm-scripts-mergetest.tar.xz tm-scripts-mergetest.zip |
Merge remote-tracking branch 'remotes/origin/test' into mergetestmergetest
Diffstat (limited to 'server/modules/local_accounts/opt/openslx/scripts/systemd-local_accounts')
-rwxr-xr-x | server/modules/local_accounts/opt/openslx/scripts/systemd-local_accounts | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/server/modules/local_accounts/opt/openslx/scripts/systemd-local_accounts b/server/modules/local_accounts/opt/openslx/scripts/systemd-local_accounts new file mode 100755 index 00000000..5cabd4fd --- /dev/null +++ b/server/modules/local_accounts/opt/openslx/scripts/systemd-local_accounts @@ -0,0 +1,66 @@ +#!/bin/ash + +. /opt/openslx/config || { echo "Could not source config!"; exit 23; } + +#generate new user with useradd and insert password in /etc/shadow if exists +create_user(){ + local username="$1" + local password="$2" + uset IFS + + #if the users doesn't exists, create him without the password + if useradd -s /bin/bash -m "$username" -K UID_MIN=1000 -K GID_MIN=1000; then + if [ -n "$password" ]; then + #set the password in the /etc/shadow file + sed -i "s#^${username}:[^:]*:#${username}:${password}:#" "/etc/shadow" + fi + else + echo 'user ${username} already exists' + #if the user already exists, check if the password has changed + if [ -n "$password" ] && [ $(grep ^${username}: /etc/shadow | cut -d ':' -f2) != "$password" ]; then + echo "User password changed, updating /etc/shadow to new one" + #set the password in the /etc/shadow file + sed -i "s#^${username}:[^:]*:#${username}:${password}:#" "/etc/shadow" + fi + fi +} + +# check if the /home partition exists +if mount | grep "/home" > /dev/null; then + echo "/home partition found" + + #try to create the 'openslx' user in whose home dir backups and patch files will be stored + if useradd -s /bin/bash -m openslx -K UID_MIN=1000 -K GID_MIN=1000; then + echo "user openslx created" + #set the password in the /etc/shadow file + sed -i "s#^openslx:[^:]*:#openslx:$OPENSLX_PASS:#" "/etc/shadow" + fi + + #create the accounts specified in the SLX_USERS config. + for line in $SLX_USERS; do + IFS=, + set $line + create_user $1 $2 + done + + #patch passwd, shadow and group with changes the local admin made in that machine + 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." + for line in $SLX_USERS; do # create the accounts specified in the SLX_USERS config. + IFS=, + set $line + create_user $1 $2 + done +fi |