From de192642ea009e9b8e16f54209575536538869e2 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 16:29:07 -0500 Subject: touch up libremessages --- src/libremessages | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libremessages b/src/libremessages index 68badb8..756e19a 100755 --- a/src/libremessages +++ b/src/libremessages @@ -1,3 +1,4 @@ +#!/bin/bash # Copyright (c) 2006-2010 Pacman Development Team # Copyright (c) 2002-2006 by Judd Vinet # Copyright (c) 2005 by Aurelien Foret @@ -105,3 +106,10 @@ in_array() { return 1 # Not Found } + +if [[ "${0##*/}" = libremessages ]]; then + _libremessages_cmd=$1 + shift + "$_libremessages_cmd" "$@" + unset _libremessages_cmd +fi -- cgit v1.2.2 From a7158a6772f830ae8b40430e3c974356384eb3a4 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 16:43:36 -0500 Subject: libretools.conf: clean up .ssh/config recomendation --- src/libretools.conf | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/src/libretools.conf b/src/libretools.conf index 8032397..d310776 100644 --- a/src/libretools.conf +++ b/src/libretools.conf @@ -33,6 +33,13 @@ CACHEDIR=`grep "^#\?CacheDir" /etc/pacman.conf | cut -d'=' -f2` ## Parabola hostname (should be the same used on ssh_config PARABOLAHOST=parabola +## Assumes something similar in your .ssh/config: + +## Repo server +# Host parabola +# Port 1863 +# HostName repo.parabolagnulinux.org +# User repo ## Server destination of libre packages # Don't change unless you know what you're doing and you won't screw @@ -96,27 +103,3 @@ source /usr/bin/libremessages ## These are architecture specific files. ## Uncomment them if you installed libretools-mips64el # source /etc/libretools.d/mips64el.conf - -## Recommended SSH Config follows -# SSH host, it's better if you have it configured on ~/.ssh/config -# with ControlMaster auto (and a shell opened somewhere else) -# -# Example: -# Host * -# Protocol 2 -# ControlMaster auto -# ControlPath /tmp/ssh-%r@%h:%p -# -## Repo server -# Host parabola -# Port 22 -# HostName repo.parabolagnulinux.org -# User parabolavnx -# IdentityFile ~/.ssh/id_rsa -# -## Git server -# Host vparabola -# Port 1863 -# HostName parabolagnulinux.org -# User parabola -# IdentityFile ~/.ssh/id_rsa -- cgit v1.2.2 From 53da04831f410d86412361564b1018e9c72e4b66 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 16:54:55 -0500 Subject: libretools.conf: improve the "code" section at the end * verify that XDG_CONFIG_HOME is set; if not, then set it * warn about all unconfigured variables, not just the first one * source the user-specific libretools.conf, if it exists --- src/libretools.conf | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/libretools.conf b/src/libretools.conf index d310776..cc8a8f1 100644 --- a/src/libretools.conf +++ b/src/libretools.conf @@ -84,22 +84,36 @@ TORUPATH=/var/lib/libretools/toru #SIGEXT=".sig" #SIGID="0xYOURID" -# Checks if vars aren't empty - +################################################################################ +# This probably shouldn't be in a .conf file... # +################################################################################ + +if [[ -z $XDG_CONFIG_HOME ]]; then + if [[ -n $SUDO_USER ]]; then + SUDO_HOME="$(eval echo ~$SUDO_USER)" + export XDG_CONFIG_HOME="${SUDO_HOME}/.config" + unset SUDO_HOME + else + export XDG_CONFIG_HOME="${HOME}/.config" + fi +fi +if [[ -e "$XDG_CONFIG_HOME/libretools/libretools.conf" ]]; then + . "$XDG_CONFIG_HOME/libretools/libretools.conf" +fi + +ret=0 for VAR in CHROOTDIR CHROOT CACHEDIR PARABOLAHOST LIBREDESTDIR \ - BLACKLIST WORKDIR REPOS ARCHES ABSLIBREGIT \ - COMMITCMD DIFFTOOL FULLBUILDCMD; do - - ret=0 - [[ -z ${!VAR} ]] && { - echo "Configure $VAR var in /etc/libretools.conf" - ret=1 - } - [ $ret -ne 0 ] && exit 1 -done + BLACKLIST WORKDIR REPOS ARCHES ABSLIBREGIT \ + COMMITCMD DIFFTOOL FULLBUILDCMD; do -source /usr/bin/libremessages + if [[ -z ${!VAR} ]]; then + echo "Configure $VAR var in /etc/libretools.conf" + ret=1 + fi +done +if [[ $ret != 0 ]]; then + exit 1 +fi +unset ret -## These are architecture specific files. -## Uncomment them if you installed libretools-mips64el -# source /etc/libretools.d/mips64el.conf +. /usr/bin/libremessages -- cgit v1.2.2 From 803ec5f8b5f1450d0ecd6f52463bd3882f03c05c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 16:57:01 -0500 Subject: libretools.conf: remove CACHEDIR (grep confirms it is unused) --- src/libretools.conf | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libretools.conf b/src/libretools.conf index cc8a8f1..01c93e6 100644 --- a/src/libretools.conf +++ b/src/libretools.conf @@ -28,9 +28,6 @@ CHROOTEXTRAPKG=(distcc ccache tsocks tokyocabinet) # CHROOT=$SUDO_USER # CHROOT=root -## Obtains CacheDir from pacman.conf -CACHEDIR=`grep "^#\?CacheDir" /etc/pacman.conf | cut -d'=' -f2` - ## Parabola hostname (should be the same used on ssh_config PARABOLAHOST=parabola ## Assumes something similar in your .ssh/config: @@ -102,7 +99,7 @@ if [[ -e "$XDG_CONFIG_HOME/libretools/libretools.conf" ]]; then fi ret=0 -for VAR in CHROOTDIR CHROOT CACHEDIR PARABOLAHOST LIBREDESTDIR \ +for VAR in CHROOTDIR CHROOT PARABOLAHOST LIBREDESTDIR \ BLACKLIST WORKDIR REPOS ARCHES ABSLIBREGIT \ COMMITCMD DIFFTOOL FULLBUILDCMD; do -- cgit v1.2.2 From a5f4fb2d351c2972daa6bffad4e74e0a49f5760b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 17:04:51 -0500 Subject: libretools.conf: add [prc] and [java] to REPOS --- src/libretools.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libretools.conf b/src/libretools.conf index 01c93e6..e62dd90 100644 --- a/src/libretools.conf +++ b/src/libretools.conf @@ -12,7 +12,7 @@ WORKDIR=/home/$USER/packages # inverted order of precedence. Put testing repos first so fullpkg find new # PKGBUILDs first, for instance. Toru-path uses reverse order to enforce repo # precedence on the path cache (the last path added replaces the rest) -REPOS=('core' 'libre' 'extra' 'community' 'libre-testing' 'social' 'sugar') +REPOS=('core' 'libre' 'extra' 'community' 'libre-testing' 'social' 'sugar' 'pcr' 'java') # The architectures ARCHES=('i686' 'x86_64' 'mips64el' 'any') -- cgit v1.2.2 From f607063e49984bfd5286001699ff101f0bf3663b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 17:05:37 -0500 Subject: libretools.conf: autodetect DIFFTOOL --- src/libretools.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libretools.conf b/src/libretools.conf index e62dd90..75d47fe 100644 --- a/src/libretools.conf +++ b/src/libretools.conf @@ -2,7 +2,7 @@ BLACKLIST=http://repo.parabolagnulinux.org/docs/blacklist.txt # Diff tool (vimdiff, gvimdiff, meld, etc) -DIFFTOOL=vimdiff +DIFFTOOL=`which vimdiff gvimdiff meld colordiff 2>/dev/null|sed 's/\s.*//'` # The dir where you work on WORKDIR=/home/$USER/packages -- cgit v1.2.2 From 96ae7c177a39d09e5c1cd0116d7199259a20f239 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 17:06:09 -0500 Subject: libretools.conf: add a shebang to help editors out --- src/libretools.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libretools.conf b/src/libretools.conf index 75d47fe..f3e327a 100644 --- a/src/libretools.conf +++ b/src/libretools.conf @@ -1,3 +1,5 @@ +#!/bin/bash + ## Blacklist URL BLACKLIST=http://repo.parabolagnulinux.org/docs/blacklist.txt -- cgit v1.2.2 From 7d455f70d317d36693e2d3d194b2bed299ad194e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 17:06:54 -0500 Subject: libretools.conf: set COMMITCMD=git by default --- src/libretools.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libretools.conf b/src/libretools.conf index f3e327a..4a69998 100644 --- a/src/libretools.conf +++ b/src/libretools.conf @@ -51,7 +51,7 @@ ABSLIBREGIT=http://projects.parabolagnulinux.org/abslibre.git ## Commit Command ## Should be git or hg ## Uncomment only one of those -#COMMITCMD=git +COMMITCMD=git #COMMITCMD=hg ## Uncomment one of those or make one of your choice -- cgit v1.2.2 From 027db84b180a16a17a9414a88e7a35a7669983fa Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 17:10:23 -0500 Subject: libretools.conf: clean up CHROOT* settings: * CHROOTEXTRAPKG: add libretools, remove tokyocabinet (dep of libretools) * CHROOT=default new devtools does NOT like 'root' --- src/libretools.conf | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/libretools.conf b/src/libretools.conf index 4a69998..70d2eca 100644 --- a/src/libretools.conf +++ b/src/libretools.conf @@ -21,14 +21,11 @@ ARCHES=('i686' 'x86_64' 'mips64el' 'any') ## The directory where the chroots are stored CHROOTDIR=/home/chroot -# Extra packages to have installed on the chroot (besides base base-devel and sudo) -CHROOTEXTRAPKG=(distcc ccache tsocks tokyocabinet) - -## The working chroot -## A chroot is useful to build packages isolated from the current system and avoid -## unwanted (as in not in dependencies) automatic library linking -# CHROOT=$SUDO_USER -# CHROOT=root +## Extra packages to have installed on the chroot (besides base base-devel and sudo) +CHROOTEXTRAPKG=(distcc ccache tsocks libretools) +## The meaning of this changes based on the version of libretools+devtools +## do NOT set it to 'root' +CHROOT=default ## Parabola hostname (should be the same used on ssh_config PARABOLAHOST=parabola -- cgit v1.2.2 From 487602793c43a5858b734fde4bbb8d0fdb80e96b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 17:18:14 -0500 Subject: libretools.conf: organize into sections --- src/libretools.conf | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/src/libretools.conf b/src/libretools.conf index 70d2eca..631ca89 100644 --- a/src/libretools.conf +++ b/src/libretools.conf @@ -1,24 +1,33 @@ #!/bin/bash +################################################################################ +# misc # +################################################################################ + ## Blacklist URL +## Used by `pkgbuild-check-nonfree` BLACKLIST=http://repo.parabolagnulinux.org/docs/blacklist.txt -# Diff tool (vimdiff, gvimdiff, meld, etc) +## Diff tool (vimdiff, gvimdiff, meld, etc) +## Used by `aur`, `diff-unfree` DIFFTOOL=`which vimdiff gvimdiff meld colordiff 2>/dev/null|sed 's/\s.*//'` -# The dir where you work on -WORKDIR=/home/$USER/packages -# The repos you'll be packaging for -# +## The repos you'll be packaging for +## Used by `toru`, `createworkdir`, `prfullpkg` # Tip: As early repos take precedence on $REPOS loops, you can use this as # inverted order of precedence. Put testing repos first so fullpkg find new # PKGBUILDs first, for instance. Toru-path uses reverse order to enforce repo # precedence on the path cache (the last path added replaces the rest) REPOS=('core' 'libre' 'extra' 'community' 'libre-testing' 'social' 'sugar' 'pcr' 'java') -# The architectures +## The architectures +## Used by `librestage` ARCHES=('i686' 'x86_64' 'mips64el' 'any') +################################################################################ +# chroot # +################################################################################ + ## The directory where the chroots are stored CHROOTDIR=/home/chroot ## Extra packages to have installed on the chroot (besides base base-devel and sudo) @@ -27,7 +36,19 @@ CHROOTEXTRAPKG=(distcc ccache tsocks libretools) ## do NOT set it to 'root' CHROOT=default -## Parabola hostname (should be the same used on ssh_config +################################################################################ +# abslibre # +################################################################################ + +# The dir where you work on +WORKDIR=/home/$USER/packages + +## Package signing +# Leave commented to disable signing +#SIGEXT=".sig" +#SIGID="0xYOURID" + +## Parabola hostname PARABOLAHOST=parabola ## Assumes something similar in your .ssh/config: @@ -51,6 +72,10 @@ ABSLIBREGIT=http://projects.parabolagnulinux.org/abslibre.git COMMITCMD=git #COMMITCMD=hg +################################################################################ +# fullpkg # +################################################################################ + ## Uncomment one of those or make one of your choice # Normal fullpkg FULLBUILDCMD="sudo libremakepkg -cuN" @@ -71,15 +96,13 @@ HOOKPRERELEASE="ssh -fN parabola" # succesfully # HOOKLOCALRELEASE="" -## Toru +################################################################################ +# toru # +################################################################################ + # Section for toru's vars TORUPATH=/var/lib/libretools/toru -## Package signing -# Leave commented to disable signing -#SIGEXT=".sig" -#SIGID="0xYOURID" - ################################################################################ # This probably shouldn't be in a .conf file... # ################################################################################ -- cgit v1.2.2 From 16e41597e98333f6383a3cb9aa6e9371f64522bf Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 17:32:40 -0500 Subject: 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 --- src/chroot-tools/buildenv | 28 ------ src/chroot-tools/librechroot | 160 ++++++++++++++++++--------------- src/chroot-tools/libremakepkg | 195 ++++++++++++++++++++++------------------- src/chroot-tools/libremkchroot | 56 ++++++------ 4 files changed, 222 insertions(+), 217 deletions(-) delete mode 100755 src/chroot-tools/buildenv 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 . -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 : use 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 Use this dir instead of \`${CHROOTDIR}'" + echo ' -l 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 . +. /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 : use this dir instead of "$CHROOTDIR"' - echo ' -n : 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 Use this dir instead of \`$CHROOTDIR'" + echo " -n Use this chroot instead of \`$CHROOT'" + echo ' -l 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 . -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 Use this dir instead of "$CHROOTDIR".' - echo " -c Location of pacman cache. Default: \`/var/cache/pacman/pkg'." echo ' -C Location of pacman config file.' echo ' -M 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 "$@" -- cgit v1.2.2 From 749e8295844160ba96f0a67cab1a0799a5a81a24 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 18:54:52 -0500 Subject: libremakepkg: touch up brackets --- src/chroot-tools/libremakepkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg index 69e8998..a146627 100755 --- a/src/chroot-tools/libremakepkg +++ b/src/chroot-tools/libremakepkg @@ -130,7 +130,7 @@ main() { unset CLEANFIRST UPDATEFIRST librechroot_args - makechrootpkg "${makechrootpkg_args[@]}" -d -r "$CHROOTDIR/${CHROOT}" -l "$CHROOTCOPY" + makechrootpkg "${makechrootpkg_args[@]}" -d -r "$CHROOTDIR/$CHROOT" -l "$CHROOTCOPY" ev=$? # exit value copy_log exit $ev -- cgit v1.2.2 From 8398652c850196d05e6ad9120d93993bebd6e918 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 18:55:23 -0500 Subject: libremkchroot: don't use cleansystem --- src/chroot-tools/libremkchroot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chroot-tools/libremkchroot b/src/chroot-tools/libremkchroot index 48b255a..cc5b431 100755 --- a/src/chroot-tools/libremkchroot +++ b/src/chroot-tools/libremkchroot @@ -64,7 +64,7 @@ main() { fi mkdir -p "${CHROOTDIR}/${CHROOT}" - xargs -d'\n' mkarchroot "${mkchroot_args[@]}" "${CHROOTDIR}/${CHROOT}/root" < /etc/libretools.d/cleansystem + mkarchroot "${mkchroot_args[@]}" "${CHROOTDIR}/${CHROOT}/root" base base-devel sudo "${CHROOTEXTRAPKG[@]}" } main "$@" -- cgit v1.2.2 From e5c5ec7c6bf8d0460b870b1dacc5c928326fb81b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 18:56:53 -0500 Subject: librechroot: learn how to sync copies with root --- src/chroot-tools/librechroot | 119 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 101 insertions(+), 18 deletions(-) diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index d53448a..1c9700c 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -27,35 +27,107 @@ cmd=${0##*/} -clean_chroot() { # Clean packages with pacman - msg "Cleaning chroot with pacman: ${chroot_path}" +lock_open_write() { + local fd=$1 + local path=$2 + local msg=$3 + + # Only reopen the FD if it wasn't handed to us + if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then + exec $fd>"${path}.lock" + fi + + if ! flock -n $fd; then + stat_busy "$msg" + flock $fd + stat_done + fi +} + +lock_open_read() { + local fd=$1 + local path=$2 + local msg=$3 + + # Only reopen the FD if it wasn't handed to us + if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then + exec $fd>"${path}.lock" + fi - cp -a "$(dirname $0)/chcleanup" "${chroot_path}/clean" - mkarchroot -r "cd /build; /clean" "${chroot_path}" + if ! flock -sn $fd; then + stat_busy "$msg" + flock -s $fd + stat_done + fi +} - #mkarchroot "${chroot_path}" base base-devel sudo "${CHROOTEXTRAPKG[@]}" +lock_close() { + local fd=$1 + exec $fd>&- +} + +clean_pacman() { + msg "Cleaning chroot with pacman: ${copydir}" + + cp -a "$(dirname $0)/chcleanup" "${copydir}/clean" + mkarchroot -r "cd /build; /clean" "${copydir}" + + #mkarchroot "${copydir}" base base-devel sudo "${CHROOTEXTRAPKG[@]}" } clean_repo() { - msg "Cleaning repo for chroot: ${chroot_path}" + msg "Cleaning repo for chroot: ${copydir}" + + if [ -d "${copydir}/repo" ]; then + find "${copydir}/repo/" -mindepth 1 -delete + else + mkdir -p "${copydir}/repo" + fi + bsdtar -czf "${copydir}/repo/repo.db.tar.gz" -T /dev/null + ln -s "repo.db.tar.gz" "${copydir}/repo/repo.db" +} + +## +# This function is almost verbatim from makechrootpkg +## +sync() { + if [[ $CHROOTCOPY = root ]]; then + error "Cannot sync the root copy with itself" + exit 1 + fi + + # Note that '9' is the same FD number as in mkarchroot + lock_open_write 9 "$copydir" "Locking chroot copy '$copy'" + lock_open_read 8 "$rootdir" "Locking clean chroot" - if [ -d "${chroot_path}/repo" ]; then - find "${chroot_path}/repo/" -mindepth 1 -delete + stat_busy 'Creating clean working copy' + local use_rsync=false + if type -P btrfs >/dev/null; then + [[ -d $copydir ]] && btrfs subvolume delete "$copydir" &>/dev/null + btrfs subvolume snapshot "$chrootdir/root" "$copydir" &>/dev/null || + use_rsync=true else - mkdir -p "${chroot_path}/repo" + use_rsync=true fi - bsdtar -czf "${chroot_path}/repo/repo.db.tar.gz" -T /dev/null - ln -s "repo.db.tar.gz" "${chroot_path}/repo/repo.db" + + if $use_rsync; then + mkdir -p "$copydir" + rsync -a --delete -q -W -x "$CHROOTDIR/$CHROOT/root/" "$copydir" + fi + stat_done + + lock_close 8 + lock_close 9 } update() { - msg "Updating chroot: ${chroot_path}" - mkarchroot -u "${chroot_path}" + msg "Updating chroot: ${copydir}" + mkarchroot -u "${copydir}" } enter() { - msg "Entering chroot: ${chroot_path}" - mkarchroot -r "bash" "${chroot_path}" + msg "Entering chroot: ${copydir}" + mkarchroot -r "bash" "${copydir}" } usage() { @@ -72,6 +144,7 @@ usage() { echo ' Modes:' echo ' -h Show this message' echo ' -c Clean the chroot using pacman' + echo " -C Clean the chroot by syncing it with 'root' copy" echo ' -r Clean /repo in the chroot' echo ' -u Update the chroot' } @@ -88,7 +161,8 @@ main() { d) CHROOTDIR=$OPTARG;; l) CHROOTCOPY=$OPTARG;; - c) mode=clean_chroot;; + c) mode=clean_pacman;; + C) mode=sync;; r) mode=clean_repo;; u) mode=update;; @@ -104,15 +178,24 @@ main() { esac # not local - chroot_path="${CHROOTDIR}/${CHROOT}/${CHROOTCOPY}" + rootdir="${CHROOTDIR}/${CHROOT}/root" + copydir="${CHROOTDIR}/${CHROOT}/${CHROOTCOPY}" if (( EUID )); then error "This script must be run as root." exit 1 fi + if [[ ! -d $rootdir ]]; then + libremkchroot -d "$CHROOTDIR" "$CHROOT" + fi + + if [[ ! -d $copydir ]] && [[ $mode != sync ]]; then + sync + fi + case "$mode" in - clean_chroot) clean_chroot; exit $?;; + clean_pacman) clean_pacman; exit $?;; clean_repo) clean_repo; exit $?;; update) update; exit $?;; enter) enter; exit $?;; -- cgit v1.2.2 From ec88851b92ead25bfdd1e29046c95e7dd4508f3f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 21:45:39 -0500 Subject: I'm embarrassed; I commited non-working file lock code --- src/chroot-tools/librechroot | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index 1c9700c..2c952cc 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -34,7 +34,7 @@ lock_open_write() { # Only reopen the FD if it wasn't handed to us if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then - exec $fd>"${path}.lock" + eval "exec $fd>${path}.lock" fi if ! flock -n $fd; then @@ -51,7 +51,7 @@ lock_open_read() { # Only reopen the FD if it wasn't handed to us if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then - exec $fd>"${path}.lock" + eval "exec $fd>${path}.lock" fi if ! flock -sn $fd; then @@ -63,7 +63,7 @@ lock_open_read() { lock_close() { local fd=$1 - exec $fd>&- + eval "exec $fd>&-" } clean_pacman() { -- cgit v1.2.2 From 80125fc674b087b42791d2bd48a74bfa7edb2fe0 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 23:36:28 -0500 Subject: librechroot: fix a bug in clean_pacman --- src/chroot-tools/librechroot | 1 + 1 file changed, 1 insertion(+) diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index 2c952cc..07360d7 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -70,6 +70,7 @@ clean_pacman() { msg "Cleaning chroot with pacman: ${copydir}" cp -a "$(dirname $0)/chcleanup" "${copydir}/clean" + mkdir -p "$copydir/build" mkarchroot -r "cd /build; /clean" "${copydir}" #mkarchroot "${copydir}" base base-devel sudo "${CHROOTEXTRAPKG[@]}" -- cgit v1.2.2 From e17b270bbfa29160beb34266533f5b2e2120041f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 12 Nov 2012 23:37:29 -0500 Subject: librechroot: keep a lock on the CHROOTCOPY the whole time --- src/chroot-tools/librechroot | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index 07360d7..a5c5728 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -97,8 +97,6 @@ sync() { exit 1 fi - # Note that '9' is the same FD number as in mkarchroot - lock_open_write 9 "$copydir" "Locking chroot copy '$copy'" lock_open_read 8 "$rootdir" "Locking clean chroot" stat_busy 'Creating clean working copy' @@ -118,7 +116,6 @@ sync() { stat_done lock_close 8 - lock_close 9 } update() { @@ -187,6 +184,10 @@ main() { exit 1 fi + # Keep this lock as long as we are running + # Note that '9' is the same FD number as in mkarchroot + lock_open_write 9 "$copydir" "Locking chroot copy '$copy'" + if [[ ! -d $rootdir ]]; then libremkchroot -d "$CHROOTDIR" "$CHROOT" fi -- cgit v1.2.2 From a7d0da3e7fd7009c28e09f73c32f0a355819f2e6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 13 Nov 2012 00:07:15 -0500 Subject: libremakepkg: fix copy_log --- src/chroot-tools/libremakepkg | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg index a146627..3fa2f3d 100755 --- a/src/chroot-tools/libremakepkg +++ b/src/chroot-tools/libremakepkg @@ -29,7 +29,7 @@ # copy logs if they exist ## copy_log() { - find "${chroot_path}/build/" -maxdepth 1 -name "*\.log" -exec cp {} ./ \; + find "${copydir}/build/" -maxdepth 1 -name "*\.log" -exec cp {} ./ \; } ## @@ -89,6 +89,10 @@ main() { # Pass all arguments after -- right to makechrootpkg makechrootpkg_args+=("$@") + # not local + rootdir="${CHROOTDIR}/${CHROOT}/root" + copydir="${CHROOTDIR}/${CHROOT}/${CHROOTCOPY}" + if (( EUID )); then error "This script must be run as root" exit 1 -- cgit v1.2.2 From c611090157e9c7d04e6f411c0c5f9ca5834835fd Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 13 Nov 2012 00:43:41 -0500 Subject: pkgbuild-check-nonfree: fix a few errors, clean up This includes the notorious command-not-found error triggered in libremakepkg --- src/pkgbuild-check-nonfree | 139 +++++++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 80 deletions(-) diff --git a/src/pkgbuild-check-nonfree b/src/pkgbuild-check-nonfree index df0ff36..fba4b7b 100755 --- a/src/pkgbuild-check-nonfree +++ b/src/pkgbuild-check-nonfree @@ -1,6 +1,7 @@ #!/bin/bash # pkgbuild-check-nonfree # Copyright 2010 Joshua Ismael Haase Hernández, Joseph Graham +# Copyright 2012 Luke Shumaker # ---------- GNU General Public License 3 ---------- @@ -19,15 +20,20 @@ # You should have received a copy of the GNU General Public License # along with Parabola. If not, see . -# function log_end { +. /etc/libretools.conf + +cmd=${0##*/} +ev=0 + +# log_end() { # kill "$teepid" # rm "$logpipe" # } -# function log { -# LOG="pkgbuild-check-nonfree-$(date -u +%Y%m%d).log" +# log() { +# local LOG="pkgbuild-check-nonfree-$(date -u +%Y%m%d).log" # # ensure overridden package variables survive tee with split packages -# logpipe="$(mktemp -u "$startdir/logpipe.XXXXXXXX")" +# logpipe="$(mktemp)" # mkfifo "$logpipe" # tee "$LOG" < "$logpipe" & # teepid=$! @@ -35,18 +41,15 @@ # } -function unset_pkgbuild { - +unset_pkgbuild() { unset 'pkgbase' 'pkgname' 'pkgver' 'pkgrel' 'epoch' 'pkgdesc' \ 'arch' 'url' 'license' 'groups' 'optdepends' 'provides' \ 'conflicts' 'replaces' 'backup' 'options' 'install' \ 'changelog' 'source' 'noextract' 'md5sums' 'build' \ 'check' 'package' 'depends' 'makedepends' 'checkdepends' - } -function assert_pkgbuild { - +assert_pkgbuild() { if [ -e "$1" ]; then source "$1" @@ -60,16 +63,15 @@ function assert_pkgbuild { return 1 } -function check_replacement { - +check_replacement() { [ $2 ] || return 0 # Free (not found) local needle=$1; shift local item local rep for line in $@; do - item="$(echo "$line" | cut -d':' -f1)" - rep="$(echo "$line" | cut -s -d':' -f2)" + local item="$(echo "$line" | cut -d':' -f1)" + local rep="$(echo "$line" | cut -s -d':' -f2)" if [ "$item" == "$needle" ]; then if [ -z "$rep" ]; then @@ -84,8 +86,11 @@ function check_replacement { return 0 # Free (not found) } -function get_blacklist { # Download the blacklist. - +## +# Download the blacklist. +## +get_blacklist() { + mkdir -p "$XDG_CONFIG_HOME/libretools" pushd "$XDG_CONFIG_HOME/libretools" >/dev/null msg "Downloading the blacklist of proprietary software packages." @@ -103,103 +108,77 @@ function get_blacklist { # Download the blacklist. popd > /dev/null } -function check_deps { # Check wheter a package depends on non-free - +## +# Check wheter a package depends on non-free +## +check_deps() { unset_pkgbuild - if ! assert_pkgbuild "$1"; then - return 1 # not PKGBUILD + exit 1 # not PKGBUILD fi msg2 "${pkgbase:-${pkgname[0]}} $pkgver $pkgrel ${epoch:-""}" # > "$logpipe" - for pkg in ${pkgname[@]} ${depends[@]} ${makedepends[@]} ${checkdepends[@]}; do + for pkg in "${pkgname[@]}" "${depends[@]}" "${makedepends[@]}" "${checkdepends[@]}"; do - lines=($(grep "$pkg" "$XDG_CONFIG_HOME/libretools/blacklist.txt" | tr " " "_")) + local lines=($(grep "$pkg" "$XDG_CONFIG_HOME/libretools/blacklist.txt" | tr " " "_")) - rep="$(check_replacement $pkg ${lines[@]})" - freedom=$? + local rep="$(check_replacement $pkg ${lines[@]})" + local freedom=$? - if [ "$freedom" -eq 15 ]; then + if [[ $freedom = 15 ]]; then warning "found $pkg" # > "$logpipe" ev=15 - continue - elif [ -n "$rep" ]; then - if [ "$rep" = "$pkg" ]; then plain "$pkg is repackaged with the same name." # > "$logpipe" - continue else plain "$pkg -> $rep" # > "$logpipe" - continue fi - fi - done - } -function usage { +usage() { # TODO: implement PKGBUILD arguments + echo "Usage: $cmd [OPTIONS] [PKGBUILD1 PKGBUILD2 ...]" echo "" - echo "$(basename $0) [options] [PKGBUILD1 PKGBUILD2 ...]" - echo "" - echo "OPTIONS" + echo "If no PKGBUILD is specified, \`./PKGBUILD' is implied" echo "" - echo " -h : this message" - echo "" - echo "If no PKGBUILD is specified, one is searched on current directory" - - exit 1 + echo "Options:" + echo " -h Show this message" } -while getopts 'h' arg; do - case "$arg" in - h) usage ;; - esac -done - -if [ -w / ]; then - error "Run as normal user" -fi - -source /etc/libretools.conf -if [ -e "$XDG_CONFIG_HOME/libretools/libretools.conf" ]; then - source "$XDG_CONFIG_HOME/libretools/libretools.conf" -fi - -if [ -z "${BLACKLIST}" ]; then - error "BLACKLIST variable is not set your libretools.conf file" - exit 1 -fi - -if [ ! -d "$XDG_CONFIG_HOME/libretools" ]; then - mkdir -p "$XDG_CONFIG_HOME/libretools" -fi - -startdir=`pwd` - -get_blacklist -# log +main() { + while getopts 'fh' arg; do + case "$arg" in + h) usage; exit 0;; + *) usage; exit 1;; + esac + done + shift $(($OPTIND - 1)) + pkgbuilds=("$@") + if [[ $# < 1 ]]; then + pkgbuilds=("`pwd`/PKGBUILD") + fi -shift $(( OPTIND - 1)) + if [[ -w / ]]; then + error "Run as normal user" + exit 1 + fi -msg "Looking for unfree dependencies" + get_blacklist + # log -if [ $# -ge 1 ]; then + msg "Looking for unfree dependencies" - for p in $@; do - if [ -n "$p" ]; then + for p in "${pkgbuilds[@]}"; do + if [[ -n "$p" ]]; then check_deps "$p" fi done -else - - check_deps "`pwd`/PKGBUILD" - -fi + return $ev +} -exit $ev +main "$@" -- cgit v1.2.2 From 444cc22bc5cda7a4adc26982d3edbcfd1af426ed Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 13 Nov 2012 00:44:38 -0500 Subject: add an '-f' flag to pkgbuild-check-nonfree to let libremakepkg run as root --- src/chroot-tools/libremakepkg | 2 +- src/pkgbuild-check-nonfree | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg index 3fa2f3d..4593121 100755 --- a/src/chroot-tools/libremakepkg +++ b/src/chroot-tools/libremakepkg @@ -113,7 +113,7 @@ main() { if $CHECKNONFREE; then msg "Checking PKGBUILD for non-free issues" - if ! pkgbuild-check-nonfree; then + if ! pkgbuild-check-nonfree -f; then if [[ $? -eq 15 ]]; then # other errors mean fail, not nonfree error "PKGBUILD contains non-free issues" diff --git a/src/pkgbuild-check-nonfree b/src/pkgbuild-check-nonfree index fba4b7b..0fd480c 100755 --- a/src/pkgbuild-check-nonfree +++ b/src/pkgbuild-check-nonfree @@ -146,12 +146,15 @@ usage() { echo "If no PKGBUILD is specified, \`./PKGBUILD' is implied" echo "" echo "Options:" + echo " -f Allow running as root user" echo " -h Show this message" } main() { + local asroot=false while getopts 'fh' arg; do case "$arg" in + f) asroot=true;; h) usage; exit 0;; *) usage; exit 1;; esac @@ -162,7 +165,7 @@ main() { pkgbuilds=("`pwd`/PKGBUILD") fi - if [[ -w / ]]; then + if [[ -w / ]] && ! $asroot; then error "Run as normal user" exit 1 fi -- cgit v1.2.2 From a07049cd10c57d0df4497e389dd5b08631a10049 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 13 Nov 2012 00:47:49 -0500 Subject: aur: use bash builtins instead of sed --- src/aur | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aur b/src/aur index 24d4317..f90a776 100755 --- a/src/aur +++ b/src/aur @@ -56,7 +56,7 @@ for _pkg in ${@}; do fi msg "Downloading $_pkg..." - wget -O - -q https://aur.archlinux.org/packages/$(echo $_pkg | sed "s/^../&\/&/")/$_pkg.tar.gz | \ + wget -O - -q https://aur.archlinux.org/packages/${_pkg:0:2}/${_pkg}/$_pkg.tar.gz | \ tar xzf - >/dev/null 2>&1 if [ $? -ne 0 ]; then -- cgit v1.2.2 From 27d4291f8404cfa8992492211df6ed7042f6036e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 13 Nov 2012 12:28:21 -0500 Subject: rm src/update-cleansystem --- src/update-cleansystem | 68 -------------------------------------------------- 1 file changed, 68 deletions(-) delete mode 100755 src/update-cleansystem diff --git a/src/update-cleansystem b/src/update-cleansystem deleted file mode 100755 index 6bec742..0000000 --- a/src/update-cleansystem +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash -# Updates the cleansystem file -# Creates a fake Parabola root and writes to cleansystem all -# packages installable from base and base-devel plus extras. - -set -e -# Copyright 2012 Nicolás Reynolds, Luke Shumaker - -# ---------- GNU General Public License 3 ---------- - -# 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 . - -set -e - -# libretools.conf gives us libremessages -source /etc/libretools.conf - -cleansystem=/etc/libretools.d/cleansystem - -cmd=${0##*/} -usage() { - echo "Usage: $cmd []" - echo " $cmd -h" - echo "Creates a fake Parabola root and writes to \`$cleansystem' all" - echo "packages installable from base and base-devel plus extras." - echo '' - echo 'Options:' - echo ' -h Show this message' -} - -if [ "$1" == '-h' ]; then - usage - exit 0 -fi - -if [ ! -w "$cleansystem" ]; then - error 'This script must be run as root' - exit 1 -fi - -# Maintain a clean database in the system -db_dir="${DB:-/var/lib/libretools/clean}" -[ ! -d "${db_dir}" ] && mkdir -p "${db_dir}" - -# We sync first because updating info gets printed to stdout too -pacman -b "${db_dir}" --config /etc/pacman.conf -Sy 2>/dev/null -pacman -b "${db_dir}" \ - --config /etc/pacman.conf \ - -Sp --print-format "%n" \ - base base-devel sudo $@ | sort > "$cleansystem" - -# Ensures everything's installed -pacman -Sy --needed --noconfirm base base-devel sudo $@ - -exit $? -- cgit v1.2.2 From b72653f654882335026d04de5c25ea02c20e8412 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 13 Nov 2012 14:19:36 -0500 Subject: clean up some misc scripts --- src/diff-unfree | 95 +++++++++++++++++++++++++++++---------------------------- src/is_unfree | 5 +-- src/librediff | 60 ++++++++++++++++-------------------- src/librerepkg | 73 +++++++++++++++++++++----------------------- 4 files changed, 110 insertions(+), 123 deletions(-) diff --git a/src/diff-unfree b/src/diff-unfree index a0a8d63..24ada67 100755 --- a/src/diff-unfree +++ b/src/diff-unfree @@ -20,66 +20,67 @@ # You should have received a copy of the GNU General Public License # along with Parabola. If not, see . -source /etc/libretools.conf -custom_config=$XDG_CONFIG_HOME/libretools/libretools.conf - -[[ "$1" == "--help" ]] && { - msg "Diff-Unfree helps you diff build scripts from ABSLibre against - (Unfree) ABS. Package name and repo will we guessed if you don't - specify them." - msg2 "Usage: $0 [community|packages] [unfree-package] [repo]" - exit 0 -} +. /etc/libretools.conf + +cmd=${0##*/} -[[ ! -r PKGBUILD ]] && { - error "This is not a build dir." - exit 1 +usage() { + echo "Usage: $cmd [community|packages] [unfree-package] [repo]" + echo "Usage: $cmd --help" + echo "Helps you diff build scripts from ABSLibre against (Unfree) ABS." + echo "" + echo "Package name and repo will we guessed if you don't specify them." } -package_guess=$(basename $PWD) +main() { + if [[ "$1" == "--help" ]]; then + usage + exit 0 + fi -repo=${1:-$(basename $(dirname $PWD))} -package=${2:-${package_guess/-libre}} -trunk=${3:-trunk} + local package_guess=${PWD##*/} + local repo=${1:-$(basename ${PWD%/*})} + local package=${2:-${package_guess%-libre}} + local trunk=${3:-trunk} -tmp_dir=$(mktemp -d /tmp/${package}.XXXXXX) + svnrepo="packages" + case $repo in + community*) svnrepo="community";; + multilib*) svnrepo="community";; + *) :;; + esac -svnrepo="packages" -case $repo in - community*) - svnrepo="community" - ;; - multilib*) - svnrepo="community" - ;; - *) - ;; -esac + if [[ ! -r PKGBUILD ]]; then + error "This is not a build dir." + exit 1 + fi -unfree_dir="${tmp_dir}/${svnrepo}/${package}/${trunk}" -[[ ! -d "${tmp_dir}" ]] && { - error "Can't create temp dir" - exit 1 -} + tmp_dir="$(mktemp --tmpdir -d ${package}.XXXXXX)" + if [[ ! -d "${tmp_dir}" ]]; then + error "Can't create temp dir" + exit 1 + fi + unfree_dir="${tmp_dir}/${svnrepo}/${package}/${trunk}" -stdnull 'pushd "${tmp_dir}"' + stdnull 'pushd "${tmp_dir}"' -msg "Getting diff from $repo/$package..." + msg "Getting diff from $repo/$package..." -stdnull 'svn checkout --depth=empty svn://svn.archlinux.org/$svnrepo' + stdnull 'svn checkout --depth=empty svn://svn.archlinux.org/$svnrepo' -cd ${svnrepo} -svn update ${package} + cd ${svnrepo} + svn update ${package} -# Back to start dir -stdnull popd + # Back to start dir + stdnull popd -msg "Diffing files" + msg "Diffing files" -for _file in ${unfree_dir}/*; do - msg2 "$(basename "${_file}")" - ${DIFFTOOL} "$PWD/$(basename "${_file}")" "${_file}" -done + for _file in ${unfree_dir}/*; do + msg2 "$(basename "${_file}")" + ${DIFFTOOL} "$PWD/$(basename "${_file}")" "${_file}" + done +} -exit $? +main "$@" diff --git a/src/is_unfree b/src/is_unfree index f32c193..c2a37c9 100755 --- a/src/is_unfree +++ b/src/is_unfree @@ -1,11 +1,8 @@ #!/bin/bash # Checks if a package is on blacklist -# fail immediately on error -set -E +. /etc/libretools.conf blacklist="$XDG_CONFIG_HOME/libretools/blacklist.txt" - egrep -q "^${1}:" "${blacklist}" - exit $? diff --git a/src/librediff b/src/librediff index 1f39eb9..6dbe41b 100755 --- a/src/librediff +++ b/src/librediff @@ -20,46 +20,38 @@ # You should have received a copy of the GNU General Public License # along with Parabola. If not, see . -usage() { - echo "Usage: $0 [ ...]" - echo "Requirements:" - echo "* Have a / directory with nonfree build scripts inside" - echo "* Have a -libre/ directory with libre build scripts inside" -} +. /etc/libretools.conf -# Load custom config or system-wide config -custom_config=$XDG_CONFIG_HOME/libretools/libretools.conf -if [ -e $custom_config ]; then - source $custom_config -else - source /etc/libretools.conf -fi +cmd=${0##*/} -# Print usage if no package has been given -[[ -z "$@" ]] && { - usage - exit 1 +usage() { + echo "Usage: $cmd [ ...]" + echo "Requirements:" + echo " * Have a / directory with nonfree build scripts inside" + echo " * Have a -libre/ directory with libre build scripts inside" } +main() { + local packages=("$@") + if [[ ${packages[#]} = 0 ]]; then + usage + exit 1 + fi -for package in $@; do -# Continue on errors - [[ ! -d ./${package} || ! -d ./${package}-libre ]] && { - error "no matching ${package} and ${package}-libre found" - continue - } - - [[ ! -f ./${package}/PKGBUILD || ! -f ./${package}-libre/PKGBUILD ]] && { - error "no matching PKGBUILDs found for ${package}-libre" - continue - } + for package in "${packages[@]}"; do + if [[ ! -f ./${package}/PKGBUILD || ! -f ./${package}-libre/PKGBUILD ]] + then + error "Build scripts not found for ${package}(-libre)" + else - source ./${package}-libre/PKGBUILD - [[ -z ${pkgbase} ]] && pkgbase=${pkgname} + . ./${package}-libre/PKGBUILD + [[ -z ${pkgbase} ]] && pkgbase=${pkgname} -# Generate a diff file, no -r since we don't want to patch src/ nor pkg/ - diff -auN ${package} ${package}-libre > $PATCHDIR/${pkgbase}-${pkgver}-${pkgrel}.patch + # Generate a diff file, no -r since we don't want to patch src/ nor pkg/ + diff -auN ${package} ${package}-libre > $PATCHDIR/${pkgbase}-${pkgver}-${pkgrel}.patch + done -done + exit 0 +} -exit 0 +main "$@" diff --git a/src/librerepkg b/src/librerepkg index d506003..85c58d9 100755 --- a/src/librerepkg +++ b/src/librerepkg @@ -18,55 +18,52 @@ # You should have received a copy of the GNU General Public License # along with Parabola. If not, see . -source /etc/libretools.conf -custom_config=$XDG_CONFIG_HOME/libretools/libretools.conf -if [ -x $custom_config ]; then - source $custom_config; - unset $custom_config -fi - -[[ ! -r rePKGBUILD ]] && { - error "This build does not contains a rePKGBUILD." - exit 1 -} +. /etc/libretools.conf +. /etc/makepkg.conf +. /etc/abs.conf -source /etc/makepkg.conf -source /etc/abs.conf -source rePKGBUILD +cmd=${0##*/} usage() { - echo "cd to a dir with a rePKGBUILD and other file info and run" - echo "$0 [makepkg flags]" - echo - echo "This script will repackage an arch package without compiling" + echo "cd to a dir with a rePKGBUILD and other file info and run" + echo "$cmd [makepkg flags]" + echo "" + echo "This script will repackage an arch package without compiling" } -while getopts 'h' arg; do - case $arg in - h) usage; exit 0 ;; - esac -done - -makepkgflags=$@ +main() { + while getopts 'h' arg; do + case $arg in + h) usage; exit 0 ;; + esac + done + makepkgflags=("$@") -tempdir=$(mktemp -d /tmp/$(basename $PWD).XXXXX) + if [[ ! -r rePKGBUILD ]]; then + error "This build does not contains a rePKGBUILD." + exit 1 + fi + . rePKGBUILD -msg "Copying files" -cp ./* ${tempdir}/ + tempdir="$(mktemp --tmpdir -d ${PWD##*/}.XXXXX)" -for _arch in ${arch[@]}; do + msg "Copying files" + cp ./* "${tempdir}/" - msg "Repackaging: $pkgname $pkgver-$pkgrel ($(date -u))" + for _arch in "${arch[@]}"; do + msg "Repackaging: $pkgname $pkgver-$pkgrel ($(date -u))" + stdnull pushd "${tempdir}" - stdnull pushd ${tempdir} + msg2 "Updating md5sums" + makepkg -gp rePKGBUILD >> rePKGBUILD - msg2 "Updating md5sums" - makepkg -gp rePKGBUILD >> rePKGBUILD + echo "export CARCH=${_arch}" >> rePKGBUILD - echo "export CARCH=${_arch}" >> rePKGBUILD + msg "Repackaging using makepkg" + makepkg -Lcdp rePKGBUILD "${makepkgflags[@]}" - msg "Repackaging using makepkg" - makepkg -Lcdp rePKGBUILD ${makepkgflags} + stdnull popd "${tempdir}" + done +} - stdnull popd ${tempdir} -done +main "$@" -- cgit v1.2.2 From 066c7716e69817af9e08782a7fbfc3dc2eb6356b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 26 Nov 2012 01:30:54 -0500 Subject: libremessages: term_title: learn about xterm/rxvt --- src/libremessages | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libremessages b/src/libremessages index 756e19a..ff7476b 100755 --- a/src/libremessages +++ b/src/libremessages @@ -88,9 +88,13 @@ stat_done() { } # Set the terminal title -# TODO test on several terms - it works on screen/tmux term_title() { - printf "\033k%s\033\\" "$@" + local fmt='' + case "$TERM" in + screen|tmux) fmt='\ek%s\e\\';; + xterm*|rxvt*) fmt='\e]0;%s\a';; + esac + printf "$fmt" "$*" } # usage : in_array( $needle, $haystack ) -- cgit v1.2.2 From fd1e5a426713715d9c0e3fabbfe0d8a20b629bad Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 28 Nov 2012 15:18:44 -0500 Subject: chroot-tools: disable overriding CHROOTDIR at the command line --- src/chroot-tools/librechroot | 2 -- src/chroot-tools/libremakepkg | 2 -- src/chroot-tools/libremkchroot | 2 -- 3 files changed, 6 deletions(-) diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index a5c5728..48e6cdc 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -136,7 +136,6 @@ usage() { echo '' echo 'Options:' echo ' Settings:' - echo " -d Use this dir instead of \`${CHROOTDIR}'" echo ' -l Use this as the chroot copy instead of basing it' echo ' on the username' echo ' Modes:' @@ -156,7 +155,6 @@ main() { local mode=enter while getopts 'hrcud:l:' arg; do case $arg in - d) CHROOTDIR=$OPTARG;; l) CHROOTCOPY=$OPTARG;; c) mode=clean_pacman;; diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg index 4593121..faa50be 100755 --- a/src/chroot-tools/libremakepkg +++ b/src/chroot-tools/libremakepkg @@ -53,7 +53,6 @@ usage() { echo ' -u Update the chroot before building' echo ' -N Do not check freedom issues (for fullpkg)' echo '' - echo " -d Use this dir instead of \`$CHROOTDIR'" echo " -n Use this chroot instead of \`$CHROOT'" echo ' -l Use this chroot copy instead of basing it' echo ' on the username' @@ -77,7 +76,6 @@ main() { u) UPDATEFIRST=true;; N) CHECKNONFREE=false;; - d) CHROOTDIR=$OPTARG;; n) CHROOT=$OPTARG;; l) CHROOTCOPY=$OPTARG;; diff --git a/src/chroot-tools/libremkchroot b/src/chroot-tools/libremkchroot index cc5b431..08f69b1 100755 --- a/src/chroot-tools/libremkchroot +++ b/src/chroot-tools/libremkchroot @@ -35,7 +35,6 @@ usage() { echo 'Options:' echo ' -h Show this message' echo '' - echo ' -d Use this dir instead of "$CHROOTDIR".' echo ' -C Location of pacman config file.' echo ' -M Location of makepkg config file.' } @@ -45,7 +44,6 @@ main() { 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;; -- cgit v1.2.2 From 00d67a5051e5d4163acffa80b7ef85f81f7e548f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 28 Nov 2012 15:20:59 -0500 Subject: take (some) advantage of chroottools, fix some compatability things mkarchroot/archroot's option parsing is a little less flexible (but a lot more understandable) than it was before. --- src/chroot-tools/librechroot | 51 +++------------------- src/chroot-tools/libremkchroot | 6 +-- src/libremessages | 96 ++++++++++++++---------------------------- 3 files changed, 39 insertions(+), 114 deletions(-) diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index 48e6cdc..8830c39 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -27,53 +27,12 @@ cmd=${0##*/} -lock_open_write() { - local fd=$1 - local path=$2 - local msg=$3 - - # Only reopen the FD if it wasn't handed to us - if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then - eval "exec $fd>${path}.lock" - fi - - if ! flock -n $fd; then - stat_busy "$msg" - flock $fd - stat_done - fi -} - -lock_open_read() { - local fd=$1 - local path=$2 - local msg=$3 - - # Only reopen the FD if it wasn't handed to us - if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then - eval "exec $fd>${path}.lock" - fi - - if ! flock -sn $fd; then - stat_busy "$msg" - flock -s $fd - stat_done - fi -} - -lock_close() { - local fd=$1 - eval "exec $fd>&-" -} - clean_pacman() { msg "Cleaning chroot with pacman: ${copydir}" cp -a "$(dirname $0)/chcleanup" "${copydir}/clean" mkdir -p "$copydir/build" - mkarchroot -r "cd /build; /clean" "${copydir}" - - #mkarchroot "${copydir}" base base-devel sudo "${CHROOTEXTRAPKG[@]}" + archroot "${copydir}" -r "cd /build; /clean" } clean_repo() { @@ -120,12 +79,12 @@ sync() { update() { msg "Updating chroot: ${copydir}" - mkarchroot -u "${copydir}" + archroot "${copydir}" -u } enter() { msg "Entering chroot: ${copydir}" - mkarchroot -r "bash" "${copydir}" + archroot "${copydir}" -r "bash" } usage() { @@ -183,11 +142,11 @@ main() { fi # Keep this lock as long as we are running - # Note that '9' is the same FD number as in mkarchroot + # Note that '9' is the same FD number as in (mk)archroot lock_open_write 9 "$copydir" "Locking chroot copy '$copy'" if [[ ! -d $rootdir ]]; then - libremkchroot -d "$CHROOTDIR" "$CHROOT" + libremkchroot "$CHROOT" fi if [[ ! -d $copydir ]] && [[ $mode != sync ]]; then diff --git a/src/chroot-tools/libremkchroot b/src/chroot-tools/libremkchroot index 08f69b1..3072b9e 100755 --- a/src/chroot-tools/libremkchroot +++ b/src/chroot-tools/libremkchroot @@ -40,10 +40,10 @@ usage() { } main() { - mkarchroot_args=(); + archroot_args=(); while getopts 'hfd:C:M:' arg; do case "$arg" in - C|M) mkarchroot_args+=("-$arg" "$OPTARG");; + C|M) archroot_args+=("-$arg" "$OPTARG");; h) usage; exit 0;; *) usage; exit 1;; @@ -62,7 +62,7 @@ main() { fi mkdir -p "${CHROOTDIR}/${CHROOT}" - mkarchroot "${mkchroot_args[@]}" "${CHROOTDIR}/${CHROOT}/root" base base-devel sudo "${CHROOTEXTRAPKG[@]}" + archroot "${chroot_args[@]}" "${CHROOTDIR}/${CHROOT}/root" -i base base-devel sudo "${CHROOTEXTRAPKG[@]}" } main "$@" diff --git a/src/libremessages b/src/libremessages index ff7476b..ccb5fb4 100755 --- a/src/libremessages +++ b/src/libremessages @@ -1,11 +1,11 @@ #!/bin/bash -# Copyright (c) 2006-2010 Pacman Development Team # Copyright (c) 2002-2006 by Judd Vinet +# Copyright (c) 2006-2010 Pacman Development Team # Copyright (c) 2005 by Aurelien Foret -# Copyright (c) 2006 by Miklos Vajna # Copyright (c) 2005 by Christian Hamar # Copyright (c) 2006 by Alex Smith # Copyright (c) 2006 by Andras Voroskoi +# Copyright (c) 2006 by Miklos Vajna # Copyright (c) 2011 by Joshua Haase # # This program is free software; you can redistribute it and/or modify @@ -21,70 +21,46 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# gettext initialization -export TEXTDOMAIN='libretools' -export TEXTDOMAINDIR='/usr/share/locale' +################################################################################ +# Inherit most functions from devtools # +################################################################################ -# check if messages are to be printed using color -unset ALL_OFF BOLD BLUE GREEN RED YELLOW -if [[ -t 2 ]]; then - # prefer terminal safe colored and bold text when tput is supported - if tput setaf 0 &>/dev/null; then - ALL_OFF="$(tput sgr0)" - BOLD="$(tput bold)" - PURPLE="${ALL_OFF}$(tput setaf 5)" - BLUE="${BOLD}$(tput setaf 4)" - GREEN="${BOLD}$(tput setaf 2)" - RED="${BOLD}$(tput setaf 1)" - YELLOW="${BOLD}$(tput setaf 3)" - else - ALL_OFF="\e[1;0m" - BOLD="\e[1;1m" - BLUE="${BOLD}\e[1;34m" - GREEN="${BOLD}\e[1;32m" - RED="${BOLD}\e[1;31m" - YELLOW="${BOLD}\e[1;33m" - PURPLE="${BOLD}\033[1;30;40m" - fi -fi -readonly ALL_OFF BOLD BLUE GREEN RED YELLOW PURPLE +# This is only installed in Parabola's distribution of devtools, not Arch's +. /usr/share/devtools/common.sh -stdnull() { - eval "$@ >/dev/null 2>&1" -} +################################################################################ +# gettext initialization # +################################################################################ -plain() { - local mesg=$1; shift - printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} +export TEXTDOMAIN='libretools' +export TEXTDOMAINDIR='/usr/share/locale' -msg() { - local mesg=$1; shift - printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} +################################################################################ +# Devtools overrides # +################################################################################ -msg2() { - local mesg=$1; shift - printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} +# Override several functions with built-in text to uses gettext warning() { - local mesg=$1; shift - printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 + local mesg=$1; shift + printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } error() { - local mesg=$1; shift - printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 -} - -stat_busy() { local mesg=$1; shift - printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}...${ALL_OFF}" >&2 + printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } stat_done() { - printf "${BOLD}done${ALL_OFF}\n" >&2 + printf "${BOLD}$(gettext "done")${ALL_OFF}\n" >&2 +} + +################################################################################ +# Own functions # +################################################################################ + +stdnull() { + eval "$@ >/dev/null 2>&1" } # Set the terminal title @@ -97,19 +73,9 @@ term_title() { printf "$fmt" "$*" } -# usage : in_array( $needle, $haystack ) -in_array() { - [[ $2 ]] || return 1 # Not found - - local needle=$1; shift - local item - - for item in "$@"; do - [[ ${item#@} = $needle ]] && return 0 # Found - done - - return 1 # Not Found -} +################################################################################ +# Run one of the defined functions if invoked directly # +################################################################################ if [[ "${0##*/}" = libremessages ]]; then _libremessages_cmd=$1 -- cgit v1.2.2 From 8eaf0770e396efa4bb254c7e62e4940682817589 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 28 Nov 2012 15:21:18 -0500 Subject: libretools.conf: force CHROOT != root --- src/libretools.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libretools.conf b/src/libretools.conf index 631ca89..4157006 100644 --- a/src/libretools.conf +++ b/src/libretools.conf @@ -130,6 +130,10 @@ for VAR in CHROOTDIR CHROOT PARABOLAHOST LIBREDESTDIR \ ret=1 fi done +if [[ $CHROOT == root ]]; then + echo "Configured var CHROOT cannot equal 'root'" + ret=1 +fi if [[ $ret != 0 ]]; then exit 1 fi -- cgit v1.2.2 From 35a3071f5a06efaeab9d884fbce67426abbc010d Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 28 Nov 2012 15:21:47 -0500 Subject: libretools.conf: remove libretools from CHROOTEXTRAPKG, it is being added to base-devel --- src/libretools.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libretools.conf b/src/libretools.conf index 4157006..bef9fc4 100644 --- a/src/libretools.conf +++ b/src/libretools.conf @@ -31,7 +31,7 @@ ARCHES=('i686' 'x86_64' 'mips64el' 'any') ## The directory where the chroots are stored CHROOTDIR=/home/chroot ## Extra packages to have installed on the chroot (besides base base-devel and sudo) -CHROOTEXTRAPKG=(distcc ccache tsocks libretools) +CHROOTEXTRAPKG=(distcc ccache tsocks) ## The meaning of this changes based on the version of libretools+devtools ## do NOT set it to 'root' CHROOT=default -- cgit v1.2.2 From 4e5d7c05ada2181ce0aa3bed0ba734f4e1ae70cb Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 28 Nov 2012 15:23:43 -0500 Subject: clean up aur --- src/aur | 214 +++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 112 insertions(+), 102 deletions(-) diff --git a/src/aur b/src/aur index f90a776..12efb81 100755 --- a/src/aur +++ b/src/aur @@ -2,122 +2,132 @@ # Copyright 2010 Nicolás Reynolds, Joshua Ismael # ---------- GNU General Public License 3 ---------- - + # 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 . -source /etc/libretools.conf -source /etc/abs.conf +. /etc/libretools.conf +. /etc/abs.conf + +cmd=${0##*/} -function usage { - echo "Usage: $0 pkgname-from-aur1 [pkgname-from-aur2 ...]" - echo - echo "This script will download packages from aur to the current dir" - echo "and check their license for nonfree issues." +usage() { + echo "Usage: $cmd pkgname-from-aur1 [pkgname-from-aur2 ...]" + echo + echo "This script will download packages from aur to the current dir" + echo "and check their license for nonfree issues." } -while getopts 'h' arg; do - case $arg in - h) usage; exit 0 ;; - *) usage; exit 1 ;; - esac -done - -missing_deps=() -for _pkg in ${@}; do - -# Remove the version - _pkg="${_pkg%%[<>=]*}" - - if [ -f "${_pkg}/PKGBUILD" ]; then - warning "${_pkg} already existed." - -# Check if we want to diff - if [ -z "${DIFFTOOL}" ]; then - continue - else -# Store our copy of the PKGBUILD dir - _diff="${PWD}/${_pkg}" - stdnull "pushd $(mktemp -d /tmp/${_pkg}.XXXX)" - msg2 "Downloading PKGBUILD into ${PWD} for diff" - fi - fi - - msg "Downloading $_pkg..." - wget -O - -q https://aur.archlinux.org/packages/${_pkg:0:2}/${_pkg}/$_pkg.tar.gz | \ - tar xzf - >/dev/null 2>&1 - - if [ $? -ne 0 ]; then - error "Couldn't get $_pkg" - continue - fi - - stdnull "pushd $_pkg" - - if [ ! -z "$_diff" ]; then - msg2 "Diffing files" -# Diff all files with our difftool - for file in *; do - ${DIFFTOOL} ${_diff}/${file} ${file} - done - -# Go back to our copy to continue working - stdnull "pushd ${_diff}" - fi - - source PKGBUILD - - if ! pkgbuild-check-nonfree; then - if [ $? -eq 15 ]; then - warning "This PKGBUILD links to known unfree packages" - fi - fi - - msg2 "Checking license..." - free=0 - for _license in ${license[@]}; do - if [ ! -d /usr/share/licenses/common/$_license ]; then - warning "License $_license is not a common license" - free=1 - fi - done - - if [ $free -eq 1 ]; then - plain "Please check that the license is included in the package and - *specially* that it respects your freedom." - fi - - for _dep in ${depends[@]} ${makedepends[@]}; do - _dep=${_dep/[<>=]*/} - if ! is_built $_dep; then - if ! find ${ABSROOT} -maxdepth 2 -type d -name "$_dep" | egrep "*" >/dev/null ; then - msg2 "$_dep will be get from AUR" - missing_deps+=($_dep) - fi - else - msg2 "$_dep is on repos" - fi - done - - stdnull popd - -done - -[[ ${#missing_deps[*]} -gt 0 ]] && { - msg2 "Retrieving missing deps: ${missing_deps[@]}" - $0 ${missing_deps[@]} +main() { + while getopts 'h' arg; do + case $arg in + h) usage; exit 0;; + *) usage; exit 1;; + esac + done + + local missing_deps=() + for _pkg in "$@"; do + + # Remove the version + _pkg="${_pkg%%[<>=]*}" + + if [[ -f "${_pkg}/PKGBUILD" ]]; then + warning "${_pkg} already existed." + + # Check if we want to diff + if [[ -z "${DIFFTOOL}" ]]; then + continue + else + # Store our copy of the PKGBUILD dir + _diff="${PWD}/${_pkg}" + stdnull "pushd $(mktemp --tmpdir -d ${_pkg}.XXXX)" + msg2 "Downloading PKGBUILD into ${PWD} for diff" + fi + fi + + msg "Downloading $_pkg..." + local url=https://aur.archlinux.org/packages/${_pkg:0:2}/${_pkg}/$_pkg.tar.gz + wget -O - -q "$url" | tar xzf - >/dev/null 2>&1 + + if [[ $? -ne 0 ]]; then + error "Couldn't get $_pkg" + continue + fi + + stdnull "pushd $_pkg" + + if [[ ! -z "$_diff" ]]; then + msg2 "Diffing files" + # Diff all files with our difftool + for file in *; do + "${DIFFTOOL}" "${_diff}/${file}" "${file}" + done + + # Go back to our copy to continue working + stdnull "pushd ${_diff}" + fi + + . PKGBUILD + + ################################################################ + + if ! pkgbuild-check-nonfree; then + if [[ $? = 15 ]]; then + warning "This PKGBUILD links to known unfree packages" + fi + fi + + ################################################################ + + msg2 "Checking license..." + local free=0 + for _license in ${license[@]}; do + if [[ ! -d /usr/share/licenses/common/$_license ]]; then + warning "License $_license is not a common license" + free=1 + fi + done + + if [[ $free -eq 1 ]]; then + plain "Please check that the license is included in the package and *specially* that it respects your freedom." + fi + + ################################################################ + + for _dep in "${depends[@]}" "${makedepends[@]}"; do + _dep=${_dep/[<>=]*/} + if ! is_built $_dep; then + if ! find ${ABSROOT} -maxdepth 2 -type d -name "$_dep" | egrep "*" >/dev/null ; then + msg2 "$_dep will be get from AUR" + missing_deps+=($_dep) + fi + else + msg2 "$_dep is on repos" + fi + done + + stdnull popd + done + + [[ ${#missing_deps[*]} -gt 0 ]] && { + msg2 "Retrieving missing deps: ${missing_deps[@]}" + $0 ${missing_deps[@]} + } + + exit 0 } -exit 0 +main "$@" -- cgit v1.2.2 From 144466aaa12ef0aed8a53767becae6033df9b3cf Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 28 Nov 2012 19:17:00 -0500 Subject: libretools.conf: set LIBREUSER and LIBREHOME --- src/libretools.conf | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/libretools.conf b/src/libretools.conf index bef9fc4..20c7d90 100644 --- a/src/libretools.conf +++ b/src/libretools.conf @@ -107,14 +107,10 @@ TORUPATH=/var/lib/libretools/toru # This probably shouldn't be in a .conf file... # ################################################################################ +LIBREUSER="${SUDO_USER:-$USER}" +LIBREHOME="$(eval echo ~$SUDO_USER)" if [[ -z $XDG_CONFIG_HOME ]]; then - if [[ -n $SUDO_USER ]]; then - SUDO_HOME="$(eval echo ~$SUDO_USER)" - export XDG_CONFIG_HOME="${SUDO_HOME}/.config" - unset SUDO_HOME - else - export XDG_CONFIG_HOME="${HOME}/.config" - fi + export XDG_CONFIG_HOME="${LIBREHOME}/.config" fi if [[ -e "$XDG_CONFIG_HOME/libretools/libretools.conf" ]]; then . "$XDG_CONFIG_HOME/libretools/libretools.conf" -- cgit v1.2.2 From 56f394ecbe65b5aba13759237f8a6cbc645e5e3d Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 28 Nov 2012 19:17:19 -0500 Subject: fix getopts for libremkchroot --- src/chroot-tools/libremkchroot | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/chroot-tools/libremkchroot b/src/chroot-tools/libremkchroot index 3072b9e..992c6e5 100755 --- a/src/chroot-tools/libremkchroot +++ b/src/chroot-tools/libremkchroot @@ -1,23 +1,20 @@ #!/bin/bash -# LibreMkChroot -# Creates a chroot +# libremkchroot # Copyright 2011, 2012 Luke Shumaker - -# ---------- GNU General Public License 3 ---------- - +# # 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 . @@ -41,7 +38,7 @@ usage() { main() { archroot_args=(); - while getopts 'hfd:C:M:' arg; do + while getopts 'hC:M:' arg; do case "$arg" in C|M) archroot_args+=("-$arg" "$OPTARG");; -- cgit v1.2.2 From 2a86ab6a3575724412f32fdbd794b0fd2738eb91 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 28 Nov 2012 19:17:54 -0500 Subject: reorganize, add a few features to librechroot --- src/chroot-tools/librechroot | 130 +++++++++++++++++++++++-------------------- 1 file changed, 69 insertions(+), 61 deletions(-) diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index 8830c39..c3c7374 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -1,52 +1,27 @@ -#!/bin/bash -# LibreChRoot -# Enters a chroot +#!/bin/bash -euE +# librechroot # Copyright 2010 Nicolás Reynolds # Copyright 2011 Joshua Haase # Copyright 2012 Luke Shumaker - -# ---------- GNU General Public License 3 ---------- - +# # 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 . . /etc/libretools.conf -cmd=${0##*/} - -clean_pacman() { - msg "Cleaning chroot with pacman: ${copydir}" - - cp -a "$(dirname $0)/chcleanup" "${copydir}/clean" - mkdir -p "$copydir/build" - archroot "${copydir}" -r "cd /build; /clean" -} - -clean_repo() { - msg "Cleaning repo for chroot: ${copydir}" - - if [ -d "${copydir}/repo" ]; then - find "${copydir}/repo/" -mindepth 1 -delete - else - mkdir -p "${copydir}/repo" - fi - bsdtar -czf "${copydir}/repo/repo.db.tar.gz" -T /dev/null - ln -s "repo.db.tar.gz" "${copydir}/repo/repo.db" -} - ## # This function is almost verbatim from makechrootpkg ## @@ -62,8 +37,7 @@ sync() { local use_rsync=false if type -P btrfs >/dev/null; then [[ -d $copydir ]] && btrfs subvolume delete "$copydir" &>/dev/null - btrfs subvolume snapshot "$chrootdir/root" "$copydir" &>/dev/null || - use_rsync=true + btrfs subvolume snapshot "$chrootdir/root" "$copydir" &>/dev/null || use_rsync=true else use_rsync=true fi @@ -77,48 +51,49 @@ sync() { lock_close 8 } -update() { - msg "Updating chroot: ${copydir}" - archroot "${copydir}" -u -} - -enter() { - msg "Entering chroot: ${copydir}" - archroot "${copydir}" -r "bash" -} - usage() { - echo "Usage: $cmd [OPTIONS] [CHROOT]" + echo "Usage: $cmd [OPTIONS] [CHROOT] " echo 'Interacts with a chroot.' echo '' echo "The default CHROOT is \`${CHROOT}'." echo '' echo 'Options:' echo ' Settings:' - echo ' -l Use this as the chroot copy instead of basing it' + echo ' -l 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 " -C Clean the chroot by syncing it with 'root' copy" - echo ' -r Clean /repo in the chroot' + echo ' -N Disable networking in the chroot' + echo '' + echo ' Modes: (the last mode given will be used)' + echo ' -C Clean /repo in the chroot' + echo ' -c Clean the packages installed in the chroot' + echo ' -I Install the package FILE into the chroot' + echo ' -i Install the package PKG from repos into the chroot' + echo ' -n No-op, just make sure that the chroot exists' + echo ' -r Run CMD in the chroot' + echo " -s Sync the copy with the 'root' copy" echo ' -u Update the chroot' + echo ' -h Print this message' } main() { - # The logic for setting CHROOTCOPY is mirred from makechrootpkg - CHROOTCOPY=$USER - [[ -n $SUDO_USER ]] && CHROOTCOPY=$SUDO_USER - [[ -z $CHROOTCOPY || $CHROOTCOPY = root ]] && CHROOTCOPY=copy + CHROOTCOPY=$LIBREUSER + [[ $CHROOTCOPY != root ]] || CHROOTCOPY=copy local mode=enter - while getopts 'hrcud:l:' arg; do + local archroot_args=() + local ARG='' + while getopts 'l:NCcI:i:nrsuh' arg; do case $arg in l) CHROOTCOPY=$OPTARG;; + N) archroot_args+=(-N);; + C) mode=clean_repo c) mode=clean_pacman;; - C) mode=sync;; - r) mode=clean_repo;; + I) mode=install_file; ARG=$OPTARG;; + I) mode=install_pkg; ARG=$OPTARG;; + n) mode=noop;; + r) mode=run; ARG=$OPTARG;; + s) mode=sync;; u) mode=update;; h) usage; exit 0;; @@ -154,10 +129,43 @@ main() { fi case "$mode" in - clean_pacman) clean_pacman; exit $?;; - clean_repo) clean_repo; exit $?;; - update) update; exit $?;; - enter) enter; exit $?;; + clean_repo) + msg "Cleaning local pacman repository" + rm -rf "${copydir}/repo" + mkdir "${copydir}/repo" + bsdtar -czf "${copydir}/repo/repo.db.tar.gz" -T /dev/null + ln -s "repo.db.tar.gz" "${copydir}/repo/repo.db" + ;; + clean_pacman) + msg "Intelligently cleaning packages" + cp -a "$(dirname $0)/chcleanup" "${copydir}/clean" + mkdir -p "$copydir/build" + archroot "${archroot_args[@]}" "${copydir}" -r "cd /build; /clean" + ;; + install_file) + msg "Installing package file: $ARG" + cp "$ARG" "$copydir/${ARG##*/}" + archroot "${archroot_args[@]}" "$copydir" -r "pacman -U /${ARG##*/} --noconfirm" + rm "$copydir/${ARG##*/}" + ;; + install_pkg) + msg "Installing package(s): $ARG" + archroot "${archroot_args[@]}" "$copydir" -i $ARG + ;; + noop) :;; + run) + msg "Running command" + archroot "${archroot_args[@]}" "${copydir}" -r "$ARG" + ;; + sync) sync;; + update) + msg "Updating chroot" + archroot "${archroot_args[@]}" "${copydir}" -u + ;; + enter) + msg "Entering chroot" + archroot "${archroot_args[@]}" "${copydir}" -r bash + ;; esac } -- cgit v1.2.2 From 259c05c47fc43875415d5ecab9666a46fb4b6d76 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 28 Nov 2012 19:34:19 -0500 Subject: Rewrite libremakepkg to not use makechrootpkg --- src/chroot-tools/libremakepkg | 175 ++++++++++++++++++++++++------------- src/chroot-tools/libremakepkg.gpl2 | 102 +++++++++++++++++++++ 2 files changed, 214 insertions(+), 63 deletions(-) create mode 100755 src/chroot-tools/libremakepkg.gpl2 diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg index faa50be..d661714 100755 --- a/src/chroot-tools/libremakepkg +++ b/src/chroot-tools/libremakepkg @@ -1,141 +1,190 @@ -#!/bin/bash +#!/bin/bash -euE # 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 ---------- - +# # 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 . . /etc/libretools.conf +shopt -s nullglob + +# This file (libremakepkg) is GPLv3+, but I would like to use some code +# modified from devtools' "makechrootpkg", which is GPLv2. +. "$(dirname "$0")/libremakepkg.gpl2" +# This gives us the functions: +# - chroot_init +# - chroot_extract +# - chroot_build +# - copy_pkgs + +# Boring functions ############################################################# + ## # copy logs if they exist ## -copy_log() { - find "${copydir}/build/" -maxdepth 1 -name "*\.log" -exec cp {} ./ \; +copy_logs() { + for l in "$copydir"/build/*.log; do + chown "$LIBREUSER" "$l" + mv "$l" . + done } ## # End inmediately but print a useful message ## trap_exit() { - copy_log - error "$@" + copy_logs + error "$*" 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'" + fi +} + +chroot_makepkg_conf_get() { + local setting=$1 + eval $(grep "^$setting=" "$copydir/etc/makepkg.conf") +} + +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" +} + +# Functions that check for issues with the build ############################### + +libre_check_pkgbuild() { + msg "Checking PKGBUILD for issues" + # TODO + if ! pkgbuild-check-nonfree -f; 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 +} + +libre_check_src() { + msg "Checking src directory for issues" + # TODO +} + +libre_check_pkg() { + msg "Checking final package for issues" + # TODO +} + + +# The main program ############################################################# + usage() { echo 'cd to a dir containing a PKGBUILD and run:' - echo '$0 [options] [-- makechrootpkg args [-- makepkg args]]' + echo '$0 [options] [-- makepkg args]' echo 'This script will build your package in a chroot.' echo '' echo 'OPTIONS:' echo ' -h Show this message' echo '' - echo ' -c Clean the chroot before building' - echo ' -u Update the chroot before building' - echo ' -N Do not check freedom issues (for fullpkg)' - echo '' + echo " -R Repackage" echo " -n Use this chroot instead of \`$CHROOT'" echo ' -l 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 + # Parse command line ################################################### - makechrootpkg_args=() + CHROOTCOPY=$LIBREUSER + [[ $CHROOTCOPY != root ]] || CHROOTCOPY=copy + makepkg_args=(-s --noconfirm -L) + REPACKAGE=false - while getopts 'hcuNd:n:l:' arg ; do + while getopts 'hRn:l:' arg ; do case "${arg}" in - c) CLEANFIRST=true;; - u) UPDATEFIRST=true;; - N) CHECKNONFREE=false;; - n) CHROOT=$OPTARG;; l) CHROOTCOPY=$OPTARG;; - + R) REPACKAGE=true; makepkg_args+=(-R) ;; h) usage; exit 0;; *) usage; exit 1;; esac done shift $(($OPTIND - 1)) - # Pass all arguments after -- right to makechrootpkg - makechrootpkg_args+=("$@") + # Pass all arguments after -- right to makepkg + makepkg_args+=("$@") - # not local rootdir="${CHROOTDIR}/${CHROOT}/root" copydir="${CHROOTDIR}/${CHROOT}/${CHROOTCOPY}" + # Init ################################################################# + 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" + if [[ ! -f PKGBUILD ]]; then + error "This must be run in a directory containing a PKGBUILD" 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 -f; 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 + makepkg_conf_get SRCDEST . + makepkg_conf_get PKGDEST . - if $CLEANFIRST; then - librechroot -c -d "$CHROOTDIR" -l "$CHROOTCOPY" "$CHROOT" - fi + # OK, we're starting now ############################################### - if $UPDATEFIRST; then - librechroot -u -d "$CHROOTDIR" -l "$CHROOTCOPY" "$CHROOT" - fi + lock_open_write 9 "$copydir.lock" "Locking chroot '$copy'" - unset CLEANFIRST UPDATEFIRST librechroot_args + # Set target CARCH as it might be used within the PKGBUILD to select correct sources + chroot_makepkg_conf_get CARCH + export CARCH - makechrootpkg "${makechrootpkg_args[@]}" -d -r "$CHROOTDIR/$CHROOT" -l "$CHROOTCOPY" - ev=$? # exit value - copy_log - exit $ev + chroot_init + libre_check_pkgbuild + $REPACKAGE || chroot_extract + libre_check_src + chroot_build + libre_check_pkg + copy_pkgs + copy_logs } main "$@" diff --git a/src/chroot-tools/libremakepkg.gpl2 b/src/chroot-tools/libremakepkg.gpl2 new file mode 100755 index 0000000..8ca60e0 --- /dev/null +++ b/src/chroot-tools/libremakepkg.gpl2 @@ -0,0 +1,102 @@ +#!/bin/bash +# Contains code derived from devtools' "makechrootpkg" + +# Copyright 2011-2012 The Arch Linux Development Team +# Copyright 2012 Luke Shumaker +# +# This program 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; version 2 of the License. +# +# This program 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. + +chroot_init() { + # no-op; make sure the chroot exists + librechroot -n -l "$CHROOTCOPY" "$CHROOT" + + if [[ -r "$LIBREHOME/.gnupg/pubring.gpg" ]]; then + install -D "$HOME/.gnupg/pubring.gpg" "$copydir/build/.gnupg/pubring.gpg" + fi + + mkdir -p "$copydir/pkgdest" + mkdir -p "$copydir/srcdest" + chroot_makepkg_conf_set PKGDEST /pkgdest + chroot_makepkg_conf_set SRCDEST /srcdest + + cat > "$copydir/etc/sudoers.d/nobody-pacman" < "$file" + echo '. /etc/profile' >> "$file" + echo 'export HOME=/build' >> "$file" + echo 'cd /build' >> "$file" + echo "sudo -u nobody ${MAKEPKG:-makepkg} $makepkg_args -o" >> "$file" + chmod 755 "$file" + archroot "$copydir" -r /chrootextract +} + +chroot_build() { + local file="$copydir/chrootbuild" + echo '#!/bin/bash' > "$file" + echo '. /etc/profile' >> "$file" + echo 'export HOME=/build' >> "$file" + echo 'cd /build' >> "$file" + echo "sudo -u nobody ${MAKEPKG:-makepkg} $makepkg_args -e" >> "$file" + chmod 755 "$file" + archroot -N "$copydir" -r /chrootbuild +} + +copy_pkgs() { + for pkgfile in "$copydir"/pkgdest/*.pkg.tar*; do + mkdir -p "$copydir/repo" + pushd "$copydir/repo" >/dev/null + cp "$pkgfile" . + repo-add repo.db.tar.gz "${pkgfile##*/}" + popd >/dev/null + + chown "$LIBREUSER" "$pkgfile" + mv "$pkgfile" "$PKGDEST" + if [[ $PKGDEST != . ]]; then + ln -s "$PKGDEST/${pkgfile##*/}" . + fi + done +} -- cgit v1.2.2 From 6dd807e109d491458b26d76602ad344b4c025475 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 28 Nov 2012 19:42:08 -0500 Subject: teach libremakepkg "-m" to use a different command than "makepkg" --- src/chroot-tools/libremakepkg | 17 +++++++++++------ src/chroot-tools/libremakepkg.gpl2 | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg index d661714..b6c84c1 100755 --- a/src/chroot-tools/libremakepkg +++ b/src/chroot-tools/libremakepkg @@ -117,12 +117,14 @@ usage() { echo 'This script will build your package in a chroot.' echo '' echo 'OPTIONS:' - echo ' -h Show this message' + echo " -n Use this chroot instead of \`$CHROOT'" + echo ' -l Use this chroot copy instead of basing it' + echo ' on the username' echo '' + echo " -m Use the command MAKEPKG instead of 'makepkg'" echo " -R Repackage" - echo " -n Use this chroot instead of \`$CHROOT'" - echo ' -l Use this chroot copy instead of basing it' - echo ' on the username' + echo '' + echo ' -h Show this message' } main() { @@ -130,14 +132,17 @@ main() { CHROOTCOPY=$LIBREUSER [[ $CHROOTCOPY != root ]] || CHROOTCOPY=copy + makepkg_args=(-s --noconfirm -L) REPACKAGE=false + MAKEPKG=makepkg - while getopts 'hRn:l:' arg ; do + while getopts 'n:l:m:Rh' arg ; do case "${arg}" in n) CHROOT=$OPTARG;; l) CHROOTCOPY=$OPTARG;; - R) REPACKAGE=true; makepkg_args+=(-R) ;; + m) MAKEPKG=$OPTARG;; + R) REPACKAGE=true; makepkg_args+=(-R);; h) usage; exit 0;; *) usage; exit 1;; esac diff --git a/src/chroot-tools/libremakepkg.gpl2 b/src/chroot-tools/libremakepkg.gpl2 index 8ca60e0..1f2d185 100755 --- a/src/chroot-tools/libremakepkg.gpl2 +++ b/src/chroot-tools/libremakepkg.gpl2 @@ -69,7 +69,7 @@ chroot_extract() { echo '. /etc/profile' >> "$file" echo 'export HOME=/build' >> "$file" echo 'cd /build' >> "$file" - echo "sudo -u nobody ${MAKEPKG:-makepkg} $makepkg_args -o" >> "$file" + echo "sudo -u nobody ${MAKEPKG} $makepkg_args -o" >> "$file" chmod 755 "$file" archroot "$copydir" -r /chrootextract } @@ -80,7 +80,7 @@ chroot_build() { echo '. /etc/profile' >> "$file" echo 'export HOME=/build' >> "$file" echo 'cd /build' >> "$file" - echo "sudo -u nobody ${MAKEPKG:-makepkg} $makepkg_args -e" >> "$file" + echo "sudo -u nobody ${MAKEPKG} $makepkg_args -e" >> "$file" chmod 755 "$file" archroot -N "$copydir" -r /chrootbuild } -- cgit v1.2.2 From ba312fb72ec0843297978796a20c6ffc1fe3ef6e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 28 Nov 2012 20:14:44 -0500 Subject: fix a typo --- src/chroot-tools/librechroot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index c3c7374..e39b105 100755 --- a/src/chroot-tools/librechroot +++ b/src/chroot-tools/librechroot @@ -87,7 +87,7 @@ main() { l) CHROOTCOPY=$OPTARG;; N) archroot_args+=(-N);; - C) mode=clean_repo + C) mode=clean_repo;; c) mode=clean_pacman;; I) mode=install_file; ARG=$OPTARG;; I) mode=install_pkg; ARG=$OPTARG;; -- cgit v1.2.2