From: Stefano Stabellini Date: Wed, 25 Mar 2015 21:58:55 +0000 (+0000) Subject: move xen.sh grub.sh libvirt.sh under components X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=d13c48b614d0a8fa9ed7aafa81da34c368f11b7a;p=raisin.git move xen.sh grub.sh libvirt.sh under components Signed-off-by: Stefano Stabellini --- diff --git a/components/grub.sh b/components/grub.sh new file mode 100644 index 0000000..14ffca3 --- /dev/null +++ b/components/grub.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash + +source "$BASEDIR"/config +source "$BASEDIR"/common-functions.sh + + +function grub_install_dependencies() { + local DEP_Debian_common="build-essential tar autoconf bison flex" + local DEP_Debian_x86_32="$DEP_Debian_common" + local DEP_Debian_x86_64="$DEP_Debian_common libc6-dev-i386" + local DEP_Debian_arm32="$DEP_Debian_common" + local DEP_Debian_arm64="$DEP_Debian_common" + + local DEP_Fedora_common="make gcc tar automake autoconf sysconftool bison flex \ + glibc-devel" + local DEP_Fedora_x86_32="$DEP_Fedora_common" + local DEP_Fedora_x86_64="$DEP_Fedora_common glibc-devel.i686" + + + if test $ARCH != "x86_64" && test $ARCH != "x86_32" + then + echo grub is only supported on x86_32 and x86_64 + return + fi + echo installing Grub dependencies + eval install_dependencies \$DEP_"$DISTRO"_"$ARCH" +} + + +function grub_build() { + grub_install_dependencies + + cd "$BASEDIR" + rm -f memdisk.tar + tar cf memdisk.tar grub.cfg + ./git-checkout.sh $GRUB_UPSTREAM_URL $GRUB_UPSTREAM_REVISION grub-dir + cd grub-dir + ./autogen.sh + ## GRUB32 + ./configure --target=i386 --with-platform=xen + $MAKE CPPFLAGS="-I$INST_DIR/$PREFIX/include" + ./grub-mkimage -d grub-core -O i386-xen -c ../grub-bootstrap.cfg \ + -m ../memdisk.tar -o grub-i386-xen grub-core/*mod + cp grub-i386-xen "$INST_DIR"/$PREFIX/lib/xen/boot + ## GRUB64 + if test $ARCH = "x86_64" + then + $MAKE clean + ./configure --target=amd64 --with-platform=xen + $MAKE CPPFLAGS="-I$INST_DIR/$PREFIX/include" + ./grub-mkimage -d grub-core -O x86_64-xen -c ../grub-bootstrap.cfg \ + -m ../memdisk.tar -o grub-x86_64-xen grub-core/*mod + cp grub-x86_64-xen "$INST_DIR"/$PREFIX/lib/xen/boot + fi + cd "$BASEDIR" +} + +function grub_clean() { + cd "$BASEDIR" + rm -rf memdisk.tar + if test -d grub-dir + then + cd grub-dir + $MAKE distclean + cd .. + rm -rf grub-dir + fi +} + +function grub_configure() { + echo "Grub: nothing to configure" +} + +function grub_unconfigure() { + echo "Grub: nothing to unconfigure" +} diff --git a/components/libvirt.sh b/components/libvirt.sh new file mode 100644 index 0000000..d198bb3 --- /dev/null +++ b/components/libvirt.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +source "$BASEDIR"/config +source "$BASEDIR"/common-functions.sh + + +function libvirt_install_dependencies() { + local DEP_Debian_common="build-essential libtool autoconf autopoint \ + xsltproc libxml2-utils pkg-config python-dev \ + libxml-xpath-perl libyajl-dev libxml2-dev \ + gettext libdevmapper-dev libnl-3-dev \ + libnl-route-3-dev" + local DEP_Debian_x86_32="$DEP_Debian_common" + local DEP_Debian_x86_64="$DEP_Debian_common" + local DEP_Debian_arm32="$DEP_Debian_common" + local DEP_Debian_arm64="$DEP_Debian_common" + + local DEP_Fedora_common="patch make gcc libtool autoconf gettext-devel \ + python-devel libxslt yajl-devel libxml2-devel \ + device-mapper-devel libpciaccess-devel \ + libuuid-devel perl-XML-XPath" + local DEP_Fedora_x86_32="$DEP_Fedora_common" + local DEP_Fedora_x86_64="$DEP_Fedora_common" + + echo installing Libvirt dependencies + eval install_dependencies \$DEP_"$DISTRO"_"$ARCH" +} + +function libvirt_build() { + libvirt_install_dependencies + + cd "$BASEDIR" + ./git-checkout.sh $LIBVIRT_UPSTREAM_URL $LIBVIRT_UPSTREAM_REVISION libvirt-dir + cd libvirt-dir + CFLAGS="-I$INST_DIR/$PREFIX/include" \ + LDFLAGS="-L$INST_DIR/$PREFIX/lib -Wl,-rpath-link=$INST_DIR/$PREFIX/lib" \ + ./autogen.sh --with-xen --without-qemu --without-uml --without-openvz \ + --without-vmware --without-phyp --without-xenapi --with-libxl \ + --without-vbox --without-lxc --without-esx --without-hyperv \ + --without-parallels --without-test --with-libvirtd --without-sasl \ + --with-yajl --without-macvtap --without-avahi --prefix=$PREFIX + $MAKE + $MAKE --ignore-errors install DESTDIR="$INST_DIR" || true + if test $DISTRO = "Debian" + then + mkdir -p "$INST_DIR"/etc/init.d + cat ../libvirt.debian.init | sed -e "s,@PREFIX,$PREFIX,g" > "$INST_DIR"/etc/init.d/libvirtd + chmod +x "$INST_DIR"/etc/init.d/libvirtd + elif test $DISTRO = "Fedora" || test $DISTRO = "CentOS" + then + $MAKE -C daemon libvirtd.init + mkdir -p "$INST_DIR"/etc/rc.d/init.d + cp daemon/libvirtd.init "$INST_DIR"/etc/rc.d/init.d/libvirtd + chmod +x "$INST_DIR"/etc/rc.d/init.d/libvirtd + else + echo "I don't know how write an init script for Libvirt on $DISTRO" + fi + cd .. +} + +function libvirt_clean() { + cd "$BASEDIR" + if test -d libvirt-dir + then + cd libvirt-dir + $MAKE distclean + cd .. + rm -rf libvirt-dir + fi +} + +function libvirt_configure() { + start_initscripts libvirtd libvirt-guests virtlockd +} + +function libvirt_unconfigure() { + stop_initscripts libvirtd libvirt-guests virtlockd +} diff --git a/components/xen.sh b/components/xen.sh new file mode 100644 index 0000000..14655b7 --- /dev/null +++ b/components/xen.sh @@ -0,0 +1,133 @@ +#!/usr/bin/env bash + +source "$BASEDIR"/config +source "$BASEDIR"/common-functions.sh + + +function xen_install_dependencies() { + local DEP_Debian_common="build-essential python-dev gettext uuid-dev \ + libncurses5-dev libyajl-dev libaio-dev pkg-config libglib2.0-dev \ + libssl-dev libpixman-1-dev bridge-utils" + local DEP_Debian_x86_32="$DEP_Debian_common bcc iasl bin86 texinfo" + local DEP_Debian_x86_64="$DEP_Debian_x86_32 libc6-dev-i386" + local DEP_Debian_arm32="$DEP_Debian_common libfdt-dev" + local DEP_Debian_arm64="$DEP_Debian_arm32" + + local DEP_Fedora_common="make gcc python-devel gettext libuuid-devel \ + ncurses-devel glib2-devel libaio-devel openssl-devel yajl-devel \ + patch pixman-devel glibc-devel bridge-utils grub2" + local DEP_Fedora_x86_32="$DEP_Fedora_common dev86 iasl texinfo" + local DEP_Fedora_x86_64="$DEP_Fedora_x86_32 glibc-devel.i686" + + echo installing Xen dependencies + eval install_dependencies \$DEP_"$DISTRO"_"$ARCH" +} + +function xen_build() { + xen_install_dependencies + + cd "$BASEDIR" + ./git-checkout.sh $XEN_UPSTREAM_URL $XEN_UPSTREAM_REVISION xen-dir + cd xen-dir + ./configure --prefix=$PREFIX + $MAKE + $MAKE install DESTDIR="$INST_DIR" + chmod +x "$INST_DIR"/etc/init.d/xencommons + chmod +x "$INST_DIR"/etc/init.d/xendomains + chmod +x "$INST_DIR"/etc/init.d/xen-watchdog + cd "$BASEDIR" +} + +function xen_clean() { + cd "$BASEDIR" + if test -d xen-dir + then + cd xen-dir + $MAKE distclean + cd "$BASEDIR" + rm -rf xen-dir + fi +} + +function xen_create_bridge_Debian() { + BRIDGE="xenbr0" + IFACE=`grep "dhcp" /etc/network/interfaces | head -1 | awk '{print$2}'` + + if test -z "$IFACE" + then + echo "Please refer to the following page to setup networking:" + echo "http://wiki.xenproject.org/wiki/Network_Configuration_Examples_(Xen_4.1%2B)" + return 1 + fi + if test "`grep $BRIDGE /etc/network/interfaces`" + then + echo "a network bridge seems to be already setup" + return 0 + fi + + TMPFILE=`mktemp` + cat /etc/network/interfaces | \ + sed -e "s/iface $IFACE inet dhcp/iface $IFACE inet manual/" \ + -e "/auto/s/\<$IFACE\>/$BRIDGE/g" \ + -e "/allow-hotplug/s/\<$IFACE\>/$BRIDGE/g" > $TMPFILE + echo "" >> $TMPFILE + echo "iface $BRIDGE inet dhcp" >> $TMPFILE + echo " bridge_ports $IFACE" >> $TMPFILE + $SUDO mv -f $TMPFILE /etc/network/interfaces +} + +function xen_create_bridge_Fedora() { + BRIDGE="xenbr0" + + if test "`grep $BRIDGE /etc/sysconfig/network-scripts/*`" + then + return 0 + fi + + IFACE=`grep 'BOOTPROTO="dhcp"' /etc/sysconfig/network-scripts/* | head -1 | cut -d : -f 1` + if test -z "$IFACE" + then + return 1 + fi + + $SUDO chkconfig NetworkManager off + $SUDO chkconfig network on + $SUDO service NetworkManager stop + + TMPFILE=`mktemp` + cat $IFACE | grep -v dhcp | grep -v DHCLIENT > $TMPFILE + echo "BRIDGE=$BRIDGE" >> $TMPFILE + $SUDO mv -f $TMPFILE $IFACE + + cat ifcfg-xenbr0 | sed -e "s/@BRIDGE/$BRIDGE/g" > $TMPFILE + $SUDO mv -f $TMPFILE /etc/sysconfig/network-scripts + + $SUDO iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT + $SUDO service iptables save + $SUDO service iptables restart + + $SUDO service network start +} + +function xen_update_bootloader_Debian() { + $SUDO update-grub +} + +function xen_update_bootloader_Fedora() { + $SUDO grub2-mkconfig -o /boot/grub2/grub.cfg +} + +function xen_configure() { + xen_create_bridge_$DISTRO + start_initscripts xencommons xendomains xen-watchdog + xen_update_bootloader_$DISTRO +} + +function xen_unconfigure() { + # leave the bridge in place + stop_initscripts xencommons xendomains xen-watchdog + if test "`grep -rIi xen /boot/grub* | head -1`" + then + xen_update_bootloader_$DISTRO + fi +} diff --git a/grub.sh b/grub.sh deleted file mode 100644 index 0a5884a..0000000 --- a/grub.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env bash - -source config -source common-functions.sh - - -function grub_install_dependencies() { - local DEP_Debian_common="build-essential tar autoconf bison flex" - local DEP_Debian_x86_32="$DEP_Debian_common" - local DEP_Debian_x86_64="$DEP_Debian_common libc6-dev-i386" - local DEP_Debian_arm32="$DEP_Debian_common" - local DEP_Debian_arm64="$DEP_Debian_common" - - local DEP_Fedora_common="make gcc tar automake autoconf sysconftool bison flex \ - glibc-devel" - local DEP_Fedora_x86_32="$DEP_Fedora_common" - local DEP_Fedora_x86_64="$DEP_Fedora_common glibc-devel.i686" - - - if test $ARCH != "x86_64" && test $ARCH != "x86_32" - then - echo grub is only supported on x86_32 and x86_64 - return - fi - echo installing Grub dependencies - eval install_dependencies \$DEP_"$DISTRO"_"$ARCH" -} - - -function grub_build() { - grub_install_dependencies - - rm -f memdisk.tar - tar cf memdisk.tar grub.cfg - ./git-checkout.sh $GRUB_UPSTREAM_URL $GRUB_UPSTREAM_REVISION grub-dir - cd grub-dir - ./autogen.sh - ## GRUB32 - ./configure --target=i386 --with-platform=xen - $MAKE CPPFLAGS="-I$INST_DIR/$PREFIX/include" - ./grub-mkimage -d grub-core -O i386-xen -c ../grub-bootstrap.cfg \ - -m ../memdisk.tar -o grub-i386-xen grub-core/*mod - cp grub-i386-xen "$INST_DIR"/$PREFIX/lib/xen/boot - ## GRUB64 - if test $ARCH = "x86_64" - then - $MAKE clean - ./configure --target=amd64 --with-platform=xen - $MAKE CPPFLAGS="-I$INST_DIR/$PREFIX/include" - ./grub-mkimage -d grub-core -O x86_64-xen -c ../grub-bootstrap.cfg \ - -m ../memdisk.tar -o grub-x86_64-xen grub-core/*mod - cp grub-x86_64-xen "$INST_DIR"/$PREFIX/lib/xen/boot - fi - cd .. -} - -function grub_clean() { - rm -rf memdisk.tar - if test -d grub-dir - then - cd grub-dir - $MAKE distclean - cd .. - rm -rf grub-dir - fi -} - -function grub_configure() { - echo "Grub: nothing to configure" -} - -function grub_unconfigure() { - echo "Grub: nothing to unconfigure" -} diff --git a/libvirt.sh b/libvirt.sh deleted file mode 100644 index b12a0ef..0000000 --- a/libvirt.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env bash - -source config -source common-functions.sh - - -function libvirt_install_dependencies() { - local DEP_Debian_common="build-essential libtool autoconf autopoint \ - xsltproc libxml2-utils pkg-config python-dev \ - libxml-xpath-perl libyajl-dev libxml2-dev \ - gettext libdevmapper-dev libnl-3-dev \ - libnl-route-3-dev" - local DEP_Debian_x86_32="$DEP_Debian_common" - local DEP_Debian_x86_64="$DEP_Debian_common" - local DEP_Debian_arm32="$DEP_Debian_common" - local DEP_Debian_arm64="$DEP_Debian_common" - - local DEP_Fedora_common="patch make gcc libtool autoconf gettext-devel \ - python-devel libxslt yajl-devel libxml2-devel \ - device-mapper-devel libpciaccess-devel \ - libuuid-devel perl-XML-XPath" - local DEP_Fedora_x86_32="$DEP_Fedora_common" - local DEP_Fedora_x86_64="$DEP_Fedora_common" - - echo installing Libvirt dependencies - eval install_dependencies \$DEP_"$DISTRO"_"$ARCH" -} - -function libvirt_build() { - libvirt_install_dependencies - - ./git-checkout.sh $LIBVIRT_UPSTREAM_URL $LIBVIRT_UPSTREAM_REVISION libvirt-dir - cd libvirt-dir - CFLAGS="-I$INST_DIR/$PREFIX/include" \ - LDFLAGS="-L$INST_DIR/$PREFIX/lib -Wl,-rpath-link=$INST_DIR/$PREFIX/lib" \ - ./autogen.sh --with-xen --without-qemu --without-uml --without-openvz \ - --without-vmware --without-phyp --without-xenapi --with-libxl \ - --without-vbox --without-lxc --without-esx --without-hyperv \ - --without-parallels --without-test --with-libvirtd --without-sasl \ - --with-yajl --without-macvtap --without-avahi --prefix=$PREFIX - $MAKE - $MAKE --ignore-errors install DESTDIR="$INST_DIR" || true - if test $DISTRO = "Debian" - then - mkdir -p "$INST_DIR"/etc/init.d - cat ../libvirt.debian.init | sed -e "s,@PREFIX,$PREFIX,g" > "$INST_DIR"/etc/init.d/libvirtd - chmod +x "$INST_DIR"/etc/init.d/libvirtd - elif test $DISTRO = "Fedora" || test $DISTRO = "CentOS" - then - $MAKE -C daemon libvirtd.init - mkdir -p "$INST_DIR"/etc/rc.d/init.d - cp daemon/libvirtd.init "$INST_DIR"/etc/rc.d/init.d/libvirtd - chmod +x "$INST_DIR"/etc/rc.d/init.d/libvirtd - else - echo "I don't know how write an init script for Libvirt on $DISTRO" - fi - cd .. -} - -function libvirt_clean() { - if test -d libvirt-dir - then - cd libvirt-dir - $MAKE distclean - cd .. - rm -rf libvirt-dir - fi -} - -function libvirt_configure() { - start_initscripts libvirtd libvirt-guests virtlockd -} - -function libvirt_unconfigure() { - stop_initscripts libvirtd libvirt-guests virtlockd -} diff --git a/raise.sh b/raise.sh index 4c50ceb..28e178e 100755 --- a/raise.sh +++ b/raise.sh @@ -5,7 +5,7 @@ set -e source config source common-functions.sh -export PWD=`pwd` +export BASEDIR=`pwd` export GIT=${GIT-git} export SUDO=${SUDO-sudo} export MAKE=${MAKE-make} @@ -15,9 +15,9 @@ export INST_DIR=${DESTDIR-dist} INST_DIR=`readlink -f $INST_DIR` mkdir -p "$INST_DIR" &>/dev/null -source xen.sh -source grub.sh -source libvirt.sh +source components/xen.sh +source components/grub.sh +source components/libvirt.sh help() { echo "Usage: ./build.sh " @@ -68,7 +68,7 @@ get_arch install_dependencies git -# build and install under $DESTDIR ($PWD/dist by default) +# build and install under $DESTDIR ($BASEDIR/dist by default) if test "$XEN_UPSTREAM_REVISION" then xen_clean diff --git a/xen.sh b/xen.sh deleted file mode 100644 index d827b2e..0000000 --- a/xen.sh +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env bash - -source config -source common-functions.sh - - -function xen_install_dependencies() { - local DEP_Debian_common="build-essential python-dev gettext uuid-dev \ - libncurses5-dev libyajl-dev libaio-dev pkg-config libglib2.0-dev \ - libssl-dev libpixman-1-dev bridge-utils" - local DEP_Debian_x86_32="$DEP_Debian_common bcc iasl bin86 texinfo" - local DEP_Debian_x86_64="$DEP_Debian_x86_32 libc6-dev-i386" - local DEP_Debian_arm32="$DEP_Debian_common libfdt-dev" - local DEP_Debian_arm64="$DEP_Debian_arm32" - - local DEP_Fedora_common="make gcc python-devel gettext libuuid-devel \ - ncurses-devel glib2-devel libaio-devel openssl-devel yajl-devel \ - patch pixman-devel glibc-devel bridge-utils grub2" - local DEP_Fedora_x86_32="$DEP_Fedora_common dev86 iasl texinfo" - local DEP_Fedora_x86_64="$DEP_Fedora_x86_32 glibc-devel.i686" - - echo installing Xen dependencies - eval install_dependencies \$DEP_"$DISTRO"_"$ARCH" -} - -function xen_build() { - xen_install_dependencies - - ./git-checkout.sh $XEN_UPSTREAM_URL $XEN_UPSTREAM_REVISION xen-dir - cd xen-dir - ./configure --prefix=$PREFIX - $MAKE - $MAKE install DESTDIR="$INST_DIR" - chmod +x "$INST_DIR"/etc/init.d/xencommons - chmod +x "$INST_DIR"/etc/init.d/xendomains - chmod +x "$INST_DIR"/etc/init.d/xen-watchdog - cd .. -} - -function xen_clean() { - if test -d xen-dir - then - cd xen-dir - $MAKE distclean - cd .. - rm -rf xen-dir - fi -} - -function xen_create_bridge_Debian() { - BRIDGE="xenbr0" - IFACE=`grep "dhcp" /etc/network/interfaces | head -1 | awk '{print$2}'` - - if test -z "$IFACE" - then - echo "Please refer to the following page to setup networking:" - echo "http://wiki.xenproject.org/wiki/Network_Configuration_Examples_(Xen_4.1%2B)" - return 1 - fi - if test "`grep $BRIDGE /etc/network/interfaces`" - then - echo "a network bridge seems to be already setup" - return 0 - fi - - TMPFILE=`mktemp` - cat /etc/network/interfaces | \ - sed -e "s/iface $IFACE inet dhcp/iface $IFACE inet manual/" \ - -e "/auto/s/\<$IFACE\>/$BRIDGE/g" \ - -e "/allow-hotplug/s/\<$IFACE\>/$BRIDGE/g" > $TMPFILE - echo "" >> $TMPFILE - echo "iface $BRIDGE inet dhcp" >> $TMPFILE - echo " bridge_ports $IFACE" >> $TMPFILE - $SUDO mv -f $TMPFILE /etc/network/interfaces -} - -function xen_create_bridge_Fedora() { - BRIDGE="xenbr0" - - if test "`grep $BRIDGE /etc/sysconfig/network-scripts/*`" - then - return 0 - fi - - IFACE=`grep 'BOOTPROTO="dhcp"' /etc/sysconfig/network-scripts/* | head -1 | cut -d : -f 1` - if test -z "$IFACE" - then - return 1 - fi - - $SUDO chkconfig NetworkManager off - $SUDO chkconfig network on - $SUDO service NetworkManager stop - - TMPFILE=`mktemp` - cat $IFACE | grep -v dhcp | grep -v DHCLIENT > $TMPFILE - echo "BRIDGE=$BRIDGE" >> $TMPFILE - $SUDO mv -f $TMPFILE $IFACE - - cat ifcfg-xenbr0 | sed -e "s/@BRIDGE/$BRIDGE/g" > $TMPFILE - $SUDO mv -f $TMPFILE /etc/sysconfig/network-scripts - - $SUDO iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT - $SUDO service iptables save - $SUDO service iptables restart - - $SUDO service network start -} - -function xen_update_bootloader_Debian() { - $SUDO update-grub -} - -function xen_update_bootloader_Fedora() { - $SUDO grub2-mkconfig -o /boot/grub2/grub.cfg -} - -function xen_configure() { - xen_create_bridge_$DISTRO - start_initscripts xencommons xendomains xen-watchdog - xen_update_bootloader_$DISTRO -} - -function xen_unconfigure() { - # leave the bridge in place - stop_initscripts xencommons xendomains xen-watchdog - if test "`grep -rIi xen /boot/grub* | head -1`" - then - xen_update_bootloader_$DISTRO - fi -}