summaryrefslogtreecommitdiffstats
path: root/mcp
diff options
context:
space:
mode:
Diffstat (limited to 'mcp')
-rwxr-xr-xmcp/patches/patch.sh5
-rwxr-xr-xmcp/scripts/create-config-drive.sh49
-rw-r--r--mcp/scripts/lib.sh28
-rwxr-xr-xmcp/scripts/salt.sh3
4 files changed, 46 insertions, 39 deletions
diff --git a/mcp/patches/patch.sh b/mcp/patches/patch.sh
index d7db73591..aac0017b2 100755
--- a/mcp/patches/patch.sh
+++ b/mcp/patches/patch.sh
@@ -2,6 +2,7 @@
if [ -r "$1" ]; then
while IFS=': ' read -r p_dest p_file; do
- [[ "${p_dest}" =~ $2 ]] && patch -fd "${p_dest}" -p1 < "/root/fuel/mcp/patches/${p_file}"
- done < $1
+ [[ "${p_dest}" =~ "$2" ]] && \
+ patch -fd "${p_dest}" -p1 < "/root/fuel/mcp/patches/${p_file}"
+ done < "$1"
fi
diff --git a/mcp/scripts/create-config-drive.sh b/mcp/scripts/create-config-drive.sh
index df3f72f1f..0943914ab 100755
--- a/mcp/scripts/create-config-drive.sh
+++ b/mcp/scripts/create-config-drive.sh
@@ -11,9 +11,10 @@ usage () {
ARGS=$(getopt \
-o k:u:v:h: \
- --long help,hostname:,ssh-key:,user-data:,vendor-data: -n ${0##*/} \
+ --long help,hostname:,ssh-key:,user-data:,vendor-data: -n "${0##*/}" \
-- "$@")
+# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
usage >&2
exit 2
@@ -52,51 +53,51 @@ done
config_image=$1
shift
-if [ "$ssh_key" ] && [ -f "$ssh_key" ]; then
- echo "adding pubkey from $ssh_key"
- ssh_key_data=$(cat "$ssh_key")
+if [ "${ssh_key}" ] && [ -f "${ssh_key}" ]; then
+ echo "adding pubkey from ${ssh_key}"
+ ssh_key_data=$(cat "${ssh_key}")
fi
uuid=$(uuidgen)
-if ! [ "$hostname" ]; then
- hostname="$uuid"
+if ! [ "${hostname}" ]; then
+ hostname="${uuid}"
fi
trap 'rm -rf $config_dir' EXIT
config_dir=$(mktemp -t -d configXXXXXX)
-if [ "$user_data" ] && [ -f "$user_data" ]; then
- echo "adding user data from $user_data"
- cp ${user_data} ${config_dir}/user-data
+if [ "${user_data}" ] && [ -f "${user_data}" ]; then
+ echo "adding user data from ${user_data}"
+ cp "${user_data}" "${config_dir}/user-data"
else
- touch $config_dir/user-data
+ touch "${config_dir}/user-data"
fi
-if [ "$vendor_data" ] && [ -f "$vendor_data" ]; then
- echo "adding vendor data from $vendor_data"
- cp ${vendor_data} ${config_dir}/vendor-data
+if [ "${vendor_data}" ] && [ -f "${vendor_data}" ]; then
+ echo "adding vendor data from ${vendor_data}"
+ cp "${vendor_data}" "${config_dir}/vendor-data"
fi
-cat > $config_dir/meta-data <<-EOF
-instance-id: $uuid
-hostname: $hostname
-local-hostname: $hostname
+cat > "${config_dir}/meta-data" <<-EOF
+instance-id: ${uuid}
+hostname: ${hostname}
+local-hostname: ${hostname}
EOF
-if [ "$ssh_key_data" ]; then
- cat >> $config_dir/meta-data <<-EOF
+if [ "${ssh_key_data}" ]; then
+ cat >> "${config_dir}/meta-data" <<-EOF
public-keys:
- |
- $ssh_key_data
+ ${ssh_key_data}
EOF
fi
#PS1="debug> " bash --norc
-echo "generating configuration image at $config_image"
-if ! mkisofs -o $config_image -V cidata -r -J --quiet $config_dir; then
- echo "ERROR: failed to create $config_image" >&2
+echo "generating configuration image at ${config_image}"
+if ! mkisofs -o "${config_image}" -V cidata -r -J --quiet "${config_dir}"; then
+ echo "ERROR: failed to create ${config_image}" >&2
exit 1
fi
-chmod a+r $config_image
+chmod a+r "${config_image}"
diff --git a/mcp/scripts/lib.sh b/mcp/scripts/lib.sh
index e299e2525..33dba3ccc 100644
--- a/mcp/scripts/lib.sh
+++ b/mcp/scripts/lib.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
#
# Library of shell functions
#
@@ -5,24 +6,24 @@
generate_ssh_key() {
local user=${SUDO_USER:-$USER}
- [ -f "$SSH_KEY" ] || ssh-keygen -f ${SSH_KEY} -N ''
- install -o $user -m 0600 ${SSH_KEY} /tmp/
+ [ -f "${SSH_KEY}" ] || ssh-keygen -f "${SSH_KEY}" -N ''
+ install -o "${user}" -m 0600 "${SSH_KEY}" /tmp/
}
get_base_image() {
local base_image=$1
mkdir -p images
- wget -P /tmp -nc $base_image
+ wget -P /tmp -nc "${base_image}"
}
cleanup_vms() {
# clean up existing nodes
for node in $(virsh list --name | grep -P '\w{3}\d{2}'); do
- virsh destroy $node
+ virsh destroy "${node}"
done
for node in $(virsh list --name --all | grep -P '\w{3}\d{2}'); do
- virsh undefine --nvram $node
+ virsh undefine --nvram "${node}"
done
}
@@ -31,14 +32,15 @@ prepare_vms() {
local base_image=$2
cleanup_vms
- get_base_image $base_image
+ get_base_image "${base_image}"
envsubst < user-data.template > user-data.sh
for node in "${vnodes[@]}"; do
# create/prepare images
- ./create-config-drive.sh -k ${SSH_KEY}.pub -u user-data.sh -h ${node} images/mcp_${node}.iso
- cp /tmp/${base_image/*\/} images/mcp_${node}.qcow2
- qemu-img resize images/mcp_${node}.qcow2 100G
+ ./create-config-drive.sh -k "${SSH_KEY}.pub" -u user-data.sh \
+ -h "${node}" "images/mcp_${node}.iso"
+ cp "/tmp/${base_image/*\/}" "images/mcp_${node}.qcow2"
+ qemu-img resize "images/mcp_${node}.qcow2" 100G
done
}
@@ -78,6 +80,7 @@ create_vms() {
# create vms with specified options
for node in "${vnodes[@]}"; do
+ # shellcheck disable=SC2086
virt-install --name "${node}" \
--ram "${vnodes_ram[$node]}" --vcpus "${vnodes_vcpus[$node]}" \
--cpu host-passthrough --accelerate ${net_args} \
@@ -104,7 +107,7 @@ start_vms() {
# start vms
for node in "${vnodes[@]}"; do
- virsh start ${node}
+ virsh start "${node}"
sleep $[RANDOM%5+1]
done
}
@@ -118,8 +121,9 @@ check_connection() {
echo '[INFO] Attempting to get into Salt master ...'
# wait until ssh on Salt master is available
- while (($attempt <= $total_attempts)); do
- ssh ${SSH_OPTS} ubuntu@${SALT_MASTER} uptime
+ while ((attempt <= total_attempts)); do
+ # shellcheck disable=SC2086
+ ssh ${SSH_OPTS} "ubuntu@${SALT_MASTER}" uptime
case $? in
0) echo "${attempt}> Success"; break ;;
*) echo "${attempt}/${total_attempts}> ssh server ain't ready yet, waiting for ${sleep_time} seconds ..." ;;
diff --git a/mcp/scripts/salt.sh b/mcp/scripts/salt.sh
index 605da89ee..4c6cbf782 100755
--- a/mcp/scripts/salt.sh
+++ b/mcp/scripts/salt.sh
@@ -4,7 +4,8 @@
#
# ssh to cfg01
-ssh ${SSH_OPTS} ubuntu@${SALT_MASTER} bash -s << SALT_INSTALL_END
+# shellcheck disable=SC2086,2087
+ssh ${SSH_OPTS} "ubuntu@${SALT_MASTER}" bash -s << SALT_INSTALL_END
sudo -i
echo -n 'Checking out cloud-init has finished running ...'