summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/chroot-tools/buildenv28
-rwxr-xr-xsrc/chroot-tools/librechroot160
-rwxr-xr-xsrc/chroot-tools/libremakepkg195
-rwxr-xr-xsrc/chroot-tools/libremkchroot56
4 files changed, 222 insertions, 217 deletions
diff --git a/src/chroot-tools/buildenv b/src/chroot-tools/buildenv
deleted file mode 100755
index 84a1fc2..0000000
--- a/src/chroot-tools/buildenv
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/bash
-
-trap "umount_all" 0 ERR TERM KILL
-
-user=${SUDO_USER:-${1}}
-
-umount_all() {
- for mp in home/pkgdest home/srcdest home/${user}; do
- msg "Umounting /$mp"
- umount $CHROOTDIR/$CHROOT/$mp || error "Couldn't umount"
- done
-}
-
-source /etc/libretools.conf
-
-for mp in home/pkgdest home/srcdest home/${user} var/lib/toru; do
- msg "Binding /$mp"
- mount -o bind /$mp $CHROOTDIR/$CHROOT/$mp || exit 1
-done
-
-for etc in etc/makepkg.conf etc/abs.conf etc/mtab; do
- msg "Copying config /$etc"
- cp --remove-destination /$etc $CHROOTDIR/$CHROOT/$etc || exit 1
-done
-
-$(dirname $0)/librechroot $CHROOT
-
-exit $?
diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot
index c8e02b0..d53448a 100755
--- a/src/chroot-tools/librechroot
+++ b/src/chroot-tools/librechroot
@@ -4,6 +4,7 @@
# Copyright 2010 Nicolás Reynolds
# Copyright 2011 Joshua Haase
+# Copyright 2012 Luke Shumaker
# ---------- GNU General Public License 3 ----------
@@ -22,87 +23,100 @@
# You should have received a copy of the GNU General Public License
# along with Parabola. If not, see <http://www.gnu.org/licenses/>.
-function usage {
-
- echo ""
- echo "Usage: $0 [options] [chrootname]"
- echo "Use it as root."
- echo ""
- echo "Default chroot name: $CHROOT"
- echo "Default chrootdir: $CHROOTDIR"
- echo ""
- echo "OPTIONS:"
- echo ""
- echo " -c : clean the chroot using pacman"
- echo " only 'base', 'base-devel' and 'sudo' on chroot"
- echo " -d <chrootdir> : use <chrootdir> instead of default"
- echo " -r : clean /repo on the chroot"
- echo " -h : this message"
- echo " -u : update the chroot"
- echo ""
+. /etc/libretools.conf
-}
+cmd=${0##*/}
-function clean_chroot { # Clean packages with pacman
- cp -a "$(dirname $0)/chcleanup" "${CHROOTDIR}/${CHROOTNAME}/clean"
+clean_chroot() { # Clean packages with pacman
+ msg "Cleaning chroot with pacman: ${chroot_path}"
- mkarchroot -r "cd /build; /clean" "${CHROOTDIR}/${CHROOTNAME}"
-}
+ cp -a "$(dirname $0)/chcleanup" "${chroot_path}/clean"
+ mkarchroot -r "cd /build; /clean" "${chroot_path}"
-function clean_repo {
- msg "Cleaning repo for chroot: ${CHROOTDIR}/${CHROOTNAME}"
- if [ -d "${CHROOTDIR}/${CHROOTNAME}/repo" ]; then
- find "${CHROOTDIR}/${CHROOTNAME}/repo/" -mindepth 1 -delete
- else
- mkdir -p "${CHROOTDIR}/${CHROOTNAME}/repo"
- fi
- bsdtar -czf "${CHROOTDIR}/${CHROOTNAME}/repo/repo.db.tar.gz" -T /dev/null
- ln -s "repo.db.tar.gz" "${CHROOTDIR}/${CHROOTNAME}/repo/repo.db"
+ #mkarchroot "${chroot_path}" base base-devel sudo "${CHROOTEXTRAPKG[@]}"
}
-source /etc/libretools.conf
-
-if [ -e "$XDG_CONFIG_HOME/libretools/libretools.conf" ]; then
- source "$XDG_CONFIG_HOME/libretools/libretools.conf"
-fi
-
-CLEANCHROOT='false'
-UPDATE='false'
-CLEANREPO='false'
-CHROOTNAME="${CHROOT:-${SUDO_USER:-root}}"
-
-while getopts 'hrcud:' arg; do
- case $arg in
- h) usage; exit 0 ;;
- c) CLEANCHROOT='true' ;;
- u) UPDATE='true' ;;
- r) CLEANREPO='true' ;;
- d) CHROOTDIR="$(readlink -e $OPTARG)" ;;
- esac
-done
-
-[[ "$UID" != "0" ]] && {
- error "This script must be run as root."
- exit 1
+
+clean_repo() {
+ msg "Cleaning repo for chroot: ${chroot_path}"
+
+ if [ -d "${chroot_path}/repo" ]; then
+ find "${chroot_path}/repo/" -mindepth 1 -delete
+ else
+ mkdir -p "${chroot_path}/repo"
+ fi
+ bsdtar -czf "${chroot_path}/repo/repo.db.tar.gz" -T /dev/null
+ ln -s "repo.db.tar.gz" "${chroot_path}/repo/repo.db"
}
-shift $(($OPTIND - 1))
+update() {
+ msg "Updating chroot: ${chroot_path}"
+ mkarchroot -u "${chroot_path}"
+}
-if [ $# -eq 1 ]; then
- CHROOTNAME="$1"
-fi
+enter() {
+ msg "Entering chroot: ${chroot_path}"
+ mkarchroot -r "bash" "${chroot_path}"
+}
-if "$CLEANREPO"; then
- clean_repo
-fi
+usage() {
+ echo "Usage: $cmd [OPTIONS] [CHROOT]"
+ echo 'Interacts with a chroot.'
+ echo ''
+ echo "The default CHROOT is \`${CHROOT}'."
+ echo ''
+ echo 'Options:'
+ echo ' Settings:'
+ echo " -d <CHROOTDIR> Use this dir instead of \`${CHROOTDIR}'"
+ echo ' -l <copy> Use this as the chroot copy instead of basing it'
+ echo ' on the username'
+ echo ' Modes:'
+ echo ' -h Show this message'
+ echo ' -c Clean the chroot using pacman'
+ echo ' -r Clean /repo in the chroot'
+ echo ' -u Update the chroot'
+}
-if "$CLEANCHROOT"; then
- clean_chroot
-elif "$UPDATE"; then
- msg "Updating chroot: ${CHROOTDIR}/${CHROOTNAME}"
- mkarchroot -u "${CHROOTDIR}/${CHROOTNAME}"
-else
- msg "Entering chroot: ${CHROOTDIR}/${CHROOTNAME}"
- mkarchroot -r "bash" "${CHROOTDIR}/${CHROOTNAME}"
-fi
+main() {
+ # The logic for setting CHROOTCOPY is mirred from makechrootpkg
+ CHROOTCOPY=$USER
+ [[ -n $SUDO_USER ]] && CHROOTCOPY=$SUDO_USER
+ [[ -z $CHROOTCOPY || $CHROOTCOPY = root ]] && CHROOTCOPY=copy
+
+ local mode=enter
+ while getopts 'hrcud:l:' arg; do
+ case $arg in
+ d) CHROOTDIR=$OPTARG;;
+ l) CHROOTCOPY=$OPTARG;;
+
+ c) mode=clean_chroot;;
+ r) mode=clean_repo;;
+ u) mode=update;;
+
+ h) usage; exit 0;;
+ *) usage; exit 1;;
+ esac
+ done
+ shift $(($OPTIND - 1))
+ case $# in
+ 0) :;;
+ 1) CHROOT="$1";;
+ *) usage; exit 1;;
+ esac
+
+ # not local
+ chroot_path="${CHROOTDIR}/${CHROOT}/${CHROOTCOPY}"
+
+ if (( EUID )); then
+ error "This script must be run as root."
+ exit 1
+ fi
+
+ case "$mode" in
+ clean_chroot) clean_chroot; exit $?;;
+ clean_repo) clean_repo; exit $?;;
+ update) update; exit $?;;
+ enter) enter; exit $?;;
+ esac
+}
-exit 0
+main "$@"
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 "$@"
diff --git a/src/chroot-tools/libremkchroot b/src/chroot-tools/libremkchroot
index b576209..48b255a 100755
--- a/src/chroot-tools/libremkchroot
+++ b/src/chroot-tools/libremkchroot
@@ -21,44 +21,50 @@
# You should have received a copy of the GNU General Public License
# along with Parabola. If not, see <http://www.gnu.org/licenses/>.
-source /etc/libretools.conf
-
-if [ -e "$XDG_CONFIG_HOME/libretools/libretools.conf" ]; then
- source "$XDG_CONFIG_HOME/libretools/libretools.conf"
-fi
+. /etc/libretools.conf
cmd=${0##*/}
-function usage {
- echo "Usage: $cmd [OPTIONS]"
+
+usage() {
+ echo "Usage: $cmd [OPTIONS] [CHROOT]"
echo 'This script will create a chroot to build packages in.'
echo "Use \`librechroot' to interact with the chroot after it is created."
echo ''
+ echo "The default CHROOT is \`${CHROOT}'."
+ echo ''
echo 'Options:'
echo ' -h Show this message'
echo ''
- echo ' -f Force overwrite of files in the working-dir'
- echo ''
echo ' -d <chrootdir> Use this dir instead of "$CHROOTDIR".'
- echo " -c <pacmandir> Location of pacman cache. Default: \`/var/cache/pacman/pkg'."
echo ' -C <file> Location of pacman config file.'
echo ' -M <file> Location of makepkg config file.'
}
-mkchroot_args=();
-while getopts 'hfd:c:C:M:' arg; do
- case "$arg" in
- h) usage; exit 0 ;;
- f) mkchroot_args+=("-$arg");;
- c|C|M) mkchroot_args+=("-$arg" "$OPTARG");;
- d) CHROOTDIR=$OPTARG ;;
- ?) usage; exit 1 ;;
+main() {
+ mkarchroot_args=();
+ while getopts 'hfd:C:M:' arg; do
+ case "$arg" in
+ C|M) mkarchroot_args+=("-$arg" "$OPTARG");;
+ d) CHROOTDIR=$OPTARG;;
+
+ h) usage; exit 0;;
+ *) usage; exit 1;;
+ esac
+ done
+ shift $(($OPTIND - 1))
+ case $# in
+ 0) :;;
+ 1) CHROOT="$1";;
+ *) usage; exit 1;;
esac
-done
-if (( EUID )); then
- error "This script must be run as root"
- exit 1
-fi
+ if (( EUID )); then
+ error "This script must be run as root"
+ exit 1
+ fi
+
+ mkdir -p "${CHROOTDIR}/${CHROOT}"
+ xargs -d'\n' mkarchroot "${mkchroot_args[@]}" "${CHROOTDIR}/${CHROOT}/root" < /etc/libretools.d/cleansystem
+}
-mkdir -p "${CHROOTDIR}"
-xargs -d'\n' mkarchroot "${mkchroot_args[@]}" "${CHROOTDIR}/root" < /etc/libretools.d/cleansystem
+main "$@"