summarylogtreecommitdiffstats
path: root/build-in-docker.sh
blob: 0ccc374742fad96824f1dc9264cace59c1767d9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash

#
# This script is used to test AUR builds locally in a clean Arch Linux Docker container.
# It is not used in the AUR builds in any way, and is only for debugging purposes.
#

set -e

# Determine the current versions and if we should build or not
aurversion=$(grep pkgver .SRCINFO | awk -F= '{print $2}' | sed -e 's/ //g')
githubversion=$(curl https://api.github.com/repos/ferdium/ferdium-app/releases 2>/dev/null| jq -r 'map(select(.prerelease == false)) | first | .name')

# Convert versions to AUR friendly names
newpkgverorg="$(echo -n "${githubversion}" | sed 's/^v//')"
newpkgver="$(echo -n "${newpkgverorg}" | sed 's/\([^-]*-\)g/r\1/;s/-/./g' | sed 's/^v//')"

echo "Current AUR version: [${aurversion}]"
echo "Current GitHub version: [${githubversion}]"
echo "Future AUR version: [${newpkgver}]"

if [ "${aurversion}" = "${newpkgver}" ]
then
	echo -n "Versions are identical, if you wish to build anyway, press Enter, otherwise press Ctrl-C now: "
	read foo
	echo "Okay, here we go! Creating the build script..."
fi

# Start the build
cat << EOF > tempscript.sh
set -e

# System set-up
pacman-key --init
pacman -Sy archlinux-keyring --noconfirm
pacman -Syu --noconfirm
pacman -S pacman-contrib git openssh --noconfirm
echo 'yay ALL=(ALL:ALL) NOPASSWD: ALL' >> /etc/sudoers
useradd -d /home/yay -g users -m -s /bin/bash yay

# Build the package
cd /tmp
sudo -u yay git clone https://aur@aur.archlinux.org/ferdium-bin.git
cd /tmp/ferdium-bin
EOF
cat << 'EOF' >> tempscript.sh
sed -i -e "s/^pkgverorg=.*/pkgverorg='${newpkgverorg}'/g" PKGBUILD
sed -i -e "s/^pkgver=.*/pkgver='${newpkgver}'/g" PKGBUILD
EOF
cat << EOF >> tempscript.sh
sudo -u yay updpkgsums
sudo -u yay makepkg -s --noconfirm
sudo -u yay makepkg --printsrcinfo > .SRCINFO
EOF

echo "Starting docker container with the build script..."

docker run --rm -e newpkgverorg=${newpkgverorg} -e newpkgver=${newpkgver} -v $(pwd)/tempscript.sh:/root/tempscript.sh archlinux:base-devel /bin/bash /root/tempscript.sh

echo "Cleaning up..."
rm -rf tempscript.sh