pkg_method=$(package_method $fcdistro)
case $pkg_method in
yum)
- fedora_install || { echo "failed to install fedora root image"; exit 1 ; }
+ if [ -z "$IMAGE" ]; then
+ fedora_install || { echo "failed to install fedora root image"; exit 1 ; }
+ fi
fedora_configure || { echo "failed to configure fedora for a container"; exit 1 ; }
;;
debootstrap)
- debian_install $lxc || { echo "failed to install debian/ubuntu root image"; exit 1 ; }
+ if [ -z "$IMAGE" ]; then
+ debian_install $lxc || { echo "failed to install debian/ubuntu root image"; exit 1 ; }
+ fi
debian_configure || { echo "failed to configure debian/ubuntu for a container"; exit 1 ; }
;;
*)
[ -f $lxc_root/etc/hosts ] || echo "127.0.0.1 localhost localhost.localdomain" > $lxc_root/etc/hosts
# grant ssh access from host to guest
- mkdir $lxc_root/root/.ssh
+ mkdir -p $lxc_root/root/.ssh
cat /root/.ssh/id_rsa.pub >> $lxc_root/root/.ssh/authorized_keys
chmod 700 $lxc_root/root/.ssh
chmod 600 $lxc_root/root/.ssh/authorized_keys
( cd /vservers/$lxc/etc/apt ; head -1 sources.list | sed -e s,main,universe, > sources.list.d/universe.list )
# also adding a link to updates sounds about right
( cd /vservers/$lxc/etc/apt ; head -1 sources.list | sed -e 's, main,-updates main,' > sources.list.d/updates.list )
+ # tell apt about the changes
+ chroot /vservers/$lxc apt-get update
fi
for package in $packages ; do
# container not started yet
echo " -r repo-url - used to populate yum.repos.d - required in test mode"
echo " -P pkgs_file - defines a set of extra packages to install in guest"
echo " by default we use devel.pkgs (build mode) or runtime.pkgs (test mode)"
+ echo " -i image - the location of the rootfs"
echo " -v be verbose"
exit 1
}
exit 1
fi
- while getopts "n:f:d:p:r:P:v" opt ; do
+ while getopts "n:f:d:p:r:P:i:v" opt ; do
case $opt in
n) GUEST_HOSTNAME=$OPTARG;;
f) fcdistro=$OPTARG;;
p) personality=$OPTARG;;
r) REPO_URL=$OPTARG;;
P) PREINSTALLED=$OPTARG;;
+ i) IMAGE=$OPTARG;;
v) VERBOSE=true; set -x;;
*) usage ;;
esac
[[ -z "$@" ]] && usage
lxc=$1 ; shift
lxc_root=/vservers/$lxc
+
# rainchecks
almost_empty $lxc_root || \
{ echo "container $lxc already exists in $lxc_root - exiting" ; exit 1 ; }
{ echo "container $lxc already exists in libvirt - exiting" ; exit 1 ; }
mkdir -p $lxc_root
+ # if IMAGE, copy the provided rootfs to lxc_root
+ if [ -n "$IMAGE" ] ; then
+ [ ! -d "$IMAGE" ] && \
+ { echo "$IMAGE rootfs folder does not exist - exiting" ; exit 1 ; }
+ cp -r $IMAGE/* $lxc_root/
+ fi
+
+
# check we've exhausted the arguments
[[ -n "$@" ]] && usage
post_install $lxc $personality
echo $COMMAND Done
+
+ exit 0
}
main "$@"