arch/build-pkg/build-all.sh

87 lines
2.0 KiB
Bash
Raw Normal View History

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-05-13 17:14:49 +02:00
sleep 5s
2021-05-13 15:44:34 +02:00
;;
*)
echo "Unknown state or error!"
return 1
esac
}
function build-pkg() {
2021-05-13 19:13:19 +02:00
# --rm: Remove container after run.
2021-06-14 20:16:40 +02:00
COMPOSE_ARGS=('run' '--rm' 'makepkg')
if [ "${INTERACTIVE}" = "true" ]; then
COMPOSE_ARGS+=('interactive')
fi
COMPOSE_ARGS+=("${1}")
sudo docker-compose "${COMPOSE_ARGS[@]}"
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() {
start-docker || return $?
is-installed "docker-compose" || return $?
2021-06-14 20:16:40 +02:00
if [ "${1}" = "interactive" ]; then
echo "Interactive mode enabled"
INTERACTIVE=true
shift; # remove first argument
fi
2021-05-13 17:14:49 +02:00
PKGLIST=pkglist-de-p1st.txt # TODO
2021-06-16 20:21:21 +02:00
mapfile -t STAGES < "${PKGLIST}"
# shellcheck disable=SC2034
for line in "${STAGES[@]}"; do
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 "$@"