#!/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