]> xenbits.xensource.com Git - raisin.git/commitdiff
Move utility scripts under scripts sub-directory
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>
Tue, 7 Apr 2015 17:05:58 +0000 (17:05 +0000)
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>
Tue, 7 Apr 2015 17:10:24 +0000 (17:10 +0000)
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
13 files changed:
common-functions.sh [deleted file]
components/grub
components/libvirt
components/xen
git-checkout.sh [deleted file]
mkdeb [deleted file]
mkrpm [deleted file]
raise.sh
scripts/common-functions.sh [new file with mode: 0644]
scripts/git-checkout.sh [new file with mode: 0755]
scripts/mkdeb [new file with mode: 0755]
scripts/mkrpm [new file with mode: 0755]
unraise.sh

diff --git a/common-functions.sh b/common-functions.sh
deleted file mode 100644 (file)
index 7278c73..0000000
+++ /dev/null
@@ -1,228 +0,0 @@
-#!/usr/bin/env bash
-
-# Executed once at the beginning of the script
-function common_init() {
-    export BASEDIR=`pwd`
-    export GIT=${GIT-git}
-    export SUDO=${SUDO-sudo}
-    export MAKE=${MAKE-make}
-    export PREFIX=${PREFIX-/usr}
-    export INST_DIR=${DESTDIR-dist}
-    
-    INST_DIR=`readlink -f $INST_DIR`
-    
-    # execution
-    if [[ $EUID -eq 0 ]]
-    then
-        export SUDO=""
-    elif [[ ! -f `which sudo 2>/dev/null` ]]
-    then
-        echo "Raisin requires sudo to install build dependencies for you."
-        echo "Please install sudo, then run this script again."
-        exit 1
-    fi
-
-    if [[ -z "$BASH_VERSINFO" || ${BASH_VERSINFO[0]} -lt 3 ||
-        (${BASH_VERSINFO[0]} -eq 3 && ${BASH_VERSINFO[1]} -lt 2) ]]
-    then
-        echo "Raisin requires BASH 3.2 or newer."
-        exit 1
-    fi
-
-    get_distro
-    get_arch
-
-    for f in `cat "$BASEDIR"/components/series`
-    do
-        source "$BASEDIR"/components/"$f"
-    done
-}
-
-function get_distro() {
-    if [[ -x "`which lsb_release 2>/dev/null`" ]]
-    then
-        os_VENDOR=`lsb_release -i -s`
-        os_RELEASE=`lsb_release -r -s`
-        os_CODENAME=`lsb_release -c -s`
-        os_UPDATE=""
-    elif [[ -r /etc/redhat-release ]]
-    then
-        # Red Hat Enterprise Linux Server release 5.5 (Tikanga)
-        # Red Hat Enterprise Linux Server release 7.0 Beta (Maipo)
-        # CentOS release 5.5 (Final)
-        # CentOS Linux release 6.0 (Final)
-        # Fedora release 16 (Verne)
-        # XenServer release 6.2.0-70446c (xenenterprise)
-        os_CODENAME=""
-        for r in "Red Hat" "CentOS" "Fedora" "XenServer"; do
-            os_VENDOR="$r"
-            if [[ -n "`grep -i \"$r\" /etc/redhat-release`" ]]
-            then
-                ver=`sed -e 's/^.* \([0-9].*\) (\(.*\)).*$/\1\|\2/' /etc/redhat-release`
-                os_CODENAME=${ver#*|}
-                os_RELEASE=${ver%|*}
-                os_UPDATE=${os_RELEASE##*.}
-                os_RELEASE=${os_RELEASE%.*}
-                break
-            fi
-        done
-    elif [[ -r /etc/SuSE-release ]]
-    then
-        for r in "openSUSE" "SUSE Linux"
-        do
-            os_VENDOR="$r"
-
-            if [[ -n "`grep -i \"$r\" /etc/SuSE-release`" ]]
-            then
-                os_CODENAME=`grep "CODENAME = " /etc/SuSE-release | \
-                             sed 's:.* = ::g'`
-                os_RELEASE=`grep "VERSION = " /etc/SuSE-release | \
-                            sed 's:.* = ::g'`
-                os_UPDATE=`grep "PATCHLEVEL = " /etc/SuSE-release | \
-                           sed 's:.* = ::g'`
-                break
-            fi
-        done
-    # If lsb_release is not installed, we should be able to detect Debian OS
-    elif [[ -f /etc/debian_version && `cat /proc/version` =~ "Debian" ]]
-    then
-        os_VENDOR="Debian"
-        os_CODENAME=`awk '/VERSION=/' /etc/os-release | sed 's/VERSION=//' | \
-                     sed -r 's/\"|\(|\)//g' | awk '{print $2}'`
-        os_RELEASE=`awk '/VERSION_ID=/' /etc/os-release | sed 's/VERSION_ID=//' \
-                    | sed 's/\"//g'`
-    fi
-
-    # Simply distro version string
-    case "$os_VENDOR" in
-        "Debian"* | "Ubuntu"* | "LinuxMint"* )
-            DISTRO="Debian"
-            ;;
-        "SUSE"* )
-            DISTRO="SUSE"
-            ;;
-        "OpenSUSE"* | "openSUSE"* )
-            DISTRO="openSUSE"
-            ;;
-        "Red"* | "CentOS"* )
-            DISTRO="CentOS"
-            ;;
-        *)
-            DISTRO=$os_VENDOR
-            ;;
-    esac
-
-    export os_VENDOR os_RELEASE os_UPDATE os_CODENAME
-    export DISTRO
-}
-
-function get_arch() {
-    export ARCH=`uname -m | sed -e s/i.86/x86_32/ -e s/i86pc/x86_32/ -e \
-                s/amd64/x86_64/ -e s/armv7.*/arm32/ -e s/armv8.*/arm64/ \
-                -e s/aarch64/arm64/`
-}
-
-function install_dependencies() {
-    if [[ "$NO_DEPS" && "$NO_DEPS" -eq 1 ]]
-    then
-        echo "Not installing any dependencies, as requested."
-        echo "Depency list: $*"
-        return 0
-    fi
-    case $DISTRO in
-        "Debian" )
-        $SUDO apt-get install -y $*
-        ;;
-        "Fedora" )
-        $SUDO yum install -y $*
-        ;;
-        * )
-        echo "I don't know how to install dependencies on $DISTRO"
-        ;;
-    esac
-}
-
-function start_initscripts() {
-    while [[ $# -ge 1 ]]
-    do
-        case $DISTRO in
-            "Debian" )
-            $SUDO update-rc.d $1 defaults || echo "Couldn't set $1 to start"
-            ;;
-            "Fedora" )
-            $SUDO chkconfig --add $1 || echo "Couldn't set $1 to start"
-            ;;
-            * )
-            echo "I don't know how to start initscripts on $DISTRO"
-            return 1
-            ;;
-        esac
-        shift 1
-    done
-}
-
-function stop_initscripts() {
-    while [[ $# -ge 1 ]]
-    do
-        case $DISTRO in
-            "Debian" )
-            $SUDO update-rc.d $1 remove || echo "Couldn't remove $1 from init"
-            ;;
-            "Fedora" )
-            $SUDO chkconfig --del $1 || echo "Couldn't remove $1 from init"
-            ;;
-            * )
-            echo "I don't know how to start initscripts on $DISTRO"
-            return 1
-            ;;
-        esac
-        shift 1
-    done
-}
-
-function for_each_component () {
-    for component in `cat "$BASEDIR"/components/series`
-    do
-        capital=`echo $component | tr '[:lower:]' '[:upper:]'`
-        if eval [[ ! -z \$"$capital"_UPSTREAM_REVISION ]]
-        then
-            "$component"_"$1"
-        fi
-    done
-}
-
-function build_package() {
-    if [[ $DISTRO = "Debian" ]]
-    then
-        ./mkdeb "$1"
-    elif [[  $DISTRO = "Fedora" ]]
-    then
-        ./mkrpm "$1"
-    else
-        echo "Don't know how to create packages for $DISTRO"
-    fi
-}
-
-function install_package() {
-    if [[ $DISTRO = "Debian" ]]
-    then
-        $SUDO dpkg -i "$1".deb
-    elif [[  $DISTRO = "Fedora" ]]
-    then
-        $SUDO rpm -i --force "$1"-`git show --oneline | head -1 | cut -d " " -f 1`-0.$ARCH.rpm
-    else
-        echo "Don't know how to install packages on $DISTRO"
-    fi
-}
-
-function uninstall_package() {
-    if [[ $DISTRO = "Debian" ]]
-    then
-        $SUDO dpkg -r "$1"
-    elif [[ $DISTRO = "Fedora" ]]
-    then
-        $SUDO rpm -e "$1"
-    else
-        echo "Don't know how to uninstall packages on $DISTRO"
-    fi
-}
index 95f938249e4368ac2d392c8c21713d5e542cdbe6..ab4f58338583e6ba67a74cd611100f2dfd6560ea 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 source "$BASEDIR"/config
-source "$BASEDIR"/common-functions.sh
+source "$BASEDIR"/scripts/common-functions.sh
 
 
 function _grub_install_dependencies() {
@@ -33,7 +33,7 @@ function grub_build() {
     cd "$BASEDIR"
     rm -f memdisk.tar
     tar cf memdisk.tar -C data grub.cfg
-    ./git-checkout.sh $GRUB_UPSTREAM_URL $GRUB_UPSTREAM_REVISION grub-dir
+    ./scripts/git-checkout.sh $GRUB_UPSTREAM_URL $GRUB_UPSTREAM_REVISION grub-dir
     cd grub-dir
     ./autogen.sh
     ## GRUB32
index b39f3fa65bc9d0732f0e7455020a4c84dce25e1a..e35de8c38d0b79f9b0202cef5af7a98b1ef4b5c9 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 source "$BASEDIR"/config
-source "$BASEDIR"/common-functions.sh
+source "$BASEDIR"/scripts/common-functions.sh
 
 
 function _libvirt_install_dependencies() {
@@ -30,7 +30,7 @@ function libvirt_build() {
     _libvirt_install_dependencies
 
     cd "$BASEDIR"
-    ./git-checkout.sh $LIBVIRT_UPSTREAM_URL $LIBVIRT_UPSTREAM_REVISION libvirt-dir
+    ./scripts/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" \
index a4de7e4968577ae7f9eafc2ca9b1fa01b56f7830..d6286b285b51be2c32fdc5d07547490e75aadce5 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 source "$BASEDIR"/config
-source "$BASEDIR"/common-functions.sh
+source "$BASEDIR"/scripts/common-functions.sh
 
 
 function _xen_install_dependencies() {
@@ -27,7 +27,7 @@ function xen_build() {
     _xen_install_dependencies
 
     cd "$BASEDIR"
-    ./git-checkout.sh $XEN_UPSTREAM_URL $XEN_UPSTREAM_REVISION xen-dir
+    ./scripts/git-checkout.sh $XEN_UPSTREAM_URL $XEN_UPSTREAM_REVISION xen-dir
     cd xen-dir
     ./configure --prefix=$PREFIX
     $MAKE
diff --git a/git-checkout.sh b/git-checkout.sh
deleted file mode 100755 (executable)
index 912bfae..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/usr/bin/env bash
-
-if [[ $# -lt 3 ]]
-then
-       echo "Usage: $0 <tree> <tag> <dir>"
-       exit 1
-fi
-
-TREE=$1
-TAG=$2
-DIR=$3
-
-set -e
-
-if [[ ! -d $DIR-remote ]]
-then
-       rm -rf $DIR-remote $DIR-remote.tmp
-       mkdir -p $DIR-remote.tmp; rmdir $DIR-remote.tmp
-       $GIT clone $TREE $DIR-remote.tmp
-       if [[ "$TAG" ]]
-       then
-               cd $DIR-remote.tmp
-               $GIT branch -D dummy >/dev/null 2>&1 ||:
-               $GIT checkout -b dummy $TAG
-               cd ..
-       fi
-       mv $DIR-remote.tmp $DIR-remote
-fi
-rm -f $DIR
-ln -sf $DIR-remote $DIR
diff --git a/mkdeb b/mkdeb
deleted file mode 100755 (executable)
index 4e2ede3..0000000
--- a/mkdeb
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/usr/bin/env bash
-#
-# mkdeb: package $INST_DIR output in a .deb 
-#
-# Takes 1 argument: the package name
-# It relies on ARCH and INST_DIR being set correctly
-
-set -e
-
-if [[ -z "$1" ]]
-then 
-  echo "usage: $0 package_name"
-  exit 1
-fi 
-
-name=$1
-
-# map the architecture, if necessary
-case "$ARCH" in
-  x86_32|x86_32p)  arch=i386 ;;
-  x86_64)  arch=amd64 ;;
-  arm32)   arch=armhf ;;
-  arm64)   arch=$ARCH;;
-  *) echo "Unknown ARCH $ARCH" >&2
-     exit 1
-     ;;
-esac
-
-# Prepare the directory to package
-rm -rf deb
-cp -a "$INST_DIR" deb
-mkdir -p deb/opt/raisin
-cp -r data deb/opt/raisin
-cp -r components deb/opt/raisin
-cp common-functions.sh config git-checkout.sh raise.sh unraise.sh deb/opt/raisin
-
-
-# Debian doesn't use /usr/lib64 for 64-bit libraries
-if [[ -d deb/usr/lib64 ]]
-then 
-  cp -a deb/usr/lib64/* deb/usr/lib/
-  rm -rf deb/usr/lib64
-fi
-
-# Fill in the debian boilerplate
-mkdir -p deb/DEBIAN
-cat >deb/DEBIAN/control <<EOF
-Package: $name
-Source: raisin
-Version: $(git show --oneline | head -1 | cut -d " " -f 1)
-Architecture: $arch
-Maintainer: Unmaintained snapshot
-Section: admin
-Priority: optional
-Installed-Size: $(du -ks deb | cut -f1)
-Description: Raisin build
- Warning: This is a custom build of Xen, Libvirt and other
- components; it is not an  officially supported Debian package.
- It is just the output of a raish.sh wrapped in a .deb
- to make it easy to update and uninstall.
-EOF
-# Find all /etc files and add them to conffiles
-find deb/etc -type f -printf /etc/%P\\n >deb/DEBIAN/conffiles
-
-
-# Package it up
-chown -R root:root deb
-dpkg --build deb $name.deb
-
-# Tidy up after ourselves
-rm -rf deb
diff --git a/mkrpm b/mkrpm
deleted file mode 100755 (executable)
index 1659a25..0000000
--- a/mkrpm
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/usr/bin/env bash
-#
-# mkrpm: package INST_DIR in an .rpm
-#
-# Takes 1 argument: the package name
-# It relies on ARCH and INST_DIR being set correctly
-
-set -e
-
-if [[ -z "$1" ]]
-then 
-  echo "usage: $0 package_name"
-  exit 1
-fi 
-
-name="$1"
-
-# Prepare the directory to package
-rm -rf rpm
-
-# Fill in the rpm boilerplate
-mkdir -p rpm/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
-cat >rpm/SPECS/xen.spec <<EOF
-Summary: Raisin build
-Name: $name
-Version: $(git show --oneline | head -1 | cut -d " " -f 1)
-Release: 0
-License: GPL
-Group:   System/Hypervisor
-URL: http://xenbits.xenproject.org/sstabellini/raisin.git
-
-%description
-This package contains the Xen hypervisor, LibVirt and associated tools,
-built from source. It is not a fully packaged and supported Xen and
-related components, just the output of Raisin wrapped in an .rpm to make
-it easy to uninstall.
-
-%build
-
-%install
-rm -rf \$RPM_BUILD_ROOT
-mkdir -p \$RPM_BUILD_ROOT
-cp -ar "$INST_DIR"/* \$RPM_BUILD_ROOT
-mkdir -p \$RPM_BUILD_ROOT/opt/raisin
-cp -r "$BASEDIR"/data \$RPM_BUILD_ROOT/opt/raisin
-cp -r "$BASEDIR"/components \$RPM_BUILD_ROOT/opt/raisin
-cp "$BASEDIR"/common-functions.sh \$RPM_BUILD_ROOT/opt/raisin
-cp "$BASEDIR"/config \$RPM_BUILD_ROOT/opt/raisin
-cp "$BASEDIR"/git-checkout.sh \$RPM_BUILD_ROOT/opt/raisin
-cp "$BASEDIR"/raise.sh \$RPM_BUILD_ROOT/opt/raisin
-cp "$BASEDIR"/unraise.sh \$RPM_BUILD_ROOT/opt/raisin
-
-%clean
-
-%post
-/sbin/ldconfig
-
-%postun
-/sbin/ldconfig
-
-%files
-%defattr(-,root,root,-)
-/*
-EOF
-
-# Package it up
-rpmbuild --define "_topdir $BASEDIR/rpm" -bb rpm/SPECS/xen.spec
-
-# Tidy up after ourselves
-mv rpm/RPMS/*/*.rpm .
-rm -rf rpm
index 987490aeabe2a77f15fd57934096a303d8cde0df..3c8281e49742f46eb37673f4b14fa186532fd239 100755 (executable)
--- a/raise.sh
+++ b/raise.sh
@@ -3,7 +3,7 @@
 set -e
 
 source config
-source common-functions.sh
+source scripts/common-functions.sh
 
 _help() {
     echo "Usage: ./build.sh <options> <command>"
diff --git a/scripts/common-functions.sh b/scripts/common-functions.sh
new file mode 100644 (file)
index 0000000..cfa0c7f
--- /dev/null
@@ -0,0 +1,228 @@
+#!/usr/bin/env bash
+
+# Executed once at the beginning of the script
+function common_init() {
+    export BASEDIR=`pwd`
+    export GIT=${GIT-git}
+    export SUDO=${SUDO-sudo}
+    export MAKE=${MAKE-make}
+    export PREFIX=${PREFIX-/usr}
+    export INST_DIR=${DESTDIR-dist}
+    
+    INST_DIR=`readlink -f $INST_DIR`
+    
+    # execution
+    if [[ $EUID -eq 0 ]]
+    then
+        export SUDO=""
+    elif [[ ! -f `which sudo 2>/dev/null` ]]
+    then
+        echo "Raisin requires sudo to install build dependencies for you."
+        echo "Please install sudo, then run this script again."
+        exit 1
+    fi
+
+    if [[ -z "$BASH_VERSINFO" || ${BASH_VERSINFO[0]} -lt 3 ||
+        (${BASH_VERSINFO[0]} -eq 3 && ${BASH_VERSINFO[1]} -lt 2) ]]
+    then
+        echo "Raisin requires BASH 3.2 or newer."
+        exit 1
+    fi
+
+    get_distro
+    get_arch
+
+    for f in `cat "$BASEDIR"/components/series`
+    do
+        source "$BASEDIR"/components/"$f"
+    done
+}
+
+function get_distro() {
+    if [[ -x "`which lsb_release 2>/dev/null`" ]]
+    then
+        os_VENDOR=`lsb_release -i -s`
+        os_RELEASE=`lsb_release -r -s`
+        os_CODENAME=`lsb_release -c -s`
+        os_UPDATE=""
+    elif [[ -r /etc/redhat-release ]]
+    then
+        # Red Hat Enterprise Linux Server release 5.5 (Tikanga)
+        # Red Hat Enterprise Linux Server release 7.0 Beta (Maipo)
+        # CentOS release 5.5 (Final)
+        # CentOS Linux release 6.0 (Final)
+        # Fedora release 16 (Verne)
+        # XenServer release 6.2.0-70446c (xenenterprise)
+        os_CODENAME=""
+        for r in "Red Hat" "CentOS" "Fedora" "XenServer"; do
+            os_VENDOR="$r"
+            if [[ -n "`grep -i \"$r\" /etc/redhat-release`" ]]
+            then
+                ver=`sed -e 's/^.* \([0-9].*\) (\(.*\)).*$/\1\|\2/' /etc/redhat-release`
+                os_CODENAME=${ver#*|}
+                os_RELEASE=${ver%|*}
+                os_UPDATE=${os_RELEASE##*.}
+                os_RELEASE=${os_RELEASE%.*}
+                break
+            fi
+        done
+    elif [[ -r /etc/SuSE-release ]]
+    then
+        for r in "openSUSE" "SUSE Linux"
+        do
+            os_VENDOR="$r"
+
+            if [[ -n "`grep -i \"$r\" /etc/SuSE-release`" ]]
+            then
+                os_CODENAME=`grep "CODENAME = " /etc/SuSE-release | \
+                             sed 's:.* = ::g'`
+                os_RELEASE=`grep "VERSION = " /etc/SuSE-release | \
+                            sed 's:.* = ::g'`
+                os_UPDATE=`grep "PATCHLEVEL = " /etc/SuSE-release | \
+                           sed 's:.* = ::g'`
+                break
+            fi
+        done
+    # If lsb_release is not installed, we should be able to detect Debian OS
+    elif [[ -f /etc/debian_version && `cat /proc/version` =~ "Debian" ]]
+    then
+        os_VENDOR="Debian"
+        os_CODENAME=`awk '/VERSION=/' /etc/os-release | sed 's/VERSION=//' | \
+                     sed -r 's/\"|\(|\)//g' | awk '{print $2}'`
+        os_RELEASE=`awk '/VERSION_ID=/' /etc/os-release | sed 's/VERSION_ID=//' \
+                    | sed 's/\"//g'`
+    fi
+
+    # Simply distro version string
+    case "$os_VENDOR" in
+        "Debian"* | "Ubuntu"* | "LinuxMint"* )
+            DISTRO="Debian"
+            ;;
+        "SUSE"* )
+            DISTRO="SUSE"
+            ;;
+        "OpenSUSE"* | "openSUSE"* )
+            DISTRO="openSUSE"
+            ;;
+        "Red"* | "CentOS"* )
+            DISTRO="CentOS"
+            ;;
+        *)
+            DISTRO=$os_VENDOR
+            ;;
+    esac
+
+    export os_VENDOR os_RELEASE os_UPDATE os_CODENAME
+    export DISTRO
+}
+
+function get_arch() {
+    export ARCH=`uname -m | sed -e s/i.86/x86_32/ -e s/i86pc/x86_32/ -e \
+                s/amd64/x86_64/ -e s/armv7.*/arm32/ -e s/armv8.*/arm64/ \
+                -e s/aarch64/arm64/`
+}
+
+function install_dependencies() {
+    if [[ "$NO_DEPS" && "$NO_DEPS" -eq 1 ]]
+    then
+        echo "Not installing any dependencies, as requested."
+        echo "Depency list: $*"
+        return 0
+    fi
+    case $DISTRO in
+        "Debian" )
+        $SUDO apt-get install -y $*
+        ;;
+        "Fedora" )
+        $SUDO yum install -y $*
+        ;;
+        * )
+        echo "I don't know how to install dependencies on $DISTRO"
+        ;;
+    esac
+}
+
+function start_initscripts() {
+    while [[ $# -ge 1 ]]
+    do
+        case $DISTRO in
+            "Debian" )
+            $SUDO update-rc.d $1 defaults || echo "Couldn't set $1 to start"
+            ;;
+            "Fedora" )
+            $SUDO chkconfig --add $1 || echo "Couldn't set $1 to start"
+            ;;
+            * )
+            echo "I don't know how to start initscripts on $DISTRO"
+            return 1
+            ;;
+        esac
+        shift 1
+    done
+}
+
+function stop_initscripts() {
+    while [[ $# -ge 1 ]]
+    do
+        case $DISTRO in
+            "Debian" )
+            $SUDO update-rc.d $1 remove || echo "Couldn't remove $1 from init"
+            ;;
+            "Fedora" )
+            $SUDO chkconfig --del $1 || echo "Couldn't remove $1 from init"
+            ;;
+            * )
+            echo "I don't know how to start initscripts on $DISTRO"
+            return 1
+            ;;
+        esac
+        shift 1
+    done
+}
+
+function for_each_component () {
+    for component in `cat "$BASEDIR"/components/series`
+    do
+        capital=`echo $component | tr '[:lower:]' '[:upper:]'`
+        if eval [[ ! -z \$"$capital"_UPSTREAM_REVISION ]]
+        then
+            "$component"_"$1"
+        fi
+    done
+}
+
+function build_package() {
+    if [[ $DISTRO = "Debian" ]]
+    then
+        ./scripts/mkdeb "$1"
+    elif [[  $DISTRO = "Fedora" ]]
+    then
+        ./scripts/mkrpm "$1"
+    else
+        echo "Don't know how to create packages for $DISTRO"
+    fi
+}
+
+function install_package() {
+    if [[ $DISTRO = "Debian" ]]
+    then
+        $SUDO dpkg -i "$1".deb
+    elif [[  $DISTRO = "Fedora" ]]
+    then
+        $SUDO rpm -i --force "$1"-`git show --oneline | head -1 | cut -d " " -f 1`-0.$ARCH.rpm
+    else
+        echo "Don't know how to install packages on $DISTRO"
+    fi
+}
+
+function uninstall_package() {
+    if [[ $DISTRO = "Debian" ]]
+    then
+        $SUDO dpkg -r "$1"
+    elif [[ $DISTRO = "Fedora" ]]
+    then
+        $SUDO rpm -e "$1"
+    else
+        echo "Don't know how to uninstall packages on $DISTRO"
+    fi
+}
diff --git a/scripts/git-checkout.sh b/scripts/git-checkout.sh
new file mode 100755 (executable)
index 0000000..912bfae
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+
+if [[ $# -lt 3 ]]
+then
+       echo "Usage: $0 <tree> <tag> <dir>"
+       exit 1
+fi
+
+TREE=$1
+TAG=$2
+DIR=$3
+
+set -e
+
+if [[ ! -d $DIR-remote ]]
+then
+       rm -rf $DIR-remote $DIR-remote.tmp
+       mkdir -p $DIR-remote.tmp; rmdir $DIR-remote.tmp
+       $GIT clone $TREE $DIR-remote.tmp
+       if [[ "$TAG" ]]
+       then
+               cd $DIR-remote.tmp
+               $GIT branch -D dummy >/dev/null 2>&1 ||:
+               $GIT checkout -b dummy $TAG
+               cd ..
+       fi
+       mv $DIR-remote.tmp $DIR-remote
+fi
+rm -f $DIR
+ln -sf $DIR-remote $DIR
diff --git a/scripts/mkdeb b/scripts/mkdeb
new file mode 100755 (executable)
index 0000000..46ade07
--- /dev/null
@@ -0,0 +1,74 @@
+#!/usr/bin/env bash
+#
+# mkdeb: package $INST_DIR output in a .deb 
+#
+# Takes 1 argument: the package name
+# It relies on ARCH and INST_DIR being set correctly
+
+set -e
+
+if [[ -z "$1" ]]
+then 
+  echo "usage: $0 package_name"
+  exit 1
+fi 
+
+name=$1
+
+cd "$BASEDIR"
+
+# map the architecture, if necessary
+case "$ARCH" in
+  x86_32|x86_32p)  arch=i386 ;;
+  x86_64)  arch=amd64 ;;
+  arm32)   arch=armhf ;;
+  arm64)   arch=$ARCH;;
+  *) echo "Unknown ARCH $ARCH" >&2
+     exit 1
+     ;;
+esac
+
+# Prepare the directory to package
+rm -rf deb
+cp -a "$INST_DIR" deb
+mkdir -p deb/opt/raisin
+cp -r data deb/opt/raisin
+cp -r components deb/opt/raisin
+cp -r scripts deb/opt/raisin
+cp config raise.sh unraise.sh deb/opt/raisin
+
+
+# Debian doesn't use /usr/lib64 for 64-bit libraries
+if [[ -d deb/usr/lib64 ]]
+then 
+  cp -a deb/usr/lib64/* deb/usr/lib/
+  rm -rf deb/usr/lib64
+fi
+
+# Fill in the debian boilerplate
+mkdir -p deb/DEBIAN
+cat >deb/DEBIAN/control <<EOF
+Package: $name
+Source: raisin
+Version: $(git show --oneline | head -1 | cut -d " " -f 1)
+Architecture: $arch
+Maintainer: Unmaintained snapshot
+Section: admin
+Priority: optional
+Installed-Size: $(du -ks deb | cut -f1)
+Description: Raisin build
+ Warning: This is a custom build of Xen, Libvirt and other
+ components; it is not an  officially supported Debian package.
+ It is just the output of a raish.sh wrapped in a .deb
+ to make it easy to update and uninstall.
+EOF
+# Find all /etc files and add them to conffiles
+find deb/etc -type f -printf /etc/%P\\n >deb/DEBIAN/conffiles
+
+
+# Package it up
+chown -R root:root deb
+dpkg --build deb $name.deb
+
+# Tidy up after ourselves
+rm -rf deb
diff --git a/scripts/mkrpm b/scripts/mkrpm
new file mode 100755 (executable)
index 0000000..c530466
--- /dev/null
@@ -0,0 +1,72 @@
+#!/usr/bin/env bash
+#
+# mkrpm: package INST_DIR in an .rpm
+#
+# Takes 1 argument: the package name
+# It relies on ARCH and INST_DIR being set correctly
+
+set -e
+
+if [[ -z "$1" ]]
+then 
+  echo "usage: $0 package_name"
+  exit 1
+fi 
+
+name="$1"
+
+cd "$BASEDIR"
+
+# Prepare the directory to package
+rm -rf rpm
+
+# Fill in the rpm boilerplate
+mkdir -p rpm/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
+cat >rpm/SPECS/xen.spec <<EOF
+Summary: Raisin build
+Name: $name
+Version: $(git show --oneline | head -1 | cut -d " " -f 1)
+Release: 0
+License: GPL
+Group:   System/Hypervisor
+URL: http://xenbits.xenproject.org/sstabellini/raisin.git
+
+%description
+This package contains the Xen hypervisor, LibVirt and associated tools,
+built from source. It is not a fully packaged and supported Xen and
+related components, just the output of Raisin wrapped in an .rpm to make
+it easy to uninstall.
+
+%build
+
+%install
+rm -rf \$RPM_BUILD_ROOT
+mkdir -p \$RPM_BUILD_ROOT
+cp -ar "$INST_DIR"/* \$RPM_BUILD_ROOT
+mkdir -p \$RPM_BUILD_ROOT/opt/raisin
+cp -r "$BASEDIR"/data \$RPM_BUILD_ROOT/opt/raisin
+cp -r "$BASEDIR"/components \$RPM_BUILD_ROOT/opt/raisin
+cp -r "$BASEDIR"/scripts \$RPM_BUILD_ROOT/opt/raisin
+cp "$BASEDIR"/config \$RPM_BUILD_ROOT/opt/raisin
+cp "$BASEDIR"/raise.sh \$RPM_BUILD_ROOT/opt/raisin
+cp "$BASEDIR"/unraise.sh \$RPM_BUILD_ROOT/opt/raisin
+
+%clean
+
+%post
+/sbin/ldconfig
+
+%postun
+/sbin/ldconfig
+
+%files
+%defattr(-,root,root,-)
+/*
+EOF
+
+# Package it up
+rpmbuild --define "_topdir $BASEDIR/rpm" -bb rpm/SPECS/xen.spec
+
+# Tidy up after ourselves
+mv rpm/RPMS/*/*.rpm .
+rm -rf rpm
index 3b49f052bf02adaecce79de9a00d2707a165e408..2f08901c0dc3d133df10975c3656a6909a79cf48 100755 (executable)
@@ -3,7 +3,7 @@
 set -e
 
 source config
-source common-functions.sh
+source scripts/common-functions.sh
 
 
 # start execution