Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
| linux:server:automated_aur_repo [2022/09/07 20:25] – removed - external edit (Unknown date) 127.0.0.1 | linux:server:automated_aur_repo [2022/09/07 20:25] (current) – ↷ Page moved from linux:home:automated_aur_repo to linux:server:automated_aur_repo michaelbromilow | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Automated AUR pacman repo ====== | ||
| + | The goal of this page is to detail how to set up an AUR package repo using [[https:// | ||
| + | __**This guide is written for a btrfs file system. It's applicable to other filesystems, | ||
| + | |||
| + | ===== Prerequisites ===== | ||
| + | ==== Install LXD ==== | ||
| + | Simply install using the snap: | ||
| + | $ snap install lxd | ||
| + | |||
| + | Run the initialisation process: | ||
| + | $ lxd init | ||
| + | |||
| + | It will probably be helpful to add your user to the '' | ||
| + | $ usermod -a -G lxd $USER | ||
| + | |||
| + | Log into your session again, or run '' | ||
| + | |||
| + | ===== Set up an Arch container on the server ===== | ||
| + | I opted to use LXD to run the Arch container. I assumed that since my server runs Ubuntu server 20.04 LTS, the differing kernel versions would be an issue, but everything seems to work fine. | ||
| + | |||
| + | ==== Filesystem ==== | ||
| + | Since my server runs entirely on btrfs, I created two subvolumes; one for all of my containers to live in, and one to be mounted inside the container for my local pacman repository: | ||
| + | # mount -o subvolid=0 /dev/sdb1 /mnt | ||
| + | # cd /mnt | ||
| + | # btrfs subvol create @lxd | ||
| + | # btrfs subvol create @aur-repo | ||
| + | # mkdir /vol/lxd | ||
| + | # mkdir / | ||
| + | # cd / | ||
| + | # umount /mnt | ||
| + | |||
| + | I added these to my ''/ | ||
| + | < | ||
| + | UUID=... /vol/lxd btrfs compress=zstd, | ||
| + | UUID=... / | ||
| + | </ | ||
| + | # mount -a | ||
| + | |||
| + | I made a new group '' | ||
| + | # groupadd aur-user | ||
| + | # chown -R www-data: | ||
| + | # chmod -R 575 / | ||
| + | |||
| + | ==== Create the container ==== | ||
| + | After installing LXD, the btrfs subvolume for containers can be added as a new storage pool: | ||
| + | $ lxc storage create default btrfs source=/ | ||
| + | | ||
| + | Create a new LXD profile for the arch container, and open it for editing: | ||
| + | $ lxc profile create aur-repo-archlinux | ||
| + | $ lxc profile edit aur-repo-archlinux | ||
| + | |||
| + | Add the following content: | ||
| + | < | ||
| + | config: | ||
| + | security.nesting: | ||
| + | boot.autostart: | ||
| + | description: | ||
| + | devices: | ||
| + | aur-repo: | ||
| + | path: /aur-repo | ||
| + | source: / | ||
| + | type: disk | ||
| + | eth0: | ||
| + | name: eth0 | ||
| + | nictype: bridged | ||
| + | parent: lxdbr0 | ||
| + | type: nic | ||
| + | root: | ||
| + | path: / | ||
| + | pool: default | ||
| + | type: disk | ||
| + | name: archlinux | ||
| + | used_by: [] | ||
| + | </ | ||
| + | < | ||
| + | '' | ||
| + | |||
| + | The '' | ||
| + | </ | ||
| + | |||
| + | Create and launch the Arch Linux container with the new profile by downloading from the '' | ||
| + | $ lxc launch images: | ||
| + | |||
| + | You can now get a root shell as follows: | ||
| + | $ lxc exec archlinux-aur -- /bin/bash | ||
| + | |||
| + | If you set up a user, get a user shell with: | ||
| + | $ lxc exec archlinux-aur -- su --login username | ||
| + | |||
| + | ==== Setting up Arch ==== | ||
| + | (inside the container) | ||
| + | The system locale will need to be set up; edit ''/ | ||
| + | You will also need a non-root user to run '' | ||
| + | # useradd -m username | ||
| + | # passwd username | ||
| + | # usermod -a -G wheel username | ||
| + | |||
| + | Install the following packages: | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | # pacman -S --needed sudo base-devel git devtools btrfs-progs | ||
| + | | ||
| + | Create a system user '' | ||
| + | # useradd -r -m -s / | ||
| + | |||
| + | You should add your user to the new '' | ||
| + | # usermod -a -G aur-user username | ||
| + | |||
| + | <popover trigger=" | ||
| + | |||
| + | ==== Setting up the shared mount ==== | ||
| + | Since LXD runs containers unprivileged by default, they are namespaced by the Linux kernel so that their UID/GIDs are outside of the range of the host's UID/GIDs - therefore, even '' | ||
| + | |||
| + | To find the UID of a user, use: | ||
| + | $ id -u [username] | ||
| + | |||
| + | e.g. | ||
| + | $ id -u michael | ||
| + | < | ||
| + | 1000 | ||
| + | </ | ||
| + | |||
| + | Likewise, to find the GID of a group, use: | ||
| + | $ getent group groupname | ||
| + | |||
| + | e.g. | ||
| + | $ getent group sudo | ||
| + | < | ||
| + | sudo: | ||
| + | </ | ||
| + | |||
| + | Using these commands it can be found that **on the host** the UID of '' | ||
| + | |||
| + | Now add the necessary UID/GIDs to remap to ''/ | ||
| + | $ echo " | ||
| + | $ echo " | ||
| + | |||
| + | Now, **in the Arch container**, | ||
| + | $ id -u aur-user | ||
| + | < | ||
| + | 975 | ||
| + | </ | ||
| + | $ getent group aur-user | ||
| + | < | ||
| + | aur-user: | ||
| + | </ | ||
| + | |||
| + | Back on the host, let's add the relevant configuration line to our LXD profile: | ||
| + | $ lxc profile edit aur-repo-archlinux | ||
| + | < | ||
| + | config: | ||
| + | raw.idmap: |- | ||
| + | uid 33 975 | ||
| + | gid 1010 975 | ||
| + | </ | ||
| + | |||
| + | This remaps (inside the container) both the UID of the host's '' | ||
| + | |||
| + | < | ||
| + | If you were remapping two equal UID/GIDs on the host to two equal UID/GIDs on the container, you could use the following shorthand syntax: | ||
| + | < | ||
| + | config: | ||
| + | raw.idmap: both 1000 1000 | ||
| + | </ | ||
| + | This would remap the host's 1000 UID and GID to the container' | ||
| + | </ | ||
| + | |||
| + | Now, restart the '' | ||
| + | # systemctl restart snap.lxc.daemon | ||
| + | |||
| + | Next time the container is started, the new mapping should now be applied. You can confirm this by looking at the owner of ''/ | ||
| + | $ ls -laph / | grep aur-repo | ||
| + | < | ||
| + | dr-xrwxr-x | ||
| + | </ | ||
| + | |||
| + | ===== Setting up aurutils ===== | ||
| + | Assume instructions in this section are run in the Arch container unless otherwise specified. | ||
| + | |||
| + | ==== Installing aurutils ==== | ||
| + | The easiest way to do this is to install the AUR package like any other; something like: | ||
| + | $ mkdir ~/aur | ||
| + | $ cd ~/aur | ||
| + | $ git clone https:// | ||
| + | $ cd aurutils | ||
| + | $ makepkg -si | ||
| + | | ||
| + | You will probably need to import the PGP key before running '' | ||
| + | $ gpg --recv-keys [Key ID] | ||
| + | < | ||
| + | If gpg fails with '' | ||
| + | </ | ||
| + | |||
| + | ==== Creating a custom local repository ==== | ||
| + | Add a custom repository to ''/ | ||
| + | < | ||
| + | [mbromilow] | ||
| + | SigLevel = Optional TrustAll | ||
| + | Server = file:/// | ||
| + | </ | ||
| + | |||
| + | Create the repository root and database: | ||
| + | # install -d /aur-repo -o aur-user | ||
| + | # sudo -u aur-user repo-add / | ||
| + | |||
| + | Synchronise pacman: | ||
| + | # pacman -Syu | ||
| + | |||
| + | It's probably a good idea to add your database to your webserver now. Here's my nginx configuration to do this: | ||
| + | / | ||
| + | < | ||
| + | # Custom Arch User Repository | ||
| + | server { | ||
| + | server_name aur.bromilow.uk; | ||
| + | root / | ||
| + | |||
| + | location / { | ||
| + | # Enable folder indexing | ||
| + | autoindex on; | ||
| + | # We just try to get the URL as a file. | ||
| + | try_files $uri $uri/ =404; | ||
| + | } | ||
| + | |||
| + | listen 443 ssl; | ||
| + | listen [::]:443 ssl; | ||
| + | ssl_certificate / | ||
| + | ssl_certificate_key / | ||
| + | include / | ||
| + | ssl_dhparam / | ||
| + | } | ||
| + | |||
| + | server { | ||
| + | server_name aur.bromilow.uk; | ||
| + | listen 80; | ||
| + | listen [::]:80; | ||
| + | |||
| + | return 301 https:// | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== Adding the repository to new systems ==== | ||
| + | Following the above setup, this is quite simple. In my case, I simply add to ''/ | ||
| + | [mbromilow] | ||
| + | SigLevel = Optional TrustAll | ||
| + | Server = https:// | ||
| + | |||
| + | ==== Modifying pacstrap to work in the unprivileged container ==== | ||
| + | This one-liner replaces '' | ||
| + | # sed -i ' | ||
| + | |||
| + | < | ||
| + | This is a **required** step if you want to build your AUR packages in a clean chroot (e.g. using '' | ||
| + | </ | ||
| + | |||
| + | ===== Management ===== | ||
| + | In the Arch container... | ||
| + | |||
| + | ==== Adding Packages ==== | ||
| + | $ aur sync -c package_name | ||
| + | |||
| + | Import any missing GPG keys as usual. | ||
| + | |||
| + | ==== Updating Packages ==== | ||
| + | $ aur sync -cu | ||
| + | |||
| + | ===== Troubleshooting ===== | ||
| + | === Error: Common start logic: Failed to change ACLs on / | ||
| + | Delete the folder ''/ | ||