cosmic/cosmic-ship

36 lines
1004 B
Bash
Executable File

#!/bin/sh
run_user=$(id -u)
if [ "$run_user" -eq 0 ]; then
n="$1"
s="$2"
if [ ! -z "$n" ]; then
user_exists=$(id -u "${n}" 2> /dev/null)
if [ ! -z "${user_exists}" ]; then
if [ ! -z "${s}" ]; then
path="/var/gopher/${s}"
if [ ! -d "$path" ]; then
printf "Creating ship '%s' for user '%s'\\n" "${s}" "${n}"
mkdir "$path"
chmod 755 "$path"
chown -R "${n}" "$path"
mkdir -p "/home/${n}/ships"
ln -s "$path" "/home/${n}/ships/${s}"
sed -e "s/username/${n}/g" -e "s/shipname/${s}/" /etc/newship.tmpl | sendmail "${n}" "tomasino"
else
owner=$(stat -c %U "$path")
printf "That ship or colony already exists and is owned by %s\\n" "$owner"
fi
else
printf "Specificy a ship or colony name.\\n"
fi
else
printf "User not found.\\n"
fi
else
printf "Specify a user.\\n"
fi
else
printf "You must be root to run this script.\\n"
fi