Updated to new aurutils, added flags, using uid (ae. nfs)

This commit is contained in:
Matthias Fulz 2024-10-13 03:42:43 +02:00
parent 76457c6428
commit b4010624c4
5 changed files with 363 additions and 199 deletions

View File

@ -80,7 +80,7 @@ Create a repository, that is owned by this user for using [aurutils](https://git
To use now archbuilder as building backend inside aurutils, just add the following to your shell:
export MAKEPKG="/usr/bin/archbuilderwrap"
export AUR_MAKEPKG="/usr/bin/archbuilderwrap"
This script will wrap everything correct to archbuilder and run the makepkg inside the buildah container.

157
archbuilder Normal file
View File

@ -0,0 +1,157 @@
#!/bin/bash
readonly archbuilder_version='v0.9.6'
readonly lib_dir='/usr/lib/archbuilder'
readonly conf_dir='/etc/archbuilder'
. "${lib_dir}/ext/slog.sh"
. "${lib_dir}/ext/bash_log_internals.inc.sh"
. "${conf_dir}/archbuilder.env"
. "${lib_dir}/archbuilder.inc.sh"
. "${lib_dir}/buildah.inc.sh"
test_file "${HOME}/.archbuilder/archbuilder.env" &&
. "${HOME}/.archbuilder/archbuilder.env"
test_null "ARCHBUILDER_UID" "${ARCHBUILDER_UID}" &&
ARCHBUILDER_UID="$(id -u)"
# internal params
unset _FLAG_KEEP
unset _FLAG_SILENT
_OPT_MODE="build"
_OPT_KEYS=()
_OPT_CON_BUILD_USER="archbuilder"
_OPT_CON_LOG_LEVEL=""
_OPT_CON_COPTIONS=""
# actions to initialize runtime
unset _ACT_CREATE_IMAGE
unset _ACT_CREATE_BASE_DIR
unset _ACT_CREATE_CACHE_REPO_PATH
unset _ACT_CREATE_LOG_PATH
function usage() {
echo "archbuilder is a makepkg wrapper that uses buildah for the build process."
echo "That will lead to a very clean build, where the PKGBUILD and the dependencies,"
echo "have to be 100% correct and nothing will pollute the host system."
echo
echo "Usage:"
echo " archbuilder [options] -- <coptions>"
echo
echo "Options:"
echo -e " -h, --help\t\t\t\t\tPrint this help"
echo -e " -i, --interactive\t\t\t\t\tRun the build container in interactive mode"
echo -e " -k, --keep\t\t\t\t\tKeep the working container that is used for the build"
echo -e " -n, --name <string>\t\t\t\tImage name that is used to spin up the container (default: ${INAME})"
echo -e " -m, --mode <create | update | build>\t\tRun mode: (default: ${MODE})"
echo -e " \t\tcreate will setup the base image"
echo -e " \t\tupdate will update the base image"
echo -e " \t\tbuild will build the PKGBUILD"
echo -e " -e, --key <string>\t\t\t\tPublic signing keys that should be trusted by for the build. (Can be added multiple times)"
echo -e " -r, --repo <string>\t\t\t\tHost path to use as repository inside the container. This can be used to avoid"
echo -e " \t\t\t\thanding over dependencies via command line arguments as they will be added to this repo"
echo -e " -s, --silent <string>\t\t\t\tMake container silent: No output from container commands will be send to shell."
echo -e " -l, --level <string>\t\t\t\tLog level to use: Possible values are DEBUG, INFO, WARN, SUCCESS or ERROR"
echo -e " --version <string>\t\t\t\tPrint version information."
echo
echo "coptions:"
echo -e " These options will be handed over directly to makepkg inside the buildah container to build the package."
echo -e " coptions has to be added ater the double dash -- to work."
}
options=$(getopt \
-o hikn:m:p:r:e:sl: \
-l "help" \
-l interactive \
-l keep \
-l name: \
-l mode: \
-l repo: \
-l silent: \
-l level: \
-l version \
-l key: -- "$@" 2>/dev/null)
eval set -- "${options}"
while true; do
case "${1}" in
-i | --interactive)
ARCHBUILDER_INTERACTIVE=1
;;
-k | --keep)
_FLAG_KEEP=1
;;
-n | --name)
shift
ARCHBUILDER_IMAGE_NAME=${1}
;;
-m | --mode)
shift
_OPT_MODE="${1}"
;;
-e | --key)
shift
_OPT_KEYS[${#_OPT_KEYS[*]}]="${1}"
;;
-r | --repo)
shift
ARCHBUILDER_CACHE_REPO="${1}"
;;
-s | --silent)
_FLAG_SILENT=1
;;
-l | --level)
shift
check_log_level "${1}" ||
exit_error "${err}"
LOG_LEVEL_STDOUT="${1}"
LOG_LEVEL_LOG="${1}"
;;
--version)
echo -e "archbuilder v${archbuilder_version}"
exit 0
;;
--)
shift
break
;;
-h | --help | *)
usage
exit 0
;;
esac
shift
done
_OPT_CON_COPTIONS=$@
set_env
init_env
buildah_prepare_params
function exit_trap() {
buildah_exit
}
trap exit_trap EXIT
buildah_create
case "${_OPT_MODE}" in
"create")
buildah_create
;;
"update")
buildah_update
;;
"build")
buildah_build
;;
esac
exit 0

