aboutsummaryrefslogtreecommitdiffstats
path: root/main/apk-tools/_apk
blob: 60ed1594189aaaa41d41f9a22f954db65e6f6a26 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#compdef apk

function _apk {

	local -a global_opts=(
		"(-h --help)"{-h,--help}"[Print help information]"
		"(-i --interactive)"{-i,--interactive}"[Ask confirmation before performing certain operations]"
		"(-p --root)"{-p,--root}"[Manage file system at ROOT]"
		"(-q --quiet)"{-q,--quiet}"[Print less information]"
		"(-U --update-cache)"{-U,--update-cache}"[Alias for '--cache-max-age 1']"
		"(-v --verbose)"{-v,--verbose}"[Print more information]"
		"(-V --version)"{-V,--version}"[Print program version and exit]"
		"(-X --repository)"{-X,--repository}"[Specify additional package repository]:repository:_host"
		"--allow-untrusted[Install packages with untrusted signature or no signature]"
		"--arch[Temporarily override architecture]:arch:(armhf mips64 s390x x86_64 x86 aarch64 ppc64le armv7 riscv64)"
		"--cache-dir[Temporarily override the cache directory]:directory:_dir_list"
		"--cache-max-age[Maximum age for index in cache before it's refreshed]:minutes"
		"--force-binary-stdout[Continue even if binary data will be printed to the terminal]"
		"--force-broken-world[Continue even if world cannot be satisfied]"
		"--force-non-repository[Continue even if packages may be lost on reboot]"
		"--force-old-apk[Continue even if packages use unsupported features]"
		"--force-overwrite[Overwrite files in other packages]"
		"--force-refresh[Do not use cached files]"
		"--keys-dir[Override directory of trusted keys]:directory:_dir_list"
		"--no-cache[Do not use any local cache path]"
		"--no-network[Do not use the network]"
		"--no-progress[Disable progress bar even for TTYs]"
		"--print-arch[Print default arch and exit]"
		"--progress[Show progress]"
		"--progress-fd[Write progress to the specified file descriptor]:file descriptor"
		"--purge[Delete modified configuration files or uninstalled packages from cache]"
		"--repositories-file[Override system repositories]:repository file:_files"
		"--wait[Wait to get an exclusive repository lock before failing]:seconds"
	)

	local -a commit_opts=(
		"(-s --simulate)"{-s,--simulate}"[Simulate the requested operation without making any changes]"
		"--clean-protected[Do not create .apk-new files in configuration directories]"
		"--overlay-from-stdin[Read list of overlay files from stdin]"
		"--no-scripts[Do not execute any scripts]"
		"--no-commit-hooks[Skip pre/post hook scripts]"
		"--initramfs-diskless-boot[Enables selected force options, disables commit hooks and more]"
	)

	local -a latest_opt=("(-l --latest)"{-l,--latest}"[Always choose the latest package by version]")
	local -a upgrade_opt=("(-u --upgrade)"{-u,--upgrade}"[Upgrade packages and it's dependencies]")

	local context state state_descr line
	typeset -A opt_args
	local curcontext="$curcontext"
	local ret=1

	function _ccache_apk_world { [[ "$1" -ot /etc/apk/world ]] }
	function _ccache_apk_avail {
		for i in /var/cache/apk/APKINDEX.*; do
			[[ "$1" -ot "$i" ]] && return
		done
	}

	function _apk_available_pkgs {
		local -a _apk_available_packs
		zstyle ":completion:${curcontext}:" cache-policy _ccache_apk_avail
		local IFS=$'\n'
		if _cache_invalid apk_index_packages_available || ! _retrieve_cache apk_index_packages_available; then
			_apk_available_packs=(${${$(/sbin/apk list -a 2>/dev/null)%% *}%%-[[:digit:].]##([[:alpha:]]#)#(*[[:alpha:]]#[[:digit:]])#(-r[[:digit:]]##)#})
			_store_cache apk_index_packages_available _apk_available_packs
		fi
		_describe 'available packages' _apk_available_packs
	}

	function _apk_installed_pkgs {
		local -a _apk_installed_packs
		zstyle ":completion:${curcontext}:" cache-policy _ccache_apk_world
		local IFS=$'\n'
		if _cache_invalid apk_index_packages_installed || ! _retrieve_cache apk_index_packages_installed; then
			_apk_installed_packs=(${${$(/sbin/apk list -I 2>/dev/null)%% *}%%-[[:digit:].]##([[:alpha:]]#)#(*[[:alpha:]]#[[:digit:]])#(-r[[:digit:]]##)#})
			_store_cache apk_index_packages_installed _apk_installed_packs
		fi
		_describe 'installed packages' _apk_installed_packs
	}

	function _apk_packages {
		_alternative 'repo:available packages:_apk_available_pkgs' 'localpkgs:local packages:_files -g "*.apk"'
	}

	function _apk_cache {
		local -a cache_subcmds=(
			"clean:Remove package files which are no longer necessary"
			"download:Fetch package files from the repositories and store them in the cache"
			"sync:Clean and Download"
		)
		_describe 'subcommand' cache_subcmds
	}

	function _apk_subcmds {
		local -a cmds=(
			"add:Add packages to world and commit changes"
			"del:Remove packages from world and commit changes"
			"fix:Fix, reinstall or upgrade packages without modifying world"
			"update:Update repository indexes"
			"upgrade:Install upgrades available from repositories"
			"cache:Manage the local package cache"
			"info:Give detailed information about packages or repositories"
			"list:List packages matching a pattern or other criteria"
			"dot:Render dependencies as graphviz graphs"
			"policy:Show repository policy for packages"
			"search:Search for packages by name or description"
			"index:Create repository index file from packages"
			"fetch:Download packages from global repositories to a local directory"
			"manifest:Show checksums of package contents"
			"verify:Verify package integrity and signature"
			"audit:Audit system for changes"
			"stats:Show statistics about repositories and installations"
			"version:Compare package versions or perform tests on version strings"
		)
		_describe 'subcommand' cmds
	}

	local -a completion_spec=($global_opts ':subcommand:_apk_subcmds')

	case ${${words:#-*}[2]} in
	(add)
		completion_spec+=(
			$commit_opts \
			$latest_opt \
			$upgrade_opt \
			"--initdb[Initialize a new package database]" \
			"(-t --virtual)"{-t,--virtual}"[Create virtual package with given dependencies]" \
			"--no-chown[Do not change file owner or group]" \
			"*:package:_apk_packages"
		)
	;;
	(del)
		completion_spec+=(
			$commit_opts \
			"(-r --rdepends)"{-r,--rdepends}"[Recursively delete all top-level reverse dependencies]" \
			"*:installed package:_apk_installed_pkgs"
		)
	;;
	(fix)
		completion_spec+=(
			$commit_opts \
			"(-d --depends)"{-d,--depends}"[Fix dependencies of specified packages]" \
			"(-r --reinstall)"{-r,--reinstall}"[Reinstall packages]" \
			"(-u --upgrade)"{-u,--upgrade}"[Upgrade if an upgrade is available and does not break dependencies]" \
			"(-x --xattr)"{-x,--xattr}"[Fix packages with broken xattrs]" \
			"--directory-permissions[Reset all directory permissions]" \
			"*:package:_apk_packages"
		)
	;;
	(update) completion_spec+=($commit_opts);;
	(upgrade)
		completion_spec+=(
			$commit_opts \
			$latest_opt \
			"(-a --available)"{-a,--available}"[Reset all packages to versions available from current repositories]" \
			"--ignore[Upgrade all other packages than the ones listed]" \
			"--no-self-upgrade[Do not do an early upgrade of the 'apk-tools' package]" \
			"--prune[Remove packages which are no longer available from any configured repository]" \
			"--self-upgrade-only[Only perform a self-upgrade of the 'apk-tools' package]" \
			"*:package:_apk_packages"
		)
	;;
	(cache)
		completion_spec+=(
			$latest_opt \
			$upgrade_opt \
			'2:subcommand:_apk_cache'
		)
	;;
	(info)
		completion_spec+=(
			"(-a --all)"{-a,--all}"[List all information known about the package]" \
			"(-d --description)"{-d,--descripton}"[Print the package description]" \
			"(-e --installed)"{-e,--installed}"[Check package installed status]" \
			"(-L --contents)"{-L,--contents}"[List files included in the package]" \
			"(-P --provides)"{-P,--provides}"[List what the package provides]" \
			"(-r --rdepends)"{-r,--rdepends}"[List reverse dependencies of the package]" \
			"(-R --depends)"{-R,--depends}"[List the dependencies of the package]" \
			"(-s --size)"{-s,--size}"[Print the package's installed size]" \
			"(-w --webpage)"{-w,--webpage}"[Print the URL for the package's upstream webpage]" \
			"(-W --who-owns)"{-W,--who-owns}"[Print the package which owns the specified file]:file:_files" \
			"(-i --install-if)"{-i,--install-if}"[List the package's install_if rule]" \
			"--license[Print the package SPDX license identifier]" \
			"--replaces[List the other packages for which this package is marked as a replacement]" \
			"(-I --rinstall-if)"{-I,--rinstall-if}"[List other packages whose install_if rules refer to this package]" \
			"--triggers[Print active triggers for the package]" \
			"*:package:_apk_packages"
		)
	;;
	(list)
		completion_spec+=(
			"(-I --installed)"{-I,--installed}"[Consider only installed packages]" \
			"(-O --orphaned)"{-O,--orphaned}"[Consider only orphaned packages]" \
			"(-a --available)"{-a,--available}"[Consider only available packages]" \
			"(-u --upgradable --upgradeable)"{-u,--upgradable,--upgradeable}"[Consider only upgradable packages]" \
			"(-o --origin)"{-o,--origin}"[List packages by origin]" \
			"(-d --depends)"{-d,--depends}"[List packages by dependency]" \
			"(-P --providers)"{-P,--providers}"[List packages by provider]" \
			"*:pattern"
		)
	;;
	(dot)
		completion_spec+=(
			"--errors[Consider only packages with errors]" \
			"--installed[Consider only installed packages]"
		)
	;;
	(index)
		completion_spec+=(
			"(-d --description)"{-d,--description}"[Add a description to the index]:description" \
			"(-o --output)"{-o,--output}"[Output generated index to file]:output:_files" \
			"(-x --index)"{-x,--index}"[Read an existing index to speed up the creation of the new index]" \
			"--no-warnings[Disable warnings about missing dependencies]" \
			"--rewrite-arch[Set all package's architecture to arch]:arch:(armhf mips64 s390x x86_64 x86 aarch64 ppc64le armv7 riscv64)" \
			"*:package:_apk_packages"
		)
	;;
	(fetch)
		completion_spec+=(
			"(-l --link)"{-l,--link}"[Create hard links if possible]" \
			"(-o --output)"{-o,--output}"[Where to write the downloaded files]:directory:_dir_list" \
			"(-r --recursive)"{-r,--recursive}"[Fetch packages and all of their dependencies]" \
			"(-s --stdout)"{-s,--stdout}"[Dump the .apk file(s) to stdout]" \
			"--simulate[Simulate the requested operation without making any changes]" \
			"--url[Print the full URL for downloaded packages]" \
			"*:package:_apk_packages"
		)
	;;
	(manifest) completion_spec+=("*:package:_apk_packages");;
	(verify) completion_spec+=("*:package:_apk_packages");;
	(audit)
		completion_spec+=(
			"--backup[Audit configuration files only (default)]" \
			"--check-permissions[Check file permissions too]" \
			"--packages[Print only the packages with changed files]" \
			"--system[Audit all system files]" \
			"(-r --recursive)"{-r,--recursive}"[Descent into directories and audit them as well]" \
			"*:files:_files"
		)
	;;
	(version)
		completion_spec+=(
			"(-a --all)"{-a,--all}"[Consider packages from all repository tags]" \
			"(-c --check)"{-c,--check}"[Check versions for validity]:*: " \
			"(-I --indexes)"{-I,--indexes}"[Print the version and description for each repository's index]:*: " \
			"(-l --limit)"{-l,--limit}"[Limit to packages with output matching given operand]:operand:('>' '=' '<' '>=' '<=')" \
			"(-t --test)"{-t,--test}"[Compare two version strings]:*: " \
			"*:package:_apk_packages"
		)
	;;
	(policy) completion_spec+=("*:package:_apk_packages");;
	(search)
		completion_spec+=(
			"(-a --all)"{-a,--all}"[Print all matching package versions]" \
			"(-d --description)"{-d,--description}"[Search in description as well]" \
			"(-e -x --exact)"{-e,-x,--exact}"[Match package names exactly]" \
			"--has-origin[Match by package origin]" \
			"(-o --origin)"{-o,--origin}"[Print base package name]" \
			"(-r --rdepends)"{-r,--rdepends}"[Print reverse dependencies]" \
			"*:package:_apk_packages"
		)
	;;
	esac

	_arguments -C -s $completion_spec && ret=0
	return ret
}