Initial version

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-06-29 16:24:51 +02:00
commit a3960a3b36
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 133 additions and 0 deletions

71
sync.sh Normal file
View file

@ -0,0 +1,71 @@
#!/bin/bash
set -euo pipefail
function cleanup() {
step "Cleaning up"
rm -rf \
"${workdir}"
}
trap cleanup EXIT
function error() {
echo -e "$(tput setaf 1)$@$(tput sgr0)" >&2
}
function fail() {
error "$@"
exit 1
}
function step() {
echo -e "$(tput setaf 6)[$(date)] $@...$(tput sgr0)" >&2
}
function success() {
echo -e "$(tput setaf 2)$@$(tput sgr0)" >&2
}
function warn() {
echo -e "$(tput setaf 3)$@$(tput sgr0)" >&2
}
# ---
step "Creating a tempdir as working dir"
workdir=$(mktemp -d)
step "Checking input"
PKG=${1:-}
[[ -n ${PKG} ]] || fail "No package given as first argument"
step "Entering workdir"
pushd "${workdir}"
step "Initialize empty repo"
git init
step "Fetching remote state"
git remote add github git@github.com:luzifer-aur/${PKG}.git
git remote add aur ssh://aur@aur.archlinux.org/${PKG}.git
git fetch github
git fetch aur
step "Checking for differences in remotes"
[[ $(git rev-parse github/master) == $(git rev-parse aur/master) ]] && {
success "Remote refs are at the same commit"
exit 0
} || warn "Differences found, action needed"
step "Resetting to Github working state"
git reset --hard github/master
step "Rebasing onto AUR working state"
git rebase aur/master
step "Push to both remotes"
git push aur master
git push github master
step "Leaving working dir"
popd

62
update.sh Normal file
View file

@ -0,0 +1,62 @@
#!/bin/bash
set -euxo pipefail
# Create a tempdir to operate in
tempdir=$(mktemp -d)
# Ensure tempdir is removed on exit
function cleanup() {
rm -rf ${tempdir}
}
trap cleanup EXIT
# Check input
PKG=${1:-}
[[ -n ${PKG} ]] || {
echo "No package given as first argument" >&2
exit 1
}
# Initialize git directory
cd ${tempdir}
git init
# Configure user details
git config user.email "jenkins@luzifer.io"
git config user.name "Luzifer.io Jenkins"
# Add AUR as remote
git remote add origin "git@github.com:luzifer-aur/${PKG}.git"
# Get latest state of remote
git fetch --all --tags
# Reset to latest master
git reset --hard origin/master
git branch -u origin/master
# Check for update script
[ -f update_version.sh ] || {
echo "No update_version.sh found, skipping build."
exit 0
}
# Execute update script
docker run --rm -i -u $(id -u) \
-v "$(pwd):$(pwd)" -w "$(pwd)" \
luzifer/aur-update \
bash ./update_version.sh
# Check for new commits
(git status --porcelain -b | grep -q '^## .*ahead') || {
echo "No update-commits were made."
exit 0
}
# Check whether the build is possible
docker run --rm -i \
-v "$(pwd):/src" \
luzifer/arch-repo-builder:latest
# Push changes including tags to fork
git push origin master