Compare commits
No commits in common. "master" and "0.1.4" have entirely different histories.
687
LICENSE
687
LICENSE
@ -1,21 +1,674 @@
|
||||
MIT License
|
||||
GNU GENERAL PUBLIC 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
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Preamble
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
The licenses for most software and other practical works are designed
|
||||
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
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
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>.
|
||||
|
38
Makefile
38
Makefile
@ -1,38 +0,0 @@
|
||||
ifeq ($(PREFIX),)
|
||||
PREFIX := /usr/local
|
||||
endif
|
||||
ifeq ($(BINDIR),)
|
||||
BINDIR := $(PREFIX)/bin
|
||||
endif
|
||||
ifeq ($(SYSCONFDIR),)
|
||||
SYSCONFDIR := $(PREFIX)/etc
|
||||
endif
|
||||
ifeq ($(GO),)
|
||||
GO := $(shell type -a -P go | head -n 1)
|
||||
endif
|
||||
|
||||
build:
|
||||
mkdir -p build
|
||||
$(GO) build -ldflags "-w" -o build/bpm gitlab.com/bubble-package-manager/bpm
|
||||
|
||||
install: build/bpm config/
|
||||
mkdir -p $(DESTDIR)$(BINDIR)
|
||||
mkdir -p $(DESTDIR)$(SYSCONFDIR)
|
||||
cp build/bpm $(DESTDIR)$(BINDIR)/bpm
|
||||
cp config/bpm.conf $(DESTDIR)$(SYSCONFDIR)/bpm.conf
|
||||
|
||||
compress: build/bpm config/
|
||||
mkdir -p bpm/$(BINDIR)
|
||||
mkdir -p bpm/$(SYSCONFDIR)
|
||||
cp build/bpm bpm/$(BINDIR)/bpm
|
||||
cp config/bpm.conf bpm/$(SYSCONFDIR)/bpm.conf
|
||||
tar --owner=root --group=root -czf bpm.tar.gz bpm
|
||||
rm -r bpm
|
||||
|
||||
run: build/bpm
|
||||
build/bpm
|
||||
|
||||
clean:
|
||||
rm -r build/
|
||||
|
||||
.PHONY: build
|
62
README.md
62
README.md
@ -15,16 +15,15 @@ BPM is still in very early development. It should not be installed on any system
|
||||
|
||||
## Build from source
|
||||
|
||||
- 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
|
||||
```
|
||||
make
|
||||
```
|
||||
- Run the following command to install stormfetch 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
|
||||
```
|
||||
make install PREFIX=/usr SYSCONFDIR=/etc
|
||||
BPM requires go 1.22 or above to be built properly
|
||||
|
||||
```sh
|
||||
git clone https://gitlab.com/bubble-package-manager/bpm.git
|
||||
cd bpm
|
||||
mkdir build
|
||||
go build -o ./build/bpm capcreepergr.me/bpm
|
||||
```
|
||||
You are now able to copy the executable in the ./build directory in a VM or container's /usr/bin/ directory
|
||||
|
||||
## How to use
|
||||
|
||||
@ -51,5 +50,46 @@ bpm help
|
||||
|
||||
## Package Creation
|
||||
|
||||
Package creation is simplified using the bpm-utils package which contains helper scripts for creating and archiving packages. \
|
||||
Learn more here: https://gitlab.com/bubble-package-manager/bpm-utils
|
||||
Creating a package for BPM is simple
|
||||
|
||||
To create a package you need to
|
||||
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!
|
41
bpm_utils/general_utils.go
Normal file
41
bpm_utils/general_utils.go
Normal file
@ -0,0 +1,41 @@
|
||||
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)
|
||||
}
|
854
bpm_utils/package_utils.go
Normal file
854
bpm_utils/package_utils.go
Normal file
@ -0,0 +1,854 @@
|
||||
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 {
|
||||
err := os.RemoveAll(path.Join(installDir, f))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("Removing: " + path.Join(installDir, f))
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
compilation_env: []
|
||||
silent_compilation: false
|
||||
compilation_dir: "/var/tmp/"
|
||||
binary_output_dir: "/var/lib/bpm/compiled/"
|
||||
repositories:
|
||||
- name: example-repository
|
||||
source: https://my-repo.xyz/
|
||||
disabled: true
|
8
go.mod
8
go.mod
@ -1,9 +1,3 @@
|
||||
module gitlab.com/bubble-package-manager/bpm
|
||||
module capcreepergr.me/bpm
|
||||
|
||||
go 1.22
|
||||
|
||||
require (
|
||||
github.com/elliotchance/orderedmap/v2 v2.4.0 // indirect
|
||||
github.com/knqyf263/go-rpm-version v0.0.0-20240918084003-2afd7dc6a38f // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
9
go.sum
9
go.sum
@ -1,9 +0,0 @@
|
||||
github.com/elliotchance/orderedmap/v2 v2.4.0 h1:6tUmMwD9F998FNpwFxA5E6NQvSpk2PVw7RKsVq3+2Cw=
|
||||
github.com/elliotchance/orderedmap/v2 v2.4.0/go.mod h1:85lZyVbpGaGvHvnKa7Qhx7zncAdBIBq6u56Hb1PRU5Q=
|
||||
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
|
||||
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||
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=
|
||||
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=
|
514
main.go
514
main.go
@ -2,9 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"capcreepergr.me/bpm/bpm_utils"
|
||||
"flag"
|
||||
"fmt"
|
||||
"gitlab.com/bubble-package-manager/bpm/utils"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -12,33 +12,26 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
/* -------------BPM | Bubble Package Manager-------------- */
|
||||
/* Made By EnumDev (Previously CapCreeperGR) */
|
||||
/* A simple-to-use package manager */
|
||||
/* ------------------------------------------------------- */
|
||||
/* ---BPM | Bubble Package Manager--- */
|
||||
/* Made By CapCreeperGR */
|
||||
/* A simple-to-use package manager */
|
||||
/* ---------------------------------- */
|
||||
|
||||
var bpmVer = "0.5.0"
|
||||
var bpmVer = "0.1.4"
|
||||
|
||||
var subcommand = "help"
|
||||
var subcommandArgs []string
|
||||
|
||||
// Flags
|
||||
var rootDir = "/"
|
||||
var verbose = false
|
||||
var yesAll = false
|
||||
var buildSource = false
|
||||
var skipCheck = false
|
||||
var keepTempDir = false
|
||||
var force = false
|
||||
var forceInstall = false
|
||||
var pkgListNumbers = false
|
||||
var pkgListNames = false
|
||||
var reinstall = false
|
||||
var reinstallAll = false
|
||||
var noOptional = false
|
||||
var nosync = true
|
||||
|
||||
func main() {
|
||||
utils.ReadConfig()
|
||||
resolveFlags()
|
||||
resolveCommand()
|
||||
}
|
||||
@ -46,14 +39,11 @@ func main() {
|
||||
type commandType uint8
|
||||
|
||||
const (
|
||||
_default commandType = iota
|
||||
help
|
||||
help commandType = iota
|
||||
version
|
||||
info
|
||||
list
|
||||
search
|
||||
install
|
||||
update
|
||||
sync
|
||||
remove
|
||||
file
|
||||
)
|
||||
@ -61,19 +51,13 @@ const (
|
||||
func getCommandType() commandType {
|
||||
switch subcommand {
|
||||
case "version":
|
||||
return _default
|
||||
return version
|
||||
case "info":
|
||||
return info
|
||||
case "list":
|
||||
return list
|
||||
case "search":
|
||||
return search
|
||||
case "install":
|
||||
return install
|
||||
case "update":
|
||||
return update
|
||||
case "sync":
|
||||
return sync
|
||||
case "remove":
|
||||
return remove
|
||||
case "file":
|
||||
@ -85,7 +69,7 @@ func getCommandType() commandType {
|
||||
|
||||
func resolveCommand() {
|
||||
switch getCommandType() {
|
||||
case _default:
|
||||
case version:
|
||||
fmt.Println("Bubble Package Manager (BPM)")
|
||||
fmt.Println("Version: " + bpmVer)
|
||||
case info:
|
||||
@ -95,21 +79,24 @@ func resolveCommand() {
|
||||
return
|
||||
}
|
||||
for n, pkg := range packages {
|
||||
var info *utils.PackageInfo
|
||||
info = utils.GetPackageInfo(pkg, rootDir)
|
||||
info := bpm_utils.GetPackageInfo(pkg, rootDir, false)
|
||||
if info == nil {
|
||||
log.Fatalf("Error: package (%s) is not installed\n", pkg)
|
||||
fmt.Printf("Package (%s) could not be found\n", pkg)
|
||||
continue
|
||||
}
|
||||
fmt.Println("----------------")
|
||||
fmt.Println(utils.CreateReadableInfo(true, true, true, info, rootDir))
|
||||
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*info))
|
||||
if n == len(packages)-1 {
|
||||
fmt.Println("----------------")
|
||||
}
|
||||
}
|
||||
case list:
|
||||
packages, err := utils.GetInstalledPackages(rootDir)
|
||||
packages, err := bpm_utils.GetInstalledPackages(rootDir)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not get installed packages: %s", err.Error())
|
||||
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 {
|
||||
@ -119,280 +106,151 @@ func resolveCommand() {
|
||||
fmt.Println(pkg)
|
||||
}
|
||||
} else {
|
||||
if len(packages) == 0 {
|
||||
fmt.Println("No packages have been installed")
|
||||
return
|
||||
}
|
||||
for n, pkg := range packages {
|
||||
info := utils.GetPackageInfo(pkg, rootDir)
|
||||
info := bpm_utils.GetPackageInfo(pkg, rootDir, false)
|
||||
if info == nil {
|
||||
fmt.Printf("Package (%s) could not be found\n", pkg)
|
||||
continue
|
||||
}
|
||||
fmt.Println("----------------\n" + utils.CreateReadableInfo(true, true, true, info, rootDir))
|
||||
fmt.Print("----------------\n" + bpm_utils.CreateInfoFile(*info))
|
||||
if n == len(packages)-1 {
|
||||
fmt.Println("----------------")
|
||||
}
|
||||
}
|
||||
}
|
||||
case search:
|
||||
searchTerms := subcommandArgs
|
||||
if len(searchTerms) == 0 {
|
||||
log.Fatalf("Error: no search terms given")
|
||||
case install:
|
||||
if os.Getuid() != 0 {
|
||||
fmt.Println("This subcommand needs to be run with superuser permissions")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
for _, term := range searchTerms {
|
||||
nameResults := make([]*utils.PackageInfo, 0)
|
||||
descResults := make([]*utils.PackageInfo, 0)
|
||||
for _, repo := range utils.BPMConfig.Repositories {
|
||||
for _, entry := range repo.Entries {
|
||||
if strings.Contains(entry.Info.Name, term) {
|
||||
nameResults = append(nameResults, entry.Info)
|
||||
} else if strings.Contains(entry.Info.Description, term) {
|
||||
descResults = append(descResults, entry.Info)
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
results := append(nameResults, descResults...)
|
||||
if len(results) == 0 {
|
||||
log.Fatalf("Error: no results for term (%s) were found\n", term)
|
||||
if rootDir != "/" {
|
||||
fmt.Println("Warning: Installing to " + rootDir)
|
||||
}
|
||||
fmt.Printf("Results for term (%s)\n", term)
|
||||
for i, result := range results {
|
||||
fmt.Println("----------------")
|
||||
fmt.Printf("%d) %s: %s (%s)\n", i+1, result.Name, result.Description, result.GetFullVersion())
|
||||
}
|
||||
}
|
||||
case install:
|
||||
if os.Getuid() != 0 {
|
||||
log.Fatalf("Error: this subcommand needs to be run with superuser permissions")
|
||||
}
|
||||
pkgs := subcommandArgs
|
||||
if len(pkgs) == 0 {
|
||||
fmt.Println("No packages or files were given to install")
|
||||
return
|
||||
}
|
||||
|
||||
operation := utils.BPMOperation{
|
||||
Actions: make([]utils.OperationAction, 0),
|
||||
UnresolvedDepends: make([]string, 0),
|
||||
RootDir: rootDir,
|
||||
}
|
||||
|
||||
// Search for packages
|
||||
for _, pkg := range pkgs {
|
||||
if stat, err := os.Stat(pkg); err == nil && !stat.IsDir() {
|
||||
bpmpkg, err := utils.ReadPackage(pkg)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not read package: %s\n", err)
|
||||
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 !reinstall && utils.IsPackageInstalled(bpmpkg.PkgInfo.Name, rootDir) && utils.GetPackageInfo(bpmpkg.PkgInfo.Name, rootDir).GetFullVersion() == bpmpkg.PkgInfo.GetFullVersion() {
|
||||
}
|
||||
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
|
||||
}
|
||||
operation.Actions = append(operation.Actions, &utils.InstallPackageAction{
|
||||
File: pkg,
|
||||
IsDependency: false,
|
||||
BpmPackage: bpmpkg,
|
||||
})
|
||||
} else {
|
||||
entry, _, err := utils.GetRepositoryEntry(pkg)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not find package (%s) in any repository\n", pkg)
|
||||
}
|
||||
if !reinstall && utils.IsPackageInstalled(entry.Info.Name, rootDir) && utils.GetPackageInfo(entry.Info.Name, rootDir).GetFullVersion() == entry.Info.GetFullVersion() {
|
||||
continue
|
||||
}
|
||||
operation.Actions = append(operation.Actions, &utils.FetchPackageAction{
|
||||
IsDependency: false,
|
||||
RepositoryEntry: entry,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve dependencies
|
||||
err := operation.ResolveDependencies(reinstallAll, !noOptional, verbose)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not resolve dependencies: %s\n", err)
|
||||
}
|
||||
if len(operation.UnresolvedDepends) != 0 {
|
||||
if !force {
|
||||
log.Fatalf("Error: the following dependencies could not be found in any repositories: %s\n", strings.Join(operation.UnresolvedDepends, ", "))
|
||||
} else {
|
||||
log.Println("Warning: The following dependencies could not be found in any repositories: " + strings.Join(operation.UnresolvedDepends, ", "))
|
||||
}
|
||||
}
|
||||
|
||||
// Show operation summary
|
||||
operation.ShowOperationSummary()
|
||||
|
||||
// Confirmation Prompt
|
||||
if !yesAll {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
if len(operation.Actions) == 1 {
|
||||
fmt.Printf("Do you wish to install this package? [y\\N] ")
|
||||
} else {
|
||||
fmt.Printf("Do you wish to install these %d packages? [y\\N] ", len(operation.Actions))
|
||||
}
|
||||
|
||||
text, _ := reader.ReadString('\n')
|
||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
||||
fmt.Println("Cancelling package installation...")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Execute operation
|
||||
err = operation.Execute(verbose, force)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not complete operation: %s\n", err)
|
||||
}
|
||||
case update:
|
||||
if os.Getuid() != 0 {
|
||||
log.Fatalf("Error: this subcommand needs to be run with superuser permissions")
|
||||
}
|
||||
|
||||
// Sync repositories
|
||||
if !nosync {
|
||||
for _, repo := range utils.BPMConfig.Repositories {
|
||||
fmt.Printf("Fetching package database for repository (%s)...\n", repo.Name)
|
||||
err := repo.SyncLocalDatabase()
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not sync local database for repository (%s): %s\n", repo.Name, err)
|
||||
}
|
||||
}
|
||||
fmt.Println("All package databases synced successfully!")
|
||||
}
|
||||
|
||||
utils.ReadConfig()
|
||||
|
||||
// Get installed packages and check for updates
|
||||
pkgs, err := utils.GetInstalledPackages(rootDir)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not get installed packages: %s\n", err)
|
||||
}
|
||||
|
||||
operation := utils.BPMOperation{
|
||||
Actions: make([]utils.OperationAction, 0),
|
||||
UnresolvedDepends: make([]string, 0),
|
||||
RootDir: rootDir,
|
||||
}
|
||||
|
||||
// Search for packages
|
||||
for _, pkg := range pkgs {
|
||||
entry, _, err := utils.GetRepositoryEntry(pkg)
|
||||
err = bpm_utils.InstallPackage(file, rootDir, forceInstall, buildSource, keepTempDir)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
installedInfo := utils.GetPackageInfo(pkg, rootDir)
|
||||
if installedInfo == nil {
|
||||
log.Fatalf("Error: could not get package info for (%s)\n", pkg)
|
||||
} else {
|
||||
comparison := utils.ComparePackageVersions(*entry.Info, *installedInfo)
|
||||
if comparison > 0 || reinstall {
|
||||
operation.Actions = append(operation.Actions, &utils.FetchPackageAction{
|
||||
IsDependency: false,
|
||||
RepositoryEntry: entry,
|
||||
})
|
||||
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 **")
|
||||
}
|
||||
}
|
||||
|
||||
// Check for new dependencies in updated packages
|
||||
err = operation.ResolveDependencies(reinstallAll, !noOptional, verbose)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not resolve dependencies: %s\n", err)
|
||||
}
|
||||
if len(operation.UnresolvedDepends) != 0 {
|
||||
if !force {
|
||||
log.Fatalf("Error: the following dependencies could not be found in any repositories: %s\n", strings.Join(operation.UnresolvedDepends, ", "))
|
||||
} else {
|
||||
log.Println("Warning: The following dependencies could not be found in any repositories: " + strings.Join(operation.UnresolvedDepends, ", "))
|
||||
}
|
||||
}
|
||||
|
||||
// Show operation summary
|
||||
operation.ShowOperationSummary()
|
||||
|
||||
// Confirmation Prompt
|
||||
if !yesAll {
|
||||
fmt.Printf("Are you sure you wish to update all %d packages? [y\\N] ", len(operation.Actions))
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
text, _ := reader.ReadString('\n')
|
||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
||||
fmt.Println("Cancelling package update...")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Execute operation
|
||||
err = operation.Execute(verbose, force)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not complete operation: %s\n", err)
|
||||
}
|
||||
case sync:
|
||||
if os.Getuid() != 0 {
|
||||
log.Fatalf("Error: this subcommand needs to be run with superuser permissions")
|
||||
}
|
||||
if !yesAll {
|
||||
fmt.Printf("Are you sure you wish to sync all databases? [y\\N] ")
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
text, _ := reader.ReadString('\n')
|
||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
||||
fmt.Println("Cancelling database synchronization...")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
for _, repo := range utils.BPMConfig.Repositories {
|
||||
fmt.Printf("Fetching package database for repository (%s)...\n", repo.Name)
|
||||
err := repo.SyncLocalDatabase()
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not sync local database for repository (%s): %s\n", repo.Name, err)
|
||||
}
|
||||
}
|
||||
fmt.Println("All package databases synced successfully!")
|
||||
case remove:
|
||||
if os.Getuid() != 0 {
|
||||
log.Fatalf("Error: this subcommand needs to be run with superuser permissions")
|
||||
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
|
||||
}
|
||||
|
||||
operation := &utils.BPMOperation{
|
||||
Actions: make([]utils.OperationAction, 0),
|
||||
UnresolvedDepends: make([]string, 0),
|
||||
RootDir: rootDir,
|
||||
}
|
||||
|
||||
// Search for packages
|
||||
for _, pkg := range packages {
|
||||
bpmpkg := utils.GetPackage(pkg, rootDir)
|
||||
if bpmpkg == nil {
|
||||
log.Fatalf("Error: package (%s) could not be found\n", pkg)
|
||||
pkgInfo := bpm_utils.GetPackageInfo(pkg, rootDir, false)
|
||||
if pkgInfo == nil {
|
||||
fmt.Printf("Package (%s) could not be found\n", pkg)
|
||||
continue
|
||||
}
|
||||
operation.Actions = append(operation.Actions, &utils.RemovePackageAction{BpmPackage: bpmpkg})
|
||||
}
|
||||
|
||||
// Show operation summary
|
||||
operation.ShowOperationSummary()
|
||||
|
||||
// Confirmation Prompt
|
||||
if !yesAll {
|
||||
fmt.Printf("Are you sure you wish to remove all %d packages? [y\\N] ", len(operation.Actions))
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
text, _ := reader.ReadString('\n')
|
||||
if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" {
|
||||
fmt.Println("Cancelling package removal...")
|
||||
os.Exit(1)
|
||||
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)
|
||||
|
||||
// Execute operation
|
||||
err := operation.Execute(verbose, force)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not complete operation: %s\n", err)
|
||||
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
|
||||
@ -403,23 +261,23 @@ func resolveCommand() {
|
||||
for _, file := range files {
|
||||
absFile, err := filepath.Abs(file)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not get absolute path of file (%s)\n", file)
|
||||
log.Fatalf("Could not get absolute path of %s", file)
|
||||
}
|
||||
stat, err := os.Stat(absFile)
|
||||
if os.IsNotExist(err) {
|
||||
log.Fatalf("Error: file (%s) does not exist!\n", absFile)
|
||||
log.Fatalf(absFile + " does not exist!")
|
||||
}
|
||||
pkgs, err := utils.GetInstalledPackages(rootDir)
|
||||
pkgs, err := bpm_utils.GetInstalledPackages(rootDir)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not get installed packages: %s\n", err.Error())
|
||||
log.Fatalf("Could not get installed packages. Error %s", err.Error())
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(absFile, rootDir) {
|
||||
log.Fatalf("Error: could not get path of file (%s) relative to root path", absFile)
|
||||
log.Fatalf("Could not get relative path of %s to root path", absFile)
|
||||
}
|
||||
absFile, err = filepath.Rel(rootDir, absFile)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: could not get path of file (%s) relative to root path", absFile)
|
||||
log.Fatalf("Could not get relative path of %s to root path", absFile)
|
||||
}
|
||||
absFile = strings.TrimPrefix(absFile, "/")
|
||||
if stat.IsDir() {
|
||||
@ -428,9 +286,7 @@ func resolveCommand() {
|
||||
|
||||
var pkgList []string
|
||||
for _, pkg := range pkgs {
|
||||
if slices.ContainsFunc(utils.GetPackageFiles(pkg, rootDir), func(entry *utils.PackageFileEntry) bool {
|
||||
return entry.Path == absFile
|
||||
}) {
|
||||
if slices.Contains(bpm_utils.GetPackageFiles(pkg, rootDir), absFile) {
|
||||
pkgList = append(pkgList, pkg)
|
||||
}
|
||||
}
|
||||
@ -449,44 +305,26 @@ func resolveCommand() {
|
||||
}
|
||||
|
||||
func printHelp() {
|
||||
fmt.Println("\033[1m---- Command Format ----\033[0m")
|
||||
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("\033[1m\\ Command List /\033[0m")
|
||||
fmt.Println("-> bpm version | shows information on the installed version of bpm")
|
||||
fmt.Println("-> bpm info [-R] <packages...> | shows information on an installed package")
|
||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||
fmt.Println("-> bpm list [-R, -c, -n] | lists all installed packages")
|
||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||
fmt.Println(" -c lists the amount of installed packages")
|
||||
fmt.Println(" -n lists only the names of installed packages")
|
||||
fmt.Println("-> bpm search <search terms...> | Searches for packages through declared repositories")
|
||||
fmt.Println("-> bpm install [-R, -v, -y, -f, -o, -c, -b, -k, --reinstall, --reinstall-all, --no-optional] <packages...> | installs the following files")
|
||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||
fmt.Println(" -v Show additional information about what BPM is doing")
|
||||
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, conflict and architecture checking")
|
||||
fmt.Println(" -o=<path> set the binary package output directory (defaults to /var/lib/bpm/compiled)")
|
||||
fmt.Println(" -c=<path> set the compilation directory (defaults to /var/tmp)")
|
||||
fmt.Println(" -b creates a binary package from a source package after compilation and saves it in the binary package output directory")
|
||||
fmt.Println(" -k keeps the compilation directory created by BPM after source package installation")
|
||||
fmt.Println(" --reinstall Reinstalls packages even if they do not have a newer version available")
|
||||
fmt.Println(" --reinstall-all Same as --reinstall but also reinstalls dependencies")
|
||||
fmt.Println(" --no-optional Prevents installation of optional dependencies")
|
||||
fmt.Println("-> bpm update [-R, -v, -y, -f, --reinstall, --no-sync] | updates all packages that are available in the repositories")
|
||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||
fmt.Println(" -v Show additional information about what BPM is doing")
|
||||
fmt.Println(" -y skips the confirmation prompt")
|
||||
fmt.Println(" -f skips dependency, conflict and architecture checking")
|
||||
fmt.Println(" --reinstall Fetches and reinstalls all packages even if they do not have a newer version available")
|
||||
fmt.Println(" --no-sync Skips package database syncing")
|
||||
fmt.Println("-> bpm sync [-R, -v, -y] | Syncs package databases without updating packages")
|
||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||
fmt.Println(" -v Show additional information about what BPM is doing")
|
||||
fmt.Println(" -y skips the confirmation prompt")
|
||||
fmt.Println("-> bpm remove [-R, -v, -y] <packages...> | removes the following packages")
|
||||
fmt.Println(" -v Show additional information about what BPM is doing")
|
||||
fmt.Println(" -R=<path> lets you define the root path which will be used")
|
||||
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")
|
||||
@ -498,8 +336,9 @@ func resolveFlags() {
|
||||
listFlagSet := flag.NewFlagSet("List flags", flag.ExitOnError)
|
||||
listFlagSet.Usage = printHelp
|
||||
listFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||
listFlagSet.BoolVar(&pkgListNumbers, "c", false, "List the number of all packages installed with BPM")
|
||||
listFlagSet.BoolVar(&pkgListNames, "n", false, "List the names of all packages installed with BPM")
|
||||
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")
|
||||
@ -507,40 +346,18 @@ func resolveFlags() {
|
||||
// Install flags
|
||||
installFlagSet := flag.NewFlagSet("Install flags", flag.ExitOnError)
|
||||
installFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||
installFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing")
|
||||
installFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||
installFlagSet.StringVar(&utils.BPMConfig.BinaryOutputDir, "o", utils.BPMConfig.BinaryOutputDir, "Set the binary output directory")
|
||||
installFlagSet.StringVar(&utils.BPMConfig.CompilationDir, "c", utils.BPMConfig.CompilationDir, "Set the compilation directory")
|
||||
installFlagSet.BoolVar(&buildSource, "b", false, "Build binary package from source package")
|
||||
installFlagSet.BoolVar(&skipCheck, "s", false, "Skip check function during source compilation")
|
||||
installFlagSet.BoolVar(&keepTempDir, "k", false, "Keep temporary directory after source compilation")
|
||||
installFlagSet.BoolVar(&force, "f", false, "Force installation by skipping architecture and dependency resolution")
|
||||
installFlagSet.BoolVar(&reinstall, "reinstall", false, "Reinstalls packages even if they do not have a newer version available")
|
||||
installFlagSet.BoolVar(&reinstallAll, "reinstall-all", false, "Same as --reinstall but also reinstalls dependencies")
|
||||
installFlagSet.BoolVar(&noOptional, "no-optional", false, "Prevents installation of optional dependencies")
|
||||
installFlagSet.BoolVar(&forceInstall, "f", false, "Force installation by skipping architecture and dependency resolution")
|
||||
installFlagSet.Usage = printHelp
|
||||
// Update flags
|
||||
updateFlagSet := flag.NewFlagSet("Update flags", flag.ExitOnError)
|
||||
updateFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||
updateFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing")
|
||||
updateFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||
updateFlagSet.BoolVar(&force, "f", false, "Force update by skipping architecture and dependency resolution")
|
||||
updateFlagSet.BoolVar(&reinstall, "reinstall", false, "Fetches and reinstalls all packages even if they do not have a newer version available")
|
||||
updateFlagSet.BoolVar(&nosync, "no-sync", false, "Skips package database syncing")
|
||||
updateFlagSet.Usage = printHelp
|
||||
// Sync flags
|
||||
syncFlagSet := flag.NewFlagSet("Sync flags", flag.ExitOnError)
|
||||
syncFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||
syncFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing")
|
||||
syncFlagSet.BoolVar(&yesAll, "y", false, "Skip confirmation prompts")
|
||||
syncFlagSet.Usage = printHelp
|
||||
// Remove flags
|
||||
removeFlagSet := flag.NewFlagSet("Remove flags", flag.ExitOnError)
|
||||
removeFlagSet.StringVar(&rootDir, "R", "/", "Set the destination root")
|
||||
removeFlagSet.BoolVar(&verbose, "v", false, "Show additional information about what BPM is doing")
|
||||
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
|
||||
@ -567,18 +384,6 @@ func resolveFlags() {
|
||||
return
|
||||
}
|
||||
subcommandArgs = installFlagSet.Args()
|
||||
} else if getCommandType() == update {
|
||||
err := updateFlagSet.Parse(subcommandArgs)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
subcommandArgs = updateFlagSet.Args()
|
||||
} else if getCommandType() == sync {
|
||||
err := syncFlagSet.Parse(subcommandArgs)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
subcommandArgs = syncFlagSet.Args()
|
||||
} else if getCommandType() == remove {
|
||||
err := removeFlagSet.Parse(subcommandArgs)
|
||||
if err != nil {
|
||||
@ -592,8 +397,5 @@ func resolveFlags() {
|
||||
}
|
||||
subcommandArgs = fileFlagSet.Args()
|
||||
}
|
||||
if reinstallAll {
|
||||
reinstall = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
BIN
test_packages/x86_64/bpm-utils/bpm-utils.bpm
Normal file
BIN
test_packages/x86_64/bpm-utils/bpm-utils.bpm
Normal file
Binary file not shown.
51
test_packages/x86_64/bpm-utils/files/usr/bin/bpm-create
Executable file
51
test_packages/x86_64/bpm-utils/files/usr/bin/bpm-create
Executable file
@ -0,0 +1,51 @@
|
||||
#!/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
|
66
test_packages/x86_64/bpm-utils/files/usr/bin/bpm-setup
Executable file
66
test_packages/x86_64/bpm-utils/files/usr/bin/bpm-setup
Executable file
@ -0,0 +1,66 @@
|
||||
#!/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
|
7
test_packages/x86_64/bpm-utils/pkg.info
Normal file
7
test_packages/x86_64/bpm-utils/pkg.info
Normal file
@ -0,0 +1,7 @@
|
||||
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
|
BIN
test_packages/x86_64/bpm/bpm.bpm
Normal file
BIN
test_packages/x86_64/bpm/bpm.bpm
Normal file
Binary file not shown.
BIN
test_packages/x86_64/bpm/files/usr/bin/bpm
Executable file
BIN
test_packages/x86_64/bpm/files/usr/bin/bpm
Executable file
Binary file not shown.
7
test_packages/x86_64/bpm/pkg.info
Normal file
7
test_packages/x86_64/bpm/pkg.info
Normal file
@ -0,0 +1,7 @@
|
||||
name: bpm
|
||||
description: The Bubble Package Manager
|
||||
version: 0.1.4
|
||||
url: https://gitlab.com/bubble-package-manager/bpm/
|
||||
license: GPL3
|
||||
architecture: x86_64
|
||||
type: binary
|
BIN
test_packages/x86_64/hello/files/usr/bin/hello
Executable file
BIN
test_packages/x86_64/hello/files/usr/bin/hello
Executable file
Binary file not shown.
BIN
test_packages/x86_64/hello/hello.bpm
Normal file
BIN
test_packages/x86_64/hello/hello.bpm
Normal file
Binary file not shown.
5
test_packages/x86_64/hello/pkg.info
Normal file
5
test_packages/x86_64/hello/pkg.info
Normal file
@ -0,0 +1,5 @@
|
||||
name: hello
|
||||
description: A simple hello world program
|
||||
version: 1.0
|
||||
architecture: x86_64
|
||||
type: binary
|
BIN
test_packages/x86_64/htop-src/htop-src.bpm
Normal file
BIN
test_packages/x86_64/htop-src/htop-src.bpm
Normal file
Binary file not shown.
8
test_packages/x86_64/htop-src/pkg.info
Normal file
8
test_packages/x86_64/htop-src/pkg.info
Normal file
@ -0,0 +1,8 @@
|
||||
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
|
20
test_packages/x86_64/htop-src/source.sh
Normal file
20
test_packages/x86_64/htop-src/source.sh
Normal file
@ -0,0 +1,20 @@
|
||||
# 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!"
|
@ -1,49 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"gopkg.in/yaml.v3"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
type BPMConfigStruct struct {
|
||||
CompilationEnv []string `yaml:"compilation_env"`
|
||||
SilentCompilation bool `yaml:"silent_compilation"`
|
||||
BinaryOutputDir string `yaml:"binary_output_dir"`
|
||||
CompilationDir string `yaml:"compilation_dir"`
|
||||
Repositories []*Repository `yaml:"repositories"`
|
||||
}
|
||||
|
||||
var BPMConfig BPMConfigStruct
|
||||
|
||||
func ReadConfig() {
|
||||
if _, err := os.Stat("/etc/bpm.conf"); os.IsNotExist(err) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
bytes, err := os.ReadFile("/etc/bpm.conf")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
BPMConfig = BPMConfigStruct{
|
||||
CompilationEnv: make([]string, 0),
|
||||
SilentCompilation: false,
|
||||
BinaryOutputDir: "/var/lib/bpm/compiled/",
|
||||
CompilationDir: "/var/tmp/",
|
||||
}
|
||||
err = yaml.Unmarshal(bytes, &BPMConfig)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for i := len(BPMConfig.Repositories) - 1; i >= 0; i-- {
|
||||
if BPMConfig.Repositories[i].Disabled != nil && *BPMConfig.Repositories[i].Disabled {
|
||||
BPMConfig.Repositories = append(BPMConfig.Repositories[:i], BPMConfig.Repositories[i+1:]...)
|
||||
}
|
||||
}
|
||||
for _, repo := range BPMConfig.Repositories {
|
||||
repo.Entries = make(map[string]*RepositoryEntry)
|
||||
err := repo.ReadLocalDatabase()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
type TarballFileReader struct {
|
||||
tarReader *tar.Reader
|
||||
file *os.File
|
||||
}
|
||||
|
||||
func ReadTarballContent(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")
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func GetArch() string {
|
||||
uname := syscall.Utsname{}
|
||||
err := syscall.Uname(&uname)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
var byteString [65]byte
|
||||
var indexLength int
|
||||
for ; uname.Machine[indexLength] != 0; indexLength++ {
|
||||
byteString[indexLength] = uint8(uname.Machine[indexLength])
|
||||
}
|
||||
return string(byteString[:indexLength])
|
||||
}
|
||||
|
||||
func copyFileContents(src, dst string) (err error) {
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer in.Close()
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
cerr := out.Close()
|
||||
if err == nil {
|
||||
err = cerr
|
||||
}
|
||||
}()
|
||||
if _, err = io.Copy(out, in); err != nil {
|
||||
return
|
||||
}
|
||||
err = out.Sync()
|
||||
return
|
||||
}
|
||||
|
||||
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 UnsignedBytesToHumanReadable(b uint64) 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 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)
|
||||
}
|
@ -1,289 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type BPMOperation struct {
|
||||
Actions []OperationAction
|
||||
UnresolvedDepends []string
|
||||
RootDir string
|
||||
}
|
||||
|
||||
func (operation *BPMOperation) ActionsContainPackage(pkg string) bool {
|
||||
for _, action := range operation.Actions {
|
||||
if action.GetActionType() == "install" {
|
||||
if action.(*InstallPackageAction).BpmPackage.PkgInfo.Name == pkg {
|
||||
return true
|
||||
}
|
||||
} else if action.GetActionType() == "fetch" {
|
||||
if action.(*FetchPackageAction).RepositoryEntry.Info.Name == pkg {
|
||||
return true
|
||||
}
|
||||
} else if action.GetActionType() == "remove" {
|
||||
if action.(*RemovePackageAction).BpmPackage.PkgInfo.Name == pkg {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (operation *BPMOperation) InsertActionAt(index int, action OperationAction) {
|
||||
if len(operation.Actions) == index { // nil or empty slice or after last element
|
||||
operation.Actions = append(operation.Actions, action)
|
||||
}
|
||||
operation.Actions = append(operation.Actions[:index+1], operation.Actions[index:]...) // index < len(a)
|
||||
operation.Actions[index] = action
|
||||
}
|
||||
|
||||
func (operation *BPMOperation) GetTotalDownloadSize() uint64 {
|
||||
var ret uint64 = 0
|
||||
for _, action := range operation.Actions {
|
||||
if action.GetActionType() == "fetch" {
|
||||
ret += action.(*FetchPackageAction).RepositoryEntry.DownloadSize
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (operation *BPMOperation) GetTotalInstalledSize() uint64 {
|
||||
var ret uint64 = 0
|
||||
for _, action := range operation.Actions {
|
||||
if action.GetActionType() == "install" {
|
||||
ret += action.(*InstallPackageAction).BpmPackage.GetInstalledSize()
|
||||
} else if action.GetActionType() == "fetch" {
|
||||
ret += action.(*FetchPackageAction).RepositoryEntry.InstalledSize
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (operation *BPMOperation) GetFinalActionSize(rootDir string) int64 {
|
||||
var ret int64 = 0
|
||||
for _, action := range operation.Actions {
|
||||
if action.GetActionType() == "install" {
|
||||
ret += int64(action.(*InstallPackageAction).BpmPackage.GetInstalledSize())
|
||||
if IsPackageInstalled(action.(*InstallPackageAction).BpmPackage.PkgInfo.Name, rootDir) {
|
||||
ret -= int64(GetPackage(action.(*InstallPackageAction).BpmPackage.PkgInfo.Name, rootDir).GetInstalledSize())
|
||||
}
|
||||
} else if action.GetActionType() == "fetch" {
|
||||
ret += int64(action.(*FetchPackageAction).RepositoryEntry.InstalledSize)
|
||||
} else if action.GetActionType() == "remove" {
|
||||
ret -= int64(action.(*RemovePackageAction).BpmPackage.GetInstalledSize())
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (operation *BPMOperation) ResolveDependencies(reinstallDependencies, installOptionalDependencies, verbose bool) error {
|
||||
pos := 0
|
||||
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.RepositoryEntry.Info
|
||||
} else {
|
||||
pos++
|
||||
continue
|
||||
}
|
||||
|
||||
resolved, unresolved := pkgInfo.ResolveDependencies(&[]string{}, &[]string{}, pkgInfo.Type == "source", installOptionalDependencies, !reinstallDependencies, verbose, operation.RootDir)
|
||||
|
||||
operation.UnresolvedDepends = append(operation.UnresolvedDepends, unresolved...)
|
||||
|
||||
for _, depend := range resolved {
|
||||
if !operation.ActionsContainPackage(depend) && depend != pkgInfo.Name {
|
||||
if !reinstallDependencies && IsPackageInstalled(depend, operation.RootDir) {
|
||||
continue
|
||||
}
|
||||
entry, _, err := GetRepositoryEntry(depend)
|
||||
if err != nil {
|
||||
return errors.New("could not get repository entry for package (" + depend + ")")
|
||||
}
|
||||
operation.InsertActionAt(pos, &FetchPackageAction{
|
||||
IsDependency: true,
|
||||
RepositoryEntry: entry,
|
||||
})
|
||||
pos++
|
||||
}
|
||||
}
|
||||
pos++
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (operation *BPMOperation) ShowOperationSummary() {
|
||||
if len(operation.Actions) == 0 {
|
||||
fmt.Println("All packages are up to date!")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
for _, value := range operation.Actions {
|
||||
var pkgInfo *PackageInfo
|
||||
if value.GetActionType() == "install" {
|
||||
pkgInfo = value.(*InstallPackageAction).BpmPackage.PkgInfo
|
||||
} else if value.GetActionType() == "fetch" {
|
||||
pkgInfo = value.(*FetchPackageAction).RepositoryEntry.Info
|
||||
} else {
|
||||
pkgInfo = value.(*RemovePackageAction).BpmPackage.PkgInfo
|
||||
fmt.Printf("%s: %s (Remove)\n", pkgInfo.Name, pkgInfo.GetFullVersion())
|
||||
continue
|
||||
}
|
||||
|
||||
installedInfo := GetPackageInfo(pkgInfo.Name, operation.RootDir)
|
||||
sourceInfo := ""
|
||||
if pkgInfo.Type == "source" {
|
||||
if operation.RootDir != "/" {
|
||||
log.Fatalf("cannot compile and install source packages to a different root directory")
|
||||
}
|
||||
sourceInfo = "(From Source)"
|
||||
}
|
||||
|
||||
if installedInfo == nil {
|
||||
fmt.Printf("%s: %s (Install) %s\n", pkgInfo.Name, pkgInfo.GetFullVersion(), sourceInfo)
|
||||
} else {
|
||||
comparison := ComparePackageVersions(*pkgInfo, *installedInfo)
|
||||
if comparison < 0 {
|
||||
fmt.Printf("%s: %s -> %s (Downgrade) %s\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), sourceInfo)
|
||||
} else if comparison > 0 {
|
||||
fmt.Printf("%s: %s -> %s (Upgrade) %s\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), sourceInfo)
|
||||
} else {
|
||||
fmt.Printf("%s: %s (Reinstall) %s\n", pkgInfo.Name, pkgInfo.GetFullVersion(), sourceInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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", UnsignedBytesToHumanReadable(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) Execute(verbose, force bool) error {
|
||||
// Fetch packages from repositories
|
||||
if slices.ContainsFunc(operation.Actions, func(action OperationAction) bool {
|
||||
return action.GetActionType() == "fetch"
|
||||
}) {
|
||||
fmt.Println("Fetching packages from available repositories...")
|
||||
for i, action := range operation.Actions {
|
||||
if action.GetActionType() != "fetch" {
|
||||
continue
|
||||
}
|
||||
entry := action.(*FetchPackageAction).RepositoryEntry
|
||||
fetchedPackage, err := entry.Repository.FetchPackage(entry.Info.Name)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("could not fetch package (%s): %s\n", entry.Info.Name, err))
|
||||
}
|
||||
bpmpkg, err := ReadPackage(fetchedPackage)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("could not fetch package (%s): %s\n", entry.Info.Name, err))
|
||||
}
|
||||
fmt.Printf("Package (%s) was successfully fetched!\n", bpmpkg.PkgInfo.Name)
|
||||
operation.Actions[i] = &InstallPackageAction{
|
||||
File: fetchedPackage,
|
||||
IsDependency: action.(*FetchPackageAction).IsDependency,
|
||||
BpmPackage: bpmpkg,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 errors.New(fmt.Sprintf("could not remove package (%s): %s\n", pkgInfo.Name, err))
|
||||
}
|
||||
} else if action.GetActionType() == "install" {
|
||||
value := action.(*InstallPackageAction)
|
||||
bpmpkg := value.BpmPackage
|
||||
var err error
|
||||
if value.IsDependency {
|
||||
err = InstallPackage(value.File, operation.RootDir, verbose, true, false, false, false)
|
||||
} else {
|
||||
err = InstallPackage(value.File, operation.RootDir, verbose, force, false, false, false)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("could not install package (%s): %s\n", bpmpkg.PkgInfo.Name, err))
|
||||
}
|
||||
fmt.Printf("Package (%s) was successfully installed\n", bpmpkg.PkgInfo.Name)
|
||||
if value.IsDependency {
|
||||
err := SetInstallationReason(bpmpkg.PkgInfo.Name, Dependency, operation.RootDir)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("could not set installation reason for package (%s): %s\n", value.BpmPackage.PkgInfo.Name, err))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Println("Operation complete!")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type OperationAction interface {
|
||||
GetActionType() string
|
||||
}
|
||||
|
||||
type InstallPackageAction struct {
|
||||
File string
|
||||
IsDependency bool
|
||||
BpmPackage *BPMPackage
|
||||
}
|
||||
|
||||
func (action *InstallPackageAction) GetActionType() string {
|
||||
return "install"
|
||||
}
|
||||
|
||||
type FetchPackageAction struct {
|
||||
IsDependency bool
|
||||
RepositoryEntry *RepositoryEntry
|
||||
}
|
||||
|
||||
func (action *FetchPackageAction) GetActionType() string {
|
||||
return "fetch"
|
||||
}
|
||||
|
||||
type RemovePackageAction struct {
|
||||
BpmPackage *BPMPackage
|
||||
}
|
||||
|
||||
func (action *RemovePackageAction) GetActionType() string {
|
||||
return "remove"
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,197 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gopkg.in/yaml.v3"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Repository struct {
|
||||
Name string `yaml:"name"`
|
||||
Source string `yaml:"source"`
|
||||
Disabled *bool `yaml:"disabled"`
|
||||
Entries map[string]*RepositoryEntry
|
||||
}
|
||||
|
||||
type RepositoryEntry struct {
|
||||
Info *PackageInfo `yaml:"info"`
|
||||
Download string `yaml:"download"`
|
||||
DownloadSize uint64 `yaml:"download_size"`
|
||||
InstalledSize uint64 `yaml:"installed_size"`
|
||||
IsVirtualPackage bool `yaml:"-"`
|
||||
Repository *Repository
|
||||
}
|
||||
|
||||
func (repo *Repository) ContainsPackage(pkg string) bool {
|
||||
_, ok := repo.Entries[pkg]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (repo *Repository) ReadLocalDatabase() error {
|
||||
repoFile := "/var/lib/bpm/repositories/" + repo.Name + ".bpmdb"
|
||||
if _, err := os.Stat(repoFile); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
bytes, err := os.ReadFile(repoFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
virtualPackages := make(map[string][]string)
|
||||
|
||||
data := string(bytes)
|
||||
for _, b := range strings.Split(data, "---") {
|
||||
entry := RepositoryEntry{
|
||||
Info: &PackageInfo{
|
||||
Name: "",
|
||||
Description: "",
|
||||
Version: "",
|
||||
Revision: 1,
|
||||
Url: "",
|
||||
License: "",
|
||||
Arch: "",
|
||||
Type: "",
|
||||
Keep: make([]string, 0),
|
||||
Depends: make([]string, 0),
|
||||
MakeDepends: make([]string, 0),
|
||||
OptionalDepends: make([]string, 0),
|
||||
Conflicts: make([]string, 0),
|
||||
Provides: make([]string, 0),
|
||||
},
|
||||
Download: "",
|
||||
DownloadSize: 0,
|
||||
InstalledSize: 0,
|
||||
IsVirtualPackage: false,
|
||||
Repository: repo,
|
||||
}
|
||||
err := yaml.Unmarshal([]byte(b), &entry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, p := range entry.Info.Provides {
|
||||
virtualPackages[p] = append(virtualPackages[p], entry.Info.Name)
|
||||
}
|
||||
repo.Entries[entry.Info.Name] = &entry
|
||||
}
|
||||
|
||||
for key, value := range virtualPackages {
|
||||
if _, ok := repo.Entries[key]; ok {
|
||||
continue
|
||||
}
|
||||
sort.Strings(value)
|
||||
entry := RepositoryEntry{
|
||||
Info: repo.Entries[value[0]].Info,
|
||||
Download: repo.Entries[value[0]].Download,
|
||||
DownloadSize: repo.Entries[value[0]].DownloadSize,
|
||||
InstalledSize: repo.Entries[value[0]].InstalledSize,
|
||||
IsVirtualPackage: true,
|
||||
Repository: repo,
|
||||
}
|
||||
repo.Entries[key] = &entry
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *Repository) SyncLocalDatabase() error {
|
||||
repoFile := "/var/lib/bpm/repositories/" + repo.Name + ".bpmdb"
|
||||
err := os.MkdirAll(path.Dir(repoFile), 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
u, err := url.JoinPath(repo.Source, "database.bpmdb")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := http.Get(u)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
out, err := os.Create(repoFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
_, err = io.Copy(out, resp.Body)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetRepository(name string) *Repository {
|
||||
for _, repo := range BPMConfig.Repositories {
|
||||
if repo.Name == name {
|
||||
return repo
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetRepositoryEntry(str string) (*RepositoryEntry, *Repository, error) {
|
||||
split := strings.Split(str, "/")
|
||||
if len(split) == 1 {
|
||||
pkgName := strings.TrimSpace(split[0])
|
||||
if pkgName == "" {
|
||||
return nil, nil, errors.New("could not find repository entry for this package")
|
||||
}
|
||||
for _, repo := range BPMConfig.Repositories {
|
||||
if repo.ContainsPackage(pkgName) {
|
||||
return repo.Entries[pkgName], repo, nil
|
||||
}
|
||||
}
|
||||
return nil, nil, errors.New("could not find repository entry for this package")
|
||||
} else if len(split) == 2 {
|
||||
repoName := strings.TrimSpace(split[0])
|
||||
pkgName := strings.TrimSpace(split[1])
|
||||
if repoName == "" || pkgName == "" {
|
||||
return nil, nil, errors.New("could not find repository entry for this package")
|
||||
}
|
||||
repo := GetRepository(repoName)
|
||||
if repo == nil || !repo.ContainsPackage(pkgName) {
|
||||
return nil, nil, errors.New("could not find repository entry for this package")
|
||||
}
|
||||
return repo.Entries[pkgName], repo, nil
|
||||
} else {
|
||||
return nil, nil, errors.New("could not find repository entry for this package")
|
||||
}
|
||||
}
|
||||
|
||||
func (repo *Repository) FetchPackage(pkg string) (string, error) {
|
||||
if !repo.ContainsPackage(pkg) {
|
||||
return "", errors.New("could not fetch package '" + pkg + "'")
|
||||
}
|
||||
entry := repo.Entries[pkg]
|
||||
URL, err := url.JoinPath(repo.Source, entry.Download)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
resp, err := http.Get(URL)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
err = os.MkdirAll("/var/cache/bpm/packages/", 0755)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
out, err := os.Create("/var/cache/bpm/packages/" + path.Base(entry.Download))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
_, err = io.Copy(out, resp.Body)
|
||||
return "/var/cache/bpm/packages/" + path.Base(entry.Download), nil
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user