#!/bin/sh
#
# /usr/local/bin/adduser script from the Anonymizing Unix Project
# by van Hauser / THC <vh@reptile.rug.ac.be>
#
# This script adds a user to a system and includes the privacy setup (CFS)
#
if [ -z $1 ]; then
    echo "Syntax: $0 user"
    echo "Adds a user to the system and includes the privacy setup (CFS)"
    exit 1
fi

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
cd /
umask 077

#
# Run useradd
echo "# Adding user $1"
useradd -d /home/$1 -s /bin/bash $1

#
# Generate a password for the user
echo -e "\n# Enter login password for user $1:"
passwd $1

#
# Setup CFS for the user
# If your CFS supports blowfish (-b) use that cypher. Here it uses 3-DES
echo -e "\n# Enter CFS home directory password for user $1:"
cmkdir -3 /crypt/$1 || cmkdir -3 /crypt/$1 || cmkdir -3 /crypt/$1 || exit 1

echo -e "\n# Installing /etc/skel files, please retype the CFS home directory password
# for user $1:"
cattach /crypt/$1 $1 || cattach /crypt/$1 $1 || cattach /crypt/$1 $1 || exit 1

cd /etc/skel
cp -a * .[^.]* /home/$1 2> /dev/null
mkdir /home/$1/tmp 2> /dev/null
cdetach $1
chown -R $1 /crypt/$1
echo -e "\n# Done."

# done
