1
0
mirror of synced 2026-01-20 09:34:58 +00:00
steve 9cb33aa9b9 2007-02-23 15:37:05 by steve
Installation methods are now updated so that I can add in the
 image server method for use @Bytemark.
2007-02-23 15:37:06 +00:00

423 lines
9.4 KiB
Bash

# -*- shell-script -*-
#
# /etc/bash_completion.d/xen-tools
#
# Completion functions for Bash.
#
# This file offers basic support for all the command line options, along with
# some specialist support to complete filesystem types, distribution targets,
# virtual images, etc.
#
# References on command line completion:
#
# http://www.debian-administration.org/articles/316
# http://www.debian-administration.org/articles/317
# http://dev.gentoo.org/~plasmaroo/devmanual/tasks-reference/completion/
#
# Steve
# --
# http://www.steve.org.uk
#
# $Id: xen-tools,v 1.41 2007-02-23 15:37:06 steve Exp $
#
#
# Utility function to find the names of each existing Xen image,
# we do this by parsing the files matching /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
#
# Completes the command line flags, and will allow tab completion of
# the supported filesystems
#
_xen_create_image()
{
local cur prev ip roles dists vgs
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
opts='--admins --accounts --broadcast --boot --cache --config --dhcp --dir --dist --evms --force --fs --gateway --help --hostname --ide --image --install-method --install-source --initrd --ip --kernel --lvm --mac --manual --memory --mirror --no-hooks --no-install --noswap --p2p --passwd --role --size --swap --version --verbose'
#
# Complete the initial part of the IP in the configuration file.
ip=`grep ^gateway /etc/xen-tools/xen-tools.conf 2>/dev/null | awk -F'= ' '{print $2}'`
#
# Available distributions, by which we mean distributions which
# we have hook scripts available.
#
for i in `ls -1 /usr/lib/xen-tools/ ` ; do
if [ -d /usr/lib/xen-tools/${i} ]; then
dists="${dists} ${i/.d/}"
fi
done
#
# Volume group completion
#
vgs=`vgdisplay 2>/dev/null | grep Name 2>/dev/null | awk '{print $3}'`
#
# EVMS container completion
#
evmscontainers=`evms_query containers 2>/dev/null`
case "$prev" in
--cache)
COMPREPLY=( $( compgen -W 'yes no' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--config)
_filedir
return 0
;;
--dir)
_filedir -d
return 0
;;
--dist)
COMPREPLY=( $( compgen -W '${dists}' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--evms)
COMPREPLY=( $( compgen -W '${evmscontainers}' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--fs)
COMPREPLY=( $( compgen -W 'xfs ext3 reiserfs' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--image)
COMPREPLY=( $( compgen -W 'sparse full' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--install-method)
COMPREPLY=( $( compgen -W 'copy debootstrap rpmstrap tar' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--ip)
ip=`echo ${ip} | sed -e 's/[.][^.]*$/./'`
COMPREPLY=( $(compgen -W "${ip}" -- ${cur}) )
return 0
;;
--lvm)
COMPREPLY=( $( compgen -W '${vgs}' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--role)
roles=$(for x in `ls -1 /usr/lib/xen-tools/*.d/role.d/ 2>/dev/null | grep -v \/ 2>/dev/null`; do echo ${x} ; done )
COMPREPLY=( $( compgen -W '${roles}' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
esac
if [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
complete -F _xen_create_image xen-create-image
#
# Completion for xen-delete-image
#
_xen_delete_image()
{
local cur prev opts vgs names
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
#
# Volume Group completion
#
vgs=`vgdisplay 2>/dev/null | grep Name 2>/dev/null | awk '{print $3}'`
#
# EVMS container completion
#
evmscontainers=`evms_query containers 2>/dev/null`
#
# Complete the options + all available hostnames.
#
opts="--dir --evms --help --hostname --lvm --manual --test --version ${names}"
case "${prev}" in
--dir)
_filedir -d
return 0
;;
--evms)
COMPREPLY=( $( compgen -W '${evmscontainers}' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--hostname)
names=`_find_xen_images`
COMPREPLY=( $(compgen -W "${names}" -- ${cur}) )
return 0
;;
--lvm)
COMPREPLY=( $( compgen -W '${vgs}' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
esac
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
#
# Completion for xen-update-image
#
_xen_update_image()
{
local cur prev opts base names vgs
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
#
# Volume group completion
#
vgs=`vgdisplay 2>/dev/null | grep Name 2>/dev/null | awk '{print $3}'`
#
# EVMS container completion
#
evmscontainers=`evms_query containers 2>/dev/null`
opts="--dir --evms --help --manual --version --lvm"
case "${prev}" in
--dir)
_filedir -d
return 0
;;
esac
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
#
# Completion for xen-list-images
#
_xen_list_images()
{
local cur prev opts vgs
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--dir --evms --help --manual --test --version --lvm"
#
# Volume group completion
#
vgs=`vgdisplay 2>/dev/null | grep Name 2>/dev/null | awk '{print $3}'`
#
# EVMS container completion
#
evmscontainers=`evms_query containers 2>/dev/null`
case "${prev}" in
--dir)
_filedir -d
return 0
;;
--evms)
COMPREPLY=( $( compgen -W '${evmscontainers}' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--lvm)
COMPREPLY=( $( compgen -W '${vgs}' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
esac
if [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
complete -F _xen_list_images xen-list-images
#
# Completion for xt-create-xen-config
#
_xt-create-xen-config()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
opts='--help --manual --output --template --verbose --version'
case "$prev" in
--output)
_filedir -d
return 0
;;
--template)
COMPREPLY=( $( compgen -f -- ${cur#*:} ) )
return 0
;;
esac
if [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
complete -F _xt-create-xen-config xt-create-xen-config
#
# Completion for xt-customize-image
#
_xt-customize-image()
{
local cur prev dists
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
opts='--dist --help --location --manual --output --verbose --version'
#
# Available distributions, from rpmstrap
#
if [ -d /usr/lib/rpmstrap/scripts ]; then
dists=`ls -1 /usr/lib/rpmstrap/scripts`
fi
case "$prev" in
--location)
_filedir -d
return 0
;;
--dist)
COMPREPLY=( $( compgen -W '${dists} sid sarge etch' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
esac
if [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
complete -F _xt-customize-image xt-customize-image
#
# Completion for xt-install-image
#
#
_xt-install-image()
{
local cur prev dists
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
opts='--cache --config --dist --help --install-source --install-method --location --manual --mirror --verbose --version'
#
# Available distributions, from rpmstrap
#
if [ -d /usr/lib/rpmstrap/scripts ]; then
dists=`ls -1 /usr/lib/rpmstrap/scripts`
fi
case "$prev" in
--cache)
COMPREPLY=( $( compgen -W 'yes no' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--config)
_filedir
return 0
;;
--copy)
_filedir -d
return 0
;;
--dist)
COMPREPLY=( $( compgen -W '${dists} sid sarge etch' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--install-method)
COMPREPLY=( $( compgen -W 'copy debootstrap rpmstrap tar' -- "${COMP_WORDS[COMP_CWORD]}" ) )
return 0
;;
--location)
_filedir -d
return 0
;;
--tar)
_filedir 'tar'
return 0
;;
esac
if [[ ${cur} == -* ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
complete -F _xt-install-image xt-install-image