10 # pkgs parsing utilities
11 PATH=$(dirname $0):$PATH export PATH
15 DEFAULT_PLDISTRO=planetlab
16 DEFAULT_PERSONALITY=linux64
19 COMMAND_VBUILD="vbuild-init-lxc.sh"
20 COMMAND_MYPLC="vtest-init-lxc.sh"
22 lxc_version="lxc-0.8.0"
23 lxc_git_repo="git://lxc.git.sourceforge.net/gitroot/lxc/lxc"
25 function bridge_init () {
33 # Default Value for INTERFACE_LAN
34 INTERFACE_LAN=$(netstat -rn | grep '^0.0.0.0' | awk '{print $8;}')
37 echo "========== $COMMAND: entering start - beg"
42 echo "========== $COMMAND: entering start - end"
44 # disable netfilter calls for bridge interface (they cause panick on 2.6.35 anyway)
46 # another option would be to accept the all forward packages for
47 # bridged interface like: -A FORWARD -m physdev --physdev-is-bridged -j ACCEPT
48 sysctl net.bridge.bridge-nf-call-iptables=0
49 sysctl net.bridge.bridge-nf-call-ip6tables=0
50 sysctl net.bridge.bridge-nf-call-arptables=0
52 # take extra arg for ifname, if provided
53 [ -n "$1" ] && { INTERFACE_LAN=$1; shift ; }
55 #if we have already configured the same host_box no need to do it again
56 /sbin/ifconfig $INTERFACE_BRIDGE &> /dev/null && {
57 echo "Bridge interface $INTERFACE_BRIDGE already set up - $COMMAND start exiting"
60 /sbin/ifconfig $INTERFACE_LAN &>/dev/null || {
61 echo "Cannot use interface $INTERFACE_LAN - exiting"
66 #Getting host IP/masklen
67 address=$(/sbin/ip addr show $INTERFACE_LAN | grep -v inet6 | grep inet | head --lines=1 | awk '{print $2;}')
68 [ -z "$address" ] && { echo "ERROR: Could not determine IP address for $INTERFACE_LAN" ; exit 1 ; }
70 broadcast=$(/sbin/ip addr show $INTERFACE_LAN | grep -v inet6 | grep inet | head --lines=1 | awk '{print $4;}')
71 [ -z "$broadcast" ] && echo "WARNING: Could not determine broadcast address for $INTERFACE_LAN"
73 gateway=$(netstat -rn | grep '^0.0.0.0' | awk '{print $2;}')
74 [ -z "$gateway" ] && echo "WARNING: Could not determine gateway IP"
77 echo "Creating bridge INTERFACE_BRIDGE=$INTERFACE_BRIDGE"
78 brctl addbr $INTERFACE_BRIDGE
79 #brctl stp $INTERFACE_BRIDGE yes
80 brctl addif $INTERFACE_BRIDGE $INTERFACE_LAN
81 echo "Activating promiscuous mode INTERFACE_LAN=$INTERFACE_LAN"
82 /sbin/ifconfig $INTERFACE_LAN 0.0.0.0 promisc up
84 echo "Setting bridge address=$address broadcast=$broadcast"
86 #/sbin/ifconfig $INTERFACE_BRIDGE $address broadcast $broadcast up
87 dhclient $INTERFACE_BRIDGE
90 #Reconfigure the routing table
91 echo "Configuring gateway=$gateway"
92 route add default gw $gateway
94 echo "========== $COMMAND: exiting start - beg"
97 echo "========== $COMMAND: exiting start - end"
105 function failure () {
106 echo "$COMMAND : Bailing out"
110 function cidr_notation () {
114 for i in $(seq 1 4) ; do
115 part=$(echo $netmask | cut -d. -f $i)
117 "255") cidr=$((cidr + 8));;
118 "254") cidr=$((cidr + 7));;
119 "252") cidr=$((cidr + 6));;
120 "248") cidr=$((cidr + 5));;
121 "240") cidr=$((cidr + 4));;
122 "224") cidr=$((cidr + 3));;
123 "192") cidr=$((cidr + 2));;
124 "128") cidr=$((cidr + 1));;
125 "0") cidr=$((cidr + 0));;
132 function check_yum_installed () {
134 rpm -q $package >& /dev/null || yum -y install $package
137 function check_yumgroup_installed () {
139 yum grouplist "$group" | grep -q Installed || { yum -y groupinstall "$group" ; }
142 function prepare_host() {
144 #################### lxc-tools : rebuild as current fedora release has flaws
145 #install development tools
146 check_yumgroup_installed "Development Tools"
147 #install libcap-devel, libvirt
148 check_yum_installed libcap-devel
149 check_yum_installed libvirt
151 #retrieve and install lxc from sources
152 raw_version=$(lxc-version ||: )
153 lxc_installed_version=$(echo $raw_version | sed -e 's,.*: ,,')
154 if [ "$lxc_installed_version" != "$lxc_version" ] ; then
155 echo "Expecting version" '['$lxc_version']'
156 echo "Found version" '['$lxc_installed_version']'
157 echo "Installing lxc ..."
159 [ -d lxc ] || git clone "$lxc_git_repo"
162 git checkout $lxc_version
164 ./configure --prefix=/usr --exec-prefix=/usr
167 mkdir -p /usr/var/lib/
168 [ -d /usr/var/lib/lxc ] || ln -s /var/lib/lxc /usr/var/lib/lxc
172 # #create a placeholder (just a hack to make lxc works)
173 # [ -d "/usr/local/var/lib" ] || mkdir -p /usr/local/var/lib
175 #################### bride initialization
176 check_yum_installed bridge-utils
178 isInstalled=$(netstat -rn | grep '^0.0.0.0' | awk '{print $8;}')
179 if [ "$isInstalled" != "br0" ] ; then
189 function configure_fedora() {
191 # disable selinux in fedora
192 mkdir -p $rootfs_path/selinux
193 echo 0 > $rootfs_path/selinux/enforce
195 # configure the network
197 cat <<EOF > ${rootfs_path}/etc/sysconfig/network-scripts/ifcfg-$IFNAME
211 cat <<EOF > ${rootfs_path}/etc/sysconfig/network
217 # cat <<EOF > $rootfs_path/etc/hosts
218 #127.0.0.1 localhost $HOSTNAME
221 dev_path="${rootfs_path}/dev"
224 mknod -m 666 ${dev_path}/null c 1 3
225 mknod -m 666 ${dev_path}/zero c 1 5
226 mknod -m 666 ${dev_path}/random c 1 8
227 mknod -m 666 ${dev_path}/urandom c 1 9
228 mkdir -m 755 ${dev_path}/pts
229 mkdir -m 1777 ${dev_path}/shm
230 mknod -m 666 ${dev_path}/tty c 5 0
231 mknod -m 666 ${dev_path}/tty0 c 4 0
232 mknod -m 666 ${dev_path}/tty1 c 4 1
233 mknod -m 666 ${dev_path}/tty2 c 4 2
234 mknod -m 666 ${dev_path}/tty3 c 4 3
235 mknod -m 666 ${dev_path}/tty4 c 4 4
236 mknod -m 600 ${dev_path}/console c 5 1
237 mknod -m 666 ${dev_path}/full c 1 7
238 mknod -m 600 ${dev_path}/initctl p
239 mknod -m 666 ${dev_path}/ptmx c 5 2
241 #echo "setting root passwd to $root_password"
242 #echo "root:$root_password" | chroot $rootfs_path chpasswd
248 function configure_fedora_init() {
250 sed -i 's|.sbin.start_udev||' ${rootfs_path}/etc/rc.sysinit
251 sed -i 's|.sbin.start_udev||' ${rootfs_path}/etc/rc.d/rc.sysinit
252 chroot ${rootfs_path} chkconfig udev-post off
253 chroot ${rootfs_path} chkconfig network on
257 function configure_fedora_systemd() {
259 unlink ${rootfs_path}/etc/systemd/system/default.target
260 touch ${rootfs_path}/etc/fstab
261 chroot ${rootfs_path} ln -s /dev/null //etc/systemd/system/udev.service
262 chroot ${rootfs_path} ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
263 #dependency on a device unit fails it specially that we disabled udev
264 sed -i 's/After=dev-%i.device/After=/' ${rootfs_path}/lib/systemd/system/getty\@.service
265 chroot ${rootfs_path} chkconfig network on
268 function download_fedora() {
270 # check the mini fedora was not already downloaded
271 INSTALL_ROOT=$cache/partial
273 mkdir -p $INSTALL_ROOT
274 if [ $? -ne 0 ]; then
275 echo "Failed to create '$INSTALL_ROOT' directory"
279 # download a mini fedora into a cache
280 echo "Downloading fedora minimal ..."
281 YUM="yum --installroot $INSTALL_ROOT -y --nogpgcheck --releasever=$release"
282 PKG_LIST="yum initscripts passwd rsyslog vim-minimal dhclient chkconfig rootfiles policycoreutils openssh-server openssh-clients"
285 MIRROR_URL=http://mirror.onelab.eu/fedora/releases/$release/Everything/$arch/os
286 RELEASE_URL1="$MIRROR_URL/Packages/fedora-release-$release-1.noarch.rpm"
287 # with fedora18 the rpms are scattered by first name
288 RELEASE_URL2="$MIRROR_URL/Packages/f/fedora-release-$release-1.noarch.rpm"
289 RELEASE_TARGET=$INSTALL_ROOT/fedora-release-$release.noarch.rpm
291 for attempt in $RELEASE_URL1 $RELEASE_URL2; do
292 if curl -f $attempt -o $RELEASE_TARGET ; then
293 echo "Retrieved $attempt"
297 echo "Failed attempt $attempt"
299 [ -n "$found" ] || { echo "Could not retrieve fedora-release rpm - exiting" ; exit 1; }
301 mkdir -p $INSTALL_ROOT/var/lib/rpm
302 rpm --root $INSTALL_ROOT --initdb
303 rpm --root $INSTALL_ROOT -ivh $INSTALL_ROOT/fedora-release-$release.noarch.rpm
304 echo "$YUM install $PKG_LIST"
305 $YUM install $PKG_LIST
307 if [ $? -ne 0 ]; then
308 echo "Failed to download the rootfs, aborting."
312 mv "$INSTALL_ROOT" "$cache/rootfs"
313 echo "Download complete."
319 function copy_fedora() {
321 # make a local copy of the minifedora
322 echo -n "Copying rootfs to $rootfs_path ..."
323 mkdir -p $rootfs_path
324 rsync -a $cache/rootfs/ $rootfs_path/
329 function update_fedora() {
331 YUM="yum --installroot $cache/rootfs -y --nogpgcheck"
336 function install_fedora() {
339 mkdir -p /var/lock/subsys/
342 if [ $? -ne 0 ]; then
343 echo "Cache repository is busy."
347 echo "Checking cache download in $cache/rootfs ... "
348 if [ ! -e "$cache/rootfs" ]; then
350 if [ $? -ne 0 ]; then
351 echo "Failed to download 'fedora base'"
355 echo "Cache found. Updating..."
357 if [ $? -ne 0 ]; then
358 echo "Failed to update 'fedora base', continuing with last known good cache"
360 echo "Update finished"
364 echo "Copy $cache/rootfs to $rootfs_path ... "
366 if [ $? -ne 0 ]; then
367 echo "Failed to copy rootfs"
373 ) 200>/var/lock/subsys/lxc
379 function copy_configuration() {
381 mkdir -p $config_path
382 cat <<EOF >> $config_path/config
387 lxc.rootfs = $rootfs_path
388 lxc.mount = $config_path/fstab
390 lxc.network.type = $lxc_network_type
391 lxc.network.flags = up
392 lxc.network.link = $lxc_network_link
393 lxc.network.name = $IFNAME
394 lxc.network.mtu = 1500
395 lxc.network.ipv4 = $IP/$CIDR
396 lxc.network.veth.pair = $veth_pair
398 #lxc.cgroup.devices.deny = a
400 lxc.cgroup.devices.allow = c 1:3 rwm
401 lxc.cgroup.devices.allow = c 1:5 rwm
403 lxc.cgroup.devices.allow = c 5:1 rwm
404 lxc.cgroup.devices.allow = c 5:0 rwm
405 lxc.cgroup.devices.allow = c 4:0 rwm
406 lxc.cgroup.devices.allow = c 4:1 rwm
408 lxc.cgroup.devices.allow = c 1:9 rwm
409 lxc.cgroup.devices.allow = c 1:8 rwm
410 lxc.cgroup.devices.allow = c 136:* rwm
411 lxc.cgroup.devices.allow = c 5:2 rwm
413 lxc.cgroup.devices.allow = c 254:0 rwm
414 lxc.cgroup.devices.allow = b 255:0 rwm
419 cat <<EOF > $config_path/fstab
420 proc $rootfs_path/proc proc nodev,noexec,nosuid 0 0
421 devpts $rootfs_path/dev/pts devpts defaults 0 0
422 sysfs $rootfs_path/sys sysfs defaults 0 0
424 if [ $? -ne 0 ]; then
425 echo "Failed to add configuration"
435 # overwrite lxc's internal yum config
436 function configure_yum_in_lxc () {
445 echo "Initializing yum.repos.d in $lxc"
446 rm -f $rootfs_path/etc/yum.repos.d/*
448 cat > $rootfs_path/etc/yum.repos.d/building.repo <<EOF
450 name=Fedora $release - \$basearch
451 baseurl=http://mirror.onelab.eu/fedora/releases/$release/Everything/\$basearch/os/
455 gpgkey=http://mirror.onelab.eu/keys/RPM-GPG-KEY-fedora-$release-primary
458 name=Fedora $release - \$basearch - Updates
459 baseurl=http://mirror.onelab.eu/fedora/updates/$release/\$basearch/
463 gpgkey=http://mirror.onelab.eu/keys/RPM-GPG-KEY-fedora-$release-primary
466 # for using vtest-init-lxc.sh as a general-purpose lxc creation wrapper
467 # just mention 'none' as the repo url
468 if [ -n "$MYPLC_MODE" -a "$REPO_URL" != "none" ] ; then
469 if [ ! -d $rootfs_path/etc/yum.repos.d ] ; then
470 echo "WARNING : cannot create myplc repo"
472 # exclude kernel from fedora repos
473 yumexclude=$(pl_plcyumexclude $fcdistro $pldistro $DIRNAME)
474 for repo in $rootfs_path/etc/yum.repos.d/* ; do
475 [ -f $repo ] && yumconf_exclude $repo "exclude=$yumexclude"
477 # the build repo is not signed at this stage
478 cat > $rootfs_path/etc/yum.repos.d/myplc.repo <<EOF
489 # return yum or debootstrap
490 function package_method () {
493 f[0-9]*|centos[0-9]*|sl[0-9]*) echo yum ;;
494 lenny|etch) echo debootstrap ;;
495 *) echo Unknown distro $fcdistro ;;
499 # return arch from debian distro and personality
500 function canonical_arch () {
501 personality=$1; shift
503 case $(package_method $fcdistro) in
505 case $personality in *32) echo i386 ;; *64) echo x86_64 ;; *) echo Unknown-arch-1 ;; esac ;;
507 case $personality in *32) echo i386 ;; *64) echo amd64 ;; *) echo Unknown-arch-2 ;; esac ;;
509 echo Unknown-arch-3 ;;
513 # the new test framework creates /timestamp in /vservers/<name> *before* populating it
514 function almost_empty () {
516 # non existing is fine
517 [ ! -d $dir ] && return 0;
518 # need to have at most one file
519 count=$(cd $dir; ls | wc -l); [ $count -le 1 ];
522 function setup_lxc() {
526 #trap failure ERR INT
531 personality=$1; shift
533 # create lxc container
535 if [ $? -ne 0 ]; then
536 echo "failed write configuration file"
541 if [ $? -ne 0 ]; then
542 echo "failed to install fedora"
547 if [ $? -ne 0 ]; then
548 echo "failed to configure fedora for a container"
552 type /bin/systemd >/dev/null 2>&1
553 if [ $? -ne 0 ]; then
554 configure_fedora_init
556 configure_fedora_systemd
560 mkdir $rootfs_path/cgroup
563 cp /etc/resolv.conf $rootfs_path/etc/resolv.conf
564 # and /etc/hosts for at least localhost
565 [ -f $rootfs_path/etc/hosts ] || echo "127.0.0.1 localhost localhost.localdomain" > $rootfs_path/etc/hosts
568 mkdir $rootfs_path/root/.ssh
569 cat /root/.ssh/id_rsa.pub >> $rootfs_path/root/.ssh/authorized_keys
574 echo $IP is up, waiting for ssh...
576 # wait max 5 min for sshd to start
578 stop_time=$(($(date +%s) + 300))
579 current_time=$(date +%s)
581 while [ "$current_time" -lt "$stop_time" ] ; do
582 echo "ssh attempt ..."
583 ssh -o "StrictHostKeyChecking no" $IP 'uname -i' && { ssh_up=true; echo "SSHD in container $lxc is UP"; break ; } || :
585 current_time=$(($current_time + 10))
588 [ -z $ssh_up ] && echo "SSHD in container $lxc is not running"
592 chroot $rootfs_path rpm --rebuilddb
593 #ssh -o "StrictHostKeyChecking no" $IP "rpm --rebuilddb"
595 configure_yum_in_lxc $lxc $fcdistro $pldistro
600 function devel_or_vtest_tools () {
609 personality=$1; shift
611 pkg_method=$(package_method $fcdistro)
613 # check for .pkgs file based on pldistro
614 if [ -n "$VBUILD_MODE" ] ; then
619 pkgsfile=$(pl_locateDistroFile $DIRNAME $pldistro $pkgsname)
621 ### install individual packages, then groups
622 # get target arch - use uname -i here (we want either x86_64 or i386)
624 lxc_arch=$(chroot $rootfs_path uname -i)
625 # on debian systems we get arch through the 'arch' command
626 [ "$lxc_arch" = "unknown" ] && lxc_arch=$(chroot $rootfs_path arch)
628 packages=$(pl_getPackages -a $lxc_arch $fcdistro $pldistro $pkgsfile)
629 groups=$(pl_getGroups -a $lxc_arch $fcdistro $pldistro $pkgsfile)
631 case "$pkg_method" in
633 [ -n "$packages" ] && chroot $rootfs_path yum -y install $packages
634 for group_plus in $groups; do
635 group=$(echo $group_plus | sed -e "s,+++, ,g")
636 chroot $rootfs_path yum -y groupinstall "$group"
638 # store current rpm list in /init-lxc.rpms in case we need to check the contents
639 chroot $rootfs_path rpm -aq > $rootfs_path/init-lxc.rpms
642 chroot $rootfs_path apt-get update
643 for package in $packages ; do
644 chroot $rootfs_path apt-get install -y $package
646 ### xxx todo install groups with apt..
649 echo "unknown pkg_method $pkg_method"
656 function post_install () {
657 if [ -n "$VBUILD_MODE" ] ; then
658 post_install_vbuild "$@"
660 post_install_myplc "$@"
662 # setup localtime from the host
664 cp /etc/localtime $rootfs_path/etc/localtime
667 function post_install_vbuild () {
674 personality=$1; shift
676 ### From myplc-devel-native.spec
677 # be careful to backslash $ in this, otherwise it's the root context that's going to do the evaluation
678 cat << EOF | chroot $rootfs_path bash -x
679 # set up /dev/loop* in lxc
680 for i in \$(seq 0 255) ; do
681 mknod -m 640 /dev/loop\$i b 7 \$i
684 # create symlink for /dev/fd
685 [ ! -e "/dev/fd" ] && ln -s /proc/self/fd /dev/fd
687 # modify /etc/rpm/macros to not use /sbin/new-kernel-pkg
688 sed -i 's,/sbin/new-kernel-pkg:,,' /etc/rpm/macros
689 if [ -h "/sbin/new-kernel-pkg" ] ; then
690 filename=\$(readlink -f /sbin/new-kernel-pkg)
691 if [ "\$filename" == "/sbin/true" ] ; then
692 echo "WARNING: /sbin/new-kernel-pkg symlinked to /sbin/true"
693 echo "\tmost likely /etc/rpm/macros has /sbin/new-kernel-pkg declared in _netsharedpath."
694 echo "\tPlease remove /sbin/new-kernel-pkg from _netsharedpath and reintall mkinitrd."
699 # customize root's prompt
700 cat << PROFILE > /root/.profile
701 export PS1="[$lxc] \\w # "
707 # add a "build" user to the system
708 builduser=\$(grep "^build:" /etc/passwd | wc -l)
709 if [ \$builduser -eq 0 ] ; then
710 groupadd -o -g \$gid build;
711 useradd -o -c 'Automated Build' -u \$uid -g \$gid -n -M -s /bin/bash build;
714 # Allow build user to build certain RPMs as root
715 if [ -f /etc/sudoers ] ; then
716 buildsudo=\$(grep "^build.*ALL=(ALL).*NOPASSWD:.*ALL" /etc/sudoers | wc -l)
717 if [ \$buildsudo -eq 0 ] ; then
718 echo "build ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
720 sed -i 's,^Defaults.*requiretty,#Defaults requiretty,' /etc/sudoers
727 function post_install_myplc () {
733 personality=$1; shift
735 # be careful to backslash $ in this, otherwise it's the root context that's going to do the evaluation
736 cat << EOF | chroot $rootfs_path bash -x
738 # create /etc/sysconfig/network if missing
739 [ -f /etc/sysconfig/network ] || echo NETWORKING=yes > /etc/sysconfig/network
741 # create symlink for /dev/fd
742 [ ! -e "/dev/fd" ] && ln -s /proc/self/fd /dev/fd
744 # turn off regular crond, as plc invokes plc_crond
747 # take care of loginuid in /etc/pam.d
748 sed -i "s,#*\(.*loginuid.*\),#\1," /etc/pam.d/*
750 # customize root's prompt
751 cat << PROFILE > /root/.profile
752 export PS1="[$lxc] \\w # "
760 echo "Usage: $COMMAND_VBUILD [options] lxc-name"
761 echo "Usage: $COMMAND_MYPLC [options] lxc-name repo-url [ -- lxc-options ]"
763 echo " This command creates a fresh lxc instance, for building, or running, myplc"
764 echo "Supported options"
765 echo " -f fcdistro - for creating the root filesystem - defaults to $DEFAULT_FCDISTRO"
766 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
767 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
768 echo " -i ifname: determines ip and netmask attached to ifname, and passes it to the lxc"
769 echo "-- lxc-options"
770 echo " --netdev : interface to be defined inside lxc"
771 echo " --interface : IP to be defined for the lxc"
772 echo " --hostname : Hostname to be defined for the lxc"
773 echo "With $COMMAND_MYPLC you can give 'none' as the URL, in which case"
774 echo " myplc.repo does not get created"
782 #trap failure ERR INT
797 while getopts "f:d:p:i:" opt ; do
799 f) fcdistro=$OPTARG;;
800 d) pldistro=$OPTARG;;
801 p) personality=$OPTARG;;
807 shift $(($OPTIND - 1))
809 # parse fixed arguments
810 [[ -z "$@" ]] && usage
812 if [ -n "$MYPLC_MODE" ] ; then
813 [[ -z "$@" ]] && usage
817 # parse vserver options
818 if [[ -n "$@" ]] ; then
819 if [ "$1" == "--" ] ; then
827 eval set -- "$LXC_OPTIONS"
832 --netdev) IFNAME=$2; shift 2;;
833 --interface) IP=$2; shift 2;;
834 --hostname) HOSTNAME=$2; shift 2;;
840 if [ -n "$VBUILD_MODE" ] ; then
841 [ -z "$IFNAME" ] && IFNAME=$DEFAULT_IFNAME
842 [ -z "$HOSTNAME" ] && HOSTNAME=$lxc
845 [ -z "$fcdistro" ] && fcdistro=$DEFAULT_FCDISTRO
846 [ -z "$pldistro" ] && pldistro=$DEFAULT_PLDISTRO
847 [ -z "$personality" ] && personality=$DEFAULT_PERSONALITY
849 release=$(echo $fcdistro | cut -df -f2)
851 if [ "$personality" == "linux32" ]; then
854 elif [ "$personality" == "linux64" ]; then
858 echo "Unknown personality: $personality"
861 # need lxc installed before we can run lxc-ls
862 # need bridge installed
865 if [ -n "$VBUILD_MODE" ] ; then
867 # Bridge IP affectation
868 x=$(echo $personality | cut -dx -f2)
869 y=$(echo $fcdistro | cut -df -f2)
873 NETMASK="255.255.255.0"
874 GATEWAY="192.168.122.1"
876 lxc_network_type=veth
877 lxc_network_link=virbr0
879 echo "the IP address of container $lxc is $IP "
881 [[ -z "$REPO_URL" ]] && usage
882 [[ -z "$IP" ]] && usage
883 NETMASK=$(ifconfig br0 | grep 'inet addr' | awk '{print $4}' | sed -e 's/.*://')
884 GATEWAY=$(route -n | grep 'UG' | awk '{print $2}')
885 [[ -z "$HOSTNAME" ]] && usage
886 lxc_network_type=veth
888 veth_pair="i$(echo $HOSTNAME | cut -d. -f1)"
891 CIDR=$(cidr_notation $NETMASK)
894 if [ "$(id -u)" != "0" ]; then
895 echo "This script should be run as 'root'"
900 rootfs_path=$path/$lxc/rootfs
901 config_path=$path/$lxc
902 cache_base=/var/cache/lxc/fedora/$arch
903 cache=$cache_base/$release
906 # check whether the rootfs directory is created to know if the container exists
907 # bacause /var/lib/lxc/$lxc is already created while putting $lxc.timestamp
908 [ -d $rootfs_path ] && { echo "container $lxc already exists - exiting" ; exit 1 ; }
910 setup_lxc $lxc $fcdistro $pldistro $personality
912 devel_or_vtest_tools $lxc $fcdistro $pldistro $personality
914 post_install $lxc $personality