summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/chroot-tools/libremakepkg67
-rwxr-xr-xsrc/chroot-tools/libremakepkg.gpl250
2 files changed, 71 insertions, 46 deletions
diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg
index c66f5cc..0276315 100755
--- a/src/chroot-tools/libremakepkg
+++ b/src/chroot-tools/libremakepkg
@@ -32,9 +32,10 @@ shopt -s nullglob
. "$(dirname "$0")/libremakepkg.gpl2"
# This gives us the functions:
# - chroot_init
-# - chroot_extract
-# - chroot_build
-# - copy_pkgs
+# - chroot_exec
+# - chroot_copy_in
+# - chroot_copy_out
+# - add_to_local_repo
# Boring functions #############################################################
@@ -57,9 +58,31 @@ trap_exit() {
exit 1
}
+extract() {
+ local user=$LIBREUSER
+ $INCHROOT || user=nobody
+
+ local clean
+ if $INCHROOT; then
+ clean=chcleanup
+ else
+ cp -a "$(which chcleanup)" "${copydir}/clean"
+ clean=/clean
+ fi
+
+ chroot_exec "${clean} && sudo -u ${user} ${MAKEPKG} ${makepkg_args} -o"
+}
+
+build() {
+ local user=$LIBREUSER
+ $INCHROOT || user=nobody
+
+ chroot_exec -N "sudo -u ${user} ${MAKEPKG} ${makepkg_args} -e"
+}
+
# Functions that check for issues with the build ###############################
-libre_check_pkgbuild() {
+check_pkgbuild() {
msg "Checking PKGBUILD for issues"
# TODO
if ! pkgbuild-check-nonfree -f; then
@@ -73,12 +96,12 @@ libre_check_pkgbuild() {
fi
}
-libre_check_src() {
+check_src() {
msg "Checking src directory for issues"
# TODO
}
-libre_check_pkg() {
+check_pkg() {
msg "Checking final package for issues"
# TODO
}
@@ -95,7 +118,6 @@ usage() {
echo " -n <CHROOT> Use this chroot instead of \`$CHROOT'"
echo ' -l <COPY> Use this chroot copy instead of basing it'
echo ' on the username'
- echo ' -C Do not use a chroot'
echo ''
echo " -m <MAKEPKG> Use the command MAKEPKG instead of 'makepkg'"
echo ''
@@ -110,13 +132,16 @@ main() {
makepkg_args='-s --noconfirm -L '
MAKEPKG=makepkg
- NOCHROOT=false
+
+ INCHROOT=false
+ if [[ -f /.arch-chroot ]]; then
+ INCHROOT=true
+ fi
while getopts 'n:l:m:Rh' arg ; do
case "${arg}" in
n) CHROOT=$OPTARG;;
l) CHROOTCOPY=$OPTARG;;
- C) NOCHROOT=true;;
m) MAKEPKG=$OPTARG;;
h) usage; exit 0;;
*) usage; exit 1;;
@@ -126,8 +151,11 @@ main() {
# Pass all arguments after -- right to makepkg
makepkg_args+=" $*"
- rootdir="${CHROOTDIR}/${CHROOT}/root"
- copydir="${CHROOTDIR}/${CHROOT}/${CHROOTCOPY}"
+ if $INCHROOT; then
+ copydir=''
+ else
+ copydir="${CHROOTDIR}/${CHROOT}/${CHROOTCOPY}"
+ fi
# Init #################################################################
@@ -160,16 +188,17 @@ main() {
export CARCH="$(get_conf_makepkg CARCH)"
unset MAKEPKG_CONF
- $NOCHROOT || chroot_init
+ $INCHROOT || chroot_init
- libre_check_pkgbuild
- chroot_extract
- libre_check_src
- chroot_build
- libre_check_pkg
+ check_pkgbuild
+ $INCHROOT || chroot_copy_in
+ extract
+ check_src
+ build
+ check_pkg
- $NOCHROOT || copy_pkgs
- $NOCHROOT || copy_logs
+ add_to_local_repo
+ $INCHROOT || chroot_copy_out
}
main "$@"
diff --git a/src/chroot-tools/libremakepkg.gpl2 b/src/chroot-tools/libremakepkg.gpl2
index 50bb48e..8770bee 100755
--- a/src/chroot-tools/libremakepkg.gpl2
+++ b/src/chroot-tools/libremakepkg.gpl2
@@ -20,10 +20,10 @@ chroot_init() {
if [[ -r "$LIBREHOME/.gnupg/pubring.gpg" ]]; then
install -D "$HOME/.gnupg/pubring.gpg" "$copydir/build/.gnupg/pubring.gpg"
fi
+ rm -f "$copydir/build/.makepkg.conf"
mkdir -p "$copydir/pkgdest"
mkdir -p "$copydir/srcdest"
- mkdir -p "$copydir/build"
MAKEPKG_CONF=$copydir/etc/makepkg.conf set_conf_makepkg PKGDEST /pkgdest
MAKEPKG_CONF=$copydir/etc/makepkg.conf set_conf_makepkg SRCDEST /srcdest
@@ -35,12 +35,8 @@ EOF
chmod 440 "$copydir/etc/sudoers.d/nobody-pacman"
}
-chroot_extract() {
- if $NOCHROOT; then
- chcleanup
- sudo -u ${LIBREUSER} ${MAKEPKG} ${makepkg_args} -o
- return
- fi
+
+chroot_copy_in() {
rm -rf "$copydir"/build/*
cp PKGBUILD "$copydir/build/"
(
@@ -71,49 +67,49 @@ chroot_extract() {
)
chown -R nobody "$copydir"/{build,pkgdest,srcdest}
-
- cp -a "$(which chcleanup)" "${copydir}/clean"
- chroot_exec "/clean && sudo -u nobody ${MAKEPKG} ${makepkg_args} -o"
-}
-
-chroot_build() {
- local user=$LIBREUSER
- $NOCHROOT || user=nobody
- chroot_exec -N "sudo -u ${user} ${MAKEPKG} ${makepkg_args} -e"
}
chroot_exec() {
- local flags=''
- [[ $1 == -N ]] && { flags=$1; shift; }
+ local HASNET=true
+ [[ $1 == -N ]] && { HASNET=false; shift; }
+
local cmd="$*"
- if $NOCHROOT; then
- ${cmd}
- else
- cat >"$copydir/chrootexec" <<EOF
+ cat >"$copydir/chrootexec" <<EOF
#!/bin/bash
. /etc/profile
-export HOME=/build
-cd /build
+${INCHROOT} || export HOME=/build
+${INCHROOT} || cd /build
${cmd}
EOF
- chmod 755 "$copydir/chrootexec"
+ chmod 755 "$copydir/chrootexec"
+
+ local flags=''
+ if $INCHROOT; then
+ $HASNET || flags='-n'
+ unshare $flags -- /chrootexec
+ else
+ $HASNET || flags='-N'
librechroot $flags -n "$CHROOT" -l "$CHROOTCOPY" -r /chrootexec
fi
}
-copy_pkgs() {
+add_to_local_repo() {
for pkgfile in "$copydir"/pkgdest/*.pkg.tar*; do
mkdir -p "$copydir/repo"
pushd "$copydir/repo" >/dev/null
cp "$pkgfile" .
repo-add repo.db.tar.gz "${pkgfile##*/}"
popd >/dev/null
-
+ done
+}
+chroot_copy_out() {
+ for pkgfile in "$copydir"/pkgdest/*.pkg.tar*; do
chown "$LIBREUSER" "$pkgfile"
mv "$pkgfile" "$PKGDEST"
if [[ $PKGDEST != . ]]; then
ln -s "$PKGDEST/${pkgfile##*/}" .
fi
done
+ copy_logs
}