saltext-apk 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- saltext_apk-0.1.0/LICENSE +202 -0
- saltext_apk-0.1.0/PKG-INFO +55 -0
- saltext_apk-0.1.0/README.md +38 -0
- saltext_apk-0.1.0/pyproject.toml +34 -0
- saltext_apk-0.1.0/setup.cfg +4 -0
- saltext_apk-0.1.0/src/saltext/apk/__init__.py +0 -0
- saltext_apk-0.1.0/src/saltext/apk/modules/__init__.py +0 -0
- saltext_apk-0.1.0/src/saltext/apk/modules/apkpkg.py +592 -0
- saltext_apk-0.1.0/src/saltext_apk.egg-info/PKG-INFO +55 -0
- saltext_apk-0.1.0/src/saltext_apk.egg-info/SOURCES.txt +12 -0
- saltext_apk-0.1.0/src/saltext_apk.egg-info/dependency_links.txt +1 -0
- saltext_apk-0.1.0/src/saltext_apk.egg-info/entry_points.txt +2 -0
- saltext_apk-0.1.0/src/saltext_apk.egg-info/requires.txt +1 -0
- saltext_apk-0.1.0/src/saltext_apk.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: saltext-apk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Salt extension restoring the apk package provider (apkpkg) removed from Salt core in 3008
|
|
5
|
+
Author-email: Paul Tobias <gitlab@tobias.pt>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://gitlab.com/paulto/saltext-apk
|
|
8
|
+
Project-URL: Source, https://gitlab.com/paulto/saltext-apk
|
|
9
|
+
Keywords: salt,saltstack,saltext,apk,apkpkg,openwrt,alpine,pkg
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: System :: Systems Administration
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: salt>=3008
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# saltext-apk
|
|
19
|
+
|
|
20
|
+
A [Salt](https://docs.saltproject.io/) extension that restores the **`apkpkg`** execution module — the `pkg` provider for [apk](https://wiki.alpinelinux.org/wiki/Alpine_Package_Keeper)-based systems (Alpine Linux; OpenWrt 25.12+).
|
|
21
|
+
|
|
22
|
+
## Why this exists
|
|
23
|
+
|
|
24
|
+
Salt 3008 removed `salt/modules/apkpkg.py` in its [purge of community extensions](https://github.com/saltstack/salt/commit/dc526dc2b17660059ca19f2d486cabeba54d021a#diff-f16cabd31b0eeeefcfb3fef8a0abb8ba85eabb8190b0ba8c5ecb2ee32db9a173) (it was last present in [v3007.14](https://github.com/saltstack/salt/blob/v3007.14/salt/modules/apkpkg.py)). Unlike many purged modules — `saltext-zfs`, for example — no replacement extension was published, so on Salt 3008 there is no `pkg` provider for apk at all. This package restores it.
|
|
25
|
+
|
|
26
|
+
It matters now because **OpenWrt 25.12 switched its package manager from opkg to apk**: Salt 3008 minions on OpenWrt have no working `pkg` module without this.
|
|
27
|
+
|
|
28
|
+
## Status
|
|
29
|
+
|
|
30
|
+
`0.1.0` is the [v3007.14](https://github.com/saltstack/salt/blob/v3007.14/salt/modules/apkpkg.py) module **repackaged unchanged** (only reformatted with ruff), so it behaves exactly as it did in Salt core: it enables on `os_family == "Alpine"`, and on OpenWrt you still need a `providers: pkg: apkpkg` override.
|
|
31
|
+
|
|
32
|
+
The OpenWrt adaptation lands in **0.2.0**:
|
|
33
|
+
|
|
34
|
+
- `__virtual__` auto-detecting apk by its presence, so it loads on OpenWrt (`os_family: OpenWrt`) too — no override.
|
|
35
|
+
- `list_pkgs` using `apk list --installed --manifest` to correctly parse packages whose names contain hyphens or whose versions lack a `-rN` suffix — e.g. `luci-app-mwan3 25.360.65088~78a62f2`, which the original recorded under the wrong name so `pkg.installed` could never confirm it.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
Into the same environment as Salt (onedir / uv / system):
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
salt-pip install saltext-apk
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
or as a Salt state:
|
|
46
|
+
|
|
47
|
+
```yaml
|
|
48
|
+
saltext.apk:
|
|
49
|
+
pip.installed:
|
|
50
|
+
- bin_env: /usr/bin/salt-pip
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
Apache-2.0 — the same license as the Salt code it derives from; see [`LICENSE`](LICENSE). The `apkpkg` module is derived from SaltStack's `salt/modules/apkpkg.py`; copyright of the original portions remains with the SaltStack authors.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# saltext-apk
|
|
2
|
+
|
|
3
|
+
A [Salt](https://docs.saltproject.io/) extension that restores the **`apkpkg`** execution module — the `pkg` provider for [apk](https://wiki.alpinelinux.org/wiki/Alpine_Package_Keeper)-based systems (Alpine Linux; OpenWrt 25.12+).
|
|
4
|
+
|
|
5
|
+
## Why this exists
|
|
6
|
+
|
|
7
|
+
Salt 3008 removed `salt/modules/apkpkg.py` in its [purge of community extensions](https://github.com/saltstack/salt/commit/dc526dc2b17660059ca19f2d486cabeba54d021a#diff-f16cabd31b0eeeefcfb3fef8a0abb8ba85eabb8190b0ba8c5ecb2ee32db9a173) (it was last present in [v3007.14](https://github.com/saltstack/salt/blob/v3007.14/salt/modules/apkpkg.py)). Unlike many purged modules — `saltext-zfs`, for example — no replacement extension was published, so on Salt 3008 there is no `pkg` provider for apk at all. This package restores it.
|
|
8
|
+
|
|
9
|
+
It matters now because **OpenWrt 25.12 switched its package manager from opkg to apk**: Salt 3008 minions on OpenWrt have no working `pkg` module without this.
|
|
10
|
+
|
|
11
|
+
## Status
|
|
12
|
+
|
|
13
|
+
`0.1.0` is the [v3007.14](https://github.com/saltstack/salt/blob/v3007.14/salt/modules/apkpkg.py) module **repackaged unchanged** (only reformatted with ruff), so it behaves exactly as it did in Salt core: it enables on `os_family == "Alpine"`, and on OpenWrt you still need a `providers: pkg: apkpkg` override.
|
|
14
|
+
|
|
15
|
+
The OpenWrt adaptation lands in **0.2.0**:
|
|
16
|
+
|
|
17
|
+
- `__virtual__` auto-detecting apk by its presence, so it loads on OpenWrt (`os_family: OpenWrt`) too — no override.
|
|
18
|
+
- `list_pkgs` using `apk list --installed --manifest` to correctly parse packages whose names contain hyphens or whose versions lack a `-rN` suffix — e.g. `luci-app-mwan3 25.360.65088~78a62f2`, which the original recorded under the wrong name so `pkg.installed` could never confirm it.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
Into the same environment as Salt (onedir / uv / system):
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
salt-pip install saltext-apk
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
or as a Salt state:
|
|
29
|
+
|
|
30
|
+
```yaml
|
|
31
|
+
saltext.apk:
|
|
32
|
+
pip.installed:
|
|
33
|
+
- bin_env: /usr/bin/salt-pip
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
Apache-2.0 — the same license as the Salt code it derives from; see [`LICENSE`](LICENSE). The `apkpkg` module is derived from SaltStack's `salt/modules/apkpkg.py`; copyright of the original portions remains with the SaltStack authors.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "saltext-apk"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Salt extension restoring the apk package provider (apkpkg) removed from Salt core in 3008"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Paul Tobias", email = "gitlab@tobias.pt" }]
|
|
14
|
+
keywords = ["salt", "saltstack", "saltext", "apk", "apkpkg", "openwrt", "alpine", "pkg"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Topic :: System :: Systems Administration",
|
|
18
|
+
]
|
|
19
|
+
dependencies = ["salt>=3008"]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://gitlab.com/paulto/saltext-apk"
|
|
23
|
+
Source = "https://gitlab.com/paulto/saltext-apk"
|
|
24
|
+
|
|
25
|
+
# How Salt discovers the extension's modules.
|
|
26
|
+
[project.entry-points."salt.loader"]
|
|
27
|
+
"saltext.apk" = "saltext.apk"
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.packages.find]
|
|
30
|
+
where = ["src"]
|
|
31
|
+
namespaces = true
|
|
32
|
+
|
|
33
|
+
[tool.ruff]
|
|
34
|
+
line-length = 320 # everyone in 2026 has wide monitors
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Support for apk
|
|
3
|
+
|
|
4
|
+
.. important::
|
|
5
|
+
If you feel that Salt should be using this module to manage packages on a
|
|
6
|
+
minion, and it is using a different module (or gives an error similar to
|
|
7
|
+
*'pkg.install' is not available*), see :ref:`here
|
|
8
|
+
<module-provider-override>`.
|
|
9
|
+
|
|
10
|
+
.. versionadded:: 2017.7.0
|
|
11
|
+
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import copy
|
|
15
|
+
import logging
|
|
16
|
+
|
|
17
|
+
import salt.utils.data
|
|
18
|
+
import salt.utils.itertools
|
|
19
|
+
from salt.exceptions import CommandExecutionError
|
|
20
|
+
|
|
21
|
+
log = logging.getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
# Define the module's virtual name
|
|
24
|
+
__virtualname__ = "pkg"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def __virtual__():
|
|
28
|
+
"""
|
|
29
|
+
Confirm this module is running on an Alpine Linux distribution
|
|
30
|
+
"""
|
|
31
|
+
if __grains__.get("os_family", False) == "Alpine":
|
|
32
|
+
return __virtualname__
|
|
33
|
+
return (False, "Module apk only works on Alpine Linux based systems")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# def autoremove(list_only=False, purge=False):
|
|
37
|
+
# return 'Not available'
|
|
38
|
+
# def hold(name=None, pkgs=None, sources=None, **kwargs): # pylint: disable=W0613
|
|
39
|
+
# return 'Not available'
|
|
40
|
+
# def unhold(name=None, pkgs=None, sources=None, **kwargs): # pylint: disable=W0613
|
|
41
|
+
# return 'Not available'
|
|
42
|
+
# def upgrade_available(name):
|
|
43
|
+
# return 'Not available'
|
|
44
|
+
# def version_cmp(pkg1, pkg2, ignore_epoch=False):
|
|
45
|
+
# return 'Not available'
|
|
46
|
+
# def list_repos():
|
|
47
|
+
# return 'Not available'
|
|
48
|
+
# def get_repo(repo, **kwargs):
|
|
49
|
+
# return 'Not available'
|
|
50
|
+
# def del_repo(repo, **kwargs):
|
|
51
|
+
# return 'Not available'
|
|
52
|
+
# def del_repo_key(name=None, **kwargs):
|
|
53
|
+
# return 'Not available'
|
|
54
|
+
# def mod_repo(repo, saltenv='base', **kwargs):
|
|
55
|
+
# return 'Not available'
|
|
56
|
+
# def expand_repo_def(**kwargs):
|
|
57
|
+
# return 'Not available'
|
|
58
|
+
# def get_selections(pattern=None, state=None):
|
|
59
|
+
# return 'Not available'
|
|
60
|
+
# def set_selections(path=None, selection=None, clear=False, saltenv='base'):
|
|
61
|
+
# return 'Not available'
|
|
62
|
+
# def info_installed(*names):
|
|
63
|
+
# return 'Not available'
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def version(*names, **kwargs):
|
|
67
|
+
"""
|
|
68
|
+
Returns a string representing the package version or an empty string if not
|
|
69
|
+
installed. If more than one package name is specified, a dict of
|
|
70
|
+
name/version pairs is returned.
|
|
71
|
+
|
|
72
|
+
CLI Example:
|
|
73
|
+
|
|
74
|
+
.. code-block:: bash
|
|
75
|
+
|
|
76
|
+
salt '*' pkg.version <package name>
|
|
77
|
+
salt '*' pkg.version <package1> <package2> <package3> ...
|
|
78
|
+
"""
|
|
79
|
+
return __salt__["pkg_resource.version"](*names, **kwargs)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def refresh_db(**kwargs):
|
|
83
|
+
"""
|
|
84
|
+
Updates the package list
|
|
85
|
+
|
|
86
|
+
- ``True``: Database updated successfully
|
|
87
|
+
- ``False``: Problem updating database
|
|
88
|
+
|
|
89
|
+
CLI Example:
|
|
90
|
+
|
|
91
|
+
.. code-block:: bash
|
|
92
|
+
|
|
93
|
+
salt '*' pkg.refresh_db
|
|
94
|
+
"""
|
|
95
|
+
ret = {}
|
|
96
|
+
cmd = ["apk", "update"]
|
|
97
|
+
call = __salt__["cmd.run_all"](cmd, output_loglevel="trace", python_shell=False)
|
|
98
|
+
if call["retcode"] == 0:
|
|
99
|
+
errors = []
|
|
100
|
+
ret = True
|
|
101
|
+
else:
|
|
102
|
+
errors = [call["stdout"]]
|
|
103
|
+
ret = False
|
|
104
|
+
|
|
105
|
+
if errors:
|
|
106
|
+
raise CommandExecutionError(
|
|
107
|
+
"Problem encountered installing package(s)",
|
|
108
|
+
info={"errors": errors, "changes": ret},
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
return ret
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _list_pkgs_from_context(versions_as_list):
|
|
115
|
+
"""
|
|
116
|
+
Use pkg list from __context__
|
|
117
|
+
"""
|
|
118
|
+
if versions_as_list:
|
|
119
|
+
return __context__["pkg.list_pkgs"]
|
|
120
|
+
else:
|
|
121
|
+
ret = copy.deepcopy(__context__["pkg.list_pkgs"])
|
|
122
|
+
__salt__["pkg_resource.stringify"](ret)
|
|
123
|
+
return ret
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def list_pkgs(versions_as_list=False, **kwargs):
|
|
127
|
+
"""
|
|
128
|
+
List the packages currently installed in a dict::
|
|
129
|
+
|
|
130
|
+
{'<package_name>': '<version>'}
|
|
131
|
+
|
|
132
|
+
CLI Example:
|
|
133
|
+
|
|
134
|
+
.. code-block:: bash
|
|
135
|
+
|
|
136
|
+
salt '*' pkg.list_pkgs
|
|
137
|
+
salt '*' pkg.list_pkgs versions_as_list=True
|
|
138
|
+
"""
|
|
139
|
+
versions_as_list = salt.utils.data.is_true(versions_as_list)
|
|
140
|
+
# not yet implemented or not applicable
|
|
141
|
+
if any([salt.utils.data.is_true(kwargs.get(x)) for x in ("removed", "purge_desired")]):
|
|
142
|
+
return {}
|
|
143
|
+
|
|
144
|
+
if "pkg.list_pkgs" in __context__ and kwargs.get("use_context", True):
|
|
145
|
+
return _list_pkgs_from_context(versions_as_list)
|
|
146
|
+
|
|
147
|
+
cmd = ["apk", "info", "-v"]
|
|
148
|
+
ret = {}
|
|
149
|
+
out = __salt__["cmd.run"](cmd, output_loglevel="trace", python_shell=False)
|
|
150
|
+
for line in salt.utils.itertools.split(out, "\n"):
|
|
151
|
+
pkg_version = "-".join(line.split("-")[-2:])
|
|
152
|
+
pkg_name = "-".join(line.split("-")[:-2])
|
|
153
|
+
__salt__["pkg_resource.add_pkg"](ret, pkg_name, pkg_version)
|
|
154
|
+
|
|
155
|
+
__salt__["pkg_resource.sort_pkglist"](ret)
|
|
156
|
+
__context__["pkg.list_pkgs"] = copy.deepcopy(ret)
|
|
157
|
+
if not versions_as_list:
|
|
158
|
+
__salt__["pkg_resource.stringify"](ret)
|
|
159
|
+
return ret
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def latest_version(*names, **kwargs):
|
|
163
|
+
"""
|
|
164
|
+
Return the latest version of the named package available for upgrade or
|
|
165
|
+
installation. If more than one package name is specified, a dict of
|
|
166
|
+
name/version pairs is returned.
|
|
167
|
+
|
|
168
|
+
If the latest version of a given package is already installed, an empty
|
|
169
|
+
string will be returned for that package.
|
|
170
|
+
|
|
171
|
+
CLI Example:
|
|
172
|
+
|
|
173
|
+
.. code-block:: bash
|
|
174
|
+
|
|
175
|
+
salt '*' pkg.latest_version <package name>
|
|
176
|
+
salt '*' pkg.latest_version <package name>
|
|
177
|
+
salt '*' pkg.latest_version <package1> <package2> <package3> ...
|
|
178
|
+
"""
|
|
179
|
+
refresh = salt.utils.data.is_true(kwargs.pop("refresh", True))
|
|
180
|
+
|
|
181
|
+
if not names:
|
|
182
|
+
return ""
|
|
183
|
+
|
|
184
|
+
ret = {}
|
|
185
|
+
for name in names:
|
|
186
|
+
ret[name] = ""
|
|
187
|
+
pkgs = list_pkgs()
|
|
188
|
+
|
|
189
|
+
# Refresh before looking for the latest version available
|
|
190
|
+
if refresh:
|
|
191
|
+
refresh_db()
|
|
192
|
+
|
|
193
|
+
# Upgrade check
|
|
194
|
+
cmd = ["apk", "upgrade", "-s"]
|
|
195
|
+
out = __salt__["cmd.run_stdout"](cmd, output_loglevel="trace", python_shell=False)
|
|
196
|
+
for line in salt.utils.itertools.split(out, "\n"):
|
|
197
|
+
try:
|
|
198
|
+
name = line.split(" ")[2]
|
|
199
|
+
_oldversion = line.split(" ")[3].strip("(")
|
|
200
|
+
newversion = line.split(" ")[5].strip(")")
|
|
201
|
+
if name in names:
|
|
202
|
+
ret[name] = newversion
|
|
203
|
+
except (ValueError, IndexError):
|
|
204
|
+
pass
|
|
205
|
+
|
|
206
|
+
# If version is empty, package may not be installed
|
|
207
|
+
for pkg in ret:
|
|
208
|
+
if not ret[pkg]:
|
|
209
|
+
installed = pkgs.get(pkg)
|
|
210
|
+
cmd = ["apk", "search", pkg]
|
|
211
|
+
out = __salt__["cmd.run_stdout"](cmd, output_loglevel="trace", python_shell=False)
|
|
212
|
+
for line in salt.utils.itertools.split(out, "\n"):
|
|
213
|
+
try:
|
|
214
|
+
pkg_version = "-".join(line.split("-")[-2:])
|
|
215
|
+
pkg_name = "-".join(line.split("-")[:-2])
|
|
216
|
+
if pkg == pkg_name:
|
|
217
|
+
if installed == pkg_version:
|
|
218
|
+
ret[pkg] = ""
|
|
219
|
+
else:
|
|
220
|
+
ret[pkg] = pkg_version
|
|
221
|
+
except ValueError:
|
|
222
|
+
pass
|
|
223
|
+
|
|
224
|
+
# Return a string if only one package name passed
|
|
225
|
+
if len(names) == 1:
|
|
226
|
+
return ret[names[0]]
|
|
227
|
+
return ret
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
# TODO: Support specific version installation
|
|
231
|
+
def install(name=None, refresh=False, pkgs=None, sources=None, **kwargs):
|
|
232
|
+
"""
|
|
233
|
+
Install the passed package, add refresh=True to update the apk database.
|
|
234
|
+
|
|
235
|
+
name
|
|
236
|
+
The name of the package to be installed. Note that this parameter is
|
|
237
|
+
ignored if either "pkgs" or "sources" is passed. Additionally, please
|
|
238
|
+
note that this option can only be used to install packages from a
|
|
239
|
+
software repository. To install a package file manually, use the
|
|
240
|
+
"sources" option.
|
|
241
|
+
|
|
242
|
+
CLI Example:
|
|
243
|
+
|
|
244
|
+
.. code-block:: bash
|
|
245
|
+
|
|
246
|
+
salt '*' pkg.install <package name>
|
|
247
|
+
|
|
248
|
+
refresh
|
|
249
|
+
Whether or not to refresh the package database before installing.
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
Multiple Package Installation Options:
|
|
253
|
+
|
|
254
|
+
pkgs
|
|
255
|
+
A list of packages to install from a software repository. Must be
|
|
256
|
+
passed as a python list.
|
|
257
|
+
|
|
258
|
+
CLI Example:
|
|
259
|
+
|
|
260
|
+
.. code-block:: bash
|
|
261
|
+
|
|
262
|
+
salt '*' pkg.install pkgs='["foo", "bar"]'
|
|
263
|
+
|
|
264
|
+
sources
|
|
265
|
+
A list of IPK packages to install. Must be passed as a list of dicts,
|
|
266
|
+
with the keys being package names, and the values being the source URI
|
|
267
|
+
or local path to the package. Dependencies are automatically resolved
|
|
268
|
+
and marked as auto-installed.
|
|
269
|
+
|
|
270
|
+
CLI Example:
|
|
271
|
+
|
|
272
|
+
.. code-block:: bash
|
|
273
|
+
|
|
274
|
+
salt '*' pkg.install sources='[{"foo": "salt://foo.deb"},{"bar": "salt://bar.deb"}]'
|
|
275
|
+
|
|
276
|
+
install_recommends
|
|
277
|
+
Whether to install the packages marked as recommended. Default is True.
|
|
278
|
+
|
|
279
|
+
Returns a dict containing the new package names and versions::
|
|
280
|
+
|
|
281
|
+
{'<package>': {'old': '<old-version>',
|
|
282
|
+
'new': '<new-version>'}}
|
|
283
|
+
"""
|
|
284
|
+
refreshdb = salt.utils.data.is_true(refresh)
|
|
285
|
+
pkg_to_install = []
|
|
286
|
+
|
|
287
|
+
old = list_pkgs()
|
|
288
|
+
|
|
289
|
+
if name and not (pkgs or sources):
|
|
290
|
+
if "," in name:
|
|
291
|
+
pkg_to_install = name.split(",")
|
|
292
|
+
else:
|
|
293
|
+
pkg_to_install = [name]
|
|
294
|
+
|
|
295
|
+
if pkgs:
|
|
296
|
+
# We don't support installing specific version for now
|
|
297
|
+
# so transform the dict in list ignoring version provided
|
|
298
|
+
pkgs = [next(iter(p)) for p in pkgs if isinstance(p, dict)]
|
|
299
|
+
pkg_to_install.extend(pkgs)
|
|
300
|
+
|
|
301
|
+
if not pkg_to_install:
|
|
302
|
+
return {}
|
|
303
|
+
|
|
304
|
+
if refreshdb:
|
|
305
|
+
refresh_db()
|
|
306
|
+
|
|
307
|
+
cmd = ["apk", "add"]
|
|
308
|
+
|
|
309
|
+
# Switch in update mode if a package is already installed
|
|
310
|
+
for _pkg in pkg_to_install:
|
|
311
|
+
if old.get(_pkg):
|
|
312
|
+
cmd.append("-u")
|
|
313
|
+
break
|
|
314
|
+
|
|
315
|
+
cmd.extend(pkg_to_install)
|
|
316
|
+
|
|
317
|
+
out = __salt__["cmd.run_all"](cmd, output_loglevel="trace", python_shell=False)
|
|
318
|
+
|
|
319
|
+
if out["retcode"] != 0 and out["stderr"]:
|
|
320
|
+
errors = [out["stderr"]]
|
|
321
|
+
else:
|
|
322
|
+
errors = []
|
|
323
|
+
|
|
324
|
+
__context__.pop("pkg.list_pkgs", None)
|
|
325
|
+
new = list_pkgs()
|
|
326
|
+
ret = salt.utils.data.compare_dicts(old, new)
|
|
327
|
+
|
|
328
|
+
if errors:
|
|
329
|
+
raise CommandExecutionError(
|
|
330
|
+
"Problem encountered installing package(s)",
|
|
331
|
+
info={"errors": errors, "changes": ret},
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
return ret
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def purge(name=None, pkgs=None, **kwargs):
|
|
338
|
+
"""
|
|
339
|
+
Alias to remove
|
|
340
|
+
"""
|
|
341
|
+
return remove(name=name, pkgs=pkgs, purge=True)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def remove(name=None, pkgs=None, purge=False, **kwargs): # pylint: disable=unused-argument
|
|
345
|
+
"""
|
|
346
|
+
Remove packages using ``apk del``.
|
|
347
|
+
|
|
348
|
+
name
|
|
349
|
+
The name of the package to be deleted.
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
Multiple Package Options:
|
|
353
|
+
|
|
354
|
+
pkgs
|
|
355
|
+
A list of packages to delete. Must be passed as a python list. The
|
|
356
|
+
``name`` parameter will be ignored if this option is passed.
|
|
357
|
+
|
|
358
|
+
Returns a dict containing the changes.
|
|
359
|
+
|
|
360
|
+
CLI Example:
|
|
361
|
+
|
|
362
|
+
.. code-block:: bash
|
|
363
|
+
|
|
364
|
+
salt '*' pkg.remove <package name>
|
|
365
|
+
salt '*' pkg.remove <package1>,<package2>,<package3>
|
|
366
|
+
salt '*' pkg.remove pkgs='["foo", "bar"]'
|
|
367
|
+
"""
|
|
368
|
+
old = list_pkgs()
|
|
369
|
+
pkg_to_remove = []
|
|
370
|
+
|
|
371
|
+
if name:
|
|
372
|
+
if "," in name:
|
|
373
|
+
pkg_to_remove = name.split(",")
|
|
374
|
+
else:
|
|
375
|
+
pkg_to_remove = [name]
|
|
376
|
+
|
|
377
|
+
if pkgs:
|
|
378
|
+
pkg_to_remove.extend(pkgs)
|
|
379
|
+
|
|
380
|
+
if not pkg_to_remove:
|
|
381
|
+
return {}
|
|
382
|
+
|
|
383
|
+
if purge:
|
|
384
|
+
cmd = ["apk", "del", "--purge"]
|
|
385
|
+
else:
|
|
386
|
+
cmd = ["apk", "del"]
|
|
387
|
+
|
|
388
|
+
cmd.extend(pkg_to_remove)
|
|
389
|
+
|
|
390
|
+
out = __salt__["cmd.run_all"](cmd, output_loglevel="trace", python_shell=False)
|
|
391
|
+
if out["retcode"] != 0 and out["stderr"]:
|
|
392
|
+
errors = [out["stderr"]]
|
|
393
|
+
else:
|
|
394
|
+
errors = []
|
|
395
|
+
|
|
396
|
+
__context__.pop("pkg.list_pkgs", None)
|
|
397
|
+
new = list_pkgs()
|
|
398
|
+
ret = salt.utils.data.compare_dicts(old, new)
|
|
399
|
+
|
|
400
|
+
if errors:
|
|
401
|
+
raise CommandExecutionError(
|
|
402
|
+
"Problem encountered removing package(s)",
|
|
403
|
+
info={"errors": errors, "changes": ret},
|
|
404
|
+
)
|
|
405
|
+
|
|
406
|
+
return ret
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
def upgrade(name=None, pkgs=None, refresh=True, **kwargs):
|
|
410
|
+
"""
|
|
411
|
+
Upgrades all packages via ``apk upgrade`` or a specific package if name or
|
|
412
|
+
pkgs is specified. Name is ignored if pkgs is specified
|
|
413
|
+
|
|
414
|
+
Returns a dict containing the changes.
|
|
415
|
+
|
|
416
|
+
{'<package>': {'old': '<old-version>',
|
|
417
|
+
'new': '<new-version>'}}
|
|
418
|
+
|
|
419
|
+
CLI Example:
|
|
420
|
+
|
|
421
|
+
.. code-block:: bash
|
|
422
|
+
|
|
423
|
+
salt '*' pkg.upgrade
|
|
424
|
+
"""
|
|
425
|
+
ret = {
|
|
426
|
+
"changes": {},
|
|
427
|
+
"result": True,
|
|
428
|
+
"comment": "",
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if salt.utils.data.is_true(refresh):
|
|
432
|
+
refresh_db()
|
|
433
|
+
|
|
434
|
+
old = list_pkgs()
|
|
435
|
+
|
|
436
|
+
pkg_to_upgrade = []
|
|
437
|
+
|
|
438
|
+
if name and not pkgs:
|
|
439
|
+
if "," in name:
|
|
440
|
+
pkg_to_upgrade = name.split(",")
|
|
441
|
+
else:
|
|
442
|
+
pkg_to_upgrade = [name]
|
|
443
|
+
|
|
444
|
+
if pkgs:
|
|
445
|
+
pkg_to_upgrade.extend(pkgs)
|
|
446
|
+
|
|
447
|
+
if pkg_to_upgrade:
|
|
448
|
+
cmd = ["apk", "add", "-u"]
|
|
449
|
+
cmd.extend(pkg_to_upgrade)
|
|
450
|
+
else:
|
|
451
|
+
cmd = ["apk", "upgrade"]
|
|
452
|
+
|
|
453
|
+
call = __salt__["cmd.run_all"](cmd, output_loglevel="trace", python_shell=False, redirect_stderr=True)
|
|
454
|
+
|
|
455
|
+
if call["retcode"] != 0:
|
|
456
|
+
ret["result"] = False
|
|
457
|
+
if call["stdout"]:
|
|
458
|
+
ret["comment"] = call["stdout"]
|
|
459
|
+
|
|
460
|
+
__context__.pop("pkg.list_pkgs", None)
|
|
461
|
+
new = list_pkgs()
|
|
462
|
+
ret["changes"] = salt.utils.data.compare_dicts(old, new)
|
|
463
|
+
|
|
464
|
+
return ret
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
def list_upgrades(refresh=True, **kwargs):
|
|
468
|
+
"""
|
|
469
|
+
List all available package upgrades.
|
|
470
|
+
|
|
471
|
+
CLI Example:
|
|
472
|
+
|
|
473
|
+
.. code-block:: bash
|
|
474
|
+
|
|
475
|
+
salt '*' pkg.list_upgrades
|
|
476
|
+
"""
|
|
477
|
+
ret = {}
|
|
478
|
+
if salt.utils.data.is_true(refresh):
|
|
479
|
+
refresh_db()
|
|
480
|
+
|
|
481
|
+
cmd = ["apk", "upgrade", "-s"]
|
|
482
|
+
call = __salt__["cmd.run_all"](cmd, output_loglevel="trace", python_shell=False)
|
|
483
|
+
|
|
484
|
+
if call["retcode"] != 0:
|
|
485
|
+
comment = ""
|
|
486
|
+
if "stderr" in call:
|
|
487
|
+
comment += call["stderr"]
|
|
488
|
+
if "stdout" in call:
|
|
489
|
+
comment += call["stdout"]
|
|
490
|
+
raise CommandExecutionError(comment)
|
|
491
|
+
else:
|
|
492
|
+
out = call["stdout"]
|
|
493
|
+
|
|
494
|
+
for line in out.splitlines():
|
|
495
|
+
if "Upgrading" in line:
|
|
496
|
+
name = line.split(" ")[2]
|
|
497
|
+
_oldversion = line.split(" ")[3].strip("(")
|
|
498
|
+
newversion = line.split(" ")[5].strip(")")
|
|
499
|
+
ret[name] = newversion
|
|
500
|
+
|
|
501
|
+
return ret
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
def file_list(*packages, **kwargs):
|
|
505
|
+
"""
|
|
506
|
+
List the files that belong to a package. Not specifying any packages will
|
|
507
|
+
return a list of _every_ file on the system's package database (not
|
|
508
|
+
generally recommended).
|
|
509
|
+
|
|
510
|
+
CLI Examples:
|
|
511
|
+
|
|
512
|
+
.. code-block:: bash
|
|
513
|
+
|
|
514
|
+
salt '*' pkg.file_list httpd
|
|
515
|
+
salt '*' pkg.file_list httpd postfix
|
|
516
|
+
salt '*' pkg.file_list
|
|
517
|
+
"""
|
|
518
|
+
return file_dict(*packages)
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
def file_dict(*packages, **kwargs):
|
|
522
|
+
"""
|
|
523
|
+
List the files that belong to a package, grouped by package. Not
|
|
524
|
+
specifying any packages will return a list of _every_ file on the system's
|
|
525
|
+
package database (not generally recommended).
|
|
526
|
+
|
|
527
|
+
CLI Examples:
|
|
528
|
+
|
|
529
|
+
.. code-block:: bash
|
|
530
|
+
|
|
531
|
+
salt '*' pkg.file_list httpd
|
|
532
|
+
salt '*' pkg.file_list httpd postfix
|
|
533
|
+
salt '*' pkg.file_list
|
|
534
|
+
"""
|
|
535
|
+
errors = []
|
|
536
|
+
ret = {}
|
|
537
|
+
cmd_files = ["apk", "info", "-L"]
|
|
538
|
+
|
|
539
|
+
if not packages:
|
|
540
|
+
return "Package name should be provided"
|
|
541
|
+
|
|
542
|
+
for package in packages:
|
|
543
|
+
files = []
|
|
544
|
+
cmd = cmd_files[:]
|
|
545
|
+
cmd.append(package)
|
|
546
|
+
out = __salt__["cmd.run_all"](cmd, output_loglevel="trace", python_shell=False)
|
|
547
|
+
for line in out["stdout"].splitlines():
|
|
548
|
+
if line.endswith("contains:"):
|
|
549
|
+
continue
|
|
550
|
+
else:
|
|
551
|
+
files.append(line)
|
|
552
|
+
if files:
|
|
553
|
+
ret[package] = files
|
|
554
|
+
|
|
555
|
+
return {"errors": errors, "packages": ret}
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
def owner(*paths, **kwargs):
|
|
559
|
+
"""
|
|
560
|
+
Return the name of the package that owns the file. Multiple file paths can
|
|
561
|
+
be passed. Like :mod:`pkg.version <salt.modules.apk.version`, if a single
|
|
562
|
+
path is passed, a string will be returned, and if multiple paths are passed,
|
|
563
|
+
a dictionary of file/package name pairs will be returned.
|
|
564
|
+
|
|
565
|
+
If the file is not owned by a package, or is not present on the minion,
|
|
566
|
+
then an empty string will be returned for that path.
|
|
567
|
+
|
|
568
|
+
CLI Example:
|
|
569
|
+
|
|
570
|
+
.. code-block:: bash
|
|
571
|
+
|
|
572
|
+
salt '*' pkg.owns /usr/bin/apachectl
|
|
573
|
+
salt '*' pkg.owns /usr/bin/apachectl /usr/bin/basename
|
|
574
|
+
"""
|
|
575
|
+
if not paths:
|
|
576
|
+
return "You must provide a path"
|
|
577
|
+
|
|
578
|
+
ret = {}
|
|
579
|
+
cmd_search = ["apk", "info", "-W"]
|
|
580
|
+
for path in paths:
|
|
581
|
+
cmd = cmd_search[:]
|
|
582
|
+
cmd.append(path)
|
|
583
|
+
output = __salt__["cmd.run_stdout"](cmd, output_loglevel="trace", python_shell=False)
|
|
584
|
+
if output:
|
|
585
|
+
if "ERROR:" in output:
|
|
586
|
+
ret[path] = "Could not find owner package"
|
|
587
|
+
else:
|
|
588
|
+
ret[path] = output.split("by ")[1].strip()
|
|
589
|
+
else:
|
|
590
|
+
ret[path] = f"Error running {cmd}"
|
|
591
|
+
|
|
592
|
+
return ret
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: saltext-apk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Salt extension restoring the apk package provider (apkpkg) removed from Salt core in 3008
|
|
5
|
+
Author-email: Paul Tobias <gitlab@tobias.pt>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://gitlab.com/paulto/saltext-apk
|
|
8
|
+
Project-URL: Source, https://gitlab.com/paulto/saltext-apk
|
|
9
|
+
Keywords: salt,saltstack,saltext,apk,apkpkg,openwrt,alpine,pkg
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: System :: Systems Administration
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: salt>=3008
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# saltext-apk
|
|
19
|
+
|
|
20
|
+
A [Salt](https://docs.saltproject.io/) extension that restores the **`apkpkg`** execution module — the `pkg` provider for [apk](https://wiki.alpinelinux.org/wiki/Alpine_Package_Keeper)-based systems (Alpine Linux; OpenWrt 25.12+).
|
|
21
|
+
|
|
22
|
+
## Why this exists
|
|
23
|
+
|
|
24
|
+
Salt 3008 removed `salt/modules/apkpkg.py` in its [purge of community extensions](https://github.com/saltstack/salt/commit/dc526dc2b17660059ca19f2d486cabeba54d021a#diff-f16cabd31b0eeeefcfb3fef8a0abb8ba85eabb8190b0ba8c5ecb2ee32db9a173) (it was last present in [v3007.14](https://github.com/saltstack/salt/blob/v3007.14/salt/modules/apkpkg.py)). Unlike many purged modules — `saltext-zfs`, for example — no replacement extension was published, so on Salt 3008 there is no `pkg` provider for apk at all. This package restores it.
|
|
25
|
+
|
|
26
|
+
It matters now because **OpenWrt 25.12 switched its package manager from opkg to apk**: Salt 3008 minions on OpenWrt have no working `pkg` module without this.
|
|
27
|
+
|
|
28
|
+
## Status
|
|
29
|
+
|
|
30
|
+
`0.1.0` is the [v3007.14](https://github.com/saltstack/salt/blob/v3007.14/salt/modules/apkpkg.py) module **repackaged unchanged** (only reformatted with ruff), so it behaves exactly as it did in Salt core: it enables on `os_family == "Alpine"`, and on OpenWrt you still need a `providers: pkg: apkpkg` override.
|
|
31
|
+
|
|
32
|
+
The OpenWrt adaptation lands in **0.2.0**:
|
|
33
|
+
|
|
34
|
+
- `__virtual__` auto-detecting apk by its presence, so it loads on OpenWrt (`os_family: OpenWrt`) too — no override.
|
|
35
|
+
- `list_pkgs` using `apk list --installed --manifest` to correctly parse packages whose names contain hyphens or whose versions lack a `-rN` suffix — e.g. `luci-app-mwan3 25.360.65088~78a62f2`, which the original recorded under the wrong name so `pkg.installed` could never confirm it.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
Into the same environment as Salt (onedir / uv / system):
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
salt-pip install saltext-apk
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
or as a Salt state:
|
|
46
|
+
|
|
47
|
+
```yaml
|
|
48
|
+
saltext.apk:
|
|
49
|
+
pip.installed:
|
|
50
|
+
- bin_env: /usr/bin/salt-pip
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
Apache-2.0 — the same license as the Salt code it derives from; see [`LICENSE`](LICENSE). The `apkpkg` module is derived from SaltStack's `salt/modules/apkpkg.py`; copyright of the original portions remains with the SaltStack authors.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/saltext/apk/__init__.py
|
|
5
|
+
src/saltext/apk/modules/__init__.py
|
|
6
|
+
src/saltext/apk/modules/apkpkg.py
|
|
7
|
+
src/saltext_apk.egg-info/PKG-INFO
|
|
8
|
+
src/saltext_apk.egg-info/SOURCES.txt
|
|
9
|
+
src/saltext_apk.egg-info/dependency_links.txt
|
|
10
|
+
src/saltext_apk.egg-info/entry_points.txt
|
|
11
|
+
src/saltext_apk.egg-info/requires.txt
|
|
12
|
+
src/saltext_apk.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
salt>=3008
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
saltext
|