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
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown state or error!"
|
|
|
|
return 1
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
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 $?
|
|
|
|
}
|
|
|
|
|
2021-05-13 17:14:49 +02:00
|
|
|
|
2021-06-18 16:35:44 +02:00
|
|
|
# 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
|
|
|
|
# shellcheck disable=SC2154
|
|
|
|
build-and-push "${pkgs[@]}" || exit $?
|
|
|
|
done
|
2021-05-13 15:44:34 +02:00
|
|
|
|
|
|
|
echo "Successfully built all packages!"
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|