Add cachy-auto-update: unattended background updates for CachyOS
A root systemd service applies pacman, AUR, Flatpak and AppImage updates on its own, gated on battery state, gaming activity and whether anybody else is using the package system. The CLI is deliberately two switches plus status. No user password is stored anywhere: pacman runs as root directly, and the AUR step - which makepkg forbids running as root - drops to a locked system account that sudoers permits to call pacman without a password.
This commit is contained in:
1 parent
327da1dae3
commit
ceb024d7be
28 files changed
+3856
-1
No files matched your search
@@ -0,0 +1,3 @@
|
||||
# build artifacts
|
||||
po/*.mo
|
||||
doc/*.1
|
||||
@@ -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.
|
||||
|
||||
<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>.
|
||||
@@ -0,0 +1,141 @@
|
||||
# cachy-auto-update - build and install
|
||||
#
|
||||
# Everything here is plain shell; "building" only means compiling the gettext
|
||||
# catalogs and rendering the man page. Both are optional in the sense that the
|
||||
# targets degrade to a no-op when msgfmt/scdoc are missing, so the tree stays
|
||||
# usable for development without the build dependencies installed.
|
||||
|
||||
VERSION := 1.0.0
|
||||
|
||||
PREFIX ?= /usr
|
||||
DESTDIR ?=
|
||||
BINDIR ?= $(PREFIX)/bin
|
||||
LIBEXECDIR ?= $(PREFIX)/lib/cachy-auto-update
|
||||
DATADIR ?= $(PREFIX)/share
|
||||
LIBDIR ?= $(DATADIR)/cachy-auto-update/lib
|
||||
LOCALEDIR ?= $(DATADIR)/locale
|
||||
MANDIR ?= $(DATADIR)/man
|
||||
SYSCONFDIR ?= /etc
|
||||
SYSTEMDDIR ?= $(PREFIX)/lib/systemd/system
|
||||
SYSUSERSDIR ?= $(PREFIX)/lib/sysusers.d
|
||||
TMPFILESDIR ?= $(PREFIX)/lib/tmpfiles.d
|
||||
XDGAUTOSTART ?= $(SYSCONFDIR)/xdg/autostart
|
||||
|
||||
LINGUAS := de
|
||||
MOFILES := $(patsubst %,po/%.mo,$(LINGUAS))
|
||||
MANPAGE := doc/cachy-auto-update.1
|
||||
|
||||
LIBS := $(wildcard src/lib/*.sh)
|
||||
|
||||
MSGFMT := $(shell command -v msgfmt 2>/dev/null)
|
||||
SCDOC := $(shell command -v scdoc 2>/dev/null)
|
||||
|
||||
.PHONY: all build install uninstall check clean
|
||||
|
||||
all: build
|
||||
|
||||
build: $(MOFILES) $(MANPAGE)
|
||||
|
||||
po/%.mo: po/%.po
|
||||
ifdef MSGFMT
|
||||
$(MSGFMT) --check --output-file=$@ $<
|
||||
else
|
||||
@echo "msgfmt not found - skipping $@"
|
||||
endif
|
||||
|
||||
$(MANPAGE): doc/cachy-auto-update.1.scd
|
||||
ifdef SCDOC
|
||||
$(SCDOC) < $< > $@
|
||||
else
|
||||
@echo "scdoc not found - skipping $@"
|
||||
endif
|
||||
|
||||
# Syntax-check every shell file, and run shellcheck when it is available.
|
||||
check:
|
||||
@set -e; for f in src/cachy-auto-update src/cachy-auto-update-run $(LIBS); do \
|
||||
bash -n "$$f" && echo "ok $$f"; \
|
||||
done
|
||||
@if command -v shellcheck >/dev/null 2>&1; then \
|
||||
shellcheck -x -e SC1090,SC1091 src/cachy-auto-update src/cachy-auto-update-run $(LIBS); \
|
||||
echo "ok shellcheck"; \
|
||||
else \
|
||||
echo "shellcheck not found - skipped"; \
|
||||
fi
|
||||
@if command -v visudo >/dev/null 2>&1; then \
|
||||
visudo -cf res/sudoers/cachy-auto-update >/dev/null && echo "ok sudoers"; \
|
||||
fi
|
||||
|
||||
install: build
|
||||
# executables
|
||||
install -Dm755 src/cachy-auto-update "$(DESTDIR)$(BINDIR)/cachy-auto-update"
|
||||
install -Dm755 src/cachy-auto-update-run "$(DESTDIR)$(LIBEXECDIR)/cachy-auto-update-run"
|
||||
# the version and the resolved lib path are baked in at install time
|
||||
sed -i -e 's|@VERSION@|$(VERSION)|g' \
|
||||
-e 's|@LIBDIR@|$(LIBDIR)|g' \
|
||||
-e 's|@LIBEXECDIR@|$(LIBEXECDIR)|g' \
|
||||
-e 's|@LOCALEDIR@|$(LOCALEDIR)|g' \
|
||||
"$(DESTDIR)$(BINDIR)/cachy-auto-update" \
|
||||
"$(DESTDIR)$(LIBEXECDIR)/cachy-auto-update-run"
|
||||
|
||||
# shell libraries
|
||||
install -d "$(DESTDIR)$(LIBDIR)"
|
||||
install -Dm644 -t "$(DESTDIR)$(LIBDIR)" $(LIBS)
|
||||
sed -i -e 's|@VERSION@|$(VERSION)|g' \
|
||||
-e 's|@LIBDIR@|$(LIBDIR)|g' \
|
||||
-e 's|@LIBEXECDIR@|$(LIBEXECDIR)|g' \
|
||||
-e 's|@LOCALEDIR@|$(LOCALEDIR)|g' \
|
||||
"$(DESTDIR)$(LIBDIR)"/*.sh
|
||||
|
||||
# configuration (marked as backup= in the PKGBUILD)
|
||||
install -Dm644 res/config/cachy-auto-update.conf \
|
||||
"$(DESTDIR)$(SYSCONFDIR)/cachy-auto-update/cachy-auto-update.conf"
|
||||
install -Dm644 res/logrotate/cachy-auto-update \
|
||||
"$(DESTDIR)$(SYSCONFDIR)/logrotate.d/cachy-auto-update"
|
||||
|
||||
# privilege bridge for the AUR helper: a locked system account plus a
|
||||
# NOPASSWD rule scoped to pacman only
|
||||
install -Dm440 res/sudoers/cachy-auto-update \
|
||||
"$(DESTDIR)$(SYSCONFDIR)/sudoers.d/cachy-auto-update"
|
||||
install -Dm644 res/sysusers/cachy-auto-update.conf \
|
||||
"$(DESTDIR)$(SYSUSERSDIR)/cachy-auto-update.conf"
|
||||
install -Dm644 res/tmpfiles/cachy-auto-update.conf \
|
||||
"$(DESTDIR)$(TMPFILESDIR)/cachy-auto-update.conf"
|
||||
|
||||
# system units
|
||||
install -Dm644 res/systemd/cachy-auto-update.service \
|
||||
"$(DESTDIR)$(SYSTEMDDIR)/cachy-auto-update.service"
|
||||
install -Dm644 res/systemd/cachy-auto-update.timer \
|
||||
"$(DESTDIR)$(SYSTEMDDIR)/cachy-auto-update.timer"
|
||||
|
||||
# delivers notifications that were queued while nobody was logged in
|
||||
install -Dm644 res/autostart/cachy-auto-update-notify.desktop \
|
||||
"$(DESTDIR)$(XDGAUTOSTART)/cachy-auto-update-notify.desktop"
|
||||
|
||||
# translations
|
||||
@for l in $(LINGUAS); do \
|
||||
if [ -f "po/$$l.mo" ]; then \
|
||||
install -Dm644 "po/$$l.mo" \
|
||||
"$(DESTDIR)$(LOCALEDIR)/$$l/LC_MESSAGES/cachy-auto-update.mo"; \
|
||||
fi; \
|
||||
done
|
||||
|
||||
# documentation
|
||||
@if [ -f $(MANPAGE) ]; then \
|
||||
install -Dm644 $(MANPAGE) "$(DESTDIR)$(MANDIR)/man1/cachy-auto-update.1"; \
|
||||
fi
|
||||
install -Dm644 README.md "$(DESTDIR)$(DATADIR)/doc/cachy-auto-update/README.md"
|
||||
|
||||
uninstall:
|
||||
rm -f "$(DESTDIR)$(BINDIR)/cachy-auto-update"
|
||||
rm -rf "$(DESTDIR)$(LIBEXECDIR)"
|
||||
rm -rf "$(DESTDIR)$(DATADIR)/cachy-auto-update"
|
||||
rm -f "$(DESTDIR)$(SYSCONFDIR)/sudoers.d/cachy-auto-update"
|
||||
rm -f "$(DESTDIR)$(SYSUSERSDIR)/cachy-auto-update.conf"
|
||||
rm -f "$(DESTDIR)$(TMPFILESDIR)/cachy-auto-update.conf"
|
||||
rm -f "$(DESTDIR)$(SYSTEMDDIR)/cachy-auto-update.service"
|
||||
rm -f "$(DESTDIR)$(SYSTEMDDIR)/cachy-auto-update.timer"
|
||||
rm -f "$(DESTDIR)$(XDGAUTOSTART)/cachy-auto-update-notify.desktop"
|
||||
rm -f "$(DESTDIR)$(MANDIR)/man1/cachy-auto-update.1"
|
||||
|
||||
clean:
|
||||
rm -f po/*.mo $(MANPAGE)
|
||||
@@ -1,2 +1,192 @@
|
||||
# cachy-auto-update
|
||||
Auto Update CLI for CachyOS
|
||||
|
||||
Unattended background updates for CachyOS — no password prompt, no terminal,
|
||||
nothing to remember.
|
||||
|
||||
Built for the machine you set up for somebody else and would rather not have to
|
||||
maintain: it updates pacman packages, AUR packages, Flatpaks and AppImages by
|
||||
itself, stays out of the way while they are gaming or on battery, never touches
|
||||
the package database while they are using `pacman` by hand, and only speaks up
|
||||
when something actually needs a human.
|
||||
|
||||
```bash
|
||||
sudo cachy-auto-update
|
||||
```
|
||||
|
||||
That opens a menu with the two switches there are:
|
||||
|
||||
```
|
||||
CachyOS Auto-Update
|
||||
|
||||
Automatic updates ON
|
||||
Notifications ON
|
||||
|
||||
Last check 3 hours ago
|
||||
Last successful update Sat 08 Aug 2026 04:12:03 CEST (23 packages)
|
||||
Next scheduled run Sat 08 Aug 2026 05:00:00 CEST
|
||||
|
||||
[1] Toggle automatic updates
|
||||
[2] Toggle notifications
|
||||
[3] Update now
|
||||
[4] Show log
|
||||
[5] Show current conditions
|
||||
[q] Quit
|
||||
```
|
||||
|
||||
The interface is fully translated; on a German system everything above appears
|
||||
in German.
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
paru -S cachy-auto-update
|
||||
sudo cachy-auto-update enable
|
||||
```
|
||||
|
||||
Updates are **off** until you enable them — a freshly installed package has no
|
||||
business rebuilding somebody's system before being asked.
|
||||
|
||||
## What it updates
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| Repository packages | `pacman -Syu`, after `checkupdates` confirms there is work |
|
||||
| AUR | `paru` or `yay`, whichever is installed |
|
||||
| Flatpak | system and per-user installations |
|
||||
| AppImages | via [Gear Lever](https://github.com/mijorus/gearlever), if installed |
|
||||
|
||||
`-git`/`-devel` AUR packages, cache trimming and orphan removal exist as
|
||||
options but are off by default.
|
||||
|
||||
## When it holds back
|
||||
|
||||
A run is postponed — and retried an hour later — when:
|
||||
|
||||
- the battery is below 40 % (ignored on mains power; desktops without a battery
|
||||
are never affected),
|
||||
- a game is running: GameMode, a known game process, or anything holding a
|
||||
blocking idle inhibitor,
|
||||
- pacman's database is locked, or `pacman`/`yay`/`paru`/`pamac` is running.
|
||||
|
||||
`cachy-auto-update status` prints every one of these individually, which is the
|
||||
fastest way to find out why nothing is happening.
|
||||
|
||||
The machine is **never** restarted on its own. When a kernel update needs a
|
||||
restart, you get a notification saying so.
|
||||
|
||||
## About the password question
|
||||
|
||||
The obvious way to automate `yay`/`paru` is to store the user's password
|
||||
somewhere. This does not do that, and deliberately so: anything the daemon can
|
||||
decrypt is exactly what an attacker who reaches the daemon already has, so the
|
||||
encryption would be decoration.
|
||||
|
||||
Instead:
|
||||
|
||||
- The updater is a **system service running as root**, so `pacman` needs no
|
||||
escalation at all.
|
||||
- `makepkg`, `paru` and `yay` refuse to run as root, so the AUR step drops to a
|
||||
dedicated **locked system account** (`cachy-auto-update`, no password,
|
||||
`/usr/bin/nologin`, its own home under `/var/lib`). Only root can become it.
|
||||
- That account gets one line in `/etc/sudoers.d/cachy-auto-update` allowing it
|
||||
to call `/usr/bin/pacman` without a password — which is what lets the helper
|
||||
install what it built.
|
||||
|
||||
No user password is stored, encrypted or otherwise.
|
||||
|
||||
If you would rather not have that sudoers rule on the machine, set
|
||||
`UpdateAUR=no` in the config; everything else keeps working, and the rule
|
||||
becomes inert.
|
||||
|
||||
## Coexisting with manual package management
|
||||
|
||||
Before touching anything, the updater checks for `/var/lib/pacman/db.lck` and
|
||||
for a running `pacman`, `yay`, `paru`, `pamac`, `pikaur`, `octopi` or `makepkg`,
|
||||
and postpones if it finds one. On a day with no pending repository updates the
|
||||
real pacman lock is never taken at all, because `checkupdates` works against a
|
||||
private temporary database.
|
||||
|
||||
The reverse direction has an honest limit: if you start `pacman` *while* an
|
||||
update is already running, you will get the usual "unable to lock database"
|
||||
message. Nothing outside pacman can prevent that. What the updater does do is
|
||||
keep the window short, run at low priority, and hold a `systemd-inhibit` lock so
|
||||
a suspend or shutdown cannot land in the middle of a transaction.
|
||||
|
||||
A leftover `db.lck` from a crashed transaction is never deleted automatically —
|
||||
guessing wrong there corrupts a live transaction. After it has been seen
|
||||
unheld on several consecutive runs, you get a notification instead.
|
||||
|
||||
## Configuration
|
||||
|
||||
`/etc/cachy-auto-update/cachy-auto-update.conf`, one `Key=Value` per line, every
|
||||
option documented in the file. The file is parsed rather than sourced, so a
|
||||
stray line cannot turn into code executed by root.
|
||||
|
||||
```ini
|
||||
Enabled=yes
|
||||
Notifications=yes
|
||||
UpdateInterval=1d
|
||||
MinBatteryPercent=40
|
||||
SkipWhenGaming=yes
|
||||
UpdateAUR=yes
|
||||
UpdateFlatpak=yes
|
||||
UpdateAppImages=yes
|
||||
AutoResolveConflicts=yes
|
||||
IgnorePkg=
|
||||
```
|
||||
|
||||
## How package conflicts are handled
|
||||
|
||||
`pacman -Syu --noconfirm` already answers "Replace X with Y?" affirmatively, so
|
||||
ordinary replacements happen silently — which is the point.
|
||||
|
||||
What `--noconfirm` declines is `:: X and Y are in conflict. Remove Y? [y/N]`,
|
||||
and that aborts the whole transaction. With `AutoResolveConflicts=yes` (the
|
||||
default) the transaction is retried once with that question answered too, and
|
||||
everything removed is written to the log.
|
||||
|
||||
Two things are deliberately *not* automated:
|
||||
|
||||
- **File conflicts** (`exists in filesystem`) — forcing `--overwrite` could
|
||||
silently destroy something that was put there on purpose.
|
||||
- **Reboots** — you get a notification, never a surprise restart.
|
||||
|
||||
Signature failures trigger one keyring refresh and one retry, since a stale
|
||||
keyring blocks everything else until it is fixed.
|
||||
|
||||
## Logs
|
||||
|
||||
```bash
|
||||
cachy-auto-update log # the last run in full
|
||||
cachy-auto-update log -a # the rolling log
|
||||
journalctl -u cachy-auto-update
|
||||
```
|
||||
|
||||
Both work without root.
|
||||
|
||||
## Building from source
|
||||
|
||||
```bash
|
||||
make && sudo make install
|
||||
sudo systemd-sysusers && sudo systemd-tmpfiles --create
|
||||
sudo cachy-auto-update enable
|
||||
```
|
||||
|
||||
`make check` runs `bash -n` over everything, `shellcheck` when available, and
|
||||
validates the sudoers drop-in with `visudo -c`.
|
||||
|
||||
## Relationship to cachy-update
|
||||
|
||||
[cachy-update](https://github.com/CachyOS/cachy-update) is CachyOS's interactive
|
||||
updater; every one of its steps sits behind a prompt and its timer only ever
|
||||
*checks* for updates and notifies. This tool is the unattended counterpart and
|
||||
reimplements the same command sequence non-interactively, adding the battery,
|
||||
gaming and lock awareness that unattended operation needs.
|
||||
|
||||
The two coexist. `cachy-auto-update enable` offers once to switch off
|
||||
cachy-update's own "N updates available" notification, since it becomes noise
|
||||
when updates install themselves.
|
||||
|
||||
## License
|
||||
|
||||
GPL-3.0-or-later.
|
||||
@@ -0,0 +1,128 @@
|
||||
cachy-auto-update(1)
|
||||
|
||||
# NAME
|
||||
|
||||
cachy-auto-update - unattended background updates for CachyOS
|
||||
|
||||
# SYNOPSIS
|
||||
|
||||
*cachy-auto-update* [_command_] [_options_]
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
*cachy-auto-update* keeps a CachyOS machine current without anybody having to
|
||||
think about it: repository packages, AUR packages, Flatpaks and AppImages are
|
||||
updated in the background, with no password prompt and no terminal.
|
||||
|
||||
Run without a command it opens a small interactive menu with the two switches
|
||||
that matter - automatic updates on/off and notifications on/off - plus the
|
||||
current status.
|
||||
|
||||
The actual work is done by a systemd system service. The timer ticks hourly;
|
||||
whether a tick does anything is decided by _UpdateInterval_ (daily by default).
|
||||
A run that is postponed - low battery, a game running, somebody else using
|
||||
pacman - is simply retried at the next tick.
|
||||
|
||||
# COMMANDS
|
||||
|
||||
*enable*
|
||||
Turn automatic updates on and enable the systemd timer.
|
||||
|
||||
*disable*
|
||||
Turn automatic updates off and stop the timer.
|
||||
|
||||
*notifications* on|off
|
||||
Turn desktop notifications on or off.
|
||||
|
||||
*status*
|
||||
Show the current state plus an evaluation of every condition that can
|
||||
postpone a run. This is the first thing to look at when the updater
|
||||
appears to be doing nothing.
|
||||
|
||||
*run* [--force] [--dry-run]
|
||||
Update now. *--force* skips the interval, battery and gaming checks;
|
||||
*--dry-run* lists what would be updated and changes nothing. The check
|
||||
for another running package manager is never skipped.
|
||||
|
||||
*log* [-n _num_] [-f] [-a]
|
||||
Show the log of the last run. *-a* shows the rolling log instead, *-f*
|
||||
follows it.
|
||||
|
||||
*-h*, *--help*
|
||||
Show a short help text.
|
||||
|
||||
*-V*, *--version*
|
||||
Show the version.
|
||||
|
||||
# CONDITIONS
|
||||
|
||||
Before anything is installed, a run is postponed when:
|
||||
|
||||
- the battery is below _MinBatteryPercent_ (ignored on mains power, and on
|
||||
machines without a battery);
|
||||
- _RequireAC_ is set and the machine is not plugged in;
|
||||
- a game is running - detected via GameMode, a list of known game processes, or
|
||||
an application holding a blocking idle inhibitor;
|
||||
- pacman's database is locked, or pacman, yay, paru, pamac or a similar tool is
|
||||
running.
|
||||
|
||||
The last check is what keeps *cachy-auto-update* out of the way of manual
|
||||
package management. It cannot work in the other direction: if a manual pacman
|
||||
run starts while an update is already in flight, that run will report the usual
|
||||
locked-database error.
|
||||
|
||||
# HOW UPDATES ARE APPLIED
|
||||
|
||||
Repository packages are updated with *pacman -Syu --noconfirm*, but only after
|
||||
*checkupdates*(8) has confirmed there is something to do, so on a quiet day
|
||||
pacman's lock is never taken at all.
|
||||
|
||||
A package that has to replace another one is handled silently. If pacman would
|
||||
stop to ask whether a conflicting package may be removed, the transaction is
|
||||
retried once with that question answered affirmatively, unless
|
||||
_AutoResolveConflicts_ is turned off. Files on disk that collide with a package
|
||||
are *not* forced - that stays a human decision. A signature failure triggers one
|
||||
keyring refresh and one retry.
|
||||
|
||||
AUR packages are built and installed as the locked *cachy-auto-update* system
|
||||
account, because *makepkg*(8) refuses to run as root. That account has no
|
||||
password and no shell, and is allowed - through _/etc/sudoers.d/cachy-auto-update_
|
||||
- to invoke *pacman* without one. No user password is ever stored anywhere.
|
||||
|
||||
A failed AUR build is not reported the first time it happens; only a failure
|
||||
that repeats is worth waking somebody up for.
|
||||
|
||||
Flatpak system installations are updated directly as root, user installations
|
||||
inside each user's own account. AppImages are updated through Gear Lever, for
|
||||
users with a graphical session, and AppImages whose application is currently
|
||||
running are skipped.
|
||||
|
||||
The machine is never restarted automatically. When a kernel update makes a
|
||||
restart necessary, a notification says so.
|
||||
|
||||
# FILES
|
||||
|
||||
_/etc/cachy-auto-update/cachy-auto-update.conf_
|
||||
Configuration. See the comments in the file itself for every option.
|
||||
|
||||
_/etc/sudoers.d/cachy-auto-update_
|
||||
Lets the build account call pacman without a password.
|
||||
|
||||
_/var/log/cachy-auto-update/last-run.log_
|
||||
Full output of the most recent run.
|
||||
|
||||
_/var/log/cachy-auto-update/cachy-auto-update.log_
|
||||
Rolling log across runs.
|
||||
|
||||
_/var/lib/cachy-auto-update/_
|
||||
State: timestamps, counters, queued notifications.
|
||||
|
||||
# SEE ALSO
|
||||
|
||||
*pacman*(8), *checkupdates*(8), *paru*(8), *yay*(8), *flatpak*(1),
|
||||
*systemd.timer*(5)
|
||||
|
||||
# AUTHOR
|
||||
|
||||
Felitendo. Source and bug reports:
|
||||
https://github.com/Felitendo/cachy-auto-update
|
||||
@@ -0,0 +1,245 @@
|
||||
# Translation template for cachy-auto-update.
|
||||
# Copyright (C) 2026 Felitendo
|
||||
# This file is distributed under the same license as cachy-auto-update.
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: cachy-auto-update 1.0.0\n"
|
||||
"Report-Msgid-Bugs-To: https://github.com/Felitendo/cachy-auto-update/issues\n"
|
||||
"POT-Creation-Date: 2026-08-08 00:00+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#. Status labels
|
||||
msgid "ON"
|
||||
msgstr ""
|
||||
|
||||
msgid "OFF"
|
||||
msgstr ""
|
||||
|
||||
msgid "Automatic updates"
|
||||
msgstr ""
|
||||
|
||||
msgid "Notifications"
|
||||
msgstr ""
|
||||
|
||||
msgid "Last check"
|
||||
msgstr ""
|
||||
|
||||
msgid "Last successful update"
|
||||
msgstr ""
|
||||
|
||||
msgid "Next scheduled run"
|
||||
msgstr ""
|
||||
|
||||
msgid "never"
|
||||
msgstr ""
|
||||
|
||||
msgid "unknown"
|
||||
msgstr ""
|
||||
|
||||
msgid "not scheduled"
|
||||
msgstr ""
|
||||
|
||||
#, c-format
|
||||
msgid "%d packages"
|
||||
msgstr ""
|
||||
|
||||
msgid "just now"
|
||||
msgstr ""
|
||||
|
||||
#, c-format
|
||||
msgid "%d minutes ago"
|
||||
msgstr ""
|
||||
|
||||
#, c-format
|
||||
msgid "%d hours ago"
|
||||
msgstr ""
|
||||
|
||||
#, c-format
|
||||
msgid "%d days ago"
|
||||
msgstr ""
|
||||
|
||||
msgid "The last run reported a problem - see 'cachy-auto-update log'."
|
||||
msgstr ""
|
||||
|
||||
msgid "A restart is recommended to finish a kernel update."
|
||||
msgstr ""
|
||||
|
||||
#. Conditions
|
||||
msgid "Current conditions:"
|
||||
msgstr ""
|
||||
|
||||
msgid "on AC power"
|
||||
msgstr ""
|
||||
|
||||
msgid "on battery"
|
||||
msgstr ""
|
||||
|
||||
#, c-format
|
||||
msgid "on battery (%d%%, threshold %d%%)"
|
||||
msgstr ""
|
||||
|
||||
msgid "running on battery"
|
||||
msgstr ""
|
||||
|
||||
#, c-format
|
||||
msgid "battery at %d%%, below the %d%% threshold"
|
||||
msgstr ""
|
||||
|
||||
msgid "no game detected"
|
||||
msgstr ""
|
||||
|
||||
msgid "a game is running (GameMode)"
|
||||
msgstr ""
|
||||
|
||||
#, c-format
|
||||
msgid "a game is running (%s)"
|
||||
msgstr ""
|
||||
|
||||
msgid "an application is blocking idle (fullscreen game or video)"
|
||||
msgstr ""
|
||||
|
||||
msgid "package system is free"
|
||||
msgstr ""
|
||||
|
||||
msgid "pacman's database is locked by another process"
|
||||
msgstr ""
|
||||
|
||||
#, c-format
|
||||
msgid "%s is currently running"
|
||||
msgstr ""
|
||||
|
||||
#. Menu
|
||||
msgid "Toggle automatic updates"
|
||||
msgstr ""
|
||||
|
||||
msgid "Toggle notifications"
|
||||
msgstr ""
|
||||
|
||||
msgid "Update now"
|
||||
msgstr ""
|
||||
|
||||
msgid "Show log"
|
||||
msgstr ""
|
||||
|
||||
msgid "Show current conditions"
|
||||
msgstr ""
|
||||
|
||||
msgid "Quit"
|
||||
msgstr ""
|
||||
|
||||
msgid "Press Enter to continue..."
|
||||
msgstr ""
|
||||
|
||||
#. Commands
|
||||
msgid "Automatic updates are on."
|
||||
msgstr ""
|
||||
|
||||
msgid "Automatic updates are off."
|
||||
msgstr ""
|
||||
|
||||
msgid "Notifications are on."
|
||||
msgstr ""
|
||||
|
||||
msgid "Notifications are off."
|
||||
msgstr ""
|
||||
|
||||
msgid "This command has to run as root."
|
||||
msgstr ""
|
||||
|
||||
msgid "Could not write the configuration file."
|
||||
msgstr ""
|
||||
|
||||
msgid "Could not enable the systemd timer."
|
||||
msgstr ""
|
||||
|
||||
msgid "/etc/sudoers.d/cachy-auto-update is invalid; refusing to enable."
|
||||
msgstr ""
|
||||
|
||||
msgid "No AUR helper found - install paru or yay for AUR updates."
|
||||
msgstr ""
|
||||
|
||||
msgid "base-devel is missing - AUR packages cannot be built without it."
|
||||
msgstr ""
|
||||
|
||||
msgid "cachy-update also notifies about available updates. Turn its notifications off? [y/N]"
|
||||
msgstr ""
|
||||
|
||||
msgid "cachy-update's update check has been disabled."
|
||||
msgstr ""
|
||||
|
||||
msgid "No log yet."
|
||||
msgstr ""
|
||||
|
||||
#, c-format
|
||||
msgid "Unknown command: %s"
|
||||
msgstr ""
|
||||
|
||||
#. Help
|
||||
msgid "Usage: cachy-auto-update [command]"
|
||||
msgstr ""
|
||||
|
||||
msgid "Usage: cachy-auto-update notifications on|off"
|
||||
msgstr ""
|
||||
|
||||
msgid "Commands:"
|
||||
msgstr ""
|
||||
|
||||
msgid "Turn automatic updates on"
|
||||
msgstr ""
|
||||
|
||||
msgid "Turn automatic updates off"
|
||||
msgstr ""
|
||||
|
||||
msgid "Turn desktop notifications on or off"
|
||||
msgstr ""
|
||||
|
||||
msgid "Show the current state and conditions"
|
||||
msgstr ""
|
||||
|
||||
msgid "Run an update now"
|
||||
msgstr ""
|
||||
|
||||
msgid "Show the log of the last run"
|
||||
msgstr ""
|
||||
|
||||
msgid "Show this help"
|
||||
msgstr ""
|
||||
|
||||
msgid "Show the version"
|
||||
msgstr ""
|
||||
|
||||
msgid "Without a command an interactive menu is shown."
|
||||
msgstr ""
|
||||
|
||||
#. Notifications
|
||||
msgid "System updated"
|
||||
msgstr ""
|
||||
|
||||
#, c-format
|
||||
msgid "%d updates were installed."
|
||||
msgstr ""
|
||||
|
||||
msgid "Update failed"
|
||||
msgstr ""
|
||||
|
||||
msgid "Something went wrong while updating. Run 'cachy-auto-update log' for details."
|
||||
msgstr ""
|
||||
|
||||
msgid "Restart recommended"
|
||||
msgstr ""
|
||||
|
||||
msgid "A new kernel was installed. Please restart when it suits you."
|
||||
msgstr ""
|
||||
|
||||
msgid "Package database locked"
|
||||
msgstr ""
|
||||
|
||||
msgid "pacman's lock file looks left over from an interrupted update. Updates are paused until it is cleared."
|
||||
msgstr ""
|
||||
@@ -0,0 +1,246 @@
|
||||
# German translation for cachy-auto-update.
|
||||
# Copyright (C) 2026 Felitendo
|
||||
# This file is distributed under the same license as cachy-auto-update.
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: cachy-auto-update 1.0.0\n"
|
||||
"Report-Msgid-Bugs-To: https://github.com/Felitendo/cachy-auto-update/issues\n"
|
||||
"POT-Creation-Date: 2026-08-08 00:00+0200\n"
|
||||
"PO-Revision-Date: 2026-08-08 00:00+0200\n"
|
||||
"Last-Translator: Felitendo\n"
|
||||
"Language-Team: German\n"
|
||||
"Language: de\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
#. Status labels
|
||||
msgid "ON"
|
||||
msgstr "AN"
|
||||
|
||||
msgid "OFF"
|
||||
msgstr "AUS"
|
||||
|
||||
msgid "Automatic updates"
|
||||
msgstr "Automatische Updates"
|
||||
|
||||
msgid "Notifications"
|
||||
msgstr "Benachrichtigungen"
|
||||
|
||||
msgid "Last check"
|
||||
msgstr "Letzte Prüfung"
|
||||
|
||||
msgid "Last successful update"
|
||||
msgstr "Letztes Update"
|
||||
|
||||
msgid "Next scheduled run"
|
||||
msgstr "Nächster Lauf"
|
||||
|
||||
msgid "never"
|
||||
msgstr "noch nie"
|
||||
|
||||
msgid "unknown"
|
||||
msgstr "unbekannt"
|
||||
|
||||
msgid "not scheduled"
|
||||
msgstr "nicht eingeplant"
|
||||
|
||||
#, c-format
|
||||
msgid "%d packages"
|
||||
msgstr "%d Pakete"
|
||||
|
||||
msgid "just now"
|
||||
msgstr "gerade eben"
|
||||
|
||||
#, c-format
|
||||
msgid "%d minutes ago"
|
||||
msgstr "vor %d Minuten"
|
||||
|
||||
#, c-format
|
||||
msgid "%d hours ago"
|
||||
msgstr "vor %d Stunden"
|
||||
|
||||
#, c-format
|
||||
msgid "%d days ago"
|
||||
msgstr "vor %d Tagen"
|
||||
|
||||
msgid "The last run reported a problem - see 'cachy-auto-update log'."
|
||||
msgstr "Beim letzten Lauf gab es ein Problem – siehe „cachy-auto-update log“."
|
||||
|
||||
msgid "A restart is recommended to finish a kernel update."
|
||||
msgstr "Ein Neustart wird empfohlen, um ein Kernel-Update abzuschließen."
|
||||
|
||||
#. Conditions
|
||||
msgid "Current conditions:"
|
||||
msgstr "Aktuelle Bedingungen:"
|
||||
|
||||
msgid "on AC power"
|
||||
msgstr "am Stromnetz"
|
||||
|
||||
msgid "on battery"
|
||||
msgstr "im Akkubetrieb"
|
||||
|
||||
#, c-format
|
||||
msgid "on battery (%d%%, threshold %d%%)"
|
||||
msgstr "im Akkubetrieb (%d%%, Grenze %d%%)"
|
||||
|
||||
msgid "running on battery"
|
||||
msgstr "läuft im Akkubetrieb"
|
||||
|
||||
#, c-format
|
||||
msgid "battery at %d%%, below the %d%% threshold"
|
||||
msgstr "Akku bei %d%%, unter der Grenze von %d%%"
|
||||
|
||||
msgid "no game detected"
|
||||
msgstr "kein Spiel erkannt"
|
||||
|
||||
msgid "a game is running (GameMode)"
|
||||
msgstr "ein Spiel läuft (GameMode)"
|
||||
|
||||
#, c-format
|
||||
msgid "a game is running (%s)"
|
||||
msgstr "ein Spiel läuft (%s)"
|
||||
|
||||
msgid "an application is blocking idle (fullscreen game or video)"
|
||||
msgstr "eine Anwendung verhindert den Leerlauf (Vollbild-Spiel oder Video)"
|
||||
|
||||
msgid "package system is free"
|
||||
msgstr "Paketsystem ist frei"
|
||||
|
||||
msgid "pacman's database is locked by another process"
|
||||
msgstr "pacmans Datenbank ist gerade von einem anderen Prozess gesperrt"
|
||||
|
||||
#, c-format
|
||||
msgid "%s is currently running"
|
||||
msgstr "%s läuft gerade"
|
||||
|
||||
#. Menu
|
||||
msgid "Toggle automatic updates"
|
||||
msgstr "Automatische Updates umschalten"
|
||||
|
||||
msgid "Toggle notifications"
|
||||
msgstr "Benachrichtigungen umschalten"
|
||||
|
||||
msgid "Update now"
|
||||
msgstr "Jetzt aktualisieren"
|
||||
|
||||
msgid "Show log"
|
||||
msgstr "Protokoll anzeigen"
|
||||
|
||||
msgid "Show current conditions"
|
||||
msgstr "Aktuelle Bedingungen anzeigen"
|
||||
|
||||
msgid "Quit"
|
||||
msgstr "Beenden"
|
||||
|
||||
msgid "Press Enter to continue..."
|
||||
msgstr "Zum Fortfahren Enter drücken …"
|
||||
|
||||
#. Commands
|
||||
msgid "Automatic updates are on."
|
||||
msgstr "Automatische Updates sind eingeschaltet."
|
||||
|
||||
msgid "Automatic updates are off."
|
||||
msgstr "Automatische Updates sind ausgeschaltet."
|
||||
|
||||
msgid "Notifications are on."
|
||||
msgstr "Benachrichtigungen sind eingeschaltet."
|
||||
|
||||
msgid "Notifications are off."
|
||||
msgstr "Benachrichtigungen sind ausgeschaltet."
|
||||
|
||||
msgid "This command has to run as root."
|
||||
msgstr "Dieser Befehl muss als root ausgeführt werden."
|
||||
|
||||
msgid "Could not write the configuration file."
|
||||
msgstr "Die Konfigurationsdatei konnte nicht geschrieben werden."
|
||||
|
||||
msgid "Could not enable the systemd timer."
|
||||
msgstr "Der systemd-Timer konnte nicht aktiviert werden."
|
||||
|
||||
msgid "/etc/sudoers.d/cachy-auto-update is invalid; refusing to enable."
|
||||
msgstr "/etc/sudoers.d/cachy-auto-update ist fehlerhaft – wird nicht aktiviert."
|
||||
|
||||
msgid "No AUR helper found - install paru or yay for AUR updates."
|
||||
msgstr "Kein AUR-Helper gefunden – für AUR-Updates paru oder yay installieren."
|
||||
|
||||
msgid "base-devel is missing - AUR packages cannot be built without it."
|
||||
msgstr "base-devel fehlt – ohne das lassen sich AUR-Pakete nicht bauen."
|
||||
|
||||
msgid "cachy-update also notifies about available updates. Turn its notifications off? [y/N]"
|
||||
msgstr "cachy-update benachrichtigt ebenfalls über verfügbare Updates. Dessen Benachrichtigungen abschalten? [j/N]"
|
||||
|
||||
msgid "cachy-update's update check has been disabled."
|
||||
msgstr "Die Update-Prüfung von cachy-update wurde abgeschaltet."
|
||||
|
||||
msgid "No log yet."
|
||||
msgstr "Noch kein Protokoll vorhanden."
|
||||
|
||||
#, c-format
|
||||
msgid "Unknown command: %s"
|
||||
msgstr "Unbekannter Befehl: %s"
|
||||
|
||||
#. Help
|
||||
msgid "Usage: cachy-auto-update [command]"
|
||||
msgstr "Aufruf: cachy-auto-update [Befehl]"
|
||||
|
||||
msgid "Usage: cachy-auto-update notifications on|off"
|
||||
msgstr "Aufruf: cachy-auto-update notifications on|off"
|
||||
|
||||
msgid "Commands:"
|
||||
msgstr "Befehle:"
|
||||
|
||||
msgid "Turn automatic updates on"
|
||||
msgstr "Automatische Updates einschalten"
|
||||
|
||||
msgid "Turn automatic updates off"
|
||||
msgstr "Automatische Updates ausschalten"
|
||||
|
||||
msgid "Turn desktop notifications on or off"
|
||||
msgstr "Benachrichtigungen ein- oder ausschalten"
|
||||
|
||||
msgid "Show the current state and conditions"
|
||||
msgstr "Aktuellen Zustand und Bedingungen anzeigen"
|
||||
|
||||
msgid "Run an update now"
|
||||
msgstr "Jetzt ein Update durchführen"
|
||||
|
||||
msgid "Show the log of the last run"
|
||||
msgstr "Protokoll des letzten Laufs anzeigen"
|
||||
|
||||
msgid "Show this help"
|
||||
msgstr "Diese Hilfe anzeigen"
|
||||
|
||||
msgid "Show the version"
|
||||
msgstr "Version anzeigen"
|
||||
|
||||
msgid "Without a command an interactive menu is shown."
|
||||
msgstr "Ohne Befehl wird ein interaktives Menü angezeigt."
|
||||
|
||||
#. Notifications
|
||||
msgid "System updated"
|
||||
msgstr "System aktualisiert"
|
||||
|
||||
#, c-format
|
||||
msgid "%d updates were installed."
|
||||
msgstr "%d Updates wurden installiert."
|
||||
|
||||
msgid "Update failed"
|
||||
msgstr "Update fehlgeschlagen"
|
||||
|
||||
msgid "Something went wrong while updating. Run 'cachy-auto-update log' for details."
|
||||
msgstr "Beim Update ist etwas schiefgelaufen. Details mit „cachy-auto-update log“."
|
||||
|
||||
msgid "Restart recommended"
|
||||
msgstr "Neustart empfohlen"
|
||||
|
||||
msgid "A new kernel was installed. Please restart when it suits you."
|
||||
msgstr "Es wurde ein neuer Kernel installiert. Bitte bei Gelegenheit neu starten."
|
||||
|
||||
msgid "Package database locked"
|
||||
msgstr "Paketdatenbank gesperrt"
|
||||
|
||||
msgid "pacman's lock file looks left over from an interrupted update. Updates are paused until it is cleared."
|
||||
msgstr "Die Sperrdatei von pacman scheint von einem abgebrochenen Update übrig zu sein. Bis sie entfernt ist, pausieren die Updates."
|
||||
@@ -0,0 +1,13 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=CachyOS Auto-Update notifications
|
||||
Name[de]=CachyOS Auto-Update Benachrichtigungen
|
||||
Comment=Delivers update notifications that arrived while nobody was logged in
|
||||
Comment[de]=Stellt Update-Benachrichtigungen zu, die eingingen, während niemand angemeldet war
|
||||
Exec=cachy-auto-update --deliver-notifications
|
||||
Icon=system-software-update
|
||||
Terminal=false
|
||||
NoDisplay=true
|
||||
X-GNOME-Autostart-enabled=true
|
||||
X-GNOME-Autostart-Delay=20
|
||||
X-KDE-autostart-after=panel
|
||||
@@ -0,0 +1,94 @@
|
||||
# cachy-auto-update configuration
|
||||
#
|
||||
# One "Key=Value" per line, '#' starts a comment. The file is parsed, never
|
||||
# sourced, so shell syntax has no special meaning here.
|
||||
#
|
||||
# After editing run: systemctl restart cachy-auto-update.timer
|
||||
# Documentation: man cachy-auto-update
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Main switches - normally set through `cachy-auto-update enable/disable`
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# Apply updates automatically in the background.
|
||||
# Off after installation: a freshly installed package should not start
|
||||
# rebuilding the machine before anybody asked it to.
|
||||
Enabled=no
|
||||
|
||||
# Show a desktop notification after an update, and whenever something needs
|
||||
# attention.
|
||||
Notifications=yes
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# When
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# How much time has to pass between two update runs. Accepts a plain number of
|
||||
# seconds or a suffix of s, m, h, d, w.
|
||||
# The systemd timer ticks hourly regardless; this is what decides whether a
|
||||
# tick actually does anything, which is also how a postponed run retries.
|
||||
UpdateInterval=1d
|
||||
|
||||
# Never update while the battery is below this percentage. Ignored on mains
|
||||
# power and on machines without a battery.
|
||||
MinBatteryPercent=40
|
||||
|
||||
# Update only while plugged in. Stricter than MinBatteryPercent.
|
||||
RequireAC=no
|
||||
|
||||
# Postpone the update while a game is running (GameMode, known game processes,
|
||||
# or an application blocking idle).
|
||||
SkipWhenGaming=yes
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# What
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
UpdateAUR=yes
|
||||
UpdateFlatpak=yes
|
||||
UpdateAppImages=yes
|
||||
|
||||
# Also rebuild -git / -devel AUR packages. Off by default: these rebuild
|
||||
# constantly and break more often than released packages.
|
||||
UpdateDevel=no
|
||||
|
||||
# Which AUR helper to use: auto, paru, yay or pikaur.
|
||||
AURHelper=auto
|
||||
|
||||
# When a new package has to replace or remove an existing one, decide it
|
||||
# automatically instead of aborting the update. Straightforward replacements
|
||||
# are handled either way; this covers the case where pacman would otherwise
|
||||
# stop and ask.
|
||||
AutoResolveConflicts=yes
|
||||
|
||||
# Packages that are never updated automatically, space separated.
|
||||
# Example: IgnorePkg=linux linux-headers nvidia
|
||||
IgnorePkg=
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Housekeeping - all off by default
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# Trim the pacman package cache after an update.
|
||||
CleanCache=no
|
||||
|
||||
# How many old versions per package to keep when CleanCache is on.
|
||||
KeepOldPackages=3
|
||||
|
||||
# Remove packages that were installed as dependencies and are no longer needed.
|
||||
RemoveOrphans=no
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Notification detail
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# Say something after a successful update. Nothing is ever shown when there
|
||||
# was nothing to do.
|
||||
NotifyOnSuccess=yes
|
||||
|
||||
# Report failures.
|
||||
NotifyOnError=yes
|
||||
|
||||
# Point out that a kernel update needs a restart. The machine is never
|
||||
# restarted automatically.
|
||||
NotifyReboot=yes
|
||||
@@ -0,0 +1,9 @@
|
||||
/var/log/cachy-auto-update/*.log {
|
||||
weekly
|
||||
rotate 8
|
||||
missingok
|
||||
notifempty
|
||||
compress
|
||||
delaycompress
|
||||
create 0644 root root
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
# Privilege bridge for unattended AUR updates.
|
||||
#
|
||||
# makepkg, paru and yay refuse to run as root, so the update service runs them
|
||||
# as the "cachy-auto-update" system account. That account then needs to be able
|
||||
# to hand the finished packages to pacman without a human typing a password.
|
||||
#
|
||||
# The account is created by sysusers.d with no password and /usr/bin/nologin:
|
||||
# it cannot be logged into, and only root can become it. Since the service that
|
||||
# uses it already runs as root, this rule does not widen the trust boundary -
|
||||
# it only lets an existing root process take the detour that makepkg demands.
|
||||
#
|
||||
# The rule is deliberately not restricted by arguments. paru and yay call
|
||||
# pacman with argument lists that vary per transaction, so any pattern match
|
||||
# would give the appearance of a restriction while breaking at random.
|
||||
|
||||
Defaults:cachy-auto-update !requiretty
|
||||
Defaults:cachy-auto-update env_keep += "PACMAN"
|
||||
|
||||
cachy-auto-update ALL=(root) NOPASSWD: /usr/bin/pacman
|
||||
@@ -0,0 +1,37 @@
|
||||
[Unit]
|
||||
Description=CachyOS unattended update run
|
||||
Documentation=man:cachy-auto-update(1)
|
||||
Documentation=https://github.com/Felitendo/cachy-auto-update
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
ConditionPathExists=/etc/cachy-auto-update/cachy-auto-update.conf
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/lib/cachy-auto-update/cachy-auto-update-run
|
||||
|
||||
# Tool output has to stay parseable; everything shown to a human is rendered
|
||||
# back into their own locale explicitly.
|
||||
Environment=LC_ALL=C
|
||||
|
||||
# Stay out of the way of whatever the user is actually doing. Building an AUR
|
||||
# package should never make the desktop stutter.
|
||||
Nice=19
|
||||
CPUSchedulingPolicy=idle
|
||||
IOSchedulingClass=idle
|
||||
IOSchedulingPriority=7
|
||||
OOMScoreAdjust=500
|
||||
|
||||
# A large AUR package can legitimately take a long time to build.
|
||||
TimeoutStartSec=4h
|
||||
|
||||
# Deliberately *not* sandboxed the way paccache.service is: this unit installs
|
||||
# packages across the whole filesystem and downloads them over the network, so
|
||||
# ProtectSystem=, PrivateNetwork= and friends would break it. NoNewPrivileges
|
||||
# in particular has to stay off - the AUR step relies on the build account
|
||||
# calling sudo.
|
||||
NoNewPrivileges=no
|
||||
ProtectHostname=yes
|
||||
|
||||
# No [Install] section on purpose: this is driven by cachy-auto-update.timer,
|
||||
# never wanted by a target of its own.
|
||||
@@ -0,0 +1,19 @@
|
||||
[Unit]
|
||||
Description=CachyOS unattended update check
|
||||
Documentation=man:cachy-auto-update(1)
|
||||
|
||||
[Timer]
|
||||
# The tick is hourly, but an actual update only happens once per
|
||||
# UpdateInterval (default: daily). That combination is what makes a postponed
|
||||
# run - low battery, a game running, somebody else using pacman - retry by
|
||||
# itself an hour later without any backoff bookkeeping.
|
||||
OnBootSec=15min
|
||||
OnCalendar=hourly
|
||||
RandomizedDelaySec=20min
|
||||
AccuracySec=5min
|
||||
|
||||
# Catch up after the machine was switched off.
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -0,0 +1,6 @@
|
||||
# The account that builds and installs AUR packages.
|
||||
#
|
||||
# makepkg, paru and yay all refuse to run as root, so the update service drops
|
||||
# to this account for the AUR step. It has no password and no shell: nobody can
|
||||
# log into it, and only root can become it.
|
||||
u cachy-auto-update - "CachyOS Auto-Update builder" /var/lib/cachy-auto-update/builder /usr/bin/nologin
|
||||
@@ -0,0 +1,15 @@
|
||||
# Type Path Mode UID GID Age Argument
|
||||
|
||||
# State the CLI reads unprivileged (`cachy-auto-update status`).
|
||||
d /var/lib/cachy-auto-update 0755 root root - -
|
||||
|
||||
# Home of the build account. Everything the AUR helper clones and compiles
|
||||
# stays in here instead of in somebody's home directory.
|
||||
d /var/lib/cachy-auto-update/builder 0700 cachy-auto-update cachy-auto-update - -
|
||||
d /var/cache/cachy-auto-update 0700 cachy-auto-update cachy-auto-update - -
|
||||
|
||||
# Logs, matching pacman's own world-readable convention so `log` works without
|
||||
# root.
|
||||
d /var/log/cachy-auto-update 0755 root root - -
|
||||
|
||||
d /run/cachy-auto-update 0755 root root - -
|
||||
@@ -0,0 +1,260 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# cachy-auto-update - unattended updates for CachyOS
|
||||
#
|
||||
# The command line front end. Everything it does is either flipping a switch in
|
||||
# /etc/cachy-auto-update/cachy-auto-update.conf, driving the systemd timer, or
|
||||
# handing off to the runner in @LIBEXECDIR@.
|
||||
#
|
||||
# Copyright (C) 2026 Felitendo
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
CAU_LIBDIR="${CAU_LIBDIR:-@LIBDIR@}"
|
||||
CAU_LIBEXECDIR="${CAU_LIBEXECDIR:-@LIBEXECDIR@}"
|
||||
|
||||
for _mod in common config users conditions locks notify menu; do
|
||||
# shellcheck source=/dev/null
|
||||
if ! source "$CAU_LIBDIR/$_mod.sh"; then
|
||||
printf 'cachy-auto-update: cannot load %s/%s.sh\n' "$CAU_LIBDIR" "$_mod" >&2
|
||||
exit 14
|
||||
fi
|
||||
done
|
||||
unset _mod
|
||||
|
||||
CAU_SELF="$(readlink -f "${BASH_SOURCE[0]}")"
|
||||
CAU_ARGV=("$@")
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Privilege
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# Re-executes itself with elevation when a human is at the terminal, so that
|
||||
# typing `cachy-auto-update` just works instead of printing a lecture.
|
||||
cau_need_root() {
|
||||
cau_is_root && return 0
|
||||
|
||||
local candidate elevate=''
|
||||
if [[ -t 0 && -t 1 ]]; then
|
||||
for candidate in sudo run0 doas; do
|
||||
if cau_have "$candidate"; then elevate="$candidate"; break; fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ -n $elevate ]]; then
|
||||
exec "$elevate" "$CAU_SELF" "${CAU_ARGV[@]}"
|
||||
fi
|
||||
|
||||
cau_bad "$(cau_msg "This command has to run as root.")"
|
||||
exit 2
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Commands
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
cau_do_enable() {
|
||||
cau_need_root
|
||||
|
||||
# A broken sudoers drop-in would take down sudo for the whole machine, so
|
||||
# it is verified before anything is switched on.
|
||||
if [[ -f /etc/sudoers.d/cachy-auto-update ]]; then
|
||||
if cau_have visudo && ! visudo -cf /etc/sudoers.d/cachy-auto-update > /dev/null 2>&1; then
|
||||
cau_bad "$(cau_msg "/etc/sudoers.d/cachy-auto-update is invalid; refusing to enable.")"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
cau_config_set Enabled yes || { cau_bad "$(cau_msg "Could not write the configuration file.")"; return 1; }
|
||||
|
||||
if cau_have systemctl; then
|
||||
systemctl enable --now cachy-auto-update.timer > /dev/null 2>&1 \
|
||||
|| cau_bad "$(cau_msg "Could not enable the systemd timer.")"
|
||||
fi
|
||||
|
||||
cau_ok "$(cau_msg "Automatic updates are on.")"
|
||||
|
||||
cau_config_load
|
||||
if [[ $CFG_AUR == yes ]] && ! cau_aur_detect_quiet; then
|
||||
cau_note "$(cau_msg "No AUR helper found - install paru or yay for AUR updates.")"
|
||||
fi
|
||||
if [[ $CFG_AUR == yes ]] && ! cau_have makepkg; then
|
||||
cau_note "$(cau_msg "base-devel is missing - AUR packages cannot be built without it.")"
|
||||
fi
|
||||
|
||||
cau_offer_disable_cachy_update
|
||||
}
|
||||
|
||||
# Whether an AUR helper exists at all, without the logging cau_aur_detect does.
|
||||
cau_aur_detect_quiet() {
|
||||
local c
|
||||
if [[ -n ${CFG_AUR_HELPER:-} && $CFG_AUR_HELPER != auto ]]; then
|
||||
cau_have "$CFG_AUR_HELPER"
|
||||
return $?
|
||||
fi
|
||||
for c in paru yay pikaur; do cau_have "$c" && return 0; done
|
||||
return 1
|
||||
}
|
||||
|
||||
# cachy-update ships an enabled user timer that only ever says "N updates
|
||||
# available". Once updates apply themselves that notification is pure noise,
|
||||
# so offer to silence it - but only ask, never decide.
|
||||
cau_offer_disable_cachy_update() {
|
||||
local user uid answer found=0
|
||||
|
||||
[[ -t 0 && -t 1 ]] || return 0
|
||||
cau_have systemctl || return 0
|
||||
|
||||
while read -r user uid; do
|
||||
[[ -n $user ]] || continue
|
||||
if cau_as_user "$user" "$uid" systemctl --user is-enabled --quiet arch-update.timer 2>/dev/null; then
|
||||
found=1
|
||||
break
|
||||
fi
|
||||
done < <(cau_active_session_users)
|
||||
|
||||
(( found )) || return 0
|
||||
|
||||
printf '\n %s\n ' \
|
||||
"$(cau_msg "cachy-update also notifies about available updates. Turn its notifications off? [y/N]")"
|
||||
read -r answer || return 0
|
||||
[[ ${answer,,} == y ]] || return 0
|
||||
|
||||
while read -r user uid; do
|
||||
[[ -n $user ]] || continue
|
||||
cau_as_user "$user" "$uid" systemctl --user disable --now arch-update.timer > /dev/null 2>&1 || true
|
||||
done < <(cau_active_session_users)
|
||||
|
||||
cau_ok "$(cau_msg "cachy-update's update check has been disabled.")"
|
||||
}
|
||||
|
||||
cau_do_disable() {
|
||||
cau_need_root
|
||||
|
||||
cau_config_set Enabled no || { cau_bad "$(cau_msg "Could not write the configuration file.")"; return 1; }
|
||||
|
||||
if cau_have systemctl; then
|
||||
systemctl disable --now cachy-auto-update.timer > /dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
cau_ok "$(cau_msg "Automatic updates are off.")"
|
||||
}
|
||||
|
||||
cau_do_notifications() {
|
||||
cau_need_root
|
||||
|
||||
case "${1:-}" in
|
||||
on|yes|true|1)
|
||||
cau_config_set Notifications yes || return 1
|
||||
cau_ok "$(cau_msg "Notifications are on.")"
|
||||
;;
|
||||
off|no|false|0)
|
||||
cau_config_set Notifications no || return 1
|
||||
cau_ok "$(cau_msg "Notifications are off.")"
|
||||
;;
|
||||
*)
|
||||
cau_bad "$(cau_msg "Usage: cachy-auto-update notifications on|off")"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
cau_do_status() {
|
||||
cau_config_load
|
||||
cau_head " $CAU_PRETTY"
|
||||
cau_ui_status
|
||||
cau_ui_status_conditions
|
||||
printf '\n'
|
||||
}
|
||||
|
||||
cau_do_run() {
|
||||
cau_need_root
|
||||
exec "$CAU_LIBEXECDIR/cachy-auto-update-run" "$@"
|
||||
}
|
||||
|
||||
cau_do_log() {
|
||||
local file="$CAU_RUNLOG" lines=200 follow=0
|
||||
|
||||
while (( $# )); do
|
||||
case "$1" in
|
||||
-n) lines="${2:-200}"; shift 2 ;;
|
||||
-n*) lines="${1#-n}"; shift ;;
|
||||
-f|--follow) follow=1; shift ;;
|
||||
-a|--all) file="$CAU_LOGFILE"; shift ;;
|
||||
*) shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ ! -r $file ]]; then
|
||||
cau_note "$(cau_msg "No log yet.")"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if (( follow )); then
|
||||
tail -n "$lines" -f "$file"
|
||||
else
|
||||
tail -n "$lines" "$file"
|
||||
fi
|
||||
}
|
||||
|
||||
cau_do_help() {
|
||||
cat <<- EOF
|
||||
$CAU_PRETTY $CAU_VERSION
|
||||
|
||||
$(cau_msg "Usage: cachy-auto-update [command]")
|
||||
|
||||
$(cau_msg "Commands:")
|
||||
enable $(cau_msg "Turn automatic updates on")
|
||||
disable $(cau_msg "Turn automatic updates off")
|
||||
notifications on|off $(cau_msg "Turn desktop notifications on or off")
|
||||
status $(cau_msg "Show the current state and conditions")
|
||||
run [--force] [--dry-run] $(cau_msg "Run an update now")
|
||||
log [-n N] [-f] [-a] $(cau_msg "Show the log of the last run")
|
||||
-h, --help $(cau_msg "Show this help")
|
||||
-V, --version $(cau_msg "Show the version")
|
||||
|
||||
$(cau_msg "Without a command an interactive menu is shown.")
|
||||
EOF
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Dispatch
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
main() {
|
||||
local cmd="${1:-}"
|
||||
[[ $# -gt 0 ]] && shift
|
||||
|
||||
case "$cmd" in
|
||||
enable) cau_do_enable "$@" ;;
|
||||
disable) cau_do_disable "$@" ;;
|
||||
notifications) cau_do_notifications "$@" ;;
|
||||
status) cau_do_status "$@" ;;
|
||||
run) cau_do_run "$@" ;;
|
||||
log) cau_do_log "$@" ;;
|
||||
|
||||
# Invoked unprivileged from the XDG autostart entry to replay
|
||||
# notifications that were produced while nobody was logged in.
|
||||
--deliver-notifications)
|
||||
cau_config_load
|
||||
cau_notify_deliver_queue
|
||||
;;
|
||||
|
||||
-h|--help|help) cau_do_help ;;
|
||||
-V|--version) printf '%s %s\n' "$CAU_NAME" "$CAU_VERSION" ;;
|
||||
|
||||
'')
|
||||
cau_need_root
|
||||
cau_ui_menu
|
||||
;;
|
||||
*)
|
||||
cau_bad "$(cau_msg "Unknown command: %s" "$cmd")"
|
||||
printf '\n'
|
||||
cau_do_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -0,0 +1,214 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# cachy-auto-update-run - one unattended update pass
|
||||
#
|
||||
# Started by cachy-auto-update.service as root. The timer fires hourly and this
|
||||
# decides whether anything should happen; that is what makes deferrals free.
|
||||
# Refusing to run is the normal, expected outcome most of the time, so it is
|
||||
# never treated as an error.
|
||||
#
|
||||
# Copyright (C) 2026 Felitendo
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
CAU_LIBDIR="${CAU_LIBDIR:-@LIBDIR@}"
|
||||
|
||||
for _mod in common config users conditions locks notify \
|
||||
pkg_pacman pkg_aur pkg_flatpak pkg_appimage; do
|
||||
# shellcheck source=/dev/null
|
||||
if ! source "$CAU_LIBDIR/$_mod.sh"; then
|
||||
printf 'cachy-auto-update-run: cannot load %s/%s.sh\n' "$CAU_LIBDIR" "$_mod" >&2
|
||||
exit 14
|
||||
fi
|
||||
done
|
||||
unset _mod
|
||||
|
||||
FORCE=0
|
||||
DRY_RUN=0
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--force) FORCE=1 ;;
|
||||
--dry-run) DRY_RUN=1 ;;
|
||||
--debug) CAU_DEBUG=1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
printf 'cachy-auto-update-run: must run as root\n' >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Re-exec under an inhibitor so a suspend or shutdown cannot land in the middle
|
||||
# of a pacman transaction and leave the database half-written. Done before
|
||||
# anything else so the whole pass is covered, including the lock.
|
||||
if [[ -z ${CAU_INHIBITED:-} ]] && command -v systemd-inhibit > /dev/null 2>&1; then
|
||||
export CAU_INHIBITED=1
|
||||
exec systemd-inhibit \
|
||||
--what=sleep:shutdown \
|
||||
--mode=block \
|
||||
--who="CachyOS Auto-Update" \
|
||||
--why="Applying system updates" \
|
||||
-- "$0" "$@"
|
||||
fi
|
||||
|
||||
cau_config_load
|
||||
cau_log_open
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Should this run happen at all?
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
defer() {
|
||||
cau_info "Deferred: $1"
|
||||
exit 0
|
||||
}
|
||||
|
||||
if ! cau_acquire_lock; then
|
||||
cau_debug "Another run is already in progress"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if (( ! FORCE )); then
|
||||
if [[ $CFG_ENABLED != yes ]]; then
|
||||
cau_debug "Automatic updates are disabled"
|
||||
exit 0
|
||||
fi
|
||||
if ! cau_update_due; then
|
||||
cau_debug "Not due yet (interval $CFG_INTERVAL)"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
cau_state_write last_run "$(date +%s)"
|
||||
|
||||
if (( ! FORCE )); then
|
||||
CAU_SKIP_REASON=''
|
||||
cau_power_ok || defer "$CAU_SKIP_REASON"
|
||||
|
||||
if [[ $CFG_SKIP_GAMING == yes ]]; then
|
||||
CAU_SKIP_REASON=''
|
||||
if cau_busy; then
|
||||
defer "$CAU_SKIP_REASON"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# This one is checked even with --force: proceeding anyway would just hand the
|
||||
# user a lock error instead of doing anything useful.
|
||||
CAU_SKIP_REASON=''
|
||||
if cau_package_manager_busy; then
|
||||
if cau_track_stale_lock; then
|
||||
cau_warn "pacman's database lock appears to be stale"
|
||||
cau_notify normal \
|
||||
"Package database locked" \
|
||||
"pacman's lock file looks left over from an interrupted update. Updates are paused until it is cleared."
|
||||
fi
|
||||
defer "$CAU_SKIP_REASON"
|
||||
fi
|
||||
cau_state_clear stale_lock_count
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Dry run
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
if (( DRY_RUN )); then
|
||||
printf '%s\n' "Would update on this machine:"
|
||||
|
||||
if cau_pacman_pending; then
|
||||
printf ' repository packages: %s\n' "$(grep -c . <<< "$CAU_PACMAN_PENDING")"
|
||||
sed 's/^/ /' <<< "$CAU_PACMAN_PENDING"
|
||||
else
|
||||
printf ' repository packages: 0\n'
|
||||
fi
|
||||
|
||||
if [[ $CFG_AUR == yes ]] && cau_aur_ready; then
|
||||
printf ' AUR packages: %s (%s)\n' "$(cau_aur_pending)" "$CAU_AUR_HELPER"
|
||||
else
|
||||
printf ' AUR packages: skipped\n'
|
||||
fi
|
||||
|
||||
if [[ $CFG_FLATPAK == yes ]] && cau_have flatpak; then
|
||||
printf ' system Flatpaks: %s\n' "$(cau_flatpak_pending_system)"
|
||||
else
|
||||
printf ' system Flatpaks: skipped\n'
|
||||
fi
|
||||
|
||||
printf ' AppImages: %s\n' \
|
||||
"$([[ $CFG_APPIMAGE == yes ]] && printf 'checked via Gear Lever' || printf 'skipped')"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Do the work
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
cau_info "Starting update run"
|
||||
failed=0
|
||||
|
||||
if ! cau_pacman_update; then
|
||||
failed=1
|
||||
fi
|
||||
|
||||
if [[ $CFG_AUR == yes ]]; then
|
||||
cau_aur_update || failed=1
|
||||
fi
|
||||
|
||||
if [[ $CFG_FLATPAK == yes ]]; then
|
||||
cau_flatpak_update || failed=1
|
||||
fi
|
||||
|
||||
if [[ $CFG_APPIMAGE == yes ]]; then
|
||||
cau_appimage_update || true # best effort; never marks the run as failed
|
||||
fi
|
||||
|
||||
cau_pacman_cleanup
|
||||
|
||||
pacnew="$(cau_pacman_pacnew_count)"
|
||||
if [[ $pacnew =~ ^[0-9]+$ ]] && (( pacnew > 0 )); then
|
||||
cau_info "$pacnew .pacnew file(s) present; left untouched"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Record and report
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
total=$(( CAU_PACMAN_COUNT + CAU_AUR_COUNT + CAU_FLATPAK_COUNT + CAU_APPIMAGE_COUNT ))
|
||||
|
||||
cau_state_write last_counts \
|
||||
"$CAU_PACMAN_COUNT $CAU_AUR_COUNT $CAU_FLATPAK_COUNT $CAU_APPIMAGE_COUNT"
|
||||
|
||||
if (( failed )); then
|
||||
cau_state_write last_result failed
|
||||
cau_error "Update run finished with errors"
|
||||
[[ $CFG_NOTIFY_ERROR == yes ]] && cau_notify critical \
|
||||
"Update failed" \
|
||||
"Something went wrong while updating. Run 'cachy-auto-update log' for details."
|
||||
else
|
||||
cau_state_write last_result ok
|
||||
cau_state_write last_success "$(date +%s)"
|
||||
cau_info "Update run finished successfully ($total item(s) updated)"
|
||||
|
||||
if (( total > 0 )) && [[ $CFG_NOTIFY_SUCCESS == yes ]]; then
|
||||
cau_notify low "System updated" "%d updates were installed." "$total"
|
||||
fi
|
||||
fi
|
||||
|
||||
if cau_pacman_reboot_needed; then
|
||||
cau_state_write reboot_needed 1
|
||||
cau_info "A kernel update needs a restart"
|
||||
[[ $CFG_NOTIFY_REBOOT == yes ]] && cau_notify normal \
|
||||
"Restart recommended" \
|
||||
"A new kernel was installed. Please restart when it suits you."
|
||||
else
|
||||
cau_state_write reboot_needed 0
|
||||
fi
|
||||
|
||||
# Keep the state readable for the unprivileged `status` and `log` commands.
|
||||
# Only the plain files: the build account's home lives in here too and must
|
||||
# keep its own ownership and mode.
|
||||
chmod 0755 "$CAU_STATEDIR" 2>/dev/null || true
|
||||
find "$CAU_STATEDIR" -maxdepth 1 -type f -exec chmod 0644 {} + 2>/dev/null || true
|
||||
|
||||
exit $(( failed ? 1 : 0 ))
|
||||
@@ -0,0 +1,225 @@
|
||||
# shellcheck shell=bash
|
||||
#
|
||||
# Paths, logging, translations and small shared helpers.
|
||||
#
|
||||
# Sourced by both the CLI and the update runner, so it must not assume it is
|
||||
# running as root and must not produce any output on its own.
|
||||
|
||||
CAU_VERSION="@VERSION@"
|
||||
CAU_NAME="cachy-auto-update"
|
||||
CAU_PRETTY="CachyOS Auto-Update"
|
||||
|
||||
# Directories. All of them are overridable so the tree can be exercised
|
||||
# straight from a git checkout without installing anything.
|
||||
CAU_LIBDIR="${CAU_LIBDIR:-@LIBDIR@}"
|
||||
CAU_LIBEXECDIR="${CAU_LIBEXECDIR:-@LIBEXECDIR@}"
|
||||
CAU_LOCALEDIR="${CAU_LOCALEDIR:-@LOCALEDIR@}"
|
||||
CAU_CONFDIR="${CAU_CONFDIR:-/etc/cachy-auto-update}"
|
||||
CAU_CONFIG="${CAU_CONFIG:-${CAU_CONFDIR}/cachy-auto-update.conf}"
|
||||
CAU_STATEDIR="${CAU_STATEDIR:-/var/lib/cachy-auto-update}"
|
||||
CAU_CACHEDIR="${CAU_CACHEDIR:-/var/cache/cachy-auto-update}"
|
||||
CAU_LOGDIR="${CAU_LOGDIR:-/var/log/cachy-auto-update}"
|
||||
CAU_RUNDIR="${CAU_RUNDIR:-/run/cachy-auto-update}"
|
||||
|
||||
CAU_LOGFILE="${CAU_LOGDIR}/cachy-auto-update.log"
|
||||
CAU_RUNLOG="${CAU_LOGDIR}/last-run.log"
|
||||
CAU_LOCKFILE="${CAU_RUNDIR}/run.lock"
|
||||
CAU_NOTIFY_QUEUE="${CAU_STATEDIR}/notify-queue"
|
||||
|
||||
# The locked system account that builds and installs AUR packages. Created by
|
||||
# sysusers.d; its home lives under the state directory.
|
||||
CAU_BUILD_USER="cachy-auto-update"
|
||||
CAU_BUILD_HOME="${CAU_STATEDIR}/builder"
|
||||
|
||||
# Pacman's own database lock. Presence means somebody is mid-transaction.
|
||||
CAU_PACMAN_LOCK="/var/lib/pacman/db.lck"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Translations
|
||||
# ---------------------------------------------------------------------------
|
||||
# Messages are authored in English and translated through gettext. The runner
|
||||
# is started with LC_ALL=C so that pacman/upower output stays parseable, which
|
||||
# means every user-facing string has to opt back into a real locale explicitly
|
||||
# via cau_msg / cau_msg_in.
|
||||
|
||||
export TEXTDOMAIN="cachy-auto-update"
|
||||
export TEXTDOMAINDIR="${CAU_LOCALEDIR}"
|
||||
|
||||
# The locale user-facing text should be rendered in.
|
||||
#
|
||||
# Standard POSIX precedence, deliberately: LC_ALL wins outright, and LC_ALL=C
|
||||
# really does mean English. The service sets LC_ALL=C so that pacman and upower
|
||||
# stay parseable, which makes the log English - correct, since the log is a
|
||||
# technical artefact. Anything aimed at a person (a desktop notification) does
|
||||
# not go through here at all; it names the recipient's own locale explicitly
|
||||
# via cau_msg_in and cau_user_locale.
|
||||
cau_ui_locale() {
|
||||
local l="${CAU_UI_LOCALE:-}"
|
||||
|
||||
if [[ -z $l ]]; then
|
||||
l="${LC_ALL:-}"
|
||||
[[ -z $l ]] && l="${LC_MESSAGES:-}"
|
||||
[[ -z $l ]] && l="${LANG:-}"
|
||||
fi
|
||||
|
||||
if [[ -z $l && -r /etc/locale.conf ]]; then
|
||||
l="$(sed -n 's/^LANG=//p' /etc/locale.conf | tr -d '"' | head -n1)"
|
||||
fi
|
||||
|
||||
printf '%s\n' "${l:-C}"
|
||||
}
|
||||
|
||||
# cau_msg <msgid> [printf args...]
|
||||
# Translate a string into the UI locale and printf it (no trailing newline).
|
||||
cau_msg() {
|
||||
cau_msg_in "$(cau_ui_locale)" "$@"
|
||||
}
|
||||
|
||||
# cau_msg_in <locale> <msgid> [printf args...]
|
||||
cau_msg_in() {
|
||||
local locale="$1" msgid="$2" translated
|
||||
shift 2
|
||||
|
||||
translated="$(LC_ALL="$locale" LANGUAGE="${locale%%.*}" gettext -- "$msgid" 2>/dev/null)"
|
||||
[[ -n $translated ]] || translated="$msgid"
|
||||
|
||||
# shellcheck disable=SC2059 # the format string is the translated message
|
||||
printf -- "$translated" "$@"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Output and logging
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
if [[ -t 1 && -z ${NO_COLOR:-} ]]; then
|
||||
CAU_C_RESET=$'\033[0m'
|
||||
CAU_C_BOLD=$'\033[1m'
|
||||
CAU_C_DIM=$'\033[2m'
|
||||
CAU_C_BLUE=$'\033[38;2;23;147;209m'
|
||||
CAU_C_GREEN=$'\033[32m'
|
||||
CAU_C_YELLOW=$'\033[33m'
|
||||
CAU_C_RED=$'\033[31m'
|
||||
else
|
||||
CAU_C_RESET='' CAU_C_BOLD='' CAU_C_DIM='' CAU_C_BLUE=''
|
||||
CAU_C_GREEN='' CAU_C_YELLOW='' CAU_C_RED=''
|
||||
fi
|
||||
|
||||
# Appends to the persistent log when writable (i.e. when running as root) and
|
||||
# always echoes to stderr so journald picks it up for the service.
|
||||
cau_log() {
|
||||
local level="$1"
|
||||
shift
|
||||
local line
|
||||
line="$(date '+%Y-%m-%d %H:%M:%S') [$level] $*"
|
||||
|
||||
printf '%s\n' "$line" >&2
|
||||
if [[ -n ${CAU_LOG_OPEN:-} ]]; then
|
||||
printf '%s\n' "$line" >> "$CAU_LOGFILE" 2>/dev/null || true
|
||||
printf '%s\n' "$line" >> "$CAU_RUNLOG" 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
cau_info() { cau_log INFO "$@"; }
|
||||
cau_warn() { cau_log WARN "$@"; }
|
||||
cau_error() { cau_log ERROR "$@"; }
|
||||
cau_debug() { [[ -n ${CAU_DEBUG:-} ]] && cau_log DEBUG "$@"; return 0; }
|
||||
|
||||
# Opens the log files for this run. Only meaningful as root.
|
||||
cau_log_open() {
|
||||
mkdir -p "$CAU_LOGDIR" 2>/dev/null || return 0
|
||||
chmod 0750 "$CAU_LOGDIR" 2>/dev/null || true
|
||||
: > "$CAU_RUNLOG" 2>/dev/null || return 0
|
||||
CAU_LOG_OPEN=1
|
||||
}
|
||||
|
||||
# Runs a command, streaming its combined output into the run log. Returns the
|
||||
# command's exit status.
|
||||
cau_run_logged() {
|
||||
if [[ -n ${CAU_LOG_OPEN:-} ]]; then
|
||||
"$@" >> "$CAU_RUNLOG" 2>&1
|
||||
else
|
||||
"$@" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Terminal helpers for the CLI
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
cau_say() { printf '%s\n' "$*"; }
|
||||
cau_head() { printf '\n%s%s%s\n\n' "$CAU_C_BOLD$CAU_C_BLUE" "$*" "$CAU_C_RESET"; }
|
||||
cau_ok() { printf '%s✔%s %s\n' "$CAU_C_GREEN" "$CAU_C_RESET" "$*"; }
|
||||
cau_bad() { printf '%s✘%s %s\n' "$CAU_C_RED" "$CAU_C_RESET" "$*" >&2; }
|
||||
cau_note() { printf '%s•%s %s\n' "$CAU_C_DIM" "$CAU_C_RESET" "$*"; }
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# State files
|
||||
# ---------------------------------------------------------------------------
|
||||
# Every piece of state is one small file under CAU_STATEDIR. That keeps the
|
||||
# CLI, the runner and the login-time notification delivery from needing any
|
||||
# shared parsing code.
|
||||
|
||||
cau_state_read() {
|
||||
local key="$1" default="${2:-}"
|
||||
if [[ -r "$CAU_STATEDIR/$key" ]]; then
|
||||
cat "$CAU_STATEDIR/$key"
|
||||
else
|
||||
printf '%s\n' "$default"
|
||||
fi
|
||||
}
|
||||
|
||||
cau_state_write() {
|
||||
local key="$1"
|
||||
shift
|
||||
mkdir -p "$CAU_STATEDIR" 2>/dev/null || return 1
|
||||
printf '%s\n' "$*" > "$CAU_STATEDIR/$key"
|
||||
}
|
||||
|
||||
cau_state_clear() {
|
||||
rm -f "$CAU_STATEDIR/$1" 2>/dev/null || true
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Misc
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
cau_have() { command -v "$1" > /dev/null 2>&1; }
|
||||
|
||||
cau_is_root() { [[ $EUID -eq 0 ]]; }
|
||||
|
||||
# Turns a duration such as "1d", "6h", "30m" or a bare number of seconds into
|
||||
# seconds. Returns the fallback for anything unparseable.
|
||||
cau_duration_to_seconds() {
|
||||
local v="$1" fallback="${2:-86400}" num unit
|
||||
|
||||
[[ $v =~ ^([0-9]+)([smhdw]?)$ ]] || { printf '%s\n' "$fallback"; return; }
|
||||
num="${BASH_REMATCH[1]}"
|
||||
unit="${BASH_REMATCH[2]}"
|
||||
|
||||
case "$unit" in
|
||||
s|'') printf '%s\n' "$num" ;;
|
||||
m) printf '%s\n' "$(( num * 60 ))" ;;
|
||||
h) printf '%s\n' "$(( num * 3600 ))" ;;
|
||||
d) printf '%s\n' "$(( num * 86400 ))" ;;
|
||||
w) printf '%s\n' "$(( num * 604800 ))" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Human-readable "x minutes ago" for a unix timestamp. Empty input yields the
|
||||
# translated "never".
|
||||
cau_time_ago() {
|
||||
local ts="$1" now delta
|
||||
|
||||
[[ $ts =~ ^[0-9]+$ ]] || { cau_msg "never"; printf '\n'; return; }
|
||||
|
||||
now="$(date +%s)"
|
||||
delta=$(( now - ts ))
|
||||
(( delta < 0 )) && delta=0
|
||||
|
||||
if (( delta < 60 )); then cau_msg "just now"
|
||||
elif (( delta < 3600 )); then cau_msg "%d minutes ago" "$(( delta / 60 ))"
|
||||
elif (( delta < 86400 )); then cau_msg "%d hours ago" "$(( delta / 3600 ))"
|
||||
else cau_msg "%d days ago" "$(( delta / 86400 ))"
|
||||
fi
|
||||
printf '\n'
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
# shellcheck shell=bash
|
||||
#
|
||||
# Should we update right now?
|
||||
#
|
||||
# Every check here is allowed to say "not now" and nothing more. The timer
|
||||
# ticks hourly, so a deferral costs nothing: the next tick simply tries again.
|
||||
# That is also why none of these functions ever return a hard failure.
|
||||
|
||||
# Set by the checks below to a human-readable, already translated reason.
|
||||
CAU_SKIP_REASON=''
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Power
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# cau_on_ac
|
||||
# True when running on mains power. systemd-ac-power also returns success when
|
||||
# the machine has neither a battery nor an adapter, which is exactly right for
|
||||
# desktops - hand-rolled sysfs globbing gets that case wrong.
|
||||
cau_on_ac() {
|
||||
if cau_have systemd-ac-power; then
|
||||
systemd-ac-power > /dev/null 2>&1
|
||||
return $?
|
||||
fi
|
||||
|
||||
local ps online
|
||||
for ps in /sys/class/power_supply/*; do
|
||||
[[ -r "$ps/type" ]] || continue
|
||||
[[ "$(< "$ps/type")" == Mains ]] || continue
|
||||
[[ -r "$ps/online" ]] || continue
|
||||
online="$(< "$ps/online")"
|
||||
[[ $online == 1 ]] && return 0
|
||||
done
|
||||
|
||||
# No mains device found at all: if there is no system battery either this
|
||||
# is a desktop, so assume mains rather than blocking updates forever.
|
||||
cau_battery_percent > /dev/null || return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
# cau_battery_percent
|
||||
# Average charge across the system batteries, or failure when the machine has
|
||||
# none. Peripheral batteries (mice, headsets) advertise type=Battery too and
|
||||
# are filtered out via the scope attribute; when scope is missing entirely -
|
||||
# as on many laptops - the device counts as a system battery.
|
||||
cau_battery_percent() {
|
||||
local ps sum=0 count=0 cap
|
||||
|
||||
for ps in /sys/class/power_supply/*; do
|
||||
[[ -r "$ps/type" ]] || continue
|
||||
[[ "$(< "$ps/type")" == Battery ]] || continue
|
||||
|
||||
if [[ -r "$ps/scope" ]]; then
|
||||
[[ "$(< "$ps/scope")" == System ]] || continue
|
||||
fi
|
||||
if [[ -r "$ps/present" ]]; then
|
||||
[[ "$(< "$ps/present")" == 1 ]] || continue
|
||||
fi
|
||||
[[ -r "$ps/capacity" ]] || continue
|
||||
|
||||
cap="$(< "$ps/capacity")"
|
||||
[[ $cap =~ ^[0-9]+$ ]] || continue
|
||||
sum=$(( sum + cap ))
|
||||
count=$(( count + 1 ))
|
||||
done
|
||||
|
||||
(( count > 0 )) || return 1
|
||||
printf '%s\n' "$(( sum / count ))"
|
||||
}
|
||||
|
||||
# cau_power_ok
|
||||
# Applies RequireAC and MinBatteryPercent.
|
||||
cau_power_ok() {
|
||||
local pct
|
||||
|
||||
if cau_on_ac; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ $CFG_REQUIRE_AC == yes ]]; then
|
||||
CAU_SKIP_REASON="$(cau_msg "running on battery")"
|
||||
return 1
|
||||
fi
|
||||
|
||||
pct="$(cau_battery_percent)" || return 0 # no battery: nothing to gate on
|
||||
|
||||
if (( pct < CFG_MIN_BATTERY )); then
|
||||
CAU_SKIP_REASON="$(cau_msg "battery at %d%%, below the %d%% threshold" \
|
||||
"$pct" "$CFG_MIN_BATTERY")"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Is the user in the middle of something?
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# Process names that mean a game is actually running. Deliberately excludes
|
||||
# "steam" itself, which sits in the tray all day on a gaming machine.
|
||||
CAU_GAME_PROCESSES=(
|
||||
gamescope
|
||||
wine wine64 wineserver wine-preloader wine64-preloader
|
||||
umu-run proton
|
||||
reaper
|
||||
lutris lutris-wrapper heroic bottles
|
||||
retroarch dolphin-emu pcsx2-qt rpcs3 cemu ryujinx ppsspp citra-qt duckstation-qt
|
||||
)
|
||||
|
||||
# cau_process_running <name>
|
||||
# Exact-name match that ignores kernel threads. The exactness matters: a
|
||||
# substring match on "reaper" hits the kernel's own oom_reaper on every box.
|
||||
cau_process_running() {
|
||||
local name="$1" pid ppid
|
||||
|
||||
while read -r pid; do
|
||||
[[ $pid =~ ^[0-9]+$ ]] || continue
|
||||
(( pid == 2 )) && continue
|
||||
# /proc/<pid>/status rather than /stat: the comm field in /stat can
|
||||
# contain spaces and parentheses, which shifts every column after it.
|
||||
ppid="$(sed -n 's/^PPid:[[:space:]]*//p' "/proc/$pid/status" 2>/dev/null)" || continue
|
||||
[[ $ppid == 2 ]] && continue # kernel thread
|
||||
return 0
|
||||
done < <(pgrep -x -- "$name" 2>/dev/null)
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# cau_gamemode_active
|
||||
# Asks GameMode how many clients it is tracking, per graphical session.
|
||||
# GameMode is optional and frequently absent; any failure means "unknown", not
|
||||
# "busy".
|
||||
cau_gamemode_active() {
|
||||
local user uid out count
|
||||
|
||||
cau_have busctl || return 1
|
||||
|
||||
while read -r user uid; do
|
||||
[[ -n $user ]] || continue
|
||||
# timeout runs inside the runuser call because it has to be a real
|
||||
# binary there - it cannot wrap a shell function from out here.
|
||||
out="$(cau_as_user "$user" "$uid" timeout 5 busctl --user --json=short \
|
||||
get-property com.feralinteractive.GameMode \
|
||||
/com/feralinteractive/GameMode \
|
||||
com.feralinteractive.GameMode ClientCount 2>/dev/null)" || continue
|
||||
count="$(sed -nE 's/.*"data"[[:space:]]*:[[:space:]]*([0-9]+).*/\1/p' <<< "$out")"
|
||||
[[ -z $count ]] && count="$(awk '{print $NF}' <<< "$out")"
|
||||
[[ $count =~ ^[0-9]+$ ]] || continue
|
||||
(( count > 0 )) && return 0
|
||||
done < <(cau_active_session_users)
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# cau_idle_inhibited
|
||||
# A blocking "idle" inhibitor is what fullscreen games and video players take.
|
||||
cau_idle_inhibited() {
|
||||
cau_have systemd-inhibit || return 1
|
||||
systemd-inhibit --list 2>/dev/null \
|
||||
| awk 'tolower($0) ~ /idle/ && $NF == "block" { found = 1 } END { exit !found }'
|
||||
}
|
||||
|
||||
# cau_busy
|
||||
# True when something is running that an update should not interrupt.
|
||||
cau_busy() {
|
||||
local proc
|
||||
|
||||
if cau_gamemode_active; then
|
||||
CAU_SKIP_REASON="$(cau_msg "a game is running (GameMode)")"
|
||||
return 0
|
||||
fi
|
||||
|
||||
for proc in "${CAU_GAME_PROCESSES[@]}"; do
|
||||
if cau_process_running "$proc"; then
|
||||
CAU_SKIP_REASON="$(cau_msg "a game is running (%s)" "$proc")"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
if cau_idle_inhibited; then
|
||||
CAU_SKIP_REASON="$(cau_msg "an application is blocking idle (fullscreen game or video)")"
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Scheduling
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# cau_update_due
|
||||
# The timer fires hourly; this decides whether enough time has passed since the
|
||||
# last *successful* run. Deferred runs therefore retry automatically without
|
||||
# any backoff bookkeeping of their own.
|
||||
cau_update_due() {
|
||||
local last now
|
||||
|
||||
last="$(cau_state_read last_success 0)"
|
||||
[[ $last =~ ^[0-9]+$ ]] || last=0
|
||||
(( last == 0 )) && return 0
|
||||
|
||||
now="$(date +%s)"
|
||||
(( now - last >= CFG_INTERVAL_SECONDS ))
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
# shellcheck shell=bash
|
||||
#
|
||||
# Reading and writing /etc/cachy-auto-update/cachy-auto-update.conf.
|
||||
#
|
||||
# The file is deliberately *parsed* rather than sourced: it is edited by a
|
||||
# root-run daemon, and sourcing it would turn a stray line into arbitrary code
|
||||
# execution. The format is one "Key=Value" per line, '#' starts a comment.
|
||||
|
||||
# cau_config_get <Key> [default]
|
||||
cau_config_get() {
|
||||
local key="$1" default="${2:-}" val
|
||||
|
||||
[[ -r $CAU_CONFIG ]] || { printf '%s\n' "$default"; return; }
|
||||
|
||||
val="$(sed -nE "s/^[[:space:]]*${key}[[:space:]]*=[[:space:]]*(.*)$/\\1/p" \
|
||||
"$CAU_CONFIG" 2>/dev/null | tail -n1)"
|
||||
|
||||
# strip a trailing comment and surrounding whitespace/quotes
|
||||
val="${val%%#*}"
|
||||
val="${val#"${val%%[![:space:]]*}"}"
|
||||
val="${val%"${val##*[![:space:]]}"}"
|
||||
val="${val%\"}"
|
||||
val="${val#\"}"
|
||||
|
||||
if [[ -n $val ]]; then
|
||||
printf '%s\n' "$val"
|
||||
else
|
||||
printf '%s\n' "$default"
|
||||
fi
|
||||
}
|
||||
|
||||
# cau_config_bool <Key> <default: yes|no>
|
||||
# Succeeds when the key is truthy.
|
||||
cau_config_bool() {
|
||||
local val
|
||||
val="$(cau_config_get "$1" "$2")"
|
||||
case "${val,,}" in
|
||||
yes|y|true|1|on|enabled) return 0 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# cau_config_int <Key> <default>
|
||||
cau_config_int() {
|
||||
local val
|
||||
val="$(cau_config_get "$1" "$2")"
|
||||
[[ $val =~ ^-?[0-9]+$ ]] && printf '%s\n' "$val" || printf '%s\n' "$2"
|
||||
}
|
||||
|
||||
# cau_config_set <Key> <Value>
|
||||
# Replaces the key in place if present (including a commented-out template
|
||||
# line), otherwise appends it. Requires write access to the config file.
|
||||
cau_config_set() {
|
||||
local key="$1" value="$2" tmp
|
||||
|
||||
if [[ ! -e $CAU_CONFIG ]]; then
|
||||
mkdir -p "$(dirname "$CAU_CONFIG")" || return 1
|
||||
printf '# %s configuration\n' "$CAU_NAME" > "$CAU_CONFIG" || return 1
|
||||
fi
|
||||
[[ -w $CAU_CONFIG ]] || return 1
|
||||
|
||||
tmp="$(mktemp "${CAU_CONFIG}.XXXXXX")" || return 1
|
||||
# keep the original permissions rather than mktemp's 0600
|
||||
chmod --reference="$CAU_CONFIG" "$tmp" 2>/dev/null || chmod 0644 "$tmp"
|
||||
|
||||
if grep -qE "^[[:space:]]*#?[[:space:]]*${key}[[:space:]]*=" "$CAU_CONFIG"; then
|
||||
awk -v key="$key" -v value="$value" '
|
||||
!done && $0 ~ "^[[:space:]]*#?[[:space:]]*" key "[[:space:]]*=" {
|
||||
print key "=" value; done = 1; next
|
||||
}
|
||||
# drop any further occurrences so the file cannot grow duplicates
|
||||
$0 ~ "^[[:space:]]*" key "[[:space:]]*=" { next }
|
||||
{ print }
|
||||
' "$CAU_CONFIG" > "$tmp" || { rm -f "$tmp"; return 1; }
|
||||
else
|
||||
cat "$CAU_CONFIG" > "$tmp" || { rm -f "$tmp"; return 1; }
|
||||
printf '%s=%s\n' "$key" "$value" >> "$tmp"
|
||||
fi
|
||||
|
||||
mv -f "$tmp" "$CAU_CONFIG"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Resolved settings
|
||||
# ---------------------------------------------------------------------------
|
||||
# Loaded once per process into plain variables so the rest of the code does not
|
||||
# re-parse the file for every lookup.
|
||||
|
||||
cau_config_load() {
|
||||
CFG_ENABLED=no; cau_config_bool Enabled no && CFG_ENABLED=yes
|
||||
CFG_NOTIFICATIONS=no; cau_config_bool Notifications yes && CFG_NOTIFICATIONS=yes
|
||||
CFG_REQUIRE_AC=no; cau_config_bool RequireAC no && CFG_REQUIRE_AC=yes
|
||||
CFG_SKIP_GAMING=no; cau_config_bool SkipWhenGaming yes && CFG_SKIP_GAMING=yes
|
||||
CFG_AUR=no; cau_config_bool UpdateAUR yes && CFG_AUR=yes
|
||||
CFG_FLATPAK=no; cau_config_bool UpdateFlatpak yes && CFG_FLATPAK=yes
|
||||
CFG_APPIMAGE=no; cau_config_bool UpdateAppImages yes && CFG_APPIMAGE=yes
|
||||
CFG_DEVEL=no; cau_config_bool UpdateDevel no && CFG_DEVEL=yes
|
||||
CFG_RESOLVE_CONFLICTS=no; cau_config_bool AutoResolveConflicts yes && CFG_RESOLVE_CONFLICTS=yes
|
||||
CFG_CLEAN_CACHE=no; cau_config_bool CleanCache no && CFG_CLEAN_CACHE=yes
|
||||
CFG_REMOVE_ORPHANS=no; cau_config_bool RemoveOrphans no && CFG_REMOVE_ORPHANS=yes
|
||||
CFG_NOTIFY_SUCCESS=no; cau_config_bool NotifyOnSuccess yes && CFG_NOTIFY_SUCCESS=yes
|
||||
CFG_NOTIFY_ERROR=no; cau_config_bool NotifyOnError yes && CFG_NOTIFY_ERROR=yes
|
||||
CFG_NOTIFY_REBOOT=no; cau_config_bool NotifyReboot yes && CFG_NOTIFY_REBOOT=yes
|
||||
|
||||
CFG_INTERVAL="$(cau_config_get UpdateInterval 1d)"
|
||||
CFG_INTERVAL_SECONDS="$(cau_duration_to_seconds "$CFG_INTERVAL" 86400)"
|
||||
CFG_MIN_BATTERY="$(cau_config_int MinBatteryPercent 40)"
|
||||
CFG_KEEP_OLD="$(cau_config_int KeepOldPackages 3)"
|
||||
CFG_AUR_HELPER="$(cau_config_get AURHelper auto)"
|
||||
CFG_IGNORE_PKG="$(cau_config_get IgnorePkg '')"
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
# shellcheck shell=bash
|
||||
#
|
||||
# Staying out of the way of a human using pacman/yay/paru.
|
||||
#
|
||||
# The contract this file implements: the machine's owner may run any package
|
||||
# manager at any time and must never see a lock error caused by us. We can only
|
||||
# guarantee that in one direction - by never *starting* while somebody else is
|
||||
# mid-transaction - so the checks here run before anything is touched, and a
|
||||
# refusal simply defers the run to the next hourly tick.
|
||||
|
||||
# Package managers that take /var/lib/pacman/db.lck. checkupdates is absent on
|
||||
# purpose: it works against a private temporary database and never touches the
|
||||
# real lock.
|
||||
CAU_PACKAGE_MANAGERS=(
|
||||
pacman pacman-static
|
||||
yay paru pikaur aurman trizen
|
||||
pamac pamac-daemon pamac-manager pamac-tray
|
||||
octopi octopi-helper
|
||||
makepkg
|
||||
)
|
||||
|
||||
# cau_acquire_lock
|
||||
# Guards against two runs overlapping (a slow run still going when the next
|
||||
# tick fires). Non-blocking: if another run holds it, this one is pointless.
|
||||
cau_acquire_lock() {
|
||||
mkdir -p "$CAU_RUNDIR" 2>/dev/null || return 1
|
||||
|
||||
exec {CAU_LOCK_FD}> "$CAU_LOCKFILE" || return 1
|
||||
flock -n "$CAU_LOCK_FD" || return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# cau_pacman_lock_holder
|
||||
# Prints the pids currently holding pacman's database lock, if any.
|
||||
cau_pacman_lock_holder() {
|
||||
[[ -e $CAU_PACMAN_LOCK ]] || return 1
|
||||
cau_have fuser || return 0 # cannot tell; assume it is held
|
||||
fuser "$CAU_PACMAN_LOCK" 2>/dev/null | tr -s ' ' '\n' | grep -E '^[0-9]+$' || return 0
|
||||
}
|
||||
|
||||
# cau_package_manager_busy
|
||||
# True when somebody else is using the package system right now. Sets
|
||||
# CAU_SKIP_REASON.
|
||||
cau_package_manager_busy() {
|
||||
local pm
|
||||
|
||||
if [[ -e $CAU_PACMAN_LOCK ]]; then
|
||||
CAU_SKIP_REASON="$(cau_msg "pacman's database is locked by another process")"
|
||||
return 0
|
||||
fi
|
||||
|
||||
for pm in "${CAU_PACKAGE_MANAGERS[@]}"; do
|
||||
if cau_process_running "$pm"; then
|
||||
CAU_SKIP_REASON="$(cau_msg "%s is currently running" "$pm")"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# cau_track_stale_lock
|
||||
# A db.lck with no process behind it is left over from a crashed transaction.
|
||||
# Removing it automatically would be reckless - if the guess is wrong it
|
||||
# corrupts a live transaction - so instead it is counted, and after enough
|
||||
# consecutive sightings the user is told to clean it up.
|
||||
CAU_STALE_LOCK_RUNS=3
|
||||
|
||||
cau_track_stale_lock() {
|
||||
local count
|
||||
|
||||
if [[ ! -e $CAU_PACMAN_LOCK ]]; then
|
||||
cau_state_clear stale_lock_count
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -n "$(cau_pacman_lock_holder)" ]]; then
|
||||
# genuinely held; not stale
|
||||
cau_state_clear stale_lock_count
|
||||
return 1
|
||||
fi
|
||||
|
||||
count="$(cau_state_read stale_lock_count 0)"
|
||||
[[ $count =~ ^[0-9]+$ ]] || count=0
|
||||
count=$(( count + 1 ))
|
||||
cau_state_write stale_lock_count "$count"
|
||||
|
||||
(( count >= CAU_STALE_LOCK_RUNS ))
|
||||
}
|
||||
|
||||
# cau_inhibit_prefix
|
||||
# Builds the command prefix that keeps logind from suspending or shutting the
|
||||
# machine down mid-transaction. Falls back to running unprotected rather than
|
||||
# refusing to update at all.
|
||||
cau_inhibit_prefix() {
|
||||
if cau_have systemd-inhibit; then
|
||||
printf '%s\n' systemd-inhibit
|
||||
printf '%s\n' --what=sleep:shutdown
|
||||
printf '%s\n' --mode=block
|
||||
printf '%s\n' "--who=$CAU_PRETTY"
|
||||
printf '%s\n' "--why=$(cau_msg_in C "applying system updates")"
|
||||
printf '%s\n' --
|
||||
fi
|
||||
}
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
# shellcheck shell=bash
|
||||
#
|
||||
# The interactive front end.
|
||||
#
|
||||
# This is the part the machine's owner actually sees, so it stays deliberately
|
||||
# small: two switches, a status block, and a way to look at what happened.
|
||||
|
||||
CAU_UNIT="cachy-auto-update.timer"
|
||||
|
||||
# _cau_row <label> <value>
|
||||
# printf's %-28s pads by bytes, so a label containing "ü" comes out one column
|
||||
# short. ${#s} counts characters in a UTF-8 locale, so the padding is computed
|
||||
# here instead - and applied inline, because command substitution would eat the
|
||||
# trailing spaces again.
|
||||
_cau_row() {
|
||||
local label="$1" value="$2" pad
|
||||
pad=$(( 28 - ${#label} ))
|
||||
(( pad < 0 )) && pad=0
|
||||
printf ' %s%*s %s\n' "$label" "$pad" '' "$value"
|
||||
}
|
||||
|
||||
_cau_onoff() {
|
||||
if [[ $1 == yes ]]; then
|
||||
printf '%s%s%s' "$CAU_C_GREEN" "$(cau_msg "ON")" "$CAU_C_RESET"
|
||||
else
|
||||
printf '%s%s%s' "$CAU_C_DIM" "$(cau_msg "OFF")" "$CAU_C_RESET"
|
||||
fi
|
||||
}
|
||||
|
||||
# cau_timer_next
|
||||
# When systemd will fire the timer next, in the user's locale.
|
||||
cau_timer_next() {
|
||||
local raw
|
||||
|
||||
cau_have systemctl || { cau_msg "unknown"; return; }
|
||||
systemctl is-enabled --quiet "$CAU_UNIT" 2>/dev/null || { cau_msg "not scheduled"; return; }
|
||||
|
||||
raw="$(systemctl show "$CAU_UNIT" --property=NextElapseUSecRealtime --value 2>/dev/null)"
|
||||
|
||||
if [[ $raw =~ ^[0-9]+$ ]] && (( raw > 0 )); then
|
||||
date -d "@$(( raw / 1000000 ))" '+%c'
|
||||
elif [[ -n $raw && $raw != 0 && $raw != n/a ]]; then
|
||||
printf '%s' "$raw"
|
||||
else
|
||||
cau_msg "unknown"
|
||||
fi
|
||||
}
|
||||
|
||||
# cau_ui_status
|
||||
# Shared by the `status` subcommand and the menu header.
|
||||
cau_ui_status() {
|
||||
local last_run last_success result counts reboot
|
||||
local pac aur fp ai total
|
||||
|
||||
last_run="$(cau_state_read last_run '')"
|
||||
last_success="$(cau_state_read last_success '')"
|
||||
result="$(cau_state_read last_result '')"
|
||||
counts="$(cau_state_read last_counts '0 0 0 0')"
|
||||
reboot="$(cau_state_read reboot_needed 0)"
|
||||
|
||||
read -r pac aur fp ai <<< "$counts"
|
||||
pac=${pac:-0}; aur=${aur:-0}; fp=${fp:-0}; ai=${ai:-0}
|
||||
total=$(( pac + aur + fp + ai ))
|
||||
|
||||
_cau_row "$(cau_msg "Automatic updates")" "$(_cau_onoff "$CFG_ENABLED")"
|
||||
_cau_row "$(cau_msg "Notifications")" "$(_cau_onoff "$CFG_NOTIFICATIONS")"
|
||||
printf '\n'
|
||||
|
||||
_cau_row "$(cau_msg "Last check")" "$(cau_time_ago "$last_run")"
|
||||
|
||||
if [[ -n $last_success ]]; then
|
||||
_cau_row "$(cau_msg "Last successful update")" \
|
||||
"$(date -d "@$last_success" '+%c' 2>/dev/null || printf '%s' "$last_success") ($(cau_msg "%d packages" "$total"))"
|
||||
else
|
||||
_cau_row "$(cau_msg "Last successful update")" "$(cau_msg "never")"
|
||||
fi
|
||||
|
||||
_cau_row "$(cau_msg "Next scheduled run")" "$(cau_timer_next)"
|
||||
|
||||
if [[ $result == failed ]]; then
|
||||
printf '\n %s%s%s\n' "$CAU_C_YELLOW" \
|
||||
"$(cau_msg "The last run reported a problem - see 'cachy-auto-update log'.")" \
|
||||
"$CAU_C_RESET"
|
||||
fi
|
||||
if [[ $reboot == 1 ]]; then
|
||||
printf '\n %s%s%s\n' "$CAU_C_YELLOW" \
|
||||
"$(cau_msg "A restart is recommended to finish a kernel update.")" \
|
||||
"$CAU_C_RESET"
|
||||
fi
|
||||
}
|
||||
|
||||
# cau_ui_status_conditions
|
||||
# Evaluates every gate individually. Without this there is no way to explain
|
||||
# why an enabled updater has not done anything on somebody else's machine.
|
||||
cau_ui_status_conditions() {
|
||||
local pct
|
||||
|
||||
printf '\n %s\n' "$(cau_msg "Current conditions:")"
|
||||
|
||||
if cau_on_ac; then
|
||||
printf ' %s %s\n' "${CAU_C_GREEN}✔${CAU_C_RESET}" "$(cau_msg "on AC power")"
|
||||
else
|
||||
pct="$(cau_battery_percent || true)"
|
||||
if [[ -n $pct ]]; then
|
||||
printf ' %s %s\n' "${CAU_C_DIM}•${CAU_C_RESET}" \
|
||||
"$(cau_msg "on battery (%d%%, threshold %d%%)" "$pct" "$CFG_MIN_BATTERY")"
|
||||
else
|
||||
printf ' %s %s\n' "${CAU_C_DIM}•${CAU_C_RESET}" "$(cau_msg "on battery")"
|
||||
fi
|
||||
fi
|
||||
|
||||
CAU_SKIP_REASON=''
|
||||
if cau_busy; then
|
||||
printf ' %s %s\n' "${CAU_C_YELLOW}•${CAU_C_RESET}" "$CAU_SKIP_REASON"
|
||||
else
|
||||
printf ' %s %s\n' "${CAU_C_GREEN}✔${CAU_C_RESET}" "$(cau_msg "no game detected")"
|
||||
fi
|
||||
|
||||
CAU_SKIP_REASON=''
|
||||
if cau_package_manager_busy; then
|
||||
printf ' %s %s\n' "${CAU_C_YELLOW}•${CAU_C_RESET}" "$CAU_SKIP_REASON"
|
||||
else
|
||||
printf ' %s %s\n' "${CAU_C_GREEN}✔${CAU_C_RESET}" "$(cau_msg "package system is free")"
|
||||
fi
|
||||
}
|
||||
|
||||
# cau_ui_menu
|
||||
# The default view. Reloads the config after every action so the toggles always
|
||||
# reflect what is actually on disk.
|
||||
cau_ui_menu() {
|
||||
local choice
|
||||
|
||||
while true; do
|
||||
cau_config_load
|
||||
|
||||
clear 2>/dev/null || true
|
||||
cau_head " $CAU_PRETTY"
|
||||
cau_ui_status
|
||||
printf '\n'
|
||||
printf ' [1] %s\n' "$(cau_msg "Toggle automatic updates")"
|
||||
printf ' [2] %s\n' "$(cau_msg "Toggle notifications")"
|
||||
printf ' [3] %s\n' "$(cau_msg "Update now")"
|
||||
printf ' [4] %s\n' "$(cau_msg "Show log")"
|
||||
printf ' [5] %s\n' "$(cau_msg "Show current conditions")"
|
||||
printf ' [q] %s\n' "$(cau_msg "Quit")"
|
||||
printf '\n > '
|
||||
|
||||
read -r choice || { printf '\n'; return 0; }
|
||||
|
||||
case "$choice" in
|
||||
1)
|
||||
if [[ $CFG_ENABLED == yes ]]; then cau_do_disable; else cau_do_enable; fi
|
||||
cau_pause
|
||||
;;
|
||||
2)
|
||||
if [[ $CFG_NOTIFICATIONS == yes ]]; then
|
||||
cau_do_notifications off
|
||||
else
|
||||
cau_do_notifications on
|
||||
fi
|
||||
cau_pause
|
||||
;;
|
||||
3) cau_do_run --force; cau_pause ;;
|
||||
4) cau_do_log; cau_pause ;;
|
||||
5) cau_ui_status_conditions; cau_pause ;;
|
||||
q|Q|'') return 0 ;;
|
||||
*) ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
cau_pause() {
|
||||
printf '\n %s' "$(cau_msg "Press Enter to continue...")"
|
||||
read -r _ || true
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
# shellcheck shell=bash
|
||||
#
|
||||
# Desktop notifications from a root system service.
|
||||
#
|
||||
# Two paths exist:
|
||||
# * live - somebody has a graphical session, so notify-send is run inside
|
||||
# it via runuser with the session bus address set;
|
||||
# * queued - nobody is logged in, so the message is appended to a spool that
|
||||
# the XDG autostart entry replays at the next login.
|
||||
#
|
||||
# Messages travel as a msgid plus printf arguments rather than as finished
|
||||
# text, so a notification queued at 04:00 is still rendered in whatever locale
|
||||
# the user's desktop turns out to be running in.
|
||||
|
||||
CAU_NOTIFY_ICON="system-software-update"
|
||||
CAU_NOTIFY_QUEUE_MAX=20
|
||||
|
||||
# cau_notify <urgency> <title-msgid> <body-msgid> [body printf args...]
|
||||
# Never fails: a machine without libnotify, or with nobody logged in, is a
|
||||
# normal state, not an error.
|
||||
cau_notify() {
|
||||
local urgency="$1" title="$2" body="$3"
|
||||
shift 3
|
||||
local -a args=("$@")
|
||||
local delivered=0 user uid locale t b
|
||||
|
||||
[[ $CFG_NOTIFICATIONS == yes ]] || return 0
|
||||
|
||||
while read -r user uid; do
|
||||
[[ -n $user ]] || continue
|
||||
cau_as_user "$user" "$uid" sh -c 'command -v notify-send >/dev/null' || continue
|
||||
|
||||
locale="$(cau_user_locale "$user" "$uid")"
|
||||
t="$(cau_msg_in "$locale" "$title")"
|
||||
b="$(cau_msg_in "$locale" "$body" "${args[@]}")"
|
||||
|
||||
if cau_as_user "$user" "$uid" notify-send \
|
||||
--app-name="$CAU_PRETTY" \
|
||||
--icon="$CAU_NOTIFY_ICON" \
|
||||
--urgency="$urgency" \
|
||||
-- "$t" "$b" 2>/dev/null
|
||||
then
|
||||
delivered=1
|
||||
fi
|
||||
done < <(cau_active_session_users)
|
||||
|
||||
(( delivered )) && return 0
|
||||
|
||||
cau_notify_enqueue "$urgency" "$title" "$body" "${args[@]}"
|
||||
}
|
||||
|
||||
# cau_notify_enqueue <urgency> <title-msgid> <body-msgid> [args...]
|
||||
# Tab-separated records, oldest first. The file is world-readable on purpose:
|
||||
# the login-time delivery runs unprivileged and only ever reads it.
|
||||
#
|
||||
# The key is a nanosecond timestamp rather than a second one: delivery marks
|
||||
# progress by "last key seen", so two records sharing a key could make the
|
||||
# second one unreachable forever if a login landed between them.
|
||||
cau_notify_enqueue() {
|
||||
local urgency="$1" title="$2" body="$3"
|
||||
shift 3
|
||||
local record tmp
|
||||
|
||||
mkdir -p "$CAU_STATEDIR" 2>/dev/null || return 0
|
||||
|
||||
record="$(date +%s%N)"$'\t'"$urgency"$'\t'"$title"$'\t'"$body"
|
||||
local arg
|
||||
for arg in "$@"; do
|
||||
record+=$'\t'"${arg//$'\t'/ }"
|
||||
done
|
||||
|
||||
printf '%s\n' "$record" >> "$CAU_NOTIFY_QUEUE" 2>/dev/null || return 0
|
||||
|
||||
# keep the spool bounded - nobody wants three weeks of backlog at login
|
||||
if (( $(wc -l < "$CAU_NOTIFY_QUEUE" 2>/dev/null || echo 0) > CAU_NOTIFY_QUEUE_MAX )); then
|
||||
tmp="$(mktemp "${CAU_NOTIFY_QUEUE}.XXXXXX")" || return 0
|
||||
tail -n "$CAU_NOTIFY_QUEUE_MAX" "$CAU_NOTIFY_QUEUE" > "$tmp"
|
||||
mv -f "$tmp" "$CAU_NOTIFY_QUEUE"
|
||||
fi
|
||||
chmod 0644 "$CAU_NOTIFY_QUEUE" 2>/dev/null || true
|
||||
}
|
||||
|
||||
# cau_notify_deliver_queue
|
||||
# Runs unprivileged, as the freshly logged-in user, from the XDG autostart
|
||||
# entry. State about what has already been seen lives in the user's own home,
|
||||
# so no write access to /var/lib is needed and each user is tracked separately.
|
||||
cau_notify_deliver_queue() {
|
||||
local seen_file seen ts urgency title body
|
||||
local -a args
|
||||
|
||||
[[ -r $CAU_NOTIFY_QUEUE ]] || return 0
|
||||
cau_have notify-send || return 0
|
||||
|
||||
seen_file="${XDG_STATE_HOME:-$HOME/.local/state}/cachy-auto-update/notify-seen"
|
||||
mkdir -p "$(dirname "$seen_file")" 2>/dev/null || return 0
|
||||
|
||||
seen=0
|
||||
[[ -r $seen_file ]] && seen="$(< "$seen_file")"
|
||||
[[ $seen =~ ^[0-9]+$ ]] || seen=0
|
||||
|
||||
local newest="$seen"
|
||||
while IFS=$'\t' read -r ts urgency title body rest; do
|
||||
[[ $ts =~ ^[0-9]+$ ]] || continue
|
||||
(( ts > seen )) || continue
|
||||
|
||||
# remaining tab-separated fields are the body's printf arguments
|
||||
args=()
|
||||
if [[ -n ${rest:-} ]]; then
|
||||
IFS=$'\t' read -r -a args <<< "$rest"
|
||||
fi
|
||||
|
||||
notify-send \
|
||||
--app-name="$CAU_PRETTY" \
|
||||
--icon="$CAU_NOTIFY_ICON" \
|
||||
--urgency="${urgency:-normal}" \
|
||||
-- "$(cau_msg "$title")" "$(cau_msg "$body" "${args[@]}")" 2>/dev/null || true
|
||||
|
||||
(( ts > newest )) && newest="$ts"
|
||||
done < "$CAU_NOTIFY_QUEUE"
|
||||
|
||||
printf '%s\n' "$newest" > "$seen_file" 2>/dev/null || true
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
# shellcheck shell=bash
|
||||
#
|
||||
# AppImages, by way of Gear Lever.
|
||||
#
|
||||
# AppImages have no package manager of their own; Gear Lever is what tracks
|
||||
# where each one came from and how to fetch a new build. Its CLI is a first
|
||||
# class interface - `--update --all -y` is exactly the unattended entry point
|
||||
# we need, and it skips AppImages whose application is currently running rather
|
||||
# than pulling the file out from under it (we deliberately do not pass
|
||||
# --force).
|
||||
#
|
||||
# This only runs for users with a live graphical session: Gear Lever is a
|
||||
# Flatpak GTK application and needs the session's runtime directory. Nothing is
|
||||
# lost by waiting - the next hourly tick will catch it once they log in.
|
||||
|
||||
CAU_APPIMAGE_ID="it.mijorus.gearlever"
|
||||
CAU_APPIMAGE_COUNT=0
|
||||
|
||||
# _cau_gearlever_cmd <user> <uid>
|
||||
# Prints the argv prefix that invokes Gear Lever for that user, or nothing when
|
||||
# it is not installed for them.
|
||||
_cau_gearlever_cmd() {
|
||||
local user="$1" uid="$2"
|
||||
|
||||
if cau_as_user "$user" "$uid" sh -c 'command -v gearlever >/dev/null 2>&1'; then
|
||||
printf '%s\n' gearlever
|
||||
return 0
|
||||
fi
|
||||
|
||||
if cau_have flatpak && \
|
||||
cau_as_user "$user" "$uid" flatpak info "$CAU_APPIMAGE_ID" > /dev/null 2>&1
|
||||
then
|
||||
printf '%s\n' flatpak run "--command=gearlever" "$CAU_APPIMAGE_ID"
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# cau_appimage_update
|
||||
# Never fatal: a headless GTK application is a best-effort proposition.
|
||||
cau_appimage_update() {
|
||||
local user uid count rc=0
|
||||
local -a cmd
|
||||
|
||||
while read -r user uid; do
|
||||
[[ -n $user ]] || continue
|
||||
|
||||
mapfile -t cmd < <(_cau_gearlever_cmd "$user" "$uid")
|
||||
(( ${#cmd[@]} )) || continue
|
||||
|
||||
# "[Update available, <manager>]" is the per-app marker in the plain
|
||||
# text listing; the alternative is --json, which would drag in a JSON
|
||||
# parser for no gain.
|
||||
count="$(cau_as_user "$user" "$uid" timeout 300 "${cmd[@]}" --list-updates 2>/dev/null \
|
||||
| grep -c '\[Update available')" || count=0
|
||||
[[ $count =~ ^[0-9]+$ ]] || count=0
|
||||
|
||||
if (( count == 0 )); then
|
||||
cau_info "No AppImage updates pending for $user"
|
||||
continue
|
||||
fi
|
||||
|
||||
cau_info "Updating $count AppImage(s) for $user"
|
||||
if cau_run_logged cau_as_user "$user" "$uid" timeout 1800 \
|
||||
"${cmd[@]}" --update --all -y
|
||||
then
|
||||
CAU_APPIMAGE_COUNT=$(( CAU_APPIMAGE_COUNT + count ))
|
||||
else
|
||||
cau_warn "AppImage update failed for $user"
|
||||
rc=1
|
||||
fi
|
||||
done < <(cau_active_session_users)
|
||||
|
||||
return $rc
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
# shellcheck shell=bash
|
||||
#
|
||||
# AUR packages.
|
||||
#
|
||||
# makepkg - and therefore paru and yay - refuse to run as root, so this is the
|
||||
# one part of the run that cannot happen in the service's own context. It is
|
||||
# executed as the locked "cachy-auto-update" system account instead, which
|
||||
# sysusers.d creates with no password and no shell. That account is granted
|
||||
# NOPASSWD access to /usr/bin/pacman through /etc/sudoers.d/cachy-auto-update,
|
||||
# which is what lets the helper install what it built without a human present.
|
||||
#
|
||||
# The alternative - stashing the user's password somewhere the daemon can read
|
||||
# it - buys nothing: whatever can decrypt it is exactly what an attacker would
|
||||
# already have.
|
||||
|
||||
CAU_AUR_COUNT=0
|
||||
CAU_AUR_HELPER=''
|
||||
|
||||
# Notify only after this many consecutive failed AUR runs. A single failed
|
||||
# build is routine (upstream broke a tarball, a checksum moved) and self-heals
|
||||
# a day later; nagging about it on someone's parents' machine is noise.
|
||||
CAU_AUR_FAILURE_THRESHOLD=2
|
||||
|
||||
# cau_aur_detect
|
||||
# Resolves the helper to use, honouring AURHelper from the config.
|
||||
cau_aur_detect() {
|
||||
local candidate
|
||||
|
||||
CAU_AUR_HELPER=''
|
||||
|
||||
if [[ -n $CFG_AUR_HELPER && $CFG_AUR_HELPER != auto ]]; then
|
||||
if cau_have "$CFG_AUR_HELPER"; then
|
||||
CAU_AUR_HELPER="$CFG_AUR_HELPER"
|
||||
return 0
|
||||
fi
|
||||
cau_warn "Configured AUR helper '$CFG_AUR_HELPER' not found"
|
||||
return 1
|
||||
fi
|
||||
|
||||
for candidate in paru yay pikaur; do
|
||||
if cau_have "$candidate"; then
|
||||
CAU_AUR_HELPER="$candidate"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# cau_as_build_user <command> [args...]
|
||||
# A deliberately small environment: the helper gets its own HOME and cache so
|
||||
# nothing it downloads ever lands in a human's home directory.
|
||||
cau_as_build_user() {
|
||||
runuser -u "$CAU_BUILD_USER" -- env \
|
||||
"HOME=$CAU_BUILD_HOME" \
|
||||
"USER=$CAU_BUILD_USER" \
|
||||
"LOGNAME=$CAU_BUILD_USER" \
|
||||
"XDG_CACHE_HOME=$CAU_CACHEDIR" \
|
||||
"XDG_CONFIG_HOME=$CAU_BUILD_HOME/.config" \
|
||||
"XDG_DATA_HOME=$CAU_BUILD_HOME/.local/share" \
|
||||
"PATH=/usr/local/sbin:/usr/local/bin:/usr/bin" \
|
||||
LC_ALL=C \
|
||||
"$@"
|
||||
}
|
||||
|
||||
# cau_aur_ready
|
||||
# True when everything the AUR path needs is actually in place.
|
||||
cau_aur_ready() {
|
||||
cau_aur_detect || { cau_info "No AUR helper installed; skipping AUR updates"; return 1; }
|
||||
|
||||
if ! getent passwd "$CAU_BUILD_USER" > /dev/null; then
|
||||
cau_warn "Build account '$CAU_BUILD_USER' is missing; skipping AUR updates"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# -l asks sudo whether the command is permitted; -n guarantees it can
|
||||
# never block on a password prompt. Testing `sudo -n true` instead would
|
||||
# fail by design, because the rule is scoped to pacman alone.
|
||||
if ! cau_as_build_user sudo -n -l /usr/bin/pacman > /dev/null 2>&1; then
|
||||
cau_warn "Build account cannot run pacman without a password; check /etc/sudoers.d/cachy-auto-update"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! cau_have makepkg; then
|
||||
cau_warn "makepkg not found (base-devel missing); skipping AUR updates"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# cau_aur_helper_args
|
||||
# The flags that turn an interactive helper into a silent one.
|
||||
cau_aur_helper_args() {
|
||||
case "$CAU_AUR_HELPER" in
|
||||
paru)
|
||||
printf '%s\n' -Sua --noconfirm --skipreview --removemake --cleanafter --color never
|
||||
[[ $CFG_DEVEL == yes ]] && printf '%s\n' --devel
|
||||
;;
|
||||
yay)
|
||||
printf '%s\n' -Sua --noconfirm --removemake --cleanafter --color never
|
||||
printf '%s\n' --answerclean All --answerdiff None --answeredit None --answerupgrade None
|
||||
[[ $CFG_DEVEL == yes ]] && printf '%s\n' --devel
|
||||
;;
|
||||
pikaur)
|
||||
printf '%s\n' -Sua --noconfirm --noedit
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# cau_aur_pending
|
||||
# Number of AUR packages with an update available.
|
||||
cau_aur_pending() {
|
||||
local out
|
||||
out="$(cau_as_build_user "$CAU_AUR_HELPER" -Qua 2>/dev/null | grep -c .)" || out=0
|
||||
[[ $out =~ ^[0-9]+$ ]] || out=0
|
||||
printf '%s\n' "$out"
|
||||
}
|
||||
|
||||
# cau_aur_update
|
||||
# Returns 0 on success or "nothing to do", 1 on a failure worth reporting.
|
||||
# Transient build failures are swallowed until they repeat.
|
||||
cau_aur_update() {
|
||||
local pending failures
|
||||
local -a args
|
||||
|
||||
cau_aur_ready || return 0
|
||||
|
||||
pending="$(cau_aur_pending)"
|
||||
if (( pending == 0 )); then
|
||||
cau_info "No AUR updates pending"
|
||||
cau_state_clear aur_failures
|
||||
return 0
|
||||
fi
|
||||
|
||||
cau_info "Updating $pending AUR package(s) with $CAU_AUR_HELPER"
|
||||
mapfile -t args < <(cau_aur_helper_args)
|
||||
|
||||
if cau_run_logged cau_as_build_user "$CAU_AUR_HELPER" "${args[@]}"; then
|
||||
CAU_AUR_COUNT="$pending"
|
||||
cau_state_clear aur_failures
|
||||
return 0
|
||||
fi
|
||||
|
||||
CAU_AUR_COUNT=0
|
||||
failures="$(cau_state_read aur_failures 0)"
|
||||
[[ $failures =~ ^[0-9]+$ ]] || failures=0
|
||||
failures=$(( failures + 1 ))
|
||||
cau_state_write aur_failures "$failures"
|
||||
|
||||
if (( failures >= CAU_AUR_FAILURE_THRESHOLD )); then
|
||||
cau_error "AUR update failed $failures times in a row"
|
||||
return 1
|
||||
fi
|
||||
|
||||
cau_warn "AUR update failed (attempt $failures); will retry on the next run"
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
# shellcheck shell=bash
|
||||
#
|
||||
# Flatpak.
|
||||
#
|
||||
# System-wide installations are updated directly as root. That side-steps a
|
||||
# real obstacle: the shipped polkit rule for Flatpak only grants install and
|
||||
# uninstall, and only to a subject that is active, local and in the wheel
|
||||
# group - none of which is true for an unattended service. Being root means
|
||||
# polkit is never consulted in the first place.
|
||||
#
|
||||
# Per-user installations live in the user's home and are updated inside their
|
||||
# own account.
|
||||
|
||||
CAU_FLATPAK_COUNT=0
|
||||
|
||||
# cau_flatpak_pending_system
|
||||
cau_flatpak_pending_system() {
|
||||
local out
|
||||
out="$(flatpak remote-ls --system --updates --columns=application 2>/dev/null | grep -c .)" || out=0
|
||||
[[ $out =~ ^[0-9]+$ ]] || out=0
|
||||
printf '%s\n' "$out"
|
||||
}
|
||||
|
||||
# cau_flatpak_update
|
||||
# Failures are reported but never abort the rest of the run.
|
||||
cau_flatpak_update() {
|
||||
local rc=0 pending user uid home count
|
||||
|
||||
cau_have flatpak || return 0
|
||||
|
||||
# refresh appstream metadata first so remote-ls sees current versions
|
||||
cau_run_logged flatpak update --appstream --system --noninteractive || true
|
||||
|
||||
pending="$(cau_flatpak_pending_system)"
|
||||
if (( pending > 0 )); then
|
||||
cau_info "Updating $pending system Flatpak(s)"
|
||||
if cau_run_logged flatpak update --system --noninteractive --assumeyes; then
|
||||
CAU_FLATPAK_COUNT=$(( CAU_FLATPAK_COUNT + pending ))
|
||||
else
|
||||
cau_warn "System Flatpak update failed"
|
||||
rc=1
|
||||
fi
|
||||
else
|
||||
cau_info "No system Flatpak updates pending"
|
||||
fi
|
||||
|
||||
while read -r user uid home; do
|
||||
[[ -d "$home/.local/share/flatpak" ]] || continue
|
||||
|
||||
count="$(cau_as_user "$user" "$uid" flatpak remote-ls --user --updates \
|
||||
--columns=application 2>/dev/null | grep -c .)" || count=0
|
||||
[[ $count =~ ^[0-9]+$ ]] || count=0
|
||||
(( count > 0 )) || continue
|
||||
|
||||
cau_info "Updating $count user Flatpak(s) for $user"
|
||||
if cau_run_logged cau_as_user "$user" "$uid" \
|
||||
flatpak update --user --noninteractive --assumeyes
|
||||
then
|
||||
CAU_FLATPAK_COUNT=$(( CAU_FLATPAK_COUNT + count ))
|
||||
else
|
||||
cau_warn "User Flatpak update failed for $user"
|
||||
rc=1
|
||||
fi
|
||||
done < <(cau_human_users)
|
||||
|
||||
if [[ $CFG_CLEAN_CACHE == yes ]]; then
|
||||
cau_run_logged flatpak uninstall --system --unused --noninteractive --assumeyes || true
|
||||
fi
|
||||
|
||||
return $rc
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
# shellcheck shell=bash
|
||||
#
|
||||
# Repository packages.
|
||||
#
|
||||
# The whole step is skipped when checkupdates reports nothing pending, which
|
||||
# matters more than it looks: checkupdates works against a private temporary
|
||||
# database, so on the common "nothing to do" day the real pacman lock is never
|
||||
# taken at all and a human using pacman is never inconvenienced.
|
||||
|
||||
CAU_PACMAN_COUNT=0
|
||||
CAU_PACMAN_PENDING=''
|
||||
|
||||
# Base flags for every unattended pacman invocation.
|
||||
cau_pacman_flags() {
|
||||
printf '%s\n' --noconfirm --color never --noprogressbar --disable-download-timeout
|
||||
local pkg
|
||||
for pkg in $CFG_IGNORE_PKG; do
|
||||
printf '%s\n' --ignore "$pkg"
|
||||
done
|
||||
}
|
||||
|
||||
# cau_pacman_pending
|
||||
# Fills CAU_PACMAN_PENDING and returns 1 when there is nothing to do.
|
||||
cau_pacman_pending() {
|
||||
local db
|
||||
|
||||
cau_have checkupdates || {
|
||||
# Without pacman-contrib we cannot look ahead cheaply; assume work.
|
||||
CAU_PACMAN_PENDING=''
|
||||
return 0
|
||||
}
|
||||
|
||||
# Kept out of CAU_CACHEDIR, which belongs to the unprivileged build
|
||||
# account; this one is written by root. pacman keeps its own sync
|
||||
# databases under /var/lib too.
|
||||
db="${CAU_STATEDIR}/checkupdates-db"
|
||||
mkdir -p "$db" 2>/dev/null || db="${TMPDIR:-/tmp}/cachy-auto-update-checkupdates"
|
||||
|
||||
CAU_PACMAN_PENDING="$(CHECKUPDATES_DB="$db" checkupdates --nocolor 2>/dev/null)"
|
||||
local rc=$?
|
||||
|
||||
# exit 2 means "no updates", anything else non-zero is a lookup failure and
|
||||
# is treated as "might have work" so a transient network hiccup does not
|
||||
# silently skip the whole run
|
||||
if (( rc == 2 )) || [[ -z $CAU_PACMAN_PENDING ]]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# _cau_pacman_classify <logfile>
|
||||
# Which kind of unattended failure was this?
|
||||
_cau_pacman_classify() {
|
||||
local log="$1"
|
||||
|
||||
if grep -qiE 'are in conflict|unresolvable package conflicts' "$log"; then
|
||||
printf 'conflict\n'
|
||||
elif grep -qiE 'signature from .* is (unknown trust|marginal trust|invalid)|invalid or corrupted package \(PGP signature\)|key ".*" is unknown|keyring is not writable' "$log"; then
|
||||
printf 'keyring\n'
|
||||
elif grep -qiE 'exists in filesystem' "$log"; then
|
||||
printf 'filesystem\n'
|
||||
else
|
||||
printf 'other\n'
|
||||
fi
|
||||
}
|
||||
|
||||
# cau_pacman_update
|
||||
# Returns 0 on success (including "nothing to do"), 1 on a failure the user
|
||||
# needs to hear about. CAU_PACMAN_COUNT holds how many packages moved.
|
||||
cau_pacman_update() {
|
||||
local log kind
|
||||
local -a flags
|
||||
|
||||
if ! cau_pacman_pending; then
|
||||
cau_info "No repository updates pending"
|
||||
return 0
|
||||
fi
|
||||
|
||||
CAU_PACMAN_COUNT="$(grep -c . <<< "$CAU_PACMAN_PENDING")"
|
||||
[[ $CAU_PACMAN_COUNT =~ ^[0-9]+$ ]] || CAU_PACMAN_COUNT=0
|
||||
cau_info "Updating $CAU_PACMAN_COUNT repository package(s)"
|
||||
|
||||
mapfile -t flags < <(cau_pacman_flags)
|
||||
log="$(mktemp)" || return 1
|
||||
|
||||
if pacman -Syu "${flags[@]}" > "$log" 2>&1; then
|
||||
cat "$log" >> "$CAU_RUNLOG" 2>/dev/null
|
||||
rm -f "$log"
|
||||
return 0
|
||||
fi
|
||||
|
||||
cat "$log" >> "$CAU_RUNLOG" 2>/dev/null
|
||||
kind="$(_cau_pacman_classify "$log")"
|
||||
cau_warn "pacman -Syu failed ($kind)"
|
||||
|
||||
case "$kind" in
|
||||
keyring)
|
||||
# A stale keyring is the one failure that is always safe to fix
|
||||
# automatically, and it blocks everything else until it is.
|
||||
cau_info "Refreshing keyrings and retrying"
|
||||
local -a keyrings=()
|
||||
pacman -Qq archlinux-keyring &> /dev/null && keyrings+=(archlinux-keyring)
|
||||
pacman -Qq cachyos-keyring &> /dev/null && keyrings+=(cachyos-keyring)
|
||||
if (( ${#keyrings[@]} )); then
|
||||
cau_run_logged pacman -Sy --noconfirm --color never "${keyrings[@]}" || true
|
||||
fi
|
||||
if pacman -Syu "${flags[@]}" > "$log" 2>&1; then
|
||||
cat "$log" >> "$CAU_RUNLOG" 2>/dev/null
|
||||
rm -f "$log"
|
||||
return 0
|
||||
fi
|
||||
cat "$log" >> "$CAU_RUNLOG" 2>/dev/null
|
||||
;;
|
||||
|
||||
conflict)
|
||||
# A package that has to replace another one. --noconfirm already
|
||||
# answers "Replace X with Y?" affirmatively; what it declines is
|
||||
# ":: X and Y are in conflict. Remove Y? [y/N]". --ask is pacman's
|
||||
# question bitmask: 4 = CONFLICT_PKG, 16 = REMOVE_PKGS.
|
||||
if [[ $CFG_RESOLVE_CONFLICTS != yes ]]; then
|
||||
cau_error "Package conflict requires a decision (AutoResolveConflicts is off)"
|
||||
rm -f "$log"
|
||||
return 1
|
||||
fi
|
||||
cau_info "Resolving package conflicts automatically and retrying"
|
||||
if pacman -Syu "${flags[@]}" --ask=20 > "$log" 2>&1; then
|
||||
cat "$log" >> "$CAU_RUNLOG" 2>/dev/null
|
||||
grep -E '^(removing|replacing) ' "$log" 2>/dev/null \
|
||||
| while read -r line; do cau_info " $line"; done
|
||||
rm -f "$log"
|
||||
return 0
|
||||
fi
|
||||
cat "$log" >> "$CAU_RUNLOG" 2>/dev/null
|
||||
;;
|
||||
|
||||
filesystem)
|
||||
# Untracked files in the way. Forcing --overwrite here could
|
||||
# silently clobber something the user put there deliberately, so
|
||||
# this one stays a human decision.
|
||||
cau_error "Files on disk conflict with the update; manual review needed"
|
||||
rm -f "$log"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
rm -f "$log"
|
||||
CAU_PACMAN_COUNT=0
|
||||
return 1
|
||||
}
|
||||
|
||||
# cau_pacman_reboot_needed
|
||||
# The running kernel's module tree no longer carries a vmlinuz, so the kernel
|
||||
# package was replaced underneath us.
|
||||
cau_pacman_reboot_needed() {
|
||||
[[ ! -f "/usr/lib/modules/$(uname -r)/vmlinuz" ]]
|
||||
}
|
||||
|
||||
# cau_pacman_pacnew_count
|
||||
# Purely informational; the files themselves are never touched.
|
||||
cau_pacman_pacnew_count() {
|
||||
cau_have pacdiff || { printf '0\n'; return; }
|
||||
pacdiff -o 2>/dev/null | grep -c . || printf '0\n'
|
||||
}
|
||||
|
||||
# cau_pacman_cleanup
|
||||
# Optional and off by default.
|
||||
cau_pacman_cleanup() {
|
||||
local -a orphans
|
||||
|
||||
if [[ $CFG_REMOVE_ORPHANS == yes ]]; then
|
||||
mapfile -t orphans < <(pacman -Qtdq 2>/dev/null)
|
||||
if (( ${#orphans[@]} )); then
|
||||
cau_info "Removing ${#orphans[@]} orphaned package(s)"
|
||||
cau_run_logged pacman -Rns --noconfirm --color never "${orphans[@]}" \
|
||||
|| cau_warn "Removing orphans failed"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $CFG_CLEAN_CACHE == yes ]] && cau_have paccache; then
|
||||
cau_info "Trimming the package cache"
|
||||
cau_run_logged paccache -r --nocolor -k"$CFG_KEEP_OLD" || cau_warn "paccache -r failed"
|
||||
cau_run_logged paccache -ru --nocolor -k0 || cau_warn "paccache -ru failed"
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
# shellcheck shell=bash
|
||||
#
|
||||
# Finding the humans on this machine and running things on their behalf.
|
||||
#
|
||||
# The updater runs as a root system service, but a fair amount of the work
|
||||
# (per-user Flatpak installations, AppImages, desktop notifications) only makes
|
||||
# sense inside a user's own session.
|
||||
|
||||
# Lowest uid considered a human account. Matches /etc/login.defs on Arch.
|
||||
CAU_UID_MIN=1000
|
||||
CAU_UID_MAX=60000
|
||||
|
||||
# cau_human_users
|
||||
# Prints "user uid home" for every non-system account with a real shell.
|
||||
cau_human_users() {
|
||||
local name uid home shell
|
||||
while IFS=: read -r name _ uid _ _ home shell; do
|
||||
(( uid >= CAU_UID_MIN && uid <= CAU_UID_MAX )) || continue
|
||||
case "$shell" in
|
||||
*/nologin|*/false|'') continue ;;
|
||||
esac
|
||||
printf '%s %s %s\n' "$name" "$uid" "$home"
|
||||
done < <(getent passwd)
|
||||
}
|
||||
|
||||
# cau_active_sessions
|
||||
# Prints "user uid session_id" for every seated, graphical, non-closing
|
||||
# session. These are the sessions a notification can actually reach.
|
||||
cau_active_sessions() {
|
||||
local ids id props name uid class type state
|
||||
|
||||
cau_have loginctl || return 0
|
||||
|
||||
ids="$(loginctl list-sessions --no-legend 2>/dev/null | awk '{print $1}')"
|
||||
[[ -n $ids ]] || return 0
|
||||
|
||||
for id in $ids; do
|
||||
props="$(loginctl show-session "$id" \
|
||||
--property=Name --property=User --property=Class \
|
||||
--property=Type --property=State 2>/dev/null)" || continue
|
||||
|
||||
name=''; uid=''; class=''; type=''; state=''
|
||||
while IFS='=' read -r k v; do
|
||||
case "$k" in
|
||||
Name) name="$v" ;;
|
||||
User) uid="$v" ;;
|
||||
Class) class="$v" ;;
|
||||
Type) type="$v" ;;
|
||||
State) state="$v" ;;
|
||||
esac
|
||||
done <<< "$props"
|
||||
|
||||
[[ $class == user ]] || continue
|
||||
[[ $state == active || $state == online ]] || continue
|
||||
case "$type" in
|
||||
wayland|x11|mir) ;;
|
||||
*) continue ;;
|
||||
esac
|
||||
[[ -n $name && -n $uid ]] || continue
|
||||
|
||||
printf '%s %s %s\n' "$name" "$uid" "$id"
|
||||
done
|
||||
}
|
||||
|
||||
# cau_active_session_users
|
||||
# Deduplicated "user uid" for everyone with a reachable graphical session.
|
||||
cau_active_session_users() {
|
||||
cau_active_sessions | awk '{print $1, $2}' | sort -u
|
||||
}
|
||||
|
||||
# cau_user_locale <user> <uid>
|
||||
# Best effort at the locale that user's desktop is running in, so a
|
||||
# notification does not arrive in English on a German machine.
|
||||
cau_user_locale() {
|
||||
local user="$1" uid="$2" locale=''
|
||||
|
||||
if [[ -d "/run/user/$uid" ]]; then
|
||||
locale="$(cau_as_user "$user" "$uid" systemctl --user show-environment 2>/dev/null \
|
||||
| sed -n 's/^LANG=//p' | head -n1)"
|
||||
fi
|
||||
|
||||
if [[ -z $locale && -r /etc/locale.conf ]]; then
|
||||
locale="$(sed -n 's/^LANG=//p' /etc/locale.conf | tr -d '"' | head -n1)"
|
||||
fi
|
||||
|
||||
printf '%s\n' "${locale:-C}"
|
||||
}
|
||||
|
||||
# cau_as_user <user> <uid> <command> [args...]
|
||||
# Runs a command as that user with a session-shaped environment. LC_ALL is
|
||||
# explicitly cleared: the service sets LC_ALL=C for parseable tool output, but
|
||||
# anything user-facing should follow the user's own locale.
|
||||
cau_as_user() {
|
||||
local user="$1" uid="$2"
|
||||
shift 2
|
||||
local home
|
||||
home="$(getent passwd "$user" | cut -d: -f6)"
|
||||
|
||||
local -a env_args=(
|
||||
"HOME=${home:-/home/$user}"
|
||||
"USER=$user"
|
||||
"LOGNAME=$user"
|
||||
"XDG_RUNTIME_DIR=/run/user/$uid"
|
||||
)
|
||||
[[ -S "/run/user/$uid/bus" ]] && \
|
||||
env_args+=("DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus")
|
||||
|
||||
runuser -u "$user" -- env --unset=LC_ALL "${env_args[@]}" "$@"
|
||||
}
|
||||
Reference in new issue
Block a user