Fix shellcheck warnings in install.sh and upgrade.sh

Change-Id: Ica0c09c8bc7c154b6a5bbdeb6473900ab8da2553
This commit is contained in:
Vitalii Kovalchuk 2016-08-03 16:09:55 +03:00 committed by Illia Polliul
parent eabaf2635f
commit 023d727fed
2 changed files with 43 additions and 42 deletions

View File

@ -28,9 +28,9 @@ set -ex
PLUGIN_PATH="/var/www/nailgun/plugins/contrail-4.0"
#Now uses the latest package file
UBUNTU_PKG=`find $PLUGIN_PATH -maxdepth 1 -name 'contrail-install-packages*.deb' -exec stat -c "%y %n" {} + | sort -r | head -n 1 | cut -d' ' -f 4`
CENTOS_PKG=`find $PLUGIN_PATH -maxdepth 1 -name 'contrail-install-packages*.rpm' -exec stat -c "%y %n" {} + | sort -r | head -n 1 | cut -d' ' -f 4`
VMWARE_PKG=`find $PLUGIN_PATH -maxdepth 1 -name 'contrail-install-vcenter-plugin*.deb' -exec stat -c "%y %n" {} + | sort -r | head -n 1 | cut -d' ' -f 4`
UBUNTU_PKG=$(find $PLUGIN_PATH -maxdepth 1 -name 'contrail-install-packages*.deb' -exec stat -c "%y %n" {} + | sort -r | head -n 1 | cut -d' ' -f 4)
CENTOS_PKG=$(find $PLUGIN_PATH -maxdepth 1 -name 'contrail-install-packages*.rpm' -exec stat -c "%y %n" {} + | sort -r | head -n 1 | cut -d' ' -f 4)
VMWARE_PKG=$(find $PLUGIN_PATH -maxdepth 1 -name 'contrail-install-vcenter-plugin*.deb' -exec stat -c "%y %n" {} + | sort -r | head -n 1 | cut -d' ' -f 4)
yum -y install dpkg dpkg-dev createrepo
@ -45,38 +45,38 @@ fi
if [ -f "$UBUNTU_PKG" ];
then
DEB=`mktemp -d`
dpkg -x $UBUNTU_PKG $DEB
DEB=$(mktemp -d)
dpkg -x "$UBUNTU_PKG" "$DEB"
cd $PLUGIN_PATH/repositories/ubuntu/
find . -type f -name "*.deb" -delete
tar -xzvf $DEB/opt/contrail/contrail_packages/contrail_debs.tgz -C $PLUGIN_PATH/repositories/ubuntu/
tar -xzvf "$DEB"/opt/contrail/contrail_packages/contrail_debs.tgz -C "$PLUGIN_PATH"/repositories/ubuntu/
if [ -f "$VMWARE_PKG" ];
then
cp $VMWARE_PKG $PLUGIN_PATH/repositories/ubuntu/
DEB2=`mktemp -d`
dpkg -x $VMWARE_PKG $DEB2
cp $DEB2/opt/contrail/contrail_vcenter_plugin_install_repo/*.deb $PLUGIN_PATH/repositories/ubuntu/
cp "$VMWARE_PKG" "$PLUGIN_PATH"/repositories/ubuntu/
DEB2=$(mktemp -d)
dpkg -x "$VMWARE_PKG" "$DEB2"
cp "$DEB2"/opt/contrail/contrail_vcenter_plugin_install_repo/*.deb "$PLUGIN_PATH"/repositories/ubuntu/
fi
DPDK_PKG=`find $PLUGIN_PATH -maxdepth 4 -name 'dpdk-depends-packages*.deb' -exec stat -c "%y %n" {} + | sort -r | head -n 1 | cut -d' ' -f 4`
DPDK_PKG=$(find $PLUGIN_PATH -maxdepth 4 -name 'dpdk-depends-packages*.deb' -exec stat -c "%y %n" {} + | sort -r | head -n 1 | cut -d' ' -f 4)
if [ -f "$DPDK_PKG" ];
then
DEB3=`mktemp -d`
cp $DPDK_PKG $DEB3
cd $DEB3 && ar vx dpdk-depends-packages*.deb && tar xf data.tar.xz && cp $DEB3/opt/contrail/contrail_install_repo_dpdk/contrail-dpdk-kernel-modules-dkms*.deb $PLUGIN_PATH/repositories/ubuntu/
DEB3=$(mktemp -d)
cp "$DPDK_PKG" "$DEB3"
cd "$DEB3" && ar vx dpdk-depends-packages*.deb && tar xf data.tar.xz && cp "$DEB3"/opt/contrail/contrail_install_repo_dpdk/contrail-dpdk-kernel-modules-dkms*.deb "$PLUGIN_PATH"/repositories/ubuntu/
fi
cd $PLUGIN_PATH/repositories/ubuntu/
cd "$PLUGIN_PATH"/repositories/ubuntu/
dpkg-scanpackages ./ | gzip -c - > Packages.gz
fi
if [ -f "$CENTOS_PKG" ];
then
RPM=`mktemp -d`
cd $RPM
rpm2cpio $CENTOS_PKG | cpio -id
mkdir -p $PLUGIN_PATH/repositories/centos/Packages
cd $PLUGIN_PATH/repositories/centos/
RPM=$(mktemp -d)
cd "$RPM"
rpm2cpio "$CENTOS_PKG" | cpio -id
mkdir -p "$PLUGIN_PATH"/repositories/centos/Packages
cd "$PLUGIN_PATH"/repositories/centos/
find Packages -type f -name "*.rpm" -delete
tar -xzvf $RPM/opt/contrail/contrail_packages/contrail_rpms.tgz -C $PLUGIN_PATH/repositories/centos/Packages/
tar -xzvf "$RPM"/opt/contrail/contrail_packages/contrail_rpms.tgz -C "$PLUGIN_PATH"/repositories/centos/Packages/
createrepo .
fi

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Copyright 2016 Mirantis, Inc.
#
@ -35,15 +35,16 @@
# Returns a list of nodes with role defined in argument, which are in 'ready' state,
# or a list of all ready nodes if no argument supplied
get_nodes_list () {
local _role=$1
local _role
_role=$1
if [ -z "$_role" ]; then
local _nodes=$(fuel node 2>/dev/null | grep 'ready' | cut -d "|" -f 1,7 | awk '{printf $1 ","}' | sed -e 's|,$||')
_nodes=$(fuel node 2>/dev/null | grep 'ready' | cut -d "|" -f 1,7 | awk '{printf $1 ","}' | sed -e 's|,$||')
elif [ "$_role" == "compute" ]; then
local _nodes=$(fuel node 2>/dev/null | grep 'ready' | cut -d "|" -f 1,7 | grep $_role | grep -v vmware | awk '{printf $1 ","}' | sed -e 's|,$||')
_nodes=$(fuel node 2>/dev/null | grep 'ready' | cut -d "|" -f 1,7 | grep "$_role" | grep -v vmware | awk '{printf $1 ","}' | sed -e 's|,$||')
else
local _nodes=$(fuel node 2>/dev/null | grep 'ready' | cut -d "|" -f 1,7 | grep $_role | awk '{printf $1 ","}' | sed -e 's|,$||')
_nodes=$(fuel node 2>/dev/null | grep 'ready' | cut -d "|" -f 1,7 | grep "$_role" | awk '{printf $1 ","}' | sed -e 's|,$||')
fi
echo $_nodes
echo "$_nodes"
}
# Run the task on particular node
@ -51,7 +52,7 @@ start_task_on_node () {
local _nodes=$1
local _tasks=$2
fuel node --node-id $_nodes --task $_tasks 2>/dev/null
fuel node --node-id "$_nodes" --task "$_tasks" 2>/dev/null
}
# Wait for task to complete or fail
@ -86,7 +87,7 @@ fuel plugins --sync 2>/dev/null
# Rsync the plugins manifests
nodes=$(get_nodes_list)
start_task_on_node $nodes rsync_core_puppet
start_task_on_node "$nodes" rsync_core_puppet
wait_for_tasks
# Run the upgrade tasks
@ -95,41 +96,41 @@ controllers*)
# Start the pre-upgrade tasks on contrail nodes
nodes=$(get_nodes_list contrail)
start_task_on_node $nodes upgrade-contrail-pre
start_task_on_node "$nodes" upgrade-contrail-pre
wait_for_tasks
# Stop the contrail config services
nodes=$(get_nodes_list contrail-config)
start_task_on_node $nodes upgrade-contrail-stop-config
start_task_on_node "$nodes" upgrade-contrail-stop-config
wait_for_tasks
# Stop the contrail collector services
nodes=$(get_nodes_list contrail-analytics)
if [ -n "$nodes" ]; then
start_task_on_node $nodes upgrade-contrail-stop-analytics
start_task_on_node "$nodes" upgrade-contrail-stop-analytics
else
nodes_cfg=$(get_nodes_list contrail-config)
start_task_on_node $nodes_cfg upgrade-contrail-stop-analytics
start_task_on_node "$nodes_cfg" upgrade-contrail-stop-analytics
fi
wait_for_tasks
# Start the upgrade tasks on database nodes
nodes=$(get_nodes_list contrail-db)
start_task_on_node $nodes upgrade-contrail-db
start_task_on_node "$nodes" upgrade-contrail-db
wait_for_tasks
# Start the upgrade tasks on config nodes
nodes=$(get_nodes_list contrail-config)
start_task_on_node $nodes upgrade-contrail-config
start_task_on_node "$nodes" upgrade-contrail-config
wait_for_tasks
# Start the upgrade tasks on collector nodes
nodes=$(get_nodes_list contrail-analytics)
if [ -n "$nodes" ]; then
start_task_on_node $nodes upgrade-contrail-analytics
start_task_on_node "$nodes" upgrade-contrail-analytics
else
nodes_cfg=$(get_nodes_list contrail-config)
start_task_on_node $nodes_cfg upgrade-contrail-analytics
start_task_on_node "$nodes_cfg" upgrade-contrail-analytics
fi
wait_for_tasks
@ -137,18 +138,18 @@ controllers*)
nodes=$(get_nodes_list contrail-control)
for node in ${nodes//,/ }
do
start_task_on_node $node upgrade-contrail-control
start_task_on_node "$node" upgrade-contrail-control
wait_for_tasks
done
# Start the post-upgrade tasks on contrail nodes
nodes=$(get_nodes_list contrail)
start_task_on_node $nodes upgrade-contrail-post
start_task_on_node "$nodes" upgrade-contrail-post
wait_for_tasks
# Start the upgrade tasks on config nodes
nodes=$(get_nodes_list controller)
start_task_on_node $nodes upgrade-contrail-controller
start_task_on_node "$nodes" upgrade-contrail-controller
wait_for_tasks
;;
@ -156,14 +157,14 @@ computes*)
# Start the repo tasks on compute nodes
nodes=$(get_nodes_list compute)
start_task_on_node $nodes contrail-repository
start_task_on_node "$nodes" contrail-repository
wait_for_tasks
# Start the upgrade tasks on compute nodes, one by one
nodes=$(get_nodes_list compute)
for node in ${nodes//,/ }
do
start_task_on_node $node upgrade-contrail-compute
start_task_on_node "$node" upgrade-contrail-compute
wait_for_tasks
done
;;