From 0c9ae7ba033687de2e1eea5e2a12c190a561c01a Mon Sep 17 00:00:00 2001 From: Michael Pereira Neves Date: Tue, 11 Nov 2014 18:34:21 -0200 Subject: [local-account] rename systemd script for local accounts --- .../opt/openslx/scripts/systemd-create_users | 66 ---------------------- .../opt/openslx/scripts/systemd-local_accounts | 66 ++++++++++++++++++++++ 2 files changed, 66 insertions(+), 66 deletions(-) delete mode 100755 server/modules/local_accounts/opt/openslx/scripts/systemd-create_users create mode 100755 server/modules/local_accounts/opt/openslx/scripts/systemd-local_accounts diff --git a/server/modules/local_accounts/opt/openslx/scripts/systemd-create_users b/server/modules/local_accounts/opt/openslx/scripts/systemd-create_users deleted file mode 100755 index 5cabd4fd..00000000 --- a/server/modules/local_accounts/opt/openslx/scripts/systemd-create_users +++ /dev/null @@ -1,66 +0,0 @@ -#!/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 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 -- cgit v1.2.3-55-g7522