Shell version compliance
------------------------
-Although we are requiring bash to run at the moment, please don't make
-assumption on the bash version available. Use modern features only when
-no older constructs do what you need.
+Raisin requires BASH 3.2 or newer, use BASH features accordingly.
Indentation
echo something
}
+Prepend _ to the function name if it is a local function.
+
Tests
-----
-Use "test" to make a test. Do not use [. Do not use [[ unless you have a
-good reason.
+Use [[ for tests. Do not use test or [.
Subshell
Numeric tests
-------------
-Use expr for calculations.
+Use $(( )) for calculations.
Awk
---
-Use cut, tr, bash 4+ and sed instead of awk when possible, in this order.
+Use bash 3 features, cut, tr and sed instead of awk when possible.
Block structure
if statements, place then on a new line:
-if test -z "$VAR"
+if [[ -z "$VAR" ]]
then
echo do something
fi
INST_DIR=`readlink -f $INST_DIR`
# execution
- if test $EUID -eq 0
+ if [[ $EUID -eq 0 ]]
then
export SUDO=""
- elif test ! -f `which sudo 2>/dev/null`
+ 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 test -z "$BASH_VERSINFO" || test ${BASH_VERSINFO[0]} -lt 3 ||
- (test ${BASH_VERSINFO[0]} -eq 3 && test ${BASH_VERSINFO[1]} -lt 2)
+ 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
}
function get_distro() {
- if test -x "`which lsb_release 2>/dev/null`"
+ 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 test -r /etc/redhat-release
+ 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)
os_CODENAME=""
for r in "Red Hat" "CentOS" "Fedora" "XenServer"; do
os_VENDOR="$r"
- if test -n "`grep -i \"$r\" /etc/redhat-release`"
+ if [[ -n "`grep -i \"$r\" /etc/redhat-release`" ]]
then
ver=`sed -e 's/^.* \([0-9].*\) (\(.*\)).*$/\1\|\2/' /etc/redhat-release`
os_CODENAME=${ver#*|}
break
fi
done
- elif test -r /etc/SuSE-release
+ elif [[ -r /etc/SuSE-release ]]
then
for r in "openSUSE" "SUSE Linux"
do
os_VENDOR="$r"
- if test -n "`grep -i \"$r\" /etc/SuSE-release`"
+ if [[ -n "`grep -i \"$r\" /etc/SuSE-release`" ]]
then
os_CODENAME=`grep "CODENAME = " /etc/SuSE-release | \
sed 's:.* = ::g'`
fi
done
# If lsb_release is not installed, we should be able to detect Debian OS
- elif test -f /etc/debian_version && [[ `cat /proc/version` =~ "Debian" ]]
+ elif [[ -f /etc/debian_version && `cat /proc/version` =~ "Debian" ]]
then
os_VENDOR="Debian"
os_CODENAME=`awk '/VERSION=/' /etc/os-release | sed 's/VERSION=//' | \
}
function install_dependencies() {
- if test "$NO_DEPS" && test "$NO_DEPS" -eq 1
+ if [[ "$NO_DEPS" && "$NO_DEPS" -eq 1 ]]
then
echo "Not installing any dependencies, as requested."
echo "Depency list: $*"
}
function start_initscripts() {
- while test $# -ge 1
+ while [[ $# -ge 1 ]]
do
case $DISTRO in
"Debian" )
}
function stop_initscripts() {
- while test $# -ge 1
+ while [[ $# -ge 1 ]]
do
case $DISTRO in
"Debian" )
for component in `cat "$BASEDIR"/components/series`
do
capital=`echo $component | tr '[:lower:]' '[:upper:]'`
- if test "`eval echo \$"$capital"_UPSTREAM_URL`"
+ if [[ "`eval echo \$"$capital"_UPSTREAM_URL`" ]]
then
"$component"_"$1"
fi
}
function build_package() {
- if test $DISTRO = "Debian"
+ if [[ $DISTRO = "Debian" ]]
then
./mkdeb "$1"
- elif test $DISTRO = "Fedora"
+ elif [[ $DISTRO = "Fedora" ]]
then
./mkrpm "$1"
else
}
function install_package() {
- if test $DISTRO = "Debian"
+ if [[ $DISTRO = "Debian" ]]
then
$SUDO dpkg -i "$1".deb
- elif test $DISTRO = "Fedora"
+ elif [[ $DISTRO = "Fedora" ]]
then
$SUDO rpm -i --force "$1"-`git show --oneline | head -1 | cut -d " " -f 1`-0.$ARCH.rpm
else
}
function uninstall_package() {
- if test $DISTRO = "Debian"
+ if [[ $DISTRO = "Debian" ]]
then
$SUDO dpkg -r "$1"
- elif test $DISTRO = "Fedora"
+ elif [[ $DISTRO = "Fedora" ]]
then
$SUDO rpm -e "$1"
else
source "$BASEDIR"/common-functions.sh
-function grub_install_dependencies() {
+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_Fedora_x86_64="$DEP_Fedora_common glibc-devel.i686"
- if test $ARCH != "x86_64" && test $ARCH != "x86_32"
+ if [[ $ARCH != "x86_64" && $ARCH != "x86_32" ]]
then
echo grub is only supported on x86_32 and x86_64
return
function grub_build() {
- grub_install_dependencies
+ _grub_install_dependencies
cd "$BASEDIR"
rm -f memdisk.tar
-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"
+ if [[ $ARCH = "x86_64" ]]
then
$MAKE clean
./configure --target=amd64 --with-platform=xen
function grub_clean() {
cd "$BASEDIR"
rm -rf memdisk.tar
- if test -d grub-dir
+ if [[ -d grub-dir ]]
then
cd grub-dir
$MAKE distclean
source "$BASEDIR"/common-functions.sh
-function libvirt_install_dependencies() {
+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 \
}
function libvirt_build() {
- libvirt_install_dependencies
+ _libvirt_install_dependencies
cd "$BASEDIR"
./git-checkout.sh $LIBVIRT_UPSTREAM_URL $LIBVIRT_UPSTREAM_REVISION libvirt-dir
--with-yajl --without-macvtap --without-avahi --prefix=$PREFIX
$MAKE
$MAKE --ignore-errors install DESTDIR="$INST_DIR" || true
- if test $DISTRO = "Debian"
+ if [[ $DISTRO = "Debian" ]]
then
mkdir -p "$INST_DIR"/etc/init.d
cat "$BASEDIR"/data/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"
+ elif [[ $DISTRO = "Fedora" || $DISTRO = "CentOS" ]]
then
$MAKE -C daemon libvirtd.init
mkdir -p "$INST_DIR"/etc/rc.d/init.d
function libvirt_clean() {
cd "$BASEDIR"
- if test -d libvirt-dir
+ if [[ -d libvirt-dir ]]
then
cd libvirt-dir
$MAKE distclean
function libvirt_configure() {
start_initscripts libvirtd
- if test $DISTRO = "Fedora" || test $DISTRO = "CentOS"
+ if [[ $DISTRO = "Fedora" || $DISTRO = "CentOS" ]]
then
start_initscripts libvirt-guests virtlockd
fi
function libvirt_unconfigure() {
stop_initscripts libvirtd
- if test $DISTRO = "Fedora" || test $DISTRO = "CentOS"
+ if [[ $DISTRO = "Fedora" || $DISTRO = "CentOS" ]]
then
stop_initscripts libvirt-guests virtlockd
fi
source "$BASEDIR"/common-functions.sh
-function xen_install_dependencies() {
+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"
}
function xen_build() {
- xen_install_dependencies
+ _xen_install_dependencies
cd "$BASEDIR"
./git-checkout.sh $XEN_UPSTREAM_URL $XEN_UPSTREAM_REVISION xen-dir
function xen_clean() {
cd "$BASEDIR"
- if test -d xen-dir
+ if [[ -d xen-dir ]]
then
cd xen-dir
$MAKE distclean
fi
}
-function xen_create_bridge_Debian() {
+function _xen_create_bridge_Debian() {
BRIDGE="xenbr0"
IFACE=`grep "dhcp" /etc/network/interfaces | head -1 | awk '{print$2}'`
- if test -z "$IFACE"
+ if [[ -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`"
+ if [[ "`grep $BRIDGE /etc/network/interfaces`" ]]
then
echo "a network bridge seems to be already setup"
return 0
$SUDO mv -f $TMPFILE /etc/network/interfaces
}
-function xen_create_bridge_Fedora() {
+function _xen_create_bridge_Fedora() {
BRIDGE="xenbr0"
- if test "`grep $BRIDGE /etc/sysconfig/network-scripts/*`"
+ if [[ "`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"
+ if [[ -z "$IFACE" ]]
then
return 1
fi
$SUDO service network start
}
-function xen_update_bootloader_Debian() {
+function _xen_update_bootloader_Debian() {
$SUDO update-grub
}
-function xen_update_bootloader_Fedora() {
+function _xen_update_bootloader_Fedora() {
$SUDO grub2-mkconfig -o /boot/grub2/grub.cfg
}
function xen_configure() {
- xen_create_bridge_$DISTRO
+ _xen_create_bridge_$DISTRO
start_initscripts xencommons xendomains xen-watchdog
- xen_update_bootloader_$DISTRO
+ _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`"
+ if [[ "`grep -rIi xen /boot/grub* | head -1`" ]]
then
xen_update_bootloader_$DISTRO
fi
-#!/bin/sh
+#!/usr/bin/env bash
-if test $# -lt 3; then
+if [[ $# -lt 3 ]]
+then
echo "Usage: $0 <tree> <tag> <dir>"
exit 1
fi
set -e
-if test \! -d $DIR-remote; then
+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 test "$TAG" ; then
+ if [[ "$TAG" ]]
+ then
cd $DIR-remote.tmp
$GIT branch -D dummy >/dev/null 2>&1 ||:
$GIT checkout -b dummy $TAG
set -e
-if test -z "$1"
+if [[ -z "$1" ]]
then
echo "usage: $0 package_name"
exit 1
cp -a "$INST_DIR" deb
# Debian doesn't use /usr/lib64 for 64-bit libraries
-if test -d deb/usr/lib64 ; then
+if [[ -d deb/usr/lib64 ]]
+then
cp -a deb/usr/lib64/* deb/usr/lib/
rm -rf deb/usr/lib64
fi
set -e
-if test -z "$1"
+if [[ -z "$1" ]]
then
echo "usage: $0 package_name"
exit 1
INST=0
export NO_DEPS=0
export VERBOSE=0
-while test $# -ge 1
+while [[ $# -ge 1 ]]
do
- if test "$1" = "-n" || test "$1" = "--no-deps"
+ if [[ "$1" = "-n" || "$1" = "--no-deps" ]]
then
NO_DEPS=1
shift 1
- elif test "$1" = "-v" || test "$1" = "--verbose"
+ elif [[ "$1" = "-v" || "$1" = "--verbose" ]]
then
VERBOSE=1
shift 1
- elif test "$1" = "-i" || test "$1" = "--install"
+ elif [[ "$1" = "-i" || "$1" = "--install" ]]
then
INST=1
shift 1
mkdir -p "$INST_DIR" &>/dev/null
install_dependencies git
-if test $DISTRO = "Fedora"
+if [[ $DISTRO = "Fedora" ]]
then
install_dependencies rpm-build
fi
build_package xen-system
-if test -z "$INST" || test "$INST" -eq 0
+if [[ -z "$INST" || "$INST" -eq 0 ]]
then
exit 0
fi