diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cab6be7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +volume/ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..327b779 --- /dev/null +++ b/.gitignore @@ -0,0 +1,102 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# next.js build output +.next + +# nuxt.js build output +.nuxt + +# gatsby files +.cache/ +public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + + +# custom .gitignore +volume diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5557577 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM archlinux:base-devel + +WORKDIR /usr/files + +ENV REPO="git@github.com:torvalds/linux.git" +ENV CRON="0 * * * *" + +RUN pacman -Sy --noconfirm openssh git jq cronie doas && \ + groupadd user && \ + useradd -m -g user user && \ + ln -sf /usr/files/.cron /etc/cron.d/.cron && \ + ln -sf /usr/volume/common/gitconfig /home/user/.gitconfig && \ + rm -rf /home/user/.ssh && \ + ln -sf /usr/volume/common/ssh /home/user/.ssh && \ + ssh-keyscan -t rsa aur.archlinux.org >> ./known_hosts && \ + ssh-keyscan -t rsa github.com >> ./known_hosts && \ + ssh-keyscan -t rsa gitlab.com >> ./known_hosts && \ + chown user:user . && \ + echo "permit nopass :user as root cmd $(which crond)" > /etc/doas.conf && \ + chmod 0400 /etc/doas.conf + +COPY . . + +USER user + +CMD ./startup.sh diff --git a/README.md b/README.md index 63b0221..f0a6796 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,32 @@ # aur-deploy -Tool for automating the updating of AUR packages or other git repositories +Docker image that automates the updating of AUR packages or other git repositories + +## Configuration + +Use the provided [docker-compose file](docker-compose.yml) as a guide. + +aur-deploy takes environment variables: + +| Environment Variable | Description | +|----------------------|------------------------------------------------------------------------------------------------| +| CRON | Cron expression for how often aur-deploy should run the update routine. Default is `0 * * * *` | +| REPO | The address of the git repository to be modified | + +There are also some configuration files that are provided in `/usr/volume/`: + +```bash +/usr/volume/ +├── common +│   ├── gitconfig # .gitconfig file +│   └── ssh # .ssh directory +│   ├── id_ed25519 +│   └── id_ed25519.pub +└── script + └── script.sh # script that updates your PKGBUILD +``` + +Note that if the ssh directory is empty, a key will be automatically generated. Just add the public key to your AUR account. + +## script.sh + +This script runs within the repository directory. It should check for an update and make the appropriate changes to the PKGBUILD file. No need to update the .SRCINFO and no need to stage PKGBUILD or .SRCINFO. All other files that aren't staged will be removed, so don't worry about cleaning up. \ No newline at end of file diff --git a/commit.sh b/commit.sh new file mode 100755 index 0000000..75d074b --- /dev/null +++ b/commit.sh @@ -0,0 +1,20 @@ +#!/bin/bash +cd /usr/files/repo +echo "==> Checking for updates..." +/usr/volume/script/script.sh +git clean -fdx +if [[ `git status --porcelain` ]]; then + echo "==> Update detected" + sed -i -e 's/pkgrel=.*/pkgrel=1/g' ./PKGBUILD + makepkg --printsrcinfo > .SRCINFO + git diff ./PKGBUILD + git add PKGBUILD .SRCINFO + pkgname="$(grep -oP '(?<=pkgname = ).*' .SRCINFO)" + pkgver="$(grep -oP '(?<=pkgver = ).*' .SRCINFO)" + commit="$pkgname $pkgver-1" + echo "==> pushing $commit" + git commit -m "upgpkg: $commit" -m "pushed by aur-updater" + git push origin HEAD +else + echo "==> No update detected" +fi diff --git a/cron b/cron new file mode 100644 index 0000000..8b262b0 --- /dev/null +++ b/cron @@ -0,0 +1 @@ +%CRON% bash /usr/files/commit.sh > /proc/1/fd/1 2>/proc/1/fd/2 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9ced823 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: '2' + +services: + aur-deploy: + container_name: aur-deploy + build: + context: ./ + dockerfile: ./Dockerfile + volumes: + - ./volume:/usr/volume + environment: + REPO: ssh://aur@aur.archlinux.org/scorespy-launcher.git + CRON: "0 * * * *" + diff --git a/startup.sh b/startup.sh new file mode 100755 index 0000000..8082e6c --- /dev/null +++ b/startup.sh @@ -0,0 +1,27 @@ +#!/bin/bash +cd /usr/files +mkdir -p /usr/volume/common/ssh && chown user:user /usr/volume/common/ssh && chmod 700 /usr/volume/common/ssh +touch /usr/volume/common/gitconfig +if [ -z "$(ls -A ~/.ssh/)" ]; then + echo "==> SSH folder empty. Generating key..." + ssh-keygen -t ed25519 -C "aur-updater" -f "/usr/volume/common/ssh/id_ed25519" -N "" + echo "==> Public key:" + cat ~/.ssh/id_ed25519.pub +fi +$(which cp) -u /usr/files/known_hosts /usr/volume/common/ssh/known_hosts && chmod 600 /usr/volume/common/ssh/known_hosts +if [ ! -d "repo" ]; then + echo "==> Cloning repo..." + git clone "$REPO" repo || exit 500 +else + echo "==> Repo found. Pulling from origin..." + cd repo + git reset --hard HEAD + git pull || exit 1 + cd .. +fi +rm -f /usr/volume/common/ssh/known_hosts.old +echo "==> Ready. Cron job is scheduled." +R=$(echo "$CRON" | sed "s/\\//\\\\\\//g") +sed "s/%CRON%/$R/" /usr/files/cron > /usr/files/.cron +crontab /etc/cron.d/.cron +doas `which crond` -n