1#compdef linux uml_moo uml_mconsole uml_switch tunctl
2
3local curcontext="$curcontext" state st line expl suf ret=1
4typeset -A opt_args
5
6case $service in
7  uml_moo)
8    _arguments '1:COW file:_files -g "*cow*(-.)"' '2:new backing file:_files'
9    return
10  ;;
11  uml_switch)
12    _arguments \
13      '-unix[listen on specified pair of sockets]:control socket: :data socket' \
14      '-hub[act like a hub]'
15    return
16  ;;
17  uml_mconsole)
18    if (( CURRENT == 2 )); then
19      _wanted socket expl 'socket name' compadd {~/.uml,/tmp}/*/mconsole(N=:h:t) && ret=0
20    elif [[ $words[CURRENT-1] = config ]]; then
21      if [[ -prefix ubd || -prefix eth ]]; then
22        state=option
23      else
24        _wanted device expl device compadd -S '' ubd eth && ret=0
25      fi
26    elif [[ $words[CURRENT-1] = remove ]]; then
27      _wanted device expl device compadd ubd{0..7} eth{0..9} && ret=0
28    elif (( CURRENT == 3 )); then
29      _values 'command' \
30        'version[print the UML kernel version number]' \
31	'help[print help]' \
32	'halt[shutdown UML system immediately]' \
33	'reboot[reboot the UML system immediately]' \
34	'config[add a new device to the virtual machine]' \
35	'remove[delete a device from the virtual machine]' \
36	'sysrq[perform sysrq action]:key:((r\:turn\ of\ keyboard\ raw\ mode k\:secure\ access\ key b\:reboot o\:shutdown s\:sync u\:remount p\:dump\ registers t\:dump\ tasks m\:dump\ memory e\:SIGTERM\ to\ all i\:SIGKILL\ to\ all l\:SIGKILL\ to\ all\ inc.\ init h\:help {0..9}\:console\ log\ level))' \
37	'cad[invoke ctrl-alt-del handler]' \
38	'stop[pause the UML]' \
39	'go[continue the UML]' \
40	&& ret=0
41    else
42      _message 'no more arguments'
43    fi
44  ;;
45  linux)
46    _arguments -C \
47      '(* -)--version[display kernel version number]' \
48      '(* -)--help[print usage information]' \
49      '(* -)--showconfig[show kernel configuration]' \
50      '(-)*:option:->option' && ret=0
51  ;;
52  tunctl)
53    _arguments \
54      '(-d)-b[brief output]' \
55      '-f[specify tun clone device]:tun clone device:_files' \
56      '(-d)-u[specify owner]:owner:_users' \
57      '(-b -u -t)-d[specify devicename to delete]:device name:(tap{0..9})' \
58      '(-d)-t[specify devicename]:device name:(tap{0..9})'
59    return
60  ;;
61esac
62
63while [[ -n $state ]]; do
64  st=$state
65  unset state
66  case $st in
67    option)
68      if compset -P '(ssl|con)[0-9]#='; then
69        state=channel
70	continue
71      elif compset -P con; then
72	_message -e consoles 'console number'
73	return
74      elif compset -P ssl; then
75	_message -e serial 'serial line number'
76	return
77      elif compset -P 'ubd[0-7](|r)(|s)='; then
78        compset -P '*,'
79        _files && return
80      elif compset -P ubd; then
81        _message -e devices 'device number'
82	return
83      elif compset -P 'eth[0-9]##='; then
84        if compset -P 1 '*,'; then
85	  _message -e options option
86	else
87	  _wanted transports expl transports compadd -S, \
88	    ethertap tuntap daemon mcast slip && return
89        fi
90	return
91      elif compset -P eth; then
92        _message -e ethernet number
93	return
94      fi
95      compadd -n -S '' con ssl ubd eth && ret=0
96      _values -C -w "option" \
97	'mem[specify amount of "physical" memory to allocate]:memory' \
98	'iomem[configure file as named IO memory region]:arg:->iomem' \
99	'gdb[attach gdb to specified channel]:channel:->channel' \
100	'gdb-pid[specify pid of debugger]:debugger pid:_pids' \
101	'debugtrace[cause tracing thread to wait for debugger]' \
102	'honeypot[put process stacks in the same location as on host]' \
103	'debug[start kernel under gdb control]' \
104	'root[specify root filesystem]:root device' \
105	'umid[specify name for this UML machine]:name' \
106	'uml_dir[location to place pid and umid files]:directory:_directories' \
107	'initrd[boot from initrd image]:initrd file:_files' \
108	'jail[enable protection of kernel memory from processes]' \
109	'*con[attach a console to a host channel]:channel:->channel' \
110	'*ssl[attach a serial line to a host channel]:channel:->channel' \
111	'fake_ide[create ide0 entries which map onto ubd devices]' \
112	'*ubd[associate device with host file]' \
113	'fakehd[change the ubd device name to "hd"]' \
114	'*eth[configure a network device]' \
115	'ncpus[specify number of virtual processors to start]:processors' \
116	'mode[force UML to run in specified mode]:mode:(tt)' \
117	'mconsole[request mconsole driver to send a message to socket]:socket' \
118	'xterm[specify alternate terminal emulator]:terminal emulator:->xterm' \
119	'dsp[specify host dsp device]:dsp device:_files' \
120	'mixer[specify host mixer device]:mixer device:_files' \
121	'umn[specify ip address for host side of slip device]' && ret=0
122    ;;
123    iomem)
124      if compset -P '*,'; then
125	_files && ret=0
126      else
127	_message -e name
128      fi
129    ;;
130    channel)
131      compset -P '*,' || suf=( -S , )
132      _values -S : ${suf/S/s} "channel" \
133	pty pts xterm \
134	'tty:tty:_files $suf' \
135	"fd:file descriptor:_file_descriptors $suf" && ret=0
136    ;;
137    xterm)
138      if compset -P 2 '*,'; then
139        _wanted -x argument expl 'execute switch' compadd - -e -x && ret=0
140      elif compset -P 1 '*,'; then
141        _wanted -x argument expl 'title switch' compadd -S , - -t -T -title && ret=0
142      else
143        _wanted command expl 'terminal emulator' _command_names -e -S , && ret=0
144      fi
145    ;;
146  esac
147done
148
149return ret
150