M .gitignore => .gitignore +2 -1
@@ 1,7 1,8 @@
.SRCINFO
*.gz
-# Paur volume's residual files
+# Paur container and its residual files
+PaurContainer/
packages/.aur/
packages/.cache/
packages/.local/
D Dockerfile => Dockerfile +0 -19
@@ 1,19 0,0 @@
-FROM archlinux:base-devel
-
-RUN useradd -m mrpaur \
- && pacman-key --init \
- && pacman -Syu --noconfirm \
- git \
- pacman-contrib \
- python \
- sudo \
- && pacman -Rcnsu --noconfirm $(pacman -Qtdq) || true \
- && pacman -Sc --noconfirm
-
-
-COPY paur /usr/bin/paur
-RUN echo "mrpaur ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
-
-WORKDIR /home/mrpaur/
-USER mrpaur
-ENTRYPOINT ["paur"]
M README.md => README.md +17 -7
@@ 1,26 1,36 @@
# pkgbuilds
-**Where I test my PKGBUILD files**
+**Where I test my AUR PKGBUILD files**
+
+## Dependencies
+
+You need an Arch Linux host system with `systemd-nspawn` and `archstrap`.
+Operations with the container from the host system require `sudo`.
## Usage
-First, build the docker image:
+First, initialise the container:
```bash
-docker build -t paur .
+./paur-container -m init
```
Then, you can test the installation of any package in a clean environment:
```bash
# For example, to test `manim`
-# Not setting --ulimit will make entering `fakeroot` painfully slow!
-docker run --ulimit "nofile=1024:1048576" -v ./packages:/home/mrpaur/ paur:latest manim
+./paur-container -m test -p manim
```
+The environment is ephemeral, meaning that it will be reset after every run.
+Both `paur` and the `packages/` directory are bound to the container, so you
+don't need to update the executable and the `PKGBUILD` and `.SRCINFO` files are
+automatically updated in the host system.
+
> **NOTE:**
>
> Keep in mind that `paur` will greedily **remove *ALL* directories** it finds
> during cleanup. If you're not sure about the side effects this could have in
-> your machine, manually copy the `packages/` directory in the `Dockerfile`
-> instead of using Docker volumes.
+> your machine, make a backup of your `packages/` directory before testing.
+
+To clean up the container, remove its directory as `root`.
A paur-container => paur-container +90 -0
@@ 0,0 1,90 @@
+#!/usr/bin/env sh
+
+
+PAURUSER="mrpaur"
+rootdir="./PaurContainer"
+mode=""
+package=""
+
+
+print_help () {
+cat << EOF
+usage: paur-container -m <mode> [-d <rootdir>] [-p <package>]
+
+Arguments:
+ -d <rootdir> Directory to use as the root of the clean environment.
+ Set to "$rootdir" by default.
+
+ -m <mode> Mode to run the script in. See below.
+
+ -p <package> Package to install.
+
+Modes:
+ init Initialises a container environment in <rootdir>.
+ test Test the installation of <package> in <rootdir>.
+EOF
+}
+
+
+init_script () {
+cat << EOF
+#!/usr/bin/env sh
+
+sed -i \
+ 's/#\?ParallelDownloads.*/ParallelDownloads=50\nILoveCandy/' \
+ /etc/pacman.conf
+
+pacman-key --init
+pacman -Rcnsu --noconfirm \$(pacman -Qtdq) || true
+pacman -Sc --noconfirm
+
+useradd -m $PAURUSER
+echo "$PAURUSER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
+EOF
+}
+
+
+main () {
+ while getopts d:m:p: opt; do
+ case "$opt" in
+ d) rootdir="$OPTARG";;
+ m) mode="$OPTARG";;
+ p) package="$OPTARG";;
+ *) print_help; exit 1;;
+ esac
+ done
+
+ case "$mode" in
+ init) (
+ [ -d "$rootdir" ] && (echo "$rootdir already exists!"; exit 1)
+ sudo mkdir "$rootdir"
+ sudo pacstrap -K -c "$rootdir" \
+ base \
+ base-devel \
+ git \
+ pacman-contrib \
+ python \
+ sudo
+
+ init_sh_file="$rootdir/root/init.sh"
+ init_script | sudo tee "$init_sh_file"
+ sudo chmod +x "$init_sh_file"
+
+ sudo systemd-nspawn -D "$rootdir" --chdir="/root" sh -c " \
+ ./init.sh; \
+ rm init.sh"
+ );;
+ test) (
+ [ -z "$package" ] && (print_help; exit 1)
+
+ sudo systemd-nspawn -D "$rootdir" \
+ --bind="paur:/usr/bin/paur" \
+ --bind="packages:/home/$PAURUSER/packages" \
+ -u "$PAURUSER" --chdir="/home/$PAURUSER" sh -c " \
+ sudo chown -R $PAURUSER:$PAURUSER packages; \
+ cd packages; \
+ paur $package"
+ );;
+ *) print_help; exit 1;;
+ esac
+}; main "$@"