diff --git a/.pct-helpers b/.pct-helpers index d9eb763..2f7dce2 100644 --- a/.pct-helpers +++ b/.pct-helpers @@ -4,6 +4,7 @@ CT_DIR=${CT_DIR:=/etc/pve/lxc/} + #---------------------------------------------------------------------- # XXX this is quite generic, might be a good idea to move this to a # seporate lib/file... @@ -21,45 +22,12 @@ CT_DIR=${CT_DIR:=/etc/pve/lxc/} } -#---------------------------------------------------------------------- -# CT hostname <-> id... - -ct2hostname(){ - local ct=${CT_DIR}/${1}.conf - local host=$(cat $ct | grep hostname | head -1) - echo ${host/hostname: /} -} - -hostname2ct(){ - if [ -e "${CT_DIR}/${1}.conf" ] ; then - echo $1 - fi - local running=$2 - running=${running:=any} - local ct - local host - for ct in "${CT_DIR}"/*.conf ; do - host=$(cat $ct | grep hostname | head -1) - host=${host/hostname: /} - if [ "$host" = $1 ] ; then - ct=${ct#${CT_DIR}} - ct=${ct%.conf} - ct=${ct#\/} - # filter results if needed... - if [ $running = "any" ] ; then - echo $ct - else - local status=`pct status $ct` - if [ "$running" = "${status/status: /}" ] ; then - echo $ct - fi - fi - fi - done -} - #---------------------------------------------------------------------- +# Fill section... +# +# XXX this is quite generic... + fillsection(){ ( usage(){ echo "Usage:" @@ -115,5 +83,44 @@ fillsection(){ ( ) } + +#---------------------------------------------------------------------- +# CT hostname <-> CT id... + +ct2hostname(){ + local ct=${CT_DIR}/${1}.conf + local host=$(cat $ct | grep hostname | head -1) + echo ${host/hostname: /} +} + +hostname2ct(){ + if [ -e "${CT_DIR}/${1}.conf" ] ; then + echo $1 + fi + local running=$2 + running=${running:=any} + local ct + local host + for ct in "${CT_DIR}"/*.conf ; do + host=$(cat $ct | grep hostname | head -1) + host=${host/hostname: /} + if [ "$host" = $1 ] ; then + ct=${ct#${CT_DIR}} + ct=${ct%.conf} + ct=${ct#\/} + # filter results if needed... + if [ $running = "any" ] ; then + echo $ct + else + local status=`pct status $ct` + if [ "$running" = "${status/status: /}" ] ; then + echo $ct + fi + fi + fi + done +} + + #---------------------------------------------------------------------- # vim:set ts=4 sw=4 nowrap :