]> xenbits.xensource.com Git - people/sstabellini/raisin.git/commitdiff
First, create a new global variable, PKGTYPE. At the moment support "deb" and "rpm".
authorGeorge Dunlap <George.Dunlap@eu.citrix.com>
Fri, 10 Apr 2015 11:57:21 +0000 (11:57 +0000)
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>
Fri, 10 Apr 2015 14:29:47 +0000 (14:29 +0000)
Define _check-package-$PKGTYPE which returns true if the package is
installed, false otherwise, and _install-package-$PKGTYPE which will
install a list of packages.

Define check-package(), which will take a list of packages, and check
to see if they're installed.  Any missing packages will be added to an
array called "missing".

Change _${COMPONENT}_install_dependencies to
${COMPONENT}_check_package.  Have these call check-package.

Define check-builddeps().  Define an empty "missing" array.  Call
check-package for "raisin" dependincies (like git and rpmbuild).  Then
call for_each_component check_package.

At this point we have an array with all missing packages.  If it's
empty, be happy.  If it's non-empty, and deps=true, try to install the
packages; otherwise print the missing packages and exit.

Add install-builddeps(), which is basically check-builddeps() with
YES=y.

Call check-builddeps from build() to close the loop.

Add function keyword to all other exported functions in commands.sh.

Remove --no-deps command line option.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
components/grub
components/libvirt
components/xen
lib/commands.sh
lib/common-functions.sh
raise

