mirror of
https://github.com/EnumeratedDev/bpm.git
synced 2026-09-16 18:46:12 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3950c5f0d6
|
||
|
|
f3c2b9f0f6
|
||
|
|
dc8959c2f8
|
||
|
|
9122ffb9ca
|
||
|
|
a4e20b7d88
|
||
|
|
a03c9ad9ce
|
||
|
|
3f205ec412
|
||
|
|
2f9487affe
|
||
|
|
596d8753a7
|
||
|
|
2de4eea7a4
|
||
|
|
5d0312856d
|
||
|
|
248359c02f
|
||
|
|
1d81690bff
|
||
|
|
618916cd22
|
||
|
|
8e4177c899
|
||
|
|
3f23580d16
|
||
|
|
95dee0560a
|
||
|
|
45721cfc43
|
||
|
|
2aceb9efe8
|
||
|
|
bc3df83936
|
||
|
|
f18c837bc2
|
||
|
|
76ad8e77c5
|
||
|
|
9ae2d3f893
|
||
|
|
89c0c0892f
|
||
|
|
ad89650dc4
|
||
|
|
3a7adb27ab
|
||
|
|
f6aa01339e
|
||
|
|
a29de2e52d
|
||
|
|
619335bbe6
|
||
|
|
8579c688d7
|
||
|
|
48cec35f0c
|
||
|
|
e19d64bf04
|
||
|
|
ee80640153
|
||
|
|
e4d94e378f
|
||
|
|
b37360ed82
|
||
|
|
ba0d288e45
|
||
|
|
c1fa9d9474
|
||
|
|
0742c81f2f
|
||
|
|
dd20574470
|
||
|
|
b3dc6e3e34
|
||
|
|
0a06808303
|
||
|
|
9f8a20c671
|
||
|
|
2072e3856f
|
||
|
|
72f574209f
|
||
|
|
9c2d4595c7
|
||
|
|
72f17f8954
|
||
|
|
fd646a820d
|
||
|
|
f23537ba7d
|
||
|
|
6e9f16837c
|
||
|
|
271e87cb77
|
||
|
|
25ccc208d7
|
||
|
|
9c7e20d27d
|
||
|
|
6206fdbf43
|
||
|
|
9e48d97dc8
|
||
|
|
08a4e24889
|
||
|
|
4a32df6335
|
||
|
|
548b2476bd
|
||
|
|
a660039be1
|
||
|
|
44c2678ef9
|
||
|
|
2a7c6ce5d9
|
||
|
|
f98760d1dd
|
||
|
|
2ba78f16db
|
||
|
|
04a71b573b
|
||
|
|
aa229af8df
|
||
|
|
9912b173ff
|
||
|
|
879c832f60
|
||
|
|
2c91a9332b
|
||
|
|
1895fabfb0
|
||
|
|
0dfb66c6c0
|
||
|
|
dfdf38bad8
|
||
|
|
52f25c8f3f
|
||
|
|
7e372eef91
|
||
|
|
b07a7f8778
|
||
|
|
b2fc963389
|
||
|
|
b27e9fb0df
|
||
|
|
089bc61d58
|
||
|
|
fb821b3190
|
||
|
|
444b2032e2
|
||
|
|
70ba64ca6b
|
||
|
|
ed172f2805
|
||
|
|
f0ea57d500
|
||
|
|
e923aefff9
|
||
|
|
c2d420d854
|
||
|
|
2db01fb0d4
|
||
|
|
b451c5c320
|
||
|
|
27427d5654
|
||
|
|
04e966fef5
|
||
|
|
8a7519628f
|
||
|
|
8986e24334
|
||
|
|
f066e26dc2
|
||
|
|
bee23e2f56
|
||
|
|
d56005e63e
|
||
|
|
c9e16d6df1
|
||
|
|
45c536b326
|
||
|
|
705aec8e6e
|
||
|
|
34fb7ce1d6
|
||
|
|
fee0e6a96f
|
||
|
|
c5f48becf8
|
||
|
|
ac1ba2ada3
|
||
|
|
5fb8211933
|
||
|
|
4110ad9c5c
|
||
|
|
dcff59d560
|
||
|
|
1594eec5ce
|
||
|
|
0c30d85589
|
||
|
|
768c75c9bd
|
||
|
|
abc6674b97
|
||
|
|
1d858076fd
|
||
|
|
5909370407
|
||
|
|
5a78fd3002
|
||
|
|
a7c03c272e
|
||
|
|
8ba209cf35
|
||
|
|
6f27f39065
|
||
|
|
91479e58f1
|
||
|
|
b6d055a38d
|
||
|
|
0c754a7e0f
|
||
|
|
eeb9a01e31
|
||
|
|
53e08ce7f9
|
||
|
|
6f124e0586
|
||
|
|
93921d4093
|
||
|
|
bc89db8cef
|
||
|
|
ea6d722fa8
|
||
|
|
264a0f87ba
|
||
|
|
926b0e35fc
|
||
|
|
a4d1365e55 | ||
|
|
bc3fe6fd7e | ||
|
|
85d5befbda | ||
|
|
27713e468c | ||
|
|
da184ecb19 | ||
|
|
812caa1485 | ||
|
|
5181c43ecf | ||
|
|
17af8dbaaf | ||
|
|
6501105dd1 | ||
|
|
c01ca62e34 | ||
|
|
998d4a2252 | ||
|
|
57231fdec5 | ||
|
|
713eafb708 | ||
|
|
38b6ea0175 | ||
|
|
ef5697321b | ||
|
|
e63398c853 | ||
|
|
6492fd028f | ||
|
|
4bfc325c66 | ||
|
|
8a627254c9 | ||
|
|
458c091ac2 | ||
|
|
966d351a80 | ||
|
|
815d0bb29a | ||
|
|
bf2b4e95ac | ||
|
|
d26d878308 | ||
|
|
f20d7b66d1 | ||
|
|
5f03a6a1ad | ||
|
|
f2bc7c8968 | ||
|
|
97d5a06ce7 | ||
|
|
f0709ff410 | ||
|
|
a32dfba54a | ||
|
|
b07df8c7df | ||
|
|
1329109810 | ||
|
|
4a8c4e22ec | ||
|
|
eb8db1bc99 | ||
|
|
4f1eeeb11d | ||
|
|
2e416b9e6f | ||
|
|
d8a42c780d | ||
|
|
b1bb8de661 | ||
|
|
c425b263fe | ||
|
|
5776784021 | ||
|
|
903c7dce3e | ||
|
|
5085981f52 | ||
|
|
9cdb3d29aa | ||
|
|
d8146cb3f3 | ||
|
|
c8c1fded76 | ||
|
|
4bf9ac9c60 | ||
|
|
b73519ba9c | ||
|
|
382a3fc8b6 | ||
|
|
1843bceef5 | ||
|
|
6af3b77d69 | ||
|
|
8b6ef5fa63 | ||
|
|
e8d5f0a565 | ||
|
|
7b0a8bf1d6 | ||
|
|
3a62f23db5 | ||
|
|
d9d85b4943 | ||
|
|
877fba8767 | ||
|
|
0858a49636 | ||
|
|
b27137da29 | ||
|
|
78dce34b64 | ||
|
|
f74372f13b | ||
|
|
dd41369e05 | ||
|
|
fa3f59d8ba | ||
|
|
46f7d96acf | ||
|
|
2f8d6a7ea9 | ||
|
|
c767f26937 | ||
|
|
3f2d5cf7a1 | ||
|
|
14fe71842e | ||
|
|
d1a2d28cff | ||
|
|
151de2112e | ||
|
|
e60381beb1 | ||
|
|
0801612166 | ||
|
|
9485248d8e | ||
|
|
68291e2666 | ||
|
|
05f273d687 | ||
|
|
fcb2ef1515 | ||
|
|
97de746a7d | ||
|
|
a26737859c | ||
|
|
90d5a23fcc | ||
|
|
7104441727 | ||
|
|
5f8e4f00ea | ||
|
|
87c492a30c | ||
|
|
e94b2a8816 | ||
|
|
4f9d2cdecd | ||
|
|
e2e2629dc9 | ||
|
|
c3981ad95c | ||
|
|
852e615806 | ||
|
|
e285fd792e | ||
|
|
2accc30390 | ||
|
|
b625fe97ef | ||
|
|
6e2bb86ef0 | ||
|
|
e30a32c568 | ||
|
|
a2da73e26b | ||
|
|
2c7c4eeb73 | ||
|
|
6e11f937a6 | ||
|
|
db6a776763 | ||
|
|
e888fe06e8 | ||
|
|
fe928dbbd6 | ||
|
|
0b439bcfed | ||
|
|
4aed0fe5b0 | ||
|
|
a054717b23 | ||
|
|
918ff984ca | ||
|
|
a7b025d92d | ||
|
|
ef16fa8195 | ||
|
|
1aec288013 | ||
|
|
7816d0072c | ||
|
|
1bd57110a0 | ||
|
|
76efa42bcf | ||
|
|
c8939614b1 | ||
|
|
4793424f3d | ||
|
|
e1726ddce5 | ||
|
|
e6cfd112ea | ||
|
|
2d35ac12a1 | ||
|
|
a3d1167358 | ||
|
|
3ff01093a0 | ||
|
|
c427499fb6 | ||
|
|
108e355e94 | ||
|
|
7b491874eb | ||
|
|
82d3c8bd51 | ||
|
|
7a489af220 | ||
|
|
6d9157e878 | ||
|
|
fd6ddbfc41 | ||
|
|
368b098888 | ||
|
|
5e2fc138e9 | ||
|
|
bc489ebd23 | ||
|
|
6247c6eff7 | ||
|
|
c24b7c85e3 | ||
|
|
2fd01a3fc2 | ||
|
|
747c770499 | ||
|
|
26500d670d | ||
|
|
59df2324e6 | ||
|
|
12d5e7580e | ||
|
|
123697e1dc | ||
|
|
743918702a | ||
|
|
7d2caa542c | ||
|
|
ab75193022 | ||
|
|
7d577a8dc2 | ||
|
|
c85c9b5d1c | ||
|
|
721414679d | ||
|
|
c20e74203c | ||
|
|
23f9a13939 | ||
|
|
1d41236740 | ||
|
|
e445863dca | ||
|
|
f9ef17cd66 | ||
|
|
124802ecc1 | ||
|
|
9927c7f7ef | ||
|
|
f6b182cc3d | ||
|
|
eae1e05102 | ||
|
|
9cbc36f869 | ||
|
|
e72aa2320d | ||
|
|
6af297efa6 | ||
|
|
ea469c4180 | ||
|
|
8db2635314 | ||
|
|
977e81c420 | ||
|
|
84259de9e8 | ||
|
|
555ea75403 | ||
|
|
4d7bf7179b | ||
|
|
e75d2fb1da | ||
|
|
497c94cbc0 | ||
|
|
d086b4a639 | ||
|
|
3e8b247e83 |
@@ -0,0 +1,5 @@
|
|||||||
|
# IDE Directories
|
||||||
|
.idea
|
||||||
|
|
||||||
|
# Build directory
|
||||||
|
build
|
||||||
@@ -1,674 +1,21 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
MIT License
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
Copyright (c) 2024 EnumDev
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this license document, but changing it is not allowed.
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
Preamble
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
The GNU General Public License is a free, copyleft license for
|
furnished to do so, subject to the following conditions:
|
||||||
software and other kinds of works.
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
The licenses for most software and other practical works are designed
|
copies or substantial portions of the Software.
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
share and change all versions of a program--to make sure it remains free
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
GNU General Public License for most of our software; it applies also to
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
any other work released this way by its authors. You can apply it to
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
your programs, too.
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
|
||||||
or can get the source code. And you must show them these terms so they
|
|
||||||
know their rights.
|
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
|
||||||
that there is no warranty for this free software. For both users' and
|
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
|
||||||
changed, so that their problems will not be attributed erroneously to
|
|
||||||
authors of previous versions.
|
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the manufacturer
|
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
|
||||||
protecting users' freedom to change the software. The systematic
|
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
|
||||||
products. If such problems arise substantially in other domains, we
|
|
||||||
stand ready to extend this provision to those domains in future versions
|
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
|
||||||
patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the special requirements of the GNU Affero General Public License,
|
|
||||||
section 13, concerning interaction through a network will apply to the
|
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) 2024 CapCreeperGR
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
<program> Copyright (C) 2024 CapCreeperGR
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
|
||||||
<https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
# Installation paths
|
||||||
|
PREFIX ?= /usr/local
|
||||||
|
SBINDIR ?= $(PREFIX)/sbin
|
||||||
|
SYSCONFDIR := $(PREFIX)/etc
|
||||||
|
|
||||||
|
# Compilers and tools
|
||||||
|
GO ?= go
|
||||||
|
|
||||||
|
# Build-time variables
|
||||||
|
VERSION ?= $(shell git describe --tags --dirty)
|
||||||
|
ROOT_COMPILATION_UID ?= 65534
|
||||||
|
ROOT_COMPILATION_GID ?= 65534
|
||||||
|
|
||||||
|
build:
|
||||||
|
mkdir -p build
|
||||||
|
cd src/bpm; $(GO) build $(GOFLAGS) -ldflags "-w -X 'main.BpmVersion=$(VERSION)' -X 'github.com/EnumeratedDev/bpm/src/bpmlib.rootCompilationUID=$(ROOT_COMPILATION_UID)' -X 'github.com/EnumeratedDev/bpm/src/bpmlib.rootCompilationGID=$(ROOT_COMPILATION_GID)'" -o ../../build/bpm bpm
|
||||||
|
|
||||||
|
install: build/bpm config/
|
||||||
|
# Create directory
|
||||||
|
install -dm755 $(DESTDIR)$(SBINDIR)
|
||||||
|
|
||||||
|
# Install binary
|
||||||
|
install -Dm755 build/bpm $(DESTDIR)$(SBINDIR)/bpm
|
||||||
|
|
||||||
|
install-config:
|
||||||
|
# Create directory
|
||||||
|
install -dm755 $(DESTDIR)$(SYSCONFDIR)
|
||||||
|
|
||||||
|
# Install files
|
||||||
|
install -Dm644 config/bpm.conf $(DESTDIR)$(SYSCONFDIR)/bpm.conf
|
||||||
|
install -Dm644 config/bpm-compilation.conf $(DESTDIR)$(SYSCONFDIR)/bpm-compilation.conf
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
-rm -f $(DESTDIR)$(SBINDIR)/bpm
|
||||||
|
-rm -f $(DESTDIR)$(SYSCONFDIR)/bpm.conf
|
||||||
|
-rm -f $(DESTDIR)$(SYSCONFDIR)/bpm-compilation.conf
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -r build/
|
||||||
|
|
||||||
|
.PHONY: build install install-config uninstall clean
|
||||||
@@ -1,29 +1,26 @@
|
|||||||
# Bubble Package Manager (BPM)
|
# Bubble Package Manager (BPM)
|
||||||
## _A simple package manager_
|
## _The official package manager for Tide Linux_
|
||||||
|
|
||||||
BPM is a simple package manager for Linux systems
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
- Simple to use subcommands
|
- Simple to use subcommands
|
||||||
- Can install binary and source packages
|
- Can install both binary and source packages
|
||||||
- Can be easily installed on practically any system
|
|
||||||
- No bloat
|
|
||||||
|
|
||||||
## Information
|
## Information
|
||||||
|
BPM is still in very early development. There may be bugs that could completely break installations. For now it is recommended you use this only in Virtual Machines, containers or in a Tide Linux installation
|
||||||
BPM is still in very early development. It should not be installed on any system you use seriously. I recommend trying this out in a VM or container. In addition to this, this is one of the first projects I have made using the go programming language so code quality may not be the best. This project was made to help me learn go and how linux systems work better. It is not meant to replace the big package managers in any way
|
|
||||||
|
|
||||||
## Build from source
|
## Build from source
|
||||||
|
|
||||||
BPM requires go 1.22 or above to be built properly
|
- Download `go` from your package manager or from the go website
|
||||||
|
- Download `make` from your package manager
|
||||||
|
- Run the following command to compile the project. You may need to set the `GO` environment variable if your Go installation is not in your PATH
|
||||||
```sh
|
```sh
|
||||||
git clone https://gitlab.com/bubble-package-manager/bpm.git
|
make
|
||||||
cd bpm
|
```
|
||||||
mkdir build
|
- Run the following command to install BPM into your system. You may also append a DESTDIR variable at the end of this line if you wish to install in a different location
|
||||||
go build -o ./build/bpm capcreepergr.me/bpm
|
```sh
|
||||||
|
make install PREFIX=/usr SYSCONFDIR=/etc
|
||||||
|
make install-config PREFIX=/usr SYSCONFDIR=/etc
|
||||||
```
|
```
|
||||||
You are now able to copy the executable in the ./build directory in a VM or container's /usr/bin/ directory
|
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
@@ -31,65 +28,38 @@ You are able to install bpm packages by typing the following:
|
|||||||
```sh
|
```sh
|
||||||
bpm install /path/to/package.bpm
|
bpm install /path/to/package.bpm
|
||||||
```
|
```
|
||||||
You may also use the -y flag as shown below to bypass the installation confirmation prompt
|
You can also use the package name directly if using databases
|
||||||
|
```sh
|
||||||
|
bpm install package_name
|
||||||
|
```
|
||||||
|
The -y flag may be used as shown below to bypass the confirmation prompt
|
||||||
```sh
|
```sh
|
||||||
bpm install -y /path/to/package.bpm
|
bpm install -y /path/to/package.bpm
|
||||||
```
|
```
|
||||||
Flags must strictly be typed before the first package path otherwise they'll be read as package locations themselves
|
Flags must strictly be typed before the first package path or name, otherwise they'll be read as package locations themselves
|
||||||
|
|
||||||
You can remove an installed package by typing the following
|
You can remove an installed package by typing the following
|
||||||
```sh
|
```sh
|
||||||
bpm remove package_name
|
bpm remove package_name
|
||||||
```
|
```
|
||||||
The -y flag applies here as well if you wish to skip the removal confirmation prompt
|
|
||||||
|
To remove all unused dependencies and clean cached files try using the cleanup command
|
||||||
|
```sh
|
||||||
|
bpm cleanup
|
||||||
|
```
|
||||||
|
|
||||||
|
If using databases, all packages can be updated using this simple command
|
||||||
|
```sh
|
||||||
|
bpm update
|
||||||
|
```
|
||||||
|
|
||||||
For information on the rest of the commands simply use the help command or pass in no arguments at all
|
For information on the rest of the commands simply use the help command or pass in no arguments at all
|
||||||
```
|
```sh
|
||||||
bpm help
|
bpm help
|
||||||
```
|
```
|
||||||
|
|
||||||
## Package Creation
|
## Package Creation
|
||||||
|
|
||||||
Creating a package for BPM is simple
|
Package creation is simplified using the bpm-utils package which contains helper scripts for creating packages
|
||||||
|
|
||||||
To create a package you need to
|
Learn more here: https://git.enumerated.dev/bubble-package-manager/bpm-utils
|
||||||
1) Create a working directory
|
|
||||||
```
|
|
||||||
mkdir my_bpm_package
|
|
||||||
```
|
|
||||||
2) Create a pkg.info file following this format (You can find examples in the test_packages directory)
|
|
||||||
```
|
|
||||||
name: my_package
|
|
||||||
description: My package's description
|
|
||||||
version: 1.0
|
|
||||||
architecture: x86_64
|
|
||||||
type: <binary/source>
|
|
||||||
depends: dependency1,dependency2
|
|
||||||
make_depends: make_depend1,make_depend2
|
|
||||||
```
|
|
||||||
depends and make depends are optional fields, you may skip them if you'd like
|
|
||||||
### Binary Packages
|
|
||||||
3) If you are making a binary package, simply create a 'files' directory
|
|
||||||
```
|
|
||||||
mkdir files
|
|
||||||
```
|
|
||||||
4) Copy all your binaries along with the directories they reside in (i.e files/usr/bin/my_binary)
|
|
||||||
5) Either copy the bpm-create script from the bpm-utils test package into your /usr/local/bin directory or install the bpm-utils.bpm package
|
|
||||||
6) Run the following
|
|
||||||
```
|
|
||||||
bpm-create <filename.bpm>
|
|
||||||
```
|
|
||||||
7) It's done! You now hopefully have a working BPM package!
|
|
||||||
### Source Packages
|
|
||||||
3) If you are making a source package, you need to create a 'source.sh' file
|
|
||||||
```
|
|
||||||
touch source.sh
|
|
||||||
```
|
|
||||||
4) If you would like to bundle patches or other files with your source package create a 'source-files' directory and place your files in there. They will be extracted to the same location as the source.sh file during compilation
|
|
||||||
5) You are able to run bash code in source.sh. BPM will extract this file in a directory under /tmp and it will be run there
|
|
||||||
6) Your goal is to download your program's source code with either git, wget, curl, etc. and put the binaries under a folder called 'output' in the root of the temp directory. There is a simple example script with helpful comments in the htop-src test package
|
|
||||||
7) When you are done making your source.sh script run the following to create a package archive
|
|
||||||
```
|
|
||||||
bpm-create <filename.bpm>
|
|
||||||
```
|
|
||||||
8) That's it! Your source package should now be compiling correctly!
|
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
package bpm_utils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetArch() string {
|
|
||||||
output, err := exec.Command("/usr/bin/uname", "-m").Output()
|
|
||||||
if err != nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return strings.TrimSpace(string(output))
|
|
||||||
}
|
|
||||||
|
|
||||||
func stringSliceRemove(s []string, r string) []string {
|
|
||||||
for i, v := range s {
|
|
||||||
if v == r {
|
|
||||||
return append(s[:i], s[i+1:]...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
func stringSliceRemoveEmpty(s []string) []string {
|
|
||||||
var r []string
|
|
||||||
for _, str := range s {
|
|
||||||
if str != "" {
|
|
||||||
r = append(r, str)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func byteArrayToString(bs []byte) string {
|
|
||||||
b := make([]byte, len(bs))
|
|
||||||
for i, v := range bs {
|
|
||||||
b[i] = v
|
|
||||||
}
|
|
||||||
return string(b)
|
|
||||||
}
|
|
||||||
@@ -1,876 +0,0 @@
|
|||||||
package bpm_utils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"archive/tar"
|
|
||||||
"bufio"
|
|
||||||
"compress/gzip"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/fs"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"slices"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PackageInfo struct {
|
|
||||||
Name string
|
|
||||||
Description string
|
|
||||||
Version string
|
|
||||||
Url string
|
|
||||||
License string
|
|
||||||
Arch string
|
|
||||||
Type string
|
|
||||||
Depends []string
|
|
||||||
MakeDepends []string
|
|
||||||
Provides []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetPackageInfoRaw(filename string) (string, error) {
|
|
||||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
file, err := os.Open(filename)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
archive, err := gzip.NewReader(file)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
tr := tar.NewReader(archive)
|
|
||||||
for {
|
|
||||||
header, err := tr.Next()
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if header.Name == "pkg.info" {
|
|
||||||
bs, _ := io.ReadAll(tr)
|
|
||||||
err := file.Close()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(bs), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "", errors.New("pkg.info not found in archive")
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReadPackage(filename string) (*PackageInfo, error) {
|
|
||||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
file, err := os.Open(filename)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
archive, err := gzip.NewReader(file)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
tr := tar.NewReader(archive)
|
|
||||||
for {
|
|
||||||
header, err := tr.Next()
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if header.Name == "pkg.info" {
|
|
||||||
bs, _ := io.ReadAll(tr)
|
|
||||||
err := file.Close()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
pkgInfo, err := ReadPackageInfo(string(bs), false)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return pkgInfo, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, errors.New("pkg.info not found in archive")
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReadPackageInfo(contents string, defaultValues bool) (*PackageInfo, error) {
|
|
||||||
pkgInfo := PackageInfo{
|
|
||||||
Name: "",
|
|
||||||
Description: "",
|
|
||||||
Version: "",
|
|
||||||
Url: "",
|
|
||||||
License: "",
|
|
||||||
Arch: "",
|
|
||||||
Type: "",
|
|
||||||
Depends: nil,
|
|
||||||
MakeDepends: nil,
|
|
||||||
Provides: nil,
|
|
||||||
}
|
|
||||||
lines := strings.Split(contents, "\n")
|
|
||||||
for num, line := range lines {
|
|
||||||
if len(strings.TrimSpace(line)) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if line[0] == '#' {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
split := strings.SplitN(line, ":", 2)
|
|
||||||
if len(split) != 2 {
|
|
||||||
return nil, errors.New("invalid pkg.info format at line " + strconv.Itoa(num))
|
|
||||||
}
|
|
||||||
split[0] = strings.Trim(split[0], " ")
|
|
||||||
split[1] = strings.Trim(split[1], " ")
|
|
||||||
switch split[0] {
|
|
||||||
case "name":
|
|
||||||
if strings.Contains(split[1], " ") {
|
|
||||||
return nil, errors.New("the " + split[0] + " field cannot contain spaces")
|
|
||||||
}
|
|
||||||
pkgInfo.Name = split[1]
|
|
||||||
case "description":
|
|
||||||
pkgInfo.Description = split[1]
|
|
||||||
case "version":
|
|
||||||
if strings.Contains(split[1], " ") {
|
|
||||||
return nil, errors.New("the " + split[0] + " field cannot contain spaces")
|
|
||||||
}
|
|
||||||
pkgInfo.Version = split[1]
|
|
||||||
case "url":
|
|
||||||
pkgInfo.Url = split[1]
|
|
||||||
case "license":
|
|
||||||
pkgInfo.License = split[1]
|
|
||||||
case "architecture":
|
|
||||||
pkgInfo.Arch = split[1]
|
|
||||||
case "type":
|
|
||||||
pkgInfo.Type = split[1]
|
|
||||||
case "depends":
|
|
||||||
pkgInfo.Depends = strings.Split(strings.Replace(split[1], " ", "", -1), ",")
|
|
||||||
pkgInfo.Depends = stringSliceRemoveEmpty(pkgInfo.Depends)
|
|
||||||
case "make_depends":
|
|
||||||
pkgInfo.MakeDepends = strings.Split(strings.Replace(split[1], " ", "", -1), ",")
|
|
||||||
pkgInfo.MakeDepends = stringSliceRemoveEmpty(pkgInfo.MakeDepends)
|
|
||||||
case "provides":
|
|
||||||
pkgInfo.Provides = strings.Split(strings.Replace(split[1], " ", "", -1), ",")
|
|
||||||
pkgInfo.Provides = stringSliceRemoveEmpty(pkgInfo.Provides)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !defaultValues {
|
|
||||||
if pkgInfo.Name == "" {
|
|
||||||
return nil, errors.New("this package contains no name")
|
|
||||||
} else if pkgInfo.Description == "" {
|
|
||||||
return nil, errors.New("this package contains no description")
|
|
||||||
} else if pkgInfo.Version == "" {
|
|
||||||
return nil, errors.New("this package contains no version")
|
|
||||||
} else if pkgInfo.Arch == "" {
|
|
||||||
return nil, errors.New("this package contains no architecture")
|
|
||||||
} else if pkgInfo.Type == "" {
|
|
||||||
return nil, errors.New("this package contains no type")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return &pkgInfo, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreateInfoFile(pkgInfo PackageInfo) string {
|
|
||||||
ret := ""
|
|
||||||
ret = ret + "name: " + pkgInfo.Name + "\n"
|
|
||||||
ret = ret + "description: " + pkgInfo.Description + "\n"
|
|
||||||
ret = ret + "version: " + pkgInfo.Version + "\n"
|
|
||||||
if pkgInfo.Url != "" {
|
|
||||||
ret = ret + "url: " + pkgInfo.Url + "\n"
|
|
||||||
}
|
|
||||||
if pkgInfo.License != "" {
|
|
||||||
ret = ret + "license: " + pkgInfo.License + "\n"
|
|
||||||
}
|
|
||||||
ret = ret + "architecture: " + pkgInfo.Arch + "\n"
|
|
||||||
ret = ret + "type: " + pkgInfo.Type + "\n"
|
|
||||||
if len(pkgInfo.Depends) > 0 {
|
|
||||||
ret = ret + "depends (" + strconv.Itoa(len(pkgInfo.Depends)) + "): " + strings.Join(pkgInfo.Depends, ",") + "\n"
|
|
||||||
}
|
|
||||||
if len(pkgInfo.Provides) > 0 {
|
|
||||||
ret = ret + "provides (" + strconv.Itoa(len(pkgInfo.Provides)) + "): " + strings.Join(pkgInfo.Provides, ",") + "\n"
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
func InstallPackage(filename, installDir string, force, binaryPkgFromSrc, keepTempDir bool) error {
|
|
||||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
file, err := os.Open(filename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
archive, err := gzip.NewReader(file)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
tr := tar.NewReader(archive)
|
|
||||||
var oldFiles []string
|
|
||||||
var files []string
|
|
||||||
pkgInfo, err := ReadPackage(filename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if IsPackageInstalled(pkgInfo.Name, installDir) {
|
|
||||||
oldFiles = GetPackageFiles(pkgInfo.Name, installDir)
|
|
||||||
}
|
|
||||||
if !force {
|
|
||||||
if pkgInfo.Arch != "any" && pkgInfo.Arch != GetArch() {
|
|
||||||
return errors.New("cannot install a package with a different architecture")
|
|
||||||
}
|
|
||||||
if unresolved := CheckDependencies(pkgInfo, installDir); len(unresolved) != 0 {
|
|
||||||
return errors.New("Could not resolve all dependencies. Missing " + strings.Join(unresolved, ", "))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if pkgInfo.Type == "binary" {
|
|
||||||
seenHardlinks := make(map[string]string)
|
|
||||||
for {
|
|
||||||
header, err := tr.Next()
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(header.Name, "files/") && header.Name != "files/" {
|
|
||||||
extractFilename := path.Join(installDir, strings.TrimPrefix(header.Name, "files/"))
|
|
||||||
switch header.Typeflag {
|
|
||||||
case tar.TypeDir:
|
|
||||||
files = append(files, strings.TrimPrefix(header.Name, "files/"))
|
|
||||||
if err := os.Mkdir(extractFilename, 0755); err != nil {
|
|
||||||
if !os.IsExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Println("Creating Directory: " + extractFilename)
|
|
||||||
}
|
|
||||||
case tar.TypeReg:
|
|
||||||
err := os.Remove(extractFilename)
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
outFile, err := os.Create(extractFilename)
|
|
||||||
fmt.Println("Creating File: " + extractFilename)
|
|
||||||
files = append(files, strings.TrimPrefix(header.Name, "files/"))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := io.Copy(outFile, tr); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := os.Chmod(extractFilename, header.FileInfo().Mode()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = outFile.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case tar.TypeSymlink:
|
|
||||||
fmt.Println("Creating Symlink: " + extractFilename + " -> " + header.Linkname)
|
|
||||||
files = append(files, strings.TrimPrefix(header.Name, "files/"))
|
|
||||||
err := os.Remove(extractFilename)
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = os.Symlink(header.Linkname, extractFilename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case tar.TypeLink:
|
|
||||||
fmt.Println("Detected Hard Link: " + extractFilename + " -> " + path.Join(installDir, strings.TrimPrefix(header.Linkname, "files/")))
|
|
||||||
files = append(files, strings.TrimPrefix(header.Name, "files/"))
|
|
||||||
seenHardlinks[extractFilename] = path.Join(strings.TrimPrefix(header.Linkname, "files/"))
|
|
||||||
err := os.Remove(extractFilename)
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return errors.New("ExtractTarGz: unknown type: " + strconv.Itoa(int(header.Typeflag)) + " in " + extractFilename)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for extractFilename, destination := range seenHardlinks {
|
|
||||||
fmt.Println("Creating Hard Link: " + extractFilename + " -> " + path.Join(installDir, destination))
|
|
||||||
err := os.Link(path.Join(installDir, destination), extractFilename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if pkgInfo.Type == "source" {
|
|
||||||
temp := "/var/tmp/bpm_source-" + pkgInfo.Name
|
|
||||||
err = os.RemoveAll(temp)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = os.Mkdir(temp, 0755)
|
|
||||||
fmt.Println("Creating temp directory at: " + temp)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for {
|
|
||||||
header, err := tr.Next()
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(header.Name, "source-files/") && header.Name != "source-files/" {
|
|
||||||
extractFilename := path.Join(temp, strings.TrimPrefix(header.Name, "source-files/"))
|
|
||||||
switch header.Typeflag {
|
|
||||||
case tar.TypeDir:
|
|
||||||
if err := os.Mkdir(extractFilename, 0755); err != nil {
|
|
||||||
if !os.IsExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Println("Creating Directory: " + extractFilename)
|
|
||||||
}
|
|
||||||
case tar.TypeReg:
|
|
||||||
err := os.Remove(extractFilename)
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
outFile, err := os.Create(extractFilename)
|
|
||||||
fmt.Println("Creating File: " + extractFilename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := io.Copy(outFile, tr); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := os.Chmod(extractFilename, header.FileInfo().Mode()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = outFile.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case tar.TypeSymlink:
|
|
||||||
fmt.Println("Skipping symlink (Bundling symlinks in source packages is not supported)")
|
|
||||||
case tar.TypeLink:
|
|
||||||
fmt.Println("Skipping hard link (Bundling hard links in source packages is not supported)")
|
|
||||||
default:
|
|
||||||
return errors.New("ExtractTarGz: unknown type: " + strconv.Itoa(int(header.Typeflag)) + " in " + extractFilename)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if header.Name == "source.sh" {
|
|
||||||
bs, err := io.ReadAll(tr)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = os.WriteFile(path.Join(temp, "source.sh"), bs, 0644)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if _, err := os.Stat(path.Join(temp, "source.sh")); os.IsNotExist(err) {
|
|
||||||
return errors.New("source.sh file could not be found in the temporary build directory")
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Println("Running source.sh file...")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
cmd := exec.Command("/bin/bash", "-e", "source.sh")
|
|
||||||
cmd.Stdin = os.Stdin
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
cmd.Dir = temp
|
|
||||||
cmd.Env = os.Environ()
|
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_NAME=%s", pkgInfo.Name))
|
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_DESC=%s", pkgInfo.Description))
|
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_VERSION=%s", pkgInfo.Version))
|
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_URL=%s", pkgInfo.Url))
|
|
||||||
depends := make([]string, len(pkgInfo.Depends))
|
|
||||||
copy(depends, pkgInfo.Depends)
|
|
||||||
for i := 0; i < len(depends); i++ {
|
|
||||||
depends[i] = fmt.Sprintf("\"%s\"", depends[i])
|
|
||||||
}
|
|
||||||
makeDepends := make([]string, len(pkgInfo.MakeDepends))
|
|
||||||
copy(makeDepends, pkgInfo.MakeDepends)
|
|
||||||
for i := 0; i < len(makeDepends); i++ {
|
|
||||||
makeDepends[i] = fmt.Sprintf("\"%s\"", makeDepends[i])
|
|
||||||
}
|
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_DEPENDS=(%s)", strings.Join(depends, " ")))
|
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_MAKE_DEPENDS=(%s)", strings.Join(makeDepends, " ")))
|
|
||||||
cmd.Env = append(cmd.Env, "BPM_PKG_TYPE=source")
|
|
||||||
err = cmd.Run()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := os.Stat(path.Join(temp, "/output/")); err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return errors.New("Output directory not be found at " + path.Join(temp, "/output/"))
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Println("Copying all files...")
|
|
||||||
err = filepath.WalkDir(path.Join(temp, "/output/"), func(fullpath string, d fs.DirEntry, err error) error {
|
|
||||||
relFilename, err := filepath.Rel(path.Join(temp, "/output/"), fullpath)
|
|
||||||
if relFilename == "." {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
extractFilename := path.Join(installDir, relFilename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if d.Type() == os.ModeDir {
|
|
||||||
files = append(files, relFilename+"/")
|
|
||||||
if err := os.Mkdir(extractFilename, 0755); err != nil {
|
|
||||||
if !os.IsExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Println("Creating Directory: " + extractFilename)
|
|
||||||
}
|
|
||||||
} else if d.Type().IsRegular() {
|
|
||||||
err := os.Remove(extractFilename)
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
outFile, err := os.Create(extractFilename)
|
|
||||||
fmt.Println("Creating File: " + extractFilename)
|
|
||||||
files = append(files, relFilename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
f, err := os.Open(fullpath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := io.Copy(outFile, f); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
info, err := os.Stat(fullpath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := os.Chmod(extractFilename, info.Mode()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = outFile.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = f.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else if d.Type() == os.ModeSymlink {
|
|
||||||
link, err := os.Readlink(fullpath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = os.Remove(extractFilename)
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Println("Creating Symlink: "+extractFilename, " -> "+link)
|
|
||||||
files = append(files, relFilename)
|
|
||||||
err = os.Symlink(link, extractFilename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if binaryPkgFromSrc {
|
|
||||||
compiledDir := path.Join(installDir, "var/lib/bpm/compiled/")
|
|
||||||
err = os.MkdirAll(compiledDir, 755)
|
|
||||||
compiledInfo := PackageInfo{}
|
|
||||||
compiledInfo = *pkgInfo
|
|
||||||
compiledInfo.Type = "binary"
|
|
||||||
compiledInfo.Arch = GetArch()
|
|
||||||
err = os.WriteFile(path.Join(compiledDir, "pkg.info"), []byte(CreateInfoFile(compiledInfo)), 0644)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
sed := fmt.Sprintf("s/%s/files/", strings.Replace(strings.TrimPrefix(path.Join(temp, "/output/"), "/"), "/", `\/`, -1))
|
|
||||||
cmd := exec.Command("/usr/bin/tar", "-czvf", compiledInfo.Name+"-"+compiledInfo.Version+".bpm", "pkg.info", path.Join(temp, "/output/"), "--transform", sed)
|
|
||||||
cmd.Stdin = os.Stdin
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
cmd.Dir = compiledDir
|
|
||||||
fmt.Printf("running command: %s %s\n", cmd.Path, strings.Join(cmd.Args, " "))
|
|
||||||
err := cmd.Run()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = os.Remove(path.Join(compiledDir, "pkg.info"))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !keepTempDir {
|
|
||||||
err := os.RemoveAll(temp)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(files) == 0 {
|
|
||||||
return errors.New("no output files for source package. Cancelling package installation")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return errors.New("Unknown package type: " + pkgInfo.Type)
|
|
||||||
}
|
|
||||||
slices.Sort(files)
|
|
||||||
slices.Reverse(files)
|
|
||||||
|
|
||||||
filesDiff := slices.DeleteFunc(oldFiles, func(f string) bool {
|
|
||||||
return slices.Contains(files, f)
|
|
||||||
})
|
|
||||||
|
|
||||||
installedDir := path.Join(installDir, "var/lib/bpm/installed/")
|
|
||||||
err = os.MkdirAll(installedDir, 755)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
pkgDir := path.Join(installedDir, pkgInfo.Name)
|
|
||||||
err = os.RemoveAll(pkgDir)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = os.Mkdir(pkgDir, 755)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := os.Create(path.Join(pkgDir, "files"))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, line := range files {
|
|
||||||
_, err := f.WriteString(line + "\n")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err = f.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err = os.Create(path.Join(pkgDir, "info"))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
raw, err := GetPackageInfoRaw(filename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = f.WriteString(raw)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = f.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = archive.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = file.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(filesDiff) != 0 {
|
|
||||||
fmt.Println("Removing obsolete files")
|
|
||||||
for _, f := range filesDiff {
|
|
||||||
f = path.Join(installDir, f)
|
|
||||||
stat, err := os.Lstat(f)
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if stat.IsDir() {
|
|
||||||
dir, err := os.ReadDir(f)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(dir) == 0 {
|
|
||||||
fmt.Println("Removing: " + f)
|
|
||||||
err := os.Remove(f)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Println("Removing: " + f)
|
|
||||||
err := os.Remove(f)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetSourceScript(filename string) (string, error) {
|
|
||||||
pkgInfo, err := ReadPackage(filename)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if pkgInfo.Type != "source" {
|
|
||||||
return "", errors.New("package not of source type")
|
|
||||||
}
|
|
||||||
file, err := os.Open(filename)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
archive, err := gzip.NewReader(file)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
tr := tar.NewReader(archive)
|
|
||||||
for {
|
|
||||||
header, err := tr.Next()
|
|
||||||
if err == io.EOF {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if header.Name == "source.sh" {
|
|
||||||
err := archive.Close()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
err = file.Close()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
bs, err := io.ReadAll(tr)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(bs), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "", errors.New("package does not contain a source.sh file")
|
|
||||||
}
|
|
||||||
|
|
||||||
func CheckDependencies(pkgInfo *PackageInfo, rootDir string) []string {
|
|
||||||
unresolved := make([]string, len(pkgInfo.Depends))
|
|
||||||
copy(unresolved, pkgInfo.Depends)
|
|
||||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
|
||||||
if _, err := os.Stat(installedDir); err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
items, err := os.ReadDir(installedDir)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, item := range items {
|
|
||||||
if !item.IsDir() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, err := os.Stat(path.Join(installedDir, item.Name(), "/info"))
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
bs, err := os.ReadFile(path.Join(installedDir, item.Name(), "/info"))
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
info, err := ReadPackageInfo(string(bs), false)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if slices.Contains(unresolved, info.Name) {
|
|
||||||
unresolved = stringSliceRemove(unresolved, info.Name)
|
|
||||||
}
|
|
||||||
for _, prov := range info.Provides {
|
|
||||||
if slices.Contains(unresolved, prov) {
|
|
||||||
unresolved = stringSliceRemove(unresolved, prov)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return unresolved
|
|
||||||
}
|
|
||||||
|
|
||||||
func CheckMakeDependencies(pkgInfo *PackageInfo, rootDir string) []string {
|
|
||||||
unresolved := make([]string, len(pkgInfo.MakeDepends))
|
|
||||||
copy(unresolved, pkgInfo.MakeDepends)
|
|
||||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
|
||||||
if _, err := os.Stat(installedDir); err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
items, err := os.ReadDir(installedDir)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, item := range items {
|
|
||||||
if !item.IsDir() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, err := os.Stat(path.Join(installedDir, item.Name(), "/info"))
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
bs, err := os.ReadFile(path.Join(installedDir, item.Name(), "/info"))
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
info, err := ReadPackageInfo(string(bs), false)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if slices.Contains(unresolved, info.Name) {
|
|
||||||
unresolved = stringSliceRemove(unresolved, info.Name)
|
|
||||||
}
|
|
||||||
for _, prov := range info.Provides {
|
|
||||||
if slices.Contains(unresolved, prov) {
|
|
||||||
unresolved = stringSliceRemove(unresolved, prov)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return unresolved
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsPackageInstalled(pkg, rootDir string) bool {
|
|
||||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
|
||||||
pkgDir := path.Join(installedDir, pkg)
|
|
||||||
if _, err := os.Stat(pkgDir); err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetInstalledPackages(rootDir string) ([]string, error) {
|
|
||||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
|
||||||
items, err := os.ReadDir(installedDir)
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var ret []string
|
|
||||||
for _, item := range items {
|
|
||||||
ret = append(ret, item.Name())
|
|
||||||
}
|
|
||||||
return ret, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetPackageFiles(pkg, rootDir string) []string {
|
|
||||||
var ret []string
|
|
||||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
|
||||||
pkgDir := path.Join(installedDir, pkg)
|
|
||||||
files := path.Join(pkgDir, "files")
|
|
||||||
if _, err := os.Stat(installedDir); os.IsNotExist(err) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if _, err := os.Stat(pkgDir); os.IsNotExist(err) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
file, err := os.Open(files)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
scanner := bufio.NewScanner(file)
|
|
||||||
for scanner.Scan() {
|
|
||||||
ret = append(ret, scanner.Text())
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetPackageInfo(pkg, rootDir string, defaultValues bool) *PackageInfo {
|
|
||||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
|
||||||
pkgDir := path.Join(installedDir, pkg)
|
|
||||||
files := path.Join(pkgDir, "info")
|
|
||||||
if _, err := os.Stat(installedDir); os.IsNotExist(err) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if _, err := os.Stat(pkgDir); os.IsNotExist(err) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
file, err := os.Open(files)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
bs, err := io.ReadAll(file)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
info, err := ReadPackageInfo(string(bs), defaultValues)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return info
|
|
||||||
}
|
|
||||||
|
|
||||||
func setPackageInfo(pkg, contents, rootDir string) error {
|
|
||||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
|
||||||
pkgDir := path.Join(installedDir, pkg)
|
|
||||||
info := path.Join(pkgDir, "info")
|
|
||||||
if _, err := os.Stat(installedDir); os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := os.Stat(pkgDir); os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
bs := []byte(contents)
|
|
||||||
err := os.WriteFile(info, bs, 0644)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func RemovePackage(pkg, rootDir string) error {
|
|
||||||
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
|
||||||
pkgDir := path.Join(installedDir, pkg)
|
|
||||||
files := GetPackageFiles(pkg, rootDir)
|
|
||||||
for _, file := range files {
|
|
||||||
file = path.Join(rootDir, file)
|
|
||||||
stat, err := os.Lstat(file)
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if stat.IsDir() {
|
|
||||||
dir, err := os.ReadDir(file)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(dir) == 0 {
|
|
||||||
fmt.Println("Removing: " + file)
|
|
||||||
err := os.Remove(file)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Println("Removing: " + file)
|
|
||||||
err := os.Remove(file)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err := os.RemoveAll(pkgDir)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Println("Removing: " + pkgDir)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
privilege_escalator_cmd: "sudo"
|
||||||
|
compilation_env: []
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
ignore_packages: []
|
||||||
|
show_source_package_contents: always
|
||||||
|
cleanup_make_dependencies: true
|
||||||
|
databases:
|
||||||
|
- name: example-database
|
||||||
|
source: https://my-database.xyz/
|
||||||
|
disabled: true
|
||||||
@@ -1,401 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"capcreepergr.me/bpm/bpm_utils"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"slices"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
/* ---BPM | Bubble Package Manager--- */
|
|
||||||
/* Made By CapCreeperGR */
|
|
||||||
/* A simple-to-use package manager */
|
|
||||||
/* ---------------------------------- */
|
|
||||||
|
|
||||||
var bpmVer = "0.1.5"
|
|
||||||
|
|
||||||
var subcommand = "help"
|
|
||||||
var subcommandArgs []string
|
|
||||||
|
|
||||||
// Flags
|
|
||||||
var rootDir = "/"
|
|
||||||
var yesAll = false
|
|
||||||
var buildSource = false
|
|
||||||
var keepTempDir = false
|
|
||||||
var forceInstall = false
|
|
||||||
var pkgListNumbers = false
|
|
||||||
var pkgListNames = false
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
resolveFlags()
|
|
||||||
resolveCommand()
|
|
||||||
}
|
|
||||||
|
|
||||||
type commandType uint8
|
|
||||||
|
|
||||||
const (
|
|
||||||
help commandType = iota
|
|
||||||
version
|
|
||||||
info
|
|
||||||
list
|
|
||||||
install
|
|
||||||
remove
|
|
||||||
file
|
|
||||||
)
|
|
||||||
|
|
||||||
func getCommandType() commandType {
|
|
||||||
switch subcommand {
|
|
||||||
case "version":
|
|
||||||
return version
|
|
||||||
case "info":
|
|
||||||
return info
|
|
||||||
case "list":
|
|
||||||
return list
|
|
||||||
case "install":
|
|
||||||
return install
|
|
||||||
case "remove":
|
|
||||||
return remove
|
|
||||||
case "file":
|
|
||||||
return file
|
|
||||||
default:
|
|
||||||
return help
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func resolveCommand() {
|
|
||||||
switch getCommandType() {
|
|
||||||
case version:
|
|
||||||
fmt.Println("Bubble Package Manager (BPM)")
|
|
||||||
fmt.Println("Version: " + bpmVer)
|
|
||||||
case info:
|
|
||||||
packages := subcommandArgs
|
|
||||||
if len(packages) == 0 {
|
|
||||||
fmt.Println("No packages were given")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for n, pkg := range packages {
|
|
||||||
info := bpm_utils.GetPackageInfo(pkg, rootDir, false)
|
|
||||||
if info == nil {
|
|
||||||
fmt.Printf("Package (%s) could not be found\n", pkg)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*info))
|
|
||||||
if n == len(packages)-1 {
|
|
||||||
fmt.Println("----------------")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case list:
|
|
||||||
packages, err := bpm_utils.GetInstalledPackages(rootDir)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not get installed packages\nError: %s", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(packages) == 0 {
|
|
||||||
fmt.Println("No packages have been installed")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if pkgListNumbers {
|
|
||||||
fmt.Println(len(packages))
|
|
||||||
} else if pkgListNames {
|
|
||||||
for _, pkg := range packages {
|
|
||||||
fmt.Println(pkg)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for n, pkg := range packages {
|
|
||||||
info := bpm_utils.GetPackageInfo(pkg, rootDir, false)
|
|
||||||
if info == nil {
|
|
||||||
fmt.Printf("Package (%s) could not be found\n", pkg)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*info))
|
|
||||||
if n == len(packages)-1 {
|
|
||||||
fmt.Println("----------------")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case install:
|
|
||||||
if os.Getuid() != 0 {
|
|
||||||
fmt.Println("This subcommand needs to be run with superuser permissions")
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
files := subcommandArgs
|
|
||||||
if len(files) == 0 {
|
|
||||||
fmt.Println("No files were given to install")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, file := range files {
|
|
||||||
pkgInfo, err := bpm_utils.ReadPackage(file)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not read package\nError: %s\n", err)
|
|
||||||
}
|
|
||||||
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*pkgInfo))
|
|
||||||
fmt.Println("----------------")
|
|
||||||
verb := "install"
|
|
||||||
if pkgInfo.Type == "source" {
|
|
||||||
verb = "build"
|
|
||||||
}
|
|
||||||
if !forceInstall {
|
|
||||||
if pkgInfo.Arch != "any" && pkgInfo.Arch != bpm_utils.GetArch() {
|
|
||||||
fmt.Printf("skipping... cannot %s a package with a different architecture\n", verb)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if unresolved := bpm_utils.CheckDependencies(pkgInfo, rootDir); len(unresolved) != 0 {
|
|
||||||
fmt.Printf("skipping... cannot %s package (%s) due to missing dependencies: %s\n", verb, pkgInfo.Name, strings.Join(unresolved, ", "))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if pkgInfo.Type == "source" {
|
|
||||||
if unresolved := bpm_utils.CheckMakeDependencies(pkgInfo, rootDir); len(unresolved) != 0 {
|
|
||||||
fmt.Printf("skipping... cannot %s package (%s) due to missing make dependencies: %s\n", verb, pkgInfo.Name, strings.Join(unresolved, ", "))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if rootDir != "/" {
|
|
||||||
fmt.Println("Warning: Installing to " + rootDir)
|
|
||||||
}
|
|
||||||
if !yesAll {
|
|
||||||
reader := bufio.NewReader(os.Stdin)
|
|
||||||
if pkgInfo.Type == "source" {
|
|
||||||
fmt.Print("Would you like to view the source.sh file of this package? [Y\\n] ")
|
|
||||||
text, _ := reader.ReadString('\n')
|
|
||||||
if strings.TrimSpace(strings.ToLower(text)) != "n" && strings.TrimSpace(strings.ToLower(text)) != "no" {
|
|
||||||
script, err := bpm_utils.GetSourceScript(file)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not read source script\nError: %s\n", err)
|
|
||||||
}
|
|
||||||
fmt.Println(script)
|
|
||||||
fmt.Println("-------EOF-------")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if bpm_utils.IsPackageInstalled(pkgInfo.Name, rootDir) {
|
|
||||||
if !yesAll {
|
|
||||||
installedInfo := bpm_utils.GetPackageInfo(pkgInfo.Name, rootDir, false)
|
|
||||||
if strings.Compare(pkgInfo.Version, installedInfo.Version) > 0 {
|
|
||||||
fmt.Println("This file contains a newer version of this package (" + installedInfo.Version + " -> " + pkgInfo.Version + ")")
|
|
||||||
fmt.Print("Do you wish to update this package? [y\\N] ")
|
|
||||||
} else if strings.Compare(pkgInfo.Version, installedInfo.Version) < 0 {
|
|
||||||
fmt.Println("This file contains an older version of this package (" + installedInfo.Version + " -> " + pkgInfo.Version + ")")
|
|
||||||
fmt.Print("Do you wish to downgrade this package? (Not recommended) [y\\N] ")
|
|
||||||
} else if strings.Compare(pkgInfo.Version, installedInfo.Version) == 0 {
|
|
||||||
fmt.Println("This package is already installed on the system and is up to date")
|
|
||||||
fmt.Printf("Do you wish to re%s this package? [y\\N] ", verb)
|
|
||||||
}
|
|
||||||
reader := bufio.NewReader(os.Stdin)
|
|
||||||
text, _ := reader.ReadString('\n')
|
|
||||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
|
||||||
fmt.Printf("Skipping package (%s)...\n", pkgInfo.Name)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if !yesAll {
|
|
||||||
reader := bufio.NewReader(os.Stdin)
|
|
||||||
fmt.Printf("Do you wish to %s this package? [y\\N] ", verb)
|
|
||||||
text, _ := reader.ReadString('\n')
|
|
||||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
|
||||||
fmt.Printf("Skipping package (%s)...\n", pkgInfo.Name)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = bpm_utils.InstallPackage(file, rootDir, forceInstall, buildSource, keepTempDir)
|
|
||||||
if err != nil {
|
|
||||||
if pkgInfo.Type == "source" && keepTempDir {
|
|
||||||
fmt.Println("BPM temp directory was created at /var/tmp/bpm_source-" + pkgInfo.Name)
|
|
||||||
}
|
|
||||||
log.Fatalf("Could not install package\nError: %s\n", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Package (%s) was successfully installed!\n", pkgInfo.Name)
|
|
||||||
if pkgInfo.Type == "source" && keepTempDir {
|
|
||||||
fmt.Println("** It is recommended you delete the temporary bpm folder in /var/tmp **")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case remove:
|
|
||||||
if os.Getuid() != 0 {
|
|
||||||
fmt.Println("This subcommand needs to be run with superuser permissions")
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
packages := subcommandArgs
|
|
||||||
if len(packages) == 0 {
|
|
||||||
fmt.Println("No packages were given")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, pkg := range packages {
|
|
||||||
pkgInfo := bpm_utils.GetPackageInfo(pkg, rootDir, false)
|
|
||||||
if pkgInfo == nil {
|
|
||||||
fmt.Printf("Package (%s) could not be found\n", pkg)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*pkgInfo))
|
|
||||||
fmt.Println("----------------")
|
|
||||||
if rootDir != "/" {
|
|
||||||
fmt.Println("Warning: Installing to " + rootDir)
|
|
||||||
}
|
|
||||||
if !yesAll {
|
|
||||||
reader := bufio.NewReader(os.Stdin)
|
|
||||||
fmt.Print("Do you wish to remove this package? [y\\N] ")
|
|
||||||
text, _ := reader.ReadString('\n')
|
|
||||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
|
||||||
fmt.Printf("Skipping package (%s)...\n", pkgInfo.Name)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err := bpm_utils.RemovePackage(pkg, rootDir)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not remove package\nError: %s\n", err)
|
|
||||||
}
|
|
||||||
fmt.Printf("Package (%s) was successfully removed!\n", pkgInfo.Name)
|
|
||||||
}
|
|
||||||
case file:
|
|
||||||
files := subcommandArgs
|
|
||||||
if len(files) == 0 {
|
|
||||||
fmt.Println("No files were given to get which packages manage it")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, file := range files {
|
|
||||||
absFile, err := filepath.Abs(file)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not get absolute path of %s", file)
|
|
||||||
}
|
|
||||||
stat, err := os.Stat(absFile)
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
log.Fatalf(absFile + " does not exist!")
|
|
||||||
}
|
|
||||||
pkgs, err := bpm_utils.GetInstalledPackages(rootDir)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not get installed packages. Error %s", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.HasPrefix(absFile, rootDir) {
|
|
||||||
log.Fatalf("Could not get relative path of %s to root path", absFile)
|
|
||||||
}
|
|
||||||
absFile, err = filepath.Rel(rootDir, absFile)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not get relative path of %s to root path", absFile)
|
|
||||||
}
|
|
||||||
absFile = strings.TrimPrefix(absFile, "/")
|
|
||||||
if stat.IsDir() {
|
|
||||||
absFile = absFile + "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
var pkgList []string
|
|
||||||
for _, pkg := range pkgs {
|
|
||||||
if slices.Contains(bpm_utils.GetPackageFiles(pkg, rootDir), absFile) {
|
|
||||||
pkgList = append(pkgList, pkg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(pkgList) == 0 {
|
|
||||||
fmt.Println(absFile + " is not managed by any packages")
|
|
||||||
} else {
|
|
||||||
fmt.Println(absFile + " is managed by the following packages:")
|
|
||||||
for _, pkg := range pkgList {
|
|
||||||
fmt.Println("- " + pkg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
printHelp()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func printHelp() {
|
|
||||||
fmt.Println("\033[1m------Help------\033[0m")
|
|
||||||
fmt.Println("\033[1m\\ Command Format /\033[0m")
|
|
||||||
fmt.Println("-> command format: bpm <subcommand> [-flags]...")
|
|
||||||
fmt.Println("-> flags will be read if passed right after the subcommand otherwise they will be read as subcommand arguments")
|
|
||||||
fmt.Println("\033[1m\\ Command List /\033[0m")
|
|
||||||
fmt.Println("-> bpm version | shows information on the installed version of bpm")
|
|
||||||
fmt.Println("-> bpm info [-R] | shows information on an installed package")
|
|
||||||
fmt.Println(" -R=<root_path> lets you define the root path which will be used")
|
|
||||||
fmt.Println("-> bpm list [-R, -n, -l] | lists all installed packages")
|
|
||||||
fmt.Println(" -R=<root_path> lets you define the root path which will be used")
|
|
||||||
fmt.Println(" -n shows the number of packages")
|
|
||||||
fmt.Println(" -l lists package names only")
|
|
||||||
fmt.Println("-> bpm install [-R, -y, -f, -b] <files...> | installs the following files")
|
|
||||||
fmt.Println(" -R=<root_path> lets you define the root path which will be used")
|
|
||||||
fmt.Println(" -y skips the confirmation prompt")
|
|
||||||
fmt.Println(" -f skips dependency and architecture checking")
|
|
||||||
fmt.Println(" -b creates a binary package for a source package after compilation and saves it in /var/lib/bpm/compiled")
|
|
||||||
fmt.Println(" -k keeps the temp directory created by BPM after source package installation")
|
|
||||||
fmt.Println("-> bpm remove [-R, -y] <packages...> | removes the following packages")
|
|
||||||
fmt.Println(" -R=<root_path> lets you define the root path which will be used")
|
|
||||||
fmt.Println(" -y skips the confirmation prompt")
|
|
||||||
fmt.Println("-> bpm file [-R] <files...> | shows what packages the following packages are managed by")
|
|
||||||
fmt.Println(" -R=<root_path> lets you define the root path which will be used")
|
|
||||||
fmt.Println("\033[1m----------------\033[0m")
|
|
||||||
}
|
|
||||||
|
|
||||||
func resolveFlags() {
|
|
||||||
// List flags
|
|
||||||
listFlagSet := flag.NewFlagSet("List flags", flag.ExitOnError)
|
|
||||||
listFlagSet.Usage = printHelp
|
|
||||||
listFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
|
||||||
listFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
|
||||||
listFlagSet.BoolVar(&pkgListNumbers, "n", false, "List the number of all packages installed with BPM")
|
|
||||||
listFlagSet.BoolVar(&pkgListNames, "l", false, "List the names of all packages installed with BPM")
|
|
||||||
// Info flags
|
|
||||||
infoFlagSet := flag.NewFlagSet("Info flags", flag.ExitOnError)
|
|
||||||
infoFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
|
||||||
infoFlagSet.Usage = printHelp
|
|
||||||
// Install flags
|
|
||||||
installFlagSet := flag.NewFlagSet("Install flags", flag.ExitOnError)
|
|
||||||
installFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
|
||||||
installFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
|
||||||
installFlagSet.BoolVar(&buildSource, "b", false, "Build binary package from source package")
|
|
||||||
installFlagSet.BoolVar(&keepTempDir, "k", false, "Keep temporary directory after source compilation")
|
|
||||||
installFlagSet.BoolVar(&forceInstall, "f", false, "Force installation by skipping architecture and dependency resolution")
|
|
||||||
installFlagSet.Usage = printHelp
|
|
||||||
// Remove flags
|
|
||||||
removeFlagSet := flag.NewFlagSet("Remove flags", flag.ExitOnError)
|
|
||||||
removeFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
|
||||||
removeFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
|
||||||
removeFlagSet.Usage = printHelp
|
|
||||||
// File flags
|
|
||||||
// Remove flags
|
|
||||||
fileFlagSet := flag.NewFlagSet("Remove flags", flag.ExitOnError)
|
|
||||||
fileFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
|
||||||
fileFlagSet.Usage = printHelp
|
|
||||||
if len(os.Args[1:]) <= 0 {
|
|
||||||
subcommand = "help"
|
|
||||||
} else {
|
|
||||||
subcommand = os.Args[1]
|
|
||||||
subcommandArgs = os.Args[2:]
|
|
||||||
if getCommandType() == list {
|
|
||||||
err := listFlagSet.Parse(subcommandArgs)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
subcommandArgs = listFlagSet.Args()
|
|
||||||
} else if getCommandType() == info {
|
|
||||||
err := infoFlagSet.Parse(subcommandArgs)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
subcommandArgs = infoFlagSet.Args()
|
|
||||||
} else if getCommandType() == install {
|
|
||||||
err := installFlagSet.Parse(subcommandArgs)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
subcommandArgs = installFlagSet.Args()
|
|
||||||
} else if getCommandType() == remove {
|
|
||||||
err := removeFlagSet.Parse(subcommandArgs)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
subcommandArgs = removeFlagSet.Args()
|
|
||||||
} else if getCommandType() == file {
|
|
||||||
err := fileFlagSet.Parse(subcommandArgs)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
subcommandArgs = fileFlagSet.Args()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
module bpm
|
||||||
|
|
||||||
|
go 1.24.0
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/EnumeratedDev/bpm/src/bpmlib v0.0.0
|
||||||
|
github.com/lithammer/fuzzysearch v1.1.8
|
||||||
|
github.com/spf13/pflag v1.0.10
|
||||||
|
)
|
||||||
|
|
||||||
|
replace github.com/EnumeratedDev/bpm/src/bpmlib => ../bpmlib
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/drone/envsubst v1.0.3 // indirect
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f // indirect
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||||
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
|
github.com/schollz/progressbar/v3 v3.18.0 // indirect
|
||||||
|
golang.org/x/sys v0.37.0 // indirect
|
||||||
|
golang.org/x/term v0.36.0 // indirect
|
||||||
|
golang.org/x/text v0.9.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM=
|
||||||
|
github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/drone/envsubst v1.0.3 h1:PCIBwNDYjs50AsLZPYdfhSATKaRg/FJmDc2D6+C2x8g=
|
||||||
|
github.com/drone/envsubst v1.0.3/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g=
|
||||||
|
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
||||||
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f h1:xt29M2T6STgldg+WEP51gGePQCsQvklmP2eIhPIBK3g=
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f/go.mod h1:i4sF0l1fFnY1aiw08QQSwVAFxHEm311Me3WsU/X7nL0=
|
||||||
|
github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4=
|
||||||
|
github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4=
|
||||||
|
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||||
|
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
|
github.com/schollz/progressbar/v3 v3.18.0 h1:uXdoHABRFmNIjUfte/Ex7WtuyVslrw2wVPQmCN62HpA=
|
||||||
|
github.com/schollz/progressbar/v3 v3.18.0/go.mod h1:IsO3lpbaGuzh8zIMzgY3+J8l4C8GjO0Y9S69eFvNsec=
|
||||||
|
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
||||||
|
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
|
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
|
||||||
|
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
|
golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
|
||||||
|
golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
||||||
|
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
|
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
+1690
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,758 @@
|
|||||||
|
package bpmlib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"slices"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/drone/envsubst"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
var rootCompilationUID = "65534"
|
||||||
|
var rootCompilationGID = "65534"
|
||||||
|
|
||||||
|
func CompileSourcePackage(archiveFilename, outputDirectory string, compilationJobs int, skipChecks, keepCompilationFiles, verbose bool) (outputBpmPackages map[string]string, err error) {
|
||||||
|
// Set compilation jobs
|
||||||
|
if compilationJobs <= 0 || compilationJobs > runtime.NumCPU() {
|
||||||
|
compilationJobs = runtime.NumCPU()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize map
|
||||||
|
outputBpmPackages = make(map[string]string)
|
||||||
|
|
||||||
|
// Read BPM archive
|
||||||
|
bpmpkg, err := ReadPackage(archiveFilename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure package type is 'source'
|
||||||
|
if bpmpkg.PkgInfo.Type != "source" {
|
||||||
|
return nil, errors.New("cannot compile a non-source package")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get HOME directory
|
||||||
|
homeDir, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get UID and GID to use for compilation
|
||||||
|
var uid, gid int
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
_uid, err := strconv.ParseInt(rootCompilationUID, 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not convert UID '%s' to int", rootCompilationUID)
|
||||||
|
}
|
||||||
|
_gid, err := strconv.ParseInt(rootCompilationGID, 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not convert GID '%s' to int", rootCompilationGID)
|
||||||
|
}
|
||||||
|
uid = int(_uid)
|
||||||
|
gid = int(_gid)
|
||||||
|
} else {
|
||||||
|
uid = os.Getuid()
|
||||||
|
gid = os.Getgid()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set temporary directory
|
||||||
|
var tempDirectory string
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
tempDirectory = path.Join("/var/cache/bpm/compilation/", bpmpkg.PkgInfo.Name)
|
||||||
|
} else {
|
||||||
|
tempDirectory = path.Join(homeDir, ".cache/bpm/compilation/", bpmpkg.PkgInfo.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure temporary directory does not exist
|
||||||
|
if _, err := os.Stat(tempDirectory); err == nil {
|
||||||
|
err := os.RemoveAll(tempDirectory)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create temporary directory
|
||||||
|
err = os.MkdirAll(tempDirectory, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change temporary directory owner
|
||||||
|
err = os.Chown(tempDirectory, uid, gid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract source.sh file
|
||||||
|
err = extractTarballFile(archiveFilename, "source.sh", tempDirectory, uid, gid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get package scripts and extract them
|
||||||
|
packageScripts := getPackageScripts(archiveFilename)
|
||||||
|
for _, script := range packageScripts {
|
||||||
|
err = extractTarballFile(archiveFilename, script, tempDirectory, uid, gid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract source files
|
||||||
|
err = extractTarballDirectory(archiveFilename, "source-files", tempDirectory, uid, gid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create source directory
|
||||||
|
err = os.Mkdir(path.Join(tempDirectory, "source"), 0755)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change source directory owner
|
||||||
|
err = os.Chown(path.Join(tempDirectory, "source"), uid, gid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download files
|
||||||
|
err = downloadPackageFiles(bpmpkg.PkgInfo, tempDirectory, verbose)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup environment for commands
|
||||||
|
env := os.Environ()
|
||||||
|
env = append(env, "HOME="+tempDirectory)
|
||||||
|
env = append(env, "BPM_WORKDIR="+tempDirectory)
|
||||||
|
env = append(env, "BPM_SOURCE="+path.Join(tempDirectory, "source"))
|
||||||
|
env = append(env, "BPM_PKG_NAME="+bpmpkg.PkgInfo.Name)
|
||||||
|
env = append(env, "BPM_PKG_VERSION="+bpmpkg.PkgInfo.Version)
|
||||||
|
env = append(env, "BPM_PKG_REVISION="+strconv.Itoa(bpmpkg.PkgInfo.Revision))
|
||||||
|
env = append(env, "BPM_PKG_URL="+bpmpkg.PkgInfo.Url)
|
||||||
|
env = append(env, "BPM_PKG_ARCH="+bpmpkg.PkgInfo.OutputArch)
|
||||||
|
env = append(env, "BPM_JOBS="+strconv.Itoa(compilationJobs))
|
||||||
|
env = append(env, CompilationBPMConfig.CompilationEnvironment...)
|
||||||
|
|
||||||
|
// Set common flags used for limiting job count
|
||||||
|
makeflags := ""
|
||||||
|
env = slices.DeleteFunc(env, func(s string) bool {
|
||||||
|
if strings.HasPrefix(s, "MAKEFLAGS=") {
|
||||||
|
makeflags = s + " "
|
||||||
|
return true
|
||||||
|
} else if strings.HasPrefix(s, "CMAKE_BUILD_PARALLEL_LEVEL=") {
|
||||||
|
return true
|
||||||
|
} else if strings.HasPrefix(s, "CARGO_BUILD_JOBS=") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
env = append(env, makeflags+"-j"+strconv.Itoa(compilationJobs))
|
||||||
|
env = append(env, "CMAKE_BUILD_PARALLEL_LEVEL="+strconv.Itoa(compilationJobs))
|
||||||
|
env = append(env, "CARGO_BUILD_JOBS="+strconv.Itoa(compilationJobs))
|
||||||
|
|
||||||
|
// Execute prepare and build functions in source.sh script
|
||||||
|
cmd := exec.Command("bash", "-c",
|
||||||
|
"set -a\n"+ // Source and export functions and variables in source.sh script
|
||||||
|
". \"${BPM_WORKDIR}\"/source.sh\n"+
|
||||||
|
"set +a\n"+
|
||||||
|
"[[ $(type -t prepare) == \"function\" ]] && { echo \"Running prepare() function...\"; bash -e -c 'cd \"$BPM_WORKDIR\" && prepare' || exit 1; }\n"+ // Run prepare() function if it exists
|
||||||
|
"[[ $(type -t build) == \"function\" ]] && { echo \"Running build() function...\"; bash -e -c 'cd \"$BPM_SOURCE\" && build' || exit 1; }\n"+ // Run build() function if it exists
|
||||||
|
"exit 0")
|
||||||
|
cmd.Dir = tempDirectory
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Env = env
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||||
|
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
|
||||||
|
}
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute check function in source.sh script if not skipping checks
|
||||||
|
if !skipChecks {
|
||||||
|
cmd = exec.Command("bash", "-c",
|
||||||
|
"set -a\n"+ // Source and export functions and variables in source.sh script
|
||||||
|
". \"${BPM_WORKDIR}\"/source.sh\n"+
|
||||||
|
"set +a\n"+
|
||||||
|
"[[ $(type -t check) == \"function\" ]] && { echo \"Running check() function...\"; bash -e -c 'cd \"$BPM_SOURCE\" && check' || exit 1; }\n"+ // Run check() function if it exists
|
||||||
|
"exit 0")
|
||||||
|
cmd.Dir = tempDirectory
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Env = env
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||||
|
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
|
||||||
|
}
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all packages to compile
|
||||||
|
packagesToCompile := bpmpkg.PkgInfo.SplitPackages
|
||||||
|
if !bpmpkg.PkgInfo.IsSplitPackage() {
|
||||||
|
packagesToCompile = append(packagesToCompile, bpmpkg.PkgInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create output directories for each package
|
||||||
|
for _, pkg := range packagesToCompile {
|
||||||
|
// Create new output directory
|
||||||
|
err = os.Mkdir(path.Join(tempDirectory, "output_"+pkg.Name), 0755)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change output directory owner
|
||||||
|
err = os.Chown(path.Join(tempDirectory, "output_"+pkg.Name), uid, gid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compile each package
|
||||||
|
for _, pkg := range packagesToCompile {
|
||||||
|
// Get package function name
|
||||||
|
packageFunctionName := "package"
|
||||||
|
if bpmpkg.PkgInfo.IsSplitPackage() {
|
||||||
|
packageFunctionName = "package_" + pkg.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute package function in source.sh script and generate package file list
|
||||||
|
cmd = exec.Command("bash", "-c",
|
||||||
|
"set -a\n"+ // Source and export functions and variables in source.sh script
|
||||||
|
". \"${BPM_WORKDIR}\"/source.sh\n"+
|
||||||
|
"set +a\n"+
|
||||||
|
"echo \"Running "+packageFunctionName+"() function...\"\n"+
|
||||||
|
"( cd \"$BPM_SOURCE\" && fakeroot -s \"$BPM_WORKDIR\"/fakeroot_file bash -e -c '"+packageFunctionName+"' ) || exit 1\n") // Run package() function
|
||||||
|
|
||||||
|
cmd.Dir = tempDirectory
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Env = append(env, "BPM_OUTPUT="+path.Join(tempDirectory, "output_"+pkg.Name))
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||||
|
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
|
||||||
|
}
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip all ELF binaries
|
||||||
|
if !slices.Contains(pkg.Options, "nostrip") {
|
||||||
|
if _, err := exec.LookPath("strip"); err != nil {
|
||||||
|
fmt.Println("Skip stripping ELF binaries. 'strip' not in path")
|
||||||
|
} else {
|
||||||
|
fmt.Println("Stripping ELF binaries...")
|
||||||
|
|
||||||
|
err = filepath.WalkDir(path.Join(tempDirectory, "output_"+pkg.Name), func(path string, d fs.DirEntry, err error) error {
|
||||||
|
cmd = exec.Command("file", "-bi", path)
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
mimetype := strings.Split(string(output), ";")[0]
|
||||||
|
|
||||||
|
if strings.HasPrefix(mimetype, "application/x-executable") {
|
||||||
|
cmd := exec.Command("strip", path)
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if verbose {
|
||||||
|
fmt.Printf("Stripped %s (%s)\n", path, mimetype)
|
||||||
|
}
|
||||||
|
} else if strings.HasPrefix(mimetype, "application/x-pie-executable") || strings.HasPrefix(mimetype, "application/x-sharedlib") {
|
||||||
|
cmd = exec.Command("file", "-b", path)
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
output, err = cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Skip files that use ELF as a container format
|
||||||
|
if strings.Contains(string(output), "no machine") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command("strip", "--strip-unneeded", path)
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if verbose {
|
||||||
|
fmt.Printf("Stripped %s (%s)\n", path, mimetype)
|
||||||
|
}
|
||||||
|
} else if strings.HasPrefix(mimetype, "application/x-archive") {
|
||||||
|
cmd := exec.Command("strip", "--strip-debug", path)
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if verbose {
|
||||||
|
fmt.Printf("Stripped %s (%s)\n", path, mimetype)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate package file list
|
||||||
|
fmt.Println("Generating package file list...")
|
||||||
|
cmd = exec.Command("bash", "-c", "fakeroot -i \"$BPM_WORKDIR\"/fakeroot_file find \"$BPM_OUTPUT\" -mindepth 1 -printf \"%P %#m %U %G %s\\n\" > \"$BPM_WORKDIR\"/pkg.files")
|
||||||
|
cmd.Dir = tempDirectory
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Env = append(env, "BPM_OUTPUT="+path.Join(tempDirectory, "output_"+pkg.Name))
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||||
|
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
|
||||||
|
}
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create gzip-compressed archive for the package files
|
||||||
|
fmt.Println("Generating compressed file archive...")
|
||||||
|
cmd = exec.Command("bash", "-c", fmt.Sprintf("find %s -printf \"%%P\\n\" | fakeroot -i %s/fakeroot_file tar -czf files.tar.gz --no-recursion -C %s -T -", "output_"+pkg.Name, tempDirectory, "output_"+pkg.Name))
|
||||||
|
cmd.Dir = tempDirectory
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Env = env
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||||
|
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
|
||||||
|
}
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("files.tar.gz archive could not be created: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone source package info
|
||||||
|
pkgInfo := *pkg
|
||||||
|
|
||||||
|
// Set package type to binary
|
||||||
|
pkgInfo.Type = "binary"
|
||||||
|
|
||||||
|
// Set package architecture
|
||||||
|
pkgInfo.Arch = pkg.OutputArch
|
||||||
|
pkgInfo.OutputArch = ""
|
||||||
|
|
||||||
|
// Remove split package and downloads fields
|
||||||
|
pkgInfo.SplitPackages = nil
|
||||||
|
pkgInfo.Downloads = nil
|
||||||
|
|
||||||
|
// Marshal package info
|
||||||
|
pkgInfoBytes, err := yaml.Marshal(pkgInfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
pkgInfoBytes = append(pkgInfoBytes, '\n')
|
||||||
|
|
||||||
|
// Create pkg.info file
|
||||||
|
err = os.WriteFile(path.Join(tempDirectory, "pkg.info"), pkgInfoBytes, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change pkg.info file owner
|
||||||
|
err = os.Chown(path.Join(tempDirectory, "pkg.info"), uid, gid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get files to include in BPM archive
|
||||||
|
bpmArchiveFiles := make([]string, 0)
|
||||||
|
bpmArchiveFiles = append(bpmArchiveFiles, "pkg.info", "pkg.files", "files.tar.gz") // Base files
|
||||||
|
bpmArchiveFiles = append(bpmArchiveFiles, packageScripts...) // Package scripts
|
||||||
|
|
||||||
|
// Create final BPM archive
|
||||||
|
fmt.Println("Generating final BPM archive...")
|
||||||
|
cmd = exec.Command("bash", "-c", "tar -cf final-archive.bpm --owner=0 --group=0 -C \"$BPM_WORKDIR\" "+strings.Join(bpmArchiveFiles, " "))
|
||||||
|
cmd.Dir = tempDirectory
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
currentDir, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
cmd.Env = append(env, "CURRENT_DIR="+currentDir)
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||||
|
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
|
||||||
|
}
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("BPM archive could not be created: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove pkg.info file
|
||||||
|
err = os.Remove(path.Join(tempDirectory, "pkg.info"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set output filename
|
||||||
|
outputFilename := path.Join(outputDirectory, fmt.Sprintf("%s-%s-%d-%s.bpm", pkgInfo.Name, pkgInfo.Version, pkgInfo.Revision, pkgInfo.Arch))
|
||||||
|
|
||||||
|
// Move final BPM archive
|
||||||
|
err = os.Rename(path.Join(tempDirectory, "final-archive.bpm"), outputFilename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set final BPM archive owner
|
||||||
|
err = os.Chown(outputFilename, os.Getuid(), os.Getgid())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove output directory
|
||||||
|
err = os.RemoveAll(path.Join(tempDirectory, "output_"+pkg.Name))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
outputBpmPackages[pkgInfo.Name] = outputFilename
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete temporary directory
|
||||||
|
if !keepCompilationFiles {
|
||||||
|
os.RemoveAll(tempDirectory)
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputBpmPackages, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func downloadPackageFiles(pkgInfo *PackageInfo, tempDirectory string, verbose bool) error {
|
||||||
|
// Get UID and GID to use for compilation
|
||||||
|
var uid, gid int
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
_uid, err := strconv.ParseInt(rootCompilationUID, 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not convert UID '%s' to int", rootCompilationUID)
|
||||||
|
}
|
||||||
|
_gid, err := strconv.ParseInt(rootCompilationGID, 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not convert GID '%s' to int", rootCompilationGID)
|
||||||
|
}
|
||||||
|
uid = int(_uid)
|
||||||
|
gid = int(_gid)
|
||||||
|
} else {
|
||||||
|
uid = os.Getuid()
|
||||||
|
gid = os.Getgid()
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, download := range pkgInfo.Downloads {
|
||||||
|
// Replace variables
|
||||||
|
replaceVars := func(s string) string {
|
||||||
|
switch s {
|
||||||
|
case "BPM_PKG_NAME":
|
||||||
|
return pkgInfo.Name
|
||||||
|
case "BPM_PKG_VERSION":
|
||||||
|
return pkgInfo.Version
|
||||||
|
case "BPM_PKG_URL":
|
||||||
|
return pkgInfo.Url
|
||||||
|
case "BPM_SOURCE":
|
||||||
|
return path.Join(tempDirectory, "source/")
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadUrl, err := envsubst.Eval(strings.TrimSpace(download.Url), replaceVars)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
filepath, err := envsubst.Eval(strings.TrimSpace(download.Filepath), replaceVars)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
extractTo, err := envsubst.Eval(strings.TrimSpace(download.ExtractTo), replaceVars)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cloneTo, err := envsubst.Eval(strings.TrimSpace(download.CloneTo), replaceVars)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make relative paths absolute
|
||||||
|
if extractTo != "" && extractTo[0] != '/' {
|
||||||
|
extractTo = path.Join(tempDirectory, extractTo)
|
||||||
|
}
|
||||||
|
// Make relative paths absolute
|
||||||
|
if cloneTo != "" && cloneTo[0] != '/' {
|
||||||
|
cloneTo = path.Join(tempDirectory, cloneTo)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch download.Type {
|
||||||
|
case "", "file":
|
||||||
|
if filepath == "" {
|
||||||
|
filepath = path.Join(tempDirectory, path.Base(downloadUrl))
|
||||||
|
}
|
||||||
|
if filepath[0] != '/' {
|
||||||
|
filepath = path.Join(tempDirectory, filepath)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := downloadFile("Downloading file "+path.Base(filepath), downloadUrl, filepath, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if download.Checksum != "skip" {
|
||||||
|
f, err := os.Open(filepath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
h := sha256.New()
|
||||||
|
_, err = io.Copy(h, f)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if hex.EncodeToString(h.Sum(nil)) != download.Checksum {
|
||||||
|
fmt.Printf("Downloaded file checksum: %x\n", h.Sum(nil))
|
||||||
|
return fmt.Errorf("downloaded file checksums did not match")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("Skipping checksum checking...")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change downloaded file ownership
|
||||||
|
err = os.Chown(filepath, uid, gid)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !download.NoExtract && (strings.Contains(filepath, ".tar") || strings.HasSuffix(filepath, ".tgz")) {
|
||||||
|
cmd := exec.Command("tar", "xf", filepath, "--strip-components="+strconv.Itoa(download.ExtractStripComponents))
|
||||||
|
if verbose {
|
||||||
|
cmd.Args[1] = "xvf"
|
||||||
|
}
|
||||||
|
cmd.Dir = tempDirectory
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||||
|
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
|
||||||
|
}
|
||||||
|
if extractTo != "" {
|
||||||
|
err := os.MkdirAll(extractTo, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cmd.Args = append(cmd.Args, "-C", extractTo)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if !download.NoExtract && strings.HasSuffix(filepath, ".zip") {
|
||||||
|
cmd := exec.Command("unzip", filepath)
|
||||||
|
cmd.Dir = tempDirectory
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||||
|
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
|
||||||
|
}
|
||||||
|
if extractTo != "" {
|
||||||
|
err := os.MkdirAll(extractTo, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cmd.Args = append(cmd.Args, "-d", extractTo)
|
||||||
|
} else {
|
||||||
|
err := os.Mkdir(path.Join(tempDirectory, strings.TrimSuffix(path.Base(filepath), ".zip")), 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Args = append(cmd.Args, "-d", path.Join(tempDirectory, strings.TrimSuffix(path.Base(filepath), ".zip")))
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "git":
|
||||||
|
// Replace variables in git branch
|
||||||
|
gitBranch := download.GitBranch
|
||||||
|
gitBranch, err := envsubst.Eval(gitBranch, func(s string) string {
|
||||||
|
switch s {
|
||||||
|
case "BPM_PKG_NAME":
|
||||||
|
return pkgInfo.Name
|
||||||
|
case "BPM_PKG_VERSION":
|
||||||
|
return pkgInfo.Version
|
||||||
|
case "BPM_PKG_URL":
|
||||||
|
return pkgInfo.Url
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command("git", "clone", "--depth=1", downloadUrl)
|
||||||
|
cmd.Dir = tempDirectory
|
||||||
|
if os.Getuid() == 0 {
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||||
|
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}
|
||||||
|
}
|
||||||
|
if gitBranch != "" {
|
||||||
|
cmd.Args = slices.Insert(cmd.Args, len(cmd.Args)-1, "--branch="+gitBranch)
|
||||||
|
}
|
||||||
|
if cloneTo != "" {
|
||||||
|
err := os.MkdirAll(cloneTo, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cmd.Args = append(cmd.Args, cloneTo)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if download.Checksum != "skip" {
|
||||||
|
cmd := exec.Command("git", "rev-parse", "HEAD")
|
||||||
|
if cloneTo != "" {
|
||||||
|
cmd.Dir = cloneTo
|
||||||
|
} else {
|
||||||
|
cmd.Dir = path.Join(tempDirectory, strings.TrimSuffix(path.Base(downloadUrl), ".git"))
|
||||||
|
}
|
||||||
|
|
||||||
|
branchChecksum, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(string(branchChecksum)) != download.Checksum {
|
||||||
|
fmt.Printf("Git branch checksum: %s\n", strings.TrimSpace(string(branchChecksum)))
|
||||||
|
return fmt.Errorf("Cloned git repository checksum did not match")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("Skipping checksum checking...")
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unknown download type (%s)", download.Type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func showPackageFiles(archiveFilename string) error {
|
||||||
|
// Read BPM archive
|
||||||
|
bpmpkg, err := ReadPackage(archiveFilename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure package type is 'source'
|
||||||
|
if bpmpkg.PkgInfo.Type != "source" {
|
||||||
|
return fmt.Errorf("cannot compile a non-source package")
|
||||||
|
}
|
||||||
|
|
||||||
|
printTarballContent := func(filename string) error {
|
||||||
|
// Get tarball reader for file
|
||||||
|
reader, err := readTarballFile(archiveFilename, filename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read file content
|
||||||
|
data, err := io.ReadAll(reader.tarReader)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print file name and content
|
||||||
|
fmt.Println("==============================")
|
||||||
|
fmt.Printf("%s: %s\n", bpmpkg.PkgInfo.Name, filename)
|
||||||
|
fmt.Println("==============================")
|
||||||
|
fmt.Printf("%s\n", data)
|
||||||
|
|
||||||
|
// Close reader
|
||||||
|
err = reader.file.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print pkg.info content
|
||||||
|
err = printTarballContent("pkg.info")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print source files contents
|
||||||
|
files, err := listTarballContent(archiveFilename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, file := range files {
|
||||||
|
if !strings.HasPrefix(file, "source-files/") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print source file content
|
||||||
|
err = printTarballContent(file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print source.sh content
|
||||||
|
err = printTarballContent("source.sh")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package bpmlib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MainBPMConfigStruct struct {
|
||||||
|
IgnorePackages []string `yaml:"ignore_packages"`
|
||||||
|
IgnorePaths []string `yaml:"ignore_paths"`
|
||||||
|
ShowSourcePackageContents string `yaml:"show_source_package_contents"`
|
||||||
|
CleanupMakeDependencies bool `yaml:"cleanup_make_dependencies"`
|
||||||
|
Databases []configDatabase `yaml:"databases"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type configDatabase struct {
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
Source string `yaml:"source"`
|
||||||
|
VerificationLevel string `yaml:"verification_level"`
|
||||||
|
Disabled *bool `yaml:"disabled"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CompilationBPMConfigStruct struct {
|
||||||
|
PrivilegeEscalatorCmd string `yaml:"privilege_escalator_cmd"`
|
||||||
|
CompilationJobs int `yaml:"compilation_jobs"`
|
||||||
|
CompilationEnvironment []string `yaml:"compilation_env"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var MainBPMConfig MainBPMConfigStruct
|
||||||
|
var CompilationBPMConfig CompilationBPMConfigStruct
|
||||||
|
|
||||||
|
func ReadConfig() (err error) {
|
||||||
|
var file *os.File
|
||||||
|
|
||||||
|
// Set default config options
|
||||||
|
MainBPMConfig = MainBPMConfigStruct{
|
||||||
|
ShowSourcePackageContents: "always",
|
||||||
|
CleanupMakeDependencies: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read main BPM config
|
||||||
|
file, err = os.Open("/etc/bpm.conf")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = yaml.NewDecoder(file).Decode(&MainBPMConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
file.Close()
|
||||||
|
|
||||||
|
// Read compilation BPM config
|
||||||
|
if _, err := os.Stat("/etc/bpm-compilation.conf"); err == nil {
|
||||||
|
file, err = os.Open("/etc/bpm-compilation.conf")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = yaml.NewDecoder(file).Decode(&CompilationBPMConfig)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
file.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove disabled databases from memory
|
||||||
|
for i := len(MainBPMConfig.Databases) - 1; i >= 0; i-- {
|
||||||
|
if MainBPMConfig.Databases[i].Disabled != nil && *MainBPMConfig.Databases[i].Disabled {
|
||||||
|
MainBPMConfig.Databases = append(MainBPMConfig.Databases[:i], MainBPMConfig.Databases[i+1:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,597 @@
|
|||||||
|
package bpmlib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"maps"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"slices"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type VerificationLevel int
|
||||||
|
|
||||||
|
const (
|
||||||
|
VerificationLevelNone VerificationLevel = iota
|
||||||
|
VerificationLevelAll
|
||||||
|
VerificationLevelTrusted
|
||||||
|
)
|
||||||
|
|
||||||
|
type BPMDatabase struct {
|
||||||
|
DatabaseVersion int `yaml:"database_version"`
|
||||||
|
Entries map[string]*BPMDatabaseEntry `yaml:"entries"`
|
||||||
|
VirtualPackages map[string][]*BPMDatabaseEntry
|
||||||
|
Name string
|
||||||
|
VerificationLevel VerificationLevel
|
||||||
|
Source string
|
||||||
|
}
|
||||||
|
|
||||||
|
type BPMDatabaseEntry struct {
|
||||||
|
Info *PackageInfo `yaml:"info"`
|
||||||
|
Filepath string `yaml:"filepath"`
|
||||||
|
DownloadSize int64 `yaml:"download_size"`
|
||||||
|
InstalledSize int64 `yaml:"installed_size"`
|
||||||
|
Database *BPMDatabase
|
||||||
|
}
|
||||||
|
|
||||||
|
var BPMDatabases = make(map[string]*BPMDatabase)
|
||||||
|
|
||||||
|
func (db *BPMDatabase) ContainsPackage(pkg string) bool {
|
||||||
|
_, ok := db.Entries[pkg]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *configDatabase) ReadLocalDatabase() error {
|
||||||
|
dbFile := "/var/lib/bpm/databases/" + db.Name + ".bpmdb"
|
||||||
|
if _, err := os.Stat(dbFile); err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes, err := os.ReadFile(dbFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unmarshal yaml
|
||||||
|
database := &BPMDatabase{}
|
||||||
|
err = yaml.Unmarshal(bytes, database)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize struct values
|
||||||
|
database.VirtualPackages = make(map[string][]*BPMDatabaseEntry)
|
||||||
|
database.Name = db.Name
|
||||||
|
switch db.VerificationLevel {
|
||||||
|
case "0", "none":
|
||||||
|
database.VerificationLevel = VerificationLevelNone
|
||||||
|
case "1", "all":
|
||||||
|
database.VerificationLevel = VerificationLevelAll
|
||||||
|
case "2", "trusted":
|
||||||
|
database.VerificationLevel = VerificationLevelTrusted
|
||||||
|
default:
|
||||||
|
database.VerificationLevel = VerificationLevelAll
|
||||||
|
}
|
||||||
|
database.Source = db.Source
|
||||||
|
|
||||||
|
for entryName, entry := range database.Entries {
|
||||||
|
entry.Database = database
|
||||||
|
|
||||||
|
if entry.Info.IsSplitPackage() {
|
||||||
|
delete(database.Entries, entryName)
|
||||||
|
|
||||||
|
// Handle split packages
|
||||||
|
for _, splitPkg := range entry.Info.SplitPackages {
|
||||||
|
// Turn split package into json data
|
||||||
|
splitPkgJson, err := yaml.Marshal(splitPkg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone all main package fields onto split package
|
||||||
|
splitPkgClone := *entry.Info
|
||||||
|
|
||||||
|
// Set split package field of split package to nil
|
||||||
|
splitPkgClone.SplitPackages = nil
|
||||||
|
|
||||||
|
// Unmarshal json data back to struct
|
||||||
|
err = yaml.Unmarshal(splitPkgJson, &splitPkgClone)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force set split package version, revision and URL
|
||||||
|
splitPkgClone.Version = entry.Info.Version
|
||||||
|
splitPkgClone.Revision = entry.Info.Revision
|
||||||
|
splitPkgClone.Url = entry.Info.Url
|
||||||
|
|
||||||
|
// Create entry for split package
|
||||||
|
database.Entries[splitPkg.Name] = &BPMDatabaseEntry{
|
||||||
|
Info: &splitPkgClone,
|
||||||
|
Filepath: entry.Filepath,
|
||||||
|
DownloadSize: entry.DownloadSize,
|
||||||
|
InstalledSize: 0,
|
||||||
|
Database: database,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add virtual packages to database
|
||||||
|
for _, p := range splitPkg.Provides {
|
||||||
|
database.VirtualPackages[p] = append(database.VirtualPackages[p], database.Entries[splitPkg.Name])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Add virtual packages to database
|
||||||
|
for _, p := range entry.Info.Provides {
|
||||||
|
database.VirtualPackages[p] = append(database.VirtualPackages[p], entry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BPMDatabases[db.Name] = database
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *configDatabase) SyncLocalDatabaseFile() error {
|
||||||
|
dbFile := "/var/lib/bpm/databases/" + db.Name + ".bpmdb"
|
||||||
|
|
||||||
|
// Get URL to database
|
||||||
|
u, err := url.JoinPath(db.Source, "database.bpmdb")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve data from URL
|
||||||
|
req, err := http.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// Create progress bar
|
||||||
|
bar := createProgressBar(resp.ContentLength, "Syncing "+db.Name, false)
|
||||||
|
|
||||||
|
// Copy data
|
||||||
|
var buffer bytes.Buffer
|
||||||
|
_, err = io.Copy(io.MultiWriter(&buffer, bar), resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unmarshal data to ensure it is a valid BPM database
|
||||||
|
err = yaml.Unmarshal(buffer.Bytes(), &BPMDatabase{})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not decode database: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create parent directories to database file
|
||||||
|
err = os.MkdirAll(path.Dir(dbFile), 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create file and save database data
|
||||||
|
out, err := os.Create(dbFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer out.Close()
|
||||||
|
|
||||||
|
_, err = out.Write(buffer.Bytes())
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadLocalDatabaseFiles() (err error) {
|
||||||
|
for _, db := range MainBPMConfig.Databases {
|
||||||
|
// Read database
|
||||||
|
err = db.ReadLocalDatabase()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDatabaseEntry(str string) (*BPMDatabaseEntry, *BPMDatabase, error) {
|
||||||
|
split := strings.Split(str, "/")
|
||||||
|
if len(split) == 1 {
|
||||||
|
pkgName := strings.TrimSpace(split[0])
|
||||||
|
if pkgName == "" {
|
||||||
|
return nil, nil, errors.New("could not find database entry for this package")
|
||||||
|
}
|
||||||
|
for _, db := range BPMDatabases {
|
||||||
|
if db.ContainsPackage(pkgName) {
|
||||||
|
return db.Entries[pkgName], db, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, nil, errors.New("could not find database entry for this package")
|
||||||
|
} else if len(split) == 2 {
|
||||||
|
dbName := strings.TrimSpace(split[0])
|
||||||
|
pkgName := strings.TrimSpace(split[1])
|
||||||
|
if dbName == "" || pkgName == "" {
|
||||||
|
return nil, nil, errors.New("could not find database entry for this package")
|
||||||
|
}
|
||||||
|
db := BPMDatabases[dbName]
|
||||||
|
if db == nil || !db.ContainsPackage(pkgName) {
|
||||||
|
return nil, nil, errors.New("could not find database entry for this package")
|
||||||
|
}
|
||||||
|
return db.Entries[pkgName], db, nil
|
||||||
|
} else {
|
||||||
|
return nil, nil, errors.New("could not find database entry for this package")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func FindReplacement(pkg string) *BPMDatabaseEntry {
|
||||||
|
for _, db := range BPMDatabases {
|
||||||
|
for _, entry := range db.Entries {
|
||||||
|
for _, replaced := range entry.Info.Replaces {
|
||||||
|
if replaced == pkg {
|
||||||
|
return entry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDatabaseVirtualPackageEntry(vpkg string) (providers []*BPMDatabaseEntry) {
|
||||||
|
for _, db := range BPMDatabases {
|
||||||
|
providers = append(providers, db.VirtualPackages[vpkg]...)
|
||||||
|
}
|
||||||
|
|
||||||
|
slices.SortFunc(providers, func(a, b *BPMDatabaseEntry) int {
|
||||||
|
return strings.Compare(a.Info.Name, b.Info.Name)
|
||||||
|
})
|
||||||
|
|
||||||
|
return providers
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *BPMDatabase) FetchPackage(pkg string) (string, error) {
|
||||||
|
// Check if package exists in database
|
||||||
|
if !db.ContainsPackage(pkg) {
|
||||||
|
return "", errors.New("could not fetch package '" + pkg + "'")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get package url from database
|
||||||
|
entry := db.Entries[pkg]
|
||||||
|
u, err := url.JoinPath(db.Source, entry.Filepath)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download package from url
|
||||||
|
filepath := path.Join("/var/cache/bpm/fetched/", path.Base(entry.Filepath))
|
||||||
|
err = downloadFile("Downloading "+entry.Info.Name, u, filepath, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download and verify signature if required
|
||||||
|
if db.VerificationLevel != VerificationLevelNone {
|
||||||
|
err = downloadFile("", u+".sig", filepath+".sig", 0644)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
err := VerifySignature(filepath, filepath+".sig", db.VerificationLevel == VerificationLevelTrusted, "/")
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("Could not verify signature for %s: %s", filepath, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filepath, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *BPMDatabaseEntry) GetEntryDependants() (dependants []string) {
|
||||||
|
dependantsMap := make(map[string][]string)
|
||||||
|
|
||||||
|
// Loop through all entries
|
||||||
|
for _, db := range BPMDatabases {
|
||||||
|
for _, e := range db.Entries {
|
||||||
|
// Skip iteration if comparing the same packages
|
||||||
|
if e.Info.Name == entry.Info.Name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add installed package to list if its dependencies include pkgName
|
||||||
|
if slices.ContainsFunc(e.Info.Depends, func(n string) bool {
|
||||||
|
n, _, _ = SplitPkgNameAndVersion(n)
|
||||||
|
return n == entry.Info.Name
|
||||||
|
}) {
|
||||||
|
dependantsMap[e.Info.Name] = append(dependantsMap[e.Info.Name], db.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add installed package to list if its runtime dependencies include pkgName
|
||||||
|
if slices.ContainsFunc(e.Info.RuntimeDepends, func(n string) bool {
|
||||||
|
n, _, _ = SplitPkgNameAndVersion(n)
|
||||||
|
return n == entry.Info.Name
|
||||||
|
}) {
|
||||||
|
dependantsMap[e.Info.Name] = append(dependantsMap[e.Info.Name], db.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through each virtual package
|
||||||
|
for _, vpkg := range entry.Info.Provides {
|
||||||
|
// Add installed package to list if its dependencies contain a provided virtual package
|
||||||
|
if slices.ContainsFunc(e.Info.Depends, func(n string) bool {
|
||||||
|
n, _, _ = SplitPkgNameAndVersion(n)
|
||||||
|
return n == vpkg
|
||||||
|
}) {
|
||||||
|
dependantsMap[e.Info.Name] = append(dependantsMap[e.Info.Name], db.Name)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add installed package to list if its runtime dependencies contain a provided virtual package
|
||||||
|
if slices.ContainsFunc(e.Info.RuntimeDepends, func(n string) bool {
|
||||||
|
n, _, _ = SplitPkgNameAndVersion(n)
|
||||||
|
return n == vpkg
|
||||||
|
}) {
|
||||||
|
dependantsMap[e.Info.Name] = append(dependantsMap[e.Info.Name], db.Name)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get keys
|
||||||
|
keySlice := slices.Collect(maps.Keys(dependantsMap))
|
||||||
|
slices.Sort(keySlice)
|
||||||
|
|
||||||
|
// Add all dependant entries to slice in alphabetical order
|
||||||
|
for _, entryName := range keySlice {
|
||||||
|
dbs := dependantsMap[entryName]
|
||||||
|
if len(dbs) > 1 {
|
||||||
|
for _, db := range dbs {
|
||||||
|
dependants = append(dependants, db+"/"+entryName)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dependants = append(dependants, entryName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dependants
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *BPMDatabaseEntry) GetEntryOptionalDependants() (dependants []string) {
|
||||||
|
dependantsMap := make(map[string][]string)
|
||||||
|
for _, db := range BPMDatabases {
|
||||||
|
for _, e := range db.Entries {
|
||||||
|
if slices.ContainsFunc(e.Info.OptionalDepends, func(n string) bool {
|
||||||
|
// Remove optional dependency comment
|
||||||
|
n = strings.SplitN(n, ":", 2)[0]
|
||||||
|
|
||||||
|
// Remove required version
|
||||||
|
n, _, _ = SplitPkgNameAndVersion(n)
|
||||||
|
|
||||||
|
return n == entry.Info.Name
|
||||||
|
}) {
|
||||||
|
dependantsMap[e.Info.Name] = append(dependantsMap[e.Info.Name], e.Database.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get keys
|
||||||
|
keySlice := slices.Collect(maps.Keys(dependantsMap))
|
||||||
|
slices.Sort(keySlice)
|
||||||
|
|
||||||
|
// Add all dependant entries to slice in alphabetical order
|
||||||
|
for _, entryName := range keySlice {
|
||||||
|
dbs := dependantsMap[entryName]
|
||||||
|
if len(dbs) > 1 {
|
||||||
|
for _, db := range dbs {
|
||||||
|
dependants = append(dependants, db+"/"+entryName)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dependants = append(dependants, entryName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dependants
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *BPMDatabaseEntry) GetEntryMakeDependants() (dependants []string) {
|
||||||
|
dependantsMap := make(map[string][]string)
|
||||||
|
for _, db := range BPMDatabases {
|
||||||
|
for _, e := range db.Entries {
|
||||||
|
if slices.ContainsFunc(e.Info.MakeDepends, func(n string) bool {
|
||||||
|
n, _, _ = SplitPkgNameAndVersion(n)
|
||||||
|
return n == entry.Info.Name
|
||||||
|
}) {
|
||||||
|
dependantsMap[e.Info.Name] = append(dependantsMap[e.Info.Name], e.Database.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get keys
|
||||||
|
keySlice := slices.Collect(maps.Keys(dependantsMap))
|
||||||
|
slices.Sort(keySlice)
|
||||||
|
|
||||||
|
// Add all dependant entries to slice in alphabetical order
|
||||||
|
for _, entryName := range keySlice {
|
||||||
|
dbs := dependantsMap[entryName]
|
||||||
|
if len(dbs) > 1 {
|
||||||
|
for _, db := range dbs {
|
||||||
|
dependants = append(dependants, db+"/"+entryName)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dependants = append(dependants, entryName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dependants
|
||||||
|
}
|
||||||
|
|
||||||
|
func (entry *BPMDatabaseEntry) CreateReadableInfo(rootDir string, showBytes bool) string {
|
||||||
|
builder := strings.Builder{}
|
||||||
|
builderWriteStringNotEmpty := func(label string, value string) {
|
||||||
|
if value != "" {
|
||||||
|
builder.WriteString(label + ": " + value + "\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builderWriteArray := func(label string, array []string, sort bool) {
|
||||||
|
if len(array) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort array
|
||||||
|
if sort {
|
||||||
|
slices.Sort(array)
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.WriteString(label + " (" + strconv.Itoa(len(array)) + "):\n")
|
||||||
|
for _, val := range array {
|
||||||
|
builder.WriteString(" - " + val + "\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builderWriteDependencyArray := func(label string, depends []string) {
|
||||||
|
if len(depends) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort array
|
||||||
|
slices.Sort(depends)
|
||||||
|
|
||||||
|
builder.WriteString(label + " (" + strconv.Itoa(len(depends)) + "):\n")
|
||||||
|
for _, val := range depends {
|
||||||
|
builder.WriteString(" - " + val)
|
||||||
|
|
||||||
|
// Show virtual package providers
|
||||||
|
if providers := GetDatabaseVirtualPackageEntry(val); len(providers) > 0 {
|
||||||
|
builder.WriteString(" (")
|
||||||
|
for i, vpkg := range providers {
|
||||||
|
if i == len(providers)-1 {
|
||||||
|
builder.WriteString(vpkg.Info.Name)
|
||||||
|
} else {
|
||||||
|
builder.WriteString(vpkg.Info.Name + ", ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builder.WriteString(")")
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.WriteString("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main information
|
||||||
|
builder.WriteString("Name: " + entry.Info.Name + "\n")
|
||||||
|
builder.WriteString("Database: " + entry.Database.Name + "\n")
|
||||||
|
builder.WriteString("Description: " + entry.Info.Description + "\n")
|
||||||
|
builder.WriteString("Version: " + entry.Info.GetFullVersion() + "\n")
|
||||||
|
builderWriteStringNotEmpty("URL", entry.Info.Url)
|
||||||
|
builderWriteStringNotEmpty("License", entry.Info.License)
|
||||||
|
builderWriteArray("Maintainers", entry.Info.Maintainers, false)
|
||||||
|
builder.WriteString("Architecture: " + entry.Info.Arch + "\n")
|
||||||
|
if entry.Info.Type == "source" && entry.Info.OutputArch != "" && entry.Info.OutputArch != GetArch() {
|
||||||
|
builder.WriteString("Output architecture: " + entry.Info.OutputArch + "\n")
|
||||||
|
}
|
||||||
|
builder.WriteString("Type: " + entry.Info.Type + "\n")
|
||||||
|
|
||||||
|
// Dependencies
|
||||||
|
builderWriteDependencyArray("Dependencies", entry.Info.Depends)
|
||||||
|
if entry.Info.Type == "source" {
|
||||||
|
builderWriteDependencyArray("Make dependencies", entry.Info.MakeDepends)
|
||||||
|
builderWriteDependencyArray("Check dependencies", entry.Info.CheckDepends)
|
||||||
|
}
|
||||||
|
builderWriteDependencyArray("Runtime dependencies", entry.Info.RuntimeDepends)
|
||||||
|
if len(entry.Info.OptionalDepends) > 0 {
|
||||||
|
builder.WriteString("Optional dependencies: (" + strconv.Itoa(len(entry.Info.OptionalDepends)) + ")\n")
|
||||||
|
for _, depend := range entry.Info.OptionalDepends {
|
||||||
|
dependSplit := strings.SplitN(depend, ":", 2)
|
||||||
|
if len(dependSplit) == 2 {
|
||||||
|
builder.WriteString(fmt.Sprintf(" - %s (%s)", dependSplit[0], dependSplit[1]))
|
||||||
|
} else {
|
||||||
|
builder.WriteString(" - " + dependSplit[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show virtual package providers
|
||||||
|
if providers := GetDatabaseVirtualPackageEntry(dependSplit[0]); len(providers) > 0 {
|
||||||
|
builder.WriteString(" (")
|
||||||
|
for i, vpkg := range providers {
|
||||||
|
if i == len(providers)-1 {
|
||||||
|
builder.WriteString(vpkg.Info.Name)
|
||||||
|
} else {
|
||||||
|
builder.WriteString(vpkg.Info.Name + ", ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builder.WriteString(")")
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.WriteString("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builderWriteArray("Dependant packages", entry.GetEntryDependants(), true)
|
||||||
|
builderWriteArray("Optionally dependant packages", entry.GetEntryOptionalDependants(), true)
|
||||||
|
builderWriteArray("Make dependant packages", entry.GetEntryMakeDependants(), true)
|
||||||
|
|
||||||
|
// Other package relations
|
||||||
|
builderWriteArray("Conflicting packages", entry.Info.Conflicts, true)
|
||||||
|
builderWriteArray("Provided packages", entry.Info.Provides, true)
|
||||||
|
builderWriteArray("Replaces packages", entry.Info.Replaces, true)
|
||||||
|
|
||||||
|
// Split packages
|
||||||
|
if entry.Info.Type == "source" && len(entry.Info.SplitPackages) != 0 {
|
||||||
|
splitPkgs := make([]string, len(entry.Info.SplitPackages))
|
||||||
|
for i, splitPkgInfo := range entry.Info.SplitPackages {
|
||||||
|
splitPkgs[i] = splitPkgInfo.Name
|
||||||
|
}
|
||||||
|
builderWriteArray("Split packages", splitPkgs, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Installation reason
|
||||||
|
if rootDir != "" && IsPackageInstalled(entry.Info.Name, rootDir) {
|
||||||
|
installationReason := GetPackage(entry.Info.Name, rootDir).LocalInfo.GetInstallationReason()
|
||||||
|
var installationReasonString string
|
||||||
|
switch installationReason {
|
||||||
|
case InstallationReasonManual:
|
||||||
|
installationReasonString = "Manual"
|
||||||
|
case InstallationReasonDependency:
|
||||||
|
installationReasonString = "Dependency"
|
||||||
|
case InstallationReasonMakeDependency:
|
||||||
|
installationReasonString = "Make dependency"
|
||||||
|
default:
|
||||||
|
installationReasonString = "Unknown"
|
||||||
|
}
|
||||||
|
builder.WriteString("Installation reason: " + installationReasonString + "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download size
|
||||||
|
downloadSize := entry.DownloadSize
|
||||||
|
var downloadSizeStr string
|
||||||
|
if showBytes {
|
||||||
|
downloadSizeStr = strconv.FormatInt(downloadSize, 10)
|
||||||
|
} else {
|
||||||
|
downloadSizeStr = BytesToHumanReadable(downloadSize)
|
||||||
|
}
|
||||||
|
builder.WriteString("Download size: " + downloadSizeStr + "\n")
|
||||||
|
|
||||||
|
// Installed size
|
||||||
|
if entry.Info.Type == "binary" {
|
||||||
|
installedSize := entry.InstalledSize
|
||||||
|
var installedSizeStr string
|
||||||
|
if showBytes {
|
||||||
|
installedSizeStr = strconv.FormatInt(installedSize, 10)
|
||||||
|
} else {
|
||||||
|
installedSizeStr = BytesToHumanReadable(installedSize)
|
||||||
|
}
|
||||||
|
builder.WriteString("Installed size: " + installedSizeStr + "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.TrimSpace(builder.String())
|
||||||
|
}
|
||||||
@@ -0,0 +1,247 @@
|
|||||||
|
package bpmlib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (pkgInfo *PackageInfo) GetPackageDependants(rootDir string, skipMultipleProviders bool) (dependants []string) {
|
||||||
|
// Get installed package names
|
||||||
|
pkgs, ok := localPackageInformation[rootDir]
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through all installed packages
|
||||||
|
for _, installedPkg := range pkgs {
|
||||||
|
// Skip iteration if comparing the same packages
|
||||||
|
if installedPkg.Name == pkgInfo.Name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add installed package to list if its dependencies include pkgName
|
||||||
|
if slices.ContainsFunc(installedPkg.Depends, func(n string) bool {
|
||||||
|
n, _, _ = SplitPkgNameAndVersion(n)
|
||||||
|
return n == pkgInfo.Name
|
||||||
|
}) {
|
||||||
|
dependants = append(dependants, installedPkg.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add installed package to list if its runtime dependencies include pkgName
|
||||||
|
if slices.ContainsFunc(installedPkg.RuntimeDepends, func(n string) bool {
|
||||||
|
n, _, _ = SplitPkgNameAndVersion(n)
|
||||||
|
return n == pkgInfo.Name
|
||||||
|
}) {
|
||||||
|
dependants = append(dependants, installedPkg.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through each virtual package
|
||||||
|
for _, vpkg := range pkgInfo.Provides {
|
||||||
|
if skipMultipleProviders && len(GetVirtualPackageInfo(vpkg, rootDir)) > 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add installed package to list if its dependencies contain a provided virtual package
|
||||||
|
if slices.ContainsFunc(installedPkg.Depends, func(n string) bool {
|
||||||
|
n, _, _ = SplitPkgNameAndVersion(n)
|
||||||
|
return n == vpkg
|
||||||
|
}) {
|
||||||
|
dependants = append(dependants, installedPkg.Name)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add installed package to list if its runtime dependencies contain a provided virtual package
|
||||||
|
if slices.ContainsFunc(installedPkg.RuntimeDepends, func(n string) bool {
|
||||||
|
n, _, _ = SplitPkgNameAndVersion(n)
|
||||||
|
return n == vpkg
|
||||||
|
}) {
|
||||||
|
dependants = append(dependants, installedPkg.Name)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dependants
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pkgInfo *PackageInfo) GetPackageOptionalDependants(rootDir string) (dependants []string) {
|
||||||
|
// Get installed package names
|
||||||
|
pkgs, ok := localPackageInformation[rootDir]
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through all installed packages
|
||||||
|
for _, installedPkg := range pkgs {
|
||||||
|
// Skip iteration if comparing the same packages
|
||||||
|
if installedPkg.Name == pkgInfo.Name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add installed package to list if its optional dependencies include pkgName
|
||||||
|
if slices.ContainsFunc(installedPkg.OptionalDepends, func(n string) bool {
|
||||||
|
// Remove optional dependency comment
|
||||||
|
n = strings.SplitN(n, ":", 2)[0]
|
||||||
|
|
||||||
|
// Remove required version
|
||||||
|
n, _, _ = SplitPkgNameAndVersion(n)
|
||||||
|
|
||||||
|
return n == pkgInfo.Name
|
||||||
|
}) {
|
||||||
|
dependants = append(dependants, installedPkg.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through each virtual package
|
||||||
|
for _, vpkg := range pkgInfo.Provides {
|
||||||
|
// Add installed package to list if its optional dependencies contain a provided virtual package
|
||||||
|
if slices.ContainsFunc(installedPkg.OptionalDepends, func(n string) bool {
|
||||||
|
// Remove optional dependency comment
|
||||||
|
n = strings.SplitN(n, ":", 2)[0]
|
||||||
|
|
||||||
|
// Remove required version
|
||||||
|
n, _, _ = SplitPkgNameAndVersion(n)
|
||||||
|
|
||||||
|
return n == vpkg
|
||||||
|
}) {
|
||||||
|
dependants = append(dependants, installedPkg.Name)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dependants
|
||||||
|
}
|
||||||
|
|
||||||
|
type ResolvedPackage struct {
|
||||||
|
DatabaseEntry *BPMDatabaseEntry
|
||||||
|
InstallationReason InstallationReason
|
||||||
|
}
|
||||||
|
|
||||||
|
func ResolveDependencies(pkgInfo *PackageInfo, resolvedVirtualPackages map[string]string, includeRuntimeDepends bool, rootDir string) (resolved []ResolvedPackage, unresolved []string) {
|
||||||
|
visited := make([]string, 0)
|
||||||
|
|
||||||
|
var dfs func(resolvedPkg *PackageInfo)
|
||||||
|
dfs = func(pkgInfo *PackageInfo) {
|
||||||
|
checkDependencies := func(dependencies []string, installationReason InstallationReason) {
|
||||||
|
for _, depend := range dependencies {
|
||||||
|
// Split dependency name and required version
|
||||||
|
dependName, _, _ := SplitPkgNameAndVersion(depend)
|
||||||
|
|
||||||
|
// Ignore if package is already installed
|
||||||
|
if IsPackageInstalled(dependName, rootDir) && EvaluateDependency(depend, GetPackageInfo(dependName, rootDir).Version) {
|
||||||
|
continue
|
||||||
|
} else if providers := GetVirtualPackageInfo(dependName, rootDir); len(providers) > 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find database entry for dependency
|
||||||
|
var dependEntry *BPMDatabaseEntry
|
||||||
|
if resolvedVpkg, ok := resolvedVirtualPackages[dependName]; ok {
|
||||||
|
dependEntry, _, _ = GetDatabaseEntry(resolvedVpkg)
|
||||||
|
} else if entry, _, _ := GetDatabaseEntry(dependName); entry != nil {
|
||||||
|
dependEntry = entry
|
||||||
|
} else if providers := GetDatabaseVirtualPackageEntry(dependName); len(providers) > 0 {
|
||||||
|
dependEntry = providers[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if dependEntry == nil {
|
||||||
|
unresolved = append(unresolved, depend)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure entry has required version
|
||||||
|
if !EvaluateDependency(depend, dependEntry.Info.Version) {
|
||||||
|
unresolved = append(unresolved, depend)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip ignored packages in config
|
||||||
|
if rootDir == "/" && slices.Contains(MainBPMConfig.IgnorePackages, dependEntry.Info.Name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !slices.Contains(visited, dependEntry.Info.Name) {
|
||||||
|
dfs(dependEntry.Info)
|
||||||
|
resolved = append(resolved, ResolvedPackage{DatabaseEntry: dependEntry, InstallationReason: installationReason})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
visited = append(visited, pkgInfo.Name)
|
||||||
|
|
||||||
|
checkDependencies(pkgInfo.Depends, InstallationReasonDependency)
|
||||||
|
if includeRuntimeDepends {
|
||||||
|
checkDependencies(pkgInfo.RuntimeDepends, InstallationReasonDependency)
|
||||||
|
}
|
||||||
|
if pkgInfo.Type == "source" {
|
||||||
|
checkDependencies(pkgInfo.MakeDepends, InstallationReasonMakeDependency)
|
||||||
|
checkDependencies(pkgInfo.CheckDepends, InstallationReasonMakeDependency)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dfs(pkgInfo)
|
||||||
|
|
||||||
|
return resolved, unresolved
|
||||||
|
}
|
||||||
|
|
||||||
|
func SplitPkgNameAndVersion(pkg string) (string, string, string) {
|
||||||
|
if strings.Contains(pkg, ">=") {
|
||||||
|
pkgSplit := strings.SplitN(pkg, ">=", 2)
|
||||||
|
pkgName := pkgSplit[0]
|
||||||
|
pkgVersion := pkgSplit[1]
|
||||||
|
|
||||||
|
return pkgName, ">=", pkgVersion
|
||||||
|
} else if strings.Contains(pkg, ">") {
|
||||||
|
pkgSplit := strings.SplitN(pkg, ">", 2)
|
||||||
|
pkgName := pkgSplit[0]
|
||||||
|
pkgVersion := pkgSplit[1]
|
||||||
|
|
||||||
|
return pkgName, ">", pkgVersion
|
||||||
|
} else if strings.Contains(pkg, "<=") {
|
||||||
|
pkgSplit := strings.SplitN(pkg, "<=", 2)
|
||||||
|
pkgName := pkgSplit[0]
|
||||||
|
pkgVersion := pkgSplit[1]
|
||||||
|
|
||||||
|
return pkgName, "<=", pkgVersion
|
||||||
|
} else if strings.Contains(pkg, "<") {
|
||||||
|
pkgSplit := strings.SplitN(pkg, "<", 2)
|
||||||
|
pkgName := pkgSplit[0]
|
||||||
|
pkgVersion := pkgSplit[1]
|
||||||
|
|
||||||
|
return pkgName, "<", pkgVersion
|
||||||
|
} else if strings.Contains(pkg, "=") {
|
||||||
|
pkgSplit := strings.SplitN(pkg, "=", 2)
|
||||||
|
pkgName := pkgSplit[0]
|
||||||
|
pkgVersion := pkgSplit[1]
|
||||||
|
|
||||||
|
return pkgName, "=", pkgVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
return pkg, "", ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func EvaluateDependency(pkg, matchVersion string) bool {
|
||||||
|
_, comparisonSymbol, pkgVersion := SplitPkgNameAndVersion(pkg)
|
||||||
|
|
||||||
|
switch comparisonSymbol {
|
||||||
|
case ">=":
|
||||||
|
return CompareVersions(matchVersion, pkgVersion) >= 0
|
||||||
|
case ">":
|
||||||
|
return CompareVersions(matchVersion, pkgVersion) > 0
|
||||||
|
case "<=":
|
||||||
|
return CompareVersions(matchVersion, pkgVersion) <= 0
|
||||||
|
case "<":
|
||||||
|
return CompareVersions(matchVersion, pkgVersion) < 0
|
||||||
|
case "=":
|
||||||
|
if cutPkgVersion, ok := strings.CutSuffix(pkgVersion, "*"); ok {
|
||||||
|
return strings.HasPrefix(matchVersion, cutPkgVersion)
|
||||||
|
} else {
|
||||||
|
return CompareVersions(matchVersion, pkgVersion) == 0
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package bpmlib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PackageNotFoundErr struct {
|
||||||
|
packages []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e PackageNotFoundErr) Error() string {
|
||||||
|
slices.Sort(e.packages)
|
||||||
|
return "The following packages were not found in any databases: " + strings.Join(e.packages, ", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
type DependencyNotFoundErr struct {
|
||||||
|
dependencies []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e DependencyNotFoundErr) Error() string {
|
||||||
|
slices.Sort(e.dependencies)
|
||||||
|
return "The following dependencies were not found in any databases: " + strings.Join(e.dependencies, ", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
type PackageConflictErr struct {
|
||||||
|
pkg string
|
||||||
|
conflicts []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e PackageConflictErr) Error() string {
|
||||||
|
slices.Sort(e.conflicts)
|
||||||
|
return fmt.Sprintf("Package (%s) is in conflict with the following packages: %s", e.pkg, strings.Join(e.conflicts, ", "))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
type PackageScriptErr struct {
|
||||||
|
err error
|
||||||
|
packageName string
|
||||||
|
packageScript string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e PackageScriptErr) Error() string {
|
||||||
|
return fmt.Sprintf("could not execute package script (%s) for package (%s): %s", e.packageScript, e.packageName, e.err)
|
||||||
|
}
|
||||||
|
|
||||||
|
type PackageRemovalDependencyErr struct {
|
||||||
|
RequiredPackages map[string][]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e PackageRemovalDependencyErr) Error() string {
|
||||||
|
return "removing these package would break other installed packages"
|
||||||
|
}
|
||||||
@@ -0,0 +1,560 @@
|
|||||||
|
package bpmlib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"maps"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// InstallPackages installs the specified packages into the given root directory by fetching them from databases or directly from local bpm archives
|
||||||
|
func InstallPackages(rootDir string, forceInstallationReason InstallationReason, reinstallPackages bool, installRuntimeDependencies, forceInstallation, runChecks bool, verbose bool, packages ...string) (operation *BPMOperation, err error) {
|
||||||
|
// Setup operation struct
|
||||||
|
operation = &BPMOperation{
|
||||||
|
Actions: make([]OperationAction, 0),
|
||||||
|
UnresolvedDepends: make([]string, 0),
|
||||||
|
ModifiedFiles: make(map[string]string),
|
||||||
|
RunChecks: runChecks,
|
||||||
|
RootDir: rootDir,
|
||||||
|
compiledPackages: make(map[string]string),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove duplicates from packages
|
||||||
|
packages = removeDuplicates(packages)
|
||||||
|
|
||||||
|
// Resolve packages
|
||||||
|
pkgsNotFound := make([]string, 0)
|
||||||
|
for _, pkg := range packages {
|
||||||
|
if stat, err := os.Stat(pkg); err == nil && !stat.IsDir() {
|
||||||
|
bpmpkg, err := ReadPackage(pkg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not read package: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if bpmpkg.PkgInfo.Type == "source" && bpmpkg.PkgInfo.IsSplitPackage() {
|
||||||
|
for _, splitPkg := range bpmpkg.PkgInfo.SplitPackages {
|
||||||
|
if !reinstallPackages && IsPackageInstalled(splitPkg.Name, rootDir) && GetPackageInfo(splitPkg.Name, rootDir).GetFullVersion() == splitPkg.GetFullVersion() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set package installation reason
|
||||||
|
installationReason := forceInstallationReason
|
||||||
|
if installationReason == InstallationReasonUnknown {
|
||||||
|
if IsPackageInstalled(splitPkg.Name, rootDir) {
|
||||||
|
installationReason = GetPackage(splitPkg.Name, rootDir).LocalInfo.GetInstallationReason()
|
||||||
|
} else {
|
||||||
|
installationReason = InstallationReasonManual
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
operation.Actions = append(operation.Actions, &InstallPackageAction{
|
||||||
|
File: pkg,
|
||||||
|
InstallationReason: installationReason,
|
||||||
|
BpmPackage: bpmpkg,
|
||||||
|
SplitPackageToInstall: splitPkg.Name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reinstallPackages && IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) && GetPackageInfo(bpmpkg.PkgInfo.Name, rootDir).GetFullVersion() == bpmpkg.PkgInfo.GetFullVersion() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set package installation reason
|
||||||
|
installationReason := forceInstallationReason
|
||||||
|
if installationReason == InstallationReasonUnknown {
|
||||||
|
if IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) {
|
||||||
|
installationReason = GetPackage(bpmpkg.PkgInfo.Name, rootDir).LocalInfo.GetInstallationReason()
|
||||||
|
} else {
|
||||||
|
installationReason = InstallationReasonManual
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
operation.Actions = append(operation.Actions, &InstallPackageAction{
|
||||||
|
File: pkg,
|
||||||
|
InstallationReason: installationReason,
|
||||||
|
BpmPackage: bpmpkg,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// Split package name and required version
|
||||||
|
pkgName, _, _ := SplitPkgNameAndVersion(pkg)
|
||||||
|
|
||||||
|
var entry *BPMDatabaseEntry
|
||||||
|
|
||||||
|
if e, _, err := GetDatabaseEntry(pkgName); err == nil {
|
||||||
|
entry = e
|
||||||
|
} else if providers := GetVirtualPackageInfo(pkgName, rootDir); len(providers) > 0 {
|
||||||
|
entry, _, err = GetDatabaseEntry(providers[0].Name)
|
||||||
|
if err != nil {
|
||||||
|
pkgsNotFound = append(pkgsNotFound, pkg)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} else if providers := GetDatabaseVirtualPackageEntry(pkgName); len(providers) > 0 {
|
||||||
|
entry = providers[0]
|
||||||
|
} else {
|
||||||
|
pkgsNotFound = append(pkgsNotFound, pkg)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !EvaluateDependency(pkg, entry.Info.Version) {
|
||||||
|
pkgsNotFound = append(pkgsNotFound, pkg)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reinstallPackages && IsPackageInstalled(entry.Info.Name, rootDir) && GetPackageInfo(entry.Info.Name, rootDir).GetFullVersion() == entry.Info.GetFullVersion() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set package installation reason
|
||||||
|
installationReason := forceInstallationReason
|
||||||
|
if installationReason == InstallationReasonUnknown {
|
||||||
|
if IsPackageInstalled(entry.Info.Name, rootDir) {
|
||||||
|
installationReason = GetPackage(entry.Info.Name, rootDir).LocalInfo.GetInstallationReason()
|
||||||
|
} else {
|
||||||
|
installationReason = InstallationReasonManual
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
operation.Actions = append(operation.Actions, &FetchPackageAction{
|
||||||
|
InstallationReason: installationReason,
|
||||||
|
DatabaseEntry: entry,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return error if not all packages are found
|
||||||
|
if len(pkgsNotFound) != 0 {
|
||||||
|
return nil, PackageNotFoundErr{pkgsNotFound}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve dependencies
|
||||||
|
operation.ResolveDependencies(installRuntimeDependencies)
|
||||||
|
if len(operation.UnresolvedDepends) != 0 {
|
||||||
|
if !forceInstallation {
|
||||||
|
return nil, DependencyNotFoundErr{operation.UnresolvedDepends}
|
||||||
|
} else if verbose {
|
||||||
|
log.Printf("Warning: %s", DependencyNotFoundErr{operation.UnresolvedDepends})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace obsolete packages
|
||||||
|
operation.ReplaceObsoletePackages()
|
||||||
|
|
||||||
|
// Check for conflicts
|
||||||
|
conflicts := operation.CheckForConflicts()
|
||||||
|
if len(conflicts) > 0 {
|
||||||
|
err = fmt.Errorf("conflicts detected")
|
||||||
|
for pkg, conflict := range conflicts {
|
||||||
|
err = errors.Join(err, PackageConflictErr{pkg, conflict})
|
||||||
|
}
|
||||||
|
if !forceInstallation {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
log.Printf("Warning: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check whether compiling source packages on different root directory
|
||||||
|
if rootDir != "/" {
|
||||||
|
sourcePackages := make([]string, 0)
|
||||||
|
for _, action := range operation.Actions {
|
||||||
|
switch action := action.(type) {
|
||||||
|
case *InstallPackageAction:
|
||||||
|
if action.BpmPackage.PkgInfo.Type == "source" {
|
||||||
|
sourcePackages = append(sourcePackages, action.BpmPackage.PkgInfo.Name)
|
||||||
|
}
|
||||||
|
case *FetchPackageAction:
|
||||||
|
if action.DatabaseEntry.Info.Type == "source" {
|
||||||
|
sourcePackages = append(sourcePackages, action.DatabaseEntry.Info.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return error if source packages are present in the operation
|
||||||
|
if len(sourcePackages) != 0 {
|
||||||
|
return nil, fmt.Errorf("cannot compile source packages in different root directory: %s", strings.Join(sourcePackages, ", "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return operation, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemovePackages removes the specified packages from the given root directory
|
||||||
|
func RemovePackages(rootDir string, force, cleanupDependencies bool, packages ...string) (operation *BPMOperation, err error) {
|
||||||
|
operation = &BPMOperation{
|
||||||
|
Actions: make([]OperationAction, 0),
|
||||||
|
UnresolvedDepends: make([]string, 0),
|
||||||
|
ModifiedFiles: make(map[string]string),
|
||||||
|
RootDir: rootDir,
|
||||||
|
compiledPackages: make(map[string]string),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove duplicates from packages
|
||||||
|
packages = removeDuplicates(packages)
|
||||||
|
|
||||||
|
// Search for packages
|
||||||
|
for _, pkg := range packages {
|
||||||
|
bpmpkg := GetPackage(pkg, rootDir)
|
||||||
|
if providers := GetVirtualPackageInfo(pkg, rootDir); len(providers) > 0 {
|
||||||
|
bpmpkg = GetPackage(providers[0].Name, rootDir)
|
||||||
|
}
|
||||||
|
if bpmpkg == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
operation.Actions = append(operation.Actions, &RemovePackageAction{BpmPackage: bpmpkg})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do package cleanup
|
||||||
|
if cleanupDependencies {
|
||||||
|
err := operation.Cleanup(MainBPMConfig.CleanupMakeDependencies)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not perform cleanup for operation: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return error if other packages depend on removed ones
|
||||||
|
if !force {
|
||||||
|
// Get packages and their dependants
|
||||||
|
packageDepndants := make(map[string][]string, 0)
|
||||||
|
for _, action := range operation.Actions {
|
||||||
|
// Skip package if ignored in config
|
||||||
|
if rootDir == "/" && slices.Contains(MainBPMConfig.IgnorePackages, action.(*RemovePackageAction).BpmPackage.PkgInfo.Name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
dependants := action.(*RemovePackageAction).BpmPackage.PkgInfo.GetPackageDependants(rootDir, true)
|
||||||
|
packageDepndants[action.(*RemovePackageAction).BpmPackage.PkgInfo.Name] = dependants
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove dependant packages from map if they are to be removed by this operation
|
||||||
|
for pkg, required := range packageDepndants {
|
||||||
|
required = slices.DeleteFunc(required, func(pkgName string) bool {
|
||||||
|
_, ok := packageDepndants[pkgName]
|
||||||
|
return ok
|
||||||
|
})
|
||||||
|
packageDepndants[pkg] = required
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove dependant packages if ignored
|
||||||
|
for pkg, required := range packageDepndants {
|
||||||
|
required = slices.DeleteFunc(required, func(pkgName string) bool {
|
||||||
|
return rootDir == "/" && slices.Contains(MainBPMConfig.IgnorePackages, pkgName)
|
||||||
|
})
|
||||||
|
packageDepndants[pkg] = required
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove empty keys from map
|
||||||
|
maps.DeleteFunc(packageDepndants, func(pkg string, required []string) bool {
|
||||||
|
return len(required) == 0
|
||||||
|
})
|
||||||
|
|
||||||
|
// Return error
|
||||||
|
if len(packageDepndants) != 0 {
|
||||||
|
return nil, PackageRemovalDependencyErr{RequiredPackages: packageDepndants}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return operation, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CleanupPackages finds packages installed as dependencies which are no longer required by the rest of the system in the given root directory
|
||||||
|
func CleanupPackages(cleanupMakeDepends bool, rootDir string) (operation *BPMOperation, err error) {
|
||||||
|
operation = &BPMOperation{
|
||||||
|
Actions: make([]OperationAction, 0),
|
||||||
|
UnresolvedDepends: make([]string, 0),
|
||||||
|
ModifiedFiles: make(map[string]string),
|
||||||
|
RootDir: rootDir,
|
||||||
|
compiledPackages: make(map[string]string),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do package cleanup
|
||||||
|
err = operation.Cleanup(cleanupMakeDepends)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not perform cleanup for operation: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return operation, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CleanupCache(rootDir string, cleanupCompilationFiles, cleanupCompiledPackages, cleanupFetchedPackages, verbose bool) error {
|
||||||
|
if cleanupCompilationFiles {
|
||||||
|
globalCompilationCacheDir := path.Join(rootDir, "var/cache/bpm/compilation")
|
||||||
|
|
||||||
|
// Ensure path exists and is a directory
|
||||||
|
if stat, err := os.Stat(globalCompilationCacheDir); err == nil && stat.IsDir() {
|
||||||
|
// Delete directory
|
||||||
|
if verbose {
|
||||||
|
log.Printf("Removing directory (%s)\n", globalCompilationCacheDir)
|
||||||
|
}
|
||||||
|
err = os.RemoveAll(globalCompilationCacheDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get home directories of users in root directory
|
||||||
|
homeDirs, err := os.ReadDir(path.Join(rootDir, "home"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through all home directories
|
||||||
|
for _, homeDir := range homeDirs {
|
||||||
|
// Skip if not a directory
|
||||||
|
if !homeDir.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
localCompilationDir := path.Join(rootDir, "home", homeDir.Name(), ".cache/bpm/compilation")
|
||||||
|
|
||||||
|
// Ensure path exists and is a directory
|
||||||
|
if stat, err := os.Stat(localCompilationDir); err != nil || !stat.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete directory
|
||||||
|
if verbose {
|
||||||
|
log.Printf("Removing directory (%s)\n", localCompilationDir)
|
||||||
|
}
|
||||||
|
err = os.RemoveAll(localCompilationDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if cleanupCompiledPackages {
|
||||||
|
dirToRemove := path.Join(rootDir, "var/cache/bpm/compiled")
|
||||||
|
|
||||||
|
// Ensure path exists and is a directory
|
||||||
|
if stat, err := os.Stat(dirToRemove); err == nil && stat.IsDir() {
|
||||||
|
// Delete directory
|
||||||
|
if verbose {
|
||||||
|
log.Printf("Removing directory (%s)\n", dirToRemove)
|
||||||
|
}
|
||||||
|
err = os.RemoveAll(dirToRemove)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if cleanupFetchedPackages {
|
||||||
|
dirToRemove := path.Join(rootDir, "var/cache/bpm/fetched")
|
||||||
|
|
||||||
|
// Ensure path exists and is a directory
|
||||||
|
if stat, err := os.Stat(dirToRemove); err == nil && stat.IsDir() {
|
||||||
|
// Delete directory
|
||||||
|
if verbose {
|
||||||
|
log.Printf("Removing directory (%s)\n", dirToRemove)
|
||||||
|
}
|
||||||
|
err = os.RemoveAll(dirToRemove)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatePackages fetches the newest versions of all installed packages from
|
||||||
|
func UpdatePackages(rootDir string, syncDatabase, allowDowngrades, forceInstallation, runChecks, verbose bool) (operation *BPMOperation, err error) {
|
||||||
|
// Sync databases
|
||||||
|
if syncDatabase {
|
||||||
|
err := SyncDatabase(verbose)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not sync local database: %s", err)
|
||||||
|
}
|
||||||
|
if verbose {
|
||||||
|
fmt.Println("All package databases synced successfully!")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reload config and local databases
|
||||||
|
err = ReadConfig()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not read BPM config: %s", err)
|
||||||
|
}
|
||||||
|
err = ReadLocalDatabaseFiles()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not read local databases: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get installed packages and check for updates
|
||||||
|
pkgs, err := GetInstalledPackages(rootDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not get installed packages: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
operation = &BPMOperation{
|
||||||
|
Actions: make([]OperationAction, 0),
|
||||||
|
UnresolvedDepends: make([]string, 0),
|
||||||
|
ModifiedFiles: make(map[string]string),
|
||||||
|
RunChecks: runChecks,
|
||||||
|
RootDir: rootDir,
|
||||||
|
compiledPackages: make(map[string]string),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search for packages
|
||||||
|
pkgsNotFound := make([]string, 0)
|
||||||
|
for _, pkg := range pkgs {
|
||||||
|
if rootDir == "/" && slices.Contains(MainBPMConfig.IgnorePackages, pkg) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var entry *BPMDatabaseEntry
|
||||||
|
// Check if installed package can be replaced and install that instead
|
||||||
|
if e := FindReplacement(pkg); e != nil {
|
||||||
|
entry = e
|
||||||
|
} else if entry, _, err = GetDatabaseEntry(pkg); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
installedInfo := GetPackageInfo(pkg, rootDir)
|
||||||
|
if installedInfo == nil {
|
||||||
|
return nil, fmt.Errorf("could not get package info for package (%s)", pkg)
|
||||||
|
} else {
|
||||||
|
comparison := CompareVersions(entry.Info.GetFullVersion(), installedInfo.GetFullVersion())
|
||||||
|
if (!allowDowngrades && comparison > 0) || (allowDowngrades && comparison != 0) {
|
||||||
|
operation.Actions = append(operation.Actions, &FetchPackageAction{
|
||||||
|
InstallationReason: GetPackage(pkg, rootDir).LocalInfo.GetInstallationReason(),
|
||||||
|
DatabaseEntry: entry,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for missing dependencies
|
||||||
|
for _, depend := range entry.Info.Depends {
|
||||||
|
// Split package name and required version
|
||||||
|
dependName, _, _ := SplitPkgNameAndVersion(depend)
|
||||||
|
|
||||||
|
if IsPackageInstalled(dependName, rootDir) && EvaluateDependency(depend, GetPackageInfo(dependName, rootDir).Version) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(GetVirtualPackageInfo(dependName, rootDir)) > 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find database entry for missing dependency
|
||||||
|
dependEntry, _, err := GetDatabaseEntry(dependName)
|
||||||
|
if err != nil {
|
||||||
|
providers := GetDatabaseVirtualPackageEntry(dependName)
|
||||||
|
if len(providers) == 0 {
|
||||||
|
pkgsNotFound = append(pkgsNotFound, depend)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
dependEntry = providers[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip dependency if action already exists
|
||||||
|
if ActionSliceIndex(operation.Actions, dependEntry.Info.Name) != -1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip dependency if ignored in config
|
||||||
|
if rootDir == "/" && slices.Contains(MainBPMConfig.IgnorePackages, dependEntry.Info.Name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure entry has required version
|
||||||
|
if !EvaluateDependency(depend, dependEntry.Info.Version) {
|
||||||
|
pkgsNotFound = append(pkgsNotFound, depend)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch dependency
|
||||||
|
operation.Actions = append(operation.Actions, &FetchPackageAction{
|
||||||
|
InstallationReason: InstallationReasonDependency,
|
||||||
|
DatabaseEntry: dependEntry,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for missing runtime dependencies
|
||||||
|
for _, depend := range entry.Info.RuntimeDepends {
|
||||||
|
// Split package name and required version
|
||||||
|
dependName, _, _ := SplitPkgNameAndVersion(depend)
|
||||||
|
|
||||||
|
if IsPackageInstalled(dependName, rootDir) && EvaluateDependency(depend, GetPackageInfo(dependName, rootDir).Version) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(GetVirtualPackageInfo(dependName, rootDir)) > 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find database entry for missing dependency
|
||||||
|
dependEntry, _, err := GetDatabaseEntry(dependName)
|
||||||
|
if err != nil {
|
||||||
|
providers := GetDatabaseVirtualPackageEntry(dependName)
|
||||||
|
if len(providers) == 0 {
|
||||||
|
pkgsNotFound = append(pkgsNotFound, depend)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
dependEntry = providers[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip dependency if ignored in config
|
||||||
|
if rootDir == "/" && slices.Contains(MainBPMConfig.IgnorePackages, dependEntry.Info.Name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure entry has required version
|
||||||
|
if !EvaluateDependency(depend, dependEntry.Info.Version) {
|
||||||
|
pkgsNotFound = append(pkgsNotFound, depend)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch dependency
|
||||||
|
operation.Actions = append(operation.Actions, &FetchPackageAction{
|
||||||
|
InstallationReason: InstallationReasonDependency,
|
||||||
|
DatabaseEntry: dependEntry,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return error if not all packages are found
|
||||||
|
if len(pkgsNotFound) != 0 {
|
||||||
|
return nil, PackageNotFoundErr{pkgsNotFound}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace obsolete packages
|
||||||
|
operation.ReplaceObsoletePackages()
|
||||||
|
|
||||||
|
// Check for conflicts
|
||||||
|
conflicts := operation.CheckForConflicts()
|
||||||
|
if len(conflicts) > 0 {
|
||||||
|
err = fmt.Errorf("conflicts detected")
|
||||||
|
for pkg, conflict := range conflicts {
|
||||||
|
err = errors.Join(err, PackageConflictErr{pkg, conflict})
|
||||||
|
}
|
||||||
|
if !forceInstallation {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
log.Printf("Warning: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return operation, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SyncDatabase syncs all databases declared in /etc/bpm.conf
|
||||||
|
func SyncDatabase(verbose bool) (err error) {
|
||||||
|
for _, db := range MainBPMConfig.Databases {
|
||||||
|
if verbose {
|
||||||
|
fmt.Printf("Fetching package database file for database (%s)...\n", db.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := db.SyncLocalDatabaseFile()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
module github.com/EnumeratedDev/bpm/src/bpmlib
|
||||||
|
|
||||||
|
go 1.24.0
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/drone/envsubst v1.0.3
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f
|
||||||
|
github.com/schollz/progressbar/v3 v3.18.0
|
||||||
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||||
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
|
golang.org/x/sys v0.37.0 // indirect
|
||||||
|
golang.org/x/term v0.36.0 // indirect
|
||||||
|
)
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM=
|
||||||
|
github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/drone/envsubst v1.0.3 h1:PCIBwNDYjs50AsLZPYdfhSATKaRg/FJmDc2D6+C2x8g=
|
||||||
|
github.com/drone/envsubst v1.0.3/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g=
|
||||||
|
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
||||||
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f h1:xt29M2T6STgldg+WEP51gGePQCsQvklmP2eIhPIBK3g=
|
||||||
|
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f/go.mod h1:i4sF0l1fFnY1aiw08QQSwVAFxHEm311Me3WsU/X7nL0=
|
||||||
|
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||||
|
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
|
github.com/schollz/progressbar/v3 v3.18.0 h1:uXdoHABRFmNIjUfte/Ex7WtuyVslrw2wVPQmCN62HpA=
|
||||||
|
github.com/schollz/progressbar/v3 v3.18.0/go.mod h1:IsO3lpbaGuzh8zIMzgY3+J8l4C8GjO0Y9S69eFvNsec=
|
||||||
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
|
||||||
|
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
|
golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
|
||||||
|
golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
package bpmlib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InitializeKeyring(rootDir string) error {
|
||||||
|
gpgHomedir := path.Join(rootDir, "/var/lib/bpm/gpg")
|
||||||
|
|
||||||
|
// Create GPG directory
|
||||||
|
err := os.Mkdir(gpgHomedir, 0700)
|
||||||
|
if err != nil && !os.IsExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get number of secret keys
|
||||||
|
cmd := exec.Command("gpg", "--homedir="+gpgHomedir, "--list-secret-keys", "--with-colons")
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
secretKeysLineCount := len(strings.Split(strings.TrimSpace(string(output)), "\n"))
|
||||||
|
|
||||||
|
// Create signing key
|
||||||
|
if secretKeysLineCount <= 1 {
|
||||||
|
cmd := exec.Command("gpg", "--homedir="+gpgHomedir, "--batch", "--gen-key")
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Stdin = strings.NewReader(`%echo Creating signing key...
|
||||||
|
Key-Type: RSA
|
||||||
|
Key-Length: 4096
|
||||||
|
Key-Usage: sign
|
||||||
|
Name-Real: BPM signing key
|
||||||
|
Name-Email: bpm@localhost
|
||||||
|
Expire-Date: 0
|
||||||
|
%no-protection
|
||||||
|
%commit
|
||||||
|
%echo Done`)
|
||||||
|
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsKeyringInitialized(rootDir string) bool {
|
||||||
|
gpgHomedir := path.Join(rootDir, "/var/lib/bpm/gpg")
|
||||||
|
|
||||||
|
// Check if gpg directory exists
|
||||||
|
if stat, err := os.Stat(gpgHomedir); err != nil || !stat.IsDir() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get number of secret keys
|
||||||
|
cmd := exec.Command("gpg", "--homedir="+gpgHomedir, "--list-secret-keys", "--with-colons")
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
secretKeysLineCount := len(strings.Split(strings.TrimSpace(string(output)), "\n"))
|
||||||
|
|
||||||
|
// Return false if no signing key has been created
|
||||||
|
if secretKeysLineCount <= 1 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func PopulateKeyring(rootDir string) error {
|
||||||
|
gpgHomedir := path.Join(rootDir, "/var/lib/bpm/gpg")
|
||||||
|
keyringsDir := path.Join(rootDir, "/var/lib/bpm/keyrings")
|
||||||
|
|
||||||
|
dirEntries, err := os.ReadDir(keyringsDir)
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove removed keys
|
||||||
|
for _, entry := range dirEntries {
|
||||||
|
if entry.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !strings.HasSuffix(entry.Name(), ".revoked") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := os.ReadFile(path.Join(keyringsDir, entry.Name()))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop over all key IDs
|
||||||
|
for entry := range strings.SplitSeq(strings.TrimSpace(string(data)), "\n") {
|
||||||
|
// Ensure key ID exists
|
||||||
|
err := exec.Command("gpg", "--homedir="+gpgHomedir, "--list-keys", entry).Run()
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command("gpg", "--homedir="+gpgHomedir, "--batch", "--yes", "--delete-secret-and-public-keys", entry)
|
||||||
|
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Import all keyrings
|
||||||
|
for _, entry := range dirEntries {
|
||||||
|
if entry.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !strings.HasSuffix(entry.Name(), ".pgp") && !strings.HasSuffix(entry.Name(), ".asc") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command("gpg", "--homedir="+gpgHomedir, "--import", path.Join(keyringsDir, entry.Name()))
|
||||||
|
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trust keys
|
||||||
|
for _, entry := range dirEntries {
|
||||||
|
if entry.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !strings.HasSuffix(entry.Name(), ".trustdb") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := os.ReadFile(path.Join(keyringsDir, entry.Name()))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop over all key IDs
|
||||||
|
for entry := range strings.SplitSeq(strings.TrimSpace(string(data)), "\n") {
|
||||||
|
keyID := strings.Split(entry, ":")[0]
|
||||||
|
|
||||||
|
// Ensure key ID exists
|
||||||
|
err := exec.Command("gpg", "--homedir="+gpgHomedir, "--list-keys", keyID).Run()
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sign key
|
||||||
|
cmd := exec.Command("gpg", "--homedir="+gpgHomedir, "--command-fd=0", "--batch", "--lsign-key", keyID)
|
||||||
|
cmd.Stdin = strings.NewReader("y\ny\n")
|
||||||
|
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Import owner trust database
|
||||||
|
cmd := exec.Command("gpg", "--homedir="+gpgHomedir, "--import-ownertrust", path.Join(keyringsDir, entry.Name()))
|
||||||
|
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func VerifySignature(filename, signature string, requireTrusted bool, rootDir string) error {
|
||||||
|
gpgHomedir := path.Join(rootDir, "/var/lib/bpm/gpg")
|
||||||
|
|
||||||
|
if _, err := os.Stat(gpgHomedir); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command("gpg", "--homedir="+gpgHomedir, "--status-fd=3", "--verify", signature, filename)
|
||||||
|
pipeReader, pipeWriter, err := os.Pipe()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer pipeReader.Close()
|
||||||
|
defer pipeWriter.Close()
|
||||||
|
cmd.ExtraFiles = append(cmd.ExtraFiles, pipeWriter)
|
||||||
|
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pipeWriter.Close()
|
||||||
|
|
||||||
|
if requireTrusted {
|
||||||
|
data, err := io.ReadAll(pipeReader)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
dataStr := string(data)
|
||||||
|
if !strings.Contains(dataStr, "[GNUPG:] TRUST_FULLY") && !strings.Contains(dataStr, "[GNUPG:] TRUST_ULTIMATE") {
|
||||||
|
return fmt.Errorf("signature verified but not trusted")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
package bpmlib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BPMHook struct {
|
||||||
|
SourcePath string
|
||||||
|
SourceContent string
|
||||||
|
TriggerActions []string `yaml:"trigger_actions"`
|
||||||
|
TriggerPreOperation bool `yaml:"trigger_pre_operation"`
|
||||||
|
Targets []string `yaml:"targets"`
|
||||||
|
Run string `yaml:"run"`
|
||||||
|
PassTargets bool `yaml:"pass_targets"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// createHook returns a BPMHook instance based on the content of the given string
|
||||||
|
func createHook(sourcePath string) (*BPMHook, error) {
|
||||||
|
// Read hook from source path
|
||||||
|
bytes, err := os.ReadFile(sourcePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create base hook structure
|
||||||
|
hook := &BPMHook{
|
||||||
|
SourcePath: sourcePath,
|
||||||
|
SourceContent: string(bytes),
|
||||||
|
TriggerActions: nil,
|
||||||
|
Targets: nil,
|
||||||
|
Run: "",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unmarshal yaml string
|
||||||
|
err = yaml.Unmarshal(bytes, hook)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure hook is valid
|
||||||
|
if err := hook.IsValid(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return hook, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValid ensures hook is valid
|
||||||
|
func (hook *BPMHook) IsValid() error {
|
||||||
|
ValidOperations := []string{"install", "upgrade", "remove"}
|
||||||
|
|
||||||
|
// Return error if any trigger operation is not valid or none are given
|
||||||
|
if len(hook.TriggerActions) == 0 {
|
||||||
|
return errors.New("no trigger operations specified")
|
||||||
|
}
|
||||||
|
for _, operation := range hook.TriggerActions {
|
||||||
|
if !slices.Contains(ValidOperations, operation) {
|
||||||
|
return errors.New("trigger operation '" + operation + "' is not valid")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(hook.Run) == 0 {
|
||||||
|
return errors.New("command to run is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return nil as hook is valid
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute hook if all conditions are met
|
||||||
|
func (hook *BPMHook) Execute(modifiedFiles map[string]string, preOperation bool, verbose bool, rootDir string) error {
|
||||||
|
// Check if any targets are met
|
||||||
|
targetsMet := make([]string, 0)
|
||||||
|
for _, target := range hook.Targets {
|
||||||
|
for modifiedFile, action := range modifiedFiles {
|
||||||
|
// Check if this hook is triggered by this file's action
|
||||||
|
if !slices.Contains(hook.TriggerActions, action) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if file has already been checked
|
||||||
|
if slices.Contains(targetsMet, modifiedFile) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if matched, _ := filepath.Match(target, modifiedFile); !matched {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
targetsMet = append(targetsMet, modifiedFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(targetsMet) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute the command
|
||||||
|
splitCommand := strings.Split(hook.Run, " ")
|
||||||
|
cmd := exec.Command(splitCommand[0], splitCommand[1:]...)
|
||||||
|
// Setup subprocess environment
|
||||||
|
cmd.Dir = "/"
|
||||||
|
// Pass targets
|
||||||
|
if hook.PassTargets {
|
||||||
|
buffer := bytes.Buffer{}
|
||||||
|
buffer.WriteString(strings.Join(targetsMet, "\n") + "\n")
|
||||||
|
|
||||||
|
cmd.Stdin = &buffer
|
||||||
|
}
|
||||||
|
// Run hook in chroot if using the -R flag
|
||||||
|
if rootDir != "/" {
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{Chroot: rootDir}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !verbose {
|
||||||
|
fmt.Printf("Running hook (%s)\n", filepath.Base(hook.SourcePath))
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Running hook (%s) with run command: %s\n", filepath.Base(hook.SourcePath), strings.Join(splitCommand, " "))
|
||||||
|
}
|
||||||
|
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,400 @@
|
|||||||
|
package bpmlib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
var persistentDataVersion int = 1
|
||||||
|
|
||||||
|
var localPackageInformation map[string]map[string]*PackageInfo = make(map[string]map[string]*PackageInfo)
|
||||||
|
var installedVirtualPackages map[string]map[string][]*PackageInfo = make(map[string]map[string][]*PackageInfo)
|
||||||
|
|
||||||
|
func InitializeLocalPackageInformation(rootDir string) (err error) {
|
||||||
|
// Return if information is already initialized
|
||||||
|
if _, ok := localPackageInformation[rootDir]; ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
tempPackageInformation := make(map[string]*PackageInfo)
|
||||||
|
tempInstalledVirtualPackages := make(map[string][]*PackageInfo)
|
||||||
|
|
||||||
|
// Get paths
|
||||||
|
persistentDataDir := path.Join(rootDir, "var/lib/bpm")
|
||||||
|
installedDir := path.Join(persistentDataDir, "installed")
|
||||||
|
|
||||||
|
// Ensure persistent data directory is up-to-date
|
||||||
|
if _, err := os.Stat(persistentDataDir); err == nil {
|
||||||
|
data, err := os.ReadFile(path.Join(persistentDataDir, ".version"))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("persistent data is not up-to-date! Please run 'bpm upgrade-persistent-data' first")
|
||||||
|
}
|
||||||
|
currentPersistentDataVersion, err := strconv.Atoi(strings.TrimSpace(string(data)))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("persistent data is not up-to-date! Please run 'bpm upgrade-persistent-data' first")
|
||||||
|
}
|
||||||
|
if currentPersistentDataVersion != persistentDataVersion {
|
||||||
|
return fmt.Errorf("persistent data is not up-to-date! Please run 'bpm upgrade-persistent-data' first")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get directory content
|
||||||
|
items, err := os.ReadDir(installedDir)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
localPackageInformation[rootDir] = make(map[string]*PackageInfo)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through each subdirectory
|
||||||
|
for _, item := range items {
|
||||||
|
// Skip if not a directory
|
||||||
|
if !item.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read package info
|
||||||
|
infoData, err := os.ReadFile(path.Join(installedDir, item.Name(), "info"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
info, err := ReadPackageInfo(string(infoData))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add package to slice
|
||||||
|
tempPackageInformation[info.Name] = info
|
||||||
|
|
||||||
|
// Add virtual packages
|
||||||
|
for _, vpkg := range info.Provides {
|
||||||
|
tempInstalledVirtualPackages[vpkg] = append(tempInstalledVirtualPackages[vpkg], info)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
localPackageInformation[rootDir] = tempPackageInformation
|
||||||
|
installedVirtualPackages[rootDir] = tempInstalledVirtualPackages
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetInstalledPackages(rootDir string) (ret []string, err error) {
|
||||||
|
// Initialize local package information
|
||||||
|
err = InitializeLocalPackageInformation(rootDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through each package and add it to slice
|
||||||
|
for _, pkgInfo := range localPackageInformation[rootDir] {
|
||||||
|
ret = append(ret, pkgInfo.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort packages
|
||||||
|
slices.Sort(ret)
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPathOwners(path, rootDir string) (ret []string, err error) {
|
||||||
|
// Get absolte path to path
|
||||||
|
path, err = filepath.Abs(path)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
path, err = filepath.Rel(rootDir, path)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trim leading and trailing slashes
|
||||||
|
path = strings.TrimLeft(path, "/")
|
||||||
|
path = strings.TrimRight(path, "/")
|
||||||
|
|
||||||
|
// Get installed packages
|
||||||
|
pkgs, err := GetInstalledPackages(rootDir)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add packages that own path to list
|
||||||
|
for _, pkg := range pkgs {
|
||||||
|
pkgFiles := getPackageFiles(pkg, rootDir)
|
||||||
|
if slices.ContainsFunc(pkgFiles, func(entry *PackageFileEntry) bool {
|
||||||
|
return entry.Path == path
|
||||||
|
}) {
|
||||||
|
ret = append(ret, pkg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsPackageInstalled(pkg, rootDir string) bool {
|
||||||
|
// Initialize local package information
|
||||||
|
err := InitializeLocalPackageInformation(rootDir)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := localPackageInformation[rootDir][pkg]; !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetVirtualPackageInfo(vpkg, rootDir string) []*PackageInfo {
|
||||||
|
err := InitializeLocalPackageInformation(rootDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
providers := installedVirtualPackages[rootDir][vpkg]
|
||||||
|
slices.SortFunc(providers, func(a, b *PackageInfo) int {
|
||||||
|
return strings.Compare(a.Name, b.Name)
|
||||||
|
})
|
||||||
|
|
||||||
|
return providers
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPackageInfo(pkg string, rootDir string) *PackageInfo {
|
||||||
|
err := InitializeLocalPackageInformation(rootDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return localPackageInformation[rootDir][pkg]
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPackage(pkg, rootDir string) *BPMPackage {
|
||||||
|
pkgInfo := GetPackageInfo(pkg, rootDir)
|
||||||
|
if pkgInfo == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
files := getPackageFiles(pkgInfo.Name, rootDir)
|
||||||
|
localInfo := getPackageLocalInfo(pkgInfo.Name, rootDir)
|
||||||
|
|
||||||
|
return &BPMPackage{
|
||||||
|
PkgInfo: pkgInfo,
|
||||||
|
PkgFiles: files,
|
||||||
|
LocalInfo: localInfo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAllPackageFiles(rootDir string, excludePackages ...string) (map[string][]*BPMPackage, error) {
|
||||||
|
ret := make(map[string][]*BPMPackage)
|
||||||
|
|
||||||
|
pkgNames, err := GetInstalledPackages(rootDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, pkgName := range pkgNames {
|
||||||
|
if slices.Contains(excludePackages, pkgName) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
bpmpkg := GetPackage(pkgName, rootDir)
|
||||||
|
if bpmpkg == nil {
|
||||||
|
return nil, fmt.Errorf("could not get BPM package (%s)", pkgName)
|
||||||
|
}
|
||||||
|
for _, entry := range bpmpkg.PkgFiles {
|
||||||
|
ret[entry.Path] = append(ret[entry.Path], bpmpkg)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getPackageFiles(pkg, rootDir string) []*PackageFileEntry {
|
||||||
|
var pkgFiles []*PackageFileEntry
|
||||||
|
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
||||||
|
pkgDir := path.Join(installedDir, pkg)
|
||||||
|
files := path.Join(pkgDir, "files")
|
||||||
|
if _, err := os.Stat(installedDir); os.IsNotExist(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(pkgDir); os.IsNotExist(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
bs, err := os.ReadFile(files)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, line := range strings.Split(string(bs), "\n") {
|
||||||
|
if strings.TrimSpace(line) == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
stringEntry := strings.Split(strings.TrimSpace(line), " ")
|
||||||
|
if len(stringEntry) < 5 {
|
||||||
|
pkgFiles = append(pkgFiles, &PackageFileEntry{
|
||||||
|
Path: strings.TrimSuffix(line, "/"),
|
||||||
|
OctalPerms: 0,
|
||||||
|
UserID: 0,
|
||||||
|
GroupID: 0,
|
||||||
|
SizeInBytes: 0,
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
uid, err := strconv.ParseInt(stringEntry[len(stringEntry)-4], 0, 32)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
octalPerms, err := strconv.ParseInt(stringEntry[len(stringEntry)-3], 0, 32)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
gid, err := strconv.ParseInt(stringEntry[len(stringEntry)-2], 0, 32)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
size, err := strconv.ParseInt(stringEntry[len(stringEntry)-1], 0, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
pkgFiles = append(pkgFiles, &PackageFileEntry{
|
||||||
|
Path: strings.TrimSuffix(strings.Join(stringEntry[:len(stringEntry)-4], " "), "/"),
|
||||||
|
OctalPerms: uint32(octalPerms),
|
||||||
|
UserID: int(uid),
|
||||||
|
GroupID: int(gid),
|
||||||
|
SizeInBytes: size,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return pkgFiles
|
||||||
|
}
|
||||||
|
|
||||||
|
func getPackageLocalInfo(pkg, rootDir string) PackageLocalInfo {
|
||||||
|
localInfo := PackageLocalInfo{}
|
||||||
|
|
||||||
|
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
||||||
|
pkgDir := path.Join(installedDir, pkg)
|
||||||
|
localInfoFile := path.Join(path.Join(pkgDir, "local"))
|
||||||
|
|
||||||
|
if _, err := os.Stat(localInfoFile); os.IsNotExist(err) {
|
||||||
|
return localInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := os.Open(localInfoFile)
|
||||||
|
if err != nil {
|
||||||
|
return localInfo
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
err = yaml.NewDecoder(file).Decode(&localInfo)
|
||||||
|
if err != nil {
|
||||||
|
return localInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
return localInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetPackageLocalInfo(pkg string, localInfo PackageLocalInfo, rootDir string) error {
|
||||||
|
installedDir := path.Join(rootDir, "var/lib/bpm/installed/")
|
||||||
|
pkgDir := path.Join(installedDir, pkg)
|
||||||
|
|
||||||
|
localFile, err := os.OpenFile(path.Join(pkgDir, "local"), os.O_WRONLY|os.O_CREATE, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer localFile.Close()
|
||||||
|
|
||||||
|
err = yaml.NewEncoder(localFile).Encode(localInfo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpgradePersistentData(rootDir string) error {
|
||||||
|
persistentDataDir := path.Join(rootDir, "var/lib/bpm")
|
||||||
|
|
||||||
|
// Create persistent data directory
|
||||||
|
os.MkdirAll(persistentDataDir, 0755)
|
||||||
|
|
||||||
|
// Upgrade installed package directories
|
||||||
|
dirEntries, err := os.ReadDir(path.Join(persistentDataDir, "installed"))
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
} else if err == nil {
|
||||||
|
for _, entry := range dirEntries {
|
||||||
|
pkgDir := path.Join(persistentDataDir, "installed", entry.Name())
|
||||||
|
|
||||||
|
// Generate default local package information file
|
||||||
|
if _, err := os.Stat(path.Join(pkgDir, "local")); err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
} else if os.IsNotExist(err) {
|
||||||
|
fmt.Printf("Generating local package information for package (%s)\n", entry.Name())
|
||||||
|
|
||||||
|
out, err := yaml.Marshal(PackageLocalInfo{
|
||||||
|
InstallationReason: "unknown",
|
||||||
|
InstalledOn: 0,
|
||||||
|
LastUpdatedOn: 0,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.WriteFile(path.Join(pkgDir, "local"), out, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move installation reason to local package information file
|
||||||
|
if installationReason, err := os.ReadFile(path.Join(pkgDir, "installation_reason")); err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
} else if err == nil {
|
||||||
|
fmt.Printf("Moving installation reason to local package information for package (%s)\n", entry.Name())
|
||||||
|
|
||||||
|
data, err := os.ReadFile(path.Join(pkgDir, "local"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
localInfo := &PackageLocalInfo{}
|
||||||
|
err = yaml.Unmarshal(data, localInfo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
localInfo.InstallationReason = strings.TrimSpace(string(installationReason))
|
||||||
|
|
||||||
|
out, err := yaml.Marshal(localInfo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.WriteFile(path.Join(pkgDir, "local"), out, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Remove(path.Join(pkgDir, "installation_reason"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set persistent data version number
|
||||||
|
err = os.WriteFile(path.Join(persistentDataDir, ".version"), []byte(strconv.Itoa(persistentDataVersion)), 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package bpmlib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func downloadFile(barText, u, filepath string, perm os.FileMode) error {
|
||||||
|
if strings.HasSuffix(filepath, "/") {
|
||||||
|
return fmt.Errorf("Filepath must not end in '/'")
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// Create parent directories
|
||||||
|
err = os.MkdirAll(path.Dir(filepath), 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create file
|
||||||
|
file, err := os.Create(filepath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
// Create progress bar
|
||||||
|
bar := createProgressBar(resp.ContentLength, barText, barText == "")
|
||||||
|
defer bar.Close()
|
||||||
|
|
||||||
|
// Copy data
|
||||||
|
_, err = io.Copy(io.MultiWriter(file, bar), resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set file permissions
|
||||||
|
err = file.Chmod(perm)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,833 @@
|
|||||||
|
package bpmlib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"text/tabwriter"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BPMOperation struct {
|
||||||
|
Actions []OperationAction
|
||||||
|
UnresolvedDepends []string
|
||||||
|
ModifiedFiles map[string]string
|
||||||
|
CompilationJobs int
|
||||||
|
RunChecks bool
|
||||||
|
RootDir string
|
||||||
|
|
||||||
|
compiledPackages map[string]string
|
||||||
|
hasFetchedPackages bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) GetTotalDownloadSize() int64 {
|
||||||
|
var ret int64 = 0
|
||||||
|
for _, action := range operation.Actions {
|
||||||
|
if action.GetActionType() == "fetch" {
|
||||||
|
ret += action.(*FetchPackageAction).DatabaseEntry.DownloadSize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) GetTotalInstalledSize() int64 {
|
||||||
|
var ret int64 = 0
|
||||||
|
for _, action := range operation.Actions {
|
||||||
|
if action.GetActionType() == "install" {
|
||||||
|
ret += action.(*InstallPackageAction).BpmPackage.GetInstalledSize()
|
||||||
|
} else if action.GetActionType() == "fetch" {
|
||||||
|
ret += action.(*FetchPackageAction).DatabaseEntry.InstalledSize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) GetFinalActionSize(rootDir string) int64 {
|
||||||
|
var ret int64 = 0
|
||||||
|
for _, action := range operation.Actions {
|
||||||
|
if action.GetActionType() == "install" {
|
||||||
|
ret += action.(*InstallPackageAction).BpmPackage.GetInstalledSize()
|
||||||
|
if IsPackageInstalled(action.(*InstallPackageAction).BpmPackage.PkgInfo.Name, rootDir) {
|
||||||
|
ret -= GetPackage(action.(*InstallPackageAction).BpmPackage.PkgInfo.Name, rootDir).GetInstalledSize()
|
||||||
|
}
|
||||||
|
} else if action.GetActionType() == "fetch" {
|
||||||
|
ret += action.(*FetchPackageAction).DatabaseEntry.InstalledSize
|
||||||
|
if IsPackageInstalled(action.(*FetchPackageAction).DatabaseEntry.Info.Name, rootDir) {
|
||||||
|
ret -= action.(*FetchPackageAction).DatabaseEntry.InstalledSize
|
||||||
|
}
|
||||||
|
} else if action.GetActionType() == "remove" {
|
||||||
|
ret -= action.(*RemovePackageAction).BpmPackage.GetInstalledSize()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) ResolveDependencies(installRuntimeDepends bool) {
|
||||||
|
// Discover resolved virtual packages
|
||||||
|
resolvedVirtualPackages := make(map[string]string)
|
||||||
|
for _, value := range slices.Clone(operation.Actions) {
|
||||||
|
var pkgInfo *PackageInfo
|
||||||
|
if value.GetActionType() == "install" {
|
||||||
|
action := value.(*InstallPackageAction)
|
||||||
|
pkgInfo = action.BpmPackage.PkgInfo
|
||||||
|
} else if value.GetActionType() == "fetch" {
|
||||||
|
action := value.(*FetchPackageAction)
|
||||||
|
pkgInfo = action.DatabaseEntry.Info
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, vpkg := range pkgInfo.Provides {
|
||||||
|
if _, ok := resolvedVirtualPackages[vpkg]; !ok {
|
||||||
|
resolvedVirtualPackages[vpkg] = pkgInfo.Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Discover all dependencies
|
||||||
|
newActions := make([]OperationAction, 0)
|
||||||
|
for _, value := range operation.Actions {
|
||||||
|
var pkgInfo *PackageInfo
|
||||||
|
if value.GetActionType() == "install" {
|
||||||
|
action := value.(*InstallPackageAction)
|
||||||
|
pkgInfo = action.BpmPackage.PkgInfo
|
||||||
|
} else if value.GetActionType() == "fetch" {
|
||||||
|
action := value.(*FetchPackageAction)
|
||||||
|
pkgInfo = action.DatabaseEntry.Info
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
resolved, unresolved := ResolveDependencies(pkgInfo, resolvedVirtualPackages, installRuntimeDepends, operation.RootDir)
|
||||||
|
|
||||||
|
// Append unresolved dependencies
|
||||||
|
operation.UnresolvedDepends = append(operation.UnresolvedDepends, unresolved...)
|
||||||
|
operation.UnresolvedDepends = removeDuplicates(operation.UnresolvedDepends)
|
||||||
|
|
||||||
|
for _, resolvedPkg := range resolved {
|
||||||
|
if ActionSliceIndex(newActions, resolvedPkg.DatabaseEntry.Info.Name) == -1 { // Dependency not in actions slice
|
||||||
|
var action OperationAction = &FetchPackageAction{
|
||||||
|
InstallationReason: resolvedPkg.InstallationReason,
|
||||||
|
DatabaseEntry: resolvedPkg.DatabaseEntry,
|
||||||
|
}
|
||||||
|
newActions = append(newActions, action)
|
||||||
|
|
||||||
|
for _, vpkg := range resolvedPkg.DatabaseEntry.Info.Provides {
|
||||||
|
if _, ok := resolvedVirtualPackages[vpkg]; !ok {
|
||||||
|
resolvedVirtualPackages[vpkg] = resolvedPkg.DatabaseEntry.Info.Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if can move original action
|
||||||
|
if i := ActionSliceIndex(operation.Actions, resolvedPkg.DatabaseEntry.Info.Name); i != -1 {
|
||||||
|
newActions[len(newActions)-1] = operation.Actions[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ActionSliceIndex(newActions, pkgInfo.Name) == -1 {
|
||||||
|
newActions = append(newActions, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
operation.Actions = newActions
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) Cleanup(cleanupMakeDepends bool) error {
|
||||||
|
// Get all installed packages
|
||||||
|
installedPackageNames, err := GetInstalledPackages(operation.RootDir)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not get installed packages: %s", err)
|
||||||
|
}
|
||||||
|
installedPackages := make([]*PackageInfo, len(installedPackageNames))
|
||||||
|
for i, value := range installedPackageNames {
|
||||||
|
pkgInfo := GetPackageInfo(value, operation.RootDir)
|
||||||
|
if pkgInfo == nil {
|
||||||
|
return errors.New("could not find installed package (" + value + ")")
|
||||||
|
}
|
||||||
|
installedPackages[i] = pkgInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get packages to remove
|
||||||
|
removeActions := make(map[string]*RemovePackageAction)
|
||||||
|
for _, action := range slices.Clone(operation.Actions) {
|
||||||
|
if action.GetActionType() == "remove" {
|
||||||
|
removeActions[action.(*RemovePackageAction).BpmPackage.PkgInfo.Name] = action.(*RemovePackageAction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run BFS on all manually installed packages
|
||||||
|
visited := make([]string, 0)
|
||||||
|
for _, pkg := range installedPackages {
|
||||||
|
if getPackageLocalInfo(pkg.Name, operation.RootDir).GetInstallationReason() != InstallationReasonManual {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
queue := make([]*PackageInfo, 0)
|
||||||
|
|
||||||
|
queue = append(queue, pkg)
|
||||||
|
|
||||||
|
for len(queue) > 0 {
|
||||||
|
v := queue[len(queue)-1]
|
||||||
|
queue = queue[:len(queue)-1]
|
||||||
|
|
||||||
|
// Skip package if it's to be removed
|
||||||
|
if _, ok := removeActions[v.Name]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark package as visited
|
||||||
|
visited = append(visited, v.Name)
|
||||||
|
|
||||||
|
// Get all package dependencies
|
||||||
|
depends := v.Depends
|
||||||
|
depends = append(depends, v.RuntimeDepends...)
|
||||||
|
if cleanupMakeDepends && v.Type == "source" {
|
||||||
|
depends = append(depends, v.MakeDepends...)
|
||||||
|
depends = append(depends, v.CheckDepends...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop through all dependencies
|
||||||
|
for _, depend := range depends {
|
||||||
|
// Remove required version
|
||||||
|
depend, _, _ = SplitPkgNameAndVersion(depend)
|
||||||
|
|
||||||
|
// Resolve dependency
|
||||||
|
var dependPkgInfo *PackageInfo
|
||||||
|
if providers := GetVirtualPackageInfo(depend, operation.RootDir); len(providers) > 0 {
|
||||||
|
dependPkgInfo = providers[0]
|
||||||
|
} else {
|
||||||
|
dependPkgInfo = GetPackageInfo(depend, operation.RootDir)
|
||||||
|
}
|
||||||
|
if dependPkgInfo == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark dependency as visited and add it to the queue
|
||||||
|
if !slices.Contains(visited, dependPkgInfo.Name) {
|
||||||
|
visited = append(visited, dependPkgInfo.Name)
|
||||||
|
queue = append(queue, dependPkgInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove all packages that were not discovered after running BFS
|
||||||
|
for _, pkg := range installedPackageNames {
|
||||||
|
// Do not add package removal action if there already is one
|
||||||
|
if _, ok := removeActions[pkg]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !slices.Contains(visited, pkg) {
|
||||||
|
bpmpkg := GetPackage(pkg, operation.RootDir)
|
||||||
|
if bpmpkg == nil {
|
||||||
|
return errors.New("Error: could not find installed package (" + pkg + ")")
|
||||||
|
}
|
||||||
|
operation.Actions = append(operation.Actions, &RemovePackageAction{BpmPackage: bpmpkg})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) ReplaceObsoletePackages() {
|
||||||
|
for _, value := range slices.Clone(operation.Actions) {
|
||||||
|
var pkgInfo *PackageInfo
|
||||||
|
if value.GetActionType() == "install" {
|
||||||
|
action := value.(*InstallPackageAction)
|
||||||
|
pkgInfo = action.BpmPackage.PkgInfo
|
||||||
|
|
||||||
|
} else if value.GetActionType() == "fetch" {
|
||||||
|
action := value.(*FetchPackageAction)
|
||||||
|
pkgInfo = action.DatabaseEntry.Info
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, r := range pkgInfo.Replaces {
|
||||||
|
if bpmpkg := GetPackage(r, operation.RootDir); bpmpkg != nil && ActionSliceIndex(operation.Actions, bpmpkg.PkgInfo.Name) == -1 {
|
||||||
|
var action OperationAction = &RemovePackageAction{
|
||||||
|
BpmPackage: bpmpkg,
|
||||||
|
}
|
||||||
|
operation.Actions = slices.Insert(operation.Actions, 0, action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) CheckForConflicts() map[string][]string {
|
||||||
|
conflicts := make(map[string][]string)
|
||||||
|
|
||||||
|
// Get installed packages
|
||||||
|
installedPackages := localPackageInformation[operation.RootDir]
|
||||||
|
|
||||||
|
// Get packages to be removed
|
||||||
|
removedPackages := make([]string, 0)
|
||||||
|
for _, value := range slices.Clone(operation.Actions) {
|
||||||
|
if value.GetActionType() != "remove" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
removedPackages = append(removedPackages, value.(*RemovePackageAction).BpmPackage.PkgInfo.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for conflicts
|
||||||
|
for _, value := range slices.Clone(operation.Actions) {
|
||||||
|
var pkgInfo *PackageInfo
|
||||||
|
if value.GetActionType() == "install" {
|
||||||
|
pkgInfo = value.(*InstallPackageAction).BpmPackage.PkgInfo
|
||||||
|
} else if value.GetActionType() == "fetch" {
|
||||||
|
pkgInfo = value.(*FetchPackageAction).DatabaseEntry.Info
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for conflicts with installed packages
|
||||||
|
for _, installedPkg := range installedPackages {
|
||||||
|
// Skip if package is to be removed
|
||||||
|
if slices.Contains(removedPackages, installedPkg.Name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip if same package
|
||||||
|
if pkgInfo.Name == installedPkg.Name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for new package conflicts
|
||||||
|
if slices.Contains(pkgInfo.Conflicts, installedPkg.Name) {
|
||||||
|
conflicts[pkgInfo.Name] = append(conflicts[pkgInfo.Name], installedPkg.Name)
|
||||||
|
}
|
||||||
|
for _, vpkg := range installedPkg.Provides {
|
||||||
|
if slices.Contains(pkgInfo.Conflicts, vpkg) {
|
||||||
|
conflicts[pkgInfo.Name] = append(conflicts[pkgInfo.Name], vpkg+" ("+installedPkg.Name+")")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for installed package conflicts
|
||||||
|
for _, vpkg := range pkgInfo.Provides {
|
||||||
|
if slices.Contains(installedPkg.Conflicts, vpkg) {
|
||||||
|
conflicts[installedPkg.Name] = append(conflicts[installedPkg.Name], vpkg+" ("+pkgInfo.Name+")")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for conflicts with other new packages
|
||||||
|
for _, value := range slices.Clone(operation.Actions) {
|
||||||
|
var pkgInfo2 *PackageInfo
|
||||||
|
if value.GetActionType() == "install" {
|
||||||
|
pkgInfo2 = value.(*InstallPackageAction).BpmPackage.PkgInfo
|
||||||
|
} else if value.GetActionType() == "fetch" {
|
||||||
|
pkgInfo2 = value.(*FetchPackageAction).DatabaseEntry.Info
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip if same package
|
||||||
|
if pkgInfo.Name == pkgInfo2.Name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for other package conflicts
|
||||||
|
if slices.Contains(pkgInfo.Conflicts, pkgInfo2.Name) {
|
||||||
|
conflicts[pkgInfo.Name] = append(conflicts[pkgInfo.Name], pkgInfo2.Name)
|
||||||
|
}
|
||||||
|
for _, vpkg := range pkgInfo2.Provides {
|
||||||
|
if slices.Contains(pkgInfo.Conflicts, vpkg) {
|
||||||
|
conflicts[pkgInfo.Name] = append(conflicts[pkgInfo.Name], vpkg+" ("+pkgInfo2.Name+")")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return conflicts
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) ShowOperationSummary() {
|
||||||
|
if len(operation.Actions) == 0 {
|
||||||
|
fmt.Println("No action needs to be taken")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
writer := tabwriter.NewWriter(os.Stdout, 6, 4, 6, ' ', 0)
|
||||||
|
fmt.Fprintln(writer, "Name\tVersion\tAction\tInstallation Reason\tFrom Source")
|
||||||
|
|
||||||
|
for _, value := range operation.Actions {
|
||||||
|
var pkgInfo *PackageInfo
|
||||||
|
var installationReason = InstallationReasonUnknown
|
||||||
|
if value.GetActionType() == "install" {
|
||||||
|
installationReason = value.(*InstallPackageAction).InstallationReason
|
||||||
|
pkgInfo = value.(*InstallPackageAction).BpmPackage.PkgInfo
|
||||||
|
if value.(*InstallPackageAction).SplitPackageToInstall != "" {
|
||||||
|
pkgInfo = pkgInfo.GetSplitPackageInfo(value.(*InstallPackageAction).SplitPackageToInstall)
|
||||||
|
}
|
||||||
|
} else if value.GetActionType() == "fetch" {
|
||||||
|
installationReason = value.(*FetchPackageAction).InstallationReason
|
||||||
|
pkgInfo = value.(*FetchPackageAction).DatabaseEntry.Info
|
||||||
|
} else {
|
||||||
|
pkgInfo = value.(*RemovePackageAction).BpmPackage.PkgInfo
|
||||||
|
fmt.Fprintf(writer, "%s\t%s\t%s\t%s\t%s\n", pkgInfo.Name, pkgInfo.GetFullVersion(), "Remove", "-", "-")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
installationReasonStr := ""
|
||||||
|
switch installationReason {
|
||||||
|
case InstallationReasonManual:
|
||||||
|
installationReasonStr = "Manual"
|
||||||
|
case InstallationReasonDependency:
|
||||||
|
installationReasonStr = "Dependency"
|
||||||
|
case InstallationReasonMakeDependency:
|
||||||
|
installationReasonStr = "Make dependency"
|
||||||
|
default:
|
||||||
|
installationReasonStr = "Unknown"
|
||||||
|
}
|
||||||
|
|
||||||
|
installedInfo := GetPackageInfo(pkgInfo.Name, operation.RootDir)
|
||||||
|
if installedInfo == nil {
|
||||||
|
fmt.Fprintf(writer, "%s\t%s\t%s\t%s\t%t\n", pkgInfo.Name, pkgInfo.GetFullVersion(), "Install", installationReasonStr, pkgInfo.Type == "source")
|
||||||
|
} else {
|
||||||
|
comparison := CompareVersions(pkgInfo.GetFullVersion(), installedInfo.GetFullVersion())
|
||||||
|
if comparison < 0 {
|
||||||
|
fmt.Fprintf(writer, "%s\t%s -> %s\t%s\t%s\t%t\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), "Downgrade", installationReasonStr, pkgInfo.Type == "source")
|
||||||
|
} else if comparison > 0 {
|
||||||
|
fmt.Fprintf(writer, "%s\t%s -> %s\t%s\t%s\t%t\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), "Upgrade", installationReasonStr, pkgInfo.Type == "source")
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(writer, "%s\t%s\t%s\t%s\t%t\n", pkgInfo.Name, pkgInfo.GetFullVersion(), "Reinstall", installationReasonStr, pkgInfo.Type == "source")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.Flush()
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
if operation.RootDir != "/" {
|
||||||
|
fmt.Println("Warning: Operating in " + operation.RootDir)
|
||||||
|
}
|
||||||
|
if operation.GetTotalDownloadSize() > 0 {
|
||||||
|
fmt.Printf("%s will be downloaded to complete this operation\n", BytesToHumanReadable(operation.GetTotalDownloadSize()))
|
||||||
|
}
|
||||||
|
if operation.GetFinalActionSize(operation.RootDir) > 0 {
|
||||||
|
fmt.Printf("A total of %s will be installed after the operation finishes\n", BytesToHumanReadable(operation.GetFinalActionSize(operation.RootDir)))
|
||||||
|
} else if operation.GetFinalActionSize(operation.RootDir) < 0 {
|
||||||
|
fmt.Printf("A total of %s will be freed after the operation finishes\n", strings.TrimPrefix(BytesToHumanReadable(operation.GetFinalActionSize(operation.RootDir)), "-"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) ShowSourcePackageContent() (sourcePackagesShown int, err error) {
|
||||||
|
// Fetch packages
|
||||||
|
if !operation.hasFetchedPackages {
|
||||||
|
err = operation.FetchPackages()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, action := range operation.Actions {
|
||||||
|
if action.GetActionType() != "install" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if action.(*InstallPackageAction).BpmPackage.PkgInfo.Type != "source" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err = showPackageFiles(action.(*InstallPackageAction).File)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sourcePackagesShown++
|
||||||
|
}
|
||||||
|
|
||||||
|
return sourcePackagesShown, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) GetOptionalDependencies() (optionalDepends map[string][]string) {
|
||||||
|
optionalDepends = make(map[string][]string)
|
||||||
|
|
||||||
|
// Find all optional dependencies
|
||||||
|
for _, value := range slices.Clone(operation.Actions) {
|
||||||
|
var pkgInfo *PackageInfo
|
||||||
|
if value.GetActionType() == "install" {
|
||||||
|
action := value.(*InstallPackageAction)
|
||||||
|
pkgInfo = action.BpmPackage.PkgInfo
|
||||||
|
} else if value.GetActionType() == "fetch" {
|
||||||
|
action := value.(*FetchPackageAction)
|
||||||
|
pkgInfo = action.DatabaseEntry.Info
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, depend := range pkgInfo.OptionalDepends {
|
||||||
|
// Get optional dependency name
|
||||||
|
dependSplit := strings.SplitN(depend, ":", 2)
|
||||||
|
dependName, _, _ := SplitPkgNameAndVersion(dependSplit[0])
|
||||||
|
|
||||||
|
// Skip if dependency is already installed
|
||||||
|
if IsPackageInstalled(dependName, operation.RootDir) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip if not a new dependency of the package
|
||||||
|
if installedPkg := GetPackage(pkgInfo.Name, operation.RootDir); installedPkg != nil && slices.ContainsFunc(installedPkg.PkgInfo.OptionalDepends, func(n string) bool {
|
||||||
|
// Remove optional dependency comment
|
||||||
|
n = strings.SplitN(n, ":", 2)[0]
|
||||||
|
|
||||||
|
// Remove required version
|
||||||
|
n, _, _ = SplitPkgNameAndVersion(n)
|
||||||
|
|
||||||
|
return n == dependName
|
||||||
|
}) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(dependSplit) == 2 {
|
||||||
|
optionalDepends[pkgInfo.Name] = append(optionalDepends[pkgInfo.Name], fmt.Sprintf("%s (%s)", dependSplit[0], dependSplit[1]))
|
||||||
|
} else {
|
||||||
|
optionalDepends[pkgInfo.Name] = append(optionalDepends[pkgInfo.Name], dependName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) RunPreHooks(verbose bool) error {
|
||||||
|
// Return if hooks directory does not exist
|
||||||
|
if stat, err := os.Stat(path.Join(operation.RootDir, "var/lib/bpm/hooks")); err != nil || !stat.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get directory entries in hooks directory
|
||||||
|
dirEntries, err := os.ReadDir(path.Join(operation.RootDir, "var/lib/bpm/hooks"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find all hooks, validate and execute them
|
||||||
|
for _, entry := range dirEntries {
|
||||||
|
if entry.Type().IsRegular() && strings.HasSuffix(entry.Name(), ".bpmhook") {
|
||||||
|
hook, err := createHook(path.Join(operation.RootDir, "var/lib/bpm/hooks", entry.Name()))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error while reading hook (%s): %s", entry.Name(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !hook.TriggerPreOperation {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err = hook.Execute(operation.ModifiedFiles, false, verbose, operation.RootDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warning: could not execute hook (%s): %s\n", entry.Name(), err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) RunPostHooks(verbose bool) error {
|
||||||
|
// Return if hooks directory does not exist
|
||||||
|
if stat, err := os.Stat(path.Join(operation.RootDir, "var/lib/bpm/hooks")); err != nil || !stat.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get directory entries in hooks directory
|
||||||
|
dirEntries, err := os.ReadDir(path.Join(operation.RootDir, "var/lib/bpm/hooks"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find all hooks, validate and execute them
|
||||||
|
for _, entry := range dirEntries {
|
||||||
|
if entry.Type().IsRegular() && strings.HasSuffix(entry.Name(), ".bpmhook") {
|
||||||
|
hook, err := createHook(path.Join(operation.RootDir, "var/lib/bpm/hooks", entry.Name()))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error while reading hook (%s): %s", entry.Name(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if hook.TriggerPreOperation {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err = hook.Execute(operation.ModifiedFiles, false, verbose, operation.RootDir)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warning: could not execute hook (%s): %s\n", entry.Name(), err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) FetchPackages() (err error) {
|
||||||
|
// Fetch packages from databases
|
||||||
|
if slices.ContainsFunc(operation.Actions, func(action OperationAction) bool {
|
||||||
|
return action.GetActionType() == "fetch"
|
||||||
|
}) {
|
||||||
|
fmt.Println("Fetching packages from available databases...")
|
||||||
|
|
||||||
|
// Create map for fetched packages
|
||||||
|
fetchedPackages := make(map[string]string)
|
||||||
|
|
||||||
|
for i, action := range operation.Actions {
|
||||||
|
if action.GetActionType() != "fetch" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get database entry
|
||||||
|
entry := action.(*FetchPackageAction).DatabaseEntry
|
||||||
|
|
||||||
|
// Create bpmpkg variable
|
||||||
|
var bpmpkg *BPMPackage
|
||||||
|
|
||||||
|
// Check if package has already been fetched from download link
|
||||||
|
if fetchedFilepath, ok := fetchedPackages[entry.Filepath]; !ok {
|
||||||
|
// Fetch package from database
|
||||||
|
fetchedPackage, err := entry.Database.FetchPackage(entry.Info.Name)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not fetch package (%s): %s\n", entry.Info.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read fetched package
|
||||||
|
bpmpkg, err = ReadPackage(fetchedPackage)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not fetch package (%s): %s\n", entry.Info.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add fetched package to map
|
||||||
|
fetchedPackages[entry.Filepath] = fetchedPackage
|
||||||
|
} else {
|
||||||
|
// Read fetched package
|
||||||
|
bpmpkg, err = ReadPackage(fetchedFilepath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not read package (%s): %s\n", entry.Info.Name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get size of fetched archive
|
||||||
|
stat, err := os.Stat(fetchedFilepath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
bar := createProgressBar(stat.Size(), "Downloading "+entry.Info.Name, false)
|
||||||
|
bar.Set64(stat.Size())
|
||||||
|
bar.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
if bpmpkg.PkgInfo.IsSplitPackage() {
|
||||||
|
operation.Actions[i] = &InstallPackageAction{
|
||||||
|
File: fetchedPackages[entry.Filepath],
|
||||||
|
InstallationReason: action.(*FetchPackageAction).InstallationReason,
|
||||||
|
BpmPackage: bpmpkg,
|
||||||
|
SplitPackageToInstall: entry.Info.Name,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
operation.Actions[i] = &InstallPackageAction{
|
||||||
|
File: fetchedPackages[entry.Filepath],
|
||||||
|
InstallationReason: action.(*FetchPackageAction).InstallationReason,
|
||||||
|
BpmPackage: bpmpkg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
operation.hasFetchedPackages = true
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) GetModifiedFiles() {
|
||||||
|
// Get modified files
|
||||||
|
for _, action := range operation.Actions {
|
||||||
|
if action.GetActionType() == "install" {
|
||||||
|
installAction := action.(*InstallPackageAction)
|
||||||
|
isUpgrade := IsPackageInstalled(installAction.BpmPackage.PkgInfo.Name, operation.RootDir)
|
||||||
|
|
||||||
|
for _, pkgFile := range installAction.BpmPackage.PkgFiles {
|
||||||
|
operation.ModifiedFiles[pkgFile.Path] = "install"
|
||||||
|
if isUpgrade {
|
||||||
|
operation.ModifiedFiles[pkgFile.Path] = "upgrade"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if action.GetActionType() == "remove" {
|
||||||
|
removeAction := action.(*RemovePackageAction)
|
||||||
|
|
||||||
|
for _, pkgFile := range removeAction.BpmPackage.PkgFiles {
|
||||||
|
operation.ModifiedFiles[pkgFile.Path] = "remove"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (operation *BPMOperation) Execute(verbose, force bool) (err error) {
|
||||||
|
// Fetch packages
|
||||||
|
if !operation.hasFetchedPackages {
|
||||||
|
err = operation.FetchPackages()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine words to be used for the following message
|
||||||
|
words := make([]string, 0)
|
||||||
|
if slices.ContainsFunc(operation.Actions, func(action OperationAction) bool {
|
||||||
|
return action.GetActionType() == "install"
|
||||||
|
}) {
|
||||||
|
words = append(words, "Installing")
|
||||||
|
}
|
||||||
|
|
||||||
|
if slices.ContainsFunc(operation.Actions, func(action OperationAction) bool {
|
||||||
|
return action.GetActionType() == "remove"
|
||||||
|
}) {
|
||||||
|
words = append(words, "Removing")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(words) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
fmt.Printf("%s packages...\n", strings.Join(words, "/"))
|
||||||
|
|
||||||
|
// Installing/Removing packages from system
|
||||||
|
for _, action := range operation.Actions {
|
||||||
|
if action.GetActionType() == "remove" {
|
||||||
|
pkgInfo := action.(*RemovePackageAction).BpmPackage.PkgInfo
|
||||||
|
err := removePackage(pkgInfo.Name, verbose, operation.RootDir)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not remove package (%s): %s\n", pkgInfo.Name, err)
|
||||||
|
}
|
||||||
|
} else if action.GetActionType() == "install" {
|
||||||
|
value := action.(*InstallPackageAction)
|
||||||
|
fileToInstall := value.File
|
||||||
|
bpmpkg := value.BpmPackage
|
||||||
|
var err error
|
||||||
|
|
||||||
|
// Compile package if type is 'source'
|
||||||
|
if bpmpkg.PkgInfo.Type == "source" {
|
||||||
|
// Get path to compiled package directory
|
||||||
|
compiledDir := path.Join(operation.RootDir, "/var/cache/bpm/compiled/")
|
||||||
|
|
||||||
|
// Create compiled package directory if not exists
|
||||||
|
if _, err := os.Stat(compiledDir); err != nil {
|
||||||
|
err := os.MkdirAll(compiledDir, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get package name to install
|
||||||
|
pkgNameToInstall := bpmpkg.PkgInfo.Name
|
||||||
|
if bpmpkg.PkgInfo.IsSplitPackage() {
|
||||||
|
pkgNameToInstall = value.SplitPackageToInstall
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compile source package if not compiled already
|
||||||
|
if _, ok := operation.compiledPackages[pkgNameToInstall]; !ok {
|
||||||
|
outputBpmPackages, err := CompileSourcePackage(value.File, compiledDir, operation.CompilationJobs, !operation.RunChecks, false, verbose)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not compile source package (%s): %s\n", value.File, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add compiled packages to slice
|
||||||
|
for pkgName, pkgFile := range outputBpmPackages {
|
||||||
|
operation.compiledPackages[pkgName] = pkgFile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set values
|
||||||
|
fileToInstall = operation.compiledPackages[pkgNameToInstall]
|
||||||
|
bpmpkg, err = ReadPackage(fileToInstall)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not read package (%s): %s\n", fileToInstall, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if value.InstallationReason != InstallationReasonManual {
|
||||||
|
err = installPackage(fileToInstall, value.InstallationReason, operation.RootDir, verbose, true)
|
||||||
|
} else {
|
||||||
|
err = installPackage(fileToInstall, value.InstallationReason, operation.RootDir, verbose, force)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not install package (%s): %s\n", bpmpkg.PkgInfo.Name, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type OperationAction interface {
|
||||||
|
GetActionType() string
|
||||||
|
}
|
||||||
|
|
||||||
|
type InstallPackageAction struct {
|
||||||
|
File string
|
||||||
|
InstallationReason InstallationReason
|
||||||
|
SplitPackageToInstall string
|
||||||
|
BpmPackage *BPMPackage
|
||||||
|
}
|
||||||
|
|
||||||
|
func (action *InstallPackageAction) GetActionType() string {
|
||||||
|
return "install"
|
||||||
|
}
|
||||||
|
|
||||||
|
type FetchPackageAction struct {
|
||||||
|
InstallationReason InstallationReason
|
||||||
|
DatabaseEntry *BPMDatabaseEntry
|
||||||
|
}
|
||||||
|
|
||||||
|
func (action *FetchPackageAction) GetActionType() string {
|
||||||
|
return "fetch"
|
||||||
|
}
|
||||||
|
|
||||||
|
type RemovePackageAction struct {
|
||||||
|
BpmPackage *BPMPackage
|
||||||
|
}
|
||||||
|
|
||||||
|
func (action *RemovePackageAction) GetActionType() string {
|
||||||
|
return "remove"
|
||||||
|
}
|
||||||
|
|
||||||
|
func ActionSliceIndex(actions []OperationAction, pkg string) int {
|
||||||
|
for i, action := range actions {
|
||||||
|
if action.GetActionType() == "install" {
|
||||||
|
if action.(*InstallPackageAction).BpmPackage.PkgInfo.Name == pkg {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
} else if action.GetActionType() == "fetch" {
|
||||||
|
if action.(*FetchPackageAction).DatabaseEntry.Info.Name == pkg {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
} else if action.GetActionType() == "remove" {
|
||||||
|
if action.(*RemovePackageAction).BpmPackage.PkgInfo.Name == pkg {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
func ActionSliceRemove(actions []OperationAction, pkg, actionType string) []OperationAction {
|
||||||
|
actions = slices.DeleteFunc(actions, func(a OperationAction) bool {
|
||||||
|
if a.GetActionType() != actionType {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if a.GetActionType() == "install" {
|
||||||
|
return a.(*InstallPackageAction).BpmPackage.PkgInfo.Name == pkg
|
||||||
|
} else if a.GetActionType() == "fetch" {
|
||||||
|
return a.(*FetchPackageAction).DatabaseEntry.Info.Name == pkg
|
||||||
|
} else if a.GetActionType() == "remove" {
|
||||||
|
return a.(*RemovePackageAction).BpmPackage.PkgInfo.Name == pkg
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
return actions
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,209 @@
|
|||||||
|
package bpmlib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"archive/tar"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type tarballFileReader struct {
|
||||||
|
tarReader *tar.Reader
|
||||||
|
file *os.File
|
||||||
|
}
|
||||||
|
|
||||||
|
func listTarballContent(tarballPath string) (content []string, err error) {
|
||||||
|
file, err := os.Open(tarballPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
tr := tar.NewReader(file)
|
||||||
|
for {
|
||||||
|
header, err := tr.Next()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch header.Typeflag {
|
||||||
|
case tar.TypeDir:
|
||||||
|
continue
|
||||||
|
default:
|
||||||
|
content = append(content, header.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return content, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func readTarballFile(tarballPath, fileToExtract string) (*tarballFileReader, error) {
|
||||||
|
file, err := os.Open(tarballPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
tr := tar.NewReader(file)
|
||||||
|
for {
|
||||||
|
header, err := tr.Next()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if header.Name == fileToExtract {
|
||||||
|
if header.Typeflag != tar.TypeReg {
|
||||||
|
return nil, errors.New("file to extract must be a regular file")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &tarballFileReader{
|
||||||
|
tarReader: tr,
|
||||||
|
file: file,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New("could not file in tarball")
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractTarballFile(tarballPath, fileToExtract string, workingDirectory string, uid, gid int) (err error) {
|
||||||
|
file, err := os.Open(tarballPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
tr := tar.NewReader(file)
|
||||||
|
for {
|
||||||
|
header, err := tr.Next()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip if filename does not match
|
||||||
|
if header.Name != fileToExtract {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trim directory name from header name
|
||||||
|
header.Name = strings.Split(header.Name, "/")[len(strings.Split(header.Name, "/"))-1]
|
||||||
|
outputPath := path.Join(workingDirectory, header.Name)
|
||||||
|
|
||||||
|
switch header.Typeflag {
|
||||||
|
case tar.TypeReg:
|
||||||
|
// Create file and set permissions
|
||||||
|
file, err = os.Create(outputPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err := file.Chmod(header.FileInfo().Mode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if uid >= 0 && gid >= 0 {
|
||||||
|
err = file.Chown(uid, gid)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy data to file
|
||||||
|
_, err = io.Copy(file, tr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close file
|
||||||
|
file.Close()
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractTarballDirectory(tarballPath, directoryToExtract, workingDirectory string, uid, gid int) (err error) {
|
||||||
|
file, err := os.Open(tarballPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
tr := tar.NewReader(file)
|
||||||
|
for {
|
||||||
|
header, err := tr.Next()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(header.Name, directoryToExtract+"/") {
|
||||||
|
// Skip directory to extract
|
||||||
|
if strings.TrimRight(header.Name, "/") == workingDirectory {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trim directory name from header name
|
||||||
|
header.Name = strings.TrimPrefix(header.Name, directoryToExtract+"/")
|
||||||
|
outputPath := path.Join(workingDirectory, header.Name)
|
||||||
|
|
||||||
|
switch header.Typeflag {
|
||||||
|
case tar.TypeDir:
|
||||||
|
// Create directory
|
||||||
|
err := os.MkdirAll(outputPath, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set directory owner
|
||||||
|
if uid >= 0 && gid >= 0 {
|
||||||
|
err = os.Chown(outputPath, uid, gid)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case tar.TypeReg:
|
||||||
|
// Create file and set permissions
|
||||||
|
file, err = os.Create(outputPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err := file.Chmod(header.FileInfo().Mode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if uid >= 0 && gid >= 0 {
|
||||||
|
err = file.Chown(uid, gid)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy data to file
|
||||||
|
_, err = io.Copy(file, tr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close file
|
||||||
|
file.Close()
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
package bpmlib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"math"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
version "github.com/knqyf263/go-rpm-version"
|
||||||
|
"github.com/schollz/progressbar/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BPMLock struct {
|
||||||
|
file *os.File
|
||||||
|
path string
|
||||||
|
}
|
||||||
|
|
||||||
|
func LockBPM(rootDir string) (*BPMLock, error) {
|
||||||
|
// Create cache directory if it doesn't already exist
|
||||||
|
err := os.MkdirAll(path.Join(rootDir, "/var/cache/bpm"), 0755)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create file
|
||||||
|
f, err := os.Create(path.Join(rootDir, "var/cache/bpm/bpm.lock"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get exclusive file lock on file
|
||||||
|
err = syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &BPMLock{f, path.Join(rootDir, "var/cache/bpm/bpm.lock")}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lock *BPMLock) Unlock() error {
|
||||||
|
err := lock.file.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Remove(lock.path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetArch() string {
|
||||||
|
uname := syscall.Utsname{}
|
||||||
|
err := syscall.Uname(&uname)
|
||||||
|
if err != nil {
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
|
var byteString [65]byte
|
||||||
|
var indexLength int
|
||||||
|
for ; uname.Machine[indexLength] != 0; indexLength++ {
|
||||||
|
byteString[indexLength] = uint8(uname.Machine[indexLength])
|
||||||
|
}
|
||||||
|
return string(byteString[:indexLength])
|
||||||
|
}
|
||||||
|
|
||||||
|
func CompareVersions(version1, version2 string) int {
|
||||||
|
v1 := version.NewVersion(version1)
|
||||||
|
v2 := version.NewVersion(version2)
|
||||||
|
|
||||||
|
return v1.Compare(v2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func createProgressBar(max int64, description string, hideBar bool) *progressbar.ProgressBar {
|
||||||
|
var output io.Writer
|
||||||
|
if hideBar {
|
||||||
|
output = io.Discard
|
||||||
|
} else {
|
||||||
|
output = os.Stderr
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(description) < 40 {
|
||||||
|
for i := len(description); i < 40; i++ {
|
||||||
|
description += " "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(description) > 40 {
|
||||||
|
overflow := len(description) - 37
|
||||||
|
description = description[:len(description)-overflow] + "..."
|
||||||
|
}
|
||||||
|
|
||||||
|
return progressbar.NewOptions64(max,
|
||||||
|
progressbar.OptionSetDescription(description),
|
||||||
|
progressbar.OptionSetWriter(output),
|
||||||
|
progressbar.OptionShowBytes(true),
|
||||||
|
progressbar.OptionShowTotalBytes(true),
|
||||||
|
progressbar.OptionSetWidth(20),
|
||||||
|
progressbar.OptionThrottle(65*time.Millisecond),
|
||||||
|
progressbar.OptionShowCount(),
|
||||||
|
progressbar.OptionOnCompletion(func() {
|
||||||
|
fmt.Fprint(output, "\n")
|
||||||
|
}),
|
||||||
|
progressbar.OptionSpinnerType(14),
|
||||||
|
progressbar.OptionSetRenderBlankState(true),
|
||||||
|
progressbar.OptionSetTheme(progressbar.ThemeASCII))
|
||||||
|
}
|
||||||
|
|
||||||
|
func stringSliceRemove(s []string, r string) []string {
|
||||||
|
for i, v := range s {
|
||||||
|
if v == r {
|
||||||
|
return append(s[:i], s[i+1:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func BytesToHumanReadable(b int64) string {
|
||||||
|
bf := float64(b)
|
||||||
|
for _, unit := range []string{"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"} {
|
||||||
|
if math.Abs(bf) < 1024.0 {
|
||||||
|
return fmt.Sprintf("%3.1f%sB", bf, unit)
|
||||||
|
}
|
||||||
|
bf /= 1024.0
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%.1fYiB", bf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeDuplicates[T comparable](sliceList []T) []T {
|
||||||
|
allKeys := make(map[T]bool)
|
||||||
|
list := []T{}
|
||||||
|
for _, item := range sliceList {
|
||||||
|
if _, value := allKeys[item]; !value {
|
||||||
|
allKeys[item] = true
|
||||||
|
list = append(list, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -1,51 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
if [ $# -eq 0 ]
|
|
||||||
then
|
|
||||||
echo "No output package name given!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
output=$1
|
|
||||||
|
|
||||||
if [[ ! "$output" =~ ^[a-z.A-Z0-9_-]{1,}$ ]]; then
|
|
||||||
echo "Invalid output name! The name must only contain letters, numbers, hyphens or underscores!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
type="binary"
|
|
||||||
|
|
||||||
echo "Creating package with the name $output..."
|
|
||||||
|
|
||||||
if [ -d files ]; then
|
|
||||||
echo "files/ directory found"
|
|
||||||
else
|
|
||||||
if [ -f source.sh ]; then
|
|
||||||
type="source"
|
|
||||||
echo "source.sh file found"
|
|
||||||
if [ -d source-files ]; then
|
|
||||||
echo "source-files/ directory found"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "files/ directory or source.sh file not found in $PWD"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f pkg.info ]; then
|
|
||||||
echo "pkg.info file found"
|
|
||||||
else
|
|
||||||
echo "pkg.info file not found in $PWD"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Creating $type package as $output"
|
|
||||||
|
|
||||||
if [[ "$type" == "binary" ]]; then
|
|
||||||
tar -czf "$output" files/ pkg.info
|
|
||||||
else
|
|
||||||
if [ -d source-files ]; then
|
|
||||||
tar -czf "$output" source.sh source-files/ pkg.info
|
|
||||||
else
|
|
||||||
tar -czf "$output" source.sh pkg.info
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
if [ $# -lt 2 ]; then
|
|
||||||
echo "Arguments missing! Try 'bpm-setup <directory> <binary/source>'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
output=$1
|
|
||||||
type=$2
|
|
||||||
|
|
||||||
if [[ ! "$output" =~ ^[a-zA-Z0-9_-]{1,}$ ]]; then
|
|
||||||
echo "Invalid output name! The name must only contain letters, numbers, hyphens or underscores!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$type" != "binary" ]] && [[ "$type" != "source" ]]; then
|
|
||||||
echo "Invalid package type! Package type must be either 'binary' or 'source'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -pv $output
|
|
||||||
cd $output
|
|
||||||
|
|
||||||
if [[ "$type" == "binary" ]]; then
|
|
||||||
cat > pkg.info << EOF
|
|
||||||
name: package_name
|
|
||||||
description: Package Description
|
|
||||||
version: 1.0
|
|
||||||
url: your package's website/repository url. Optonal
|
|
||||||
license: your package's license. Optional
|
|
||||||
architecture: $(uname -m)
|
|
||||||
type: binary
|
|
||||||
EOF
|
|
||||||
mkdir -pv files
|
|
||||||
echo "Package directory created successfully!"
|
|
||||||
echo "Make sure to edit the pkg.info file with the appropriate information for your package"
|
|
||||||
echo "Add your binaries under the files/ directory. For example a binary called 'my_binary' should go under files/usr/bin/my_binary"
|
|
||||||
echo "You can turn your package into a .bpm file use the 'bpm-create <name>' command"
|
|
||||||
else
|
|
||||||
cat > pkg.info << EOF
|
|
||||||
name: package_name
|
|
||||||
description: Package Description
|
|
||||||
version: 1.0
|
|
||||||
url: your package's website/repository url. Optional
|
|
||||||
license: your package's license. Optional
|
|
||||||
architecture: any
|
|
||||||
type: source
|
|
||||||
EOF
|
|
||||||
cat > source.sh << 'EOF'
|
|
||||||
# This is the source.sh script. It is executed by BPM in a temporary directory when compiling a source package
|
|
||||||
# BPM expects there to be an 'output' directory under the root of the temporary directory after this script finishes executing, otherwise your program may not be correctly installed
|
|
||||||
# It is recommended you create the 'output' directory along with a 'source' directory in the root of the temporary directory like this
|
|
||||||
echo "Compiling my_program..."
|
|
||||||
# Creating 'source' and 'output' directory variables
|
|
||||||
source=$(pwd)/source
|
|
||||||
output=$(pwd)/output
|
|
||||||
# Creating the 'source' and 'output' directories
|
|
||||||
mkdir $source
|
|
||||||
mkdir $output
|
|
||||||
# Downloading files
|
|
||||||
git clone https://myrepo.com/repo.git source
|
|
||||||
EOF
|
|
||||||
echo "Package directory created successfully!"
|
|
||||||
echo "Make sure to edit the pkg.info file with the appropriate information for your package"
|
|
||||||
echo "Add your compilation code in the source.sh file. Follow the instructions on the template file on how to do properly compile your program"
|
|
||||||
echo "You can turn your package into a .bpm file use the 'bpm-create <name>' command"
|
|
||||||
fi
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
name: bpm-utils
|
|
||||||
description: Utilities to create BPM packages
|
|
||||||
version: 1.3.0
|
|
||||||
url: https://gitlab.com/bubble-package-manager/bpm/
|
|
||||||
license: GPL3
|
|
||||||
architecture: x86_64
|
|
||||||
type: binary
|
|
||||||
Binary file not shown.
Binary file not shown.
@@ -1,7 +0,0 @@
|
|||||||
name: bpm
|
|
||||||
description: The Bubble Package Manager
|
|
||||||
version: 0.1.5
|
|
||||||
url: https://gitlab.com/bubble-package-manager/bpm/
|
|
||||||
license: GPL3
|
|
||||||
architecture: x86_64
|
|
||||||
type: binary
|
|
||||||
Binary file not shown.
Binary file not shown.
@@ -1,5 +0,0 @@
|
|||||||
name: hello
|
|
||||||
description: A simple hello world program
|
|
||||||
version: 1.0
|
|
||||||
architecture: x86_64
|
|
||||||
type: binary
|
|
||||||
Binary file not shown.
@@ -1,8 +0,0 @@
|
|||||||
name: htop
|
|
||||||
description: An interactive process viewer
|
|
||||||
version: 3.3.0
|
|
||||||
url: https://github.com/htop-dev/htop
|
|
||||||
license: GPL2
|
|
||||||
architecture: x86_64
|
|
||||||
type: source
|
|
||||||
#make_depends: git
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
# This file is read and executed by BPM to compile htop. It will run inside a temporary folder in /tmp during execution
|
|
||||||
echo "Compiling htop..."
|
|
||||||
# Creating 'source' directory
|
|
||||||
mkdir source
|
|
||||||
# Cloning the git repository into the 'source' directory
|
|
||||||
git clone https://github.com/htop-dev/htop.git source
|
|
||||||
# Changing directory into 'source'
|
|
||||||
cd source
|
|
||||||
# Configuring and making htop according to the installation instructions in the repository
|
|
||||||
./autogen.sh
|
|
||||||
./configure --prefix=/usr
|
|
||||||
make
|
|
||||||
# Creating an 'output' directory in the root of the temporary directory created by BPM
|
|
||||||
mkdir ./../output/
|
|
||||||
# Setting $dir to the 'output' directory
|
|
||||||
dir=$(pwd)/../output/
|
|
||||||
# Installing htop to $dir
|
|
||||||
make DESTDIR="$dir" install
|
|
||||||
# The compilation is done. BPM will now copy the files from the 'output' directory into the root of your system
|
|
||||||
echo "htop compilation complete!"
|
|
||||||
Reference in New Issue
Block a user