File: oci-runtime-tool

package info (click to toggle)
golang-github-opencontainers-runtime-tools 0.9.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,108 kB
  • sloc: sh: 557; makefile: 104
file content (566 lines) | stat: -rwxr-xr-x 12,358 bytes parent folder | download
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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
#!/bin/bash
#
# bash completion file for core oci-runtime-tool commands
#
# This script provides completion of:
#  - commands and their options
#  - filepaths
#
# To enable the completions either:
#  - place this file in /usr/share/bash-completion/completions
#  or
#  - copy this file to e.g. ~/.oci-runtime-tool-completion.sh and add the line
#    below to your .bashrc after bash completion features are loaded
#    . ~/.oci-runtime-tool-completion.sh
#
# Configuration:
#


# Note for developers:
# Please arrange options sorted alphabetically by long name with the short
# options immediately following their corresponding long form.
# This order should be applied to lists, alternatives and code blocks.

__oci-runtime-tool_previous_extglob_setting=$(shopt -p extglob)
shopt -s extglob

__oci-runtime-tool_pos_first_nonflag() {
	local argument_flags=$1

	local counter=$((${subcommand_pos:-${command_pos}} + 1))
	while [ $counter -le $cword ]; do
		if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
			(( counter++ ))
		else
			case "${words[$counter]}" in
				-*)
					;;
				*)
					break
					;;
			esac
		fi
		(( counter++ ))
	done

	echo $counter
}

# Transforms a multiline list of strings into a single line string
# with the words separated by "|".
# This is used to prepare arguments to __oci-runtime-tool_pos_first_nonflag().
__oci-runtime-tool_to_alternatives() {
	local parts=( $1 )
	local IFS='|'
	echo "${parts[*]}"
}

# Transforms a multiline list of options into an extglob pattern
# suitable for use in case statements.
__oci-runtime-tool_to_extglob() {
	local extglob=$( __oci-runtime-tool_to_alternatives "$1" )
	echo "@($extglob)"
}

# Subcommand processing.
# Locates the first occurrence of any of the subcommands contained in the
# first argument. In case of a match, calls the corresponding completion
# function and returns 0.
# If no match is found, 1 is returned. The calling function can then
# continue processing its completion.
#
# TODO if the preceding command has options that accept arguments and an
# argument is equal ot one of the subcommands, this is falsely detected as
# a match.
__oci-runtime-tool_subcommands() {
	local subcommands="$1"

	local counter=$(($command_pos + 1))
	while [ $counter -lt $cword ]; do
		case "${words[$counter]}" in
			$(__oci-runtime-tool_to_extglob "$subcommands") )
				subcommand_pos=$counter
				local subcommand=${words[$counter]}
				local completions_func=_oci-runtime-tool_${command}_${subcommand}
				declare -F $completions_func >/dev/null && $completions_func
				return 0
				;;
		esac
		(( counter++ ))
	done
	return 1
}

# List groups
__oci-runtime-tool_groups() {
	cut -d: -f 1 /etc/group
}

