Skip to content

Commit

Permalink
Create aurto: aur local repo tool
Browse files Browse the repository at this point in the history
  • Loading branch information
alexheretic committed Jan 29, 2018
0 parents commit 89fafdb
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# aurto
A simple Arch Linux aur tool for managing a local 'aurto' repository with [aurutils](https://github.com/AladW/aurutils).

- Simple `aurto add`, `aurto remove` management of local ***aurto*** repo package.
- Automatic hourly checks & updates aur packages in the ***aurto*** repo.
- Automatic daily checks & updates `*-git` packages in the ***aurto*** repo.
- Uses systemd-nspawn containers to build packages.

# Install
From a plain Arch install, first install **aurutils** from the aur (skip if already installed).
```sh
curl -L https://aur.archlinux.org/cgit/aur.git/snapshot/aurutils.tar.gz | tar xz
cd aurutils
gpg --recv-keys DBE7D3DD8C81D58D0A13D0E76BC26A17B9B7018A
makepkg -srci
```

Install **aurto** from the aur.
```sh
curl -L https://aur.archlinux.org/cgit/aur.git/snapshot/aurto.tar.gz | tar xz
cd aurto
makepkg -srci
```

# Usage
You add aur packages to your local 'aurto' repo. This is different to installing them.
```sh
aurto add|remove PACKAGES
```
Once added you can install them as normal with pacman.
The packages are automatically updated periodically,
you'll see ***aurto*** updates in the same way as other repos after a `pacman -Syu`.

# Useful commands
View the contents of the ***aurto*** repo, _you may want to `pacman -Sy` first if recently changed_.
```sh
pacman -Sl aurto
```

Check recent auto-update logs.
```sh
journalctl -u update-aurto --since '12 hours ago' -e
```

# Limitations & Security
aurto automatically builds and regularly re-builds updated remote code from the aur.
Code is _built_ in a container, but presumably will eventually be installed to your system.
Only add aur packages from maintainers you trust.

aurto is for simple folk's simple needs. If it can't do what you want uninstall & use [aurutils](https://github.com/AladW/aurutils) directly.
29 changes: 29 additions & 0 deletions bin/aurto
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

set -eu
command=${1:-}
arg1=${2:-}

if [ "$command" == "add" ] && [ -n "$arg1" ]; then
echo "aurto: Running: \`aursync --no-view --rmdeps --no-confirm --chroot --repo=aurto ${*:2}\`" >&2
# TODO use -M /usr/liv/aurto/aurto-makepkg.conf
aursync --no-view --rmdeps --no-confirm --chroot --repo=aurto "${@:2}"
elif [ "$command" == "remove" ] && [ -n "$arg1" ]; then
removed=""
for pkg in "${@:2}"; do
remove_out=$(repo-remove /var/cache/pacman/aurto/aurto.db.tar "$pkg" 2>&1)
if [[ $remove_out = *"ERROR"* ]]; then
echo -e "aurto: \\e[36m$pkg \\e[31mnot found\\e[39m" >&2
else
rm -rf /var/cache/pacman/aurto/"$pkg"*.pkg.* || true
removed="$pkg $removed"
fi
done
if [ -n "$removed" ]; then
echo -e "aurto: Removed \\e[36m$removed\\e[39m" >&2
fi
else
echo -e "Simple management tool for the 'aurto' repository"
echo -e " Usage: \\e[32maurto add\\e[39m|\\e[32mremove \\e[36mPACKAGES\\e[39m"
exit 1
fi
8 changes: 8 additions & 0 deletions conf/aurto.pacman.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[options]
CacheDir = /var/cache/pacman/pkg
CacheDir = /var/cache/pacman/aurto
CleanMethod = KeepCurrent

[aurto]
SigLevel = Optional TrustAll
Server = file:///var/cache/pacman/aurto
65 changes: 65 additions & 0 deletions install/aurto.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

set -eu
user="${SUDO_USER:-$USER}"

function initialised {
grep -q '^Include = /etc/pacman.d/aurto$' /etc/pacman.conf
}

post_install() {
if initialised; then
echo 'Already initialised' >&2
exit 0
fi

echo "aurto: Initialising for user: $user"
echo "$user" > /usr/lib/aurto/user
chmod 700 /usr/lib/aurto/user

echo 'aurto: Adding include /etc/pacman.d/aurto to pacman.conf' >&2
cp /etc/pacman.conf /etc/pacman.conf.aurto-backup
echo -e "# aurto repo\\nInclude = /etc/pacman.d/aurto" >> /etc/pacman.conf

install -d /var/cache/pacman/aurto -o "$user"
sudo -u "$user" repo-add /var/cache/pacman/aurto/aurto.db.tar 2>/dev/null

echo 'aurto: Adding passwordless use of arch-nspawn, mkarchroot, makechrootpkg, aurbuild_chroot' >&2
cp /etc/sudoers /etc/sudoers.aurto-backup
echo "## aurto rules
%$user ALL=(ALL) NOPASSWD: /usr/bin/arch-nspawn
%$user ALL=(ALL) NOPASSWD: /usr/bin/mkarchroot
%$user ALL=(ALL) NOPASSWD:SETENV: /usr/bin/makechrootpkg
%$user ALL=(ALL) NOPASSWD:SETENV: /usr/bin/aurbuild_chroot
## /aurto rules" >> /etc/sudoers

echo 'aurto: Adding systemd timer update tasks' >&2
systemctl enable --now /usr/lib/systemd/system/check-aurto-git-trigger.timer
systemctl enable --now /usr/lib/systemd/system/update-aurto.timer
}

pre_remove() {
if ! initialised; then
exit 0
fi

echo 'aurto: Removing systemd timer update tasks' >&2
systemctl disable --now check-aurto-git-trigger.timer
systemctl disable --now update-aurto.timer
}

post_remove() {
if ! initialised; then
exit 0
fi

echo 'aurto: Removing include from pacman.conf' >&2
sed -i '/^Include = \/etc\/pacman.d\/aurto$/d' /etc/pacman.conf
sed -i '/^# aurto repo$/d' /etc/pacman.conf

echo 'aurto: Removing /var/cache/pacman/aurto' >&2
rm -rf /var/cache/pacman/aurto

echo 'aurto: Removing aurto rules from /etc/sudoers' >&2
sed -i '/^## aurto rules$/,/^## \/aurto rules$/d' /etc/sudoers
}
64 changes: 64 additions & 0 deletions lib/check-aurto-git
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
## Checks aur-git for updates

set -u

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
user=$(cat /usr/lib/aurto/user)
command -v aurfetch >/dev/null 2>&1 || { echo >&2 "aurfetch not installed. Aborting."; exit 1; }

function check_auto_updates {
for dir in *; do
if [[ -d $dir ]] && pacman -Qq "$dir" >/dev/null 2>&1; then
cd "$dir" || exit
echo -n "Checking $dir..." >&2
before_ver=$(grep -m1 pkgver= PKGBUILD | sed -e 's/^[^=]*=//g')
before_rel=$(grep -m1 pkgrel= PKGBUILD | sed -e 's/^[^=]*=//g')
installed_ver=$(pacman -Q "$dir" | sed -e 's/^[^ ]* //g')

arch-nspawn /var/lib/aurbuild/x86_64/"$user" \
--bind="$SCRIPT_DIR"/tmp/"$dir" \
-u builduser \
/usr/bin/env bash -c "
cd $SCRIPT_DIR/tmp/$dir
makepkg -sco --noprepare --noconfirm >/dev/null 2>&1
"
if [ $? -ne 0 ]; then
echo -e " \\e[31mfailed\\e[39m" >&2
cd ..
rm -rf "$dir"
continue
fi

after_ver=$(grep -m1 pkgver= PKGBUILD | sed -e 's/^[^=]*=//g')
after_rel=$(grep -m1 pkgrel= PKGBUILD | sed -e 's/^[^=]*=//g')
cd ..
if [ "$before_ver-$before_rel" = "$after_ver-$after_rel" ] || \
[ "$installed_ver" = "$after_ver-$after_rel" ]; then
echo -e " \\e[32m✓ up to date\\e[39m" >&2
else
echo -e " \\e[34m$installed_ver -> $after_ver-$after_rel available\\e[39m" >&2
echo "$dir"
fi
fi
rm -rf "$dir"
done
}

# rm the temporary build files
function rm_tmp {
rm -rf "$SCRIPT_DIR"/tmp || true
}
trap rm_tmp EXIT

mkdir -p "$SCRIPT_DIR"/tmp
cd "$SCRIPT_DIR"/tmp || exit 1

# All *-git packages
CHECK_FOR_AUTO_UPDATES="$(pacman -Slq aurto | grep '\-git$')"

if [ ! -z "$CHECK_FOR_AUTO_UPDATES" ]; then
echo "$CHECK_FOR_AUTO_UPDATES" | aurfetch >/dev/null 2>&1
chmod -R 0777 "$SCRIPT_DIR"/tmp
check_auto_updates
fi
28 changes: 28 additions & 0 deletions lib/update-aurto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
## Builds new aur packages into repo 'aurto'
## Should be in the same dir as `check-aurto-git`
set -eu

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
user=$(cat /usr/lib/aurto/user)

if [ -z "$user" ]; then
echo 'Missing /usr/lib/aurto/user' >&2
exit 1
fi

pacman -Sy >/dev/null 2>&1

sudo -u "$user" aursync --no-view --rmdeps --no-confirm --chroot \
--repo aurto --update

if [ -e /usr/lib/aurto/check-vcs ]; then
rm -f /usr/lib/aurto/check-vcs || true

GIT_OUTDATED=$("$SCRIPT_DIR"/check-aurto-git)
if [ -n "$GIT_OUTDATED" ]; then
sudo -u "$user" aurto add "$GIT_OUTDATED"
fi
fi

/usr/bin/paccache -rk1 -c /var/cache/pacman/aurto
20 changes: 20 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

PREFIX = /usr
build_dist_args?=

all:
@rm -rf target

@mkdir -p target/etc/pacman.d
@cp conf/aurto.pacman.conf target/etc/pacman.d/

@mkdir -p target$(PREFIX)/bin
@cp -r bin/* target$(PREFIX)/bin/

@mkdir -p target$(PREFIX)/lib/aurto
@cp -r lib/* target$(PREFIX)/lib/aurto/

@mkdir -p target$(PREFIX)/lib/systemd/system
@cp -r timer/* target$(PREFIX)/lib/systemd/system/

@if command -v tree >/dev/null 2>&1; then tree target; fi
6 changes: 6 additions & 0 deletions timer/check-aurto-git-trigger.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Unit]
Description=Lazily sets to check for aurto git updates

[Service]
Type=oneshot
ExecStart=/usr/bin/touch /usr/lib/aurto/check-vcs
9 changes: 9 additions & 0 deletions timer/check-aurto-git-trigger.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Lazily sets to check for aurto git updates every day

[Timer]
OnCalendar=*-*-* 08:29:00
Persistent=true

[Install]
WantedBy=timers.target
6 changes: 6 additions & 0 deletions timer/update-aurto.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Unit]
Description=Updates 'aurto' repo

[Service]
Type=oneshot
ExecStart=/usr/lib/aurto/update-aurto
8 changes: 8 additions & 0 deletions timer/update-aurto.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=Updates 'aurto' repo every hour

[Timer]
OnCalendar=*-*-* *:30:00

[Install]
WantedBy=timers.target

0 comments on commit 89fafdb

Please sign in to comment.