summaryrefslogtreecommitdiff
path: root/src/chroot-tools/libremakepkg
diff options
context:
space:
mode:
Diffstat (limited to 'src/chroot-tools/libremakepkg')
-rwxr-xr-xsrc/chroot-tools/libremakepkg181
1 files changed, 152 insertions, 29 deletions
diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg
index a9e1fb7..25f23c6 100755
--- a/src/chroot-tools/libremakepkg
+++ b/src/chroot-tools/libremakepkg
@@ -3,7 +3,7 @@
# Copyright 2010 - 2011 Nicolás Reynolds
# Copyright 2011 Joshua Ismael Haase Hernández
-# Copyright 2012 Luke Shumaker
+# Copyright 2012-2013 Luke Shumaker
#
# This file is part of Parabola.
#
@@ -23,22 +23,131 @@
. /usr/share/libretools/conf.sh
load_conf_libretools_chroot
-. "$(which libremessages)"
-. /usr/share/devtools/makechrootpkg.sh
+. libremessages
shopt -s nullglob
+umask 0022
-# Boring functions #############################################################
+# Boring/mundane functions #####################################################
-##
# End inmediately but print a useful message
-##
trap_exit() {
- copy_logs
error "$*"
+ set +euE
+ . /usr/share/devtools/makechrootpkg.sh
+ chroot_copy_out_logs "$@"
exit 1
}
+# Usage run [-N] $copydir "$cmd"
+# Runs cmd properly, whether in a chroot already or not.
+#
+# Note that $cmd is a quoted string, not a list of arguments.
+# $copydir=/ if INCHROOT=true
+#
+# Environment
+# - $INCHROOT is set
+run() {
+ local HASNET=true
+ [[ $1 == -N ]] && { HASNET=false; shift; }
+ local cmd="$*"
+
+ cat >"$copydir/chrootexec" <<EOF
+#!/bin/bash
+. /etc/profile
+${INCHROOT} || export HOME=/build
+${INCHROOT} || cd /build
+
+${cmd}
+EOF
+ chmod 755 "$copydir/chrootexec"
+
+ local flags=''
+ if $INCHROOT; then
+ $HASNET || flags='-n'
+ unshare $flags -- /chrootexec
+ else
+ $HASNET || flags='-N'
+ librechroot $flags -l "$copydir" run /chrootexec
+ fi
+}
+
+# Usage: add_to_local_repo $copydir
+add_to_local_repo() (
+ set +euE
+ . /usr/share/devtools/makechrootpkg.sh
+ chroot_add_to_local_repo "$@"
+)
+
+# Usage: chroot_copy_in $copydir
+# Environment:
+# - In the dirctory of a PKGBUILD
+# - $SRCDEST is set
+chroot_copy_in() (
+ set +euE
+ . /usr/share/devtools/makechrootpkg.sh
+ chroot_copy_in "$@"
+)
+
+# Usage: chroot_copy_out $copydir $owner
+# Environment:
+# - $SRCDEST is set
+# - $PKGDEST is set
+chroot_copy_out() (
+ set +euE
+ . /usr/share/devtools/makechrootpkg.sh
+ chroot_copy_out_pkgs "$@"
+ chroot_copy_out_logs "$@"
+ chroot_copy_out_srcs "$@"
+)
+
+# Usage: chroot_let_nobody_use_pacman $copydir
+chroot_let_nobody_use_pacman() (
+ set +euE
+ . /usr/share/devtools/makechrootpkg.real.sh
+ chroot_let_nobody_use_pacman "$@"
+}
+
+# Usage: chroot_init $copydir $repack
+# Environment
+# - $LIBREHOME is set
+chroot_init() {
+ local $copydir=$1
+ local $repack=$2
+
+ librechroot -l "$copydir" make # make sure the chroot exists
+ mkdir -p "$copydir"/{build,pkgdest,srcdest}
+
+ # Remove anything in there UNLESS -R (repack) was passed
+ $repack || rm -rf "$copydir"/build/*
+
+ if [[ -r "$LIBREHOME/.gnupg/pubring.gpg" ]]; then
+ install -D "$LIBREHOME/.gnupg/pubring.gpg" "$copydir/build/.gnupg/pubring.gpg"
+ fi
+ rm -f "$copydir/build/.makepkg.conf"
+
+ MAKEPKG_CONF="$copydir/etc/makepkg.conf" set_conf_makepkg PKGDEST /pkgdest
+ MAKEPKG_CONF="$copydir/etc/makepkg.conf" set_conf_makepkg SRCDEST /srcdest
+
+ if grep -q '^\[repo\]' "$copydir/etc/pacman.conf"; then
+ cat >> "$copydir/etc/makepkg.conf" <<EOF
+[repo]
+SigLevel = Optional TrustAll
+Server = file:///repo
+EOF
+ fi
+
+ chroot_let_nobody_use_pacman
+}
+
+# Core functions ###############################################################
+
+# Usage: extract
+# Extracts the sources (`makepkg -o`)
+# Environment:
+# - $INCHROOT is set
+# - $copydir is set
+# - $LIBREUSER is set
extract() {
local user=$LIBREUSER
$INCHROOT || user=nobody
@@ -51,14 +160,21 @@ extract() {
clean=/clean
fi
- chroot_exec "${clean} && sudo -u ${user} ${MAKEPKG} ${makepkg_args} -o"
+ run "$copydir" "${clean} && sudo -u ${user} makepkg ${makepkg_args} -o"
+ rm -f "$copydir"/clean
}
+# Usage: build
+# Builds the package (`makepkg -e`)
+# Environment:
+# - $INCHROOT is set
+# - $copydir is set
+# - $LIBREUSER is set
build() {
local user=$LIBREUSER
$INCHROOT || user=nobody
- chroot_exec -N "sudo -u ${user} ${MAKEPKG} ${makepkg_args} -e"
+ run -N "$copydir" "sudo -u ${user} makepkg ${makepkg_args} -e"
}
# Functions that check for issues with the build ###############################
@@ -99,34 +215,39 @@ usage() {
echo "SRCDEST in the chroot's \`/etc/makepkg.conf', as well as making"
echo "whataver alterations to the chroot \`librechroot' makes."
echo ''
+ echo "The \`-n' and \`-l' options behave identically to librechroot,"
+ echo 'see the documentation there.'
+ echo ''
echo 'Options:'
- echo " -n <CHROOT> Use this chroot instead of \`$CHROOT'"
- echo " -l <COPY> Use this chroot copy instead \`$CHROOTCOPY'"
- echo " -m <MAKEPKG> Use the command MAKEPKG instead of \'makepkg'"
+ echo ' -n <CHROOT> Name of the chroot to use'
+ echo ' -l <COPY> Name of, or absolute path to, the copy to use'
+ echo ' -R Repackage contents of the package without rebuilding'
echo ' -h Show this message'
}
+# Globals: $CHROOTDIR, $CHROOT, $COPY and $copydir
+# Globals: $makepkg_args, $INCHROOT
main() {
# Parse command line ###################################################
- CHROOTCOPY=$LIBREUSER
- [[ $CHROOTCOPY != root ]] || CHROOTCOPY=copy
+ COPY=$LIBREUSER
+ [[ $COPY != root ]] || COPY=copy
makepkg_args='-s --noconfirm -L '
- MAKEPKG=makepkg
+ local repack=false
INCHROOT=false
if [[ -f /.arch-chroot ]]; then
INCHROOT=true
fi
- while getopts 'n:l:m:Rh' arg ; do
+ while getopts 'n:l:Rh' arg ; do
case "${arg}" in
n) CHROOT=$OPTARG;;
- l) CHROOTCOPY=$OPTARG;;
- m) MAKEPKG=$OPTARG;;
- h) usage; exit 0;;
- *) usage; exit 1;;
+ l) COPY=$OPTARG;;
+ R) repack=true; makepkg_args+=" -R";;
+ h) usage; return 0;;
+ *) usage; return 1;;
esac
done
shift $(($OPTIND - 1))
@@ -134,9 +255,11 @@ main() {
makepkg_args+=" $*"
if $INCHROOT; then
- copydir=''
+ copydir='/'
+ elif [[ ${COPY:0:1} = / ]]; then
+ copydir=$COPY
else
- copydir="${CHROOTDIR}/${CHROOT}/${CHROOTCOPY}"
+ copydir="${CHROOTDIR}/${CHROOT}/${COPY}"
fi
# Init #################################################################
@@ -148,14 +271,14 @@ main() {
if [[ ! -f PKGBUILD ]]; then
# This is the message used by makepkg
- error "PKGBUILD does not exist"
+ error "PKGBUILD does not exist."
exit 1
fi
# Trap signals from makepkg
trap 'trap_exit "(libremakepkg): TERM signal caught. Exiting..."' TERM HUP QUIT
trap 'trap_exit "(libremakepkg): Aborted by user! Exiting..."' INT
- trap 'trap_exit "(libremakepkg): An unknown error has occurred. Exiting..."' ERR
+ trap 'trap_exit "(libremakepkg): An error has occurred. Exiting..."' ERR
SRCDEST="$(get_conf_makepkg SRCDEST .)"
PKGDEST="$(get_conf_makepkg PKGDEST .)"
@@ -163,7 +286,7 @@ main() {
# OK, we're starting now ###############################################
lock_open_write 9 "$copydir" \
- "Waiting for existing lock on \`$copydir' to be released"
+ "Waiting for existing lock on chroot copy to be released: [$COPY]"
# Set target CARCH as it might be used within the PKGBUILD to select
# correct sources
@@ -171,17 +294,17 @@ main() {
export CARCH="$(get_conf_makepkg CARCH)"
unset MAKEPKG_CONF
- $INCHROOT || chroot_init
+ $INCHROOT || chroot_init "$copydir" "$repack"
check_pkgbuild
- $INCHROOT || chroot_copy_in
+ $INCHROOT || chroot_copy_in "$copydir"
extract
check_src
build
check_pkg
- add_to_local_repo
- $INCHROOT || chroot_copy_out
+ add_to_local_repo "$copydir"
+ $INCHROOT || chroot_copy_out "$copydir" "$LIBREUSER"
}
main "$@"