View File

@ -6,6 +6,7 @@ ARCHBUILDER_CACHE_REPO="${ARCHBUILDER_BASE_DIR}/crepo"
ARCHBUILDER_LOG_PATH="${ARCHBUILDER_BASE_DIR}/logs"
ARCHBUILDER_LOG_TO_FILE=1
ARCHBUILDER_INTERACTIVE=0
LOG_LEVEL_STDOUT="INFO"
LOG_LEVEL_LOG="INFO"

View File

@ -12,8 +12,11 @@ readonly conf_dir='ARCHBUILDER_CONF_DIR'
. "${lib_dir}/archbuilder.inc.sh"
. "${lib_dir}/buildah.inc.sh"
test_file "${HOME}/.archbuilder/archbuilder.env" \
&& . "${HOME}/.archbuilder/archbuilder.env"
test_file "${HOME}/.archbuilder/archbuilder.env" &&
. "${HOME}/.archbuilder/archbuilder.env"
test_null "ARCHBUILDER_UID" "${ARCHBUILDER_UID}" &&
ARCHBUILDER_UID="$(id -u)"
# internal params
unset _FLAG_KEEP
@ -42,6 +45,7 @@ function usage() {
echo
echo "Options:"
echo -e " -h, --help\t\t\t\t\tPrint this help"
echo -e " -i, --interactive\t\t\t\t\tRun the build container in interactive mode"
echo -e " -k, --keep\t\t\t\t\tKeep the working container that is used for the build"
echo -e " -n, --name <string>\t\t\t\tImage name that is used to spin up the container (default: ${INAME})"
echo -e " -m, --mode <create | update | build>\t\tRun mode: (default: ${MODE})"
@ -61,8 +65,9 @@ function usage() {
}
options=$(getopt \
-o hkn:m:p:r:e:sl: \
-o hikn:m:p:r:e:sl: \
-l "help" \
-l interactive \
-l keep \
-l name: \
-l mode: \
@ -75,32 +80,35 @@ options=$(getopt \
eval set -- "${options}"
while true; do
case "${1}" in
-k|--keep)
-i | --interactive)
ARCHBUILDER_INTERACTIVE=1
;;
-k | --keep)
_FLAG_KEEP=1
;;
-n|--name)
-n | --name)
shift
ARCHBUILDER_IMAGE_NAME=${1}
;;
-m|--mode)
-m | --mode)
shift
_OPT_MODE="${1}"
;;
-e|--key)
-e | --key)
shift
_OPT_KEYS[${#_OPT_KEYS[*]}]="${1}"
;;
-r|--repo)
-r | --repo)
shift
ARCHBUILDER_CACHE_REPO="${1}"
;;
-s|--silent)
-s | --silent)
_FLAG_SILENT=1
;;
-l|--level)
-l | --level)
shift
check_log_level "${1}" \
|| exit_error "${err}"
check_log_level "${1}" ||
exit_error "${err}"
LOG_LEVEL_STDOUT="${1}"
LOG_LEVEL_LOG="${1}"
;;
@ -112,7 +120,7 @@ while true; do
shift
break
;;
-h|--help|*)
-h | --help | *)
usage
exit 0
;;
@ -127,7 +135,6 @@ init_env
buildah_prepare_params
function exit_trap() {
buildah_exit
}
@ -136,13 +143,13 @@ trap exit_trap EXIT
buildah_create
case "${_OPT_MODE}" in
"create")
"create")
buildah_create
;;
"update")
"update")
buildah_update
;;
"build")
"build")
buildah_build
;;
esac

View File

