]> xenbits.xensource.com Git - raisin.git/commitdiff
Move common-functions.sh and git-checkout.sh into lib
authorGeorge Dunlap <george.dunlap@eu.citrix.com>
Thu, 9 Apr 2015 14:40:18 +0000 (15:40 +0100)
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>
Fri, 10 Apr 2015 10:49:36 +0000 (10:49 +0000)
"script" implies something which is designed to be run standalone.

"lib" implies that this is going to be sourced from another bash script.

Also change "git-checkout" to be a function rather than a script

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
components/grub
components/libvirt
components/xen
lib/common-functions.sh [new file with mode: 0644]
lib/git-checkout.sh [new file with mode: 0755]
raise.sh
scripts/common-functions.sh [deleted file]
scripts/git-checkout.sh [deleted file]
unraise.sh

index 5a420009cbd1e372f4ec972ccd1a34b5597350b0..a5aa27d753bd86782daf63505c691e70d3bd9ca6 100644 (file)
@@ -29,7 +29,7 @@ function grub_build() {
     cd "$BASEDIR"
     rm -f memdisk.tar
     tar cf memdisk.tar -C data grub.cfg
-    ./scripts/git-checkout.sh $GRUB_UPSTREAM_URL $GRUB_UPSTREAM_REVISION grub-dir
+    git-checkout $GRUB_UPSTREAM_URL $GRUB_UPSTREAM_REVISION grub-dir
     cd grub-dir
     ./autogen.sh
     ## GRUB32
index e22996ea5069808e0ab1f542027dcfdc57c6e0bc..6602dcfc45e294e74c91067209548da2567c3f14 100644 (file)
@@ -26,7 +26,7 @@ function libvirt_build() {
     _libvirt_install_dependencies
 
     cd "$BASEDIR"
-    ./scripts/git-checkout.sh $LIBVIRT_UPSTREAM_URL $LIBVIRT_UPSTREAM_REVISION libvirt-dir
+    git-checkout $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 a49a1d1f582ab57a1878c1b2be942b2eaf1934da..70b72b0a015a9b6b8d0abf8fef24408a09d320f7 100644 (file)
@@ -23,7 +23,7 @@ function xen_build() {
     _xen_install_dependencies
 
     cd "$BASEDIR"
-    ./scripts/git-checkout.sh $XEN_UPSTREAM_URL $XEN_UPSTREAM_REVISION xen-dir
+    git-checkout $XEN_UPSTREAM_URL $XEN_UPSTREAM_REVISION xen-dir
     cd xen-dir
     ./configure --prefix=$PREFIX
     $MAKE
diff --git a/lib/common-functions.sh b/lib/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/lib/git-checkout.sh b/lib/git-checkout.sh
new file mode 100755 (executable)
index 0000000..2ca8f25
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+
+function git-checkout() {
+    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
+}
index 3c8281e49742f46eb37673f4b14fa186532fd239..422fbe44c258c868834829d6dd2d6a40038bf3ef 100755 (executable)
--- a/raise.sh
+++ b/raise.sh
@@ -3,7 +3,8 @@
 set -e
 
 source config
-source scripts/common-functions.sh
+source lib/common-functions.sh
+source lib/git-checkout.sh
 
 _help() {
     echo "Usage: ./build.sh <options> <command>"
diff --git a/scripts/common-functions.sh b/scripts/common-functions.sh
deleted file mode 100644 (file)
index cfa0c7f..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
-        ./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
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
index 2f08901c0dc3d133df10975c3656a6909a79cf48..50ce31027064a3eb09eb5a597ef2a522e154160f 100755 (executable)
@@ -3,7 +3,7 @@
 set -e
 
 source config
-source scripts/common-functions.sh
+source lib/common-functions.sh
 
 
 # start execution