Add is_ubuntu function
This replaces all of the [[ "$os_PACKAGE" = "deb" ]] tests, except when
those tests are before straight calls to dpkg.
Change-Id: I8a3ebf1b1bc5a55d736f9258d5ba1d24dabf04ea
diff --git a/functions b/functions
index 794e474..0911557 100644
--- a/functions
+++ b/functions
@@ -341,6 +341,19 @@
}
+# Determine if current distribution is an Ubuntu-based distribution.
+# It will also detect non-Ubuntu but Debian-based distros; this is not an issue
+# since Debian and Ubuntu should be compatible.
+# is_ubuntu
+function is_ubuntu {
+ if [[ -z "$os_PACKAGE" ]]; then
+ GetOSVersion
+ fi
+
+ [ "$os_PACKAGE" = "deb" ]
+}
+
+
# Determine if current distribution is a SUSE-based distribution
# (openSUSE, SLE).
# is_suse
@@ -580,11 +593,7 @@
# Distro-agnostic package installer
# install_package package [package ...]
function install_package() {
- if [[ -z "$os_PACKAGE" ]]; then
- GetOSVersion
- fi
-
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
[[ "$NO_UPDATE_REPOS" = "True" ]] || apt_get update
NO_UPDATE_REPOS=True
@@ -609,6 +618,7 @@
if [[ -z "$os_PACKAGE" ]]; then
GetOSVersion
fi
+
if [[ "$os_PACKAGE" = "deb" ]]; then
dpkg -l "$@" > /dev/null
return $?
@@ -661,10 +671,7 @@
# Service wrapper to restart services
# restart_service service-name
function restart_service() {
- if [[ -z "$os_PACKAGE" ]]; then
- GetOSVersion
- fi
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
sudo /usr/sbin/service $1 restart
else
sudo /sbin/service $1 restart
@@ -746,10 +753,7 @@
# Service wrapper to start services
# start_service service-name
function start_service() {
- if [[ -z "$os_PACKAGE" ]]; then
- GetOSVersion
- fi
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
sudo /usr/sbin/service $1 start
else
sudo /sbin/service $1 start
@@ -760,10 +764,7 @@
# Service wrapper to stop services
# stop_service service-name
function stop_service() {
- if [[ -z "$os_PACKAGE" ]]; then
- GetOSVersion
- fi
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
sudo /usr/sbin/service $1 stop
else
sudo /sbin/service $1 stop
@@ -1031,11 +1032,7 @@
function get_rootwrap_location() {
local module=$1
- if [[ -z "$os_PACKAGE" ]]; then
- GetOSVersion
- fi
-
- if [[ "$os_PACKAGE" = "deb" ]] || is_suse; then
+ if is_ubuntu || is_suse; then
echo "/usr/local/bin/$module-rootwrap"
else
echo "/usr/bin/$module-rootwrap"
@@ -1045,11 +1042,7 @@
# Get the path to the pip command.
# get_pip_command
function get_pip_command() {
- if [[ -z "$os_PACKAGE" ]]; then
- GetOSVersion
- fi
-
- if [[ "$os_PACKAGE" = "deb" ]] || is_suse; then
+ if is_ubuntu || is_suse; then
echo "/usr/bin/pip"
else
echo "/usr/bin/pip-python"
diff --git a/lib/cinder b/lib/cinder
index 1aa34cd..ce160bf 100644
--- a/lib/cinder
+++ b/lib/cinder
@@ -237,7 +237,7 @@
# start_cinder() - Start running processes, including screen
function start_cinder() {
if is_service_enabled c-vol; then
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
_configure_tgt_for_config_d
if [[ ! -f /etc/tgt/conf.d/cinder.conf ]]; then
echo "include $CINDER_STATE_PATH/volumes/*" | sudo tee /etc/tgt/conf.d/cinder.conf
diff --git a/lib/databases/mysql b/lib/databases/mysql
index eb84f2c..60ea143 100644
--- a/lib/databases/mysql
+++ b/lib/databases/mysql
@@ -20,7 +20,7 @@
function configure_database_mysql {
echo_summary "Configuring and starting MySQL"
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
MY_CONF=/etc/mysql/my.cnf
MYSQL=mysql
else
@@ -61,7 +61,7 @@
}
function install_database_mysql {
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
# Seed configuration with mysql password so that apt-get install doesn't
# prompt us for a password upon install.
cat <<MYSQL_PRESEED | sudo debconf-set-selections
diff --git a/lib/horizon b/lib/horizon
index 189ca10..d0a0f05 100644
--- a/lib/horizon
+++ b/lib/horizon
@@ -71,7 +71,7 @@
sudo mkdir -p $HORIZON_DIR/.blackhole
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
APACHE_NAME=apache2
APACHE_CONF=sites-available/horizon
# Clean up the old config name
@@ -110,7 +110,7 @@
# install_horizon() - Collect source and prepare
function install_horizon() {
# Apache installation, because we mark it NOPRIME
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
# Install apache2, which is NOPRIME'd
install_package apache2 libapache2-mod-wsgi
elif is_suse; then
@@ -121,7 +121,7 @@
fi
# NOTE(sdague) quantal changed the name of the node binary
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
if [[ ! -e "/usr/bin/node" ]]; then
install_package nodejs-legacy
fi
diff --git a/lib/nova b/lib/nova
index 6445a07..970806d 100644
--- a/lib/nova
+++ b/lib/nova
@@ -202,7 +202,7 @@
# splitting a system into many smaller parts. LXC uses cgroups and chroot
# to simulate multiple systems.
if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
if [[ ! "$DISTRO" > natty ]]; then
cgline="none /cgroup cgroup cpuacct,memory,devices,cpu,freezer,blkio 0 0"
sudo mkdir -p /cgroup
@@ -228,7 +228,7 @@
EOF
fi
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
LIBVIRT_DAEMON=libvirt-bin
else
# http://wiki.libvirt.org/page/SSHPolicyKitSetup
@@ -393,7 +393,7 @@
# install_nova() - Collect source and prepare
function install_nova() {
if is_service_enabled n-cpu; then
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
LIBVIRT_PKG_NAME=libvirt-bin
else
LIBVIRT_PKG_NAME=libvirt
@@ -403,7 +403,7 @@
# splitting a system into many smaller parts. LXC uses cgroups and chroot
# to simulate multiple systems.
if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
if [[ "$DISTRO" > natty ]]; then
install_package cgroup-lite
fi
diff --git a/lib/swift b/lib/swift
index 366c467..140e5e9 100644
--- a/lib/swift
+++ b/lib/swift
@@ -159,7 +159,7 @@
s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
" $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
# rsyncd.conf just prepared for 4 nodes
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
else
sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
@@ -341,7 +341,7 @@
# (re)start rsyslog
restart_service rsyslog
# Start rsync
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
sudo /etc/init.d/rsync restart || :
else
sudo systemctl start xinetd.service
diff --git a/stack.sh b/stack.sh
index 55eafa8..9428356 100755
--- a/stack.sh
+++ b/stack.sh
@@ -677,7 +677,7 @@
# Install package requirements
echo_summary "Installing package prerequisites"
-if [[ "$os_PACKAGE" = "deb" ]]; then
+if is_ubuntu; then
install_package $(get_packages $FILES/apts)
elif is_suse; then
install_package $(get_packages $FILES/rpms-suse)
@@ -726,7 +726,7 @@
if is_quantum_ovs_base_plugin "$Q_PLUGIN"; then
# Install deps
# FIXME add to ``files/apts/quantum``, but don't install if not needed!
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
kernel_version=`cat /proc/version | cut -d " " -f3`
install_package make fakeroot dkms openvswitch-switch openvswitch-datapath-dkms linux-headers-$kernel_version
else
diff --git a/tools/info.sh b/tools/info.sh
index a872d59..583a994 100755
--- a/tools/info.sh
+++ b/tools/info.sh
@@ -88,7 +88,7 @@
# - We are going to check packages only for the services needed.
# - We are parsing the packages files and detecting metadatas.
-if [[ "$os_PACKAGE" = "deb" ]]; then
+if is_ubuntu; then
PKG_DIR=$FILES/apts
else
PKG_DIR=$FILES/rpms
diff --git a/unstack.sh b/unstack.sh
index 20ba17b..81ce088 100755
--- a/unstack.sh
+++ b/unstack.sh
@@ -65,7 +65,7 @@
# If tgt driver isn't running this won't work obviously
# So check the response and restart if need be
echo "tgtd seems to be in a bad state, restarting..."
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
restart_service tgt
else
restart_service tgtd
@@ -85,7 +85,7 @@
sudo rm -rf $CINDER_STATE_PATH/volumes/*
fi
- if [[ "$os_PACKAGE" = "deb" ]]; then
+ if is_ubuntu; then
stop_service tgt
else
stop_service tgtd