#!/bin/ksh93 VERSION='$Rev$' FPROG="${.sh.file}" PROG="${FPROG##*/}" function showUsage { getopts -a ${PROG} "${ print ${USAGE}; }" OPT --man } function printOption { typeset X="Option -$1" [[ -n $2 ]] && X+=" '$2'" # arg print "$X" } # -copyright is just for demo - change to whatever you want to (jel). USAGE='[-?$Id$ ] [-copyright?Copyright (c) 2014 Jens Elkner. All rights reserved.] [-license?CDDL 1.0] [+NAME?'"${PROG}"' - template invoked POSIXLY_CORRECT ?] [+DESCRIPTION?Check, whether \blxc-create\b(1) (i.e. lxccontainer:create_run_template()) behaves POSIXly correct. Just pass this script as a template.] [h:help?Print this help and exit.] [F:functions?Print a list of all functions available.] [T:trace]:[functionList?A comma separated list of functions of this script to trace (convinience for troubleshooting).] [+?] [n:name]:[cid?The container identifier (an alphanum string). Required.] [P:path]:[cfgdir?The base directory to use for keeping/maintaining container configurations and state. The configuration/state for the container to setup is kept in its sub directory \acid/\a. Required. lxc-create default: \alxc.lxcpath\a] [R:rootfs]:[path?The root directory aka / of the new container from its parent perspective. Required. lxc-create default: \alxc.rootfs\a (fallback: \acfgdir\a\b/\b\acid\a\b/rootfs\b)] [u:mapped-uid]:[num?Optional: The decimal UID within the new container, to which the effective UID running this script gets mapped to.] [g:mapped-gid]:[num?Optional: The decimal GID within the new container, to which the effective GID running this script gets mapped to.] [v:version?Print current version of this script and exit.] [+EXAMPLES] [+?If no uid/gid maps have been created/granted so far:]{ [+?ksh93] [+?integer NID=${ id -u ; } LID] [+?(( NID*=65536 ))] [+?(( LID=NID+65535 ))] [+?print "lxc.id_map = u 0 ${NID} 65535\\nlxc.id_map = g 0 ${NID} 65535"\ ] [+?\t>/tmp/lxc.cfg] [+?sudo usermod -v ${NID}-${LID} -w ${NID}-${LID} ${ id -un; }] [+?exit] } [+?Try out the template:]{ [+?lxc-create -n pt1 -P /tmp -f /tmp/lxc.cfg -B dir \ ] [+?\t--template='"${FPROG}"' myarg1 myarg2] [+?] [+?lxc-destroy -n pt1 -P /tmp] } [+SEE ALSO?\blxc-create\b(1)] \n\n[\aoperand\a]... ' X="${ print ${USAGE} ; }" while getopts "${X}" OPT ; do case "${OPT}" in # common options h) showUsage ; exit 0 ;; F) typeset +f ; exit 0 ;; T) typeset -ft ${OPTARG//,/ } ;; # script specific n|P|R|u|g) printOption "${OPT}" "${OPTARG}";; v) printOption "${OPT}" print "Version: ${VERSION#* }" exit 0 ;; esac done X=$((OPTIND-1)) shift $X && OPTIND=1 integer I=0 for X in "$@" ; do print "Operand ${I}: $X" (( I++ )) done X=( ${ id -u ; id -g ; } ) print "Hello World! (${X[0]}:${X[1]})"