]>
Commit | Line | Data |
---|---|---|
0d6883b6 | 1 | # systemd-nspawn(1) completion -*- shell-script -*- |
7059062c | 2 | # SPDX-License-Identifier: LGPL-2.1+ |
0d6883b6 TA |
3 | # |
4 | # This file is part of systemd. | |
5 | # | |
0d6883b6 TA |
6 | # |
7 | # systemd is free software; you can redistribute it and/or modify it | |
8 | # under the terms of the GNU Lesser General Public License as published by | |
9 | # the Free Software Foundation; either version 2.1 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | # systemd is distributed in the hope that it will be useful, but | |
13 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | # General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU Lesser General Public License | |
18 | # along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ||
20 | __contains_word() { | |
21 | local w word=$1; shift | |
22 | for w in "$@"; do | |
23 | [[ $w = "$word" ]] && return | |
24 | done | |
25 | } | |
26 | ||
27 | __get_users() { | |
28 | local a b | |
29 | loginctl list-users --no-legend --no-pager | { while read a b; do echo " $b"; done; }; | |
30 | } | |
31 | ||
32 | __get_slices() { | |
33 | local a b | |
34 | systemctl list-units -t slice --no-legend --no-pager | { while read a b; do echo " $a"; done; }; | |
35 | } | |
36 | ||
8c546358 CMC |
37 | __get_machines() { |
38 | local a b | |
39 | machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; }; | |
40 | } | |
41 | ||
42 | __get_env() { | |
43 | local a | |
44 | env | { while read a; do echo " ${a%%=*}"; done; }; | |
45 | } | |
46 | ||
d5acf7da YW |
47 | __get_interfaces(){ |
48 | local name | |
49 | for name in $(cd /sys/class/net && ls); do | |
e81eb287 ZJS |
50 | [[ "$name" != "lo" ]] && echo "$name" |
51 | done | |
8c546358 CMC |
52 | } |
53 | ||
ff1cf894 YW |
54 | __get_rlimit() { |
55 | local i | |
56 | for i in $(systemd-nspawn --rlimit=help 2>/dev/null); do | |
57 | echo " ${i}=" | |
58 | done | |
59 | } | |
60 | ||
0d6883b6 TA |
61 | _systemd_nspawn() { |
62 | local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} | |
63 | local i verb comps | |
64 | ||
65 | local -A OPTS=( | |
86b4188d YW |
66 | [STANDALONE]='-h --help --version --private-network -b --boot --read-only -q --quiet --share-system --keep-unit -n --network-veth |
67 | -j -x --ephemeral -a --as-pid2 --private-users-chown -U' | |
68 | [ARG]='-D --directory -u --user --uuid --capability --drop-capability --link-journal --bind --bind-ro -M --machine | |
69 | -S --slice -E --setenv -Z --selinux-context -L --selinux-apifs-context --register --network-interface --network-bridge | |
70 | --personality -i --image --tmpfs --volatile --network-macvlan --kill-signal --template --notify-ready --root-hash | |
71 | --chdir --pivot-root --property --private-users --network-namespace-path --network-ipvlan --network-veth-extra | |
ff1cf894 YW |
72 | --network-zone -p --port --system-call-filter --overlay --overlay-ro --settings |
73 | --rlimit --hostname --no-new-privileges --oom-score-adjust --cpu-affinity --resolv-conf --timezone' | |
0d6883b6 TA |
74 | ) |
75 | ||
76 | _init_completion || return | |
77 | ||
78 | if __contains_word "$prev" ${OPTS[ARG]}; then | |
79 | case $prev in | |
6d94d993 | 80 | --directory|-D|--template) |
8c546358 CMC |
81 | compopt -o nospace |
82 | comps=$(compgen -S/ -A directory -- "$cur" ) | |
0d6883b6 TA |
83 | ;; |
84 | --user|-u) | |
85 | comps=$( __get_users ) | |
86 | ;; | |
86b4188d | 87 | --uuid|--root-hash) |
0d6883b6 TA |
88 | comps='' |
89 | ;; | |
90 | --capability) | |
91 | comps='CAP_BLOCK_SUSPEND CAP_IPC_LOCK CAP_MAC_ADMIN CAP_MAC_OVERRIDE CAP_SYS_MODULE CAP_SYS_PACCT CAP_SYS_RAWIO | |
92 | CAP_SYS_TIME CAP_SYSLOG CAP_WAKE_ALARM CAP_NET_ADMIN' | |
93 | ;; | |
94 | --drop-capability) | |
95 | comps='CAP_AUDIT_CONTROL CAP_AUDIT_WRITE CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_FOWNER CAP_FSETID | |
96 | CAP_IPC_OWNER CAP_KILL CAP_LEASE CAP_LINUX_IMMUTABLE CAP_MKNOD CAP_NET_ADMIN CAP_NET_BIND_SERVICE | |
97 | CAP_NET_BROADCAST CAP_NET_RAW CAP_SETFCAP CAP_SETGID CAP_SETPCAP CAP_SETUID CAP_SYS_ADMIN CAP_SYS_BOOT | |
98 | CAP_SYS_CHROOT CAP_SYS_NICE CAP_SYS_PTRACE CAP_SYS_RESOURCE CAP_SYS_TTY_CONFIG' | |
99 | ;; | |
100 | --link-journal) | |
043a090d | 101 | comps='no auto guest try-guest host try-host' |
0d6883b6 TA |
102 | ;; |
103 | --bind|--bind-ro) | |
8c546358 CMC |
104 | compopt -o nospace |
105 | comps=$(compgen -S/ -A directory -- "$cur" ) | |
106 | ;; | |
107 | --tmpfs) | |
108 | compopt -o nospace | |
109 | comps=$(compgen -S/ -A directory -- "$cur" ) | |
0d6883b6 TA |
110 | ;; |
111 | --machine|-M) | |
8c546358 | 112 | comps=$( __get_machines ) |
0d6883b6 TA |
113 | ;; |
114 | --slice|-S) | |
115 | comps=$( __get_slices ) | |
116 | ;; | |
86b4188d | 117 | --setenv|-E) |
8c546358 | 118 | comps=$( __get_env ) |
0d6883b6 TA |
119 | ;; |
120 | --selinux-context|-Z) | |
121 | comps='' | |
122 | ;; | |
123 | --selinux-apifs-context|-L) | |
124 | comps='' | |
125 | ;; | |
126 | --register) | |
127 | comps='yes no' | |
128 | ;; | |
129 | --network-interface) | |
8c546358 | 130 | comps=$(__get_interfaces) |
0d6883b6 TA |
131 | ;; |
132 | --network-bridge) | |
133 | comps='' | |
134 | ;; | |
8c546358 CMC |
135 | --network-macvlan) |
136 | comps='' | |
137 | ;; | |
0d6883b6 TA |
138 | --personality) |
139 | comps='x86 x86-64' | |
140 | ;; | |
8c546358 | 141 | --volatile) |
ff1cf894 | 142 | comps=$( systemd-nspawn --volatile=help 2>/dev/null ) |
8c546358 | 143 | ;; |
5ba85788 | 144 | --image|-i) |
8c546358 | 145 | compopt -o nospace |
5ba85788 TA |
146 | comps=$( compgen -A file -- "$cur" ) |
147 | ;; | |
d5d841ff | 148 | --kill-signal) |
18540892 ZJS |
149 | _signals |
150 | return | |
d5d841ff | 151 | ;; |
14ca5c9c AP |
152 | --notify-ready) |
153 | comps='yes no' | |
86b4188d YW |
154 | ;; |
155 | --private-users) | |
156 | comps='yes no pick' | |
157 | ;; | |
158 | --network-namespace-path) | |
159 | comps=$( compgen -A file -- "$cur" ) | |
160 | ;; | |
161 | --settings) | |
162 | comps='yes no override trusted' | |
14ca5c9c | 163 | ;; |
ff1cf894 YW |
164 | --rlimit) |
165 | comps=$( __get_rlimit ) | |
166 | ;; | |
167 | --hostname) | |
168 | comps='' | |
169 | ;; | |
170 | --no-new-privileges) | |
171 | comps='yes no' | |
172 | ;; | |
173 | --oom-score-adjust) | |
174 | comps='' | |
175 | ;; | |
176 | --cpu-affinity) | |
177 | comps='' | |
178 | ;; | |
179 | --resolv-conf) | |
180 | comps=$( systemd-nspawn --resolv-conf=help 2>/dev/null ) | |
181 | ;; | |
182 | --timezone) | |
183 | comps=$( systemd-nspawn --timezone=help 2>/dev/null ) | |
184 | ;; | |
0d6883b6 TA |
185 | esac |
186 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
187 | return 0 | |
188 | fi | |
189 | ||
190 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
191 | } | |
192 | ||
193 | complete -F _systemd_nspawn systemd-nspawn |