summarylogtreecommitdiffstats
path: root/yay-support.patch
blob: 59fb4256f6e9c49f482a7b66a22e43fd3eb30a8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
From e348a5424317b62dfa95bd88c85cb2da0f95571c Mon Sep 17 00:00:00 2001
From: Kenny Strawn <Kenny.Strawn@gmail.com>
Date: Fri, 25 Mar 2022 16:14:13 -0700
Subject: [PATCH] Patch calamares instead of forking

---
 src/modules/packages/main.py       | 129 +++++++++++++++++++++++++++++
 src/modules/packages/packages.conf |   1 +
 2 files changed, 130 insertions(+)

diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py
index e373a3443..05c8d22d3 100644
--- a/src/modules/packages/main.py
+++ b/src/modules/packages/main.py
@@ -475,6 +475,135 @@ class PMPacman(PackageManager):
 
         self.run_pacman(command)
 
+class PMYay(PackageManager):
+    backend = "yay"
+
+    def __init__(self):
+        import re
+        import shutil
+
+        progress_match = re.compile("^\\((\\d+)/(\\d+)\\)")
+
+        # Note that this writes to /etc/sudoers.d, NOT /etc/sudoers!
+        sudoers_entry = open("/etc/sudoers.d/autoupdate", "w")
+        sudoers_entry.write("nobody ALL = NOPASSWD: " + shutil.which("pacman"))
+        sudoers_entry.close()
+
+        def line_cb(line):
+            if line.startswith(":: "):
+                self.in_package_changes = "package" in line or "hooks" in line
+            else:
+                if self.in_package_changes and line.endswith("...\n"):
+                    # Update the message, untranslated; do not change the
+                    # progress percentage, since there may be more "installing..."
+                    # lines in the output for the group, than packages listed
+                    # explicitly. We don't know how to calculate proper progress.
+                    global custom_status_message
+                    custom_status_message = "yay: " + line.strip()
+                    libcalamares.job.setprogress(self.progress_fraction)
+            libcalamares.utils.debug(line)
+
+        self.in_package_changes = False
+        self.line_cb = line_cb
+
+        yay = libcalamares.job.configuration.get("yay", None)
+        if yay is None:
+            yay = dict()
+        if type(yay) is not dict:
+            libcalamares.utils.warning("Job configuration *yay* will be ignored.")
+            yay = dict()
+        self.yay_num_retries = yay.get("num_retries", 0)
+        self.yay_disable_timeout = yay.get("disable_download_timeout", False)
+        self.yay_needed_only = yay.get("needed_only", False)
+
+    def reset_progress(self):
+        self.in_package_changes = False
+        # These are globals
+        self.progress_fraction = (completed_packages * 1.0 / total_packages)
+
+    def run_yay(self, command, callback=False):
+        """
+        Call yay in a loop until it is successful or the number of retries is exceeded
+        :param command: The yay command to run
+        :param callback: An optional boolean that indicates if this yay run should use the callback
+        :return:
+        """
+
+        yay_count = 0
+        while yay_count <= self.yay_num_retries:
+            yay_count += 1
+            try:
+                if False: # callback:
+                    libcalamares.utils.target_env_process_output(command, self.line_cb)
+                else:
+                    libcalamares.utils.target_env_process_output(command)
+
+                return
+            except subprocess.CalledProcessError:
+                if yay_count <= self.yay_num_retries:
+                    pass
+                else:
+                    raise
+
+    def install(self, pkgs, from_local=False):
+        import os
+
+        os.environ["PWD"] = "/var/cache"
+        os.environ["XDG_CACHE_HOME"] = "/var/cache"
+
+        command = ["sudo", "-E", "-u", "nobody", "yay"]
+
+        if from_local:
+            command.append("-U")
+        else:
+            command.append("-S")
+
+        # Don't ask for user intervention, take the default action
+        command.append("--noconfirm")
+
+        # Don't report download progress for each file
+        command.append("--noprogressbar")
+
+        if self.yay_needed_only is True:
+            command.append("--needed")
+
+        if self.yay_disable_timeout is True:
+            command.append("--disable-download-timeout")
+
+        command += pkgs
+
+        self.reset_progress()
+        self.run_yay(command, True)
+
+    def remove(self, pkgs):
+        import os
+
+        os.environ["PWD"] = "/var/cache"
+        os.environ["XDG_CACHE_HOME"] = "/var/cache"
+
+        self.reset_progress()
+        self.run_yay(["sudo", "-E", "-u", "nobody", "yay", "-Rs", "--noconfirm"] + pkgs, True)
+
+    def update_db(self):
+        import os
+
+        os.environ["PWD"] = "/var/cache"
+        os.environ["XDG_CACHE_HOME"] = "/var/cache"
+
+        self.run_yay(["sudo", "-E", "-u", "nobody", "yay", "-Sy"])
+
+    def update_system(self):
+        import os
+
+        os.environ["PWD"] = "/var/cache"
+        os.environ["XDG_CACHE_HOME"] = "/var/cache"
+
+        command = ["sudo", "-E", "-u", "nobody", "yay", "-Su", "--noconfirm"]
+        if self.yay_disable_timeout is True:
+            command.append("--disable-download-timeout")
+
+        self.run_yay(command)
+
 
 class PMPamac(PackageManager):
     backend = "pamac"
diff --git a/src/modules/packages/packages.conf b/src/modules/packages/packages.conf
index 6e62f4b5f..74ab8d3cb 100644
--- a/src/modules/packages/packages.conf
+++ b/src/modules/packages/packages.conf
@@ -29,6 +29,7 @@
 #  - pacman      - Pacman
 #  - pamac       - Manjaro package manager
 #  - portage     - Gentoo package manager
+#  - yay         - AUR package manager
 #  - yum         - Yum RPM frontend
 #  - zypp        - Zypp RPM frontend
 #
-- 
2.35.1