summaryrefslogtreecommitdiff
path: root/src/chroot-tools/libremakepkg
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2012-11-12 17:32:40 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2012-11-12 17:32:40 -0500
commit16e41597e98333f6383a3cb9aa6e9371f64522bf (patch)
tree88dc4ed11a6cfa3e86a0bb95eadaeaf0a8e717f3 /src/chroot-tools/libremakepkg
parentde192642ea009e9b8e16f54209575536538869e2 (diff)
chroot-tools: clean up, make play nice with new devtools
* buildenv: delete; this is done by `mkarchroot` * librechroot: - adopt `archbuild`'s concept of CHROOT and CHROOTCOPY - add `-l` option to set the CHROOTCOPY * libremakepkg: - adopt `archbuild`'s concept of CHROOT and CHROOTCOPY - add `-l` option to set the CHROOTCOPY - pass options to `makechrootpkg` and `makepkg` the way `-h` always said it did * libremkchroot: - adopt `archbuild`'s concept of CHROOT and CHROOTCOPY - remove `-c` option to set the pacman cache - remove `-f` option to force overwrite
Diffstat (limited to 'src/chroot-tools/libremakepkg')
-rwxr-xr-xsrc/chroot-tools/libremakepkg195
1 files changed, 104 insertions, 91 deletions
diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg
index f7924f6..69e8998 100755
--- a/src/chroot-tools/libremakepkg
+++ b/src/chroot-tools/libremakepkg
@@ -1,6 +1,10 @@
#!/bin/bash
+# libremakepkg
+# analogous to devtools' archbuild
+
# Copyright 2010 - 2011 Nicolás Reynolds
# Copyright 2011 Joshua Ismael Haase Hernández
+# Copyright 2012 Luke Shumaker
# ---------- GNU General Public License 3 ----------
@@ -19,108 +23,117 @@
# 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
-# set -x # uncomment for debug
-
-function copy_log { # copy logs if they exist
-
- find "${CHROOTDIR}/${CHROOT}/build/" -maxdepth 1 -name "*\.log" -exec cp {} ./ \;
-
+##
+# copy logs if they exist
+##
+copy_log() {
+ find "${chroot_path}/build/" -maxdepth 1 -name "*\.log" -exec cp {} ./ \;
}
-
-function trap_exit { # End inmediately but print a useful message
-
- copy_log
- error "$@"
- exit 1
-
+##
+# End inmediately but print a useful message
+##
+trap_exit() {
+ copy_log
+ error "$@"
+ exit 1
}
-# Trap signals from makepkg
-set -E
-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
-
-source /etc/libretools.conf
-
-CLEANFIRST="false"
-UPDATEFIRST="false"
-CHECKNONFREE="true"
-LIBRECHROOT_ARGS=""
-MAKEPKG_ARGS=""
-
-function usage {
-
- echo ''
+usage() {
echo 'cd to a dir containing a PKGBUILD and run:'
echo '$0 [options] [-- makechrootpkg args [-- makepkg args]]'
- echo 'This script will build your package on a chroot.'
+ echo 'This script will build your package in a chroot.'
echo ''
echo 'OPTIONS:'
+ echo ' -h Show this message'
echo ''
- echo ' -h : show this message.'
- echo ' -c : clean the chroot before building.'
- echo ' -u : update the chroot before building.'
- echo ' -d <chrootdir> : use this dir instead of "$CHROOTDIR"'
- echo ' -n <chrootname> : use this dir instead of "$CHROOT".'
- echo ' -N : do not check freedom issues' # As fullpkg-check will do that before
+ echo ' -c Clean the chroot before building'
+ echo ' -u Update the chroot before building'
+ echo ' -N Do not check freedom issues (for fullpkg)'
echo ''
- exit 1
+ echo " -d <chrootdir> Use this dir instead of \`$CHROOTDIR'"
+ echo " -n <chroot> Use this chroot instead of \`$CHROOT'"
+ echo ' -l <copy> Use this chroot copy instead of basing it'
+ echo ' on the username'
+}
+main() {
+ # The logic for setting CHROOTCOPY is mirred from makechrootpkg
+ CHROOTCOPY=$USER
+ [[ -n $SUDO_USER ]] && CHROOTCOPY=$SUDO_USER
+ [[ -z $CHROOTCOPY || $CHROOTCOPY = root ]] && CHROOTCOPY=copy
+
+ CLEANFIRST=false
+ UPDATEFIRST=false
+ CHECKNONFREE=true
+
+ makechrootpkg_args=()
+
+ while getopts 'hcuNd:n:l:' arg ; do
+ case "${arg}" in
+ c) CLEANFIRST=true;;
+ u) UPDATEFIRST=true;;
+ N) CHECKNONFREE=false;;
+
+ d) CHROOTDIR=$OPTARG;;
+ n) CHROOT=$OPTARG;;
+ l) CHROOTCOPY=$OPTARG;;
+
+ h) usage; exit 0;;
+ *) usage; exit 1;;
+ esac
+ done
+ shift $(($OPTIND - 1))
+ # Pass all arguments after -- right to makechrootpkg
+ makechrootpkg_args+=("$@")
+
+ if (( EUID )); then
+ error "This script must be run as root"
+ exit 1
+ fi
+
+ if [[ ! -e PKGBUILD ]]; then
+ error "This isn't a build directory"
+ exit 1
+ fi
+
+ # OK, we're starting now ###############################################
+
+ # Trap signals from makepkg
+ set -E
+ 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
+
+ if $CHECKNONFREE; then
+ msg "Checking PKGBUILD for non-free issues"
+ if ! pkgbuild-check-nonfree; then
+ if [[ $? -eq 15 ]]; then
+ # other errors mean fail, not nonfree
+ error "PKGBUILD contains non-free issues"
+ exit 15
+ else
+ warning "PKGBUILD couldn't be check aganist non-free issues"
+ fi
+ fi
+ fi
+
+ if $CLEANFIRST; then
+ librechroot -c -d "$CHROOTDIR" -l "$CHROOTCOPY" "$CHROOT"
+ fi
+
+ if $UPDATEFIRST; then
+ librechroot -u -d "$CHROOTDIR" -l "$CHROOTCOPY" "$CHROOT"
+ fi
+
+ unset CLEANFIRST UPDATEFIRST librechroot_args
+
+ makechrootpkg "${makechrootpkg_args[@]}" -d -r "$CHROOTDIR/${CHROOT}" -l "$CHROOTCOPY"
+ ev=$? # exit value
+ copy_log
+ exit $ev
}
-while getopts 'hcud:n:N' arg ; do
- case "${arg}" in
- h) usage ;;
- c) CLEANFIRST="true" ;;
- u) UPDATEFIRST="true" ;;
- d) CHROOTDIR="$OPTARG"
- LIBRECHROOT_ARGS='-d "$OPTARG"' ;;
- n) CHROOT="$OPTARG" ;;
- N) CHECKNONFREE="false" ;;
- esac
-done
-
-# Pass all arguments after -- right to makechrootpkg
-MAKEPKG_ARGS="$makepkg_args ${*:$OPTIND}"
-
-if (( EUID )); then
- error "This script must be run as root"
- exit 1
-fi
-
-if [ ! -e PKGBUILD ]; then # Check if we are actually on a build directory. Do this early.
- error "This isn't a build directory"; usage
-fi
-
-msg "Checking PKGBUILD for non-free issues"
-if "$CHECKNONFREE"; then
- if ! pkgbuild-check-nonfree; then
-
- if [[ $? -eq 15 ]]; then # other errors mean fail, not nonfree
- error "PKGBUILD contains non-free issues"
- exit 15
- else
- warning "PKGBUILD couldn't be check aganist non-free issues"
- fi
- fi
-fi
-
-if "$CLEANFIRST"; then
- librechroot -c "$LIBRECHROOT_ARGS" "$CHROOT"
-fi
-
-if "$UPDATEFIRST"; then
- librechroot -u "$LIBRECHROOT_ARGS" "$CHROOT"
-fi
-
-unset CLEANFIRST UPDATEFIRST LIBRECHROOT_ARGS
-
-makechrootpkg -d -r "$CHROOTDIR" -l "$CHROOT" -- $MAKEPKG_ARGS
-ev="$?" # exit value
-
-copy_log
-
-exit $ev
+main "$@"