#!/bin/bash #Copyright 2002 William Stearns #Released under the GPL CondMkdir () { #Modified from the version in uml/functions while [ -n "$1" ]; do if [ -e "$1" ]; then if [ ! -d "$1" ]; then echo "$1" exists but is not a directory, not creating it. return 1 else echo \("$1" exists\) fi else echo "Making $1" $SUDO mkdir --parents "$1" fi shift done } renice +15 -p $$ >/dev/null 2>&1 SourceDir='/home/shared/uml/' if [ -z "$1" ]; then echo Usage: echo $0 '[username] [distribution]' echo 'where distribution is rh73 (default), de30, or fc2' echo Exiting exit 1 fi case "$1" in .*|/*|*/|*/*|pub|shared) echo No username games, please, exiting. exit 1 ;; esac if [ ! -d "/home/$1" ]; then echo Please set up "$1" as a user first - \"adduser "$1"\", perhaps. Exiting. exit 1 fi #FIXME - check that a $1 user and $1 group entry exist. if [ -n "$2" ]; then case "$2" in [Rr][Hh]73) Dist=rh73 RootBase=root_fs.rh-7.3-full.pristine.20020905.zaphod ;; [Dd][Ee]30) Dist=de30 RootBase=Debian-3.0r0.ext3.zaphod ;; [Ff][Cc]2) Dist=fc2 RootBase=root_fs.fc-2-client.pristine.20040504 ;; *) echo Unknown distribution \""$2"\", exiting. exit 1 ;; esac else Dist=rh73 RootBase=root_fs.rh-7.3-full.pristine.20020905.zaphod fi echo Using distribution "$Dist", file "$RootBase" #Because we're allowing people non-chrooted access to the host #filesystem, but don't want people logging in to the actual host, we're #locking down the host home directories so that they shouldn't be able #to log in. echo Locking down "/home/$1" chmod 500 "/home/$1" CondMkdir "/home/$1/.ssh" "/home/$1/.ssh2" chmod 000 "/home/$1/.ssh" "/home/$1/.ssh2" #Create /home/shared and /home/pub once CondMkdir /home/pub /home/shared chown root.root /home/pub /home/shared #Give them a writeable directory in /home/pub and /home/shared, and make #the top level directories for uml storage and uml backup CondMkdir "/home/pub/$1" "/home/shared/$1" "/home/$1/.uml" "/home/$1/backup" chown "$1.$1" "/home/pub/$1" "/home/shared/$1" "/home/$1/.uml" "/home/$1/backup" chmod 755 "/home/pub/$1" "/home/shared/$1" "/home/$1/.uml" "/home/$1/backup" if [ ! -e "/home/$1/.uml/$1" ]; then echo Creating linux binary ln -sf $SourceDir/linux "/home/$1/.uml/$1" else echo \(linux binary already linked\) fi #The swap file is copied over fresh at every uml start - no need to copy it now. #if [ ! -e "/home/$1/.uml/swap" ]; then # echo Copying swap # cp -p --sparse=always $SourceDir/swap.512.pristine "/home/$1/.uml/swap" # chown "$1.$1" "/home/$1/.uml/swap" # chmod 644 "/home/$1/.uml/swap" #else # echo \(swap already exists\) #fi if [ ! -e "/home/$1/.uml/$RootBase" ]; then echo Linking $RootBase ln -f $SourceDir/$RootBase "/home/$1/.uml/$RootBase" else echo \(pristine root filesystem already linked\) fi if [ ! -e "/home/$1/.uml/home" ]; then echo Copying home partition cp -p --sparse=always $SourceDir/home.8192.pristine "/home/$1/.uml/home" chown "$1.$1" "/home/$1/.uml/home" chmod 644 "/home/$1/.uml/home" else echo \(home filesystem already exists\) fi if [ ! -e "/home/$1/.uml/params" ]; then echo Creating default params file echo "umid=$1-id mem=160M ubd0=/home/$1/.uml/root_fs.cow,/home/$1/.uml/$RootBase ubd1=/home/$1/.uml/swap ubd2=/home/$1/.uml/home eth0=daemon,FE:FD:42:3B:6F:BF con=pty con0=fd:0,fd:1" >"/home/$1/.uml/params" else echo \(params already exists\) fi