File: xen-tools.bash-completion

package info (click to toggle)
xen-tools 4.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 1,476 kB
  • sloc: perl: 4,942; sh: 1,690; makefile: 268
file content (508 lines) | stat: -rw-r--r-- 12,549 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
# -*- 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:
#
#    https://debian-administration.org/articles/316
#    https://debian-administration.org/articles/317
#    http://dev.gentoo.org/~plasmaroo/devmanual/tasks-reference/completion/
#
# Steve
# --
# https://steve.fi/
#
#


#
#  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 [ -n "${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 partitions dists vgs

    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}

    # Determine arguments dynamically.  Avoids out-of-dateness.
    opts=$(xen-create-image --help|grep -- --|awk '{print $1}' |grep -- -- | sort -u)


    #
    # 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 `/bin/ls -1 /usr/share/xen-tools/ ` ; do
        if [ -d /usr/share/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
            ;;
        --cachedir)
            _filedir -d
            return 0
            ;;
        --config)
            _filedir .conf
            return 0
            ;;
        --debootstrap-cmd)
            _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 'ext2 ext3 ext4 xfs reiserfs btrfs'  -- "${COMP_WORDS[COMP_CWORD]}" ) )
            return 0
            ;;
        --genpass)
            COMPREPLY=( $( compgen -W '0 1'  -- "${COMP_WORDS[COMP_CWORD]}" ) )
            return 0
            ;;
        --hash_method)
            COMPREPLY=( $( compgen -W 'md5 sha256 sha512'  -- "${COMP_WORDS[COMP_CWORD]}" ) )
            return 0
            ;;
        --hooks)
            COMPREPLY=( $( compgen -W '0 1'  -- "${COMP_WORDS[COMP_CWORD]}" ) )
            return 0
            ;;
        --install)
            COMPREPLY=( $( compgen -W '0 1'  -- "${COMP_WORDS[COMP_CWORD]}" ) )
            return 0
            ;;
        --image)
            COMPREPLY=( $( compgen -W 'sparse full'  -- "${COMP_WORDS[COMP_CWORD]}" ) )
            return 0
            ;;
        --image-dev)
            _filedir
            return 0
            ;;
        --initrd)
            _filedir
            return 0
            ;;
        --initrd)
            COMPREPLY=( $( compgen -W '0 1'  -- "${COMP_WORDS[COMP_CWORD]}" ) )
            return 0
            ;;
        --install-method)
            COMPREPLY=( $( compgen -W 'copy debootstrap rinse rpmstrap tar'  -- "${COMP_WORDS[COMP_CWORD]}" ) )
            return 0
            ;;
        --install-source)
            _filedir
            return 0
            ;;
        --ip)
            ip=`echo ${ip} | sed -e 's/[.][^.]*$/./'`
            COMPREPLY=( $(compgen -W "${ip}" -- ${cur}) )
            return 0
            ;;
        --kernel)
            _filedir
            return 0
            ;;
        --lvm)
            COMPREPLY=( $( compgen -W '${vgs}'  -- "${COMP_WORDS[COMP_CWORD]}" ) )
            return 0
            ;;
        --modules)
            _filedir -d
            return 0
            ;;
        --output)
            _filedir -d
            return 0
            ;;
        --partitions)
            partitions=$(for x in `/bin/ls -1 /etc/xen-tools/partitions.d/ 2>/dev/null | grep -v \/ 2>/dev/null`; do echo ${x} ; done )
            COMPREPLY=( $( compgen -W '${partitions}'  -- "${COMP_WORDS[COMP_CWORD]}" ) )
            return 0
            ;;
        --role)
            roles=$(ls -1 /etc/xen-tools/role.d/ | xargs echo )
            COMPREPLY=( $( compgen -W '${roles}'  -- "${COMP_WORDS[COMP_CWORD]}" ) )
            return 0
            ;;
        --roledir)
            _filedir -d
            return 0
            ;;
        --swap-dev)
            _filedir
            return 0
            ;;
        --template)
            _filedir
            return 0
            ;;
    esac

    if [[ ${cur} == -* ]] || [[ ${prev} == xen-create-image ]]; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}
complete -F _xen_create_image xen-create-image




#
#  Completion for xen-create-nfs
#
_xen_create_nfs()
{
    local cur prev ip roles dists vgs

    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}

    # Determine arguments dynamically.  Avoids out-of-dateness.
    opts=$(xen-create-nfs --help|grep -- --|awk '{print $1}' |grep -- -- | sort -u)


    case "$prev" in
        --template)
            _filedir
            return 0
            ;;
    esac

    if [[ ${cur} == -* ]]; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}
complete -F _xen_create_nfs xen-create-nfs



#
#  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.
    # Determine arguments dynamically.  Avoids out-of-dateness.
    #
    opts=$(xen-delete-image  --help|grep -- --|awk '{print $1}'|grep -- -- | sort -u)
    opts="${opts} ${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`

    # Determine arguments dynamically.  Avoids out-of-dateness.
    opts=$(xen-update-image  --help|grep -- --|awk '{print $1}'|grep -- -- | sort -u)

    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
        # 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]}"

    # Determine arguments dynamically.  Avoids out-of-dateness.
    opts=$(xen-list-image  --help|grep -- --|awk '{print $1}'|grep -- -- | sort -u)

    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]}

    # Determine arguments dynamically.  Avoids out-of-dateness.
    opts=$(xt-create-xen-config  --help|grep -- --|awk '{print $1}'|grep -- -- | sort -u)


    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]}

    # Determine arguments dynamically.  Avoids out-of-dateness.
    opts=$(xt-customize-image  --help|grep -- --|awk '{print $1}'|grep -- -- | sort -u)

    #
    # Available distributions, from rpmstrap
    #
    if [ -d /usr/lib/rpmstrap/scripts ]; then
       dists=`/bin/ls -1 /usr/lib/rpmstrap/scripts`
    fi

    case "$prev" in
        --dist)
            COMPREPLY=( $( compgen -W '${dists} sid sarge etch lenny'  -- "${COMP_WORDS[COMP_CWORD]}" ) )
            return 0
            ;;
        --location)
            _filedir -d
            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]}

    # Determine arguments dynamically.  Avoids out-of-dateness.
    opts=$(xt-install-image  --help|grep -- --|awk '{print $1}'|grep -- -- | sort -u)


    #
    # Available distributions, from rpmstrap
    #
    if [ -d /usr/lib/rpmstrap/scripts ]; then
       dists=`/bin/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
            ;;
        --dist)
            COMPREPLY=( $( compgen -W '${dists} sid sarge etch lenny'  -- "${COMP_WORDS[COMP_CWORD]}" ) )
            return 0
            ;;
        --install-method)
            COMPREPLY=( $( compgen -W 'copy debootstrap rinse rpmstrap tar'  -- "${COMP_WORDS[COMP_CWORD]}" ) )
            return 0
            ;;
        --location)
            _filedir -d
            return 0
            ;;
    esac

    if [[ ${cur} == -* ]]; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}
complete -F _xt-install-image xt-install-image