2006-06-18 19:00:39 by steve
Updated to actually complete on hostnames correctly for xen-delete-image + xen-update-image. Removed support for xen-duplicate-image.
This commit is contained in:
140
misc/xen-tools
140
misc/xen-tools
@@ -1,3 +1,4 @@
|
||||
# -*- shell-script -*-
|
||||
#
|
||||
# /etc/bash_completion.d/xen-tools
|
||||
#
|
||||
@@ -20,10 +21,27 @@
|
||||
# --
|
||||
# http://www.steve.org.uk
|
||||
#
|
||||
# $Id: xen-tools,v 1.27 2006-06-15 23:20:22 steve Exp $
|
||||
# $Id: xen-tools,v 1.28 2006-06-18 19:00:39 steve Exp $
|
||||
#
|
||||
|
||||
|
||||
#
|
||||
# Utility function to find the names of each existing Xen image,
|
||||
# we do this by finding parsing the files /etc/xen/*.cfg
|
||||
#
|
||||
function _find_xen_images
|
||||
{
|
||||
local names name
|
||||
|
||||
for i in /etc/xen/*.cfg ; do
|
||||
name=`grep ^name $i 2>/dev/null | awk -F\' '{print $2}'`
|
||||
if [ ! -z "${name}" ] ; then
|
||||
names="${names} ${name}"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "${names}"
|
||||
}
|
||||
|
||||
#
|
||||
# Completion for xen-create-image
|
||||
@@ -71,7 +89,7 @@ _xen_create_image()
|
||||
return 0
|
||||
;;
|
||||
--dist)
|
||||
COMPREPLY=( $( compgen -W '${dists} sid sarge etch' -- "${COMP_WORDS[COMP_CWORD]}" ) )
|
||||
COMPREPLY=( $( compgen -W '${dists} dapper sid sarge etch' -- "${COMP_WORDS[COMP_CWORD]}" ) )
|
||||
return 0
|
||||
;;
|
||||
--fs)
|
||||
@@ -104,78 +122,16 @@ complete -F _xen_create_image xen-create-image
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Completion for xen-duplicate-image
|
||||
#
|
||||
_xen_duplicate_image()
|
||||
{
|
||||
local cur prev opts base ip
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
opts="--broadcast --dhcp --dir --from --gateway --help --hostname --ip --manual --netmask --version --volume"
|
||||
|
||||
#
|
||||
# Complete the initial part of the IP in the configuration file.
|
||||
ip=`grep ^gateway /etc/xen-tools/xen-tools.conf | awk -F'= ' '{print $2}'`
|
||||
|
||||
#
|
||||
# First of all the base directory comes from the configuration file.
|
||||
#
|
||||
base=`grep ^dir /etc/xen-tools/xen-tools.conf | awk -F'= ' '{print $2}'`
|
||||
base=${base}/domains/
|
||||
|
||||
case "${prev}" in
|
||||
--dir)
|
||||
_filedir -d
|
||||
return 0
|
||||
;;
|
||||
--from)
|
||||
if [[ ${base} != '/domains/' ]] ; then
|
||||
local names=$(for x in `ls -1 ${base} 2>/dev/null`; do echo ${x} ; done )
|
||||
COMPREPLY=( $(compgen -W "${names}" -- ${cur}) )
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
--ip)
|
||||
ip=`echo ${ip} | sed -e 's/[.][^.]*$/./'`
|
||||
COMPREPLY=( $(compgen -W "${ip}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ ${cur} == -* ]]; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
complete -F _xen_duplicate_image xen-duplicate-image
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Completion for xen-delete-image
|
||||
#
|
||||
_xen_delete_image()
|
||||
{
|
||||
local cur prev opts base names vgs
|
||||
local cur prev opts vgs names
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
|
||||
#
|
||||
# First of all the base directory comes from the configuration file.
|
||||
#
|
||||
base=`grep ^dir /etc/xen-tools/xen-tools.conf | awk -F'= ' '{print $2}'`
|
||||
base=${base}/domains/
|
||||
|
||||
#
|
||||
# If we have a base which isn't empty then find all the hosts
|
||||
#
|
||||
if [[ ${base} != '/domains/' ]]; then
|
||||
names=$(for x in `ls -1 ${base} 2>/dev/null`; do echo -n "${x} " ; done )
|
||||
fi
|
||||
|
||||
#
|
||||
# Volume Group completion
|
||||
#
|
||||
@@ -195,15 +151,17 @@ _xen_delete_image()
|
||||
COMPREPLY=( $( compgen -W '${vgs}' -- "${COMP_WORDS[COMP_CWORD]}" ) )
|
||||
return 0
|
||||
;;
|
||||
--hostname)
|
||||
if [[ ${base} != '/domains/' ]] ; then
|
||||
|
||||
COMPREPLY=( $(compgen -W "${names}" -- ${cur}) )
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
if [[ ${cur} == -* ]]; then
|
||||
# Completing command line arguments.
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
else
|
||||
# Completing image names
|
||||
names=`_find_xen_images`
|
||||
COMPREPLY=( $(compgen -W "${names}" -- ${cur}) )
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
complete -F _xen_delete_image xen-delete-image
|
||||
@@ -215,25 +173,17 @@ complete -F _xen_delete_image xen-delete-image
|
||||
#
|
||||
_xen_update_image()
|
||||
{
|
||||
local cur prev opts base names
|
||||
local cur prev opts base names vgs
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
|
||||
#
|
||||
# First of all the base directory comes from the configuration file.
|
||||
# Volume group completion
|
||||
#
|
||||
base=`grep ^dir /etc/xen-tools/xen-tools.conf | awk -F'= ' '{print $2}'`
|
||||
base=${base}/domains/
|
||||
vgs=`vgdisplay 2>/dev/null | grep Name | awk '{print $3}'`
|
||||
|
||||
#
|
||||
# If we have a base which isn't empty then find all the hosts
|
||||
#
|
||||
if [[ ${base} != '/domains/' ]]; then
|
||||
names=$(for x in `ls -1 ${base} 2>/dev/null`; do echo -n "${x} " ; done )
|
||||
fi
|
||||
|
||||
opts="--dir --help --manual --version --volume ${names}"
|
||||
opts="--dir --help --manual --version --lvm"
|
||||
|
||||
case "${prev}" in
|
||||
--dir)
|
||||
@@ -242,7 +192,14 @@ _xen_update_image()
|
||||
;;
|
||||
esac
|
||||
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
if [[ ${cur} == -* ]]; then
|
||||
# Completing command line arguments.
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
else
|
||||
# Completing image names
|
||||
names=`_find_xen_images`
|
||||
COMPREPLY=( $(compgen -W "${names}" -- ${cur}) )
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
complete -F _xen_update_image xen-update-image
|
||||
@@ -254,17 +211,26 @@ complete -F _xen_update_image xen-update-image
|
||||
#
|
||||
_xen_list_images()
|
||||
{
|
||||
local cur prev opts
|
||||
local cur prev opts vgs
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
opts="--dir --help --manual --test --version --volume"
|
||||
opts="--dir --help --manual --test --version --lvm"
|
||||
|
||||
#
|
||||
# Volume group completion
|
||||
#
|
||||
vgs=`vgdisplay 2>/dev/null | grep Name | awk '{print $3}'`
|
||||
|
||||
case "${prev}" in
|
||||
--dir)
|
||||
_filedir -d
|
||||
return 0
|
||||
;;
|
||||
--lvm)
|
||||
COMPREPLY=( $( compgen -W '${vgs}' -- "${COMP_WORDS[COMP_CWORD]}" ) )
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ ${cur} == -* ]]; then
|
||||
|
||||
Reference in New Issue
Block a user