2021-05-13 15:44:34 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
function is-installed() {
|
|
|
|
type "${1}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function start-docker() {
|
|
|
|
is-installed "systemctl" || return $?
|
|
|
|
is-installed "docker" || return $?
|
|
|
|
|
|
|
|
res="$(systemctl show --property ActiveState docker)" || return $?
|
|
|
|
case "${res}" in
|
|
|
|
"ActiveState=active")
|
|
|
|
# Docker service is active
|
2021-05-13 17:14:49 +02:00
|
|
|
true
|
|
|
|
;;
|
2021-05-13 15:44:34 +02:00
|
|
|
"ActiveState=inactive")
|
|
|
|
# Docker service is inactive -> Let's start it
|
|
|
|
echo "Starting docker service ..."
|
|
|
|
sudo systemctl start docker || return $?
|
2021-06-18 16:35:44 +02:00
|
|
|
sleep 5s || return $?
|
2021-05-13 15:44:34 +02:00
|
|
|
;;
|
|
|
|
*)
|
2021-07-27 18:19:09 +02:00
|
|
|
echo "Unknown state or error! This can happen after kernel upgrade."
|
2021-05-13 15:44:34 +02:00
|
|
|
return 1
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2021-09-08 22:32:03 +02:00
|
|
|
function update-build-image() {
|
2021-09-19 18:59:43 +02:00
|
|
|
# "--no-cache" to always run the "pacman -Syu" build step
|
|
|
|
sudo docker-compose build --pull --no-cache
|
2021-09-08 22:32:03 +02:00
|
|
|
}
|
|
|
|
|
2021-05-13 15:44:34 +02:00
|
|
|
function build-pkg() {
|
2021-06-18 16:35:44 +02:00
|
|
|
# $1: package-name
|
|
|
|
# $2, $3, ...: makepkg-args
|
|
|
|
|
2021-05-13 19:13:19 +02:00
|
|
|
# --rm: Remove container after run.
|
2021-06-18 16:35:44 +02:00
|
|
|
COMPOSE_ARGS=('run' '--rm' 'makepkg' "${1}") || return $?
|
|
|
|
|
|
|
|
if [ ${#MAKEPKG_ARGS[@]} -gt 0 ]; then
|
|
|
|
COMPOSE_ARGS+=("${MAKEPKG_ARGS[@]}") || return $?
|
2021-06-14 20:16:40 +02:00
|
|
|
fi
|
|
|
|
|
2021-06-18 16:35:44 +02:00
|
|
|
sudo docker-compose "${COMPOSE_ARGS[@]}" || return $?
|
2021-05-13 15:44:34 +02:00
|
|
|
}
|
|
|
|
|
2021-05-13 17:14:49 +02:00
|
|
|
function push-pkg() {
|
|
|
|
arch-repo-push-new || return $? # Push remote repository
|
|
|
|
}
|
|
|
|
|
|
|
|
function build-and-push() {
|
|
|
|
for PKG in "$@"; do
|
|
|
|
build-pkg "${PKG}" || return $?
|
|
|
|
done
|
|
|
|
push-pkg || return $?
|
|
|
|
}
|
|
|
|
|
2021-06-16 20:21:21 +02:00
|
|
|
function space_separated_to_array() {
|
|
|
|
# arg $1: name of variable with space separated list
|
|
|
|
# arg $2: name of array to store values into
|
|
|
|
|
|
|
|
local -n ptr=$1 || return $?
|
|
|
|
local -n ptr2=$2 || return $?
|
|
|
|
# ptr space separated list.
|
|
|
|
# Store this as array ptr2.
|
|
|
|
# Without newline at last array element: https://unix.stackexchange.com/a/519917/315162
|
|
|
|
# shellcheck disable=SC2034
|
|
|
|
readarray -d " " -t ptr2 < <(printf '%s' "$ptr")
|
|
|
|
}
|
|
|
|
|
2021-05-13 15:44:34 +02:00
|
|
|
function main() {
|
|
|
|
|
2021-06-18 16:35:44 +02:00
|
|
|
# parse arguments
|
|
|
|
{
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
echo "Usage: ${0} <PKGLIST-FILE> [<makepkgArguments>]
|
|
|
|
With PKGLIST-FILE a file containing zero or more package names in each line, separated by space.
|
|
|
|
All packages in a line will be built sequentially and are then synced to the remote repository
|
|
|
|
before continuing with the next line.";
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
PKGLIST="${1}"
|
|
|
|
shift; # remove first arg
|
|
|
|
MAKEPKG_ARGS=("$@")
|
|
|
|
}
|
|
|
|
|
|
|
|
# check dependencies and start services
|
|
|
|
{
|
|
|
|
start-docker || return $?
|
|
|
|
is-installed "docker-compose" || return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
# Read content of PKGLIST file to an array
|
|
|
|
# For each line: build and push all space separated packages
|
2021-06-16 20:21:21 +02:00
|
|
|
mapfile -t STAGES < "${PKGLIST}"
|
|
|
|
# shellcheck disable=SC2034
|
|
|
|
for line in "${STAGES[@]}"; do
|
2021-06-27 14:06:38 +02:00
|
|
|
# trim leading/tailing whitespaces
|
|
|
|
line="$(echo "${line}" | xargs)" || return $?
|
2021-06-16 20:21:21 +02:00
|
|
|
space_separated_to_array line pkgs
|
2021-11-08 19:46:55 +01:00
|
|
|
|
|
|
|
# skip empty lines
|
|
|
|
# shellcheck disable=SC2154
|
|
|
|
if [ "${#pkgs[@]}" -eq 0 ]; then
|
|
|
|
echo "Skipped empty line."
|
|
|
|
continue;
|
|
|
|
fi
|
|
|
|
|
2021-09-19 18:59:43 +02:00
|
|
|
# Rebuild the docker image with refreshed mirrors => this fetches packages that were built in a previous build stage
|
|
|
|
update-build-image || return $?
|
2021-06-16 20:21:21 +02:00
|
|
|
build-and-push "${pkgs[@]}" || exit $?
|
|
|
|
done
|
2021-05-13 15:44:34 +02:00
|
|
|
|
|
|
|
echo "Successfully built all packages!"
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|