# List installed hooks
__oci-runtime-tool_hooks() {
	ls /usr/libexec/oci/hooks.d/*
}

# suppress trailing whitespace
__oci-runtime-tool_nospace() {
	# compopt is not available in ancient bash versions
	type compopt &>/dev/null && compopt -o nospace
}

__oci-runtime-tool_complete_log_level() {
	COMPREPLY=( $( compgen -W "
		debug
		error
		fatal
		info
		panic
		warn
	" -- "$cur" ) )
}

__oci-runtime-tool_complete_compliance_level() {
	COMPREPLY=( $( compgen -W "
		may
		should
		must
	" -- "$cur" ) )
}

__oci-runtime-tool_complete_propagations() {
	COMPREPLY=( $( compgen -W "
		private
		rprivate
		shared
		rshared
		slave
		rslave
		unbindable
		runbindable
	" -- "$cur" ) )
}

# a selection of the available arches that is most likely of interest in the
# context of oci-runtime-tool containers.
__oci-runtime-tool_complete_seccomp_arches() {
	COMPREPLY=( $( compgen -W "
		x86
		amd64
		x32
		arm
		arm64
		mips
		mips64
		mips64n32
		mipsel
		mipsel64
		mipsel64n32
		ppc
		ppc64
		ppc64le
		s390
		s390x
		parisc
		parisc64
	" -- "$cur" ) )
}

# a selection of the available actions that is most likely of interest in the
# context of oci-runtime-tool containers.
__oci-runtime-tool_complete_seccomp_actions() {
	COMPREPLY=( $( compgen -W "
		allow
		errno
		kill
		trace
		trap
	" -- "$cur" ) )
}
__oci-runtime-tool_complete_capabilities() {
	# The list of capabilities is defined in types.go, ALL was added manually.
	COMPREPLY=( $( compgen -W "
		CAP_ALL
		CAP_AUDIT_CONTROL
		CAP_AUDIT_WRITE
		CAP_AUDIT_READ
		CAP_BLOCK_SUSPEND
		CAP_CHOWN
		CAP_DAC_OVERRIDE
		CAP_DAC_READ_SEARCH
		CAP_FOWNER
		CAP_FSETID
		CAP_IPC_LOCK
		CAP_IPC_OWNER
		CAP_KILL
		CAP_LEASE
		CAP_LINUX_IMMUTABLE
		CAP_MAC_ADMIN
		CAP_MAC_OVERRIDE
		CAP_MKNOD
		CAP_NET_ADMIN
		CAP_NET_BIND_SERVICE
		CAP_NET_BROADCAST
		CAP_NET_RAW
		CAP_SETFCAP
		CAP_SETGID
		CAP_SETPCAP
		CAP_SETUID
		CAP_SYS_ADMIN
		CAP_SYS_BOOT
		CAP_SYS_CHROOT
		CAP_SYSLOG
		CAP_SYS_MODULE
		CAP_SYS_NICE
		CAP_SYS_PACCT
		CAP_SYS_PTRACE
		CAP_SYS_RAWIO
		CAP_SYS_RESOURCE
		CAP_SYS_TIME
		CAP_SYS_TTY_CONFIG
		CAP_WAKE_ALARM
	" -- "$cur" ) )
}


# global options that may appear after the oci-runtime-tool command
_oci-runtime-tool_oci-runtime-tool() {
	local options_with_args="
		--log-level
	"

	local options_with_args="
		--compliance-level
	"

	local boolean_options="
		--help -h
		--host-specific
		--version -v
	"

	local all_options="$options_with_args $boolean_options"

	case "$prev" in
		--log-level)
			__oci-runtime-tool_complete_log_level
			return
			;;
		--compliance-level)
			__oci-runtime-tool_complete_compliance_level
			return
			;;
	esac

	case "$cur" in
		-*)
			COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
			;;
		*)
			local counter=$( __oci-runtime-tool_pos_first_nonflag $(__oci-runtime-tool_to_extglob "$options_with_args") )
			if [ $cword -eq $counter ]; then
				COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) )
			fi
			;;
	esac
}

_oci-runtime-tool_validate() {
	case "$prev" in
		--path)
			case "$cur" in
				*:*)
					# TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
					;;
				'')
					COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
					__oci-runtime-tool_nospace
					;;
				/*)
					_filedir
					__oci-runtime-tool_nospace
					;;
			esac
			return
			;;

		--platform)
 			COMPREPLY=( $( compgen -W "linux solaris windows" -- "$cur" ) ) 
 			return
 			;;
	esac

	case "$cur" in
		-*)
			COMPREPLY=( $( compgen -W "--path --platform --help -h" -- "$cur" ) )
			;;
	esac

}

_oci-runtime-tool_help() {
	local counter=$(__oci-runtime-tool_pos_first_nonflag)
	if [ $cword -eq $counter ]; then
		COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
	fi
}

_oci-runtime-tool_generate() {
	local options_with_args="
		--args
		--env
		--env-file
		--hooks-poststart-add
		--hooks-poststop-add
		--hooks-prestart-add
		--hostname
		--label
		--linux-apparmor
		--linux-blkio-leaf-weight
		--linux-blkio-leaf-weight-device
		--linux-blkio-read-bps-device
		--linux-blkio-read-iops-device
		--linux-blkio-weight
		--linux-blkio-weight-device
		--linux-blkio-write-bps-device
		--linux-blkio-write-iops-device
		--linux-cgroups-path
		--linux-cpu-period
		--linux-cpu-quota
		--linux-cpus
		--linux-cpu-shares
		--linux-device-add
		--linux-device-remove
		--linux-device-cgroup-add
		--linux-device-cgroup-remove
		--linux-gidmappings
		--linux-hugepage-limits-add
		--linux-hugepage-limits-drop
		--linux-intelRdt-l3CacheSchema
		--linux-masked-paths
		--linux-mem-kernel-limit
		--linux-mem-kernel-tcp
		--linux-mem-limit
		--linux-mem-reservation
		--linux-mems
		--linux-mem-swap
		--linux-mem-swappiness
		--linux-mount-label
		--linux-namespace-add
		--linux-namespace-remove
		--linux-network-classid
		--linux-network-priorities
		--linux-oom-score-adj
		--linux-pids-limit
		--linux-readonly-paths
		--linux-realtime-period
		--linux-realtime-runtime
		--linux-rootfs-propagation
		--linux-seccomp-allow
		--linux-seccomp-arch
		--linux-seccomp-default
		--linux-seccomp-default-force
		--linux-seccomp-errno
		--linux-seccomp-kill
		--linux-seccomp-remove
		--linux-seccomp-trace
		--linux-seccomp-trap
		--linux-selinux-label
		--linux-sysctl
		--linux-uidmappings
		--mounts-add
		--mounts-remove
		--oci-version
		--os
		--output
		--process-cap-add
		--process-cap-add-ambient
		--process-cap-add-bounding
		--process-cap-add-effective
		--process-cap-add-inheritable
		--process-cap-add-permitted
		--process-cap-drop
		--process-cap-drop-ambient
		--process-cap-drop-bounding
		--process-cap-drop-effective
		--process-cap-drop-inheritable
		--process-cap-drop-permitted
		--process-consolesize
		--process-cwd
		--process-gid
		--process-groups
		--process-rlimits-add
		--process-rlimits-remove
		--process-uid
		--process-username
		--rootfs-path
		--solaris-anet
		--solaris-capped-cpu-ncpus
		--solaris-capped-memory-physical
		--solaris-capped-memory-swap
		--solaris-limitpriv1
		--solaris-max-shm-memory
		--solaris-milestone
		--template
		--vm-hypervisor-parameters
		--vm-hypervisor-path
		--vm-image-format
		--vm-image-path
		--vm-kernel-initrd
		--vm-kernel-parameters
		--vm-kernel-path
		--windows-devices
		--windows-hyperv-utilityVMPath
		--windows-layer-folders
		--windows-network
		--windows-network-networkNamespace
		--windows-resources-cpu
		--windows-resources-memory-limit
		--windows-resources-storage
	"

	local boolean_options="
		--help -h
		--hooks-poststart-remove-all
		--hooks-poststop-remove-all
		--hooks-prestart-remove-all
		--linux-device-remove-all
		--linux-disable-oom-kill
		--linux-namespace-remove-all
		--linux-seccomp-only
		--linux-seccomp-remove-all
		--mounts-remove-all
		--privileged
		--process-cap-drop-all
		--process-no-new-privileges
		--process-rlimits-remove-all
		--process-terminal
		--rootfs-readonly
		--windows-ignore-flushes-during-boot
		--windows-network-allowunqualifieddnsquery
		--windows-servicing
	"

	local all_options="$options_with_args $boolean_options"

	case "$prev" in
		--env|-e)
			COMPREPLY=( $( compgen -e -- "$cur" ) )
			__oci-runtime-tool_nospace
			return
			;;

		--env-file)
			_filedir
			__oci-runtime-tool_nospace
			return
			;;

		--hooks-poststart-add|--hooks-poststop-add|--hooks-prestart-add)
			COMPREPLY=( $( compgen -W "$( __oci-runtime-tool_hooks )" -- "$cur" ) )
			__oci-runtime-tool_nospace
			return
			;;

		--linux-rootfs-propagation)
			__oci-runtime-tool_complete_propagations
			return
			;;

		--linux-seccomp-arch)
			__oci-runtime-tool_complete_seccomp_arches
			return
			;;

		--linux-seccomp-default)
			__oci-runtime-tool_complete_seccomp_actions
			return
			;;

		--process-cap-add-ambient|--process-cap-add-bounding|--process-cap-add-effective|--process-cap-add-inheritable|--process-cap-add-permitted|--process-cap-drop-ambient|--process-cap-drop-bounding|--process-cap-drop-effective|--process-cap-drop-inheritable|--process-cap-drop-permitted)
			__oci-runtime-tool_complete_capabilities
			return
			;;

		--process-gid)
			_gids
			return
			;;

		--process-groups)
			COMPREPLY=( $( compgen -W "$( __oci-runtime-tool_groups )" -- "$cur" ) )
			__oci-runtime-tool_nospace
			return
			;;

		--process-uid)
			_uids
			return
			;;

		--rootfs-path|--process-cwd)
			case "$cur" in
				*:*)
					# TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine)
					;;
				'')
					COMPREPLY=( $( compgen -W '/' -- "$cur" ) )
					__oci-runtime-tool_nospace
					;;
				*)
					_filedir
					__oci-runtime-tool_nospace
					;;
			esac
			return
			;;
	esac

	case "$cur" in
		-*)
			COMPREPLY=( $( compgen -W "$all_options" -- "$cur" ) )
			;;
	esac
}

_oci-runtime-tool() {
	local previous_extglob_setting=$(shopt -p extglob)
	shopt -s extglob

	local commands=(
		validate
		generate
	)

	COMPREPLY=()
	local cur prev words cword
	_get_comp_words_by_ref -n : cur prev words cword

	local command='oci-runtime-tool' command_pos=0 subcommand_pos
	local counter=1
	while [ $counter -lt $cword ]; do
		case "${words[$counter]}" in
			-*)
				;;
			=)
				(( counter++ ))
				;;
			*)
				command="${words[$counter]}"
				command_pos=$counter
				break
				;;
		esac
		(( counter++ ))
	done

	local completions_func=_oci-runtime-tool_${command}
	declare -F $completions_func >/dev/null && $completions_func

	eval "$previous_extglob_setting"
	return 0
}

eval "$__oci-runtime-tool_previous_extglob_setting"
unset __oci-runtime-tool_previous_extglob_setting

complete -F _oci-runtime-tool oci-runtime-tool