]> git.ipfire.org Git - thirdparty/systemd.git/blame - shell-completion/bash/systemd-nspawn
Merge pull request #31511 from jamacku/prepare-for-diff-shellcheck
[thirdparty/systemd.git] / shell-completion / bash / systemd-nspawn
CommitLineData
f8457290 1# shellcheck shell=bash
0d6883b6 2# systemd-nspawn(1) completion -*- shell-script -*-
db9ecf05 3# SPDX-License-Identifier: LGPL-2.1-or-later
0d6883b6
TA
4#
5# This file is part of systemd.
6#
0d6883b6
TA
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
85fce6f4 18# along with systemd; If not, see <https://www.gnu.org/licenses/>.
0d6883b6
TA
19
20__contains_word() {
843cfcb1
ZJS
21 local w word=$1; shift
22 for w in "$@"; do
23 [[ $w = "$word" ]] && return
24 done
0d6883b6
TA
25}
26
27__get_users() {
843cfcb1
ZJS
28 local a b
29 loginctl list-users --no-legend --no-pager | { while read a b; do echo " $b"; done; };
0d6883b6
TA
30}
31
32__get_slices() {
843cfcb1 33 local a b
1cabd2d0 34 systemctl list-units -t slice --no-legend --no-pager --plain | { while read a b; do echo " $a"; done; };
0d6883b6
TA
35}
36
8c546358 37__get_machines() {
843cfcb1 38 local a b
4e918305
ZJS
39 { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
40 { while read a b; do echo " $a"; done; } | \
41 sort -u
8c546358
CMC
42}
43
44__get_env() {
843cfcb1
ZJS
45 local a
46 env | { while read a; do echo " ${a%%=*}"; done; };
8c546358
CMC
47}
48
d5acf7da 49__get_interfaces(){
843cfcb1 50 local name
66e10d45 51 for name in $(cd /sys/class/net && command ls); do
843cfcb1
ZJS
52 [[ "$name" != "lo" ]] && echo "$name"
53 done
8c546358
CMC
54}
55
ff1cf894 56__get_rlimit() {
843cfcb1
ZJS
57 local i
58 for i in $(systemd-nspawn --rlimit=help 2>/dev/null); do
59 echo " ${i}="
60 done
ff1cf894
YW
61}
62
0d6883b6 63_systemd_nspawn() {
f34173a0 64 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
843cfcb1 65 local i verb comps
0d6883b6 66
843cfcb1
ZJS
67 local -A OPTS=(
68 [STANDALONE]='-h --help --version --private-network -b --boot --read-only -q --quiet --share-system
4a4654e0 69 --keep-unit -n --network-veth -j -x --ephemeral -a --as-pid2 -U --suppress-sync=yes'
843cfcb1
ZJS
70 [ARG]='-D --directory -u --user --uuid --capability --drop-capability --link-journal --bind --bind-ro
71 -M --machine -S --slice -E --setenv -Z --selinux-context -L --selinux-apifs-context
72 --register --network-interface --network-bridge --personality -i --image --tmpfs
73 --volatile --network-macvlan --kill-signal --template --notify-ready --root-hash --chdir
ac31f596
LP
74 --pivot-root --property --private-users --private-users-ownership --network-namespace-path
75 --network-ipvlan --network-veth-extra --network-zone -p --port --system-call-filter --overlay
76 --overlay-ro --settings --rlimit --hostname --no-new-privileges --oom-score-adjust --cpu-affinity
3d8ba7b8 77 --resolv-conf --timezone --root-hash-sig --background'
843cfcb1 78 )
0d6883b6 79
843cfcb1 80 _init_completion || return
0d6883b6 81
843cfcb1
ZJS
82 if __contains_word "$prev" ${OPTS[ARG]}; then
83 case $prev in
84 --directory|-D|--template)
85 compopt -o nospace
86 comps=$(compgen -S/ -A directory -- "$cur" )
87 ;;
88 --user|-u)
89 comps=$( __get_users )
90 ;;
91 --uuid|--root-hash)
92 comps=''
93 ;;
94 --capability)
95 comps='CAP_BLOCK_SUSPEND CAP_IPC_LOCK CAP_MAC_ADMIN CAP_MAC_OVERRIDE CAP_SYS_MODULE CAP_SYS_PACCT CAP_SYS_RAWIO
96 CAP_SYS_TIME CAP_SYSLOG CAP_WAKE_ALARM CAP_NET_ADMIN'
97 ;;
98 --drop-capability)
99 comps='CAP_AUDIT_CONTROL CAP_AUDIT_WRITE CAP_CHOWN CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_FOWNER CAP_FSETID
100 CAP_IPC_OWNER CAP_KILL CAP_LEASE CAP_LINUX_IMMUTABLE CAP_MKNOD CAP_NET_ADMIN CAP_NET_BIND_SERVICE
101 CAP_NET_BROADCAST CAP_NET_RAW CAP_SETFCAP CAP_SETGID CAP_SETPCAP CAP_SETUID CAP_SYS_ADMIN CAP_SYS_BOOT
102 CAP_SYS_CHROOT CAP_SYS_NICE CAP_SYS_PTRACE CAP_SYS_RESOURCE CAP_SYS_TTY_CONFIG'
103 ;;
104 --link-journal)
105 comps='no auto guest try-guest host try-host'
106 ;;
107 --bind|--bind-ro)
afa879c3
FS
108 compopt -o nospace -o filenames
109 comps=$(compgen -f -- "$cur" )
843cfcb1
ZJS
110 ;;
111 --tmpfs)
112 compopt -o nospace
113 comps=$(compgen -S/ -A directory -- "$cur" )
114 ;;
115 --machine|-M)
116 comps=$( __get_machines )
117 ;;
118 --slice|-S)
119 comps=$( __get_slices )
120 ;;
121 --setenv|-E)
122 comps=$( __get_env )
123 ;;
124 --selinux-context|-Z)
125 comps=''
126 ;;
127 --selinux-apifs-context|-L)
128 comps=''
129 ;;
130 --register)
131 comps='yes no'
132 ;;
133 --network-interface)
134 comps=$(__get_interfaces)
135 ;;
136 --network-bridge)
137 comps=''
138 ;;
139 --network-macvlan)
140 comps=''
141 ;;
142 --personality)
143 comps='x86 x86-64'
144 ;;
145 --volatile)
146 comps=$( systemd-nspawn --volatile=help 2>/dev/null )
147 ;;
148 --image|-i)
149 compopt -o nospace
150 comps=$( compgen -A file -- "$cur" )
151 ;;
152 --kill-signal)
153 _signals
154 return
155 ;;
156 --notify-ready)
157 comps='yes no'
158 ;;
159 --private-users)
160 comps='yes no pick'
161 ;;
162 --network-namespace-path)
163 comps=$( compgen -A file -- "$cur" )
164 ;;
165 --settings)
166 comps='yes no override trusted'
167 ;;
168 --rlimit)
169 comps=$( __get_rlimit )
170 ;;
171 --hostname)
172 comps=''
173 ;;
174 --no-new-privileges)
175 comps='yes no'
176 ;;
177 --oom-score-adjust)
178 comps=''
179 ;;
180 --cpu-affinity)
181 comps=''
182 ;;
183 --resolv-conf)
184 comps=$( systemd-nspawn --resolv-conf=help 2>/dev/null )
185 ;;
186 --timezone)
187 comps=$( systemd-nspawn --timezone=help 2>/dev/null )
188 ;;
c2923fdc
LB
189 --root-hash-sig)
190 compopt -o nospace
191 comps=$( compgen -A file -- "$cur" )
192 ;;
843cfcb1
ZJS
193 esac
194 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
195 return 0
196 fi
0d6883b6 197
843cfcb1 198 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
0d6883b6
TA
199}
200
201complete -F _systemd_nspawn systemd-nspawn