@ -13,13 +13,12 @@ _BUILDAH_MOUNTS=()
_BUILDAH_PARAMS=""
_BUILDAH_MAKEPKG_ENV=""
_BUILDAH_MAKEPKG_FLAGS=" --noconfirm" # always noconfirm to avoid hanging
_BUILDAH_MAKEPKG_FLAGS="" # always noconfirm to avoid hanging
function buildah_exists() {
log_debug "Checking if buildah image '${1}' exists"
if buildah inspect "${1}" > /dev/null 2>&1
then
if buildah inspect "${1}" >/dev/null 2>&1; then
log_debug "Buildah image '${1}' exists"
return 0
fi
@ -29,12 +28,15 @@ function buildah_exists() {
}
function buildah_prepare_params() {
_BUILDAH_PARAMS="${_BUILDAH_PARAMS} -v ${ARCHBUILDER_CACHE_REPO}:${_BUILDAH_CACHE_REPO_PATH}:rw,U"
_BUILDAH_PARAMS="${_BUILDAH_PARAMS} -t -v ${ARCHBUILDER_CACHE_REPO}:${_BUILDAH_CACHE_REPO_PATH}:rw,U"
# adding working directory to container
# TODO: param -> req for aurutils
_BUILDAH_PARAMS="${_BUILDAH_PARAMS} -v $(pwd):${_BUILDAH_MKPKG_PATH}:rw,U"
test_null "ARCHBUILDER_INTERACTIVE" "${ARCHBUILDER_INTERACTIVE}" && {
_BUILDAH_MAKEPKG_FLAGS="--noconfirm"
}
log_info "Preparing makepkg environment"
test_null "PKGDEST" "${PKGDEST}" || {
_BUILDAH_PARAMS="${_BUILDAH_PARAMS} -v ${PKGDEST}:${_BUILDAH_PKGDEST_PATH}:rw,U"
@ -65,8 +67,8 @@ function buildah_create() {
exec_cmd buildah pull "${_BUILDAH_BASE_IMAGE}"
}
test_null "_ACT_CREATE_IMAGE" "${_ACT_CREATE_IMAGE}" \
&& return 0
test_null "_ACT_CREATE_IMAGE" "${_ACT_CREATE_IMAGE}" &&
return 0
log_info "Creating working container '${ARCHBUILDER_IMAGE_NAME}' from '${_BUILDAH_BASE_IMAGE}'"
_BUILDAH_CONT=$(buildah from --name "${ARCHBUILDER_IMAGE_NAME}" "${_BUILDAH_BASE_IMAGE}")
@ -78,7 +80,7 @@ function buildah_create() {
exec_cmd buildah run "${_BUILDAH_CONT}" pacman --noconfirm -S base-devel sudo vim git
log_info "Creating user '${_OPT_CON_BUILD_USER}'"
exec_cmd buildah run "${_BUILDAH_CONT}" useradd -m -s /bin/bash -U -u 1000 "${_OPT_CON_BUILD_USER}"
exec_cmd buildah run "${_BUILDAH_CONT}" useradd -m -s /bin/bash -U -u "${ARCHBUILDER_UID}" "${_OPT_CON_BUILD_USER}"
log_info "Setting up sudo for user '${_OPT_CON_BUILD_USER}'"
exec_cmd buildah run "${_BUILDAH_CONT}" bash -c "echo '${_OPT_CON_BUILD_USER} ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/${_OPT_CON_BUILD_USER}"
@ -109,8 +111,8 @@ function buildah_create() {
}
function buildah_update() {
buildah_exists "${ARCHBUILDER_IMAGE_NAME}" \
|| exit_error "Build image '${ARCHBUILDER_IMAGE_NAME}' does not exist" 1
buildah_exists "${ARCHBUILDER_IMAGE_NAME}" ||
exit_error "Build image '${ARCHBUILDER_IMAGE_NAME}' does not exist" 1
log_info "Creating working container '${ARCHBUILDER_IMAGE_NAME}' from '${ARCHBUILDER_IMAGE_NAME}'"
_BUILDAH_CONT=$(buildah from --name "${ARCHBUILDER_IMAGE_NAME}" "${ARCHBUILDER_IMAGE_NAME}")
@ -128,8 +130,8 @@ function buildah_update() {
}
function buildah_prepare_build() {
buildah_exists "${ARCHBUILDER_IMAGE_NAME}" \
|| exit_error "Build image '${ARCHBUILDER_IMAGE_NAME}' does not exist" 1
buildah_exists "${ARCHBUILDER_IMAGE_NAME}" ||
exit_error "Build image '${ARCHBUILDER_IMAGE_NAME}' does not exist" 1
log_info "Creating working container '${ARCHBUILDER_IMAGE_NAME}' from '${ARCHBUILDER_IMAGE_NAME}'"
_BUILDAH_CONT=$(buildah from --name "${ARCHBUILDER_IMAGE_NAME}" "${ARCHBUILDER_IMAGE_NAME}")
@ -140,8 +142,7 @@ function buildah_prepare_build() {
log_info "Updating container system"
exec_cmd buildah run --user ${_OPT_CON_BUILD_USER} ${_BUILDAH_PARAMS} "${_BUILDAH_CONT}" sudo pacman --noconfirm -Syu
for k in "${_OPT_KEYS[@]}"
do
for k in "${_OPT_KEYS[@]}"; do
exec_cmd buildah run --user ${_OPT_CON_BUILD_USER} ${_BUILDAH_PARAMS} "${_BUILDAH_CONT}" gpg --receive-keys "${k}"
done
}
@ -169,5 +170,3 @@ function buildah_build() {
buildah_exit
}