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