Compare commits
No commits in common. "packaging" and "main" have entirely different histories.
45 changed files with 5412 additions and 152 deletions
15
.gitignore
vendored
15
.gitignore
vendored
|
@ -1,9 +1,6 @@
|
||||||
*
|
/blend-settings/node_modules/
|
||||||
|
/blend-settings/build/
|
||||||
!.gitignore
|
/blend-settings/dist/
|
||||||
!PKGBUILD
|
/blend-settings/package-lock.json
|
||||||
!blend.sh
|
*.o
|
||||||
!blend-settings
|
/overlayfs-tools/overlayfs-tools
|
||||||
!blend-settings.desktop
|
|
||||||
!blend-package-installer.desktop
|
|
||||||
!.SRCINFO
|
|
||||||
|
|
675
LICENSE.md
Normal file
675
LICENSE.md
Normal file
|
@ -0,0 +1,675 @@
|
||||||
|
# GNU GENERAL PUBLIC LICENSE
|
||||||
|
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
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) <year> <name of author>
|
||||||
|
|
||||||
|
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) <year> <name of author>
|
||||||
|
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>.
|
107
PKGBUILD
107
PKGBUILD
|
@ -1,107 +0,0 @@
|
||||||
# Maintainer: Rudra Saraswat <rs2009@ubuntu.com>
|
|
||||||
|
|
||||||
pkgbase=blend-git
|
|
||||||
pkgname=('blend-git' 'blend-settings-git')
|
|
||||||
pkgver=r50.2e0016f
|
|
||||||
pkgrel=1
|
|
||||||
pkgdesc="A package manager for blendOS"
|
|
||||||
arch=('x86_64' 'i686')
|
|
||||||
url="https://git.askiiart.net/askiiart-blendos/blend"
|
|
||||||
license=('GPL3')
|
|
||||||
makedepends=("electron" 'git' 'npm' 'base-devel')
|
|
||||||
source=('git+https://git.askiiart.net/askiiart-blendos/blend'
|
|
||||||
'blend-settings.desktop'
|
|
||||||
'blend-package-installer.desktop'
|
|
||||||
'blend-settings'
|
|
||||||
'blend.sh')
|
|
||||||
sha256sums=('SKIP'
|
|
||||||
'ba11ef22fe92a78239855c1bbc07d8c5be7cd94728bb3baf6184d2f42a80a4c2'
|
|
||||||
'994bebb5e993130e5cfaac8f9e1e8e676662a0cc76abcf90c8e128576506b818'
|
|
||||||
'73cb7c39190d36f233b8dfbc3e3e6737d56e61e90881ad95f09e5ae1f9b405a8'
|
|
||||||
'7dab67fb5c0239b6645659a7838de85b1420683a5bf52d8a8a3d324b69210a40')
|
|
||||||
|
|
||||||
pkgver() {
|
|
||||||
cd "${srcdir}/${pkgbase%-git}"
|
|
||||||
printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
|
|
||||||
}
|
|
||||||
|
|
||||||
prepare() {
|
|
||||||
cd "${srcdir}/${pkgbase%-git}/${pkgbase%-git}-settings"
|
|
||||||
npm config set cache "${srcdir}/npm-cache"
|
|
||||||
npm install
|
|
||||||
}
|
|
||||||
|
|
||||||
build() {
|
|
||||||
cd "${srcdir}/${pkgbase%-git}/${pkgbase%-git}-settings"
|
|
||||||
npm config set cache "${srcdir}/npm-cache"
|
|
||||||
export NODE_ENV=production
|
|
||||||
electronDist="/usr/lib/electron"
|
|
||||||
electronVer="$(sed s/^v// /usr/lib/electron/version)"
|
|
||||||
npm run icons
|
|
||||||
npm run pack -- -c.electronDist=${electronDist} \
|
|
||||||
-c.electronVersion=${electronVer} --publish never
|
|
||||||
cd ../overlayfs-tools; make
|
|
||||||
}
|
|
||||||
|
|
||||||
package_blend-git() {
|
|
||||||
depends=('bash' 'blend-settings-git' 'podman' 'python' 'python-click' 'python-pexpect')
|
|
||||||
provides=("${pkgname%-git}")
|
|
||||||
conflicts=("${pkgname%-git}")
|
|
||||||
|
|
||||||
cd "${srcdir}/${pkgbase%-git}"
|
|
||||||
install -Dm755 \
|
|
||||||
"${pkgname%-git}" \
|
|
||||||
"user" \
|
|
||||||
"init-${pkgname%-git}" \
|
|
||||||
"host-${pkgname%-git}" \
|
|
||||||
"${pkgname%-git}-files" \
|
|
||||||
-t "${pkgdir}"/usr/bin/
|
|
||||||
install -Dm755 "overlayfs-tools/overlayfs-tools" -t \
|
|
||||||
"${pkgdir}/usr/bin/"
|
|
||||||
install -Dm644 ../"${pkgname%-git}.sh" -t \
|
|
||||||
"${pkgdir}"/etc/profile.d/
|
|
||||||
install -Dm644 "${pkgname%-git}-files.service" -t \
|
|
||||||
"${pkgdir}"/usr/lib/systemd/user/
|
|
||||||
install -Dm644 "${pkgname%-git}.hook" \
|
|
||||||
"${pkgdir}/usr/lib/initcpio/hooks/${pkgname%-git}"
|
|
||||||
install -Dm644 "${pkgname%-git}.install" \
|
|
||||||
"${pkgdir}/usr/lib/initcpio/install/${pkgname%-git}"
|
|
||||||
}
|
|
||||||
|
|
||||||
package_blend-settings-git() {
|
|
||||||
pkgdesc="blendOS Settings"
|
|
||||||
depends=("electron${_electronversion}")
|
|
||||||
provides=(blend-settings)
|
|
||||||
conflicts=(blend-settings)
|
|
||||||
|
|
||||||
cd "${srcdir}/${pkgbase%-git}/${pkgbase%-git}-settings"
|
|
||||||
|
|
||||||
local _arch
|
|
||||||
case ${CARCH} in
|
|
||||||
i686)
|
|
||||||
_arch=linux-ia32-unpacked
|
|
||||||
;;
|
|
||||||
x86_64)
|
|
||||||
_arch=linux-unpacked
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
_arch=linux-${CARCH}-unpacked
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
install -Dm644 "dist/${_arch}/resources/app.asar" \
|
|
||||||
"$pkgdir/usr/lib/${pkgname%-git}/${pkgname%-git}.asar"
|
|
||||||
|
|
||||||
for icon_size in 16 24 32 48 64 128 256 512; do
|
|
||||||
install -Dm644 "build/icons/png/${icon_size}x${icon_size}.png" \
|
|
||||||
"${pkgdir}/usr/share/icons/hicolor/${icon_size}x${icon_size}/apps/${pkgname%-git}.png"
|
|
||||||
done
|
|
||||||
|
|
||||||
install -Dm644 "${srcdir}/${pkgname%-git}.desktop" -t \
|
|
||||||
"${pkgdir}"/usr/share/applications/
|
|
||||||
|
|
||||||
install -Dm644 "${srcdir}/blend-package-installer.desktop" -t \
|
|
||||||
"${pkgdir}"/usr/share/applications/
|
|
||||||
|
|
||||||
install -Dm755 "${srcdir}/${pkgname%-git}" -t "${pkgdir}"/usr/bin/
|
|
||||||
}
|
|
20
README.md
Normal file
20
README.md
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<div align="center">
|
||||||
|
<h1 align="center">blend</h1>
|
||||||
|
<p align="center">A tool to manage overlays, containers and multiple distributions</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
This repository also contains **blend-settings**, a tool for configuring blend and overlays, as well as many other utilities.
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
|
||||||
|
The `init-blend` file in this repository uses a few lines (the sections have been marked clearly) uses from distrobox's init script. These lines have been marked and attributed appropriately, and are licensed under [the GPL-3.0 license](https://github.com/89luca89/distrobox/blob/main/COPYING.md).
|
||||||
|
|
||||||
|
I would also like to thank Luca Di Maio from Distrobox for NVIDIA driver support in containers.
|
||||||
|
|
||||||
|
`overlayfs-tools` has been taken from https://github.com/ecdye/zram-config, which itself forked https://github.com/kmxz/overlayfs-tools.
|
||||||
|
|
||||||
|
Aside from these lines, all the other code in this repository has been written by me (rs2009). `blend-settings` is based on [Modren](https://github.com/RudraSwat/modren), a software store I (rs2009) had written long ago, and is licensed under the same license as the rest of the code in this repository, [the GPL-3.0 license](https://github.com/blend-os/blend/blob/main/LICENSE).
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
It's recommended to use the `blend-settings` UI, instead of the `blend` CLI.
|
524
blend
Executable file
524
blend
Executable file
|
@ -0,0 +1,524 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
# Copyright (C) 2023 Rudra Saraswat
|
||||||
|
#
|
||||||
|
# This file is part of blend.
|
||||||
|
#
|
||||||
|
# blend 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.
|
||||||
|
#
|
||||||
|
# blend 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 blend. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import glob
|
||||||
|
import time
|
||||||
|
import shutil
|
||||||
|
import socket
|
||||||
|
import getpass
|
||||||
|
import pexpect
|
||||||
|
import argparse
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
__version = '2.0.0'
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
|
||||||
|
|
||||||
|
class colors:
|
||||||
|
reset = '\033[0m'
|
||||||
|
bold = '\033[01m'
|
||||||
|
disable = '\033[02m'
|
||||||
|
underline = '\033[04m'
|
||||||
|
reverse = '\033[07m'
|
||||||
|
strikethrough = '\033[09m'
|
||||||
|
invisible = '\033[08m'
|
||||||
|
|
||||||
|
class fg:
|
||||||
|
black = '\033[30m'
|
||||||
|
red = '\033[31m'
|
||||||
|
green = '\033[32m'
|
||||||
|
orange = '\033[33m'
|
||||||
|
blue = '\033[34m'
|
||||||
|
purple = '\033[35m'
|
||||||
|
cyan = '\033[36m'
|
||||||
|
lightgrey = '\033[37m'
|
||||||
|
darkgrey = '\033[90m'
|
||||||
|
lightred = '\033[91m'
|
||||||
|
lightgreen = '\033[92m'
|
||||||
|
yellow = '\033[93m'
|
||||||
|
lightblue = '\033[94m'
|
||||||
|
pink = '\033[95m'
|
||||||
|
lightcyan = '\033[96m'
|
||||||
|
|
||||||
|
class bg:
|
||||||
|
black = '\033[40m'
|
||||||
|
red = '\033[41m'
|
||||||
|
green = '\033[42m'
|
||||||
|
orange = '\033[43m'
|
||||||
|
blue = '\033[44m'
|
||||||
|
purple = '\033[45m'
|
||||||
|
cyan = '\033[46m'
|
||||||
|
lightgrey = '\033[47m'
|
||||||
|
|
||||||
|
# END
|
||||||
|
|
||||||
|
# Helper functions
|
||||||
|
|
||||||
|
|
||||||
|
def info(msg):
|
||||||
|
print(colors.bold + colors.fg.cyan + '>> i: ' +
|
||||||
|
colors.reset + colors.bold + msg + colors.reset)
|
||||||
|
|
||||||
|
|
||||||
|
def error(err):
|
||||||
|
print(colors.bold + colors.fg.red + '>> e: ' +
|
||||||
|
colors.reset + colors.bold + err + colors.reset)
|
||||||
|
|
||||||
|
# END
|
||||||
|
|
||||||
|
|
||||||
|
distro_map = {
|
||||||
|
'arch-linux': 'docker.io/library/archlinux',
|
||||||
|
'debian': 'quay.io/toolbx-images/debian-toolbox:testing',
|
||||||
|
'fedora-39': 'registry.fedoraproject.org/fedora-toolbox:39',
|
||||||
|
'centos': 'quay.io/toolbx-images/centos-toolbox:latest',
|
||||||
|
'ubuntu-22.04': 'quay.io/toolbx/ubuntu-toolbox:22.04',
|
||||||
|
}
|
||||||
|
|
||||||
|
default_distro = 'arch-linux'
|
||||||
|
|
||||||
|
|
||||||
|
def get_distro():
|
||||||
|
try:
|
||||||
|
return distro_map[args.distro]
|
||||||
|
except:
|
||||||
|
error(f"{args.distro} isn't supported by blend.")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
|
||||||
|
def list_containers():
|
||||||
|
_list = subprocess.run(['podman', 'ps', '-a', '--no-trunc', '--size', '--format',
|
||||||
|
'{{.Names}}:{{.Mounts}}'], stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
|
||||||
|
if len(_list) == 0:
|
||||||
|
info('No containers. Create one by installing a package (`blend install hello`), or manually create one (`blend create-container arch`).')
|
||||||
|
else:
|
||||||
|
info('List of containers:')
|
||||||
|
for i, container in enumerate(_list.splitlines(keepends=False)):
|
||||||
|
if 'blend' in container.split(':')[1]:
|
||||||
|
print(f"{colors.bold}{i}.{colors.reset} {container.split(':')[0]}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def check_container(name):
|
||||||
|
_list = subprocess.run(['podman', 'ps', '-a', '--no-trunc', '--size', '--format',
|
||||||
|
'{{.Names}}:{{.Mounts}}'], stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
|
||||||
|
for container in _list.splitlines(keepends=False):
|
||||||
|
if ('blend' in container.split(':')[1] or 'distrobox' in container.split(':')[1]) and name.strip() == container.split(':')[0]:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def check_container_status(name):
|
||||||
|
if os.environ.get('SUDO_USER') == None:
|
||||||
|
return host_get_output("podman inspect --type container " + name + " --format \"{{.State.Status}}\"")
|
||||||
|
else:
|
||||||
|
return host_get_output(f"sudo -u {os.environ.get('SUDO_USER')} podman inspect --type container " + name + " --format \"{{.State.Status}}\"")
|
||||||
|
|
||||||
|
|
||||||
|
def core_start_container(name, new_container=False):
|
||||||
|
sudo = []
|
||||||
|
if os.environ.get('SUDO_USER') != None:
|
||||||
|
sudo = ['sudo', '-u', os.environ.get('SUDO_USER')]
|
||||||
|
subprocess.call([*sudo, 'podman', 'start', name],
|
||||||
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
|
||||||
|
start_time = time.time() - 1000 # workaround
|
||||||
|
if check_container_status(name) != 'running':
|
||||||
|
print('')
|
||||||
|
error('the entry point failed to run; try again later')
|
||||||
|
info("here are the container's logs:")
|
||||||
|
subprocess.call(['podman', 'logs', '--since', str(start_time), name])
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
if os.environ.get('SUDO_USER') == None:
|
||||||
|
logproc = pexpect.spawn(
|
||||||
|
'podman', args=['logs', '-f', '--since', str(start_time), name], timeout=3600)
|
||||||
|
else:
|
||||||
|
logproc = pexpect.spawn(
|
||||||
|
'sudo', args=['-u', os.environ.get('SUDO_USER'), 'podman', 'logs', '-f', '--since', str(start_time), name], timeout=3600)
|
||||||
|
logproc.logfile_read = sys.stdout.buffer
|
||||||
|
|
||||||
|
logproc.expect('Started container.')
|
||||||
|
logproc.terminate()
|
||||||
|
|
||||||
|
|
||||||
|
def core_create_container():
|
||||||
|
name = args.container_name
|
||||||
|
distro = args.distro
|
||||||
|
info(f'creating container {name}, using {distro}')
|
||||||
|
|
||||||
|
if check_container(name):
|
||||||
|
error(f'container {name} already exists')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
podman_command = []
|
||||||
|
|
||||||
|
# Basic stuff
|
||||||
|
podman_command.extend(['podman', 'create', '--name', name])
|
||||||
|
podman_command.extend(['--hostname', name + '.' + socket.gethostname()])
|
||||||
|
podman_command.extend(['--privileged', '--ipc', 'host'])
|
||||||
|
podman_command.extend(['--network', 'host'])
|
||||||
|
podman_command.extend(['--security-opt', 'label=disable'])
|
||||||
|
podman_command.extend(['--user', 'root:root', '--pid', 'host'])
|
||||||
|
# identify as blend container
|
||||||
|
podman_command.extend(['--label', 'manager=blend'])
|
||||||
|
|
||||||
|
# Env variables
|
||||||
|
podman_command.extend(['--env', 'HOME=' + os.path.expanduser('~')])
|
||||||
|
podman_command.extend(['--env', 'CONTAINER_NAME=' + name])
|
||||||
|
|
||||||
|
# Volumes
|
||||||
|
podman_command.extend(['--volume', '/:/run/host:rslave'])
|
||||||
|
podman_command.extend(['--volume', '/tmp:/tmp:rslave'])
|
||||||
|
podman_command.extend(
|
||||||
|
['--volume', f"{os.path.expanduser('~')}:{os.path.expanduser('~')}:rslave"])
|
||||||
|
podman_command.extend(
|
||||||
|
['--volume', f"/run/user/{os.geteuid()}:/run/user/{os.geteuid()}:rslave"])
|
||||||
|
|
||||||
|
# Volumes (config files)
|
||||||
|
podman_command.extend(['--volume', f"/etc/hosts:/etc/hosts:ro"])
|
||||||
|
podman_command.extend(['--volume', f"/etc/localtime:/etc/localtime:ro"])
|
||||||
|
podman_command.extend(
|
||||||
|
['--volume', f"/etc/resolv.conf:/etc/resolv.conf:ro"])
|
||||||
|
|
||||||
|
# Volumes (files and tools)
|
||||||
|
podman_command.extend(['--volume', '/usr/bin/init-blend:/usr/bin/init-blend:ro',
|
||||||
|
'--entrypoint', '/usr/bin/init-blend']) # our entrypoint
|
||||||
|
# and the tool to run commands on the host
|
||||||
|
podman_command.extend(
|
||||||
|
['--volume', '/usr/bin/host-blend:/usr/bin/host-blend:ro'])
|
||||||
|
podman_command.extend(['--volume', '/var/log/journal'])
|
||||||
|
|
||||||
|
podman_command.extend(['--mount', 'type=devpts,destination=/dev/pts',
|
||||||
|
'--userns', 'keep-id',
|
||||||
|
'--annotation', 'run.oci.keep_original_groups=1'])
|
||||||
|
|
||||||
|
podman_command.extend([get_distro()])
|
||||||
|
|
||||||
|
# User (for init-blend)
|
||||||
|
podman_command.extend(['--uid', str(os.geteuid())])
|
||||||
|
podman_command.extend(['--group', str(os.getgid())])
|
||||||
|
podman_command.extend(['--username', getpass.getuser()])
|
||||||
|
podman_command.extend(['--home', os.path.expanduser('~')])
|
||||||
|
|
||||||
|
ret = subprocess.run(podman_command).returncode
|
||||||
|
if ret != 0:
|
||||||
|
error(f'failed to create container {name}')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
core_start_container(name)
|
||||||
|
|
||||||
|
|
||||||
|
def core_get_output(cmd): return subprocess.run(
|
||||||
|
cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode('UTF-8').strip()
|
||||||
|
|
||||||
|
|
||||||
|
def host_get_output(cmd): return subprocess.run(['bash', '-c', cmd],
|
||||||
|
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode('UTF-8').strip()
|
||||||
|
|
||||||
|
|
||||||
|
def core_get_retcode(cmd): return subprocess.run(['podman', 'exec', '--user', getpass.getuser(), '-it', args.container_name, 'bash', '-c', cmd],
|
||||||
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode
|
||||||
|
|
||||||
|
|
||||||
|
def core_run_container(cmd):
|
||||||
|
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
||||||
|
subprocess.call(['podman', 'exec', '--user', getpass.getuser(),
|
||||||
|
'-w', os.getcwd(), '-it', args.container_name, 'bash', '-c', cmd])
|
||||||
|
|
||||||
|
|
||||||
|
def core_install_pkg(pkg):
|
||||||
|
if args.distro == 'fedora-rawhide':
|
||||||
|
if args.noconfirm == True:
|
||||||
|
core_run_container(f'sudo dnf -y install {pkg}')
|
||||||
|
else:
|
||||||
|
core_run_container(f'sudo dnf install {pkg}')
|
||||||
|
elif args.distro == 'arch':
|
||||||
|
if core_get_retcode('[ -f /usr/bin/yay ]') != 0:
|
||||||
|
core_run_container('sudo pacman -Sy')
|
||||||
|
core_run_container(
|
||||||
|
'sudo pacman --noconfirm -Syu --needed git base-devel')
|
||||||
|
core_run_container(
|
||||||
|
'TEMP_DIR="$(mktemp -d)"; cd "${TEMP_DIR}"; git clone https://aur.archlinux.org/yay.git; cd yay; makepkg --noconfirm -si; rm -rf "${TEMP_DIR}"')
|
||||||
|
core_run_container(f'yay -Sy')
|
||||||
|
if args.noconfirm == True:
|
||||||
|
core_run_container(f'yay --noconfirm -Syu {pkg}')
|
||||||
|
else:
|
||||||
|
core_run_container(f'yay -Syu {pkg}')
|
||||||
|
elif args.distro.startswith('ubuntu-'):
|
||||||
|
core_run_container(f'sudo apt-get update')
|
||||||
|
if args.noconfirm == True:
|
||||||
|
core_run_container(f'sudo apt-get install -y {pkg}')
|
||||||
|
else:
|
||||||
|
core_run_container(f'sudo apt-get install {pkg}')
|
||||||
|
|
||||||
|
|
||||||
|
def core_remove_pkg(pkg):
|
||||||
|
if args.distro == 'fedora-rawhide':
|
||||||
|
if args.noconfirm == True:
|
||||||
|
core_run_container(f'sudo dnf -y remove {pkg}')
|
||||||
|
else:
|
||||||
|
core_run_container(f'sudo dnf remove {pkg}')
|
||||||
|
elif args.distro == 'arch':
|
||||||
|
if args.noconfirm == True:
|
||||||
|
core_run_container(f'sudo pacman --noconfirm -Rcns {pkg}')
|
||||||
|
else:
|
||||||
|
core_run_container(f'sudo pacman -Rcns {pkg}')
|
||||||
|
elif args.distro.startswith('ubuntu-'):
|
||||||
|
if args.noconfirm == True:
|
||||||
|
core_run_container(f'sudo apt-get purge -y {pkg}')
|
||||||
|
else:
|
||||||
|
core_run_container(f'sudo apt-get purge {pkg}')
|
||||||
|
core_run_container(f'sudo apt-get autoremove --purge -y {pkg}')
|
||||||
|
|
||||||
|
|
||||||
|
def core_search_pkg(pkg):
|
||||||
|
if args.distro == 'fedora-rawhide':
|
||||||
|
core_run_container(f'dnf search {pkg}')
|
||||||
|
elif args.distro == 'arch':
|
||||||
|
core_run_container(f'yay -Sy')
|
||||||
|
core_run_container(f'yay {pkg}')
|
||||||
|
elif args.distro.startswith('ubuntu-'):
|
||||||
|
core_run_container(f'sudo apt-get update')
|
||||||
|
core_run_container(f'apt-cache search {pkg}')
|
||||||
|
|
||||||
|
|
||||||
|
def core_show_pkg(pkg):
|
||||||
|
if args.distro == 'fedora-rawhide':
|
||||||
|
core_run_container(f'dnf info {pkg}')
|
||||||
|
elif args.distro == 'arch':
|
||||||
|
core_run_container(f'yay -Sy')
|
||||||
|
core_run_container(f'yay -Si {pkg}')
|
||||||
|
elif args.distro.startswith('ubuntu-'):
|
||||||
|
core_run_container(f'sudo apt-get update')
|
||||||
|
core_run_container(f'apt-cache show {pkg}')
|
||||||
|
|
||||||
|
|
||||||
|
def install_blend():
|
||||||
|
if len(args.pkg) == 0:
|
||||||
|
error('no packages to install')
|
||||||
|
|
||||||
|
for pkg in args.pkg:
|
||||||
|
info(f'installing blend {pkg}')
|
||||||
|
if not check_container(args.container_name):
|
||||||
|
core_create_container()
|
||||||
|
core_install_pkg(pkg)
|
||||||
|
|
||||||
|
|
||||||
|
def remove_blend():
|
||||||
|
if len(args.pkg) == 0:
|
||||||
|
error('no packages to remove')
|
||||||
|
|
||||||
|
for pkg in args.pkg:
|
||||||
|
info(f'removing blend {pkg}')
|
||||||
|
if not check_container(args.container_name):
|
||||||
|
error(f"container {args.container_name} doesn't exist")
|
||||||
|
core_remove_pkg(pkg)
|
||||||
|
|
||||||
|
|
||||||
|
def search_blend():
|
||||||
|
if len(args.pkg) == 0:
|
||||||
|
error('no packages to search for')
|
||||||
|
|
||||||
|
for pkg in args.pkg:
|
||||||
|
if not check_container(args.container_name):
|
||||||
|
error(f"container {args.container_name} doesn't exist")
|
||||||
|
core_search_pkg(pkg)
|
||||||
|
|
||||||
|
|
||||||
|
def show_blend():
|
||||||
|
if len(args.pkg) == 0:
|
||||||
|
error('no packages to show')
|
||||||
|
|
||||||
|
for pkg in args.pkg:
|
||||||
|
info(f'info about blend {pkg}')
|
||||||
|
if not check_container(args.container_name):
|
||||||
|
error(f"container {args.container_name} doesn't exist")
|
||||||
|
core_show_pkg(pkg)
|
||||||
|
|
||||||
|
|
||||||
|
def sync_blends():
|
||||||
|
if args.distro == 'fedora-rawhide':
|
||||||
|
core_run_container(f'dnf makecache')
|
||||||
|
elif args.distro == 'arch':
|
||||||
|
core_run_container(f'yay -Syy')
|
||||||
|
elif args.distro.startswith('ubuntu-'):
|
||||||
|
core_run_container(f'sudo apt-get update')
|
||||||
|
|
||||||
|
|
||||||
|
def update_blends():
|
||||||
|
if args.distro == 'fedora-rawhide':
|
||||||
|
if args.noconfirm == True:
|
||||||
|
core_run_container(f'sudo dnf -y upgrade')
|
||||||
|
else:
|
||||||
|
core_run_container(f'sudo dnf upgrade')
|
||||||
|
elif args.distro == 'arch':
|
||||||
|
if args.noconfirm == True:
|
||||||
|
core_run_container(f'yay --noconfirm')
|
||||||
|
else:
|
||||||
|
core_run_container(f'yay')
|
||||||
|
elif args.distro.startswith('ubuntu-'):
|
||||||
|
core_run_container(f'sudo apt-get update')
|
||||||
|
if args.noconfirm == True:
|
||||||
|
core_run_container(f'sudo apt-get dist-upgrade -y')
|
||||||
|
else:
|
||||||
|
core_run_container(f'sudo apt-get dist-upgrade')
|
||||||
|
else:
|
||||||
|
error(f'distribution {args.distro} is not supported')
|
||||||
|
|
||||||
|
|
||||||
|
def enter_container():
|
||||||
|
if check_container_status(args.container_name) != 'running':
|
||||||
|
core_start_container(args.container_name)
|
||||||
|
|
||||||
|
podman_args = ['--env', 'LC_ALL=C.UTF-8']
|
||||||
|
sudo = []
|
||||||
|
if os.environ.get('SUDO_USER') == None:
|
||||||
|
podman_args = ['--user', getpass.getuser()]
|
||||||
|
else:
|
||||||
|
sudo = ['sudo', '-u', os.environ.get(
|
||||||
|
'SUDO_USER'), f'PATH={os.path.expanduser("~/.local/share/bin/blend_bin")}:/usr/bin']
|
||||||
|
for name, val in os.environ.items():
|
||||||
|
if name not in ['LANG', 'LC_CTYPE', 'LC_ALL', 'PATH', 'HOST', 'HOSTNAME', 'SHELL'] and not name.startswith('_'):
|
||||||
|
podman_args.append('--env')
|
||||||
|
podman_args.append(name + '=' + val)
|
||||||
|
if os.environ.get('BLEND_COMMAND') == None or os.environ.get('BLEND_COMMAND') == '':
|
||||||
|
if args.pkg == []:
|
||||||
|
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
||||||
|
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args,
|
||||||
|
'-w', os.getcwd(), '-it', args.container_name, 'bash']))
|
||||||
|
else:
|
||||||
|
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w',
|
||||||
|
'/run/host' + os.getcwd(), '-it', args.container_name, 'bash']))
|
||||||
|
else:
|
||||||
|
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
||||||
|
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args,
|
||||||
|
'-w', os.getcwd(), '-it', args.container_name, *args.pkg]))
|
||||||
|
else:
|
||||||
|
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w',
|
||||||
|
'/run/host' + os.getcwd(), '-it', args.container_name, *args.pkg]))
|
||||||
|
else:
|
||||||
|
if os.getcwd() == os.path.expanduser('~') or os.getcwd().startswith(os.path.expanduser('~') + '/'):
|
||||||
|
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w', os.getcwd(
|
||||||
|
), '-it', args.container_name, 'bash', '-c', os.environ.get('BLEND_COMMAND')]))
|
||||||
|
else:
|
||||||
|
exit(subprocess.call([*sudo, 'podman', 'exec', *podman_args, '-w',
|
||||||
|
'/run/host' + os.getcwd(), '-it', args.container_name, 'bash']))
|
||||||
|
|
||||||
|
|
||||||
|
def create_container():
|
||||||
|
for container in args.pkg:
|
||||||
|
args.container_name = container
|
||||||
|
if container in distro_map.keys() and distro_input == None:
|
||||||
|
args.distro = container
|
||||||
|
core_create_container()
|
||||||
|
|
||||||
|
|
||||||
|
def remove_container():
|
||||||
|
for container in args.pkg:
|
||||||
|
info(f'removing container {container}')
|
||||||
|
subprocess.run(['podman', 'stop', container],
|
||||||
|
stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
|
||||||
|
subprocess.run(['podman', 'rm', '-f', container],
|
||||||
|
stdout=subprocess.DEVNULL)
|
||||||
|
for bin in os.listdir(os.path.expanduser('~/.local/bin/blend_bin')):
|
||||||
|
if bin.endswith(f'.{container}'):
|
||||||
|
os.remove(os.path.join(os.path.expanduser('~/.local/bin/blend_bin'), bin))
|
||||||
|
for app in os.listdir(os.path.expanduser('~/.local/share/applications')):
|
||||||
|
if app.startswith(f'blend;{container};'):
|
||||||
|
os.remove(os.path.join(os.path.expanduser('~/.local/share/applications'), app))
|
||||||
|
|
||||||
|
|
||||||
|
def start_containers():
|
||||||
|
_list = subprocess.run(['podman', 'ps', '-a', '--no-trunc', '--size', '--format',
|
||||||
|
'{{.Names}}:{{.Mounts}}'], stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
|
||||||
|
if len(_list) == 0:
|
||||||
|
info('No containers. Create one by installing a package (`blend install hello`), or manually create one (`blend create-container -d arch`).')
|
||||||
|
for container in _list.splitlines(keepends=False):
|
||||||
|
container = container.split(':')[0]
|
||||||
|
info(f'starting container {container}')
|
||||||
|
subprocess.call(['podman', 'start', container])
|
||||||
|
|
||||||
|
|
||||||
|
if shutil.which('podman') is None:
|
||||||
|
error("podman isn't installed, which is a hard dep")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
if os.geteuid() == 0 and os.environ['BLEND_ALLOW_ROOT'] == None:
|
||||||
|
error("do not run as root")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
description = f'''
|
||||||
|
{colors.bold}{colors.fg.purple}Version:{colors.reset} {__version}{colors.bold}
|
||||||
|
|
||||||
|
Use the 'blendOS Settings' app to create and manage Linux containers, Android apps and for system configuration.
|
||||||
|
|
||||||
|
You can install and submit web apps from the Web Store.
|
||||||
|
'''
|
||||||
|
|
||||||
|
epilog = f'''
|
||||||
|
{colors.bold}Made with {colors.fg.red}\u2764{colors.reset}{colors.bold} by Rudra Saraswat.{colors.reset}
|
||||||
|
'''
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description=description, usage=argparse.SUPPRESS,
|
||||||
|
epilog=epilog, formatter_class=argparse.RawTextHelpFormatter)
|
||||||
|
command_map = {'enter': enter_container,
|
||||||
|
'exec': enter_container,
|
||||||
|
'create-container': core_create_container,
|
||||||
|
'remove-container': remove_container,
|
||||||
|
'list-containers': list_containers,
|
||||||
|
'start-containers': start_containers,
|
||||||
|
'sync': sync_blends,
|
||||||
|
'help': 'help',
|
||||||
|
'version': 'version'}
|
||||||
|
parser.add_argument('command', choices=command_map.keys(),
|
||||||
|
help=argparse.SUPPRESS)
|
||||||
|
parser.add_argument('pkg', action='store', type=str,
|
||||||
|
nargs='*', help=argparse.SUPPRESS)
|
||||||
|
parser.add_argument('-cn', '--container-name', action='store',
|
||||||
|
nargs=1, metavar='CONTAINER NAME', help=argparse.SUPPRESS)
|
||||||
|
parser.add_argument('-y', '--noconfirm',
|
||||||
|
action='store_true', help=argparse.SUPPRESS)
|
||||||
|
parser.add_argument('-d', '--distro', action='store', nargs=1,
|
||||||
|
metavar='DISTRO', help=argparse.SUPPRESS)
|
||||||
|
parser.add_argument('-v', '--version', action='version',
|
||||||
|
version=f'%(prog)s {__version}', help=argparse.SUPPRESS)
|
||||||
|
|
||||||
|
if len(sys.argv) == 1:
|
||||||
|
parser.print_help()
|
||||||
|
exit()
|
||||||
|
|
||||||
|
args = parser.parse_intermixed_args()
|
||||||
|
|
||||||
|
command = command_map[args.command]
|
||||||
|
|
||||||
|
distro_input = args.distro
|
||||||
|
args.distro = default_distro if args.distro == None else args.distro[0]
|
||||||
|
cn_input = args.container_name
|
||||||
|
args.container_name = args.distro if args.container_name == None else args.container_name[0]
|
||||||
|
|
||||||
|
if command == 'help':
|
||||||
|
parser.print_help()
|
||||||
|
elif command == 'version':
|
||||||
|
parser.parse_args(['--version'])
|
||||||
|
else:
|
||||||
|
command()
|
17
blend-files
Executable file
17
blend-files
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
if os.path.isdir(os.path.expanduser('~/.local/bin/blend_bin')) and not os.path.isfile(os.path.expanduser('~/.local/bin/blend_bin/.associations')):
|
||||||
|
subprocess.call(
|
||||||
|
['rm', '-rf', os.path.expanduser('~/.local/bin/blend_bin')], shell=False)
|
||||||
|
subprocess.call(
|
||||||
|
['bash', '-c', 'rm -f "${HOME}/.local/share/applications/blend;"*'], shell=False)
|
||||||
|
|
||||||
|
subprocess.call(['mkdir', '-p', os.path.expanduser('~/.local/share/applications/')])
|
||||||
|
subprocess.call(['mkdir', '-p', os.path.expanduser('~/.local/bin/blend_bin/')])
|
||||||
|
subprocess.call(['touch', os.path.expanduser(
|
||||||
|
'~/.local/bin/blend_bin/.associations')], shell=False)
|
||||||
|
subprocess.call(['touch', os.path.expanduser(
|
||||||
|
'~/.local/share/applications/.empty')], shell=False)
|
10
blend-files.service
Normal file
10
blend-files.service
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Make container apps accessible
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
StandardOutput=journal
|
||||||
|
ExecStart=/usr/bin/blend-files
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
|
@ -1,11 +0,0 @@
|
||||||
[Desktop Entry]
|
|
||||||
Name=Package Installer
|
|
||||||
Exec=blend-settings package %F
|
|
||||||
Terminal=false
|
|
||||||
NoDisplay=true
|
|
||||||
Type=Application
|
|
||||||
Icon=blend-settings
|
|
||||||
MimeType=application/vnd.debian.binary-package;application/x-rpm;application/vnd.android.package-archive;
|
|
||||||
StartupWMClass=blend-settings
|
|
||||||
Comment=Package installer for blendOS.
|
|
||||||
Categories=System;
|
|
|
@ -1,2 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
exec electron /usr/lib/blend-settings/blend-settings.asar "$@"
|
|
|
@ -1,10 +0,0 @@
|
||||||
[Desktop Entry]
|
|
||||||
Name=System
|
|
||||||
Exec=blend-settings %U
|
|
||||||
Terminal=false
|
|
||||||
Type=Application
|
|
||||||
Icon=blend-settings
|
|
||||||
StartupWMClass=blend-settings
|
|
||||||
Comment=Settings for blendOS.
|
|
||||||
Keywords=Settings;
|
|
||||||
Categories=System;
|
|
674
blend-settings/LICENSE
Normal file
674
blend-settings/LICENSE
Normal file
|
@ -0,0 +1,674 @@
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Grapes
|
||||||
|
Copyright (C) 2023 Rudra Saraswat <rs2009@ubuntu.com>
|
||||||
|
|
||||||
|
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) 2023 Rudra Saraswat <rs2009@ubuntu.com>
|
||||||
|
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>.
|
199
blend-settings/main.js
Normal file
199
blend-settings/main.js
Normal file
|
@ -0,0 +1,199 @@
|
||||||
|
const { app, BrowserWindow, ipcMain, dialog } = require('electron')
|
||||||
|
const path = require('path')
|
||||||
|
const pty = require("node-pty");
|
||||||
|
|
||||||
|
var mainWindow, terminalWindow, packageWindow, ptyProcess
|
||||||
|
|
||||||
|
app.commandLine.appendSwitch('enable-transparent-visuals');
|
||||||
|
app.disableHardwareAcceleration();
|
||||||
|
|
||||||
|
require('@electron/remote/main').initialize()
|
||||||
|
|
||||||
|
function createWindow() {
|
||||||
|
mainWindow = new BrowserWindow({
|
||||||
|
minWidth: 1000,
|
||||||
|
minHeight: 600,
|
||||||
|
maxWidth: 1000,
|
||||||
|
maxHeight: 600,
|
||||||
|
webPreferences: {
|
||||||
|
nodeIntegration: true,
|
||||||
|
nodeIntegrationInWorker: true,
|
||||||
|
contextIsolation: false,
|
||||||
|
enableRemoteModule: true,
|
||||||
|
sandbox: false,
|
||||||
|
preload: path.join(__dirname, 'src/preload.js')
|
||||||
|
},
|
||||||
|
autoHideMenuBar: true
|
||||||
|
})
|
||||||
|
|
||||||
|
// mainWindow.setMenu(null)
|
||||||
|
|
||||||
|
mainWindow.loadFile('src/index.html')
|
||||||
|
}
|
||||||
|
|
||||||
|
function createTerminalWindow() {
|
||||||
|
let t_window_settings = {
|
||||||
|
minWidth: 800,
|
||||||
|
minHeight: 600,
|
||||||
|
webPreferences: {
|
||||||
|
nodeIntegration: true,
|
||||||
|
contextIsolation: false,
|
||||||
|
sandbox: false
|
||||||
|
},
|
||||||
|
autoHideMenuBar: true,
|
||||||
|
show: false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.argv.length > 2) {
|
||||||
|
if (process.argv[2] == 'package') {
|
||||||
|
t_window_settings['frame'] = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
terminalWindow = new BrowserWindow(t_window_settings)
|
||||||
|
|
||||||
|
terminalWindow.loadFile('src/pages/terminal.html')
|
||||||
|
|
||||||
|
// terminalWindow.setMenu(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
function createPackageWindow() {
|
||||||
|
packageWindow = new BrowserWindow({
|
||||||
|
minWidth: 450,
|
||||||
|
minHeight: 450,
|
||||||
|
width: 450,
|
||||||
|
height: 450,
|
||||||
|
webPreferences: {
|
||||||
|
nodeIntegration: true,
|
||||||
|
contextIsolation: false,
|
||||||
|
enableRemoteModule: true,
|
||||||
|
sandbox: false
|
||||||
|
},
|
||||||
|
autoHideMenuBar: true
|
||||||
|
})
|
||||||
|
|
||||||
|
packageWindow.loadFile('src/package-installer.html')
|
||||||
|
|
||||||
|
require("@electron/remote/main").enable(packageWindow.webContents)
|
||||||
|
|
||||||
|
// packageWindow.setMenu(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadTerminalWindow(title, cmd) {
|
||||||
|
if (terminalWindow.isDestroyed()) {
|
||||||
|
createTerminalWindow()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (terminalWindow.isVisible() && (title.startsWith('Container: ') && terminalWindow.getTitle().startsWith('Creating container: '))) {
|
||||||
|
dialog.showErrorBox('Error opening container window', 'You cannot open a container window while creating a container.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (terminalWindow.isVisible() && title.startsWith('Container: ')) {
|
||||||
|
dialog.showErrorBox('Error opening container window', 'You must close any other container windows before opening a new one.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (terminalWindow.isVisible() && (title.startsWith('Creating container: ') && terminalWindow.getTitle().startsWith('Creating container: '))) {
|
||||||
|
dialog.showErrorBox('Error creating container', 'You cannot create two containers simultaneously.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (terminalWindow.isVisible() && title.startsWith('Creating container: ')) {
|
||||||
|
dialog.showErrorBox('Error creating container', 'You must close the container window before creating a container.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
terminalWindow.show()
|
||||||
|
|
||||||
|
ipcMain.removeAllListeners('terminal.reset')
|
||||||
|
ipcMain.removeAllListeners('terminal.resize')
|
||||||
|
ipcMain.removeAllListeners('terminal.keystroke')
|
||||||
|
ipcMain.removeAllListeners('terminal.incomingData')
|
||||||
|
ipcMain.removeAllListeners('title')
|
||||||
|
|
||||||
|
terminalWindow.removeAllListeners()
|
||||||
|
|
||||||
|
terminalWindow.on('close', e => {
|
||||||
|
if (terminalWindow.getTitle().startsWith('Creating container: ')) {
|
||||||
|
dialog.showMessageBox(terminalWindow, {
|
||||||
|
'type': 'question',
|
||||||
|
'title': 'Are you sure?',
|
||||||
|
'message': "A container is being created. Closing this window will prevent you from seeing its creation status. Are you sure?",
|
||||||
|
'buttons': [
|
||||||
|
'Yes',
|
||||||
|
'No'
|
||||||
|
]
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.response === 0) {
|
||||||
|
terminalWindow.hide()
|
||||||
|
ptyProcess.destroy()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if (terminalWindow.getTitle().startsWith('Package installation')) {
|
||||||
|
e.preventDefault()
|
||||||
|
} else {
|
||||||
|
terminalWindow.hide()
|
||||||
|
ptyProcess.destroy()
|
||||||
|
}
|
||||||
|
e.preventDefault()
|
||||||
|
})
|
||||||
|
|
||||||
|
terminalWindow.webContents.send("terminal.reset")
|
||||||
|
|
||||||
|
terminalWindow.webContents.send("title", title);
|
||||||
|
|
||||||
|
ptyProcess = pty.spawn('/bin/bash', ['-c', cmd], {
|
||||||
|
name: "xterm-color",
|
||||||
|
cols: 80,
|
||||||
|
rows: 30,
|
||||||
|
cwd: process.env.HOME,
|
||||||
|
env: process.env
|
||||||
|
});
|
||||||
|
|
||||||
|
ptyProcess.on('data', data => {
|
||||||
|
if (!terminalWindow.isDestroyed()) {
|
||||||
|
terminalWindow.webContents.send("terminal.incomingData", data)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ptyProcess.on('exit', () => {
|
||||||
|
if (!terminalWindow.isDestroyed()) {
|
||||||
|
terminalWindow.webContents.send("terminal.reset")
|
||||||
|
terminalWindow.hide()
|
||||||
|
if (title.startsWith('Creating container: ')) {
|
||||||
|
mainWindow.webContents.send("container-created")
|
||||||
|
} else if (title.startsWith('Package installation')) {
|
||||||
|
packageWindow.webContents.send("installation-complete")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
ipcMain.on("terminal.keystroke", (event, key) => {
|
||||||
|
ptyProcess.write(key)
|
||||||
|
});
|
||||||
|
ipcMain.on("terminal.resize", (event, size) => {
|
||||||
|
ptyProcess.resize(size[0], size[1])
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
app.whenReady().then(() => {
|
||||||
|
app.allowRendererProcessReuse = false
|
||||||
|
|
||||||
|
if (process.argv.length > 2) {
|
||||||
|
if (process.argv[2] == 'package') {
|
||||||
|
createPackageWindow()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
createWindow()
|
||||||
|
}
|
||||||
|
|
||||||
|
createTerminalWindow()
|
||||||
|
|
||||||
|
ipcMain.on('create-term', (event, data) => {
|
||||||
|
loadTerminalWindow(data['title'], data['cmd'])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
app.on('window-all-closed', function () {
|
||||||
|
if (process.platform !== 'darwin') app.quit()
|
||||||
|
})
|
45
blend-settings/package.json
Normal file
45
blend-settings/package.json
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
{
|
||||||
|
"name": "blend-settings",
|
||||||
|
"version": "2.0.0",
|
||||||
|
"description": "A settings app for blendOS",
|
||||||
|
"main": "main.js",
|
||||||
|
"homepage": "https://blendos.org",
|
||||||
|
"author": "Rudra Saraswat",
|
||||||
|
"license": "GPL-3.0-or-later",
|
||||||
|
"scripts": {
|
||||||
|
"start": "electron .",
|
||||||
|
"icons": "electron-icon-maker --input=./static/icon.png --output=./build/",
|
||||||
|
"electron-builder": "electron-builder",
|
||||||
|
"pack": "electron-builder --dir",
|
||||||
|
"dist": "electron-builder"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@electron/remote": "^2.0.10",
|
||||||
|
"@types/jquery": "^3.5.16",
|
||||||
|
"jquery": "^3.6.3",
|
||||||
|
"js-yaml": "^4.1.0",
|
||||||
|
"node-pty": "github:daniel-brenot/node-pty#rust-port",
|
||||||
|
"sortablejs": "^1.15.0",
|
||||||
|
"xterm": "^5.1.0",
|
||||||
|
"xterm-addon-fit": "^0.7.0",
|
||||||
|
"xterm-addon-ligatures": "^0.6.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"electron": "^23.0.0",
|
||||||
|
"electron-builder": "^23.6.0",
|
||||||
|
"electron-icon-maker": "^0.0.5"
|
||||||
|
},
|
||||||
|
"build": {
|
||||||
|
"appId": "org.blend.settings",
|
||||||
|
"productName": "blendOS Settings",
|
||||||
|
"asar": true,
|
||||||
|
"linux": {
|
||||||
|
"target": [
|
||||||
|
"tar.gz"
|
||||||
|
],
|
||||||
|
"category": "System",
|
||||||
|
"icon": "icons/png",
|
||||||
|
"maintainer": "Rudra Saraswat"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
blend-settings/src/external/css/bootstrap.min.css
vendored
Normal file
7
blend-settings/src/external/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
7
blend-settings/src/external/js/bootstrap.bundle.min.js
vendored
Normal file
7
blend-settings/src/external/js/bootstrap.bundle.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
78
blend-settings/src/index.html
Normal file
78
blend-settings/src/index.html
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>System Settings</title>
|
||||||
|
|
||||||
|
<!-- Import bootstrap v5.0. -->
|
||||||
|
<link href="external/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
|
||||||
|
<!-- Import common styling. -->
|
||||||
|
<link href="internal/css/common.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body style="height: 100%;">
|
||||||
|
<br>
|
||||||
|
<div class="topnav">
|
||||||
|
<div class="btn-group" id="settings-tabs" role="group" aria-label="Stores">
|
||||||
|
<button class="btn btn-outline-light active shadow-none" id="containers-button" onclick="page('containers')">Linux
|
||||||
|
Containers</button>
|
||||||
|
<button class="btn btn-outline-light shadow-none d-none" id="android-button" onclick="page('android')">Android
|
||||||
|
Apps</button>
|
||||||
|
<button class="btn btn-outline-light shadow-none" id="system-button" onclick="page('system')">System Updates</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Import bootstrap JS bundle. -->
|
||||||
|
<script src="external/js/bootstrap.bundle.min.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const Sortable = require('sortablejs')
|
||||||
|
const child_process = require('child_process')
|
||||||
|
const path = require('path')
|
||||||
|
const fs = require('fs')
|
||||||
|
const ipc = require('electron').ipcRenderer
|
||||||
|
|
||||||
|
let webview = document.createElement("div")
|
||||||
|
webview.style.flexGrow = 1
|
||||||
|
webview.setAttribute("id", "webview")
|
||||||
|
webview.style.marginTop = "70px"
|
||||||
|
|
||||||
|
document.body.appendChild(webview)
|
||||||
|
|
||||||
|
const $ = require("jquery")
|
||||||
|
|
||||||
|
if (fs.existsSync('/usr/bin/waydroid')) {
|
||||||
|
document.getElementById('android-button').classList.remove('d-none')
|
||||||
|
}
|
||||||
|
|
||||||
|
function page(page) {
|
||||||
|
switch (page) {
|
||||||
|
case 'containers':
|
||||||
|
$('#webview').load("pages/containers.html");
|
||||||
|
$('#containers-button').addClass('active')
|
||||||
|
$('#android-button').removeClass('active')
|
||||||
|
$('#system-button').removeClass('active')
|
||||||
|
break;
|
||||||
|
case 'android':
|
||||||
|
$('#webview').load("pages/android.html");
|
||||||
|
$('#containers-button').removeClass('active')
|
||||||
|
$('#android-button').addClass('active')
|
||||||
|
$('#system-button').removeClass('active')
|
||||||
|
break;
|
||||||
|
case 'system':
|
||||||
|
$('#webview').load("pages/system.html");
|
||||||
|
$('#containers-button').removeClass('active')
|
||||||
|
$('#android-button').removeClass('active')
|
||||||
|
$('#system-button').addClass('active')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
page('containers')
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Import generic page JS. -->
|
||||||
|
<script src="internal/js/generic_page.js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
102
blend-settings/src/internal/css/common.css
Normal file
102
blend-settings/src/internal/css/common.css
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
body {
|
||||||
|
margin: 0 !important;
|
||||||
|
background-color: rgb(24, 24, 32);
|
||||||
|
color: rgba(240, 240, 255, 1);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-dark {
|
||||||
|
background-color: rgb(36, 36, 48);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-dark:focus {
|
||||||
|
background-color: rgb(36, 36, 48);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-dark:hover {
|
||||||
|
background-color: rgb(32, 32, 44);
|
||||||
|
}
|
||||||
|
|
||||||
|
.topnav {
|
||||||
|
display: flex;
|
||||||
|
position: fixed;
|
||||||
|
top: 20px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group-item {
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-control {
|
||||||
|
border: 0;
|
||||||
|
background-color: rgba(255, 255, 255, 0.05) !important;
|
||||||
|
color: white !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-check-input:not(:checked) {
|
||||||
|
background-color: rgba(255, 255, 255, 0.05) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
select option {
|
||||||
|
color: white;
|
||||||
|
background-color: rgb(36, 36, 48);
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group {
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#webview {
|
||||||
|
overflow-y: scroll !important;
|
||||||
|
position: fixed;
|
||||||
|
width: 100%;
|
||||||
|
height: calc(100% - 100px);
|
||||||
|
}
|
||||||
|
|
||||||
|
#webview::-webkit-scrollbar-track
|
||||||
|
{
|
||||||
|
background-color: rgb(36, 36, 48);
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#webview::-webkit-scrollbar
|
||||||
|
{
|
||||||
|
width: 5px;
|
||||||
|
background-color: rgb(36, 36, 48);
|
||||||
|
}
|
||||||
|
|
||||||
|
#webview::-webkit-scrollbar-thumb
|
||||||
|
{
|
||||||
|
background-color: rgb(61, 61, 74);
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-check-input {
|
||||||
|
position: absolute;
|
||||||
|
font-size: 1.5em;
|
||||||
|
top: 0.67em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-control:focus {
|
||||||
|
box-shadow: 0 0 0 0.25rem rgb(37, 124, 253) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group-item {
|
||||||
|
background-color: rgb(29, 29, 37);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
-webkit-scrollbar-track
|
||||||
|
{
|
||||||
|
box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
|
||||||
|
background-color: #F5F5F5;
|
||||||
|
}
|
||||||
|
|
||||||
|
-webkit-scrollbar
|
||||||
|
{
|
||||||
|
width: 10px;
|
||||||
|
background-color: #F5F5F5;
|
||||||
|
}
|
197
blend-settings/src/internal/js/android.js
Normal file
197
blend-settings/src/internal/js/android.js
Normal file
|
@ -0,0 +1,197 @@
|
||||||
|
function init_waydroid() {
|
||||||
|
document.getElementById('initialize-btn').outerHTML =
|
||||||
|
'<button type="button" id="initialize-btn" onclick="init_waydroid()" class="btn btn-primary" disabled>Initializing...</button>'
|
||||||
|
let init_worker = new Worker(
|
||||||
|
`data:text/javascript,
|
||||||
|
require('child_process').spawnSync('pkexec', ['waydroid', 'init'])
|
||||||
|
require('child_process').spawnSync('pkexec', ['systemctl', 'enable', '--now', 'waydroid-container'])
|
||||||
|
require('child_process').spawn('sh', ['-c', 'waydroid session start & disown'])
|
||||||
|
setTimeout(() => {
|
||||||
|
require('child_process').spawnSync('sh', ['-c', 'pkexec bash -c "waydroid shell wm set-fix-to-user-rotation enabled; echo persist.waydroid.multi_windows=true | tee -a /var/lib/waydroid/waydroid.cfg"'])
|
||||||
|
if (require('child_process').spawnSync('sh', ['-c', 'LC_ALL=C glxinfo | grep "^OpenGL renderer string: "']).stdout.includes('NVIDIA') || require('child_process').spawnSync('cat', ['/proc/cpuinfo']).stdout.includes('hypervisor')) {
|
||||||
|
require('child_process').spawnSync('sh', ['-c', 'echo -e "ro.hardware.gralloc=default\\nro.hardware.egl=swiftshader" | pkexec tee -a /var/lib/waydroid/waydroid.cfg'])
|
||||||
|
}
|
||||||
|
require('child_process').spawn('sh', ['-c', 'pkexec waydroid upgrade -o; waydroid session stop; waydroid session start'])
|
||||||
|
setTimeout(() => { postMessage('success') }, 2000)
|
||||||
|
}, 8000)
|
||||||
|
`
|
||||||
|
)
|
||||||
|
init_worker.onmessage = e => {
|
||||||
|
if (e.data == 'success') {
|
||||||
|
document.getElementById('waydroid-initialize-settings').classList.add('d-none')
|
||||||
|
document.getElementById('waydroid-initialized-settings').classList.remove('d-none')
|
||||||
|
document.getElementById('first-time-waydroid').classList.remove('d-none')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (require('child_process').spawnSync('waydroid', ['app', 'list']).stdout.includes('com.aurora.store')) {
|
||||||
|
document.getElementById('aurora-store-btn').outerHTML =
|
||||||
|
`<button type="button btn-success" id="aurora-store-btn" onclick="require('child_process').spawn('waydroid', ['app', 'launch', 'com.aurora.store'])"
|
||||||
|
class="btn btn-success">Open</button>`
|
||||||
|
} else {
|
||||||
|
document.getElementById('aurora-store-btn').outerHTML =
|
||||||
|
`<button type="button btn-success" id="aurora-store-btn" onclick="install_aurora_store()"
|
||||||
|
class="btn btn-success">Install</button>`
|
||||||
|
}
|
||||||
|
if (require('child_process').spawnSync('waydroid', ['app', 'list']).stdout.includes('org.fdroid.fdroid')) {
|
||||||
|
document.getElementById('f-droid-btn').outerHTML =
|
||||||
|
`<button type="button btn-success" id="fdroid-btn" onclick="require('child_process').spawn('waydroid', ['app', 'launch', 'org.fdroid.fdroid'])"
|
||||||
|
class="btn btn-primary">Open</button>`
|
||||||
|
} else {
|
||||||
|
document.getElementById('f-droid-btn').outerHTML =
|
||||||
|
`<button type="button btn-success" id="f-droid-btn" onclick="install_f_droid()"
|
||||||
|
class="btn btn-primary">Install</button>`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_aurora_store() {
|
||||||
|
document.getElementById('aurora-store-btn').outerHTML =
|
||||||
|
`<button type="button" id="aurora-store-btn" onclick="install_aurora_store()"
|
||||||
|
class="btn btn-success" disabled>Installing...</button>`
|
||||||
|
let aurora_store_worker = new Worker(
|
||||||
|
`data:text/javascript,
|
||||||
|
require('child_process').spawnSync('sh', ['-c', 'mkdir -p ~/.cache/blend-settings; rm -f ~/.cache/blend-settings/aurora.apk'])
|
||||||
|
let s1 = require('child_process').spawnSync('sh', ['-c', 'wget -O ~/.cache/blend-settings/aurora.apk https://f-droid.org/repo/com.aurora.store_58.apk']).status
|
||||||
|
if (s1 != 0) {
|
||||||
|
postMessage('failed')
|
||||||
|
} else {
|
||||||
|
require('child_process').spawn('waydroid', ['session', 'start'])
|
||||||
|
setTimeout(() => {
|
||||||
|
require('child_process').spawnSync('sh', ['-c', 'waydroid app install ~/.cache/blend-settings/aurora.apk'])
|
||||||
|
setTimeout(() => postMessage('success'), 200)
|
||||||
|
}, 2000)
|
||||||
|
}
|
||||||
|
`
|
||||||
|
)
|
||||||
|
aurora_store_worker.onmessage = e => {
|
||||||
|
if (e.data == 'success') {
|
||||||
|
document.getElementById('aurora-store-btn').outerHTML =
|
||||||
|
`<button type="button btn-success" id="aurora-store-btn" onclick="require('child_process').spawn('waydroid', ['app', 'launch', 'com.aurora.store'])"
|
||||||
|
class="btn btn-success">Open</button>`
|
||||||
|
} else if (e.data == 'failed') {
|
||||||
|
document.getElementById('aurora-store-btn').outerHTML =
|
||||||
|
`<button type="button btn-success" id="aurora-store-btn" onclick="install_aurora_store()"
|
||||||
|
class="btn btn-success" disabled>Failed</button>`
|
||||||
|
setTimeout(() => {
|
||||||
|
document.getElementById('aurora-store-btn').outerHTML =
|
||||||
|
`<button type="button btn-success" id="aurora-store-btn" onclick="install_aurora_store()"
|
||||||
|
class="btn btn-success">Install</button>`
|
||||||
|
}, 2000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_f_droid() {
|
||||||
|
document.getElementById('f-droid-btn').outerHTML =
|
||||||
|
`<button type="button" id="f-droid-btn" onclick="install_f_droid()"
|
||||||
|
class="btn btn-primary" disabled>Installing...</button>`
|
||||||
|
let f_droid_worker = new Worker(
|
||||||
|
`data:text/javascript,
|
||||||
|
require('child_process').spawnSync('sh', ['-c', 'mkdir -p ~/.cache/blend-settings; rm -f ~/.cache/blend-settings/f-droid.apk'])
|
||||||
|
let s1 = require('child_process').spawnSync('sh', ['-c', 'wget -O ~/.cache/blend-settings/f-droid.apk https://f-droid.org/F-Droid.apk']).status
|
||||||
|
if (s1 != 0) {
|
||||||
|
postMessage('failed')
|
||||||
|
} else {
|
||||||
|
require('child_process').spawn('waydroid', ['session', 'start'])
|
||||||
|
setTimeout(() => {
|
||||||
|
require('child_process').spawnSync('sh', ['-c', 'waydroid app install ~/.cache/blend-settings/f-droid.apk'])
|
||||||
|
setTimeout(() => postMessage('success'), 200)
|
||||||
|
}, 2000)
|
||||||
|
}
|
||||||
|
`
|
||||||
|
)
|
||||||
|
f_droid_worker.onmessage = e => {
|
||||||
|
if (e.data == 'success') {
|
||||||
|
document.getElementById('f-droid-btn').outerHTML =
|
||||||
|
`<button type="button btn-success" id="fdroid-btn" onclick="require('child_process').spawn('waydroid', ['app', 'launch', 'org.fdroid.fdroid'])"
|
||||||
|
class="btn btn-primary">Open</button>`
|
||||||
|
} else if (e.data == 'failed') {
|
||||||
|
document.getElementById('f-droid-btn').outerHTML =
|
||||||
|
`<button type="button btn-success" id="f-droid-btn" onclick="install_f_droid()"
|
||||||
|
class="btn btn-primary" disabled>Failed</button>`
|
||||||
|
setTimeout(() => {
|
||||||
|
document.getElementById('f-droid-btn').outerHTML =
|
||||||
|
`<button type="button btn-success" id="f-droid-btn" onclick="install_f_droid()"
|
||||||
|
class="btn btn-primary">Install</button>`
|
||||||
|
}, 2000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function waydroid_open_settings() {
|
||||||
|
require('child_process').spawn('waydroid', ['app', 'launch', 'com.android.settings'])
|
||||||
|
}
|
||||||
|
|
||||||
|
require('fs').stat('/var/lib/waydroid/waydroid.prop', (err, stat) => {
|
||||||
|
if (err == null) {
|
||||||
|
document.getElementById('waydroid-initialize-settings').classList.add('d-none')
|
||||||
|
document.getElementById('waydroid-initialized-settings').classList.remove('d-none')
|
||||||
|
if (require('child_process').spawnSync('sh', ['-c', 'LC_ALL=C lspci']).stdout.includes('NVIDIA')) {
|
||||||
|
document.getElementById('nvidia-warning-installed').classList.remove('d-none')
|
||||||
|
}
|
||||||
|
require('child_process').spawn('waydroid', ['session', 'start'])
|
||||||
|
setTimeout(() => {
|
||||||
|
if (require('child_process').spawnSync('waydroid', ['app', 'list']).stdout.includes('com.aurora.store')) {
|
||||||
|
document.getElementById('aurora-store-btn').outerHTML =
|
||||||
|
`<button type="button btn-success" id="aurora-store-btn" onclick="require('child_process').spawn('waydroid', ['app', 'launch', 'com.aurora.store'])"
|
||||||
|
class="btn btn-success">Open</button>`
|
||||||
|
} else {
|
||||||
|
document.getElementById('aurora-store-btn').outerHTML =
|
||||||
|
`<button type="button btn-success" id="aurora-store-btn" onclick="install_aurora_store()"
|
||||||
|
class="btn btn-success">Install</button>`
|
||||||
|
}
|
||||||
|
if (require('child_process').spawnSync('waydroid', ['app', 'list']).stdout.includes('org.fdroid.fdroid')) {
|
||||||
|
document.getElementById('f-droid-btn').outerHTML =
|
||||||
|
`<button type="button btn-success" id="fdroid-btn" onclick="require('child_process').spawn('waydroid', ['app', 'launch', 'org.fdroid.fdroid'])"
|
||||||
|
class="btn btn-primary">Open</button>`
|
||||||
|
} else {
|
||||||
|
document.getElementById('f-droid-btn').outerHTML =
|
||||||
|
`<button type="button btn-success" id="f-droid-btn" onclick="install_f_droid()"
|
||||||
|
class="btn btn-primary">Install</button>`
|
||||||
|
}
|
||||||
|
}, 1000)
|
||||||
|
} else {
|
||||||
|
if (require('child_process').spawnSync('sh', ['-c', 'LC_ALL=C lspci']).stdout.includes('NVIDIA')) {
|
||||||
|
document.getElementById('nvidia-warning').classList.remove('d-none')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#automatic-state-toggle').on('change', () => {
|
||||||
|
if (!document.getElementById('automatic-state-toggle').checked) {
|
||||||
|
let enable_autostate_worker = new Worker(
|
||||||
|
`data:text/javascript,
|
||||||
|
let s = require('child_process').spawnSync('pkexec', ['rm', '-f', '/blend/states/.disable_states']).status
|
||||||
|
if (s === 0) {
|
||||||
|
postMessage('success')
|
||||||
|
} else {
|
||||||
|
postMessage('failure')
|
||||||
|
}
|
||||||
|
`
|
||||||
|
)
|
||||||
|
enable_autostate_worker.onmessage = e => {
|
||||||
|
if (e.data == 'success') {
|
||||||
|
document.getElementById('automatic-state-toggle').checked = false
|
||||||
|
} else {
|
||||||
|
document.getElementById('automatic-state-toggle').checked = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let disable_autostate_worker = new Worker(
|
||||||
|
`data:text/javascript,
|
||||||
|
let s = require('child_process').spawnSync('pkexec', ['blend-system', 'toggle-states']).status
|
||||||
|
if (s === 0) {
|
||||||
|
postMessage('success')
|
||||||
|
} else {
|
||||||
|
postMessage('failure')
|
||||||
|
}
|
||||||
|
`
|
||||||
|
)
|
||||||
|
disable_autostate_worker.onmessage = e => {
|
||||||
|
if (e.data == 'success') {
|
||||||
|
document.getElementById('automatic-state-toggle').checked = true
|
||||||
|
} else {
|
||||||
|
document.getElementById('automatic-state-toggle').checked = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
212
blend-settings/src/internal/js/containers.js
Normal file
212
blend-settings/src/internal/js/containers.js
Normal file
|
@ -0,0 +1,212 @@
|
||||||
|
var term
|
||||||
|
|
||||||
|
function open_container(name) {
|
||||||
|
ipc.send("create-term", { 'title': `Container: ${name}`, 'cmd': `BLEND_NO_CHECK=true blend enter -cn ${name}` });
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_container() {
|
||||||
|
$('#inputContainerName').on('input', () => {
|
||||||
|
$('#inputContainerName').get(0).setCustomValidity('')
|
||||||
|
$('#inputContainerName').get(0).reportValidity();
|
||||||
|
})
|
||||||
|
|
||||||
|
container_name = $('#inputContainerName').val()
|
||||||
|
if (!(/^[\w\-]+$/.test(container_name))) {
|
||||||
|
$('#inputContainerName').get(0).setCustomValidity('Container name may only contain alphanumeric characters and dashes (no spaces allowed).')
|
||||||
|
$('#inputContainerName').get(0).reportValidity();
|
||||||
|
return
|
||||||
|
}
|
||||||
|
container_distro = $('#inputContainerDistro').val().toLowerCase().replace(' ', '-')
|
||||||
|
ipc.send("create-term", {
|
||||||
|
'title': `Creating container: ${container_name}`,
|
||||||
|
'cmd': `blend create-container -cn ${container_name} -d ${container_distro} \
|
||||||
|
&& echo -e '\nExiting automatically in 5 seconds.' \
|
||||||
|
|| echo -e '\nContainer creation failed. Exiting automatically in 5 seconds.';
|
||||||
|
sleep 5` })
|
||||||
|
$('#inputContainerName').val('')
|
||||||
|
ipc.on('container-created', () => {
|
||||||
|
worker.postMessage('update-list')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function remove_container(name) {
|
||||||
|
let rm_worker = new Worker(
|
||||||
|
`data:text/javascript,
|
||||||
|
require('child_process').spawnSync('podman', ['stop', '-t', '0', '${name}'], { encoding: 'utf8' })
|
||||||
|
require('child_process').spawnSync('blend', ['remove-container', '${name}'], { encoding: 'utf8' })
|
||||||
|
postMessage('')
|
||||||
|
`
|
||||||
|
)
|
||||||
|
rm_worker.onmessage = e => worker.postMessage('update-list')
|
||||||
|
}
|
||||||
|
|
||||||
|
window.worker = new Worker(
|
||||||
|
`data:text/javascript,
|
||||||
|
function list_containers() {
|
||||||
|
return require('child_process').spawnSync('podman', ['ps', '-a', '--no-trunc', '--size', '--format', '{{.Names}}'], { encoding: 'utf8' }).stdout.split(/\\r?\\n/).filter(Boolean).reverse();
|
||||||
|
}
|
||||||
|
|
||||||
|
function truncateText(text, maxLength=30) {
|
||||||
|
let truncated = text
|
||||||
|
|
||||||
|
if (truncated.length > maxLength) {
|
||||||
|
truncated = truncated.substr(0, maxLength) + '...';
|
||||||
|
}
|
||||||
|
|
||||||
|
return truncated;
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_container_list() {
|
||||||
|
container_list = list_containers()
|
||||||
|
|
||||||
|
container_list_html_default = \`
|
||||||
|
<div class="list-group-item">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col">
|
||||||
|
<strong class="mb-0">No containers present.</strong>
|
||||||
|
<p class="text-muted mb-0">Create one from above.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
\`
|
||||||
|
|
||||||
|
container_list_html = ''
|
||||||
|
|
||||||
|
container_list.forEach(container => {
|
||||||
|
container_list_html += \`
|
||||||
|
<div class="list-group-item" style="padding: 11px 20px 11px 20px; border: 0.5px solid rgba(255, 255, 255, 0.05);">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col">
|
||||||
|
<strong class="mb-0 container_name">\${container}</strong>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-play" viewBox="0 0 16 16" onclick="open_container('\${container}')" style="cursor: pointer; margin-right: 8px;">
|
||||||
|
<path d="M10.804 8 5 4.633v6.734L10.804 8zm.792-.696a.802.802 0 0 1 0 1.392l-6.363 3.692C4.713 12.69 4 12.345 4 11.692V4.308c0-.653.713-.998 1.233-.696l6.363 3.692z"/>
|
||||||
|
</svg>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16" onclick="remove_container('\${container}')" style="cursor: pointer; z-index: 10;">
|
||||||
|
<path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
|
||||||
|
<path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
\`
|
||||||
|
});
|
||||||
|
|
||||||
|
if (container_list.length == 0) {
|
||||||
|
postMessage(container_list_html_default)
|
||||||
|
} else {
|
||||||
|
postMessage(container_list_html)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.onmessage = msg => {
|
||||||
|
switch(msg) {
|
||||||
|
case 'update-list':
|
||||||
|
update_container_list()
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
update_container_list()
|
||||||
|
}
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
worker.postMessage('update-list')
|
||||||
|
|
||||||
|
worker.onmessage = function (event) {
|
||||||
|
window.data = event.data
|
||||||
|
$('#container-list').html(event.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_association() {
|
||||||
|
$('#inputAssociationContainerName').on('input', () => {
|
||||||
|
$('#inputAssociationContainerName').get(0).setCustomValidity('')
|
||||||
|
$('#inputAssociationContainerName').get(0).reportValidity();
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#inputAssociationBinaryName').on('input', () => {
|
||||||
|
$('#inputAssociationBinaryName').get(0).setCustomValidity('')
|
||||||
|
$('#inputAssociationBinaryName').get(0).reportValidity();
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!(/^[\w\-]+$/.test($('#inputAssociationContainerName').val()))) {
|
||||||
|
$('#inputAssociationContainerName').get(0).setCustomValidity('Container name may only contain alphanumeric characters and dashes (no spaces allowed).')
|
||||||
|
$('#inputAssociationContainerName').get(0).reportValidity();
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(/^[\w\-]+$/.test($('#inputAssociationBinaryName').val()))) {
|
||||||
|
$('#inputAssociationBinaryName').get(0).setCustomValidity('Binary name may only contain alphanumeric characters and dashes (no spaces allowed).')
|
||||||
|
$('#inputAssociationBinaryName').get(0).reportValidity();
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (binary_names.includes($('#inputAssociationBinaryName').val())) {
|
||||||
|
$('#inputAssociationBinaryName').get(0).setCustomValidity('Association already exists.')
|
||||||
|
$('#inputAssociationBinaryName').get(0).reportValidity();
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.appendFile(require('os').homedir() + '/.local/bin/blend_bin/.associations', `${$('#inputAssociationBinaryName').val()}\0${$('#inputAssociationContainerName').val()}\n`, err => {
|
||||||
|
require('child_process').spawnSync('ln', ['-sf', $('#inputAssociationBinaryName').val() + '.' + $('#inputAssociationContainerName').val(), require('os').homedir() + '/.local/bin/blend_bin/' + $('#inputAssociationBinaryName').val()])
|
||||||
|
update_association_list()
|
||||||
|
$('#inputAssociationContainerName').val('')
|
||||||
|
$('#inputAssociationBinaryName').val('')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove_association(binary_name) {
|
||||||
|
require('child_process').spawnSync('bash', ['-c', `sed -i 's/^${binary_name}\\x0//g' ~/.local/bin/blend_bin/.associations`])
|
||||||
|
require('child_process').spawnSync('rm', ['-f', require('os').homedir() + '/.local/bin/blend_bin/' + binary_name])
|
||||||
|
update_association_list()
|
||||||
|
}
|
||||||
|
|
||||||
|
var binary_names = []
|
||||||
|
|
||||||
|
function update_association_list() {
|
||||||
|
require('fs').readFile(require('os').homedir() + '/.local/bin/blend_bin/.associations', 'utf8', (err, data) => {
|
||||||
|
let association_list_html = ''
|
||||||
|
binary_names = []
|
||||||
|
|
||||||
|
data.split('\n').forEach(line => {
|
||||||
|
if (line.includes('\0')) {
|
||||||
|
let binary_name = line.split('\0')[0]
|
||||||
|
binary_names.push(binary_name)
|
||||||
|
let container_name = line.split('\0')[1]
|
||||||
|
console.log(binary_name, container_name)
|
||||||
|
association_list_html += `
|
||||||
|
<div class="list-group-item" style="padding: 11px 20px 11px 20px; border: 0.5px solid rgba(255, 255, 255, 0.05);">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col">
|
||||||
|
<strong class="mb-0 container_name">${binary_name} <span style="padding-left: 20px; padding-right: 20px;">→</span> ${container_name}</strong>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16" onclick="remove_association('${binary_name}')" style="cursor: pointer; z-index: 10;">
|
||||||
|
<path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/>
|
||||||
|
<path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (association_list_html != '') {
|
||||||
|
$('#association-list').html(association_list_html)
|
||||||
|
} else {
|
||||||
|
$('#association-list').html(`
|
||||||
|
<div class="list-group-item">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col">
|
||||||
|
<strong class="mb-0">No associations.</strong>
|
||||||
|
<p class="text-muted mb-0">Add one from above. It's recommended to add associations for each of the supported package managers for easier usage (apt, pacman and dnf).</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
update_association_list()
|
15
blend-settings/src/internal/js/generic_page.js
Normal file
15
blend-settings/src/internal/js/generic_page.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
if (typeof variable !== typeof undefined) {
|
||||||
|
Sortable = undefined
|
||||||
|
} else {
|
||||||
|
window.Sortable = require('sortablejs')
|
||||||
|
}
|
||||||
|
|
||||||
|
function truncateText(text, maxLength=30) {
|
||||||
|
let truncated = text
|
||||||
|
|
||||||
|
if (truncated.length > maxLength) {
|
||||||
|
truncated = truncated.substr(0, maxLength) + '...';
|
||||||
|
}
|
||||||
|
|
||||||
|
return truncated;
|
||||||
|
}
|
106
blend-settings/src/internal/js/system.js
Normal file
106
blend-settings/src/internal/js/system.js
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
function update_system() {
|
||||||
|
let start_update_worker = new Worker(
|
||||||
|
`data:text/javascript,
|
||||||
|
let s = require('child_process').spawnSync('pkexec', ['systemctl', 'start', 'akshara-system-update']).status
|
||||||
|
if (s === 0) {
|
||||||
|
postMessage('success')
|
||||||
|
} else {
|
||||||
|
postMessage('failure')
|
||||||
|
}
|
||||||
|
`
|
||||||
|
)
|
||||||
|
start_update_worker.onmessage = e => {
|
||||||
|
if (e.data == 'success') {
|
||||||
|
document.getElementById('update-btn').textContent = 'Updating...'
|
||||||
|
document.getElementById('update-btn').disabled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_system_update() {
|
||||||
|
if (require('fs').existsSync('/.update')) {
|
||||||
|
document.getElementById('update-btn').onclick = () => {
|
||||||
|
require('child_process').spawnSync('reboot')
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('update-btn').textContent = 'Reboot'
|
||||||
|
document.getElementById('update-btn').disabled = false
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let start_update_worker = new Worker(
|
||||||
|
`data:text/javascript,
|
||||||
|
let s = require('child_process').spawnSync('systemctl', ['is-active', '--quiet', 'akshara-system-update']).status
|
||||||
|
if (s === 0) {
|
||||||
|
postMessage('success')
|
||||||
|
} else {
|
||||||
|
postMessage('failure')
|
||||||
|
}
|
||||||
|
`
|
||||||
|
)
|
||||||
|
start_update_worker.onmessage = e => {
|
||||||
|
if (e.data == 'success') {
|
||||||
|
document.getElementById('update-btn').textContent = 'Updating...'
|
||||||
|
document.getElementById('update-btn').disabled = true
|
||||||
|
} else {
|
||||||
|
document.getElementById('update-btn').textContent = 'Update'
|
||||||
|
document.getElementById('update-btn').disabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
check_system_update()
|
||||||
|
setInterval(check_system_update, 5000)
|
||||||
|
|
||||||
|
// function check_app_grouping() {
|
||||||
|
// if (require('fs').existsSync(`${require('os').homedir()}/.config/categorize_apps_gnome_disable`)) {
|
||||||
|
// document.getElementById('app-grouping-toggle').setAttribute('checked', '')
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// check_app_grouping()
|
||||||
|
|
||||||
|
// $('#app-grouping-toggle').on('change', () => {
|
||||||
|
// if (!document.getElementById('app-grouping-toggle').checked) {
|
||||||
|
// let enable_autogrouping_worker = new Worker(
|
||||||
|
// `data:text/javascript,
|
||||||
|
// let s = require('child_process').spawnSync('rm', ['-f', '${require('os').homedir()}/.config/categorize_apps_gnome_disable']).status
|
||||||
|
// if (s === 0) {
|
||||||
|
// postMessage('success')
|
||||||
|
// } else {
|
||||||
|
// postMessage('failure')
|
||||||
|
// }
|
||||||
|
// `
|
||||||
|
// )
|
||||||
|
// enable_autogrouping_worker.onmessage = e => {
|
||||||
|
// if (e.data == 'success') {
|
||||||
|
// document.getElementById('app-grouping-toggle').checked = false
|
||||||
|
// } else {
|
||||||
|
// document.getElementById('app-grouping-toggle').checked = true
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// let disable_autogrouping_worker = new Worker(
|
||||||
|
// `data:text/javascript,
|
||||||
|
// require('child_process').spawnSync('mkdir', ['-p', '${require('os').homedir()}/.config']).status
|
||||||
|
// let s = require('child_process').spawnSync('touch', ['${require('os').homedir()}/.config/categorize_apps_gnome_disable']).status
|
||||||
|
// if (s === 0) {
|
||||||
|
// postMessage('success')
|
||||||
|
// } else {
|
||||||
|
// postMessage('failure')
|
||||||
|
// }
|
||||||
|
// `
|
||||||
|
// )
|
||||||
|
// disable_autogrouping_worker.onmessage = e => {
|
||||||
|
// if (e.data == 'success') {
|
||||||
|
// document.getElementById('app-grouping-toggle').checked = true
|
||||||
|
// } else {
|
||||||
|
// document.getElementById('app-grouping-toggle').checked = false
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
// if (require('process').env.XDG_CURRENT_DESKTOP.includes('GNOME')) {
|
||||||
|
// $('#app-grouping-item').removeClass('d-none')
|
||||||
|
// }
|
167
blend-settings/src/package-installer.html
Normal file
167
blend-settings/src/package-installer.html
Normal file
|
@ -0,0 +1,167 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Package Installer</title>
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
user-select: none !important;
|
||||||
|
-webkit-user-drag: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
head,
|
||||||
|
body {
|
||||||
|
background-color: #EBEBEB;
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
font-family: 'Cantarell';
|
||||||
|
}
|
||||||
|
|
||||||
|
.center {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.padding {
|
||||||
|
margin: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-weight: 900;
|
||||||
|
font-size: 2.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
background-color: #3584E4;
|
||||||
|
border-style: none;
|
||||||
|
border-radius: 50px;
|
||||||
|
color: white;
|
||||||
|
font-family: 'Cantarell';
|
||||||
|
font-weight: 600;
|
||||||
|
padding: 15px 25px 15px 25px;
|
||||||
|
font-size: 20px;
|
||||||
|
|
||||||
|
transition: 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:disabled {
|
||||||
|
background-color: #619cdf;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 0 8px 0 8px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 1.05rem;
|
||||||
|
line-height: 150%;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:hover {
|
||||||
|
cursor: default;
|
||||||
|
background-color: #3271be;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="center">
|
||||||
|
<h1>Package Installer</h1>
|
||||||
|
|
||||||
|
<div class="padding"></div>
|
||||||
|
|
||||||
|
<img id="packaging-format" width="120px">
|
||||||
|
|
||||||
|
<div class="padding"></div>
|
||||||
|
|
||||||
|
<button id="install-button" onclick="install_package()">Install package</button>
|
||||||
|
|
||||||
|
<div class="padding"></div>
|
||||||
|
|
||||||
|
<select id="source_select"></select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const ipc = require('electron').ipcRenderer
|
||||||
|
|
||||||
|
package_name = require('path').basename(require('@electron/remote').process.argv[3])
|
||||||
|
package_type = 'deb'
|
||||||
|
|
||||||
|
if (package_name.endsWith('.deb')) {
|
||||||
|
document.getElementById('packaging-format').src = '../static/DEB.svg'
|
||||||
|
package_type = 'deb'
|
||||||
|
|
||||||
|
document.getElementById('source_select').innerHTML = `
|
||||||
|
<option>Debian</option>
|
||||||
|
<option>Ubuntu 22.04</option>
|
||||||
|
`
|
||||||
|
} else if (package_name.endsWith('.rpm')) {
|
||||||
|
document.getElementById('packaging-format').src = '../static/RPM.svg'
|
||||||
|
package_type = 'rpm'
|
||||||
|
document.getElementById('source_select').innerHTML = `
|
||||||
|
<option>Fedora 39</option>
|
||||||
|
<option>CentOS</option>
|
||||||
|
`
|
||||||
|
} else if (package_name.endsWith('.apk')) {
|
||||||
|
document.getElementById('packaging-format').src = '../static/APK.svg'
|
||||||
|
package_type = 'apk'
|
||||||
|
document.getElementById('source_select').outerHTML = ''
|
||||||
|
|
||||||
|
require('fs').stat('/var/lib/waydroid/waydroid.prop', (err, stat) => {
|
||||||
|
if (err != null) {
|
||||||
|
document.getElementById('install-button').outerHTML = "<p>You'll need to initialize Android app support from the <b>System</b> app first.</p>"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if (package_name.includes('.pkg.tar')) {
|
||||||
|
document.getElementById('packaging-format').src = '../static/PKG.svg'
|
||||||
|
package_type = 'pkg'
|
||||||
|
document.getElementById('source_select').innerHTML = `
|
||||||
|
<option>Arch Linux</option>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_package() {
|
||||||
|
if (package_type == 'apk') {
|
||||||
|
document.getElementById('install-button').disabled = true
|
||||||
|
require('child_process').spawnSync('waydroid', ['app', 'install', require('@electron/remote').process.argv[3]])
|
||||||
|
document.getElementById('install-button').innerHTML = 'Installed'
|
||||||
|
require('child_process').spawnSync('rm', ['-rf', install_dir])
|
||||||
|
} else {
|
||||||
|
package_source = document.getElementById('source_select').options[document.getElementById('source_select').selectedIndex].text.toLowerCase().replace(' ', '-')
|
||||||
|
timestamp = Math.floor(new Date().getTime() / 1000)
|
||||||
|
install_dir = `${require('os').homedir()}/.cache/package-installer/${timestamp}`
|
||||||
|
require('child_process').spawnSync('mkdir', ['-p', install_dir])
|
||||||
|
require('child_process').spawnSync('cp', [require('@electron/remote').process.argv[3], install_dir])
|
||||||
|
install_command = ''
|
||||||
|
if (package_type == 'deb') {
|
||||||
|
install_command = `apt install -y ${install_dir}/${package_name}`
|
||||||
|
} else if (package_type == 'rpm') {
|
||||||
|
install_command = `dnf install -y ${install_dir}/${package_name}`
|
||||||
|
} else if (package_type == 'pkg') {
|
||||||
|
install_command = `pacman -U --noconfirm ${install_dir}/${package_name}`
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('install-button').disabled = true
|
||||||
|
|
||||||
|
if (!require('child_process').spawnSync('podman', ['container', 'exists', package_source]).status) {
|
||||||
|
ipc.send("create-term", { 'title': `Package installation`, 'cmd': `sudo.${package_source} ${install_command} && echo -e '\\nInstallation was successful.' || echo -e '\\nInstallation was unsuccessful.'; sleep 5` });
|
||||||
|
} else {
|
||||||
|
ipc.send("create-term", { 'title': `Package installation`, 'cmd': `blend create-container -cn ${package_source} -d ${package_source}; (sudo.${package_source} ${install_command} && echo -e '\\nInstallation was successful.' || echo -e '\\nInstallation was unsuccessful.'; sleep 5)` });
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('install-button').innerHTML = 'Installing'
|
||||||
|
|
||||||
|
ipc.on('installation-complete', () => {
|
||||||
|
document.getElementById('install-button').innerHTML = 'Installed'
|
||||||
|
require('child_process').spawnSync('rm', ['-rf', install_dir])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
77
blend-settings/src/pages/android.html
Normal file
77
blend-settings/src/pages/android.html
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
<div class="container-fluid d-flex justify-content-center">
|
||||||
|
<div class="col-12 col-lg-10 col-xl-8 mx-auto">
|
||||||
|
<div id="waydroid-initialize-settings">
|
||||||
|
<div class="list-group mt-3 mb-5" id="waydroid-initialize-settings">
|
||||||
|
<div class="list-group-item shadow">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col">
|
||||||
|
<strong class="mb-0">Initialize Android app support</strong>
|
||||||
|
<p class="text-muted mb-0">You may be asked to enter your password repeatedly to initialize WayDroid.</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<div class="form-check form-switch align-middle">
|
||||||
|
<button type="button" id="initialize-btn" onclick="init_waydroid()"
|
||||||
|
class="btn btn-primary">Initialize</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<p id="nvidia-warning" class="d-none">Since you're using an <b style="color: lightgreen;">NVIDIA</b> GPU,
|
||||||
|
Android apps will use software rendering.</p>
|
||||||
|
<p>After initializing WayDroid, you can install a store (or many) of your choice.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="d-none" id="waydroid-initialized-settings">
|
||||||
|
<p>Android app support (WayDroid) has successfully been initialized.<span id="first-time-waydroid" class="d-none"> It's
|
||||||
|
recomended to reboot before using or installing Android apps/stores.</span><span id="nvidia-warning-installed" class="d-none"> Since you're using an <b
|
||||||
|
style="color: lightgreen;">NVIDIA</b> GPU, apps will use software
|
||||||
|
rendering.</span></p>
|
||||||
|
<strong>Install a store</strong>
|
||||||
|
<div class="list-group mt-3 mb-4 shadow">
|
||||||
|
<div>
|
||||||
|
<div class="list-group-item" id="aurora-store-item">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col">
|
||||||
|
<strong class="mb-0">Aurora Store</strong>
|
||||||
|
<p class="text-muted mb-0">An open-source Google Play Store client.</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<div class="form-check form-switch align-middle">
|
||||||
|
<button type="button" id="aurora-store-btn" onclick="install_aurora_store()" class="btn btn-success"
|
||||||
|
disabled>Checking status...</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="list-group-item" id="f-droid-item">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col">
|
||||||
|
<strong class="mb-0">F-Droid</strong>
|
||||||
|
<p class="text-muted mb-0">An installable catalogue of FOSS Android applications.</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<div class="form-check form-switch align-middle">
|
||||||
|
<button type="button" id="f-droid-btn" onclick="install_f_droid()" class="btn btn-primary"
|
||||||
|
disabled>Checking status...</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button type="button" onclick="waydroid_open_settings()" class="btn btn-primary">Open Settings</button>
|
||||||
|
<br><br>
|
||||||
|
<strong>Useful information</strong>
|
||||||
|
<p>In the event that an app you regularly use on your phone is broken on blendOS, you could install MicroG from
|
||||||
|
F-Droid by following the instructions <a href="javascript:void()"
|
||||||
|
onclick="require('electron').shell.openExternal('https://microg.org/download.html')">here</a>.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Import generic page JS. -->
|
||||||
|
<script src="internal/js/generic_page.js"></script>
|
||||||
|
|
||||||
|
<!-- Import overlay JS. -->
|
||||||
|
<script src="internal/js/android.js"></script>
|
69
blend-settings/src/pages/containers.html
Normal file
69
blend-settings/src/pages/containers.html
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
<div class="container-fluid d-flex justify-content-center">
|
||||||
|
<div class="col-12 col-lg-10 col-xl-8 mx-auto">
|
||||||
|
<strong class="mb-0">Containers</strong>
|
||||||
|
<p>Installed apps will appear in the application launcher. Binaries can be executed with the container's name as a suffix. For example, <b>apt</b> -> <b>apt.ubuntu</b>, in a container named 'ubuntu'.</p>
|
||||||
|
<form onsubmit="create_container(); return false">
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="col-sm-4"></div>
|
||||||
|
<div class="col-sm-3">
|
||||||
|
<input type="text" class="form-control" id="inputContainerName" placeholder="Container name" required>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
<select class="form-control" id="inputContainerDistro">
|
||||||
|
<option selected>Arch Linux</option>
|
||||||
|
<option>Debian</option>
|
||||||
|
<option>CentOS</option>
|
||||||
|
<option>Fedora 39</option>
|
||||||
|
<option>Ubuntu 22.04</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-1">
|
||||||
|
<button type="submit" class="btn btn-success"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-plus" viewBox="0 0 16 16">
|
||||||
|
<path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z"/>
|
||||||
|
</svg></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div class="list-group mb-4 shadow" id="container-list">
|
||||||
|
<div class="list-group-item">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col">
|
||||||
|
<strong class="mb-0">Loading list of containers.</strong>
|
||||||
|
<p class="text-muted mb-0">You'll find a list of all the containers here.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container-fluid d-flex justify-content-center">
|
||||||
|
<div class="col-12 col-lg-10 col-xl-8 mx-auto">
|
||||||
|
<strong class="mb-0">Associations</strong>
|
||||||
|
<p>You can associate a binary to a container so as to use it without a suffix.</p>
|
||||||
|
<form onsubmit="create_association(); return false">
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="col-sm-4"></div>
|
||||||
|
<div class="col-sm-3">
|
||||||
|
<input type="text" class="form-control" id="inputAssociationBinaryName" placeholder="Binary name" required>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-4">
|
||||||
|
<input type="text" class="form-control" id="inputAssociationContainerName" placeholder="Container name" required>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm-1">
|
||||||
|
<button type="submit" class="btn btn-success"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-plus" viewBox="0 0 16 16">
|
||||||
|
<path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z"/>
|
||||||
|
</svg></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div class="list-group mb-4 shadow" id="association-list">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Import generic page JS. -->
|
||||||
|
<script src="internal/js/generic_page.js"></script>
|
||||||
|
|
||||||
|
<!-- Import containers JS. -->
|
||||||
|
<script src="internal/js/containers.js"></script>
|
30
blend-settings/src/pages/system.html
Normal file
30
blend-settings/src/pages/system.html
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<div class="container-fluid d-flex justify-content-center">
|
||||||
|
<div class="col-12 col-lg-10 col-xl-8 mx-auto">
|
||||||
|
<strong class="mb-0">System Updates</strong>
|
||||||
|
<div style="height: 0.75rem;"></div>
|
||||||
|
<div class="list-group mb-3 shadow">
|
||||||
|
<div class="list-group-item" id="system-update-item">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col">
|
||||||
|
<strong class="mb-0">Update system</strong>
|
||||||
|
<p class="text-muted mb-0">
|
||||||
|
Checks for updates, and updates your computer if they're available.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<div class="form-check form-switch align-middle">
|
||||||
|
<button type="button" id="update-btn" onclick="update_system()"
|
||||||
|
class="btn btn-primary" disabled>Checking...</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Import generic page JS. -->
|
||||||
|
<script src="internal/js/generic_page.js"></script>
|
||||||
|
|
||||||
|
<!-- Import overlay JS. -->
|
||||||
|
<script src="internal/js/system.js"></script>
|
127
blend-settings/src/pages/terminal.html
Normal file
127
blend-settings/src/pages/terminal.html
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" href="../../node_modules/xterm/css/xterm.css" />
|
||||||
|
<style>
|
||||||
|
html,
|
||||||
|
body,
|
||||||
|
#term {
|
||||||
|
margin: 0;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
background-color: #242430;
|
||||||
|
}
|
||||||
|
|
||||||
|
.xterm {
|
||||||
|
padding: 30px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
*,
|
||||||
|
*::before,
|
||||||
|
*::after {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
*::-webkit-scrollbar-track {
|
||||||
|
background-color: rgb(36, 36, 48);
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
*::-webkit-scrollbar {
|
||||||
|
width: 5px;
|
||||||
|
background-color: rgb(36, 36, 48);
|
||||||
|
}
|
||||||
|
|
||||||
|
*::-webkit-scrollbar-thumb {
|
||||||
|
background-color: rgb(61, 61, 74);
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body style="height: 100%;">
|
||||||
|
<div id="term" style="height: 100%; width: 100%;"></div>
|
||||||
|
<script>
|
||||||
|
var os = require("os");
|
||||||
|
var pty = require("node-pty");
|
||||||
|
var xterm = require("xterm");
|
||||||
|
var ipc = require("electron").ipcRenderer;
|
||||||
|
var { FitAddon } = require("xterm-addon-fit");
|
||||||
|
|
||||||
|
const fit = new FitAddon();
|
||||||
|
|
||||||
|
var once;
|
||||||
|
|
||||||
|
function create_term() {
|
||||||
|
ipc.removeAllListeners('terminal.reset')
|
||||||
|
ipc.removeAllListeners('terminal.resize')
|
||||||
|
ipc.removeAllListeners('terminal.keystroke')
|
||||||
|
ipc.removeAllListeners('terminal.incomingData')
|
||||||
|
ipc.removeAllListeners('title')
|
||||||
|
|
||||||
|
ipc.on("terminal.reset", (event, data) => {
|
||||||
|
document.getElementById('term').innerHTML = ''
|
||||||
|
create_term()
|
||||||
|
});
|
||||||
|
|
||||||
|
var term = new xterm.Terminal({
|
||||||
|
fontSize: 14,
|
||||||
|
experimentalCharAtlas: 'dynamic',
|
||||||
|
theme: {
|
||||||
|
background: '#242430'
|
||||||
|
},
|
||||||
|
fontFamily: 'JetBrains Mono'
|
||||||
|
});
|
||||||
|
|
||||||
|
once = true
|
||||||
|
|
||||||
|
term.loadAddon(fit)
|
||||||
|
|
||||||
|
term.attachCustomKeyEventHandler((arg) => {
|
||||||
|
if (arg.ctrlKey && arg.shiftKey && arg.code === "KeyC" && arg.type === "keydown") {
|
||||||
|
const selection = term.getSelection();
|
||||||
|
if (selection) {
|
||||||
|
navigator.clipboard.writeText(selection);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
var term_e = document.getElementById('term');
|
||||||
|
term.open(term_e);
|
||||||
|
fit.fit()
|
||||||
|
|
||||||
|
ipc.on("terminal.incomingData", (event, data) => {
|
||||||
|
fit.fit();
|
||||||
|
term.resize(term.cols, term.rows)
|
||||||
|
ipc.send("terminal.resize", [term.cols, term.rows])
|
||||||
|
|
||||||
|
term.write(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
ipc.on("title", (event, title) => {
|
||||||
|
document.title = title;
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('beforeunload', (event) => {
|
||||||
|
term.dispose()
|
||||||
|
})
|
||||||
|
|
||||||
|
window.onresize = function () {
|
||||||
|
fit.fit();
|
||||||
|
term.resize(term.cols, term.rows)
|
||||||
|
ipc.send("terminal.resize", [term.cols, term.rows])
|
||||||
|
};
|
||||||
|
|
||||||
|
term.onData(e => {
|
||||||
|
ipc.send("terminal.keystroke", e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ipc.on("terminal.reset", (event) => create_term)
|
||||||
|
create_term()
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
0
blend-settings/src/preload.js
Normal file
0
blend-settings/src/preload.js
Normal file
1
blend-settings/static/APK.svg
Normal file
1
blend-settings/static/APK.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 7.9 KiB |
1
blend-settings/static/DEB.svg
Normal file
1
blend-settings/static/DEB.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 8 KiB |
1
blend-settings/static/RPM.svg
Normal file
1
blend-settings/static/RPM.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 17 KiB |
BIN
blend-settings/static/icon.png
Normal file
BIN
blend-settings/static/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 46 KiB |
153
blend-system
Executable file
153
blend-system
Executable file
|
@ -0,0 +1,153 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
# Copyright (C) 2023 Rudra Saraswat
|
||||||
|
#
|
||||||
|
# This file is part of blend.
|
||||||
|
#
|
||||||
|
# blend 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.
|
||||||
|
#
|
||||||
|
# blend 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 blend. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
import os, re, sys, time
|
||||||
|
import argparse
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
__version = '2.0.0'
|
||||||
|
|
||||||
|
### Colors
|
||||||
|
class colors:
|
||||||
|
reset = '\033[0m'
|
||||||
|
bold = '\033[01m'
|
||||||
|
disable = '\033[02m'
|
||||||
|
underline = '\033[04m'
|
||||||
|
reverse = '\033[07m'
|
||||||
|
strikethrough = '\033[09m'
|
||||||
|
invisible = '\033[08m'
|
||||||
|
|
||||||
|
class fg:
|
||||||
|
black = '\033[30m'
|
||||||
|
red = '\033[31m'
|
||||||
|
green = '\033[32m'
|
||||||
|
orange = '\033[33m'
|
||||||
|
blue = '\033[34m'
|
||||||
|
purple = '\033[35m'
|
||||||
|
cyan = '\033[36m'
|
||||||
|
lightgrey = '\033[37m'
|
||||||
|
darkgrey = '\033[90m'
|
||||||
|
lightred = '\033[91m'
|
||||||
|
lightgreen = '\033[92m'
|
||||||
|
yellow = '\033[93m'
|
||||||
|
lightblue = '\033[94m'
|
||||||
|
pink = '\033[95m'
|
||||||
|
lightcyan = '\033[96m'
|
||||||
|
|
||||||
|
class bg:
|
||||||
|
black = '\033[40m'
|
||||||
|
red = '\033[41m'
|
||||||
|
green = '\033[42m'
|
||||||
|
orange = '\033[43m'
|
||||||
|
blue = '\033[44m'
|
||||||
|
purple = '\033[45m'
|
||||||
|
cyan = '\033[46m'
|
||||||
|
lightgrey = '\033[47m'
|
||||||
|
|
||||||
|
### END
|
||||||
|
|
||||||
|
### Helper functions
|
||||||
|
|
||||||
|
def info(msg):
|
||||||
|
print (colors.bold + colors.fg.cyan + '>> i: ' + colors.reset + colors.bold + msg + colors.reset)
|
||||||
|
|
||||||
|
def error(err):
|
||||||
|
print (colors.bold + colors.fg.red + '>> e: ' + colors.reset + colors.bold + err + colors.reset)
|
||||||
|
|
||||||
|
### END
|
||||||
|
|
||||||
|
def current_state():
|
||||||
|
_state = -1
|
||||||
|
for s in os.listdir('/.states'):
|
||||||
|
if re.match(r'^state([0-9]+)\.squashfs$', s):
|
||||||
|
if int(s[5:-7]) > _state:
|
||||||
|
_state = int(s[5:-7])
|
||||||
|
return _state
|
||||||
|
|
||||||
|
def save_state():
|
||||||
|
subprocess.call(['mkdir', '-p', '/.states'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
state = current_state() + 1
|
||||||
|
|
||||||
|
subprocess.call(['bash', '-c', 'rm -f /.states/*.tmp'])
|
||||||
|
|
||||||
|
if subprocess.call(['mksquashfs', '/usr', f'/.states/state{state}.squashfs.tmp', '-no-compression'], stdout=sys.stdout, stderr=sys.stderr) == 0:
|
||||||
|
subprocess.call(['rm', '-rf', 'add-squashfs'], cwd='/tmp')
|
||||||
|
subprocess.call(['mkdir', '-p', 'add-squashfs'], cwd='/tmp')
|
||||||
|
subprocess.call(['cp', '-a', '/var/lib', 'add-squashfs/varlib'], cwd='/tmp')
|
||||||
|
if subprocess.call(['mksquashfs', 'add-squashfs', f'/.states/state{state}.squashfs.tmp', '-no-compression'], cwd='/tmp') == 0:
|
||||||
|
subprocess.call(['mv', f'/.states/state{state}.squashfs.tmp', f'/.states/state{state}.squashfs'])
|
||||||
|
else:
|
||||||
|
error('state creation failed')
|
||||||
|
exit(1)
|
||||||
|
else:
|
||||||
|
error('state creation failed')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
info(f'saved state {state}')
|
||||||
|
|
||||||
|
def rollback():
|
||||||
|
info("Rollback hasn't been implemented yet.")
|
||||||
|
|
||||||
|
description = f'''
|
||||||
|
{colors.bold}{colors.fg.purple}Usage:{colors.reset}
|
||||||
|
blend-system [command] [options] [arguments]
|
||||||
|
|
||||||
|
{colors.bold}{colors.fg.purple}Version:{colors.reset} {__version}{colors.bold}
|
||||||
|
|
||||||
|
{colors.bold}{colors.fg.purple}available commands{colors.reset}:
|
||||||
|
{colors.bold}help{colors.reset} Show this help message and exit.
|
||||||
|
{colors.bold}version{colors.reset} Show version information and exit.
|
||||||
|
{colors.bold}save-state{colors.reset} Save the current state (backup).
|
||||||
|
{colors.bold}rollback{colors.reset} Rollback to previous state.
|
||||||
|
|
||||||
|
{colors.bold}{colors.fg.purple}options for commands{colors.reset}:
|
||||||
|
{colors.bold}-v, --version{colors.reset} show version information and exit
|
||||||
|
'''
|
||||||
|
|
||||||
|
epilog = f'''
|
||||||
|
{colors.bold}Made with {colors.fg.red}\u2764{colors.reset}{colors.bold} by Rudra Saraswat.{colors.reset}
|
||||||
|
'''
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description=description, usage=argparse.SUPPRESS,
|
||||||
|
epilog=epilog, formatter_class=argparse.RawTextHelpFormatter)
|
||||||
|
command_map = { 'help': 'help',
|
||||||
|
'version': 'version',
|
||||||
|
'save-state': save_state,
|
||||||
|
'rollback': rollback }
|
||||||
|
parser.add_argument('command', choices=command_map.keys(), help=argparse.SUPPRESS)
|
||||||
|
parser.add_argument('-v', '--version', action='version', version=f'%(prog)s {__version}', help=argparse.SUPPRESS)
|
||||||
|
|
||||||
|
if len(sys.argv) == 1:
|
||||||
|
parser.print_help()
|
||||||
|
exit()
|
||||||
|
|
||||||
|
if os.geteuid() != 0:
|
||||||
|
error('requires root')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
args = parser.parse_intermixed_args()
|
||||||
|
|
||||||
|
command = command_map[args.command]
|
||||||
|
|
||||||
|
if command == 'help':
|
||||||
|
parser.print_help()
|
||||||
|
elif command == 'version':
|
||||||
|
parser.parse_args(['--version'])
|
||||||
|
else:
|
||||||
|
command()
|
56
blend.hook
Executable file
56
blend.hook
Executable file
|
@ -0,0 +1,56 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
run_latehook() {
|
||||||
|
echo
|
||||||
|
|
||||||
|
if [[ "$abort_staging" == true ]]; then
|
||||||
|
echo '[ BLEND ] Not applying system changes made in previous boot.'
|
||||||
|
rm -rf '/new_root/.upperdir' '/new_root/.workdir'; mkdir -p '/new_root/.upperdir' '/new_root/.workdir'
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -d "/new_root/blend/overlay/current" ]]; then
|
||||||
|
echo '[ BLEND ] Detected old version of overlay implementation, switching.'
|
||||||
|
rm -rf /new_root/.upperdir /new_root/.workdir
|
||||||
|
mv /new_root/blend/overlay/current/usr /new_root/.upperdir
|
||||||
|
rm -rf /new_root/blend
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Broken attempt at getting rollback and snapshots working.
|
||||||
|
#
|
||||||
|
# if [[ -L "/new_root/.states/rollback.squashfs" ]] && [[ -e "/new_root/.states/rollback.squashfs" ]]; then
|
||||||
|
# echo -n '[ BLEND ] Rolling back to selected state. Do __not__ power off or reboot.'
|
||||||
|
# echo
|
||||||
|
# cd /new_root
|
||||||
|
# unsquashfs /new_root/.states/rollback.squashfs && (
|
||||||
|
# for i in bin include lib lib32 share src; do
|
||||||
|
# rm -rf rm -rf /new_root/.workdir/"$i" rm -rf /new_root/.upperdir/"$i" /new_root/usr/"$i"
|
||||||
|
# mv squashfs-root/"$i" /new_root/usr
|
||||||
|
# done
|
||||||
|
# rm -rf /new_root/.workdir/varlib /new_root/.upperdir/varlib /new_root/var/lib
|
||||||
|
# mkdir -p /new_root/var/lib
|
||||||
|
# mv squashfs-root/varlib /new_root/var/varlib
|
||||||
|
# echo ' - SUCCESS '
|
||||||
|
# echo
|
||||||
|
# ); cd ..
|
||||||
|
# fi
|
||||||
|
|
||||||
|
for i in bin include lib lib32 share src; do
|
||||||
|
echo -n "[ BLEND ] Setting up /usr/${i} overlay (applying changes)."
|
||||||
|
rm -rf /new_root/.workdir/"$i"
|
||||||
|
mkdir -p /new_root/.upperdir/"$i" /new_root/.workdir/"$i" /new_root/usr/"$i" /new_root/tmp
|
||||||
|
cd /new_root/tmp; overlayfs-tools merge -l /new_root/usr/$i -u /new_root/.upperdir/$i &>/dev/null; chmod 755 ./overlay-tools-*; ./overlay-tools-* &>/dev/null; rm -f ./overlay-tools-*; cd /
|
||||||
|
mkdir -p /new_root/.upperdir/"$i"
|
||||||
|
mount -t overlay overlay -o 'lowerdir=/new_root/usr/'$i',upperdir=/new_root/.upperdir/'$i',workdir=/new_root/.workdir/'$i /new_root/usr/"$i" -o index=off
|
||||||
|
echo " - SUCCESS"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo -n "[ BLEND ] Setting up /var/lib overlay (applying changes)."
|
||||||
|
rm -rf /new_root/.workdir/varlib
|
||||||
|
mkdir -p /new_root/.upperdir/varlib /new_root/.workdir/varlib /new_root/var/lib /new_root/tmp
|
||||||
|
cd /new_root/tmp; overlayfs-tools merge -l /new_root/var/lib -u /new_root/.upperdir/varlib &>/dev/null; chmod 755 ./overlay-tools-*; ./overlay-tools-* &>/dev/null; rm -f ./overlay-tools-*; cd /
|
||||||
|
mkdir -p /new_root/.upperdir/varlib
|
||||||
|
mount -t overlay overlay -o 'lowerdir=/new_root/var/lib,upperdir=/new_root/.upperdir/varlib,workdir=/new_root/.workdir/varlib' /new_root/var/lib -o index=off
|
||||||
|
echo ' - SUCCESS'
|
||||||
|
echo
|
||||||
|
}
|
19
blend.install
Normal file
19
blend.install
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# SPDX-License-Identifier: GPL-3.0
|
||||||
|
|
||||||
|
build() {
|
||||||
|
add_module overlay
|
||||||
|
add_binary bash
|
||||||
|
add_binary tar
|
||||||
|
add_binary overlayfs-tools
|
||||||
|
add_runscript
|
||||||
|
}
|
||||||
|
|
||||||
|
help() {
|
||||||
|
cat <<HELPEOF
|
||||||
|
This provides a support for mounting the blend overlays. No
|
||||||
|
configuration is needed.
|
||||||
|
HELPEOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# vim: set ft=sh ts=4 sw=4 et:
|
13
blend.sh
13
blend.sh
|
@ -1,13 +0,0 @@
|
||||||
# https://unix.stackexchange.com/a/217629
|
|
||||||
|
|
||||||
pathmunge () {
|
|
||||||
if ! echo "$PATH" | /bin/grep -Eq "(^|:)$1($|:)" ; then
|
|
||||||
if [ "$2" = "after" ] ; then
|
|
||||||
PATH="$PATH:$1"
|
|
||||||
else
|
|
||||||
PATH="$1:$PATH"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
pathmunge "${HOME}/.local/bin/blend_bin"
|
|
36
host-blend
Executable file
36
host-blend
Executable file
|
@ -0,0 +1,36 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Copyright (C) 2023 Rudra Saraswat
|
||||||
|
#
|
||||||
|
# This file is part of blend.
|
||||||
|
#
|
||||||
|
# blend 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.
|
||||||
|
#
|
||||||
|
# blend 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 blend. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
[ -f /run/.containerenv ] || echo 'not running in a blend container'
|
||||||
|
[ -f /run/.containerenv ] || exit 1
|
||||||
|
|
||||||
|
args=""
|
||||||
|
|
||||||
|
if [ ! -t 1 ] || [ "$(basename $0)" == xdg-open ] || [ "$(basename $0)" == gio ]; then
|
||||||
|
args="${args} --no-pty"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$(basename $0)" == host-blend ]; then
|
||||||
|
if [ "$#" -ne 1 ]; then
|
||||||
|
host-spawn $args sh; exit $?
|
||||||
|
else
|
||||||
|
host-spawn $args "$@"; exit $?
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
host-spawn $args "$(basename $0)" "$@"; exit $?
|
||||||
|
fi
|
461
init-blend
Executable file
461
init-blend
Executable file
|
@ -0,0 +1,461 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copyright (C) 2023 Rudra Saraswat
|
||||||
|
#
|
||||||
|
# This file is part of blend.
|
||||||
|
#
|
||||||
|
# blend 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.
|
||||||
|
#
|
||||||
|
# blend 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 blend. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
if [ ! -f '/run/.containerenv' ]; then
|
||||||
|
echo 'not running in container'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
shopt -s extglob
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
case $1 in
|
||||||
|
--uid)
|
||||||
|
if [ -n "$2" ]; then
|
||||||
|
_cuid="$2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
--group)
|
||||||
|
if [ -n "$2" ]; then
|
||||||
|
_cgid="$2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
--username)
|
||||||
|
if [ -n "$2" ]; then
|
||||||
|
_uname="$2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
--home)
|
||||||
|
if [ -n "$2" ]; then
|
||||||
|
_uhome="$2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
echo 'Starting container... (this may take a few minutes)'
|
||||||
|
echo
|
||||||
|
|
||||||
|
bmount() {
|
||||||
|
! [[ -d "$1" ]] && ! [[ -f "$1" ]] && return 0 # check if source dir exists
|
||||||
|
! [[ -e "$2" ]] && findmnt "$2" &>/dev/null && umount "$2" # unmount target dir if a mount
|
||||||
|
|
||||||
|
[[ -d "$1" ]] && mkdir -p "$2" # create target dir if source is a dir
|
||||||
|
[[ -f "$1" ]] && mkdir -p "$(dirname "$2")"; touch "$2" # create target file if source is a file
|
||||||
|
|
||||||
|
mountflags="rslave"
|
||||||
|
|
||||||
|
! [[ -z "$3" ]] && mountflags="$3"
|
||||||
|
|
||||||
|
mount --rbind -o "$mountflags" "$1" "$2" &>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ ! -f '/.init_blend.lock' ]]; then
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
if command -v apt-get &>/dev/null; then
|
||||||
|
apt-get update &>/dev/null
|
||||||
|
DEBIAN_FRONTEND=noninteractive apt-get -y install bash bc curl less wget apt-utils apt-transport-https dialog \
|
||||||
|
diffutils findutils gnupg2 sudo time util-linux libnss-myhostname \
|
||||||
|
lsof ncurses-base passwd inotify-tools pinentry-curses libegl1-mesa \
|
||||||
|
libgl1-mesa-glx libvulkan1 mesa-vulkan-drivers dbus &>/dev/null
|
||||||
|
|
||||||
|
elif command -v pacman &>/dev/null; then
|
||||||
|
pacman --noconfirm -Syyu &>/dev/null
|
||||||
|
pacman --noconfirm -Sy bash bc curl wget diffutils findutils gnupg sudo time util-linux vte-common lsof ncurses pinentry \
|
||||||
|
mesa opengl-driver vulkan-intel vulkan-radeon base-devel git inotify-tools dbus dbus-broker &>/dev/null
|
||||||
|
|
||||||
|
elif command -v dnf &>/dev/null; then
|
||||||
|
dnf config-manager --set-enabled crb &>/dev/null
|
||||||
|
dnf install -y epel-release &>/dev/null
|
||||||
|
dnf install -y --allowerasing bash bc curl wget diffutils findutils dnf-plugins-core gnupg2 less lsof passwd pinentry \
|
||||||
|
procps-ng vte-profile ncurses util-linux sudo time shadow-utils vulkan mesa-vulkan-drivers \
|
||||||
|
mesa-dri-drivers inotify-tools dbus &>/dev/null
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p /usr/local/bin
|
||||||
|
wget -O /usr/local/bin/host-spawn "https://github.com/1player/host-spawn/releases/latest/download/host-spawn-$(uname -m)" &>/dev/null
|
||||||
|
chmod 755 /usr/local/bin/host-spawn
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
for i in /var/log/journal /var/lib/systemd/coredump /var/lib/flatpak; do
|
||||||
|
bmount "/run/host/${i}" "$i" ro
|
||||||
|
done
|
||||||
|
|
||||||
|
for i in /etc/host.conf /run/media /media /mnt /var/mnt \
|
||||||
|
/run/libvirt /etc/machine-id /run/netconfig/ /run/udev \
|
||||||
|
/run/systemd/journal /run/systemd/seats /run/systemd/sessions \
|
||||||
|
/run/systemd/users /run/systemd/resolve/ /srv /var/lib/libvirt; do
|
||||||
|
bmount "/run/host/${i}" "$i" rw
|
||||||
|
done
|
||||||
|
|
||||||
|
init_ro_mounts="
|
||||||
|
/run/systemd/journal
|
||||||
|
/var/log/journal
|
||||||
|
/run/systemd/resolve
|
||||||
|
/run/systemd/seats
|
||||||
|
/run/systemd/sessions
|
||||||
|
/run/systemd/users
|
||||||
|
/var/lib/systemd/coredump
|
||||||
|
/etc/localtime"
|
||||||
|
|
||||||
|
### Section START https://github.com/89luca89/distrobox/blob/main/distrobox-init#L772
|
||||||
|
host_sockets="$(find /run/host/run -name 'user' \
|
||||||
|
-prune -o -path /run/host/run/media \
|
||||||
|
-prune -o -name 'nscd' \
|
||||||
|
-prune -o -name 'bees' \
|
||||||
|
-prune -o -name 'system_bus_socket' \
|
||||||
|
-prune -o -type s -print \
|
||||||
|
2> /dev/null || :)"
|
||||||
|
### Section END
|
||||||
|
|
||||||
|
for i in ${host_sockets}; do
|
||||||
|
container_socket="$(echo -n "$i" | sed 's/\/run\/host//g')"
|
||||||
|
if [ ! -S "${container_socket}" ] && [ ! -L "${container_socket}" ]; then
|
||||||
|
rm -f "${container_socket}"
|
||||||
|
mkdir -p "$(dirname "${container_socket}")"
|
||||||
|
ln -s "$i" "${container_socket}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
bmount "/run/host/usr/share/themes" "/usr/local/share/themes" ro
|
||||||
|
bmount "/run/host/usr/share/icons" "/usr/local/share/icons" ro
|
||||||
|
bmount "/run/host/usr/share/fonts" "/usr/local/share/fonts" ro
|
||||||
|
|
||||||
|
bmount "/usr/bin/host-blend" "/usr/bin/blend" ro
|
||||||
|
|
||||||
|
# sudo touch /.init_blend.lock
|
||||||
|
|
||||||
|
if [[ ! -f '/.init_blend.lock' ]]; then
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
# NVIDIA driver integration. This is straight from https://github.com/89luca89/distrobox/blob/main/distrobox-init#L816,
|
||||||
|
# entirely thanks to an effort by Luca Di Maio, save for a few tweaks for init-blend. Thanks, in case you're reading this!
|
||||||
|
|
||||||
|
NVIDIA_FILES="$(find /run/host/usr/ \
|
||||||
|
-path "/run/host/usr/share/doc*" -prune -o \
|
||||||
|
-path "/run/host/usr/src*" -prune -o \
|
||||||
|
-path "/run/host/usr/lib*/modules*" -prune -o \
|
||||||
|
-path "/run/host/usr/share/man*" -prune -o \
|
||||||
|
-path "/run/host/usr/lib*" -prune -o \
|
||||||
|
-type f -iname "*nvidia*" -print 2</dev/null || :)"
|
||||||
|
for nvidia_file in ${NVIDIA_FILES}; do
|
||||||
|
dest_file="$(printf "%s" "${nvidia_file}" | sed 's|/run/host||g')"
|
||||||
|
bmount "${nvidia_file}" "${dest_file}" ro
|
||||||
|
done
|
||||||
|
|
||||||
|
# Then we find all the ".so" libraries, there are searched separately
|
||||||
|
# because we need to extract the relative path to mount them in the
|
||||||
|
# correct path based on the guest's setup
|
||||||
|
NVIDIA_LIBS="$(find /run/host/usr/lib* \
|
||||||
|
-iname "*nvidia*.so*" \
|
||||||
|
-o -iname "libcuda*.so*" \
|
||||||
|
-o -iname "libnvcuvid*.so*" \
|
||||||
|
-o -iname "libnvoptix*.so*" ||
|
||||||
|
:)"
|
||||||
|
for nvidia_lib in ${NVIDIA_LIBS}; do
|
||||||
|
dest_file="$(printf "%s" "${nvidia_lib}" |
|
||||||
|
sed 's|/run/host/usr/lib/x86_64-linux-gnu/||g' |
|
||||||
|
sed 's|/run/host/usr/lib64/||g' |
|
||||||
|
sed 's|/run/host/usr/lib/||g')"
|
||||||
|
|
||||||
|
# In the guest we need to adjust the destination path, so if we're on
|
||||||
|
# debian based containers, we need to target /usr/lib/x86_64-linux-gnu/
|
||||||
|
if [ -e "/usr/lib/x86_64-linux-gnu/" ]; then
|
||||||
|
bmount "${nvidia_lib}" "/usr/lib/x86_64-linux-gnu/${dest_file}" ro
|
||||||
|
# /usr/lib64 is common in rpm based distros
|
||||||
|
elif [ -e "/usr/lib64" ]; then
|
||||||
|
bmount "${nvidia_lib}" "/usr/lib64/${dest_file}" ro
|
||||||
|
# fallback to /usr/lib if none of the previous
|
||||||
|
else
|
||||||
|
bmount "${nvidia_lib}" "/usr/lib/${dest_file}" ro
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Refresh ldconfig cache, also detect if there are empty files remaining
|
||||||
|
# and clean them.
|
||||||
|
# This could happen when upgrading drivers and changing versions.
|
||||||
|
empty_libs="$(ldconfig 2>&1 | grep -Eo "File.*is empty" | cut -d' ' -f2)"
|
||||||
|
if [ -n "${empty_libs}" ]; then
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
rm -f ${empty_libs}
|
||||||
|
fi
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
### Section START (based on https://github.com/89luca89/distrobox/blob/main/distrobox-init#L816)
|
||||||
|
|
||||||
|
if [ -d "/usr/lib/rpm/" ]; then
|
||||||
|
mkdir -p /usr/lib/rpm/macros.d
|
||||||
|
net_mounts=""
|
||||||
|
for net_mount in \
|
||||||
|
${HOST_MOUNTS_RO} ${HOST_MOUNTS} \
|
||||||
|
'/dev' '/proc' '/sys' '/tmp' \
|
||||||
|
'/etc/host.conf' '/etc/hosts' '/etc/resolv.conf' '/etc/localtime' \
|
||||||
|
'/usr/share/zoneinfo'; do
|
||||||
|
|
||||||
|
net_mounts="${net_mount}:${net_mounts}"
|
||||||
|
|
||||||
|
done
|
||||||
|
net_mounts=${net_mounts%?}
|
||||||
|
echo "%_netsharedpath ${net_mounts}" > /usr/lib/rpm/macros.d/macros.blend
|
||||||
|
elif [ -d "/etc/dpkg/" ]; then
|
||||||
|
mkdir -p /etc/dpkg/dpkg.cfg.d /etc/apt/apt.conf.d
|
||||||
|
|
||||||
|
echo -n > /etc/dpkg/dpkg.cfg.d/00_blend
|
||||||
|
for net_mount in ${HOST_MOUNTS_RO} ${HOST_MOUNTS} '/etc/hosts' '/etc/resolv.conf' '/etc/localtime'; do
|
||||||
|
printf "path-exclude %s/*\n" "${net_mount}" >> /etc/dpkg/dpkg.cfg.d/00_blend
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -n > /etc/apt/apt.conf.d/00_blend
|
||||||
|
for init_mount in ${init_ro_mounts}; do
|
||||||
|
printf 'DPkg::Pre-Invoke {"if findmnt %s >/dev/null; then umount -l %s; fi";};\n' \
|
||||||
|
"${init_mount}" "${init_mount}" >> /etc/apt/apt.conf.d/00_blend
|
||||||
|
|
||||||
|
printf 'DPkg::Post-Invoke {"if [ -e /run/host/%s ] || [ -e /run/host/$(readlink -fm /run/host/%s) ]; then mount --rbind $(readlink -fm /run/host/%s) %s 2>/dev/null || mount --rbind /run/host/$(readlink -fm /run/host/%s) %s; fi";};\n' \
|
||||||
|
"${init_mount}" "${init_mount}" "${init_mount}" "${init_mount}" "${init_mount}" "${init_mount}" >> /etc/apt/apt.conf.d/00_blend
|
||||||
|
done
|
||||||
|
|
||||||
|
### Section END
|
||||||
|
elif [ -d "/usr/share/libalpm/scripts" ]; then
|
||||||
|
echo "#!/bin/sh" > /usr/share/libalpm/scripts/00_blend_pre_hook.sh
|
||||||
|
echo "#!/bin/sh" > /usr/share/libalpm/scripts/01_blend_post_hook.sh
|
||||||
|
echo "#!/bin/sh" > /usr/share/libalpm/scripts/02_blend_post_hook.sh
|
||||||
|
|
||||||
|
for net_mount in ${HOST_MOUNTS_RO}; do
|
||||||
|
echo "findmnt ${net_mount} &>/dev/null && umount ${net_mount} || :" >> /usr/share/libalpm/scripts/00_blend_pre_hook.sh
|
||||||
|
echo "test -e /run/host/${net_mount} && mount --rbind -o ro /run/host/${net_mount} ${net_mount} || :" >> /usr/share/libalpm/scripts/02_blend_post_hook.sh
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -e '#!/bin/sh\necho -e "#!/bin/sh\nexit 0" > /usr/share/libalpm/scripts/systemd-hook' >/usr/share/libalpm/scripts/01_blend_post_hook.sh
|
||||||
|
|
||||||
|
chmod 755 /usr/share/libalpm/scripts/*blend*.sh
|
||||||
|
|
||||||
|
for p in 00_blend_pre_hook 01_blend_post_hook 02_blend_post_hook; do
|
||||||
|
when=PostTransaction
|
||||||
|
|
||||||
|
[[ -z "${p##*pre*}" ]] && when=PreTransaction
|
||||||
|
cat << EOF > "/usr/share/libalpm/hooks/${p}.hook"
|
||||||
|
[Trigger]
|
||||||
|
Operation = Install
|
||||||
|
Operation = Upgrade
|
||||||
|
Type = Package
|
||||||
|
Target = *
|
||||||
|
[Action]
|
||||||
|
Description = blend ${p}
|
||||||
|
When = ${when}
|
||||||
|
Exec = /usr/share/libalpm/scripts/${p}.sh
|
||||||
|
EOF
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p /etc/sudoers.d
|
||||||
|
if ! grep -q 'Defaults !fqdn' /etc/sudoers.d/sudoers &>/dev/null; then
|
||||||
|
printf "Defaults !fqdn\n" >> /etc/sudoers.d/sudoers
|
||||||
|
fi
|
||||||
|
if ! grep -q "\"${_uname}\" ALL = (root) NOPASSWD:ALL" /etc/sudoers.d/sudoers &>/dev/null; then
|
||||||
|
printf "\"%s\" ALL = (root) NOPASSWD:ALL\n" "$_uname" >> /etc/sudoers.d/sudoers
|
||||||
|
fi
|
||||||
|
if [[ $_cuid -eq 1000 ]] && grep -q ubuntu /etc/passwd; then
|
||||||
|
userdel -r ubuntu &>/dev/null
|
||||||
|
groupdel ubuntu &> /dev/null
|
||||||
|
grep -v ubuntu /etc/passwd > /etc/passwd.tmp
|
||||||
|
grep -v ubuntu /etc/group > /etc/group.tmp
|
||||||
|
mv /etc/passwd.tmp /etc/passwd
|
||||||
|
mv /etc/group.tmp /etc/group
|
||||||
|
fi
|
||||||
|
if ! grep -q "^${_uname}:" /etc/group; then
|
||||||
|
if ! groupadd --force --gid "$_cgid" "$_uname"; then
|
||||||
|
printf "%s:x:%s:" "$_uname" "$_cgid" >> /etc/group
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
useradd --uid "$_cuid" --gid "$_cgid" --shell "/bin/bash" --no-create-home --home "$_uhome" "$_uname" &>/dev/null
|
||||||
|
|
||||||
|
chown root /etc/sudo.conf
|
||||||
|
chown root /usr/bin/sudo
|
||||||
|
chmod 4755 /usr/bin/sudo
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v inotify-tools &>/dev/null; then
|
||||||
|
if command -v apt-get &>/dev/null; then
|
||||||
|
apt-get update &>/dev/null
|
||||||
|
DEBIAN_FRONTEND=noninteractive apt-get -y install inotify-tools &>/dev/null
|
||||||
|
|
||||||
|
elif command -v pacman &>/dev/null; then
|
||||||
|
pacman --noconfirm -Syyu &>/dev/null
|
||||||
|
pacman --noconfirm -Sy inotify-tools &>/dev/null
|
||||||
|
|
||||||
|
elif command -v dnf &>/dev/null; then
|
||||||
|
dnf install -y --allowerasing inotify-tools &>/dev/null
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
source /run/.containerenv
|
||||||
|
CONTAINER_NAME="$name"
|
||||||
|
|
||||||
|
if [[ ! -f '/.init_blend.lock' ]] && command -v pacman &>/dev/null; then
|
||||||
|
cd /; git clone https://aur.archlinux.org/yay.git &>/dev/null; cd yay
|
||||||
|
chown -R "$_uname" . &>/log
|
||||||
|
sudo -u "$_uname" makepkg --noconfirm -si &>/dev/null
|
||||||
|
cd /; rm -rf yay
|
||||||
|
|
||||||
|
touch /.init_blend.lock
|
||||||
|
fi
|
||||||
|
|
||||||
|
for full_file in /usr/bin/*; do
|
||||||
|
if [[ -x "$full_file" ]]; then
|
||||||
|
file="$(basename "${full_file}")"
|
||||||
|
if [[ ! -f "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}" ]]; then
|
||||||
|
mkdir -p "${HOME}/.local/bin/blend_bin"
|
||||||
|
echo "#!/bin/bash" > "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}"
|
||||||
|
echo '[ -f /run/.containerenv ] && { if [[ -e "/usr/bin/'"${file}"'" ]]; then /usr/bin/'"${file}"' "$@"; exit $?; else echo "This command can be accessed from the host, or from the container '"'${CONTAINER_NAME}'"'."; exit 127; fi } || :' >> "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}"
|
||||||
|
echo 'BLEND_ALLOW_ROOT= BLEND_NO_CHECK= blend enter -cn '"${CONTAINER_NAME}"' -- '"${file}"' "$@"' >> "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}"
|
||||||
|
chmod 755 "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
mkdir -p /usr/share/applications
|
||||||
|
touch "/usr/share/applications/empty_file.desktop"
|
||||||
|
|
||||||
|
for full_file in /usr/share/applications/*.desktop; do
|
||||||
|
file="$(basename "${full_file}")"
|
||||||
|
|
||||||
|
echo -n > "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
|
||||||
|
while read -r line; do
|
||||||
|
if [[ $line == Name* ]]; then
|
||||||
|
echo "${line} (container ${CONTAINER_NAME})" >> "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
elif [[ $line == Exec* ]]; then
|
||||||
|
echo "Exec=blend enter -cn ${CONTAINER_NAME} -- ${line:5}" >> "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
elif [[ $line == Icon* ]]; then
|
||||||
|
if [[ -e "${line:5}" ]]; then
|
||||||
|
mkdir -p "${HOME}/.local/share/blend/icons/${CONTAINER_NAME}_${file}"; cp "${line:5}" "${HOME}/.local/share/blend/icons/${CONTAINER_NAME}_${file}"
|
||||||
|
echo "Icon=${HOME}/.local/share/blend/icons/${CONTAINER_NAME}_${file}/$(basename "${line:5}")" >> "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
else
|
||||||
|
ICON_PATH="$(find /usr/share/icons/hicolor -type f -iname "*${line:5}*" -print -quit 2>/dev/null)"
|
||||||
|
mkdir -p "$(dirname "${ICON_PATH}" | sed 's/\/usr\/share/'"\/home\/${_uname}"'\/.local\/share/g')"
|
||||||
|
FINAL_ICON_PATH="$(dirname "${ICON_PATH}" | sed 's/\/usr\/share/'"\/home\/${_uname}"'\/.local\/share/g')/$(echo "${file%.*}").$(basename "${ICON_PATH}" | sed 's/^.*\.//')"
|
||||||
|
cp "${ICON_PATH}" "${FINAL_ICON_PATH}" &>/dev/null
|
||||||
|
echo "Icon=${FINAL_ICON_PATH}" >> "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "$line" >> "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
fi
|
||||||
|
done < "/usr/share/applications/${file}"
|
||||||
|
|
||||||
|
sed -i 's/DBusActivatable=true/DBusActivatable=false/g' "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
sed -i '/^TryExec/d' "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
|
||||||
|
chmod 755 "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Started container."
|
||||||
|
|
||||||
|
mkdir -p /usr/share/applications /usr/bin
|
||||||
|
inotifywait -m /usr/share/applications /usr/bin -e create,delete,move 2>/dev/null |
|
||||||
|
while read dir action file; do
|
||||||
|
( if [[ "$dir" == "/usr/bin/" ]]; then
|
||||||
|
if [[ "$action" == *"CREATE"* ]]; then
|
||||||
|
if [[ ! -f "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}" ]] && [[ -x "/usr/bin/${file}" ]]; then
|
||||||
|
mkdir -p "${HOME}/.local/bin/blend_bin"
|
||||||
|
echo "#!/bin/bash" > "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}"
|
||||||
|
echo '[ -f /run/.containerenv ] && { if [[ -e "/usr/bin/'"${file}"'" ]]; then /usr/bin/'"${file}"' "$@"; exit $?; else echo "This command can be accessed from the host, or from the container '"'${CONTAINER_NAME}'"'."; exit 127; fi } || :' >> "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}"
|
||||||
|
echo 'BLEND_ALLOW_ROOT= BLEND_NO_CHECK= blend enter -cn '"${CONTAINER_NAME}"' -- '"${file}"' "$@"' >> "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}"
|
||||||
|
chmod 755 "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}"
|
||||||
|
fi
|
||||||
|
elif [[ "$action" == *"DELETE"* ]]; then
|
||||||
|
rm -f "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}"
|
||||||
|
elif [[ "$action" == *"MOVED_FROM"* ]]; then
|
||||||
|
rm -f "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}"
|
||||||
|
elif [[ "$action" == *"MOVED_TO"* ]]; then
|
||||||
|
if [[ ! -f "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}" ]] && [[ -x "/usr/bin/${file}" ]]; then
|
||||||
|
mkdir -p "${HOME}/.local/bin/blend_bin"
|
||||||
|
echo "#!/bin/bash" > "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}"
|
||||||
|
echo '[ -f /run/.containerenv ] && { if [[ -e "/usr/bin/'"${file}"'" ]]; then /usr/bin/'"${file}"' "$@"; exit $?; else echo "This command can be accessed from the host, or from the container '"'${CONTAINER_NAME}'"'."; exit 127; fi } || :' >> "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}"
|
||||||
|
echo 'BLEND_ALLOW_ROOT= BLEND_NO_CHECK= blend enter -cn '"${CONTAINER_NAME}"' -- '"${file}"' "$@"' >> "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}"
|
||||||
|
chmod 755 "${HOME}/.local/bin/blend_bin/${file}.${CONTAINER_NAME}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi ) &
|
||||||
|
( if [[ "$dir" == "/usr/share/applications/" ]]; then
|
||||||
|
if [[ "$action" == *"CREATE"* ]] || [[ "$action" == *"MOVED_TO"* ]]; then
|
||||||
|
if [[ "$file" == *'.desktop' ]]; then
|
||||||
|
echo -n > "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
|
||||||
|
while read -r line; do
|
||||||
|
if [[ $line == Name* ]]; then
|
||||||
|
echo "${line} (${CONTAINER_NAME})" >> "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
elif [[ $line == Exec* ]]; then
|
||||||
|
echo "Exec=blend enter -cn ${CONTAINER_NAME} -- ${line:5}" >> "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
elif [[ $line == Icon* ]]; then
|
||||||
|
if [[ -e "${line:5}" ]]; then
|
||||||
|
mkdir -p "${HOME}/.local/share/blend/icons/${CONTAINER_NAME}_${file}"; cp "${line:5}" "${HOME}/.local/share/blend/icons/${CONTAINER_NAME}_${file}"
|
||||||
|
echo "Icon=${HOME}/.local/share/blend/icons/${CONTAINER_NAME}_${file}/$(basename "${line:5}")" >> "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
else
|
||||||
|
ICON_PATH="$(find /usr/share/icons/hicolor -type f -iname "*${line:5}*" -print -quit 2>/dev/null)"
|
||||||
|
mkdir -p "$(dirname "${ICON_PATH}" | sed 's/\/usr\/share/'"\/home\/${_uname}"'\/.local\/share/g')"
|
||||||
|
FINAL_ICON_PATH="$(dirname "${ICON_PATH}" | sed 's/\/usr\/share/'"\/home\/${_uname}"'\/.local\/share/g')/$(echo "${file%.*}").$(basename "${ICON_PATH}" | sed 's/^.*\.//')"
|
||||||
|
cp "${ICON_PATH}" "${FINAL_ICON_PATH}" &>/dev/null
|
||||||
|
echo "Icon=${FINAL_ICON_PATH}" >> "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "$line" >> "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
fi
|
||||||
|
done < "/usr/share/applications/${file}"
|
||||||
|
|
||||||
|
sed -i 's/DBusActivatable=true/DBusActivatable=false/g' "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
sed -i '/^TryExec/d' "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
|
||||||
|
chmod 755 "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
fi
|
||||||
|
elif [[ "$action" == *"DELETE"* ]]; then
|
||||||
|
rm -f "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
elif [[ "$action" == *"MOVED_FROM"* ]]; then
|
||||||
|
rm -f "${HOME}/.local/share/applications/blend;${CONTAINER_NAME};${file}"
|
||||||
|
fi
|
||||||
|
fi ) &
|
||||||
|
done &
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
for i in /etc/hosts /etc/localtime /etc/resolv.conf; do
|
||||||
|
cp "/run/host/${i}" / &>/dev/null || :
|
||||||
|
done
|
||||||
|
sleep 5
|
||||||
|
done
|
42
overlayfs-tools/README.md
Executable file
42
overlayfs-tools/README.md
Executable file
|
@ -0,0 +1,42 @@
|
||||||
|
overlayfs-tools
|
||||||
|
========
|
||||||
|
|
||||||
|
[OverlayFS](https://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt) is the union filesystem provided by Linux kernel.
|
||||||
|
|
||||||
|
This program comes provides three tools:
|
||||||
|
- **vacuum** - remove duplicated files in `upperdir` where `copy_up` is done but the file is not actually modified (see the sentence "the `copy_up` may turn out to be unnecessary" in the [Linux documentation](https://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt)). This may reduce the size of `upperdir` without changing `lowerdir` or `overlay`.
|
||||||
|
- **diff** - show the list of actually changed files (the difference between `overlay` and `lowerdir`). A file with its type changed (i.e. from symbolic link to regular file) will shown as deleted then added, rather than modified. Similarly, for a opaque directory in `upperdir`, the corresponding directory in `lowerdir` (if exists) will be shown as entirely deleted, and a new directory with the same name added. File permission/owner changes will be simply shown as modified.
|
||||||
|
- **merge** - merge down the changes from `upperdir` to `lowerdir`. Unlike [aubrsync](http://aufs.sourceforge.net/aufs2/brsync/README.txt) for AuFS which bypasses the union filesystem mechanism, overlayfs-utils emulates the OverlayFS logic, which will be far more efficient. After this operation, `upperdir` will be empty and `lowerdir` will be the same as original `overlay`.
|
||||||
|
- **deref** - copy changes from `upperdir` to `uppernew` while unfolding redirect directories and metacopy regular files, so that new upperdir is compatible with legacy overlayfs driver.
|
||||||
|
|
||||||
|
For safety reasons, vacuum and merge will not actually modify the filesystem, but generate a shell script to do the changes instead.
|
||||||
|
|
||||||
|
Prerequisite and Building
|
||||||
|
--------
|
||||||
|
|
||||||
|
$ make
|
||||||
|
|
||||||
|
Example usage
|
||||||
|
--------
|
||||||
|
|
||||||
|
# ./overlay diff -l /lower -u /upper
|
||||||
|
|
||||||
|
See `./overlay --help` for more.
|
||||||
|
|
||||||
|
Why sudo
|
||||||
|
--------
|
||||||
|
|
||||||
|
As [Linux documentation](https://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt) said,
|
||||||
|
|
||||||
|
> A directory is made opaque by setting the xattr "trusted.overlay.opaque" to "y".
|
||||||
|
|
||||||
|
However, only users with `CAP_SYS_ADMIN` can read `trusted.*` extended attributes.
|
||||||
|
|
||||||
|
Warnings / limitations
|
||||||
|
--------
|
||||||
|
|
||||||
|
- Only works for regular files and directories. Do not use it on OverlayFS with device files, socket files, etc..
|
||||||
|
- Hard links may be broken (i.e. resulting in duplicated independent files).
|
||||||
|
- File owner, group and permission bits will be preserved. File timestamps, attributes and extended attributes might be lost.
|
||||||
|
- This program only works for OverlayFS with only one lower layer.
|
||||||
|
- It is recommended to have the OverlayFS unmounted before running this program.
|
581
overlayfs-tools/logic.c
Executable file
581
overlayfs-tools/logic.c
Executable file
|
@ -0,0 +1,581 @@
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <linux/limits.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/xattr.h>
|
||||||
|
#include <fts.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include "logic.h"
|
||||||
|
#include "sh.h"
|
||||||
|
|
||||||
|
// exactly the same as in linux/fs.h
|
||||||
|
#define WHITEOUT_DEV 0
|
||||||
|
|
||||||
|
// exact the same as in fs/overlayfs/overlayfs.h
|
||||||
|
const char *ovl_opaque_xattr = "trusted.overlay.opaque";
|
||||||
|
const char *ovl_redirect_xattr = "trusted.overlay.redirect";
|
||||||
|
const char *ovl_metacopy_xattr = "trusted.overlay.metacopy";
|
||||||
|
|
||||||
|
#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
|
||||||
|
|
||||||
|
#define TRAILING_SLASH(ftype) (((ftype) == S_IFDIR) ? "/" : "")
|
||||||
|
|
||||||
|
static inline mode_t file_type(const struct stat *status) {
|
||||||
|
return status->st_mode & S_IFMT;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *ftype_name(mode_t type) {
|
||||||
|
switch (type) {
|
||||||
|
case S_IFDIR:
|
||||||
|
return "directory";
|
||||||
|
case S_IFREG:
|
||||||
|
return "regular file";
|
||||||
|
case S_IFLNK:
|
||||||
|
return "symbolic link";
|
||||||
|
default:
|
||||||
|
return "special file";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *ftype_name_plural(mode_t type) {
|
||||||
|
switch (type) {
|
||||||
|
case S_IFDIR:
|
||||||
|
return "Directories";
|
||||||
|
case S_IFREG:
|
||||||
|
return "Files";
|
||||||
|
case S_IFLNK:
|
||||||
|
return "Symbolic links";
|
||||||
|
default:
|
||||||
|
return "Special files";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool is_whiteout(const struct stat *status) {
|
||||||
|
return (file_type(status) == S_IFCHR) && (status->st_rdev == WHITEOUT_DEV);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline mode_t permission_bits(const struct stat *status) { // not used yet. I haven't decided how to treat permission bit changes
|
||||||
|
return status->st_mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISVTX);
|
||||||
|
}
|
||||||
|
|
||||||
|
int is_opaque(const char *path, bool *output) {
|
||||||
|
char val;
|
||||||
|
ssize_t res = getxattr(path, ovl_opaque_xattr, &val, 1);
|
||||||
|
if ((res < 0) && (errno != ENODATA)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*output = (res == 1 && val == 'y');
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int is_redirect(const char *path, bool *output) {
|
||||||
|
ssize_t res = getxattr(path, ovl_redirect_xattr, NULL, 0);
|
||||||
|
if ((res < 0) && (errno != ENODATA)) {
|
||||||
|
fprintf(stderr, "File %s redirect xattr can not be read.\n", path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*output = (res > 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int is_metacopy(const char *path, bool *output) {
|
||||||
|
ssize_t res = getxattr(path, ovl_metacopy_xattr, NULL, 0);
|
||||||
|
if ((res < 0) && (errno != ENODATA)) {
|
||||||
|
fprintf(stderr, "File %s metacopy xattr can not be read.\n", path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*output = (res >= 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Treat redirect as opaque dir because it hides the tree in lower_path
|
||||||
|
// and we do not support following to redirected lower path
|
||||||
|
int is_opaquedir(const char *path, bool *output) {
|
||||||
|
bool opaque, redirect;
|
||||||
|
if (is_opaque(path, &opaque) < 0) { return -1; }
|
||||||
|
if (is_redirect(path, &redirect) < 0) { return -1; }
|
||||||
|
*output = opaque || redirect;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool permission_identical(const struct stat *lower_status, const struct stat *upper_status) {
|
||||||
|
return (permission_bits(lower_status) == permission_bits(upper_status)) && (lower_status->st_uid == upper_status->st_uid) && (lower_status->st_gid == upper_status->st_gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
int read_chunk(int fd, char *buf, int len) {
|
||||||
|
ssize_t ret;
|
||||||
|
ssize_t remain = len;
|
||||||
|
while (remain > 0 && (ret = read(fd, buf, remain)) != 0) {
|
||||||
|
if (ret == -1) {
|
||||||
|
if (errno == EINTR) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
remain -= ret;
|
||||||
|
buf += ret;
|
||||||
|
}
|
||||||
|
return len - remain;
|
||||||
|
}
|
||||||
|
|
||||||
|
int regular_file_identical(const char *lower_path, const struct stat *lower_status, const char *upper_path, const struct stat *upper_status, bool *output) {
|
||||||
|
size_t blksize = (size_t) MIN(lower_status->st_blksize, upper_status->st_blksize);
|
||||||
|
if (lower_status->st_size != upper_status->st_size) { // different sizes
|
||||||
|
*output = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
bool metacopy, redirect;
|
||||||
|
if (is_metacopy(upper_path, &metacopy) < 0) { return -1; }
|
||||||
|
if (is_redirect(upper_path, &redirect) < 0) { return -1; }
|
||||||
|
if (metacopy) {
|
||||||
|
// metacopy means data is indentical, but redirect means it is not identical to lower_path
|
||||||
|
*output = !redirect;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
char lower_buffer[blksize];
|
||||||
|
char upper_buffer[blksize];
|
||||||
|
int lower_file = open(lower_path, O_RDONLY);
|
||||||
|
int upper_file = open(upper_path, O_RDONLY);
|
||||||
|
if (lower_file < 0) {
|
||||||
|
fprintf(stderr, "File %s can not be read for content.\n", lower_path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (upper_file < 0) {
|
||||||
|
fprintf(stderr, "File %s can not be read for content.\n", upper_path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
ssize_t read_lower; ssize_t read_upper;
|
||||||
|
do { // we can assume one will not reach EOF earlier than the other, as the file sizes are checked to be the same earlier
|
||||||
|
read_lower = read_chunk(lower_file, lower_buffer, blksize);
|
||||||
|
read_upper = read_chunk(upper_file, upper_buffer, blksize);
|
||||||
|
if (read_lower < 0) {
|
||||||
|
fprintf(stderr, "Error occured when reading file %s.\n", lower_path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (read_upper < 0) {
|
||||||
|
fprintf(stderr, "Error occured when reading file %s.\n", upper_path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (read_upper != read_lower) { // this should not happen as we've checked the sizes
|
||||||
|
fprintf(stderr, "Unexpected size difference: %s.\n", upper_path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (memcmp(lower_buffer, upper_buffer, read_upper)) { *output = false; return 0; } // the output is by default false, but we still set it for ease of reading
|
||||||
|
} while (read_lower || read_upper);
|
||||||
|
*output = true; // now we can say they are identical
|
||||||
|
if (close(lower_file) || close(upper_file)) { return -1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int symbolic_link_identical(const char *lower_path, const char *upper_path, bool *output) {
|
||||||
|
char lower_buffer[PATH_MAX];
|
||||||
|
char upper_buffer[PATH_MAX];
|
||||||
|
ssize_t lower_len = readlink(lower_path, lower_buffer, PATH_MAX);
|
||||||
|
ssize_t upper_len = readlink(upper_path, upper_buffer, PATH_MAX);
|
||||||
|
if (lower_len < 0 || lower_len == PATH_MAX) {
|
||||||
|
fprintf(stderr, "Symbolic link %s cannot be resolved.\n", lower_path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (upper_len < 0 || upper_len == PATH_MAX) {
|
||||||
|
fprintf(stderr, "Symbolic link %s cannot be resolved.\n", upper_path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
lower_buffer[lower_len] = '\0';
|
||||||
|
upper_buffer[upper_len] = '\0';
|
||||||
|
*output = (strcmp(lower_buffer, upper_buffer) == 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int vacuum_d(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr) {
|
||||||
|
bool opaque;
|
||||||
|
if (is_opaquedir(upper_path, &opaque) < 0) { return -1; }
|
||||||
|
if (opaque) { // TODO: sometimes removing opaque directory (and combine with lower directory) might be better
|
||||||
|
*fts_instr = FTS_SKIP;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int vacuum_dp(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr) {
|
||||||
|
if (lower_status == NULL) { return 0; } // lower does not exist
|
||||||
|
if (file_type(lower_status) != S_IFDIR) { return 0; }
|
||||||
|
if (!permission_identical(lower_status, upper_status)) { return 0; }
|
||||||
|
bool opaque;
|
||||||
|
if (is_opaquedir(upper_path, &opaque) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (opaque) { return 0; }
|
||||||
|
// this directory might be empty if all children are deleted in previous commands. but we simply don't test whether it's that case
|
||||||
|
return command(script_stream, "rmdir --ignore-fail-on-non-empty %U", upper_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int vacuum_f(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr) {
|
||||||
|
if (lower_status == NULL) { return 0; } // lower does not exist
|
||||||
|
if (file_type(lower_status) != S_IFREG) { return 0; }
|
||||||
|
if (!permission_identical(lower_status, upper_status)) { return 0; }
|
||||||
|
bool identical;
|
||||||
|
if (regular_file_identical(lower_path, lower_status, upper_path, upper_status, &identical) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!identical) { return 0; }
|
||||||
|
return command(script_stream, "rm %U", upper_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int vacuum_sl(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr) {
|
||||||
|
if (lower_status == NULL) { return 0; } // lower does not exist
|
||||||
|
if (file_type(lower_status) != S_IFLNK) { return 0; }
|
||||||
|
if (!permission_identical(lower_status, upper_status)) { return 0; }
|
||||||
|
bool identical;
|
||||||
|
if (symbolic_link_identical(lower_path, upper_path, &identical) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!identical) { return 0; }
|
||||||
|
return command(script_stream, "rm %U", upper_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_only_in(const char *path) {
|
||||||
|
char *dirc = strdup(path);
|
||||||
|
char *basec = strdup(path);
|
||||||
|
char *dname = dirname(dirc);
|
||||||
|
char *bname = basename(basec);
|
||||||
|
printf("Only in %s: %s\n", dname, bname);
|
||||||
|
free(dirc);
|
||||||
|
free(basec);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_removed(const char *lower_path, const size_t lower_root_len, mode_t lower_type) {
|
||||||
|
if (brief) {
|
||||||
|
print_only_in(lower_path);
|
||||||
|
} else {
|
||||||
|
printf("Removed: %s%s\n", &lower_path[lower_root_len], TRAILING_SLASH(lower_type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_added(const char *lower_path, const size_t lower_root_len, const char *upper_path, mode_t upper_type) {
|
||||||
|
if (brief) {
|
||||||
|
print_only_in(upper_path);
|
||||||
|
} else {
|
||||||
|
printf("Added: %s%s\n", &lower_path[lower_root_len], TRAILING_SLASH(upper_type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_replaced(const char *lower_path, const size_t lower_root_len, mode_t lower_type, const char *upper_path, mode_t upper_type) {
|
||||||
|
if (brief) {
|
||||||
|
printf("File %s is a %s while file %s is a %s\n", lower_path, ftype_name(lower_type), upper_path, ftype_name(upper_type));
|
||||||
|
} else {
|
||||||
|
if (lower_type != S_IFDIR) { // dir removed already printed by list_deleted_files()
|
||||||
|
print_removed(lower_path, lower_root_len, lower_type);
|
||||||
|
}
|
||||||
|
print_added(lower_path, lower_root_len, upper_path, upper_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_modified(const char *lower_path, const size_t lower_root_len, mode_t lower_type, const char *upper_path, bool identical) {
|
||||||
|
if (brief) {
|
||||||
|
if (!identical) { // brief format does not print permission difference
|
||||||
|
printf("%s %s and %s differ\n", ftype_name_plural(lower_type), lower_path, upper_path);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("Modified: %s%s\n", &lower_path[lower_root_len], TRAILING_SLASH(lower_type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int list_deleted_files(const char *lower_path, size_t lower_root_len, mode_t upper_type) { // This WORKS with files and itself is listed. However, prefixs are WRONG!
|
||||||
|
// brief format needs to print only first level deleted children under opaque dir
|
||||||
|
bool children = (brief && (upper_type == S_IFDIR));
|
||||||
|
if (!verbose && !children) {
|
||||||
|
if (!brief || upper_type == S_IFCHR) { // dir replaced already printed by print_replaced()
|
||||||
|
print_removed(lower_path, lower_root_len, S_IFDIR);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
FTSENT *cur;
|
||||||
|
char *paths[2] = {(char *) lower_path, NULL };
|
||||||
|
FTS *ftsp = fts_open(paths, FTS_NOCHDIR | FTS_PHYSICAL, NULL);
|
||||||
|
if (ftsp == NULL) { return -1; }
|
||||||
|
int return_val = 0;
|
||||||
|
while (((cur = fts_read(ftsp)) != NULL) && (return_val == 0)) {
|
||||||
|
switch (cur->fts_info) {
|
||||||
|
case FTS_D:
|
||||||
|
// brief format does not need to print deleted grand children under opaque dir
|
||||||
|
if (children && cur->fts_level > 0) {
|
||||||
|
print_removed(cur->fts_path, lower_root_len, S_IFDIR);
|
||||||
|
fts_set(ftsp, cur, FTS_SKIP);
|
||||||
|
}
|
||||||
|
break; // do nothing
|
||||||
|
case FTS_DP:
|
||||||
|
// brief format does not need to print deleted dir under opaque dir itself
|
||||||
|
if (!children) {
|
||||||
|
print_removed(cur->fts_path, lower_root_len, S_IFDIR);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case FTS_F:
|
||||||
|
print_removed(cur->fts_path, lower_root_len, S_IFREG);
|
||||||
|
break;
|
||||||
|
case FTS_SL:
|
||||||
|
print_removed(cur->fts_path, lower_root_len, S_IFLNK);
|
||||||
|
break;
|
||||||
|
case FTS_DEFAULT:
|
||||||
|
fprintf(stderr, "File %s is a special file (device or pipe). We cannot handle that.\n", cur->fts_path);
|
||||||
|
return_val = -1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Error occured when opening %s.\n", cur->fts_path);
|
||||||
|
return_val = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (errno) { return_val = -1; } // if no error happened, fts_read will "sets the external variable errno to 0" according to the documentation
|
||||||
|
return fts_close(ftsp) || return_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int diff_d(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr) {
|
||||||
|
bool opaque = false;
|
||||||
|
bool lower_exist = (lower_status != NULL);
|
||||||
|
if (lower_exist) {
|
||||||
|
if (file_type(lower_status) == S_IFDIR) {
|
||||||
|
if (is_opaquedir(upper_path, &opaque) < 0) { return -1; }
|
||||||
|
if (opaque) {
|
||||||
|
if (list_deleted_files(lower_path, lower_root_len, S_IFDIR) < 0) { return -1; }
|
||||||
|
} else {
|
||||||
|
if (!permission_identical(lower_status, upper_status)) {
|
||||||
|
print_modified(lower_path, lower_root_len, S_IFDIR, upper_path, true);
|
||||||
|
}
|
||||||
|
return 0; // children must be recursed, and directory itself does not need to be printed
|
||||||
|
}
|
||||||
|
} else { // other types of files
|
||||||
|
print_replaced(lower_path, lower_root_len, file_type(lower_status), upper_path, S_IFDIR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!(verbose || (brief && opaque))) { // brief format needs to print children of opaque dir
|
||||||
|
*fts_instr = FTS_SKIP;
|
||||||
|
}
|
||||||
|
if (!lower_exist || (!brief && opaque)) { // brief format does not need to print opaque dir itself
|
||||||
|
print_added(lower_path, lower_root_len, upper_path, S_IFDIR);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int diff_f(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr) {
|
||||||
|
bool identical;
|
||||||
|
if (lower_status != NULL) {
|
||||||
|
switch (file_type(lower_status)) {
|
||||||
|
case S_IFREG:
|
||||||
|
if (regular_file_identical(lower_path, lower_status, upper_path, upper_status, &identical) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!(identical && permission_identical(lower_status, upper_status))) {
|
||||||
|
print_modified(lower_path, lower_root_len, S_IFREG, upper_path, identical);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
case S_IFDIR:
|
||||||
|
if (list_deleted_files(lower_path, lower_root_len, S_IFREG) < 0) { return -1; }
|
||||||
|
/* fallthrough */
|
||||||
|
case S_IFLNK:
|
||||||
|
print_replaced(lower_path, lower_root_len, file_type(lower_status), upper_path, S_IFREG);
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "File %s is a special file (device or pipe). We cannot handle that.\n", lower_path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print_added(lower_path, lower_root_len, upper_path, S_IFREG);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int diff_sl(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr) {
|
||||||
|
bool identical;
|
||||||
|
if (lower_status != NULL) {
|
||||||
|
switch (file_type(lower_status)) {
|
||||||
|
case S_IFDIR:
|
||||||
|
if (list_deleted_files(lower_path, lower_root_len, S_IFLNK) < 0) { return -1; }
|
||||||
|
/* fallthrough */
|
||||||
|
case S_IFREG:
|
||||||
|
print_replaced(lower_path, lower_root_len, file_type(lower_status), upper_path, S_IFLNK);
|
||||||
|
return 0;
|
||||||
|
case S_IFLNK:
|
||||||
|
if (symbolic_link_identical(lower_path, upper_path, &identical) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!(identical && permission_identical(lower_status, upper_status))) {
|
||||||
|
print_modified(lower_path, lower_root_len, S_IFLNK, upper_path, identical);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "File %s is a special file (device or pipe). We cannot handle that.\n", lower_path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print_added(lower_path, lower_root_len, upper_path, S_IFLNK);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int diff_whiteout(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr) {
|
||||||
|
if (lower_status != NULL) {
|
||||||
|
if (file_type(lower_status) == S_IFDIR) {
|
||||||
|
if (list_deleted_files(lower_path, lower_root_len, S_IFCHR) < 0) { return -1; }
|
||||||
|
} else {
|
||||||
|
print_removed(lower_path, lower_root_len, file_type(lower_status));
|
||||||
|
}
|
||||||
|
} // else: whiteouting a nonexistent file? must be an error. but we ignore that :)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int merge_d(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr) {
|
||||||
|
bool redirect;
|
||||||
|
if (is_redirect(upper_path, &redirect) < 0) { return -1; }
|
||||||
|
// merging redirects is not supported, we must abort merge so redirected lower (under whiteout) won't be deleted
|
||||||
|
// upper_path may be hiding the directory in lower_path, but there may be another redirect upper pointing at it
|
||||||
|
if (redirect) {
|
||||||
|
fprintf(stderr, "Found redirect on %s. Merging redirect is not supported - Abort.\n", upper_path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (lower_status != NULL) {
|
||||||
|
if (file_type(lower_status) == S_IFDIR) {
|
||||||
|
bool opaque = false;
|
||||||
|
if (is_opaquedir(upper_path, &opaque) < 0) { return -1; }
|
||||||
|
if (opaque) {
|
||||||
|
if (command(script_stream, "rm -r %L", lower_path) < 0) { return -1; };
|
||||||
|
} else {
|
||||||
|
if (!permission_identical(lower_status, upper_status)) {
|
||||||
|
command(script_stream, "chmod --reference %U %L", upper_path, lower_path);
|
||||||
|
}
|
||||||
|
return 0; // children must be recursed, and directory itself does not need to be printed
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
command(script_stream, "rm %L", lower_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*fts_instr = FTS_SKIP;
|
||||||
|
return command(script_stream, "mv -T %U %L", upper_path, lower_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int merge_dp(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr) {
|
||||||
|
if (lower_status != NULL) {
|
||||||
|
if (file_type(lower_status) == S_IFDIR) {
|
||||||
|
bool opaque = false;
|
||||||
|
if (is_opaquedir(upper_path, &opaque) < 0) { return -1; }
|
||||||
|
if (!opaque) { // delete the directory: it should be empty already
|
||||||
|
return command(script_stream, "rmdir %U", upper_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int merge_f(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr) {
|
||||||
|
bool metacopy, redirect;
|
||||||
|
if (is_metacopy(upper_path, &metacopy) < 0) { return -1; }
|
||||||
|
if (is_redirect(upper_path, &redirect) < 0) { return -1; }
|
||||||
|
// merging metacopy is not supported, we must abort merge so lower data won't be deleted
|
||||||
|
if (metacopy || redirect) {
|
||||||
|
fprintf(stderr, "Found metacopy/redirect on %s. Merging metacopy/redirect is not supported - Abort.\n", upper_path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return command(script_stream, "rm -rf %L", lower_path) || command(script_stream, "mv -T %U %L", upper_path, lower_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int merge_sl(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr) {
|
||||||
|
return command(script_stream, "rm -rf %L", lower_path) || command(script_stream, "mv -T %U %L", upper_path, lower_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int merge_whiteout(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr) {
|
||||||
|
return command(script_stream, "rm -r %L", lower_path) || command(script_stream, "rm %U", upper_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef int (*TRAVERSE_CALLBACK)(const char *lower_path, const char* upper_path, const size_t lower_root_len, const struct stat *lower_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr);
|
||||||
|
|
||||||
|
int traverse(const char *lower_root, const char *upper_root, FILE* script_stream, TRAVERSE_CALLBACK callback_d, TRAVERSE_CALLBACK callback_dp, TRAVERSE_CALLBACK callback_f, TRAVERSE_CALLBACK callback_sl, TRAVERSE_CALLBACK callback_whiteout) { // returns 0 on success
|
||||||
|
FTSENT *cur;
|
||||||
|
char *paths[2] = {(char *) upper_root, NULL };
|
||||||
|
char lower_path[PATH_MAX];
|
||||||
|
strcpy(lower_path, lower_root);
|
||||||
|
size_t upper_root_len = strlen(upper_root);
|
||||||
|
size_t lower_root_len = strlen(lower_root);
|
||||||
|
FTS *ftsp = fts_open(paths, FTS_NOCHDIR | FTS_PHYSICAL, NULL);
|
||||||
|
if (ftsp == NULL) { return -1; }
|
||||||
|
int return_val = 0;
|
||||||
|
while ((return_val == 0) && ((cur = fts_read(ftsp)) != NULL)) {
|
||||||
|
TRAVERSE_CALLBACK callback = NULL;
|
||||||
|
switch (cur->fts_info) {
|
||||||
|
case FTS_D:
|
||||||
|
callback = callback_d;
|
||||||
|
break;
|
||||||
|
case FTS_DP:
|
||||||
|
callback = callback_dp;
|
||||||
|
break;
|
||||||
|
case FTS_F:
|
||||||
|
callback = callback_f;
|
||||||
|
break;
|
||||||
|
case FTS_SL:
|
||||||
|
callback = callback_sl;
|
||||||
|
break;
|
||||||
|
case FTS_DEFAULT:
|
||||||
|
if (is_whiteout(cur->fts_statp)) {
|
||||||
|
callback = callback_whiteout;
|
||||||
|
} else {
|
||||||
|
return_val = -1;
|
||||||
|
fprintf(stderr, "File %s is a special file (device or pipe). We cannot handle that.\n", cur->fts_path);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return_val = -1;
|
||||||
|
fprintf(stderr, "Error occured when opening %s.\n", cur->fts_path);
|
||||||
|
}
|
||||||
|
if (callback != NULL) {
|
||||||
|
int fts_instr = 0;
|
||||||
|
struct stat lower_status;
|
||||||
|
bool lower_exist = true;
|
||||||
|
strcpy(&lower_path[lower_root_len], &(cur->fts_path[upper_root_len]));
|
||||||
|
if (lstat(lower_path, &lower_status) != 0) {
|
||||||
|
if (errno == ENOENT || errno == ENOTDIR) { // the corresponding lower file (or its ancestor) does not exist at all
|
||||||
|
lower_exist = false;
|
||||||
|
} else { // stat failed for some unknown reason
|
||||||
|
fprintf(stderr, "Failed to stat %s.\n", lower_path);
|
||||||
|
return_val = -1;
|
||||||
|
break; // do not call callback in this case
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return_val = callback(lower_path, cur->fts_path, lower_root_len, lower_exist ? &lower_status : NULL, cur->fts_statp, script_stream, &fts_instr); // return_val must previously be 0
|
||||||
|
if (fts_instr) {
|
||||||
|
fts_set(ftsp, cur, fts_instr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (errno) { return_val = -1; } // if no error happened, fts_read will "sets the external variable errno to 0" according to the documentation
|
||||||
|
return fts_close(ftsp) || return_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int deref_d(const char *mnt_path, const char* upper_path, const size_t mnt_root_len, const struct stat *mnt_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr) {
|
||||||
|
bool redirect;
|
||||||
|
if (is_redirect(upper_path, &redirect) < 0) { return -1; }
|
||||||
|
if (!redirect) { return 0; }
|
||||||
|
*fts_instr = FTS_SKIP;
|
||||||
|
return command(script_stream, "rm -rf %U", upper_path) || command(script_stream, "cp -a %M %U", mnt_path, upper_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int deref_f(const char *mnt_path, const char* upper_path, const size_t mnt_root_len, const struct stat *mnt_status, const struct stat *upper_status, FILE* script_stream, int *fts_instr) {
|
||||||
|
bool metacopy;
|
||||||
|
if (is_metacopy(upper_path, &metacopy) < 0) { return -1; }
|
||||||
|
if (!metacopy) { return 0; }
|
||||||
|
return command(script_stream, "rm -r %U", upper_path) || command(script_stream, "cp -a %M %U", mnt_path, upper_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
int vacuum(const char* lowerdir, const char* upperdir, FILE* script_stream) {
|
||||||
|
return traverse(lowerdir, upperdir, script_stream, vacuum_d, vacuum_dp, vacuum_f, vacuum_sl, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int diff(const char* lowerdir, const char* upperdir) {
|
||||||
|
return traverse(lowerdir, upperdir, NULL, diff_d, NULL, diff_f, diff_sl, diff_whiteout);
|
||||||
|
}
|
||||||
|
|
||||||
|
int merge(const char* lowerdir, const char* upperdir, FILE* script_stream) {
|
||||||
|
return traverse(lowerdir, upperdir, script_stream, merge_d, merge_dp, merge_f, merge_sl, merge_whiteout);
|
||||||
|
}
|
||||||
|
|
||||||
|
int deref(const char* mountdir, const char* upperdir, FILE* script_stream) {
|
||||||
|
return traverse(mountdir, upperdir, script_stream, deref_d, NULL, deref_f, NULL, NULL);
|
||||||
|
}
|
37
overlayfs-tools/logic.h
Executable file
37
overlayfs-tools/logic.h
Executable file
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* logic.h / logic.c
|
||||||
|
*
|
||||||
|
* the logic for the three feature functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OVERLAYFS_TOOLS_LOGIC_H
|
||||||
|
#define OVERLAYFS_TOOLS_LOGIC_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
extern bool verbose;
|
||||||
|
extern bool brief;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* feature function. will take very long time to complete. returns 0 on success
|
||||||
|
*/
|
||||||
|
int vacuum(const char* lowerdir, const char* upperdir, FILE* script_stream);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* feature function. will take very long time to complete. returns 0 on success
|
||||||
|
*/
|
||||||
|
int diff(const char* lowerdir, const char* upperdir);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* feature function. will take very long time to complete. returns 0 on success
|
||||||
|
*/
|
||||||
|
int merge(const char* lowerdir, const char* upperdir, FILE* script_stream);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unfold metacopy and redirect upper.
|
||||||
|
*
|
||||||
|
* mountdir is required and lowerdir is irrelevant.
|
||||||
|
*/
|
||||||
|
int deref(const char* mountdir, const char* upperdir, FILE* script_stream);
|
||||||
|
|
||||||
|
#endif //OVERLAYFS_TOOLS_LOGIC_H
|
266
overlayfs-tools/main.c
Executable file
266
overlayfs-tools/main.c
Executable file
|
@ -0,0 +1,266 @@
|
||||||
|
/*
|
||||||
|
* main.c
|
||||||
|
*
|
||||||
|
* the command line user interface
|
||||||
|
*/
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <linux/limits.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/xattr.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#ifndef _SYS_STAT_H
|
||||||
|
#include <linux/stat.h>
|
||||||
|
#endif
|
||||||
|
#include "logic.h"
|
||||||
|
#include "sh.h"
|
||||||
|
|
||||||
|
#define STRING_BUFFER_SIZE PATH_MAX * 2
|
||||||
|
|
||||||
|
// currently, brief and verbose are mutually exclusive
|
||||||
|
bool verbose;
|
||||||
|
bool brief;
|
||||||
|
bool yes;
|
||||||
|
|
||||||
|
void print_help(const char *program) {
|
||||||
|
printf("Usage: %s command options\n", program);
|
||||||
|
puts("");
|
||||||
|
puts("Commands:");
|
||||||
|
puts(" vacuum - remove duplicated files in upperdir where copy_up is done but the file is not actually modified");
|
||||||
|
puts(" diff - show the list of actually changed files");
|
||||||
|
puts(" merge - merge all changes from upperdir to lowerdir, and clear upperdir");
|
||||||
|
puts(" deref - copy changes from upperdir to a new upperdir unfolding redirect and metacopy");
|
||||||
|
puts("");
|
||||||
|
puts("Options:");
|
||||||
|
puts(" -l, --lowerdir=LOWERDIR the lowerdir of OverlayFS (required)");
|
||||||
|
puts(" -u, --upperdir=UPPERDIR the upperdir of OverlayFS (required)");
|
||||||
|
puts(" -m, --mountdir=MOUNTDIR the mountdir of OverlayFS (optional)");
|
||||||
|
puts(" -L, --lowernew=LOWERNEW the lowerdir of new OverlayFS (optional)");
|
||||||
|
puts(" -U, --uppernew=UPPERNEW the upperdir of new OverlayFS (optional)");
|
||||||
|
puts(" -y --yes don't prompt if OverlayFS is still mounted (optional)");
|
||||||
|
puts(" -v, --verbose with diff action only: when a directory only exists in one version, still list every file of the directory");
|
||||||
|
puts(" -b, --brief with diff action only: conform to output of diff --brief --recursive --no-dereference");
|
||||||
|
puts(" -h, --help show this help text");
|
||||||
|
puts("");
|
||||||
|
puts("See https://github.com/kmxz/overlayfs-tools/ for warnings and more information.");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool starts_with(const char *haystack, const char* needle) {
|
||||||
|
return strncmp(needle, haystack, strlen(needle)) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_mounted(const char *lower, const char *upper) {
|
||||||
|
FILE *f = fopen("/proc/mounts", "r");
|
||||||
|
if (!f) {
|
||||||
|
fprintf(stderr, "Cannot read /proc/mounts to test whether OverlayFS is mounted.\n");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
char buf[STRING_BUFFER_SIZE];
|
||||||
|
while (fgets(buf, STRING_BUFFER_SIZE, f)) {
|
||||||
|
if (!starts_with(buf, "overlay")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (strlen(buf) == STRING_BUFFER_SIZE) {
|
||||||
|
fprintf(stderr, "OverlayFS line in /proc/mounts is too long.\n");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
char *m_lower = strstr(buf, "lowerdir=");
|
||||||
|
char *m_upper = strstr(buf, "upperdir=");
|
||||||
|
if (m_lower == NULL || m_upper == NULL) {
|
||||||
|
fprintf(stderr, "Cannot extract information from OverlayFS line in /proc/mounts.\n");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
m_lower = &(m_lower[strlen("lowerdir=")]);
|
||||||
|
m_upper = &(m_upper[strlen("upperdir=")]);
|
||||||
|
if (!(strncmp(lower, m_lower, strlen(lower)) && strncmp(upper, m_upper, strlen(upper)))) {
|
||||||
|
printf("The OverlayFS involved is still mounted.\n");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool check_mounted(const char *lower, const char *upper) {
|
||||||
|
if (is_mounted(lower, upper) && !yes) {
|
||||||
|
printf("It is strongly recommended to unmount OverlayFS first. Still continue (not recommended)?: \n");
|
||||||
|
int r = getchar();
|
||||||
|
if (r != 'Y' && r != 'y') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool directory_exists(const char *path) {
|
||||||
|
struct stat sb;
|
||||||
|
if (lstat(path, &sb) != 0) { return false; }
|
||||||
|
return (sb.st_mode & S_IFMT) == S_IFDIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool directory_create(const char *name, const char *path) {
|
||||||
|
if (mkdir(path, 0755) == 0 || errno == EEXIST) { return true; }
|
||||||
|
fprintf(stderr, "%s directory '%s' does not exist and cannot be created.\n", name, path);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool real_check_xattr_trusted(const char *tmp_path, int tmp_file) {
|
||||||
|
int ret = fsetxattr(tmp_file, "trusted.overlay.test", "naive", 5, 0);
|
||||||
|
close(tmp_file);
|
||||||
|
if (ret) { return false; }
|
||||||
|
char verify_buffer[10];
|
||||||
|
if (getxattr(tmp_path, "trusted.overlay.test", verify_buffer, 10) != 5) { return false; }
|
||||||
|
return !strncmp(verify_buffer, "naive", 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool check_xattr_trusted(const char *upper) {
|
||||||
|
char tmp_path[PATH_MAX];
|
||||||
|
strcpy(tmp_path, upper);
|
||||||
|
strcat(tmp_path, "/.xattr_test_XXXXXX.tmp");
|
||||||
|
int tmp_file = mkstemps(tmp_path, 4);
|
||||||
|
if (tmp_file < 0) { return false; }
|
||||||
|
bool ret = real_check_xattr_trusted(tmp_path, tmp_file);
|
||||||
|
unlink(tmp_path);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
char *lower = NULL;
|
||||||
|
char *upper = NULL;
|
||||||
|
char *dir, *mnt = NULL;
|
||||||
|
|
||||||
|
static struct option long_options[] = {
|
||||||
|
{ "lowerdir", required_argument, 0, 'l' },
|
||||||
|
{ "upperdir", required_argument, 0, 'u' },
|
||||||
|
{ "mountdir", required_argument, 0, 'm' },
|
||||||
|
{ "lowernew", required_argument, 0, 'L' },
|
||||||
|
{ "uppernew", required_argument, 0, 'U' },
|
||||||
|
{ "yes", no_argument , 0, 'y' },
|
||||||
|
{ "help", no_argument , 0, 'h' },
|
||||||
|
{ "verbose", no_argument , 0, 'v' },
|
||||||
|
{ "brief", no_argument , 0, 'b' },
|
||||||
|
{ 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
int opt = 0;
|
||||||
|
int long_index = 0;
|
||||||
|
while ((opt = getopt_long_only(argc, argv, "l:u:m:L:U:yhvb", long_options, &long_index)) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'l':
|
||||||
|
lower = realpath(optarg, NULL);
|
||||||
|
if (lower) { vars[LOWERDIR] = lower; }
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
upper = realpath(optarg, NULL);
|
||||||
|
if (upper) { vars[UPPERDIR] = upper; }
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
mnt = realpath(optarg, NULL);
|
||||||
|
if (mnt) { vars[MOUNTDIR] = mnt; }
|
||||||
|
break;
|
||||||
|
case 'L':
|
||||||
|
directory_create("New lowerdir", optarg);
|
||||||
|
dir = realpath(optarg, NULL);
|
||||||
|
if (dir) { vars[LOWERNEW] = dir; }
|
||||||
|
break;
|
||||||
|
case 'U':
|
||||||
|
directory_create("New upperdir", optarg);
|
||||||
|
dir = realpath(optarg, NULL);
|
||||||
|
if (dir) { vars[UPPERNEW] = dir; }
|
||||||
|
break;
|
||||||
|
case 'y':
|
||||||
|
yes = true;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
print_help(argv[0]);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
case 'v':
|
||||||
|
verbose = true;
|
||||||
|
brief = false;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
verbose = false;
|
||||||
|
brief = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Option %c is not supported.\n", opt);
|
||||||
|
goto see_help;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!lower) {
|
||||||
|
fprintf(stderr, "Lower directory not specified.\n");
|
||||||
|
goto see_help;
|
||||||
|
}
|
||||||
|
if (!directory_exists(lower)) {
|
||||||
|
fprintf(stderr, "Lower directory cannot be opened.\n");
|
||||||
|
goto see_help;
|
||||||
|
}
|
||||||
|
if (!upper) {
|
||||||
|
fprintf(stderr, "Upper directory not specified.\n");
|
||||||
|
goto see_help;
|
||||||
|
}
|
||||||
|
if (!directory_exists(upper)) {
|
||||||
|
fprintf(stderr, "Upper directory cannot be opened.\n");
|
||||||
|
goto see_help;
|
||||||
|
}
|
||||||
|
if (!check_xattr_trusted(upper)) {
|
||||||
|
fprintf(stderr, "The program cannot write trusted.* xattr. Try run again as root.\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
// Relax check for mounted overlay if we are not going to modify lowerdir/upperdir
|
||||||
|
if ((!vars[LOWERNEW] || !vars[UPPERNEW]) && check_mounted(lower, upper)) {
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optind == argc - 1) {
|
||||||
|
int out;
|
||||||
|
char filename_template[] = "overlay-tools-XXXXXX.sh";
|
||||||
|
FILE *script = NULL;
|
||||||
|
if (strcmp(argv[optind], "diff") == 0) {
|
||||||
|
out = diff(lower, upper);
|
||||||
|
} else if (strcmp(argv[optind], "vacuum") == 0) {
|
||||||
|
script = create_shell_script(filename_template);
|
||||||
|
if (script == NULL) { fprintf(stderr, "Script file cannot be created.\n"); return EXIT_FAILURE; }
|
||||||
|
out = vacuum(lower, upper, script);
|
||||||
|
} else if (strcmp(argv[optind], "merge") == 0) {
|
||||||
|
script = create_shell_script(filename_template);
|
||||||
|
if (script == NULL) { fprintf(stderr, "Script file cannot be created.\n"); return EXIT_FAILURE; }
|
||||||
|
out = merge(lower, upper, script);
|
||||||
|
} else if (strcmp(argv[optind], "deref") == 0) {
|
||||||
|
if (!mnt || !vars[UPPERNEW]) { fprintf(stderr, "'deref' command requires --uppernew and --mountdir.\n"); return EXIT_FAILURE; }
|
||||||
|
if (!directory_exists(mnt)) {
|
||||||
|
fprintf(stderr, "OverlayFS mount directory cannot be opened.\n");
|
||||||
|
goto see_help;
|
||||||
|
}
|
||||||
|
script = create_shell_script(filename_template);
|
||||||
|
if (script == NULL) { fprintf(stderr, "Script file cannot be created.\n"); return EXIT_FAILURE; }
|
||||||
|
out = deref(mnt, upper, script);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Action not supported.\n");
|
||||||
|
goto see_help;
|
||||||
|
}
|
||||||
|
if (script != NULL) {
|
||||||
|
printf("The script %s is created. Run the script to do the actual work please. Remember to run it when the OverlayFS is not mounted.\n", filename_template);
|
||||||
|
fclose(script);
|
||||||
|
}
|
||||||
|
if (out) {
|
||||||
|
fprintf(stderr, "Action aborted due to fatal error.\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "Please specify one action.\n");
|
||||||
|
|
||||||
|
see_help:
|
||||||
|
fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
|
}
|
23
overlayfs-tools/makefile
Executable file
23
overlayfs-tools/makefile
Executable file
|
@ -0,0 +1,23 @@
|
||||||
|
CC = gcc
|
||||||
|
CFLAGS = -Wall -std=c99
|
||||||
|
LDFLAGS = -lm
|
||||||
|
ifneq (,$(wildcard /etc/alpine-release))
|
||||||
|
LDFLAGS += -lfts
|
||||||
|
endif
|
||||||
|
|
||||||
|
all: overlayfs-tools
|
||||||
|
|
||||||
|
overlayfs-tools: main.o logic.o sh.o
|
||||||
|
$(CC) main.o logic.o sh.o -o overlayfs-tools $(LDFLAGS)
|
||||||
|
|
||||||
|
main.o: main.c logic.h
|
||||||
|
$(CC) $(CFLAGS) -c main.c
|
||||||
|
|
||||||
|
logic.o: logic.c logic.h sh.h
|
||||||
|
$(CC) $(CFLAGS) -c logic.c
|
||||||
|
|
||||||
|
sh.o: sh.c sh.h
|
||||||
|
$(CC) $(CFLAGS) -c sh.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) main.o logic.o sh.o overlayfs-tools
|
98
overlayfs-tools/sh.c
Executable file
98
overlayfs-tools/sh.c
Executable file
|
@ -0,0 +1,98 @@
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "sh.h"
|
||||||
|
|
||||||
|
char * vars[NUM_VARS];
|
||||||
|
const char * var_names[NUM_VARS] = {
|
||||||
|
"LOWERDIR",
|
||||||
|
"UPPERDIR",
|
||||||
|
"MOUNTDIR",
|
||||||
|
"LOWERNEW",
|
||||||
|
"UPPERNEW",
|
||||||
|
};
|
||||||
|
|
||||||
|
int quote(const char *filename, FILE *output);
|
||||||
|
|
||||||
|
FILE* create_shell_script(char *tmp_path_buffer) {
|
||||||
|
int tmp_file = mkstemps(tmp_path_buffer, 3); // the 3 is for suffix length (".sh")
|
||||||
|
if (tmp_file < 0) { return NULL; }
|
||||||
|
fchmod(tmp_file, S_IRWXU); // chmod to 0700
|
||||||
|
FILE* f = fdopen(tmp_file, "w");
|
||||||
|
if (f == NULL) { return NULL; }
|
||||||
|
fprintf(f, "#!/usr/bin/env bash\n");
|
||||||
|
fprintf(f, "set -x\n");
|
||||||
|
time_t rawtime;
|
||||||
|
time (&rawtime);
|
||||||
|
fprintf(f, "# This shell script is generated by overlayfs-tools on %s\n", ctime (&rawtime));
|
||||||
|
for (int i=0; i < NUM_VARS; i++) {
|
||||||
|
if (vars[i]) {
|
||||||
|
fprintf(f, "%s=", var_names[i]);
|
||||||
|
if (quote(vars[i], f) < 0) { return NULL; }
|
||||||
|
if (fputc('\n', f) == EOF) { return NULL; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Non-empty *NEW vars make a backup copy and override *DIR vars
|
||||||
|
if (vars[LOWERNEW]) {
|
||||||
|
fprintf(f, "rm -rf \"$LOWERNEW\"\n");
|
||||||
|
fprintf(f, "cp -a \"$LOWERDIR\" \"$LOWERNEW\"\n");
|
||||||
|
fprintf(f, "LOWERDIR=");
|
||||||
|
if (quote(vars[LOWERNEW], f) < 0) { return NULL; }
|
||||||
|
if (fputc('\n', f) == EOF) { return NULL; }
|
||||||
|
}
|
||||||
|
if (vars[UPPERNEW]) {
|
||||||
|
fprintf(f, "rm -rf \"$UPPERNEW\"\n");
|
||||||
|
fprintf(f, "cp -a \"$UPPERDIR\" \"$UPPERNEW\"\n");
|
||||||
|
fprintf(f, "UPPERDIR=");
|
||||||
|
if (quote(vars[UPPERNEW], f) < 0) { return NULL; }
|
||||||
|
if (fputc('\n', f) == EOF) { return NULL; }
|
||||||
|
}
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
int quote(const char *filename, FILE *output) {
|
||||||
|
if (fputc('\'', output) == EOF) { return -1; }
|
||||||
|
for (const char *s = filename; *s != '\0'; s++) {
|
||||||
|
if (*s == '\'') {
|
||||||
|
if (fprintf(output, "'\"'\"'") < 0) { return -1; }
|
||||||
|
} else {
|
||||||
|
if (fputc(*s, output) == EOF) { return -1; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fputc('\'', output) == EOF) { return -1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int substitue(char what, const char *filename, FILE *output) {
|
||||||
|
int i;
|
||||||
|
for (i=0; i < NUM_VARS; i++)
|
||||||
|
if (vars[i] && var_names[i][0] == what)
|
||||||
|
break;
|
||||||
|
if (i == NUM_VARS) { return -1; }
|
||||||
|
// filename prefix must match the var value
|
||||||
|
int prefix = strlen(vars[i]);
|
||||||
|
if (strncmp(filename, vars[i], prefix)) { return -1; }
|
||||||
|
filename += prefix;
|
||||||
|
fprintf(output, "\"$%s\"", var_names[i]);
|
||||||
|
return quote(filename, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
int command(FILE *output, const char *command_format, ...) {
|
||||||
|
va_list arg;
|
||||||
|
va_start(arg, command_format);
|
||||||
|
for (size_t i = 0; command_format[i] != '\0'; i++) {
|
||||||
|
if (command_format[i] == '%') {
|
||||||
|
const char *s = va_arg(arg, char *);
|
||||||
|
if (substitue(command_format[++i], s, output) < 0) { return -1; }
|
||||||
|
} else {
|
||||||
|
if (fputc(command_format[i], output) == EOF) { return -1; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
va_end(arg);
|
||||||
|
if (fputc('\n', output) == EOF) { return -1; }
|
||||||
|
return 0;
|
||||||
|
}
|
20
overlayfs-tools/sh.h
Executable file
20
overlayfs-tools/sh.h
Executable file
|
@ -0,0 +1,20 @@
|
||||||
|
#ifndef OVERLAYFS_TOOLS_SH_H
|
||||||
|
#define OVERLAYFS_TOOLS_SH_H
|
||||||
|
|
||||||
|
enum {
|
||||||
|
LOWERDIR,
|
||||||
|
UPPERDIR,
|
||||||
|
MOUNTDIR,
|
||||||
|
LOWERNEW,
|
||||||
|
UPPERNEW,
|
||||||
|
NUM_VARS
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const char *var_names[NUM_VARS];
|
||||||
|
extern char *vars[NUM_VARS];
|
||||||
|
|
||||||
|
FILE* create_shell_script(char *tmp_path_buffer);
|
||||||
|
|
||||||
|
int command(FILE *output, const char *command_format, ...);
|
||||||
|
|
||||||
|
#endif //OVERLAYFS_TOOLS_SH_H
|
253
user
Executable file
253
user
Executable file
|
@ -0,0 +1,253 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import yaml
|
||||||
|
import click
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from urllib.request import urlopen
|
||||||
|
|
||||||
|
|
||||||
|
class colors:
|
||||||
|
reset = '\033[0m'
|
||||||
|
bold = '\033[01m'
|
||||||
|
disable = '\033[02m'
|
||||||
|
underline = '\033[04m'
|
||||||
|
reverse = '\033[07m'
|
||||||
|
strikethrough = '\033[09m'
|
||||||
|
invisible = '\033[08m'
|
||||||
|
|
||||||
|
class fg:
|
||||||
|
black = '\033[30m'
|
||||||
|
red = '\033[31m'
|
||||||
|
green = '\033[32m'
|
||||||
|
orange = '\033[33m'
|
||||||
|
blue = '\033[34m'
|
||||||
|
purple = '\033[35m'
|
||||||
|
cyan = '\033[36m'
|
||||||
|
lightgrey = '\033[37m'
|
||||||
|
darkgrey = '\033[90m'
|
||||||
|
lightred = '\033[91m'
|
||||||
|
lightgreen = '\033[92m'
|
||||||
|
yellow = '\033[93m'
|
||||||
|
lightblue = '\033[94m'
|
||||||
|
pink = '\033[95m'
|
||||||
|
lightcyan = '\033[96m'
|
||||||
|
|
||||||
|
rainbow = [lightred, orange, yellow,
|
||||||
|
lightgreen, lightcyan, blue, purple]
|
||||||
|
seq = 0
|
||||||
|
|
||||||
|
def random(self):
|
||||||
|
if self.seq == 7:
|
||||||
|
self.seq = 0
|
||||||
|
self.seq += 1
|
||||||
|
return self.rainbow[self.seq - 1]
|
||||||
|
|
||||||
|
def clear_seq(self):
|
||||||
|
self.seq = 0
|
||||||
|
|
||||||
|
class bg:
|
||||||
|
black = '\033[40m'
|
||||||
|
red = '\033[41m'
|
||||||
|
green = '\033[42m'
|
||||||
|
orange = '\033[43m'
|
||||||
|
blue = '\033[44m'
|
||||||
|
purple = '\033[45m'
|
||||||
|
cyan = '\033[46m'
|
||||||
|
lightgrey = '\033[47m'
|
||||||
|
|
||||||
|
|
||||||
|
fg = colors.fg()
|
||||||
|
|
||||||
|
|
||||||
|
def info(msg):
|
||||||
|
print(colors.bold + fg.cyan + '[INFO] ' +
|
||||||
|
colors.reset + msg + colors.reset)
|
||||||
|
|
||||||
|
|
||||||
|
def print_list(msg):
|
||||||
|
print(colors.bold + fg.random() + '[LIST] ' +
|
||||||
|
colors.reset + msg + colors.reset)
|
||||||
|
|
||||||
|
|
||||||
|
def modrun(msg):
|
||||||
|
print(colors.bold + fg.green + '[MODRUN] ' +
|
||||||
|
colors.reset + msg + colors.reset)
|
||||||
|
|
||||||
|
|
||||||
|
def container_msg(msg):
|
||||||
|
print(colors.bold + fg.purple + '[CONTAINER] ' +
|
||||||
|
colors.reset + msg + colors.reset)
|
||||||
|
|
||||||
|
|
||||||
|
def association_msg(msg):
|
||||||
|
print(colors.bold + fg.random() + '[ASSOCIATION] ' +
|
||||||
|
colors.reset + msg + colors.reset)
|
||||||
|
|
||||||
|
|
||||||
|
def warn(warning):
|
||||||
|
print(colors.bold + fg.yellow + '[WARNING] ' +
|
||||||
|
colors.reset + warning + colors.reset)
|
||||||
|
|
||||||
|
|
||||||
|
def error(err):
|
||||||
|
print(colors.bold + fg.red + '[ERROR] ' +
|
||||||
|
colors.reset + err + colors.reset)
|
||||||
|
|
||||||
|
|
||||||
|
def proceed():
|
||||||
|
print(colors.bold + fg.red + '[QUESTION] ' +
|
||||||
|
colors.reset + 'would you like to proceed?' + colors.reset)
|
||||||
|
info(f'(press {colors.bold}ENTER{colors.reset} to proceed, or {colors.bold}^C{colors.reset}/{colors.bold}^D{colors.reset} to cancel)')
|
||||||
|
input()
|
||||||
|
|
||||||
|
|
||||||
|
@click.group("cli")
|
||||||
|
def cli():
|
||||||
|
"""Manage user operations using the user utility on blendOS."""
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
cli(prog_name="user")
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("associate")
|
||||||
|
@click.argument('association')
|
||||||
|
@click.argument('container')
|
||||||
|
def associate_binary(association, container):
|
||||||
|
'''
|
||||||
|
Create an association (for example, apt -> ubuntu)
|
||||||
|
'''
|
||||||
|
|
||||||
|
if not os.path.exists(os.path.expanduser(f'~/.local/bin/blend_bin/{association}.{container}')):
|
||||||
|
error(f'{colors.bold}{association}.{container}{colors.reset} does not exist')
|
||||||
|
exit()
|
||||||
|
if os.path.isfile(os.path.expanduser('~/.local/bin/blend_bin/.associations')):
|
||||||
|
subprocess.run(['sed', '-i', f's/^{association}\\x0//g',
|
||||||
|
os.path.expanduser('~/.local/bin/blend_bin/.associations')])
|
||||||
|
with open(os.path.expanduser('~/.local/bin/blend_bin/.associations'), 'a+') as f:
|
||||||
|
f.write(f'{association}\0{container}\n')
|
||||||
|
_exists = os.path.exists(os.path.expanduser(
|
||||||
|
f'~/.local/bin/blend_bin/{association}'))
|
||||||
|
subprocess.run(['ln', '-sf', f'{association}.{container}',
|
||||||
|
os.path.expanduser(f'~/.local/bin/blend_bin/{association}')])
|
||||||
|
association_msg(('modified' if _exists else 'created') +
|
||||||
|
f' {colors.bold}{association} -> {container}{colors.reset}')
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("dissociate")
|
||||||
|
@click.argument('association')
|
||||||
|
def associate_binary(association):
|
||||||
|
'''
|
||||||
|
Remove an association
|
||||||
|
'''
|
||||||
|
|
||||||
|
if not os.path.exists(os.path.expanduser(f'~/.local/bin/blend_bin/{association}')):
|
||||||
|
error(f'{colors.bold}{association}{colors.reset} does not exist')
|
||||||
|
exit()
|
||||||
|
if os.path.isfile(os.path.expanduser('~/.local/bin/blend_bin/.associations')):
|
||||||
|
subprocess.run(['sed', '-i', f's/^{association}\\x0//g',
|
||||||
|
os.path.expanduser('~/.local/bin/blend_bin/.associations')])
|
||||||
|
subprocess.run(
|
||||||
|
['rm', '-f', os.path.expanduser(f'~/.local/bin/blend_bin/{association}')])
|
||||||
|
association_msg(f'dissociated {colors.bold}{association}')
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("create-container")
|
||||||
|
@click.argument('container_name')
|
||||||
|
@click.argument('distro', default='arch')
|
||||||
|
def create_container(container_name, distro):
|
||||||
|
'''
|
||||||
|
Create a container
|
||||||
|
'''
|
||||||
|
if distro not in ('arch', 'almalinux-9', 'crystal-linux', 'debian', 'fedora-38', 'kali-linux', 'neurodebian-bookworm', 'rocky-linux', 'ubuntu-22.04', 'ubuntu-23.04'):
|
||||||
|
error(
|
||||||
|
f'distro {colors.bold}{distro}{colors.reset} not supported')
|
||||||
|
if subprocess.run(['podman', 'container', 'exists', container_name], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0:
|
||||||
|
error(f'container {colors.bold}{container_name}{colors.reset} already exists')
|
||||||
|
exit(1)
|
||||||
|
subprocess.run(['blend', 'create-container', '-cn', container_name, '-d', distro])
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("delete-container")
|
||||||
|
@click.argument('container')
|
||||||
|
def delete_container(container):
|
||||||
|
'''
|
||||||
|
Delete a container
|
||||||
|
'''
|
||||||
|
if subprocess.run(['podman', 'container', 'exists', container], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode != 0:
|
||||||
|
error(f'container {colors.bold}{container}{colors.reset} does not exist')
|
||||||
|
exit(1)
|
||||||
|
subprocess.run(['blend', 'remove-container', container])
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("shell")
|
||||||
|
@click.argument('container')
|
||||||
|
def shell(container):
|
||||||
|
'''
|
||||||
|
Enter a shell inside a container
|
||||||
|
'''
|
||||||
|
if subprocess.run(['podman', 'container', 'exists', container], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode != 0:
|
||||||
|
error(f'container {colors.bold}{container}{colors.reset} does not exist')
|
||||||
|
exit(1)
|
||||||
|
creation_env = os.environ.copy()
|
||||||
|
creation_env['BLEND_NO_CHECK'] = 'true'
|
||||||
|
subprocess.run(['blend', 'enter', '-cn', container], env=creation_env)
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("exec")
|
||||||
|
@click.argument('container')
|
||||||
|
@click.argument('cmds', nargs=-1, required=True)
|
||||||
|
def exec_c(container, cmds):
|
||||||
|
'''
|
||||||
|
Run a command inside a container
|
||||||
|
'''
|
||||||
|
if subprocess.run(['podman', 'container', 'exists', container], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode != 0:
|
||||||
|
error(f'container {colors.bold}{container}{colors.reset} does not exist')
|
||||||
|
exit(1)
|
||||||
|
creation_env = os.environ.copy()
|
||||||
|
creation_env['BLEND_NO_CHECK'] = 'true'
|
||||||
|
cmds = [ cmd.replace('\\-', '-') for cmd in cmds]
|
||||||
|
subprocess.run(['blend', 'enter', '-cn', container, '--', *cmds], env=creation_env)
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("install")
|
||||||
|
@click.argument('container')
|
||||||
|
@click.argument('pkgs', nargs=-1, required=True)
|
||||||
|
def install_c(container, pkgs):
|
||||||
|
'''
|
||||||
|
Install a package inside a container
|
||||||
|
'''
|
||||||
|
if os.path.isfile(os.path.expanduser(f'~/.local/bin/blend_bin/apt.{container}')):
|
||||||
|
subprocess.run([f'sudo.{container}', 'apt', 'update'])
|
||||||
|
subprocess.run([f'sudo.{container}', 'apt', 'install', *pkgs])
|
||||||
|
elif os.path.isfile(os.path.expanduser(f'~/.local/bin/blend_bin/dnf.{container}')):
|
||||||
|
subprocess.run([f'sudo.{container}', 'dnf', 'install', *pkgs])
|
||||||
|
elif os.path.isfile(os.path.expanduser(f'~/.local/bin/blend_bin/pacman.{container}')):
|
||||||
|
subprocess.run([f'sudo.{container}', 'pacman', '-Syu', *pkgs])
|
||||||
|
else:
|
||||||
|
error(f'container {colors.bold}{container}{colors.reset} does not exist')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("remove")
|
||||||
|
@click.argument('container')
|
||||||
|
@click.argument('pkgs', nargs=-1, required=True)
|
||||||
|
def remove_c(container, pkgs):
|
||||||
|
'''
|
||||||
|
Remove a package inside a container
|
||||||
|
'''
|
||||||
|
if os.path.isfile(os.path.expanduser(f'~/.local/bin/blend_bin/apt.{container}')):
|
||||||
|
subprocess.run([f'sudo.{container}', 'apt', 'purge', *pkgs])
|
||||||
|
elif os.path.isfile(os.path.expanduser(f'~/.local/bin/blend_bin/dnf.{container}')):
|
||||||
|
subprocess.run([f'sudo.{container}', 'dnf', 'remove', *pkgs])
|
||||||
|
elif os.path.isfile(os.path.expanduser(f'~/.local/bin/blend_bin/pacman.{container}')):
|
||||||
|
subprocess.run([f'sudo.{container}', 'pacman', '-Rcns', *pkgs])
|
||||||
|
else:
|
||||||
|
error(f'container {colors.bold}{container}{colors.reset} does not exist')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in a new issue