summaryrefslogtreecommitdiff
blob: e130d4c8f26a24ce52eba2b4b60c46be7fea793d (plain)
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
Index: contrib/bash_completion
===================================================================
--- /dev/null
+++ contrib/bash_completion
@@ -0,0 +1,300 @@
+# Completion for the vserver command. Source this file (or on some systems
+# add it to ~/.bash_completion and start a new shell) and bash's completion
+# mechanism will know all about vserver's options!
+#
+# Copyright (C) Thomas Champagne <lafeuil@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# The latest version of this software can be obtained here:
+#
+# http://linux-vserver.org/Vserver+Completion
+#
+# version 0.4.0
+
+have vserver-info && {
+: ${UTIL_VSERVER_VARS:=$(vserver-info - SYSINFO |grep prefix: | awk '{ print $2}')/lib/util-vserver/util-vserver-vars}
+
+test -e "$UTIL_VSERVER_VARS" && {
+
+. "$UTIL_VSERVER_VARS"
+. "$_LIB_FUNCTIONS"
+
+_vserver() {
+	local cur cmds cmdOpts cmdMethodOpts helpCmds names names_pipe func i j method
+
+	COMPREPLY=()
+	cur=${COMP_WORDS[COMP_CWORD]}
+
+	# find available vServers:
+	# call function getAllVservers in vserver library
+	getAllVservers names
+	names_pipe=`echo ${names[@]} | sed 's/ /|/g'`
+
+	# available commands
+	cmds='start stop restart condrestart suexec exec enter chkconfig \
+	running status unify pkg apt-get apt-config apt-cache \
+	rpm pkgmgmt delete'
+
+	# options (long and short name)
+	cmdOpts='--help --version --debug --defaulttty -s --sync -v \
+	--verbose --silent --'
+
+	cmdMethodOpts='-m -n --context --confdir --lockfile \
+	--hostname --netdev --netbcast --netmask \
+	--netprefix --interface --cpuset \
+	--cpusetcpus --cpusetmems --cpusetvirt \
+	--initstyle --flags --help --'
+
+	# if the previous option is a single option
+	helpCmds='--help|--version'
+	if [[ ${COMP_WORDS[1]} == @($helpCmds) ]] ; then
+		return 0
+	fi
+
+	# lookup the vServer name
+	for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
+		if [[ ${COMP_WORDS[i]} == @($names_pipe) ]] ; then
+			# found it!
+			break
+		fi
+	done
+
+	#a vserver has been found
+	if (( $i < ${#COMP_WORDS[@]}-1 )) ; then
+		# Show the vserver command without build
+		case "${COMP_WORDS[i+1]}" in
+			start)
+				COMPREPLY=( $( compgen -W "--rescue --rescue-cmd" -- $cur ) )
+				;;
+			# No completion for apt-config
+			stop|restart|condrestart|enter|running|status|apt-config|delete)
+				;;
+			suexec)
+				# I don't know how to do
+				COMPREPLY=( $( compgen -W  -- $cur ) )
+				;;
+			exec)
+				#I don't know how to do
+				COMPREPLY=( $( compgen -W "" -- $cur ) )
+				;;
+			unify)
+				COMPREPLY=( $( compgen -W "-R" -- $cur ) )
+				;;
+			apt-get|apt-cache)
+				func=${COMP_WORDS[i+1]}
+				COMP_WORDS=( ${COMP_WORDS[@]:$((i+1))} )
+				COMP_CWORD=$((COMP_CWORD-i-1))
+				declare -f _${func//-/_} > /dev/null && _${func//-/_}
+				;;
+			*)
+				COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
+				;;
+		esac
+		return 0
+	else
+		#no vserver name found
+		prev=${COMP_WORDS[COMP_CWORD-1]}
+
+		#search the new name of vserver
+		for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )) ; do
+			if [[ ${COMP_WORDS[i]} == !(vserver|-*) ]] ; then
+				# found it!
+				break
+			fi
+		done
+
+		if (( $i < ${#COMP_WORDS[@]}-1 )) ; then
+			j=$i
+			i=${#COMP_WORDS[@]}
+			for (( ; j < ${#COMP_WORDS[@]}-1; j++ )) ; do
+				if [[ ${COMP_WORDS[j]} == "--" ]];  then
+					# method's parameter
+					case "$method" in
+						legacy|copy)
+							;;
+						apt-rpm)
+							COMPREPLY=( $( compgen -W "-d" -- $cur ) )
+							;;
+						yum)
+							COMPREPLY=( $( compgen -W "-d" -- $cur ) )
+							;;
+						rpm)
+							COMPREPLY=( $( compgen -W "-d --empty --force --nodeps" -- $cur ) )
+							;;
+						skeleton)
+							;;
+						debootstrap)
+							COMPREPLY=( $( compgen -W "-d -m -s --" -- $cur ) )
+							;;
+						*)
+							;;
+					esac
+					return 0
+					break
+				fi
+
+				if [[ ${COMP_WORDS[j]} == @(build|-m) ]];  then
+					i=$j
+					if (( $j+1 < ${#COMP_WORDS[@]}-1 )) ; then
+						method=${COMP_WORDS[j+1]}
+					fi
+				fi
+			done
+
+			if (( $i < ${#COMP_WORDS[@]}-1 )) ; then
+				case $prev in
+					--help)
+						;;
+					-n|--context|--confdir|--lockfile|--hostname|--netdev|--netbcast|--netmask|--netprefix|--interface|--cpuset|--cpusetcpus|--cpusetmems|--cpusetvirt|--initstyle|--flags)
+						COMPREPLY=( $( compgen -W "" -- $cur ) )
+						;;
+					-m)
+						COMPREPLY=( $( compgen -W "legacy copy apt-rpm yum rpm skeleton debootstrap" -- $cur ) )
+						;;
+					*)
+						COMPREPLY=( $( compgen -W "$cmdMethodOpts" -- $cur ) )
+						;;
+				esac
+			else
+				COMPREPLY=( $( compgen -W "build" -- $cur ) )
+			fi
+		else
+			COMPREPLY=( $( compgen -W "${names[@]} $cmdOpts" -- $cur ) )
+		fi
+
+		return 0
+	fi
+
+	return 0
+}
+
+complete -F _vserver vserver
+
+_vapt_rpm_yum()
+{
+	local cur cmds cmdOpts helpCmds names func i
+
+	COMPREPLY=()
+	cur=${COMP_WORDS[COMP_CWORD]}
+
+	# options (long and short name)
+	cmdOpts='--help --version --quiet -q --all'
+
+	# if the previous option is a single option
+	helpCmds='--help|--version'
+
+	if [[ "${COMP_WORDS[1]}" == "@($helpCmds)" ]] ; then
+		return 0
+	fi
+
+	# search --
+	for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )) ; do
+		if [[ ${COMP_WORDS[i]} = "--" ]] ; then
+			# found it!
+			break
+		fi
+	done
+
+	# find available vServers
+	# call function getAllVservers in vserver library
+	getAllVservers names
+	names_pipe=`echo ${names[@]}" --all" | sed 's/ /|/g'`
+
+	if (( $i < ${#COMP_WORDS[@]}-1 )) && (( $i < $COMP_CWORD )) ; then
+		func=${COMP_WORDS[0]:1}
+		COMP_WORDS=( $func ${COMP_WORDS[@]:$((i+1))} )
+		COMP_CWORD=$((COMP_CWORD-i))
+		declare -f _${func//-/_} > /dev/null && _${func//-/_}
+	else
+		# search vServer name
+		for (( i=0; i <  ${#COMP_WORDS[@]}-1; i++ )) ; do
+			if [[ ${COMP_WORDS[i]} == @($names_pipe) ]] ; then
+				# found it!
+				break
+			fi
+		done
+
+		if (( $i < ${#COMP_WORDS[@]}-1 )) ; then
+			if [[ "${COMP_WORDS[i]}" = "--all"  ]] ; then
+				cmdOpts='--'
+				COMPREPLY=( $( compgen -W "$cmdOpts" -- $cur ) )
+			else
+				cmdOpts='--'
+				COMPREPLY=( $( compgen -W "${names[@]} $cmdOpts" -- $cur ) )
+			fi
+		else
+			COMPREPLY=( $( compgen -W "${names[@]} $cmdOpts" -- $cur ) )
+		fi
+	fi
+
+	return 0
+}
+
+_vserver_copy()
+{
+	local cur prev cmdOpts helpCmds confCmds names names_pipe i
+
+	COMPREPLY=()
+	cur=${COMP_WORDS[COMP_CWORD]}
+
+	# find available vServers
+	# call function getAllVservers in vserver library
+	getAllVservers names
+	names_pipe=`echo ${names[@]} | sed 's/ /|/g'`
+
+	# options (long and short name)
+	cmdOpts='--help -h --version -V --verbose -v --quiet -q \
+		 --vsroot -r --rsh -R --stopstart -s \
+		 --domain -d --ip -i'
+
+	# if the previous option is a single option
+	helpCmds='--help|-h|--version|-V'
+
+	if [[ ${COMP_WORDS[1]} == @($helpCmds) ]] ; then
+		return 0
+	fi
+
+	confCmds='--ip|-i|--domain|-d'
+	prev=${COMP_WORDS[COMP_CWORD-1]}
+
+	if [[ $prev == @($confCmds) ]] ; then
+		return 0
+	fi
+
+	# search a vServer name
+	for (( i=0; i <  ${#COMP_WORDS[@]}-1; i++ )); do
+		if [[ ${COMP_WORDS[i]} == @($names_pipe) ]] ; then
+			# found it!
+			break
+		fi
+	done
+
+	if (( $i < ${#COMP_WORDS[@]}-1 )) ; then
+		return 0
+	else
+		COMPREPLY=( $( compgen -W "${names[@]} $cmdOpts" -- $cur ) )
+	fi
+
+	return 0
+}
+
+complete -F _vapt_rpm_yum vapt-get
+complete -F _vapt_rpm_yum vrpm
+complete -F _vapt_rpm_yum vyum
+complete -F _vserver_copy vserver-copy
+
+}
+}
Index: contrib/zsh_completion
===================================================================
--- /dev/null
+++ contrib/zsh_completion
@@ -0,0 +1,188 @@
+#compdef vserver
+
+#  Copyright (C) 2005 intrigeri@boum.org - property is theft !
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License along
+#  with this program; if not, write to the Free Software Foundation, Inc.,
+#  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+# ,----
+# | NOTES
+# `----
+#
+#   - SVN version: $Id$
+#   - $URL$
+#   - Tested on Debian GNU/Linux with util-vserver 0.30.209.
+#
+# ,----
+# | TODO
+# `----
+#   - Use util-vserver shell functions library, as does the Bash
+#     completion script found on /usr/lib/util-vserver/functions
+#   - Implement commands arguments completion.
+#
+
+###
+### Main completion function
+###
+
+_vserver () {
+
+  # local variables
+  local curcontext="$curcontext" state line expl ret=1
+  local cmd=$words[3]
+
+  # dispatch
+  case "$cmd" in
+    apt-cache|apt-config|apt-get)
+      compset -n 3
+      _dispatch $cmd:t $cmd $cmd:t -default- && ret=0
+      ;;
+    exec)
+      _arguments -C \
+	'1: :->vsnames' \
+	'2: :->cmds' \
+	'3:command name: _command_names -e'  \
+	'*::arguments: _normal' && ret=0
+      ;;
+    stop|restart|condrestart|enter|running|status)
+      _arguments -C \
+	'1: :->vsnames' \
+	'2: :->cmds' \
+	'*::arguments: _message "no more arguments"' && ret=0
+      ;;
+    *)
+      _arguments -C \
+	'(-)--help[print help information]' \
+	'(- *)--version[print client version information]' \
+	'1: :->vsnames' \
+	'2: :->cmds' \
+	'*:: :->args' && ret=0
+      ;;
+  esac
+
+  # cache initialization
+  if [[ -n "$state" ]]; then
+    if (( ! $+_cache_vserver_cfgdir )); then
+      typeset -g _cache_vserver_cfgdir_initialized
+      _vserver_cache_cfgdir
+    fi
+    if (( ! $+_cache_vserver_vsnames )); then
+      typeset -g _cache_vserver_vsnames_initialized
+      _vserver_cache_vsnames
+    fi
+    if (( ! $+_cache_vserver_cmds )); then
+      typeset -g _cache_vserver_cmds_initialized
+      _vserver_cache_cmds
+    fi
+  fi
+
+  case "$state" in
+    vsnames)
+      _wanted commands expl 'vserver name' _vserver_vsnames && ret=0
+      ;;
+    cmds)
+      _wanted commands expl 'vserver command' _vserver_commands && ret=0
+      ;;
+    args)
+      local args
+      if $+args; then
+	_arguments "$args[@]" && ret=0
+      else
+	ret=0
+      fi
+      ;;
+  esac
+
+  return ret
+}
+
+###
+### Auxiliary completion functions
+###
+
+(( $+functions[_vserver_commands] )) ||
+_vserver_commands() {
+  compadd "$@" -k _cache_vserver_cmds || compadd "$@" ${(s.:.)_cache_vserver_cmds}
+}
+
+(( $+functions[_vserver_vsnames] )) ||
+_vserver_vsnames() {
+  local expl
+  _wanted vserver expl 'vserver name' compadd -S '' $_cache_vserver_vsnames[@]
+}
+
+###
+### Cache functions
+###
+
+(( $+functions[_vserver_cache_cfgdir] )) ||
+_vserver_cache_cfgdir() {
+  if [[ "$_cache_vserver_cfgdir_initialized" != true ]]; then
+    typeset -ga _cache_vserver_cfgdir
+    _cache_vserver_cfgdir=`vserver-info info SYSINFO | grep '^ *cfg-Directory' | awk '{print $2}'`
+    _cache_vserver_cfgdir_initialized=true
+  fi
+}
+
+(( $+functions[_vserver_cache_vsnames] )) ||
+_vserver_cache_vsnames() {
+  if [[ "$_cache_vserver_vsnames_initialized" != true ]]; then
+    typeset -ga _cache_vserver_vsnames
+    _cache_vserver_vsnames=( $(ls -d $_cache_vserver_cfgdir/*/ | sed -e s,$_cache_vserver_cfgdir,, | tr -d '/') )
+    _cache_vserver_vsnames_initialized=true
+  fi
+}
+
+(( $+functions[_vserver_cache_cmds] )) ||
+_vserver_cache_cmds() {
+  if [[ "$_cache_vserver_cmds_initialized" != true ]]; then
+    typeset -ga _cache_vserver_cmds
+      _cache_vserver_cmds=(
+      start
+      stop
+      restart
+      condrestart
+      suexec
+      exec
+      enter
+      chkconfig
+      running
+      status
+      build
+      unify
+      pkg
+      apt-get
+      apt-config
+      apt-cache
+      rpm
+      pkgmgmt
+    )
+    _cache_vserver_cmds_initialized=true
+  fi
+}
+
+###
+### Main function call
+###
+
+_vserver "$@"
+
+###
+### Emacs variables
+###
+
+# Local Variables:
+# mode:sh
+# sh-basic-offset: 2
+# End: