#!/bin/sh


# Check if the user already exists
test -e /home/$1 && exit

# Add group
groupadd -g $3 maemosdk$3

# Add the user
useradd -u $2 -g $3 -p $4 -d /home/$1 -s /bin/sh $1

# Create the home directory
mkdir -p /home/$1
chmod o+w /home/$1/

# Create the ~/.sbrsh
touch /home/$1/.sbrsh
chmod og+w /home/$1/.sbrsh
mkdir -p /home/$1/sbrsh

# Create the .ssh directory
mkdir -p /home/$1/.ssh
chmod o+w /home/$1/.ssh

# Create the ssh key
rm -f /home/$1/.ssh/id_rsa*
ssh-keygen -t rsa -f /home/$1/.ssh/id_rsa -N ''

# Change the ownership of the home directory
chown -R user:maemosdk$3 /home/$1

# Change the write access for /etc/sbrshd.conf
chmod og+w /etc/sbrshd.conf

exit 0

