First, create a new global variable, PKGTYPE. At the moment support "deb" and "rpm".
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.
Don't call _${COMPONENT}_install_dependencies from ${COMPONENT}_build.
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
deps=true by default.
Call check-builddeps from build() to close the loop.
Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
---
CC: Stefano Stabellini <stefano.stabellini@citrix.com>
#!/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"
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"
}
#!/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 \
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() {
#!/usr/bin/env bash
-function _xen_install_dependencies() {
+function xen_check_package() {
+ $requireargs DISTRO ARCH
+
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"
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
set -e
-_help() {
- echo "Usage: ./build.sh <options> <command>"
+RAISIN_HELP+=("check-builddep Check to make sure we have all dependencies installed")
+function check-builddep() {
+ local -a missing
+
+ $arg_parse
+
+ default deps "false" ; $default_post
+
+ $requireargs PKGTYPE DISTRO
+
+ check-package git
+
+ if [[ $DISTRO = "Fedora" ]] ; then
+ check-package rpm-build
+ fi
+
+ for_each_component check_package
+
+ if [[ -n "${missing[@]}" ]] ; then
+ echo "Missing packages: ${missing[@]}"
+ if $deps ; then
+ echo "Installing..."
+ install-package "${missing[@]}"
+ else
+ echo "Please install, or run ./raise install-builddep"
+ exit 1
+ fi
+ fi
+}
+
+RAISIN_HELP+=("install-builddep Install all packages required for build. Uses sudo.")
+function install-builddep() {
+ local pkgtype
+
+ $arg_parse
+
+ check-builddep deps=true
+}
+
+build-help() {
+ echo "Usage: $0 build opt=val"
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 " build Build the components enabled in config"
- echo " install Install binaries under / (requires sudo)"
- echo " configure Configure the system (requires sudo)"
+ echo " yes=(true|false) Don't ask before doing anything dangerous. Defaults to false."
+ echo " deps=(true|false) Attempt to install dependencies. Defaults to false."
+ echo " verbose=(true|false) Increased verbosity. Defaults to false."
}
+RAISIN_HELP+=("build Clone and build components enabled in config")
build() {
$arg_parse
- if [[ $YES != "y" ]]
- then
- echo "Do you want Raisin to automatically install build time dependencies for you? (y/n)"
+ default deps "false" ; $default_post
+ default verbose "false" ; $default_post
+ default yes "false" ; $default_post
+
+ if $deps && ! $yes ; then
+ echo "WARNING: You have chosen to automatically install software as root."
+ echo -n "Are you sure that you want to continue? (y/n)"
while read answer
do
if [[ "$answer" = "n" ]]
then
- NO_DEPS=1
- break
+ exit 0
elif [[ "$answer" = "y" ]]
then
+ yes="true"
break
else
echo "Reply y or n"
done
fi
+ check-builddep
+
mkdir -p "$INST_DIR" &>/dev/null
- install_dependencies git
- if [[ $DISTRO = "Fedora" ]]
- then
- install_dependencies rpm-build
- fi
+
# build and install under $DESTDIR
for_each_component clean
for_each_component build
rm -rf "$INST_DIR"
}
+RAISIN_HELP+=("install Install binaries under / (requires sudo)")
install() {
$arg_parse
install_package xen-system
}
+RAISIN_HELP+=("configure Configure the system (requires sudo)")
configure() {
$arg_parse
- if [[ $YES != "y" ]]
- then
- echo "Proceeding we'll make changes to the running system,"
+ default verbose "false" ; $default_post
+ default yes "false" ; $default_post
+
+ if $deps && ! $yes ; then
+ echo "WARNING: Proceeding we'll make changes to the running system,"
echo "are you sure that you want to continue? (y/n)"
while read answer
do
exit 0
elif [[ "$answer" = "y" ]]
then
+ yes="true"
break
else
echo "Reply y or n"
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
export os_VENDOR os_RELEASE os_UPDATE os_CODENAME
export DISTRO
+ export PKGTYPE
}
function get_arch() {
-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
+function _check-package-deb() {
+ $arg_parse
+
+ $verbose && echo "Checking for package ${args[0]}"
+
+ if dpkg -s "${args[0]}" 2>/dev/null | grep -q "Status:.*installed" ; then
+ 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() {
+ $arg_parse
+
+ $requireargs SUDO
+
+ $SUDO apt-get install -y "${args[@]}"
+}
+
+function _check-package-rpm() {
+ local pstatus
+
+ $arg_parse
+
+ $verbose && echo "Checking for package ${args[0]}"
+
+ if rpm -q "${args[0]}" 2>&1 >/dev/null ; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+function _install-package-rpm() {
+ $arg_parse
+
+ $requireargs SUDO
+
+ $SUDO yum install -y "${args[@]}"
+}
+
+# Modifies inherited variable "missing"
+function check-package() {
+ local p
+
+ $arg_parse
+
+ $requireargs PKGTYPE
+
+ for p in "${args[@]}" ; do
+ if ! _check-package-${PKGTYPE} $p ; then
+ missing+=("$p")
+ fi
+ done
+
+}
+
+function install-package() {
+ $arg_parse
+
+ $requireargs PKGTYPE
+
+ _install-package-${PKGTYPE} "${args[@]}"
}
function start_initscripts() {