index a5aa27d753bd86782daf63505c691e70d3bd9ca6..b538fb15d77a140f7d026c5a86de4f505aba0b15 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 
-function _grub_install_dependencies() {
+function grub_check_package() {
     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"
@@ -18,14 +18,12 @@ function _grub_install_dependencies() {
         echo grub is only supported on x86_32 and x86_64
         return
     fi
-    echo installing Grub dependencies
-    eval install_dependencies \$DEP_"$DISTRO"_"$ARCH"
+    echo Checking Grub dependencies
+    eval check-package \$DEP_"$DISTRO"_"$ARCH"
 }
 
 
 function grub_build() {
-    _grub_install_dependencies
-
     cd "$BASEDIR"
     rm -f memdisk.tar
     tar cf memdisk.tar -C data grub.cfg
index 6602dcfc45e294e74c91067209548da2567c3f14..430d651e2b0e1ce8c2f26fa4e11ce9e43e747c37 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 
-function _libvirt_install_dependencies() {
+function libvirt_check_package() {
     local DEP_Debian_common="build-essential libtool autoconf autopoint \
                              xsltproc libxml2-utils pkg-config python-dev   \
                              libxml-xpath-perl libyajl-dev libxml2-dev      \
@@ -18,13 +18,11 @@ function _libvirt_install_dependencies() {
     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"
+    echo Checking Libvirt dependencies
+    eval check-package \$DEP_"$DISTRO"_"$ARCH"
 }
 
 function libvirt_build() {
-    _libvirt_install_dependencies
-
     cd "$BASEDIR"
     git-checkout $LIBVIRT_UPSTREAM_URL $LIBVIRT_UPSTREAM_REVISION libvirt-dir
     cd libvirt-dir
index 7a9f22d6f873b94545c6c00d066adb767bbfd0e0..2d345a89c5bf6f7107e27bf7e0ba03011ec3b26f 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 
-function _xen_install_dependencies() {
+function xen_check_package() {
     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 wget"
@@ -15,13 +15,11 @@ function _xen_install_dependencies() {
     local DEP_Fedora_x86_32="$DEP_Fedora_common dev86 acpica-tools texinfo"
     local DEP_Fedora_x86_64="$DEP_Fedora_x86_32 glibc-devel.i686"
 
-    echo installing Xen dependencies
-    eval install_dependencies \$DEP_"$DISTRO"_"$ARCH"
+    echo Checking Xen dependencies
+    eval check-package \$DEP_"$DISTRO"_"$ARCH"
 }
 
 function xen_build() {
-    _xen_install_dependencies
-
     cd "$BASEDIR"
     git-checkout $XEN_UPSTREAM_URL $XEN_UPSTREAM_REVISION xen-dir
     cd xen-dir
index 58275657b28987ece78827e387458698b46e7476..bf5493bc9b1e6b0535379a03e05abefbde6ca49f 100755 (executable)
@@ -1,30 +1,52 @@
 #!/usr/bin/env bash
 
-build() {
-    if [[ $YES != "y" ]]
+function check-builddep() {
+    local -a missing
+
+    check-package git
+
+    if [[ $DISTRO = "Fedora" ]]
     then
-        echo "Do you want Raisin to automatically install build time dependencies for you? (y/n)"
-        while read answer
-        do
-            if [[ "$answer" = "n" ]]
-            then
-                NO_DEPS=1
-                break
-            elif [[ "$answer" = "y" ]]
-            then
-                break
-            else
-                echo "Reply y or n"
-            fi
-        done
+        check-package rpm-build
     fi
 
-    mkdir -p "$INST_DIR" &>/dev/null
-    install_dependencies git
-    if [[ $DISTRO = "Fedora" ]]
+    for_each_component check_package
+
+    if [[ -n "${missing[@]}" ]]
     then
-        install_dependencies rpm-build
+        echo "Missing packages: ${missing[@]}"
+        if [[ $YES != "y" ]]
+        then
+            echo "Do you want Raisin to automatically install them for you? (y/n)"
+            while read answer
+            do
+                if [[ "$answer" = "n" ]]
+                then
+                    echo "Please install, or run ./raise install-builddep"
+                    exit 1
+                elif [[ "$answer" = "y" ]]
+                then
+                    break
+                else
+                    echo "Reply y or n"
+                fi
+            done
+        fi
+
+        echo "Installing..."
+        install-package "${missing[@]}"
     fi
+}
+
+function install-builddep() {
+    YES=y check-builddep
+}
+
+function build() {
+    check-builddep
+    
+    mkdir -p "$INST_DIR" &>/dev/null
+
     # build and install under $DESTDIR
     for_each_component clean
     for_each_component build
@@ -32,7 +54,7 @@ build() {
     build_package xen-system
 }
 
-unraise() {
+function unraise() {
     for_each_component clean
 
     uninstall_package xen-system
@@ -41,7 +63,7 @@ unraise() {
     rm -rf "$INST_DIR"
 }
 
-install() {
+function install() {
     # need single braces for filename matching expansion
     if [ ! -f xen-sytem*rpm ] && [ ! -f xen-system*deb ]
     then
@@ -51,7 +73,7 @@ install() {
     install_package xen-system
 }
 
-configure() {
+function configure() {
     if [[ $YES != "y" ]]
     then
         echo "Proceeding we'll make changes to the running system,"
index cfa0c7f1218fbd1ec84e4140a984447310caa66b..a523f5dc7a8714125091260a6bb95891ac77209b 100644 (file)
@@ -97,15 +97,23 @@ function get_distro() {
     case "$os_VENDOR" in
         "Debian"* | "Ubuntu"* | "LinuxMint"* )
             DISTRO="Debian"
+            PKGTYPE="deb"
+            ;;
+        "Fedora" )
+            DISTRO="Fedora"
+            PKGTYPE="rpm"
             ;;
         "SUSE"* )
             DISTRO="SUSE"
+            PKGTYPE="rpm"
             ;;
         "OpenSUSE"* | "openSUSE"* )
             DISTRO="openSUSE"
+            PKGTYPE="rpm"
             ;;
         "Red"* | "CentOS"* )
             DISTRO="CentOS"
+            PKGTYPE="rpm"
             ;;
         *)
             DISTRO=$os_VENDOR
@@ -114,6 +122,7 @@ function get_distro() {
 
     export os_VENDOR os_RELEASE os_UPDATE os_CODENAME
     export DISTRO
+    export PKGTYPE
 }
 
 function get_arch() {
@@ -122,24 +131,56 @@ function get_arch() {
                 -e s/aarch64/arm64/`
 }
 
-function install_dependencies() {
-    if [[ "$NO_DEPS" && "$NO_DEPS" -eq 1 ]]
+function _check-package-deb() {
+    if [[ $VERBOSE -eq 1 ]]
+    then
+        echo "Checking for package ${args[0]}"
+    fi
+
+    if dpkg -s "$1" 2>/dev/null | grep -q "Status:.*installed"
     then
-        echo "Not installing any dependencies, as requested."
-        echo "Depency list: $*"
         return 0
+    else
+        return 1
     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 _install-package-deb() {
+    $SUDO apt-get install -y $*
+}
+
+function _check-package-rpm() {
+    if [[ $VERBOSE -eq 1 ]]
+    then
+        echo "Checking for package $1"
+    fi
+
+    if rpm -q "$1" 2>&1 >/dev/null
+    then
+        return 0
+    else
+        return 1
+    fi
+}
+
+function _install-package-rpm() {
+    $SUDO yum install -y $*
+}
+
+# Modifies inherited variable "missing"
+function check-package() {
+    for p in $*
+    do
+        if ! _check-package-${PKGTYPE} $p
+        then
+            missing+=("$p")
+        fi
+    done
+
+}
+
+function install-package() {
+    _install-package-${PKGTYPE} $*
 }
 
 function start_initscripts() {
diff --git a/raise b/raise
index 45c0c252f19d6072761758e91e73cd35b9083a68..b254904d624ffff17db08ca344454b22387feabe 100755 (executable)
--- a/raise
+++ b/raise
@@ -5,10 +5,10 @@ set -e
 _help() {
     echo "Usage: ./build.sh <options> <command>"
     echo "where options are:"
-    echo "    -n | --no-deps       Do no install build-time dependencies"
     echo "    -v | --verbose       Verbose"
     echo "    -y | --yes           Do not ask questions and continue"
     echo "where commands are:"
+    echo "    install-builddep     Install build time dependencies (requires sudo)"
     echo "    build                Build the components enabled in config"
     echo "    install              Install binaries under /  (requires sudo)"
     echo "    configure            Configure the system  (requires sudo)"
@@ -42,7 +42,6 @@ common_init
 # parameters check
 export VERBOSE=0
 export YES="n"
-export NO_DEPS=0
 while [[ $# -gt 1 ]]
 do
   if [[ "$1" = "-v" || "$1" = "--verbose" ]]
@@ -60,7 +59,7 @@ do
 done
 
 case "$1" in
-    "build" | "install" | "configure" | "unraise" )
+    "install-builddep" | "build" | "install" | "configure" | "unraise" )
         COMMAND=$1
         ;;
     *)