]> git.ipfire.org Git - people/ms/network.git/blame - src/bash-completion/network
ipsec: Generate IKE proposals with PRFs
[people/ms/network.git] / src / bash-completion / network
CommitLineData
bae37360
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2014 Michael Tremer #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
21# network(8) completion
22
1c6a4e30 23_network_find_on_cmdline () {
bae37360
MT
24 local word subcommand c=0
25 while [ ${c} -lt ${cword} ]; do
26 word="${words[c]}"
27 for subcommand in ${1}; do
28 if [ "${subcommand}" = "${word}" ]; then
29 echo "${subcommand}"
30 return
31 fi
32 done
33 ((c++))
34 done
35}
36
1c6a4e30 37_network_complete_hooks() {
bae37360
MT
38 local type="${1}"
39
40 COMPREPLY=( $(compgen -W "$(network raw list-hooks "${type}")" -- "${cur}") )
41}
42
1c6a4e30 43_network_complete_ports() {
bae37360
MT
44 COMPREPLY=( $(compgen -W "$(network raw list-ports)" -- "${cur}") )
45}
46
1c6a4e30 47_network_complete_zones() {
bae37360
MT
48 COMPREPLY=( $(compgen -W "$(network raw list-zones)" -- "${cur}") )
49}
50
b7fbb0cd
JS
51_network_color() {
52 local words=( $@ )
53
54 local commands="set reset"
55 local cmd="$(_network_find_on_cmdline "${commands}")"
56 if [[ -z "${cmd}" ]]; then
57 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
58 return 0
59 fi
60}
61
9d3ac4e4
JS
62_network_description() {
63 local words=( $@ )
64
65 local commands="edit show"
66 local cmd="$(_network_find_on_cmdline "${commands}")"
67 if [[ -z "${cmd}" ]]; then
68 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
69 return 0
70 fi
71}
1c6a4e30 72_network_device() {
bae37360
MT
73 local words=( $@ )
74
75 local commands="list $(network raw list-devices)"
76 local cmd="$(_network_find_on_cmdline "${commands}")"
77 if [[ -z "${cmd}" ]]; then
78 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
79 return 0
80 fi
81
82 local args="${words[@]:1}"
83 case "${cmd}" in
84 list)
85 return 0
86 ;;
87 *)
88 _network_device_subcommand ${args}
89 ;;
90 esac
91}
92
1c6a4e30 93_network_device_subcommand() {
bae37360
MT
94 local words=( $@ )
95
f5ee091e 96 local commands="discover identify monitor status unlock ussd"
bae37360 97 local cmd="$(_network_find_on_cmdline "${commands}")"
bae37360 98 if [[ -z "${cmd}" ]]; then
8d1d2745 99 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
bae37360
MT
100 return 0
101 fi
b7fbb0cd 102
bae37360
MT
103 case "${cmd}" in
104 ussd)
105 # TODO
106 ;;
107 esac
108}
109
1c6a4e30 110_network_dhcpd() {
cc02f6be
MT
111 local proto="${1}"
112 shift
113
114 local words=( $@ )
115
116 local commands="edit reload restart show start stop subnet"
117 local cmd="$(_network_find_on_cmdline "${commands}")"
118 if [[ -z "${cmd}" ]]; then
119 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
120 return 0
121 fi
122
123 local args="${words[@]:1}"
124 case "${cmd}" in
125 subnet)
126 _network_dhcpd_subnet "${proto}" ${args}
127 ;;
128 esac
129}
130
1c6a4e30 131_network_dhcpd_subnet() {
cc02f6be
MT
132 local proto="${1}"
133 shift
134
135 local words=( $@ )
136
137 local commands="new remove show $(network raw list-dhcpd-subnets "${proto}")"
138 local cmd="$(_network_find_on_cmdline "${commands}")"
139 if [[ -z "${cmd}" ]]; then
140 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
141 return 0
142 fi
143
144 local subnet="${words[0]}"
145 local args="${words[@]:1}"
146 case "${cmd}" in
147 new)
148 : # TODO
149 ;;
150 remove)
151 : # TODO
152 ;;
153 [0-9]*)
154 _network_dhcpd_subnet_subcommand "${proto}" "${subnet}" ${args}
155 ;;
156 esac
157}
158
1c6a4e30 159_network_dhcpd_subnet_subcommand() {
cc02f6be
MT
160 local proto="${1}"
161 local subnet="${2}"
162 shift 2
163
164 local words=( $@ )
165
166 local commands="edit options range show"
167 local cmd="$(_network_find_on_cmdline "${commands}")"
168 if [[ -z "${cmd}" ]]; then
169 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
170 return 0
171 fi
172
173 local args="${words[@]:1}"
174 case "${cmd}" in
175 edit)
176 : # TODO
177 ;;
178 options)
179 _network_dhcpd_subnet_subcommand_options "${proto}" "${subnet}" ${args}
180 ;;
181 range)
182 _network_dhcpd_subnet_subcommand_range "${proto}" "${subnet}" ${args}
183 ;;
184 esac
185}
186
1c6a4e30 187_network_dhcpd_subnet_subcommand_options() {
cc02f6be
MT
188 local proto="${1}"
189 local subnet="${2}"
190 shift 2
191
192 local options option
193 for option in $(network raw list-dhcpd-subnet-options "${proto}"); do
194 options="${options} ${option}="
195 done
196
197 COMPREPLY=( $(compgen -W "${options}" -- "${cur}") )
198}
199
1c6a4e30 200_network_dhcpd_subnet_subcommand_range() {
cc02f6be
MT
201 local proto="${1}"
202 local subnet="${2}"
203 shift 2
204
205 local words=( $@ )
206
207 local commands="new remove"
208 local cmd="$(_network_find_on_cmdline "${commands}")"
209 if [[ -z "${cmd}" ]]; then
210 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
211 return 0
212 fi
213
214 case "${cmd}" in
215 new)
216 COMPREPLY=( $(compgen -W "--end= --start=" -- "${cur}") )
217 ;;
218 remove)
219 COMPREPLY=( $(compgen -W "$(network raw list-dhcpd-ranges-of-subnet "${proto}" "${subnet}")" \
220 -- "${cur}") )
221 ;;
222 esac
223}
224
1c6a4e30 225_network_dns_server() {
8d1d2745
MT
226 local words=( $@ )
227
228 local commands="add list remove update"
229 local cmd="$(_network_find_on_cmdline "${commands}")"
230 if [[ -z "${cmd}" ]]; then
231 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
232 return 0
233 fi
234
235 case "${cmd}" in
236 remove)
237 COMPREPLY=( $(compgen -W "$(network raw list-dns-servers)" \
238 -- "${cur}") )
239 ;;
240 esac
241}
242
1c6a4e30 243_network_port() {
bae37360
MT
244 local words=( $@ )
245
246 local commands="new destroy $(network raw list-ports)"
247 local cmd="$(_network_find_on_cmdline "${commands}")"
248 if [[ -z "${cmd}" ]]; then
249 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
250 return 0
251 fi
252
253 local args="${words[@]:1}"
254 case "${cmd}" in
255 new)
256 _network_complete_hooks "port"
257 ;;
258 destroy)
259 _network_complete_ports
260 ;;
261 *)
262 local args="${words[@]:1}"
263 _network_port_subcommand ${args}
264 ;;
265 esac
266}
267
1c6a4e30 268_network_port_subcommand() {
bae37360
MT
269 local words=( $@ )
270
9d3ac4e4 271 local commands="color create description down edit identify remove status up"
bae37360
MT
272 local cmd="$(_network_find_on_cmdline "${commands}")"
273 if [[ -z "${cmd}" ]]; then
274 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
275 return 0
276 fi
b7fbb0cd
JS
277
278 local args="${words[@]:1}"
279 case "${cmd}" in
280 color)
281 _network_color ${args}
282 ;;
9d3ac4e4
JS
283 description)
284 _network_description ${args}
285 ;;
b7fbb0cd
JS
286 esac
287
bae37360
MT
288}
289
1c6a4e30 290_network_route() {
8d1d2745
MT
291 local words=( $@ )
292
240367ba
JS
293 local commands="static"
294 local cmd="$(_network_find_on_cmdline "${commands}")"
295 if [[ -z "${cmd}" ]]; then
296 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
297 return 0
298 fi
299
300 case "${cmd}" in
301 static)
302 local args="${words[@]}"
303 _network_route_static ${args}
304 ;;
305 esac
306
307}
308
309_network_route_static() {
310 local words=( $@ )
311
86c225b8 312 local commands="add list remove reload"
8d1d2745
MT
313 local cmd="$(_network_find_on_cmdline "${commands}")"
314 if [[ -z "${cmd}" ]]; then
315 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
316 return 0
317 fi
318
319 case "${cmd}" in
320 add)
321 if [[ "${cur}" = -* ]]; then
322 COMPREPLY=( $(compgen -W "--blackhole --gateway= --mtu= \
323 --prohibit --unreachable" -- "${cur}") )
324 fi
325 ;;
326 list)
327 # TODO auto-complete options like --protocol here
328 COMPREPLY=( $(compgen -W "--protocol=" -- "${cur}") )
329 ;;
330 esac
331}
332
1c6a4e30 333_network_settings() {
bae37360
MT
334 local words=( $@ )
335
336 local key keys
337 for key in $(network raw list-settings); do
338 keys="${keys} ${key}="
339 done
340 COMPREPLY=( $(compgen -W "${keys}" -- "${cur}") )
341}
342
93097eca
JS
343_network_vpn() {
344 local words=( $@ )
345
98699861 346 local commands="ipsec security-policies"
93097eca
JS
347 local cmd="$(_network_find_on_cmdline "${commands}")"
348 if [[ -z "${cmd}" ]]; then
349 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
350 return 0
351 fi
352
353
354 local args="${words[@]:1}"
355 case "${cmd}" in
356 ipsec)
357 _network_vpn_ipsec ${args}
358 ;;
98699861
JS
359 security-policies)
360 _network_vpn_security_policies ${args}
361 ;;
93097eca
JS
362 esac
363}
364
365_network_vpn_ipsec() {
366 local words=( $@ )
367
368 local commands="connection"
369 local cmd="$(_network_find_on_cmdline "${commands}")"
370 if [[ -z "${cmd}" ]]; then
371 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
372 return 0
373 fi
374
375
376 local args="${words[@]:1}"
377 case "${cmd}" in
378 connection)
379 _network_vpn_ipsec_connection ${args}
380 ;;
381 esac
382}
383
384_network_vpn_ipsec_connection() {
385 local words=( $@ )
386
387 local commands="destroy new $(network raw list-ipsec-connections)"
388 local cmd="$(_network_find_on_cmdline "${commands}")"
389 if [[ -z "${cmd}" ]]; then
390 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
391 return 0
392 fi
393
394
395 local args="${words[@]:1}"
396 case "${cmd}" in
397 destroy)
398 :
399 ;;
400 new)
401 :
402 ;;
403 *)
404 if network raw ipsec-connection-exists ${cmd}; then
405 _network_vpn_ipsec_connection_subcommands ${cmd} ${args}
406 fi
407 ;;
408 esac
409}
410
411_network_vpn_ipsec_connection_subcommands() {
412 local connection=${1}
413 shift
414 local words=( $@ )
415
dc5dcfaf 416 local commands="authentication color description down inactivity-timeout local mode peer remote security-policy show up"
93097eca
JS
417 local cmd="$(_network_find_on_cmdline "${commands}")"
418 if [[ -z "${cmd}" ]]; then
419 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
420 return 0
421 fi
422
423
424 local args="${words[@]:1}"
425 case "${cmd}" in
426 authentication)
427 _network_vpn_ipsec_connection_subcommands_authentication ${connection} ${args}
428 ;;
5bcadc60
JS
429 color)
430 _network_color ${args}
431 ;;
dc5dcfaf
JS
432 description)
433 _network_description ${args}
434 ;;
93097eca
JS
435 local)
436 _network_vpn_ipsec_connection_subcommands_local_remote ${connection} "local" ${args}
437 ;;
438 mode)
439 _network_vpn_ipsec_connection_subcommands_mode ${args}
440 ;;
441 remote)
faf53925 442 _network_vpn_ipsec_connection_subcommands_local_remote ${connection} "remote" ${args}
93097eca
JS
443 ;;
444 security-policy)
445 _network_vpn_ipsec_connection_subcommands_security_policy ${args}
446 ;;
447 esac
448}
449
450_network_vpn_ipsec_connection_subcommands_authentication() {
451 local connection=${1}
452 shift
453 local words=( $@ )
454
6fe4b2fd 455 local commands="mode pre-shared-key"
93097eca
JS
456 local cmd="$(_network_find_on_cmdline "${commands}")"
457 if [[ -z "${cmd}" ]]; then
458 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
459 return 0
460 fi
461
462
463 local args="${words[@]:1}"
464 case "${cmd}" in
465 mode)
466 _network_vpn_ipsec_connection_subcommands_authentication_mode ${connection} ${args}
467 ;;
468 esac
469}
470
471_network_vpn_ipsec_connection_subcommands_local_remote() {
472 local connection=${1}
473 local type=${2}
474 shift 2
475 local words=( $@ )
476
477 local commands="id prefix"
478 local cmd="$(_network_find_on_cmdline "${commands}")"
479 if [[ -z "${cmd}" ]]; then
480 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
481 return 0
482 fi
483
484
485 local args="${words[@]:1}"
486 case "${cmd}" in
487 prefix)
488 _network_vpn_ipsec_connection_subcommands_prefix "${connection}" "${type}" ${args}
489 ;;
490 esac
491}
492
493_network_vpn_ipsec_connection_subcommands_prefix() {
494 :
495}
496
497_network_vpn_ipsec_connection_subcommands_authentication_mode() {
498 local connection=${1}
499 shift
500 local words=( $@ )
501
502 local commands="PSK"
503 local cmd="$(_network_find_on_cmdline "${commands}")"
504 if [[ -z "${cmd}" ]]; then
505 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
506 return 0
507 fi
508}
509
510_network_vpn_ipsec_connection_subcommands_mode() {
511 local words=( $@ )
512
513 local commands="gre-transport tunnel vti"
514 local cmd="$(_network_find_on_cmdline "${commands}")"
515 if [[ -z "${cmd}" ]]; then
516 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
517 return 0
518 fi
519}
520
521_network_vpn_ipsec_connection_subcommands_security_policy() {
522 local words=( $@ )
523
524 local commands="$(network raw list-vpn-security-policies-all)"
525 local cmd="$(_network_find_on_cmdline "${commands}")"
526 if [[ -z "${cmd}" ]]; then
527 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
528 return 0
529 fi
530}
531
98699861
JS
532_network_vpn_security_policies() {
533 local words=( $@ )
534
535 local commands="destroy new $(network raw list-vpn-security-policies-all)"
536 local cmd="$(_network_find_on_cmdline "${commands}")"
537 if [[ -z "${cmd}" ]]; then
538 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
539 return 0
540 fi
541
542
543 local args="${words[@]:1}"
544 case "${cmd}" in
545 destroy)
546 :
547 ;;
548 new)
549 :
550 ;;
551 *)
552 if network raw vpn-security-policy-exists ${cmd}; then
553 _network_vpn_security_policies_subcommands ${cmd} ${args}
554 fi
555 ;;
556 esac
557}
558
559_network_vpn_security_policies_subcommands() {
560 local policy=${1}
561 shift
562 local words=( $@ )
563
564 local commands="cipher compression group-type integrity key-exchange lifetime pfs show"
565 local cmd="$(_network_find_on_cmdline "${commands}")"
566 if [[ -z "${cmd}" ]]; then
567 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
568 return 0
569 fi
570
571
572 local args="${words[@]:1}"
573 case "${cmd}" in
574 cipher)
575 _network_vpn_security_policies_subcommands_cipher ${policy} ${args}
576 ;;
577 compression)
578 _network_vpn_security_policies_subcommands_compression ${policy} ${args}
579 ;;
580 group-type)
581 _network_vpn_security_policies_subcommands_group_type ${policy} ${args}
582 ;;
583 integrity)
584 _network_vpn_security_policies_subcommands_integrity ${policy} ${args}
585 ;;
586 key-exchange)
587 _network_vpn_security_policies_subcommands_key_exchange ${policy} ${args}
588 ;;
589 pfs)
590 _network_vpn_security_policies_subcommands_pfs ${policy} ${args}
591 ;;
592 esac
593}
594
595_network_vpn_security_policies_subcommands_cipher() {
596 :
597}
598
599_network_vpn_security_policies_subcommands_compression() {
600 :
601}
602
603_network_vpn_security_policies_subcommands_group_type() {
604 :
605}
606
607_network_vpn_security_policies_subcommands_integrity() {
608 :
609}
610
611_network_vpn_security_policies_subcommands_key_exchange() {
612 :
613}
614
615_network_vpn_security_policies_subcommands_pfs() {
616 :
617}
618
1c6a4e30 619_network_zone() {
bae37360
MT
620 local words=( $@ )
621
622 local commands="new destroy $(network raw list-zones)"
623 local cmd="$(_network_find_on_cmdline "${commands}")"
624 if [[ -z "${cmd}" ]]; then
625 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
626 return 0
627 fi
628
1ca5fe9f 629
bae37360
MT
630 local args="${words[@]:1}"
631 case "${cmd}" in
632 new)
1ca5fe9f 633 _network_zone_new ${args}
bae37360
MT
634 ;;
635 destroy)
636 _network_complete_zones
637 ;;
638 *)
639 local zone="${cmd}"
640 local args="${words[@]:1}"
641 _network_zone_subcommand "${zone}" ${args}
642 ;;
643 esac
644}
645
1ca5fe9f
JS
646_network_zone_new() {
647 local words=( $@ )
648 local cmd=${words[@]:0:1}
649
650 # Suggest useful zone names
651 if [[ -z "${cmd}" ]]; then
652 local commands="$(network raw list-next-free-zones)"
653 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
654
655 # If a valid zone name was entered, we can move on
656 elif network raw zone-name-is-valid ${cmd}; then
657 local args="${words[@]:1}"
658 _network_complete_hooks zone ${args}
659 fi
660
661 return 0
662}
663
1c6a4e30 664_network_zone_subcommand() {
bae37360
MT
665 local zone="${1}"
666 shift
667
668 local words=( $@ )
669
9d3ac4e4 670 local commands="color config description disable down edit enable identify port rename status up"
bae37360
MT
671 local cmd="$(_network_find_on_cmdline "${commands}")"
672 if [[ -z "${cmd}" ]]; then
673 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
674 return 0
675 fi
b7fbb0cd 676
bae37360
MT
677 local args="${words[@]:1}"
678 case "${cmd}" in
679 config)
2a6b2397 680 _network_zone_subcommand_config "${zone}" ${args}
bae37360
MT
681 ;;
682 port)
683 _network_zone_subcommand_port "${zone}" ${args}
684 ;;
b7fbb0cd
JS
685 color)
686 _network_color ${args}
687 ;;
9d3ac4e4
JS
688 description)
689 _network_description ${args}
690 ;;
bae37360
MT
691 esac
692}
693
2a6b2397
MT
694_network_zone_subcommand_config() {
695 local zone="${1}"
696 shift
697
698 local words=( $@ )
699
c8aafc4e 700 local commands="destroy list new $(network raw list-zone-config-hids ${zone})"
cbf7473c 701
2a6b2397
MT
702 local cmd="$(_network_find_on_cmdline "${commands}")"
703 if [[ -z "${cmd}" ]]; then
704 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
705 return 0
706 fi
707
cbf7473c 708 local args="${words[@]:1}"
2a6b2397
MT
709 case "${cmd}" in
710 new)
711 _network_complete_hooks "config"
712 ;;
cbf7473c
JS
713 destroy)
714 _network_zone_subcommand_config_destroy ${zone} ${args}
715 ;;
cbf7473c 716 *)
c8aafc4e 717 if network raw zone-config-id-is-valid ${zone} ${cmd} || network raw zone-config-hid-is-valid ${zone} ${cmd}; then
cbf7473c
JS
718 _network_zone_subcommand_config_subcommand ${zone} ${args}
719 fi
720 ;;
2a6b2397
MT
721 esac
722}
723
cbf7473c
JS
724_network_zone_subcommand_config_subcommand() {
725 local zone="${1}"
726 shift
727
728 local words=( $@ )
729
730 local commands="edit"
731
732 local cmd="$(_network_find_on_cmdline "${commands}")"
733 if [[ -z "${cmd}" ]]; then
734 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
735 return 0
736 fi
737}
738
739_network_zone_subcommand_config_destroy() {
740 local zone="${1}"
741 shift
742
743 local words=( $@ )
744
745 local commands="$(network raw list-zone-config-ids ${zone})"
746
747 local cmd="$(_network_find_on_cmdline "${commands}")"
748 if [[ -z "${cmd}" ]]; then
749 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
750 return 0
751 fi
752}
753
1c6a4e30 754_network_zone_subcommand_port() {
bae37360
MT
755 local zone="${1}"
756 shift
757
758 local words=( $@ )
759
760 local commands="attach detach $(network raw list-ports-of-zone "${zone}")"
761 local cmd="$(_network_find_on_cmdline "${commands}")"
762 if [[ -z "${cmd}" ]]; then
763 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
764 return 0
765 fi
766
767 case "${cmd}" in
768 attach)
769 COMPREPLY=( $(compgen -W "$(network raw list-free-ports "${zone}")" \
770 -- "${cur}") )
771 ;;
772 detach)
773 COMPREPLY=( $(compgen -W "$(network raw list-ports-of-zone "${zone}")" \
774 -- "${cur}") )
775 ;;
776 *)
777 local port="${cmd}"
778 local args="${words[@]:1}"
779 _network_zone_subcommand_port_subcommand "${zone}" "${port}" ${args}
780 ;;
781 esac
782}
783
1c6a4e30 784_network_zone_subcommand_port_subcommand() {
bae37360
MT
785 local zone="${1}"
786 local port="${2}"
787 shift 2
788
789 local words=( $@ )
790
791 local commands="edit"
792 local cmd="$(_network_find_on_cmdline "${commands}")"
793 if [[ -z "${cmd}" ]]; then
794 COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
795 return 0
796 fi
797
798 case "${cmd}" in
799 edit)
800 # TODO auto-complete the zone-port hook
801 ;;
802 esac
803}
804
1c6a4e30 805_network() {
bae37360
MT
806 local cur prev words cword
807 _init_completion || return
808
809 local cmd i
810 for (( i=1; i < ${#words[@]} - 1; i++ )); do
811 [[ "${words[i]}" = -* ]] && continue
812 cmd="${words[i]}" && break
813 done
814
815 if [[ -z "${cmd}" ]]; then
816 case "${cur}" in
817 -*)
818 COMPREPLY=( $(compgen -W "--debug" -- "${cur}") )
819 ;;
820 *)
cc02f6be 821 COMPREPLY=( $(compgen -W "device dhcpv4 dhcpv6 dns-server \
93097eca 822 help hostname port reset route settings status vpn zone" \
cc02f6be 823 -- "${cur}") )
bae37360
MT
824 ;;
825 esac
826
827 return 0
828 fi
829
830 local args="${words[@]:i+1}"
831 case "${cmd}" in
832 device)
833 _network_device ${args}
834 ;;
cc02f6be
MT
835 dhcpv[64])
836 _network_dhcpd "${cmd/dhcpv/ipv}" ${args}
837 ;;
8d1d2745
MT
838 dns-server)
839 _network_dns_server ${args}
840 ;;
bae37360
MT
841 port)
842 _network_port ${args}
843 ;;
8d1d2745
MT
844 route)
845 _network_route ${args}
846 ;;
bae37360
MT
847 settings)
848 _network_settings ${args}
849 ;;
850 start|stop|status)
851 # start, stop and status optionally take a zone
852 _network_complete_zones
853 ;;
93097eca
JS
854 vpn)
855 _network_vpn ${args}
856 ;;
bae37360
MT
857 zone)
858 _network_zone ${args}
859 ;;
860 esac
861} && complete -F _network network