#!/bin/bash # # mkjail v0.4: chroot jail maker # feedback: rhatto at riseup.net | GPL # BASE_CONF=/etc/mkjail CONF=$BASE_CONF/mkjail.conf # under the config file, adjust this to where your things live # PACKAGES="/storage/vserver/slack/" # DEVICES="/storage/vserver/devices.tar.gz" # SCRIPTS="/storage/vserver/etc/" # GPGKEY="/storage/vserver/slack/GPG-KEY" # SKEL="/storage/vserver/skel.conf" if [ -f "$CONF" ]; then source $CONF else echo $0 error: config file $CONFIG not found exit 1 elif (($# != 1)); then echo "usage: $0 [template]" exit 1 elif [ -d "/vservers/$1" ]; then echo $0 error: vserver $1 already exists exit 1 fi if [[ ! -z "$2" && -f "$BASE_CONF/$2.template"]]; then TEMPLATE="$BASE_CONF/$2.template" elif [ -f "$BASE_CONF/default.template" ] echo template $2 not found, using default template else echo $0 error: no templates found echo please create a template using templatepkg exit 1 fi server=$1 mkdir /vservers/$server echo "instaling packages..." for pack in `cat $TEMPLATE`; do installpkg --root /vservers/$server `searchpkg -1 $pack` done echo "creating /etc/ and copying init scripts" if [ -d "$BASE_CONF/$template" ]; then rsync -Cav $BASE_CONF/$template/ /vservers/$server/ fi cp /etc/resolv.conf /vservers/$server/etc/ cp /etc/localtime /vservers/$server/etc/ echo /dev/hdv1 / ext2 defaults 1 1 > /vservers/$server/etc/fstab echo /dev/hdv1 / ext2 rw 0 0 > /vservers/$server/etc/mtab echo "creating devices and dependencies" cd /vservers/$server/ tar zxvf $DEVICES chroot /vservers/$server/ sbin/ldconfig echo "creating /etc/vservers/$server.conf" cp $SKEL /etc/vservers/$server.conf echo "importing slack gpg pubkey" mkdir /vservers/$server/root/.gnupg gpg --homedir /vservers/$server/root/.gnupg --import $GPGKEY # todo: add rebootmgr echo "done; now edit /etc/vservers/$server.conf" echo "then, set iptables rules and start $server vserver" echo "dont forget to change root's password"