]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/bash/systemd-nspawn
nspawn: rework how /run/host/ is set up
[thirdparty/systemd.git] / shell-completion / bash / systemd-nspawn
1 # systemd-nspawn(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
3 #
4 # This file is part of systemd.
5 #
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() {
20 local w word=$1; shift
21 for w in "$@"; do
22 [[ $w = "$word" ]] && return
23 done
24 }
25
26 __get_users() {
27 local a b
28 loginctl list-users --no-legend --no-pager | { while read a b; do echo " $b"; done; };
29 }
30
31 __get_slices() {
32 local a b
33 systemctl list-units -t slice --no-legend --no-pager --plain | { while read a b; do echo " $a"; done; };
34 }
35
36 __get_machines() {
37 local a b
38 machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
39 }
40
41 __get_env() {
42 local a
43 env | { while read a; do echo " ${a%%=*}"; done; };
44 }
45
46 __get_interfaces(){
47 local name
48 for name in $(cd /sys/class/net && ls); do
49 [[ "$name" != "lo" ]] && echo "$name"
50 done
51 }
52
53 __get_rlimit() {
54 local i
55 for i in $(systemd-nspawn --rlimit=help 2>/dev/null); do
56 echo " ${i}="
57 done
58 }
59
60 _systemd_nspawn() {
61 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
62 local i verb comps
63
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 --root-hash-sig'
75 )
76
77 _init_completion || return
78
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)
105 compopt -o nospace -o filenames
106 comps=$(compgen -f -- "$cur" )
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 --root-hash-sig)
187 compopt -o nospace
188 comps=$( compgen -A file -- "$cur" )
189 ;;
190 esac
191 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
192 return 0
193 fi
194
195 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
196 }
197
198 complete -F _systemd_nspawn systemd-nspawn