diff --git a/create_template_list.sh b/create_template_list.sh index 2ede209..7d4fb07 100755 --- a/create_template_list.sh +++ b/create_template_list.sh @@ -1,48 +1,53 @@ #!/bin/bash +# vim: set ts=4 sw=4 sts=4 et : # # Creates a small script to copy to dom0 to retrieve the generated template rpm's # -TEMPLATES="./rpm/install-templates.sh" - -write() { - echo "$1" >> "$TEMPLATES" -} - -if [ -x /usr/sbin/xenstore-read ]; then - XENSTORE_READ="/usr/sbin/xenstore-read" -else - XENSTORE_READ="/usr/bin/xenstore-read" -fi - -TEMPLATES="$(readlink -m $TEMPLATES)" -VERSION="-$(cat ./version)" +template_dir="$(readlink -m ./rpm/install-templates.sh)" +files=( $(ls rpm/noarch) ) name=$($XENSTORE_READ name) -path="$(readlink -m .)" -files=$(ls rpm/noarch) -# -# Write to install-templates -# +# ----------------------------------------------------------------------------- +# Write $vars +# ----------------------------------------------------------------------------- +cat << EOF > "${template_dir}" +#!/bin/bash -echo "#!/bin/bash" > "$TEMPLATES" -write "" +# Use the following command in DOM0 to retreive this file: +# qvm-run --pass-io ${name} 'cat ${template_dir}' > install-templates.sh + +files=" +$(printf "%s \n" ${files[@]}) +" + +path="$(readlink -m .)/rpm/noarch" +version="-$(cat ./version)" +EOF + +# ----------------------------------------------------------------------------- +# Write installation function +# ----------------------------------------------------------------------------- +cat << 'EOF' >> "${template_dir}" for file in ${files[@]}; do - write "qvm-run --pass-io development-qubes 'cat ${path}/rpm/noarch/${file}' > ${file}" - write "" - write "sudo yum erase $(echo "$file" | sed -r "s/($VERSION).+$//")" - write "" - write "sudo yum install ${file}" - write "" - write "" + if [ ! -e ${file} ]; then + qvm-run --pass-io development-qubes "cat ${path}/${file}" > ${file} + fi + + sudo yum erase $(echo "${file}" | sed -r "s/(${version}).+$//") && { + sudo yum install ${file} && { + rm -f ${file} + } + } done - -write "# Use the following command in DOM0 to retreive this file:" -write "# qvm-run --pass-io $name 'cat ${TEMPLATES}' > install-templates.sh" - +EOF + +# ----------------------------------------------------------------------------- +# Display instructions +# ----------------------------------------------------------------------------- echo "Use the following command in DOM0 to retreive this file:" -echo "qvm-run --pass-io $name 'cat ${TEMPLATES}' > install-templates.sh" +echo "qvm-run --pass-io ${name} 'cat ${template_dir}' > install-templates.sh"