#!/bin/bash -euE # libremakepkg # Copyright 2010 - 2011 Nicolás Reynolds # Copyright 2011 Joshua Ismael Haase Hernández # Copyright 2012-2013 Luke Shumaker # # This file is part of Parabola. # # Parabola is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Parabola is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Parabola. If not, see . . $(librelib conf.sh) load_files chroot . libremessages makechrootpkg=$(librelib makechrootpkg) shopt -s nullglob umask 0022 # Boring/mundane functions ##################################################### # End inmediately but print a useful message trap_exit() { error "$*" $INCHROOT || chroot_copy_out "$copydir" "$LIBREUSER" 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 copydir=$1; shift local cmd="$*" cat >"$copydir/chrootexec" <> "$copydir/etc/pacman.conf" < Name of the chroot to use' echo ' -l 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 ################################################### COPY=$LIBREUSER [[ $COPY != root ]] || COPY=copy makepkg_args='-s --noconfirm -L ' local repack=false INCHROOT=false if [[ -f /.arch-chroot ]]; then INCHROOT=true fi while getopts 'n:l:Rh' arg ; do case "${arg}" in n) CHROOT=$OPTARG;; l) COPY=$OPTARG;; R) repack=true; makepkg_args+=" -R";; h) usage; return 0;; *) usage; return 1;; esac done shift $(($OPTIND - 1)) # Pass all arguments after -- right to makepkg makepkg_args+=" $*" if $INCHROOT; then copydir='/' else check_vars chroot CHROOTDIR CHROOT if [[ ${COPY:0:1} = / ]]; then copydir=$COPY else copydir="${CHROOTDIR}/${CHROOT}/${COPY}" fi fi # Init ################################################################# if (( EUID )); then error "This script must be run as root" exit 1 fi if [[ ! -f PKGBUILD ]]; then # This is the message used by makepkg 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 error has occurred. Exiting..."' ERR SRCDEST="$(get_conf_makepkg SRCDEST .)" PKGDEST="$(get_conf_makepkg PKGDEST .)" # OK, we're starting now ############################################### $INCHROOT || lock_open_write 9 "$copydir" \ "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 MAKEPKG_CONF=$copydir/etc/makepkg.conf export CARCH="$(get_conf_makepkg CARCH)" unset MAKEPKG_CONF $INCHROOT || chroot_init "$copydir" "$repack" check_pkgbuild $INCHROOT || chroot_copy_in "$copydir" $repack || extract check_src build check_pkg add_to_local_repo "$copydir" "$copydir"/pkgdest/*.pkg.tar* $INCHROOT || chroot_copy_out "$copydir" "$LIBREUSER" } main "$@"