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
This commit is contained in:
Vincent Untz 2012-12-04 12:36:34 +01:00
parent 1cd8a4725b
commit c18b965152
9 changed files with 37 additions and 44 deletions

View File

@ -341,6 +341,19 @@ function GetDistro() {
} }
# 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 # Determine if current distribution is a SUSE-based distribution
# (openSUSE, SLE). # (openSUSE, SLE).
# is_suse # is_suse
@ -580,11 +593,7 @@ function disable_negated_services() {
# Distro-agnostic package installer # Distro-agnostic package installer
# install_package package [package ...] # install_package package [package ...]
function install_package() { function install_package() {
if [[ -z "$os_PACKAGE" ]]; then if is_ubuntu; then
GetOSVersion
fi
if [[ "$os_PACKAGE" = "deb" ]]; then
[[ "$NO_UPDATE_REPOS" = "True" ]] || apt_get update [[ "$NO_UPDATE_REPOS" = "True" ]] || apt_get update
NO_UPDATE_REPOS=True NO_UPDATE_REPOS=True
@ -609,6 +618,7 @@ function is_package_installed() {
if [[ -z "$os_PACKAGE" ]]; then if [[ -z "$os_PACKAGE" ]]; then
GetOSVersion GetOSVersion
fi fi
if [[ "$os_PACKAGE" = "deb" ]]; then if [[ "$os_PACKAGE" = "deb" ]]; then
dpkg -l "$@" > /dev/null dpkg -l "$@" > /dev/null
return $? return $?
@ -661,10 +671,7 @@ function pip_install {
# Service wrapper to restart services # Service wrapper to restart services
# restart_service service-name # restart_service service-name
function restart_service() { function restart_service() {
if [[ -z "$os_PACKAGE" ]]; then if is_ubuntu; then
GetOSVersion
fi
if [[ "$os_PACKAGE" = "deb" ]]; then
sudo /usr/sbin/service $1 restart sudo /usr/sbin/service $1 restart
else else
sudo /sbin/service $1 restart sudo /sbin/service $1 restart
@ -746,10 +753,7 @@ function setup_develop() {
# Service wrapper to start services # Service wrapper to start services
# start_service service-name # start_service service-name
function start_service() { function start_service() {
if [[ -z "$os_PACKAGE" ]]; then if is_ubuntu; then
GetOSVersion
fi
if [[ "$os_PACKAGE" = "deb" ]]; then
sudo /usr/sbin/service $1 start sudo /usr/sbin/service $1 start
else else
sudo /sbin/service $1 start sudo /sbin/service $1 start
@ -760,10 +764,7 @@ function start_service() {
# Service wrapper to stop services # Service wrapper to stop services
# stop_service service-name # stop_service service-name
function stop_service() { function stop_service() {
if [[ -z "$os_PACKAGE" ]]; then if is_ubuntu; then
GetOSVersion
fi
if [[ "$os_PACKAGE" = "deb" ]]; then
sudo /usr/sbin/service $1 stop sudo /usr/sbin/service $1 stop
else else
sudo /sbin/service $1 stop sudo /sbin/service $1 stop
@ -1031,11 +1032,7 @@ function add_user_to_group() {
function get_rootwrap_location() { function get_rootwrap_location() {
local module=$1 local module=$1
if [[ -z "$os_PACKAGE" ]]; then if is_ubuntu || is_suse; then
GetOSVersion
fi
if [[ "$os_PACKAGE" = "deb" ]] || is_suse; then
echo "/usr/local/bin/$module-rootwrap" echo "/usr/local/bin/$module-rootwrap"
else else
echo "/usr/bin/$module-rootwrap" echo "/usr/bin/$module-rootwrap"
@ -1045,11 +1042,7 @@ function get_rootwrap_location() {
# Get the path to the pip command. # Get the path to the pip command.
# get_pip_command # get_pip_command
function get_pip_command() { function get_pip_command() {
if [[ -z "$os_PACKAGE" ]]; then if is_ubuntu || is_suse; then
GetOSVersion
fi
if [[ "$os_PACKAGE" = "deb" ]] || is_suse; then
echo "/usr/bin/pip" echo "/usr/bin/pip"
else else
echo "/usr/bin/pip-python" echo "/usr/bin/pip-python"

View File

@ -237,7 +237,7 @@ function _configure_tgt_for_config_d() {
# start_cinder() - Start running processes, including screen # start_cinder() - Start running processes, including screen
function start_cinder() { function start_cinder() {
if is_service_enabled c-vol; then if is_service_enabled c-vol; then
if [[ "$os_PACKAGE" = "deb" ]]; then if is_ubuntu; then
_configure_tgt_for_config_d _configure_tgt_for_config_d
if [[ ! -f /etc/tgt/conf.d/cinder.conf ]]; then if [[ ! -f /etc/tgt/conf.d/cinder.conf ]]; then
echo "include $CINDER_STATE_PATH/volumes/*" | sudo tee /etc/tgt/conf.d/cinder.conf echo "include $CINDER_STATE_PATH/volumes/*" | sudo tee /etc/tgt/conf.d/cinder.conf

View File

@ -20,7 +20,7 @@ function recreate_database_mysql {
function configure_database_mysql { function configure_database_mysql {
echo_summary "Configuring and starting MySQL" echo_summary "Configuring and starting MySQL"
if [[ "$os_PACKAGE" = "deb" ]]; then if is_ubuntu; then
MY_CONF=/etc/mysql/my.cnf MY_CONF=/etc/mysql/my.cnf
MYSQL=mysql MYSQL=mysql
else else
@ -61,7 +61,7 @@ default-storage-engine = InnoDB" $MY_CONF
} }
function install_database_mysql { 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 # Seed configuration with mysql password so that apt-get install doesn't
# prompt us for a password upon install. # prompt us for a password upon install.
cat <<MYSQL_PRESEED | sudo debconf-set-selections cat <<MYSQL_PRESEED | sudo debconf-set-selections

View File

@ -71,7 +71,7 @@ function init_horizon() {
sudo mkdir -p $HORIZON_DIR/.blackhole sudo mkdir -p $HORIZON_DIR/.blackhole
if [[ "$os_PACKAGE" = "deb" ]]; then if is_ubuntu; then
APACHE_NAME=apache2 APACHE_NAME=apache2
APACHE_CONF=sites-available/horizon APACHE_CONF=sites-available/horizon
# Clean up the old config name # Clean up the old config name
@ -110,7 +110,7 @@ function init_horizon() {
# install_horizon() - Collect source and prepare # install_horizon() - Collect source and prepare
function install_horizon() { function install_horizon() {
# Apache installation, because we mark it NOPRIME # Apache installation, because we mark it NOPRIME
if [[ "$os_PACKAGE" = "deb" ]]; then if is_ubuntu; then
# Install apache2, which is NOPRIME'd # Install apache2, which is NOPRIME'd
install_package apache2 libapache2-mod-wsgi install_package apache2 libapache2-mod-wsgi
elif is_suse; then elif is_suse; then
@ -121,7 +121,7 @@ function install_horizon() {
fi fi
# NOTE(sdague) quantal changed the name of the node binary # 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 if [[ ! -e "/usr/bin/node" ]]; then
install_package nodejs-legacy install_package nodejs-legacy
fi fi

View File

@ -202,7 +202,7 @@ function configure_nova() {
# splitting a system into many smaller parts. LXC uses cgroups and chroot # splitting a system into many smaller parts. LXC uses cgroups and chroot
# to simulate multiple systems. # to simulate multiple systems.
if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
if [[ "$os_PACKAGE" = "deb" ]]; then if is_ubuntu; then
if [[ ! "$DISTRO" > natty ]]; then if [[ ! "$DISTRO" > natty ]]; then
cgline="none /cgroup cgroup cpuacct,memory,devices,cpu,freezer,blkio 0 0" cgline="none /cgroup cgroup cpuacct,memory,devices,cpu,freezer,blkio 0 0"
sudo mkdir -p /cgroup sudo mkdir -p /cgroup
@ -228,7 +228,7 @@ cgroup_device_acl = [
EOF EOF
fi fi
if [[ "$os_PACKAGE" = "deb" ]]; then if is_ubuntu; then
LIBVIRT_DAEMON=libvirt-bin LIBVIRT_DAEMON=libvirt-bin
else else
# http://wiki.libvirt.org/page/SSHPolicyKitSetup # http://wiki.libvirt.org/page/SSHPolicyKitSetup
@ -393,7 +393,7 @@ function install_novaclient() {
# install_nova() - Collect source and prepare # install_nova() - Collect source and prepare
function install_nova() { function install_nova() {
if is_service_enabled n-cpu; then if is_service_enabled n-cpu; then
if [[ "$os_PACKAGE" = "deb" ]]; then if is_ubuntu; then
LIBVIRT_PKG_NAME=libvirt-bin LIBVIRT_PKG_NAME=libvirt-bin
else else
LIBVIRT_PKG_NAME=libvirt LIBVIRT_PKG_NAME=libvirt
@ -403,7 +403,7 @@ function install_nova() {
# splitting a system into many smaller parts. LXC uses cgroups and chroot # splitting a system into many smaller parts. LXC uses cgroups and chroot
# to simulate multiple systems. # to simulate multiple systems.
if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
if [[ "$os_PACKAGE" = "deb" ]]; then if is_ubuntu; then
if [[ "$DISTRO" > natty ]]; then if [[ "$DISTRO" > natty ]]; then
install_package cgroup-lite install_package cgroup-lite
fi fi

View File

@ -159,7 +159,7 @@ function configure_swift() {
s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,; s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,;
" $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf
# rsyncd.conf just prepared for 4 nodes # 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 sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync
else else
sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync
@ -341,7 +341,7 @@ function start_swift() {
# (re)start rsyslog # (re)start rsyslog
restart_service rsyslog restart_service rsyslog
# Start rsync # Start rsync
if [[ "$os_PACKAGE" = "deb" ]]; then if is_ubuntu; then
sudo /etc/init.d/rsync restart || : sudo /etc/init.d/rsync restart || :
else else
sudo systemctl start xinetd.service sudo systemctl start xinetd.service

View File

@ -677,7 +677,7 @@ set -o xtrace
# Install package requirements # Install package requirements
echo_summary "Installing package prerequisites" echo_summary "Installing package prerequisites"
if [[ "$os_PACKAGE" = "deb" ]]; then if is_ubuntu; then
install_package $(get_packages $FILES/apts) install_package $(get_packages $FILES/apts)
elif is_suse; then elif is_suse; then
install_package $(get_packages $FILES/rpms-suse) install_package $(get_packages $FILES/rpms-suse)
@ -726,7 +726,7 @@ if is_service_enabled q-agt; then
if is_quantum_ovs_base_plugin "$Q_PLUGIN"; then if is_quantum_ovs_base_plugin "$Q_PLUGIN"; then
# Install deps # Install deps
# FIXME add to ``files/apts/quantum``, but don't install if not needed! # 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` kernel_version=`cat /proc/version | cut -d " " -f3`
install_package make fakeroot dkms openvswitch-switch openvswitch-datapath-dkms linux-headers-$kernel_version install_package make fakeroot dkms openvswitch-switch openvswitch-datapath-dkms linux-headers-$kernel_version
else else

View File

@ -88,7 +88,7 @@ done
# - We are going to check packages only for the services needed. # - We are going to check packages only for the services needed.
# - We are parsing the packages files and detecting metadatas. # - We are parsing the packages files and detecting metadatas.
if [[ "$os_PACKAGE" = "deb" ]]; then if is_ubuntu; then
PKG_DIR=$FILES/apts PKG_DIR=$FILES/apts
else else
PKG_DIR=$FILES/rpms PKG_DIR=$FILES/rpms

View File

@ -65,7 +65,7 @@ if is_service_enabled cinder; then
# If tgt driver isn't running this won't work obviously # If tgt driver isn't running this won't work obviously
# So check the response and restart if need be # So check the response and restart if need be
echo "tgtd seems to be in a bad state, restarting..." echo "tgtd seems to be in a bad state, restarting..."
if [[ "$os_PACKAGE" = "deb" ]]; then if is_ubuntu; then
restart_service tgt restart_service tgt
else else
restart_service tgtd restart_service tgtd
@ -85,7 +85,7 @@ if is_service_enabled cinder; then
sudo rm -rf $CINDER_STATE_PATH/volumes/* sudo rm -rf $CINDER_STATE_PATH/volumes/*
fi fi
if [[ "$os_PACKAGE" = "deb" ]]; then if is_ubuntu; then
stop_service tgt stop_service tgt
else else
stop_service tgtd stop_service tgtd