diff options
author | Simon Spöhel <simon@spoehel.ch> | 2021-04-23 10:41:27 +0000 |
---|---|---|
committer | Sakirnth Nagarasa <sakirnth@gmail.com> | 2021-09-01 08:25:43 +0000 |
commit | 5c5515d07af491510d29b854cfd605b303443261 (patch) | |
tree | c6a3a34973ddd2891adb648ea1e8c688865faf7f /libexec | |
parent | Adding option to select config-template. (diff) | |
download | compute-tools-5c5515d07af491510d29b854cfd605b303443261.tar.xz compute-tools-5c5515d07af491510d29b854cfd605b303443261.zip |
Adding create-qemu command.
Diffstat (limited to '')
-rwxr-xr-x | libexec/container/create-qemu | 120 |
1 files changed, 23 insertions, 97 deletions
diff --git a/libexec/container/create-qemu b/libexec/container/create-qemu index 138fb37..b678d59 100755 --- a/libexec/container/create-qemu +++ b/libexec/container/create-qemu @@ -1,5 +1,6 @@ #!/bin/sh + # Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net> # # SPDX-License-Identifier: GPL-3.0+ @@ -31,8 +32,8 @@ SCRIPTS="/usr/share/${SOFTWARE}/scripts" Parameters () { - GETOPT_LONGOPTIONS="name:,cnt.container-server:,cnt.overlay:,cnt.overlay-options:,bind:,bind-ro:,capability:,drop-capability:,script:,config-template:,verbose," - GETOPT_OPTIONS="n:,b:,c:,d:,s:,t:,v," + GETOPT_LONGOPTIONS="name:,cnt.container-server:,id:,script:,shortname:,config-template:,verbose," + GETOPT_OPTIONS="n:,i:,s:,c:,v," PARAMETERS="$(getopt --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})" @@ -52,48 +53,23 @@ Parameters () shift 2 ;; - --cnt.auto) - CNT_AUTO="${2}" - shift 2 - ;; - --cnt.container-server) CNT_CONTAINER_SERVER="${2}" shift 2 ;; - --cnt.overlay) - CNT_OVERLAY="${2}" - shift 2 - ;; - - --cnt.overlay-options) - CNT_OVERLAY_OPTIONS="${2}" - shift 2 - ;; - - -b|--bind) - BIND="${2}" - shift 2 - ;; - - --bind-ro) - BIND_RO="${2}" + -i|--id) + ID="${2}" shift 2 ;; - -c|--capability) - CAPABILITY="${2}" - shift 2 - ;; - - -d|--drop-capability) - DROP_CAPABILITY="${2}" + -s|--script) + SCRIPT="${2}" shift 2 ;; - -s|--script) - SCRIPT="${2}" + --shortname) + SHORTNAME="${2}" shift 2 ;; @@ -122,6 +98,8 @@ Parameters () Usage () { + # FIXME + echo WIP echo "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME [--cnt.container-server=true|false|FQDN] [--cnt.overlay=DIRECTORY_LOWER:DIRECTORY_UPPER:DIRECTORY_WORK:DIRECTORY_MERGED] [--cnt.overlay-options=OPTION[,OPTION]] [-b|--bind DIRECTORY:DIRECTORY[:OPTIONS]] [--bind-ro DIRECTORY:DIRECTORY[:OPTIONS]] [-c|--capability CAPABILITY[,CAPABILITY]] [-d|--drop-capability DROP_CAPABILITY[,DROP_CAPABILITY]] [-s|--script SCRIPT] [-v|--verbose] [-- SCRIPT_OPTIONS]" >&2 exit 1 } @@ -133,6 +111,11 @@ then Usage fi +if [ -z "${ID}" ] +then + Usage +fi + case "${NAME}" in ALL) echo "'${NAME}': name 'ALL' is reserved to expand to all available container" >&2 @@ -191,64 +174,13 @@ Creating container: ${NAME} ################################################################################ EOF - ;; + ;; esac -CNT_CONTAINER_SERVER="${CNT_CONTAINER_SERVER:-$(hostname -f 2> /dev/null || hostname)}" - -# Pre hooks -for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}" -do - if [ -x "${FILE}" ] - then - "${FILE}" - fi -done - -# Creating rw bind mounts -if [ -n "${BIND}" ] -then - BINDS="$(echo ${BIND} | sed -e 's|;| |g')" - - for ENTRY in ${BINDS} - do - DIRECTORY="$(echo ${ENTRY} | awk -F: '{ print $1 }')" - - mkdir -p "${DIRECTORY}" - done -fi - -# Creating ro bind mounts -if [ -n "${BIND_RO}" ] -then - BINDS_RO="$(echo ${BIND_RO} | sed -e 's|;| |g')" - - for ENTRY in ${BINDS_RO} - do - DIRECTORY="$(echo ${ENTRY} | awk -F: '{ print $1 }')" - - mkdir -p "${DIRECTORY}" - done -fi +BASE_PORT="20000" -# Creating overlay mounts -if [ -n "${CNT_OVERLAY}" ] -then - CNT_OVERLAYS="$(echo ${CNT_OVERLAY} | sed -e 's|;| |g')" - - for ENTRY in ${CNT_OVERLAYS} - do - DIRECTORY_LOWER="$(echo ${ENTRY} | awk -F: '{ print $1 }')" - DIRECTORY_UPPER="$(echo ${ENTRY} | awk -F: '{ print $2 }')" - DIRECTORY_WORK="$(echo ${ENTRY} | awk -F: '{ print $3 }')" - DIRECTORY_MERGED="$(echo ${ENTRY} | awk -F: '{ print $4 }')" - - for DIRECTORY in "${DIRECTORY_LOWER}" "${DIRECTORY_UPPER}" "${DIRECTORY_WORK}" "${DIRECTORY_MERGED}" - do - mkdir -p "${DIRECTORY}" - done - done -fi +CNT_CONTAINER_SERVER="${CNT_CONTAINER_SERVER:-$(hostname -f 2> /dev/null || hostname)}" +PORT="$((${BASE_PORT}+${ID}))" # config mkdir -p "${CONFIG}" @@ -270,19 +202,13 @@ sed -e "s|@CNT_AUTO@|${CNT_AUTO}|g" \ -e "s|@NETWORK_VETH_EXTRA@|${NETWORK_VETH_EXTRA}|g" \ -e "s|@PRIVATE_USERS@|no|g" \ -e "s|@REGISTER@|yes|g" \ + -e "s|@ID@|${ID}|g" \ + -e "s|@SHORTNAME@|${SHORTNAME}|g" \ + -e "s|@PORT@|${PORT}|g" \ "${CONFIG_TEMPLATE}" > "${CONFIG}/${NAME}.conf" # Run "${SCRIPTS}/${SCRIPT}" $(echo "${@}" | sed -e 's| -- | |') -# Post hooks -for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}" -do - if [ -x "${FILE}" ] - then - "${FILE}" - fi -done - # done echo "'${NAME}': container created." |