#!/bin/bash # # Publish builed images to OpenNebula # Based on the work of "Julien Marchetti" from here : https://dev-eole.ac-dijon.fr/projects/packer/repository # set -eo pipefail function help () { cat <> ${file} echo ${cmd} ${action} ${file} rm ${file} if [[ ${ENDING} == "CLEAN" ]] then echo "MUST CLEAN IMAGE FROM DATASTORE" fi return 0 } [ $# -eq 0 ] && help && exit 1 while getopts ":hU:u:n:D:p:t:P:d:m:M:" opt; do case $opt in U) url="${OPTARG}" >&2 ;; u) user="${OPTARG}" >&2 ;; n) name="${OPTARG}" >&2 ;; D) desc="${OPTARG}" >&2 ;; p) path="${OPTARG}" >&2 ;; t) itype="${OPTARG}" >&2 ;; P) prefix="${OPTARG}" >&2 ;; d) datastore="${OPTARG}" >&2 ;; m) market="${OPTARG}" >&2 ;; M) mode="${OPTARG}" >&2 ;; \?) echo "Invalid option : -'${OPTARG}'" >&2 help ;; h) help ; exit >&2 ;; esac done [[ -z ${mode} ]] && errorMsg "Missing option -M" 2 "help" [[ -z ${path} ]] && errorMsg "Missing option -p" 2 "help" [[ -z ${name} ]] && name=$(basename ${path}) [[ -z ${desc} ]] && desc="Image ${name} ..." [[ -z ${itype} ]] && itype="OS" [[ -z ${prefix} ]] && prefix="vd" [[ -z ${driver} ]] && driver="qcow2" [[ -z ${url} ]] && url="http://127.0.0.1:2633/XMLRPC2" case ${mode} in all) marketPush "KEEP" ;; datastore) datastorePush ;; market) marketPush "CLEAN" ;; esac