2014-10-18 12:59:21 +00:00
|
|
|
#!/bin/bash
|
2014-11-09 17:52:35 +00:00
|
|
|
# vim: set ts=4 sw=4 sts=4 et :
|
2014-10-18 12:59:21 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Creates a small script to copy to dom0 to retrieve the generated template rpm's
|
|
|
|
#
|
|
|
|
|
2015-09-20 15:38:11 +00:00
|
|
|
set -e
|
|
|
|
|
2014-11-09 17:52:35 +00:00
|
|
|
template_dir="$(readlink -m ./rpm/install-templates.sh)"
|
2015-09-20 15:38:11 +00:00
|
|
|
path="$(readlink -m .)/rpm/noarch"
|
|
|
|
version="-$(cat ./version)"
|
|
|
|
name="$(xenstore-read name)"
|
|
|
|
|
|
|
|
files_list_temp="$(echo "rpm/noarch/"*)"
|
|
|
|
files_list_temp="$(printf "%s \n" ${files_list_temp[@]})"
|
|
|
|
## Newest versions first.
|
|
|
|
files_list_temp="$(echo "$files_list_temp" | sort --reverse)"
|
|
|
|
|
|
|
|
for file_name in $files_list_temp ; do
|
|
|
|
file_name_without_version="$(echo "${file_name}" | sed -r "s/(${version}).+$//")"
|
|
|
|
template_name="$(basename "$file_name_without_version")"
|
|
|
|
template_list+="$template_name "
|
|
|
|
done
|
|
|
|
|
|
|
|
template_list="$(printf "%s \n" ${template_list[@]})"
|
|
|
|
template_list="$(echo "$template_list" | sort --unique)"
|
|
|
|
echo "template_list: $template_list"
|
|
|
|
|
|
|
|
declare -A -g remembered
|
|
|
|
|
|
|
|
for template_item_from_template_list in $template_list ; do
|
|
|
|
for file_name in $files_list_temp ; do
|
|
|
|
file_name_without_version="$(echo "${file_name}" | sed -r "s/(${version}).+$//")"
|
|
|
|
template_name="$(basename "$file_name_without_version")"
|
|
|
|
file_name_basename="$(basename "$file_name")"
|
|
|
|
if [ ! "$template_item_from_template_list" = "$template_name" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
if [ "${remembered["$template_name"]}" = "true" ]; then
|
|
|
|
files+="#$file_name_basename "
|
|
|
|
else
|
|
|
|
remembered["$template_name"]="true"
|
|
|
|
files+="$file_name_basename "
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
files="
|
|
|
|
$(printf "%s \n" ${files[@]})
|
|
|
|
"
|
2014-10-18 12:59:21 +00:00
|
|
|
|
2014-11-09 17:52:35 +00:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Write $vars
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
cat << EOF > "${template_dir}"
|
|
|
|
#!/bin/bash
|
2014-10-18 12:59:21 +00:00
|
|
|
|
2014-11-09 17:52:35 +00:00
|
|
|
# Use the following command in DOM0 to retreive this file:
|
|
|
|
# qvm-run --pass-io ${name} 'cat ${template_dir}' > install-templates.sh
|
2014-10-18 12:59:21 +00:00
|
|
|
|
2015-09-20 15:38:11 +00:00
|
|
|
files="${files}"
|
2014-10-18 12:59:21 +00:00
|
|
|
|
2015-09-20 15:38:11 +00:00
|
|
|
path="${path}"
|
|
|
|
version="${version}"
|
2014-11-11 14:00:54 +00:00
|
|
|
name="${name}"
|
2014-11-09 17:52:35 +00:00
|
|
|
EOF
|
2014-10-18 14:53:11 +00:00
|
|
|
|
2014-11-09 17:52:35 +00:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Write installation function
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
cat << 'EOF' >> "${template_dir}"
|
2014-10-18 14:53:11 +00:00
|
|
|
|
2015-09-20 15:38:11 +00:00
|
|
|
for file_name in ${files[@]}; do
|
|
|
|
if echo "$file_name" | grep -q '^#' ; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -e "${file_name}" ]; then
|
|
|
|
echo "Copying ${file_name} from ${name} to ${PWD}/${file_name}..."
|
2015-10-12 09:41:35 +00:00
|
|
|
qvm-run --pass-io "${name}" "cat ${path}/${file_name}" > "${PWD}/${file_name}"
|
2014-11-09 17:52:35 +00:00
|
|
|
fi
|
|
|
|
|
2015-10-12 09:41:35 +00:00
|
|
|
package_name="$(echo "${file_name}" | sed -r "s/(${version}).+$//")"
|
|
|
|
|
|
|
|
if sudo yum $YUM_OPTS list installed "$package_name" >/dev/null 2>&1 ; then
|
|
|
|
echo "Uninstalling package ${package_name}..."
|
|
|
|
sudo yum $YUM_OPTS erase "$package_name"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Installing file ${file_name}..."
|
|
|
|
if sudo yum $YUM_OPTS install "${file_name}" ; then
|
|
|
|
echo "Deleting ${PWD}/${file_name}..."
|
|
|
|
rm -f "${file_name}"
|
|
|
|
fi
|
2014-10-18 12:59:21 +00:00
|
|
|
done
|
2015-10-12 09:41:35 +00:00
|
|
|
|
|
|
|
echo "Done."
|
2014-11-09 17:52:35 +00:00
|
|
|
EOF
|
2015-09-20 15:38:11 +00:00
|
|
|
|
2014-11-09 17:52:35 +00:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Display instructions
|
|
|
|
# -----------------------------------------------------------------------------
|
2014-10-18 12:59:21 +00:00
|
|
|
echo "Use the following command in DOM0 to retreive this file:"
|
2014-11-09 17:52:35 +00:00
|
|
|
echo "qvm-run --pass-io ${name} 'cat ${template_dir}' > install-templates.sh"
|