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" != "$(echo $lxc_version | cut -d'-' -f2)" ] ; 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 --disable-apparmor
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 if [[ "$fcdistro" == "f18" ]] ; then
212 cat <<EOF > ${rootfs_path}/etc/hostname
216 cat <<EOF > ${rootfs_path}/etc/sysconfig/network
223 # cat <<EOF > $rootfs_path/etc/hosts
224 #127.0.0.1 localhost $HOSTNAME
227 dev_path="${rootfs_path}/dev"
230 mknod -m 666 ${dev_path}/null c 1 3
231 mknod -m 666 ${dev_path}/zero c 1 5
232 mknod -m 666 ${dev_path}/random c 1 8
233 mknod -m 666 ${dev_path}/urandom c 1 9
234 mkdir -m 755 ${dev_path}/pts
235 mkdir -m 1777 ${dev_path}/shm
236 mknod -m 666 ${dev_path}/tty c 5 0
237 mknod -m 666 ${dev_path}/tty0 c 4 0
238 mknod -m 666 ${dev_path}/tty1 c 4 1
239 mknod -m 666 ${dev_path}/tty2 c 4 2
240 mknod -m 666 ${dev_path}/tty3 c 4 3
241 mknod -m 666 ${dev_path}/tty4 c 4 4
242 mknod -m 600 ${dev_path}/console c 5 1
243 mknod -m 666 ${dev_path}/full c 1 7
244 mknod -m 600 ${dev_path}/initctl p
245 mknod -m 666 ${dev_path}/ptmx c 5 2
247 #echo "setting root passwd to $root_password"
248 #echo "root:$root_password" | chroot $rootfs_path chpasswd
254 function configure_fedora_init() {
256 sed -i 's|.sbin.start_udev||' ${rootfs_path}/etc/rc.sysinit
257 sed -i 's|.sbin.start_udev||' ${rootfs_path}/etc/rc.d/rc.sysinit
258 chroot ${rootfs_path} chkconfig udev-post off
259 chroot ${rootfs_path} chkconfig network on
263 function configure_fedora_systemd() {
264 unlink ${rootfs_path}/etc/systemd/system/default.target
265 chroot ${rootfs_path} ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
266 touch ${rootfs_path}/etc/fstab
267 chroot ${rootfs_path} systemctl mask udev.service
269 # this was intended for f16 initially, in order to enable getty that otherwise would not start
270 # having a getty running is helpful only if ssh won't start though, and we see a correlation between
271 # VM's that refuse to lxc-stop and VM's that run crazy getty's
272 # so, turning getty off for now instead
273 # #dependency on a device unit fails it specially that we disabled udev
274 # sed -i 's/After=dev-%i.device/After=/' ${rootfs_path}/lib/systemd/system/getty\@.service
275 chroot ${rootfs_path} systemctl mask getty\@.service
276 chroot ${rootfs_path} chkconfig network on
279 function download_fedora() {
281 # check the mini fedora was not already downloaded
282 INSTALL_ROOT=$cache/partial
284 mkdir -p $INSTALL_ROOT
285 if [ $? -ne 0 ]; then
286 echo "Failed to create '$INSTALL_ROOT' directory"
290 # download a mini fedora into a cache
291 echo "Downloading fedora minimal ..."
292 YUM="yum --installroot $INSTALL_ROOT -y --nogpgcheck --releasever=$release"
293 PKG_LIST="yum initscripts passwd rsyslog vim-minimal dhclient chkconfig rootfiles policycoreutils openssh-server openssh-clients"
296 MIRROR_URL=http://mirror.onelab.eu/fedora/releases/$release/Everything/$arch/os
297 RELEASE_URL1="$MIRROR_URL/Packages/fedora-release-$release-1.noarch.rpm"
298 # with fedora18 the rpms are scattered by first name
299 RELEASE_URL2="$MIRROR_URL/Packages/f/fedora-release-$release-1.noarch.rpm"
300 RELEASE_TARGET=$INSTALL_ROOT/fedora-release-$release.noarch.rpm
302 for attempt in $RELEASE_URL1 $RELEASE_URL2; do
303 if curl -f $attempt -o $RELEASE_TARGET ; then
304 echo "Retrieved $attempt"
308 echo "Failed attempt $attempt"
311 [ -n "$found" ] || { echo "Could not retrieve fedora-release rpm - exiting" ; exit 1; }
313 mkdir -p $INSTALL_ROOT/var/lib/rpm
314 rpm --root $INSTALL_ROOT --initdb
315 rpm --root $INSTALL_ROOT -ivh $INSTALL_ROOT/fedora-release-$release.noarch.rpm
316 echo "$YUM install $PKG_LIST"
317 $YUM install $PKG_LIST
319 if [ $? -ne 0 ]; then
320 echo "Failed to download the rootfs, aborting."
324 mv "$INSTALL_ROOT" "$cache/rootfs"
325 echo "Download complete."
331 function copy_fedora() {
333 # make a local copy of the minifedora
334 echo -n "Copying rootfs to $rootfs_path ..."
335 mkdir -p $rootfs_path
336 rsync -a $cache/rootfs/ $rootfs_path/
341 function update_fedora() {
343 YUM="yum --installroot $cache/rootfs -y --nogpgcheck"
348 function install_fedora() {
351 mkdir -p /var/lock/subsys/
354 if [ $? -ne 0 ]; then
355 echo "Cache repository is busy."
359 echo "Checking cache download in $cache/rootfs ... "
360 if [ ! -e "$cache/rootfs" ]; then
362 if [ $? -ne 0 ]; then
363 echo "Failed to download 'fedora base'"
367 echo "Cache found. Updating..."
369 if [ $? -ne 0 ]; then
370 echo "Failed to update 'fedora base', continuing with last known good cache"
372 echo "Update finished"
376 echo "Copy $cache/rootfs to $rootfs_path ... "
378 if [ $? -ne 0 ]; then
379 echo "Failed to copy rootfs"
385 ) 200>/var/lock/subsys/lxc
391 function copy_configuration() {
393 mkdir -p $config_path
394 cat <<EOF >> $config_path/config
399 lxc.rootfs = $rootfs_path
400 lxc.mount = $config_path/fstab
402 lxc.network.type = $lxc_network_type
403 lxc.network.flags = up
404 lxc.network.link = $lxc_network_link
405 lxc.network.name = $IFNAME
406 lxc.network.mtu = 1500
407 lxc.network.ipv4 = $IP/$CIDR
408 lxc.network.veth.pair = $veth_pair
410 #lxc.cgroup.devices.deny = a
412 lxc.cgroup.devices.allow = c 1:3 rwm
413 lxc.cgroup.devices.allow = c 1:5 rwm
415 lxc.cgroup.devices.allow = c 5:1 rwm
416 lxc.cgroup.devices.allow = c 5:0 rwm
417 lxc.cgroup.devices.allow = c 4:0 rwm
418 lxc.cgroup.devices.allow = c 4:1 rwm
420 lxc.cgroup.devices.allow = c 1:9 rwm
421 lxc.cgroup.devices.allow = c 1:8 rwm
422 lxc.cgroup.devices.allow = c 136:* rwm
423 lxc.cgroup.devices.allow = c 5:2 rwm
425 lxc.cgroup.devices.allow = c 254:0 rwm
426 lxc.cgroup.devices.allow = b 255:0 rwm
431 cat <<EOF > $config_path/fstab
432 proc $rootfs_path/proc proc nodev,noexec,nosuid 0 0
433 devpts $rootfs_path/dev/pts devpts defaults 0 0
434 sysfs $rootfs_path/sys sysfs defaults 0 0
436 if [ $? -ne 0 ]; then
437 echo "Failed to add configuration"
447 # overwrite lxc's internal yum config
448 function configure_yum_in_lxc () {
457 echo "Initializing yum.repos.d in $lxc"
458 rm -f $rootfs_path/etc/yum.repos.d/*
460 cat > $rootfs_path/etc/yum.repos.d/building.repo <<EOF
462 name=Fedora $release - \$basearch
463 baseurl=http://mirror.onelab.eu/fedora/releases/$release/Everything/\$basearch/os/
467 gpgkey=http://mirror.onelab.eu/keys/RPM-GPG-KEY-fedora-$release-primary
470 name=Fedora $release - \$basearch - Updates
471 baseurl=http://mirror.onelab.eu/fedora/updates/$release/\$basearch/
475 gpgkey=http://mirror.onelab.eu/keys/RPM-GPG-KEY-fedora-$release-primary
478 # for using vtest-init-lxc.sh as a general-purpose lxc creation wrapper
479 # just mention 'none' as the repo url
480 if [ -n "$MYPLC_MODE" -a "$REPO_URL" != "none" ] ; then
481 if [ ! -d $rootfs_path/etc/yum.repos.d ] ; then
482 echo "WARNING : cannot create myplc repo"
484 # exclude kernel from fedora repos
485 yumexclude=$(pl_plcyumexclude $fcdistro $pldistro $DIRNAME)
486 for repo in $rootfs_path/etc/yum.repos.d/* ; do
487 [ -f $repo ] && yumconf_exclude $repo "exclude=$yumexclude"
489 # the build repo is not signed at this stage
490 cat > $rootfs_path/etc/yum.repos.d/myplc.repo <<EOF
501 # return yum or debootstrap
502 function package_method () {
505 f[0-9]*|centos[0-9]*|sl[0-9]*) echo yum ;;
506 lenny|etch) echo debootstrap ;;
507 *) echo Unknown distro $fcdistro ;;
511 # return arch from debian distro and personality
512 function canonical_arch () {
513 personality=$1; shift
515 case $(package_method $fcdistro) in
517 case $personality in *32) echo i386 ;; *64) echo x86_64 ;; *) echo Unknown-arch-1 ;; esac ;;
519 case $personality in *32) echo i386 ;; *64) echo amd64 ;; *) echo Unknown-arch-2 ;; esac ;;
521 echo Unknown-arch-3 ;;
525 # the new test framework creates /timestamp in /vservers/<name> *before* populating it
526 function almost_empty () {
528 # non existing is fine
529 [ ! -d $dir ] && return 0;
530 # need to have at most one file
531 count=$(cd $dir; ls | wc -l); [ $count -le 1 ];
534 function setup_lxc() {
538 #trap failure ERR INT
543 personality=$1; shift
545 # create lxc container
547 if [ $? -ne 0 ]; then
548 echo "failed write configuration file"
553 if [ $? -ne 0 ]; then
554 echo "failed to install fedora"
559 if [ $? -ne 0 ]; then
560 echo "failed to configure fedora for a container"
564 type /bin/systemd >/dev/null 2>&1
565 if [ $? -ne 0 ]; then
566 configure_fedora_init
568 configure_fedora_systemd
572 mkdir $rootfs_path/cgroup
575 cp /etc/resolv.conf $rootfs_path/etc/resolv.conf
576 # and /etc/hosts for at least localhost
577 [ -f $rootfs_path/etc/hosts ] || echo "127.0.0.1 localhost localhost.localdomain" > $rootfs_path/etc/hosts
580 mkdir $rootfs_path/root/.ssh
581 cat /root/.ssh/id_rsa.pub >> $rootfs_path/root/.ssh/authorized_keys
586 echo $IP is up, waiting for ssh...
588 # wait max 5 min for sshd to start
590 stop_time=$(($(date +%s) + 300))
591 current_time=$(date +%s)
593 while [ "$current_time" -lt "$stop_time" ] ; do
594 echo "ssh attempt ..."
595 ssh -o "StrictHostKeyChecking no" $IP 'uname -i' && { ssh_up=true; echo "SSHD in container $lxc is UP"; break ; } || :
597 current_time=$(($current_time + 10))
600 [ -z $ssh_up ] && echo "SSHD in container $lxc is not running"
603 chroot $rootfs_path rpm --rebuilddb
604 #ssh -o "StrictHostKeyChecking no" $IP "rpm --rebuilddb"
606 configure_yum_in_lxc $lxc $fcdistro $pldistro
611 function devel_or_vtest_tools () {
620 personality=$1; shift
622 pkg_method=$(package_method $fcdistro)
624 # check for .pkgs file based on pldistro
625 if [ -n "$VBUILD_MODE" ] ; then
630 pkgsfile=$(pl_locateDistroFile $DIRNAME $pldistro $pkgsname)
632 ### install individual packages, then groups
633 # get target arch - use uname -i here (we want either x86_64 or i386)
635 lxc_arch=$(chroot $rootfs_path uname -i)
636 # on debian systems we get arch through the 'arch' command
637 [ "$lxc_arch" = "unknown" ] && lxc_arch=$(chroot $rootfs_path arch)
639 packages=$(pl_getPackages -a $lxc_arch $fcdistro $pldistro $pkgsfile)
640 groups=$(pl_getGroups -a $lxc_arch $fcdistro $pldistro $pkgsfile)
642 case "$pkg_method" in
644 [ -n "$packages" ] && chroot $rootfs_path yum -y install $packages
645 for group_plus in $groups; do
646 group=$(echo $group_plus | sed -e "s,+++, ,g")
647 chroot $rootfs_path yum -y groupinstall "$group"
649 # store current rpm list in /init-lxc.rpms in case we need to check the contents
650 chroot $rootfs_path rpm -aq > $rootfs_path/init-lxc.rpms
653 chroot $rootfs_path apt-get update
654 for package in $packages ; do
655 chroot $rootfs_path apt-get install -y $package
657 ### xxx todo install groups with apt..
660 echo "unknown pkg_method $pkg_method"
667 function post_install () {
668 if [ -n "$VBUILD_MODE" ] ; then
669 post_install_vbuild "$@"
671 post_install_myplc "$@"
673 # setup localtime from the host
675 cp /etc/localtime $rootfs_path/etc/localtime
678 function post_install_vbuild () {
685 personality=$1; shift
687 ### From myplc-devel-native.spec
688 # be careful to backslash $ in this, otherwise it's the root context that's going to do the evaluation
689 cat << EOF | chroot $rootfs_path bash -x
690 # set up /dev/loop* in lxc
691 for i in \$(seq 0 255) ; do
692 mknod -m 640 /dev/loop\$i b 7 \$i
695 # create symlink for /dev/fd
696 [ ! -e "/dev/fd" ] && ln -s /proc/self/fd /dev/fd
698 # modify /etc/rpm/macros to not use /sbin/new-kernel-pkg
699 sed -i 's,/sbin/new-kernel-pkg:,,' /etc/rpm/macros
700 if [ -h "/sbin/new-kernel-pkg" ] ; then
701 filename=\$(readlink -f /sbin/new-kernel-pkg)
702 if [ "\$filename" == "/sbin/true" ] ; then
703 echo "WARNING: /sbin/new-kernel-pkg symlinked to /sbin/true"
704 echo "\tmost likely /etc/rpm/macros has /sbin/new-kernel-pkg declared in _netsharedpath."
705 echo "\tPlease remove /sbin/new-kernel-pkg from _netsharedpath and reintall mkinitrd."
710 # customize root's prompt
711 cat << PROFILE > /root/.profile
712 export PS1="[$lxc] \\w # "
718 # add a "build" user to the system
719 builduser=\$(grep "^build:" /etc/passwd | wc -l)
720 if [ \$builduser -eq 0 ] ; then
721 groupadd -o -g \$gid build;
722 useradd -o -c 'Automated Build' -u \$uid -g \$gid -n -M -s /bin/bash build;
725 # Allow build user to build certain RPMs as root
726 if [ -f /etc/sudoers ] ; then
727 buildsudo=\$(grep "^build.*ALL=(ALL).*NOPASSWD:.*ALL" /etc/sudoers | wc -l)
728 if [ \$buildsudo -eq 0 ] ; then
729 echo "build ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
731 sed -i 's,^Defaults.*requiretty,#Defaults requiretty,' /etc/sudoers
738 function post_install_myplc () {
744 personality=$1; shift
746 # be careful to backslash $ in this, otherwise it's the root context that's going to do the evaluation
747 cat << EOF | chroot $rootfs_path bash -x
749 # create /etc/sysconfig/network if missing
750 [ -f /etc/sysconfig/network ] || echo NETWORKING=yes > /etc/sysconfig/network
752 # create symlink for /dev/fd
753 [ ! -e "/dev/fd" ] && ln -s /proc/self/fd /dev/fd
755 # turn off regular crond, as plc invokes plc_crond
758 # take care of loginuid in /etc/pam.d
759 sed -i "s,#*\(.*loginuid.*\),#\1," /etc/pam.d/*
761 # customize root's prompt
762 cat << PROFILE > /root/.profile
763 export PS1="[$lxc] \\w # "
771 echo "Usage: $COMMAND_VBUILD [options] lxc-name"
772 echo "Usage: $COMMAND_MYPLC [options] lxc-name repo-url [ -- lxc-options ]"
774 echo " This command creates a fresh lxc instance, for building, or running, myplc"
775 echo "Supported options"
776 echo " -f fcdistro - for creating the root filesystem - defaults to $DEFAULT_FCDISTRO"
777 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
778 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
779 echo " -i ifname: determines ip and netmask attached to ifname, and passes it to the lxc"
780 echo "-- lxc-options"
781 echo " --netdev : interface to be defined inside lxc"
782 echo " --interface : IP to be defined for the lxc"
783 echo " --hostname : Hostname to be defined for the lxc"
784 echo "With $COMMAND_MYPLC you can give 'none' as the URL, in which case"
785 echo " myplc.repo does not get created"
793 #trap failure ERR INT
808 while getopts "f:d:p:i:" opt ; do
810 f) fcdistro=$OPTARG;;
811 d) pldistro=$OPTARG;;
812 p) personality=$OPTARG;;
818 shift $(($OPTIND - 1))
820 # parse fixed arguments
821 [[ -z "$@" ]] && usage
823 if [ -n "$MYPLC_MODE" ] ; then
824 [[ -z "$@" ]] && usage
828 # parse vserver options
829 if [[ -n "$@" ]] ; then
830 if [ "$1" == "--" ] ; then
838 eval set -- "$LXC_OPTIONS"
843 --netdev) IFNAME=$2; shift 2;;
844 --interface) IP=$2; shift 2;;
845 --hostname) HOSTNAME=$2; shift 2;;
851 if [ -n "$VBUILD_MODE" ] ; then
852 [ -z "$IFNAME" ] && IFNAME=$DEFAULT_IFNAME
853 [ -z "$HOSTNAME" ] && HOSTNAME=$lxc
856 [ -z "$fcdistro" ] && fcdistro=$DEFAULT_FCDISTRO
857 [ -z "$pldistro" ] && pldistro=$DEFAULT_PLDISTRO
858 [ -z "$personality" ] && personality=$DEFAULT_PERSONALITY
860 release=$(echo $fcdistro | cut -df -f2)
862 if [ "$personality" == "linux32" ]; then
865 elif [ "$personality" == "linux64" ]; then
869 echo "Unknown personality: $personality"
872 # need lxc installed before we can run lxc-ls
873 # need bridge installed
876 if [ -n "$VBUILD_MODE" ] ; then
878 # Bridge IP affectation
879 x=$(echo $personality | cut -dx -f2)
880 y=$(echo $fcdistro | cut -df -f2)
884 NETMASK="255.255.255.0"
885 GATEWAY="192.168.122.1"
887 lxc_network_type=veth
888 lxc_network_link=virbr0
890 echo "the IP address of container $lxc is $IP "
892 [[ -z "$REPO_URL" ]] && usage
893 [[ -z "$IP" ]] && usage
895 NETMASK=$(ifconfig br0 | grep 'inet ' | awk '{print $4}' | sed -e 's/.*://')
896 GATEWAY=$(route -n | grep 'UG' | awk '{print $2}')
897 [[ -z "$HOSTNAME" ]] && usage
898 lxc_network_type=veth
900 veth_pair="i$(echo $HOSTNAME | cut -d. -f1)"
903 CIDR=$(cidr_notation $NETMASK)
906 if [ "$(id -u)" != "0" ]; then
907 echo "This script should be run as 'root'"
912 rootfs_path=$path/$lxc/rootfs
913 config_path=$path/$lxc
914 cache_base=/var/cache/lxc/fedora/$arch
915 cache=$cache_base/$release
918 # check whether the rootfs directory is created to know if the container exists
919 # bacause /var/lib/lxc/$lxc is already created while putting $lxc.timestamp
920 [ -d $rootfs_path ] && { echo "container $lxc already exists - exiting" ; exit 1 ; }
922 setup_lxc $lxc $fcdistro $pldistro $personality
924 devel_or_vtest_tools $lxc $fcdistro $pldistro $personality
926 post_install $lxc $personality