Introduce an error_echo function that prints to stderr.
Call error_echo or verbose_echo, instead of echo, when possible and
appropriate.
Redirect build and tests output to /dev/null unless VERBOSE==1.
Redirect apt-get and yum output to /dev/null.
Fix echo arguments in check-package-deb.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
Changes in v2:
- use "$@" instead of $* in error_echo and verbose_echo
if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]]
then
- echo grub is only supported on x86_32 and x86_64
+ verbose_echo grub is only supported on x86_32 and x86_64
return
fi
- echo Checking Grub dependencies
+ verbose_echo Checking Grub dependencies
eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
}
local DEP_CentOS_x86_32="$DEP_Fedora_x86_32"
local DEP_CentOS_x86_64="$DEP_Fedora_x86_64"
- echo Checking Libvirt dependencies
+ verbose_echo Checking Libvirt dependencies
eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
}
cp daemon/libvirtd.init "$INST_DIR"/etc/rc.d/init.d/libvirtd
chmod +x "$INST_DIR"/etc/rc.d/init.d/libvirtd
else
- echo "I don't know how write an init script for Libvirt on $DISTRO"
+ error_echo "I don't know how write an init script for Libvirt on $DISTRO"
fi
cd ..
}
local DEP_CentOS_x86_32="$DEP_Fedora_x86_32"
local DEP_CentOS_x86_64="$DEP_Fedora_x86_64"
- echo Checking Linux dependencies
+ verbose_echo Checking Linux dependencies
eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
}
if [[ $RAISIN_ARCH != "x86_64" ]]
then
- echo ovmf is only supported on x86_64
+ verbose_echo ovmf is only supported on x86_64
return
fi
- echo Checking OVMF dependencies
+ verbose_echo Checking OVMF dependencies
eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
}
function ovmf_build() {
if [[ $RAISIN_ARCH != "x86_64" ]]
then
- echo ovmf is only supported on x86_64
+ verbose_echo ovmf is only supported on x86_64
return
fi
local DEP_Fedora_x86_32="$DEP_Fedora_common"
local DEP_Fedora_x86_64="$DEP_Fedora_common"
- echo Checking QEMU dependencies
+ verbose_echo Checking QEMU dependencies
eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
}
local DEP_Fedora_x86_32="$DEP_Fedora_common"
local DEP_Fedora_x86_64="$DEP_Fedora_common"
- echo Checking QEMU dependencies
+ verbose_echo Checking QEMU dependencies
eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
}
if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]]
then
- echo seabios is only supported on x86_32 and x86_64
+ verbose_echo seabios is only supported on x86_32 and x86_64
return
fi
- echo Checking SeaBIOS dependencies
+ verbose_echo Checking SeaBIOS dependencies
eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
}
function seabios_build() {
if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]]
then
- echo seabios is only supported on x86_32 and x86_64
+ verbose_echo seabios is only supported on x86_32 and x86_64
return
fi
local DEP_CentOS_x86_32="$DEP_CentOS_common dev86 texinfo iasl"
local DEP_CentOS_x86_64="$DEP_CentOS_x86_32 glibc-devel.i686"
- echo Checking Xen dependencies
+ verbose_echo Checking Xen dependencies
eval check-package \$DEP_"$DISTRO"_"$RAISIN_ARCH"
}
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)"
+ error_echo "Please refer to the following page to setup networking:"
+ error_echo "http://wiki.xenproject.org/wiki/Network_Configuration_Examples_(Xen_4.1%2B)"
return 1
fi
if [[ "`grep $BRIDGE /etc/network/interfaces`" ]]
then
- echo "a network bridge seems to be already setup"
+ verbose_echo "a network bridge seems to be already setup"
return 0
fi
if [[ -n "${missing[@]}" ]]
then
- echo "Missing packages: ${missing[@]}"
+ echo "$PREPEND Missing packages: ${missing[@]}"
if [[ "$YES" = "n" ]]
then
return
elif [[ "$YES" != "y" ]]
then
- echo "Do you want Raisin to automatically install them for you? (y/n)"
+ echo "$PREPEND 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"
+ echo "$PREPEND Please install, or run ./raise install-builddep"
exit 1
elif [[ "$answer" = "y" ]]
then
break
else
- echo "Reply y or n"
+ echo "$PREPEND Reply y or n"
fi
done
fi
- echo "Installing..."
+ echo "$PREPEND Installing..."
install-package "${missing[@]}"
fi
}
# need single braces for filename matching expansion
if [ ! -f xen-sytem*rpm ] && [ ! -f xen-system*deb ]
then
- echo You need to raise build first.
+ error_echo You need to raise build first.
exit 1
fi
install_package xen-system
return
elif [[ "$YES" != "y" ]]
then
- echo "Proceeding we'll make changes to the running system,"
- echo "are you sure that you want to continue? (y/n)"
+ echo "$PREPEND Proceeding we'll make changes to the running system,"
+ echo "$PREPEND are you sure that you want to continue? (y/n)"
while read answer
do
if [[ "$answer" = "n" ]]
then
break
else
- echo "Reply y or n"
+ echo "$PREPEND Reply y or n"
fi
done
fi
function verbose_echo() {
if [[ $VERBOSE -eq 1 ]]
then
- echo $*
+ echo "$PREPEND" "$@"
fi
}
+function error_echo() {
+ echo "$PREPEND" "$@" >&2
+}
+
# Executed once at the beginning of the script
function common_init() {
export BASEDIR=`pwd`
export RAISIN_MAKE=${MAKE-make}
export PREFIX=${PREFIX-/usr}
export INST_DIR=${DESTDIR-dist}
+ export PREPEND="[raisin]"
INST_DIR=`readlink -f $INST_DIR`
export SUDO=""
elif [[ ! -f `which sudo 2>/dev/null` ]]
then
- echo "Raisin requires sudo to install build dependencies for you."
- echo "You can only build without it."
+ error_echo "Raisin requires sudo to install build dependencies for you."
+ error_echo "You can only build without it."
export SUDO=""
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."
+ error_echo "Raisin requires BASH 3.2 or newer."
exit 1
fi
}
function _check-package-deb() {
- verbose_echo "Checking for package ${args[0]}"
+ verbose_echo "Checking for package $1"
if dpkg -s "$1" 2>/dev/null | grep -q "Status:.*installed"
then
}
function _install-package-deb() {
- $SUDO apt-get install -y $*
+ $SUDO apt-get install -y $* > /dev/null
}
function _check-package-rpm() {
}
function _install-package-rpm() {
- $SUDO yum install -y $*
+ $SUDO yum install -y $* > /dev/null
}
# Modifies inherited variable "missing"
do
case $DISTRO in
"Debian" )
- $SUDO update-rc.d $1 defaults || echo "Couldn't set $1 to start"
+ $SUDO update-rc.d $1 defaults || error_echo "Couldn't set $1 to start"
;;
"Fedora" )
- $SUDO chkconfig --add $1 || echo "Couldn't set $1 to start"
+ $SUDO chkconfig --add $1 || error_echo "Couldn't set $1 to start"
;;
* )
- echo "I don't know how to start initscripts on $DISTRO"
+ error_echo "I don't know how to start initscripts on $DISTRO"
return 1
;;
esac
do
case $DISTRO in
"Debian" )
- $SUDO update-rc.d $1 remove || echo "Couldn't remove $1 from init"
+ $SUDO update-rc.d $1 remove || error_echo "Couldn't remove $1 from init"
;;
"Fedora" )
- $SUDO chkconfig --del $1 || echo "Couldn't remove $1 from init"
+ $SUDO chkconfig --del $1 || error_echo "Couldn't remove $1 from init"
;;
* )
- echo "I don't know how to start initscripts on $DISTRO"
+ error_echo "I don't know how to start initscripts on $DISTRO"
return 1
;;
esac
continue
fi
- verbose_echo calling "$component"_"$1"
- "$component"_"$1"
- verbose_echo "$component"_"$1" done
+ echo "$PREPEND" calling "$component"_"$1"
+ if [[ $VERBOSE -eq 0 ]]
+ then
+ "$component"_"$1" &> /dev/null
+ else
+ "$component"_"$1"
+ fi
+ echo "$PREPEND" "$component"_"$1" done
done
}
local t
local enabled
local found
+ local ret
for t in `cat "$BASEDIR"/tests/series`
do
fi
source "$BASEDIR"/tests/$t
+ ret=0
+ if [[ $VERBOSE -eq 0 ]]
+ then
+ echo -n "$PREPEND test $t: "
+ "$t"-test &>/dev/null || ret=1
+ if [[ $ret -eq 0 ]]
+ then
+ echo "success"
+ else
+ echo "fail"
+ fi
+ else
+ "$t"-test || ret=1
+ if [[ $ret -eq 0 ]]
+ then
+ echo "$PREPEND test $t: success"
+ else
+ echo "$PREPEND test $t: fail"
+ fi
+ fi
+ "$t"-cleanup
- verbose_echo running test "$t"
- "$t"_test
- "$t"_cleanup
- verbose_echo "test "$t" done"
done
}
then
check-package busybox grub2 which
else
- echo "I don't know distro $DISTRO. It might be missing packages."
+ error_echo "I don't know distro $DISTRO. It might be missing packages."
fi
if [[ -n "${missing[@]}" ]]
then
$SUDO rpm -i --force "$1"-`git show --oneline | head -1 | cut -d " " -f 1`-0.$RAISIN_ARCH.rpm
else
- echo "Don't know how to install packages on $DISTRO"
+ error_echo "Don't know how to install packages on $DISTRO"
fi
}
then
$SUDO rpm -e "$1"
else
- echo "Don't know how to uninstall packages on $DISTRO"
+ error_echo "Don't know how to uninstall packages on $DISTRO"
fi
}
--grub-mkdevicemap=$tmpdir/boot/grub/device.map \
--root-directory=$tmpdir $dev
else
- echo "I don't know how to install grub on $DISTRO"
+ echo "$PREPEND I don't know how to install grub on $DISTRO"
fi
$SUDO umount $tmpdir
i=$((i+1))
if [[ $i -gt 60 ]]
then
- echo Timeout connecting to guest
+ echo $PREPEND Timeout connecting to guest
return 1
fi
done
then
echo "/boot/initramfs-`uname -r`".img
else
- echo "I don't know how to find the initrd" >&2
+ echo "$PREPEND I don't know how to find the initrd" >&2
exit 1
fi
}
function busybox-hvm-test() {
if [[ $RAISIN_ARCH != "x86_64" && $RAISIN_ARCH != "x86_32" ]]
then
- echo busybox hvm test only valid on x86
+ echo $PREPEND busybox hvm test only valid on x86
exit 0
fi