summaryrefslogtreecommitdiff
path: root/aur.py
diff options
context:
space:
mode:
Diffstat (limited to 'aur.py')
-rw-r--r--aur.py63
1 files changed, 17 insertions, 46 deletions
diff --git a/aur.py b/aur.py
index 2bea1d1..776f026 100644
--- a/aur.py
+++ b/aur.py
@@ -11,12 +11,7 @@ __version__ = 0.4
SUDOERS_FMT = "etc/sudoers.d/{user}"
-class PipelineStep:
- def cleanup(self):
- pass
-
-
-class PackageClassifier(PipelineStep):
+class PackageClassifier:
def split(self, packages):
aur, std = [], []
for pkg in packages:
@@ -33,7 +28,7 @@ class PackageClassifier(PipelineStep):
return std, aur
-class UserManager(PipelineStep):
+class UserManager:
def __init__(self, user: str, mount_location: Path, installation):
self.user = user
self.mount_location = mount_location
@@ -43,6 +38,12 @@ class UserManager(PipelineStep):
def _run_chroot(self, command):
return self.installation.arch_chroot(command, run_as=self.user)
+ def _sudoers(self):
+ return self.mount_location / f"etc/sudoers.d/{self.user}"
+
+ def _home(self):
+ return self.mount_location / f"home/{self.user}"
+
def create(self):
if self.user_created:
return
@@ -52,8 +53,7 @@ class UserManager(PipelineStep):
)
self.installation.add_additional_packages(["fakeroot", "base-devel"])
- sudoers_path = self.mount_location / SUDOERS_FMT.format(user=self.user)
- sudoers_path.write_text(f"{self.user} ALL=(ALL:ALL) NOPASSWD: ALL\n")
+ self._sudoers().write_text(f"{self.user} ALL=(ALL:ALL) NOPASSWD: ALL\n")
password = archinstall.lib.models.users.Password(plaintext="somethingrandom")
user = archinstall.lib.models.users.User(
@@ -61,8 +61,7 @@ class UserManager(PipelineStep):
)
self.installation.create_users([user])
- home_path = self.mount_location / "home" / self.user
- home_path.mkdir(parents=True, exist_ok=True)
+ self._home().mkdir(parents=True, exist_ok=True)
self.installation.arch_chroot(
f"/usr/bin/chown {self.user}:{self.user} /home/{self.user}"
)
@@ -81,14 +80,12 @@ class UserManager(PipelineStep):
pass
self.installation.arch_chroot(f"/usr/bin/userdel {self.user}")
- shutil.rmtree(self.mount_location / f"home/{self.user}", ignore_errors=True)
- (self.mount_location / SUDOERS_FMT.format(user=self.user)).unlink(
- missing_ok=True
- )
+ shutil.rmtree(self._home(), ignore_errors=True)
+ self._sudoers.unlink(missing_ok=True)
self.user_created = False
-class PackageDownloader(PipelineStep):
+class PackageDownloader:
def __init__(self, user: str, mount_location: Path, installation):
self.user = user
self.mount_location = mount_location
@@ -124,13 +121,8 @@ class PackageDownloader(PipelineStep):
await asyncio.gather(*(sem_task(pkg) for pkg in packages))
- def cleanup(self):
- for pkg in self.downloaded:
- tar_path = self.mount_location / "home" / self.user / f"{pkg}.tar.gz"
- tar_path.unlink(missing_ok=True)
-
-class PackageInstaller(PipelineStep):
+class PackageInstaller:
def __init__(self, user: str, mount_location: Path, installation):
self.user = user
self.mount_location = mount_location
@@ -173,28 +165,12 @@ class PackageInstaller(PipelineStep):
)
return
-# packages = list(build_dir.glob("*.tar.zst"))
-# if not packages:
-# archinstall.log(
-# f"No built packages found for {package}", level=logging.ERROR, fg="red"
-# )
-# return
-#
-# self._run(
-# f"/usr/bin/pacman --noconfirm -U /home/{self.user}/{package}/{packages[0].name}"
-# )
-# self.installed.append(package)
self.installed_dirs.append(build_dir)
- def cleanup(self):
- for build_dir in self.installed_dirs:
- shutil.rmtree(build_dir, ignore_errors=True)
- self.installed_dirs.clear()
-
class Plugin:
def __init__(self):
- self.user = os.getenv("AUR_USER", "aoffline_usr")
+ self.user = os.getenv("AUR_USER", "packagebuilder")
self.lazy_initd = False
def _lazy_init(self):
@@ -210,11 +186,6 @@ class Plugin:
)
self.lazy_initd = True
- """
- TODO:
- Use the nobody account to run makepkg.
- Clone the AUR repo, chown it to nobody, then use sudo -u nobody makepkg to build it.
- """
def on_pacstrap(self, packages: list[str]) -> list[str]:
if not self.lazy_initd:
self._lazy_init()
@@ -224,12 +195,12 @@ class Plugin:
return std
self.usermgr.create()
+
asyncio.run(self.downloader.download(aur))
for pkg in self.downloader.downloaded:
self.installer.install(pkg)
- for step in reversed([self.installer, self.downloader, self.usermgr]):
- step.cleanup()
+ self.usermgr.cleanup()
return std