|
1 | | -#!/bin/sh |
| 1 | +#!/bin/sh - |
2 | 2 | # |
3 | | -# Creates a directory in /tmp, clones the AUR repository into it and finally |
4 | | -# builds the package. Definitely not gold, lots of room for improvement. |
| 3 | +# Creates a temporary build directory in /tmp and builds all packages in there |
| 4 | +# based on the provided package list file. Also supports signing the packages |
| 5 | +# and creates an appropriate repository database. The articats are finally |
| 6 | +# stored in one build directory. |
5 | 7 | # |
6 | | -# ./build.sh GIT_URL [COMMIT_HASH] |
| 8 | +# Supported environment variables: |
| 9 | +# |
| 10 | +# PACKAGE_AUTHOR: Defines who is the packager, set to 'John Doe |
| 11 | +# <[email protected]>' if not defined |
| 12 | +# |
| 13 | +# PACKAGE_BASE_URL: Base URL where the source repositories are located, |
| 14 | +# set to 'https://aur.archlinux.org' if not defined |
| 15 | +# |
| 16 | +# PACKAGE_CONFIG: File containing the package list to build, set to |
| 17 | +# 'packages.lst' if not defined |
| 18 | +# |
| 19 | +# PACKAGE_DESTINATION: Defines where to store the built packages, set to |
| 20 | +# '$HOME/build' if not defined |
| 21 | +# |
| 22 | +# PACKAGE_GPG_ID: GPG ID of the private key to use for signing the |
| 23 | +# packages, if not set the packages will not be signed |
| 24 | +# |
| 25 | +# USAGE: ./build.sh |
7 | 26 |
|
8 | 27 | set -eo pipefail |
9 | 28 |
|
10 | | -# Required tools |
11 | | -DEPENDENCIES="mktemp git" |
| 29 | +readonly DEPENDENCIES="id git makepkg pacman-key repo-add" |
| 30 | + |
| 31 | +readonly PKG_BASE_URL="${PACKAGE_BASE_URL:-https://aur.archlinux.org}" |
| 32 | +readonly PKG_CFG="${PACKAGE_CONFIG:-packages.lst}" |
| 33 | + |
| 34 | +# Specific options for makepkg and repo-add, see their respective man pages |
| 35 | +export GPGKEY="${PACKAGE_GPG_ID:-}" |
| 36 | +export PKGDEST="${PACKAGE_DESTINATION:-${HOME}/build}" |
| 37 | +export PACKAGER="${PACKAGE_AUTHOR:-John Doe <john@example.com>}" |
12 | 38 |
|
13 | | -# Test if dependencies are available |
| 39 | +# Required by makepkg to ensure signature files are stored along the packages |
| 40 | +export SRCPKGDEST="${PKGDEST}" |
| 41 | + |
| 42 | +# Check if all dependencies are available |
14 | 43 | for DEPENDENCY in ${DEPENDENCIES}; do |
15 | 44 | if [[ ! $(type "${DEPENDENCY}" 2> /dev/null) ]]; then |
16 | 45 | echo "Dependency '${DEPENDENCY}' not found in PATH, exiting..." |
17 | 46 | exit 1 |
18 | 47 | fi |
19 | 48 | done |
20 | 49 |
|
21 | | -if [[ -z "${1}" ]]; then |
22 | | - echo "No AUR git URL provided as the first parameter, exiting..." |
| 50 | +# Check if we are executed as root which does not work with makepkg |
| 51 | +if [[ "$(id -u)" -eq 0 ]]; then |
| 52 | + echo "Script must not be executed as root, exiting..." |
| 53 | + exit 1 |
| 54 | +fi |
| 55 | + |
| 56 | +echo $HOME |
| 57 | +# Check if package config file exists |
| 58 | +if [[ ! -f "${PKG_CFG}" ]]; then |
| 59 | + echo "No file named '${PKG_CFG}' found at script location, exiting..." |
23 | 60 | exit 1 |
24 | 61 | fi |
25 | 62 |
|
26 | 63 | # Create temporary build directory |
27 | | -BUILD_DIR=$(mktemp --directory --suffix=pkgbuild) |
| 64 | +readonly TMP_BUILD_DIR=$(mktemp --directory --suffix=pkgbuild) |
| 65 | + |
| 66 | +# Create package destination directory if required |
| 67 | +echo "All packages will be placed in '${PKGDEST}'" |
| 68 | +if [[ ! -d "${PKGDEST}" ]]; then |
| 69 | + mkdir "${PKGDEST}" |
| 70 | +fi |
| 71 | + |
| 72 | +# Build all packages |
| 73 | +while read -r PACKAGE; do |
| 74 | + # Skip all lines starting with a hashtag |
| 75 | + [[ "${PACKAGE}" =~ ^#.*$ ]] && continue |
| 76 | + |
| 77 | + echo "Starting build process for package '${PACKAGE}'" |
| 78 | + |
| 79 | + # Clone source repository |
| 80 | + git clone "${PKG_BASE_URL}/${PACKAGE}" "${TMP_BUILD_DIR}/${PACKAGE}" |
| 81 | + |
| 82 | + # Build package |
| 83 | + cd "${TMP_BUILD_DIR}/${PACKAGE}" |
| 84 | + if [[ ! -z "${GPGKEY}" ]]; then |
| 85 | + echo "Package will be built and signed with the GPG key '${GPGKEY}'" |
| 86 | + makepkg --noconfirm --syncdeps --install --sign |
| 87 | + else |
| 88 | + echo "Package will be built without signing it" |
| 89 | + makepkg --noconfirm --syncdeps --install |
| 90 | + fi |
| 91 | +done < "${PKG_CFG}" |
28 | 92 |
|
29 | | -# Clone (AUR) repository |
30 | | -git clone "${1}" "${BUILD_DIR}" |
| 93 | +echo "Finished building all packages, check the '${PKGDEST}' directory" |
31 | 94 |
|
32 | | -# Switch to build directory |
33 | | -cd "${BUILD_DIR}" |
| 95 | +ls -al "${PKGDEST}" |
34 | 96 |
|
35 | | -# Optionally checkout specific commit (i.e. AUR version pinning) |
36 | | -if [[ ! -z "${2}" ]]; then |
37 | | - echo "Checking out commit '${2}'" |
38 | | - git checkout --quiet "${2}" |
| 97 | +if [[ ! -z "${GPGKEY}" ]]; then |
| 98 | + echo "Creating package repository database and sign it with the GPG key '${GPGKEY}'" |
| 99 | + repo-add --sign "${PKGDEST}/karras.db.tar.xz" ${PKGDEST}/*.zst |
| 100 | +else |
| 101 | + echo "Creating package repository database without signing it" |
| 102 | + repo-add "${PKGDEST}/karras.db.tar.xz" ${PKGDEST}/*.zst |
39 | 103 | fi |
40 | 104 |
|
41 | | -# Build package |
42 | | -makepkg --noconfirm --syncdeps |
| 105 | +echo "Finished generating repository database, check the '${PKGDEST}' directory" |
0 commit comments