summaryrefslogtreecommitdiff
path: root/src/chroot-tools/libremakepkg
diff options
context:
space:
mode:
Diffstat (limited to 'src/chroot-tools/libremakepkg')
-rwxr-xr-xsrc/chroot-tools/libremakepkg123
1 files changed, 67 insertions, 56 deletions
diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg
index 4e810d1..2901b0d 100755
--- a/src/chroot-tools/libremakepkg
+++ b/src/chroot-tools/libremakepkg
@@ -20,7 +20,10 @@
# You should have received a copy of the GNU General Public License
# along with Parabola. If not, see <http://www.gnu.org/licenses/>.
-. /etc/libretools.conf
+. /usr/share/libretools/conf.sh
+load_conf_libretools_chroot
+
+. "$(which libremessages)"
shopt -s nullglob
@@ -29,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 #############################################################
@@ -54,37 +58,31 @@ trap_exit() {
exit 1
}
-##
-# Usage: makepkg_conf_get SETTING [DEFAULT]
-##
-makepkg_conf_get() {
- local setting=$1
- if [[ -f $LIBREHOME/.makepkg.conf ]]; then
- eval $(grep "^$setting=" "$LIBREHOME/.makepkg.conf")
- fi
- if [[ -z ${!setting:-} ]]; then
- eval $(grep "^$setting=" "/etc/makepkg.conf")
- fi
- if [[ -z ${!setting:-} && -n ${2:-} ]]; then
- eval "$setting='$2'"
+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_makepkg_conf_get() {
- local setting=$1
- eval $(grep "^$setting=" "$copydir/etc/makepkg.conf")
+ chroot_exec "${clean} && sudo -u ${user} ${MAKEPKG} ${makepkg_args} -o"
}
-chroot_makepkg_conf_set() {
- local key=$1
- local val=$2
- sed -i "/^$key=/d" "$copydir/etc/makepkg.conf"
- echo "$key='$val'" >> "$copydir/etc/makepkg.conf"
+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
@@ -98,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
}
@@ -113,17 +111,18 @@ libre_check_pkg() {
cmd=${0##*/}
usage() {
- echo "Usage: $cmd [options] [-- makepkg args]"
- echo 'This program will build your package.'
- echo ''
- echo 'OPTIONS:'
- 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 ''
- echo " -m <MAKEPKG> Use the command MAKEPKG instead of 'makepkg'"
- echo ''
- echo ' -h Show this message'
+ echo "Usage: $cmd [options] [-- makepkg args]"
+ echo 'This program will build your package.'
+ echo ''
+ echo 'If run from outside of a chroot, this will set PKGDEST and'
+ echo "SRCDEST in the chroot's \`/etc/makepkg.conf', as well as making"
+ echo "whataver alterations to the chroot \`librechroot' makes."
+ 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 ' -h Show this message'
}
main() {
@@ -135,6 +134,11 @@ main() {
makepkg_args='-s --noconfirm -L '
MAKEPKG=makepkg
+ INCHROOT=false
+ if [[ -f /.arch-chroot ]]; then
+ INCHROOT=true
+ fi
+
while getopts 'n:l:m:Rh' arg ; do
case "${arg}" in
n) CHROOT=$OPTARG;;
@@ -148,8 +152,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 #################################################################
@@ -169,27 +176,31 @@ main() {
trap 'trap_exit "(libremakepkg): Aborted by user! Exiting..."' INT
trap 'trap_exit "(libremakepkg): An unknown error has occurred. Exiting..."' ERR
- makepkg_conf_get SRCDEST .
- makepkg_conf_get PKGDEST .
+ SRCDEST="$(get_conf_makepkg SRCDEST .)"
+ PKGDEST="$(get_conf_makepkg PKGDEST .)"
# OK, we're starting now ###############################################
- lock_open_write 9 "$copydir" "Locking chroot '$CHROOTCOPY'"
+ lock_open_write 9 "$copydir" \
+ "Waiting for existing lock on \`$copydir' to be released"
- # Set target CARCH as it might be used within the PKGBUILD to select correct sources
- chroot_makepkg_conf_get CARCH
- export CARCH
+ # Set target CARCH as it might be used within the PKGBUILD to select
+ # correct sources
+ MAKEPKG_CONF=$copydir/etc/makepkg.conf
+ export CARCH="$(get_conf_makepkg CARCH)"
+ unset MAKEPKG_CONF
- 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
- copy_pkgs
- copy_logs
+ add_to_local_repo
+ $INCHROOT || chroot_copy_out
}
main "$@"