summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolás Reynolds <apoyosis@correo.inta.gob.ar>2012-02-04 13:17:05 -0300
committerNicolás Reynolds <apoyosis@correo.inta.gob.ar>2012-02-04 13:17:05 -0300
commit3fb8e62b798c0dffb201727439a6a0d90bc1b20f (patch)
treef69c1b6db4082e9188f22be8d3d3d5cc5212f34f
parent5ab36af3c7a505ff40bb8ca46ec387b94d85cbdf (diff)
parent9808018ca09050ade144d0dfc0b0b6edadefa368 (diff)
Merge branch 'master' of ssh://gparabola/libretools
Conflicts: libremakepkg
-rwxr-xr-xaur36
-rwxr-xr-xbuildenv28
-rwxr-xr-xchcleanup7
-rwxr-xr-xfullpkg3
-rw-r--r--fullpkg-find11
-rwxr-xr-xis_built29
-rwxr-xr-xis_unfree11
-rwxr-xr-xlibremakepkg4
-rwxr-xr-xpkgbuild-check-nonfree2
-rwxr-xr-xprtools/prfullpkg4
-rwxr-xr-xtoru27
-rwxr-xr-xtoru-path32
-rwxr-xr-xtoru-utils86
13 files changed, 233 insertions, 47 deletions
diff --git a/aur b/aur
index 1b17358..b96cb20 100755
--- a/aur
+++ b/aur
@@ -42,28 +42,48 @@ for _pkg in ${@}; do
_pkg="${_pkg%%[<>=]*}"
if [ -f "${_pkg}/PKGBUILD" ]; then
- warning "${_pkg} already existed. skipping..."
- continue
+ 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 http://aur.archlinux.org/packages/$_pkg/$_pkg.tar.gz | \
+ wget -O - -q https://aur.archlinux.org/packages/$_pkg/$_pkg.tar.gz | \
tar xzf - >/dev/null 2>&1
- [[ $? -ne 0 ]] && {
+ 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
- pkgbuild-check-nonfree || {
+ if ! pkgbuild-check-nonfree; then
if [ $? -eq 15 ]; then
warning "This PKGBUILD links to known unfree packages"
fi
- }
+ fi
msg2 "Checking license..."
free=0
@@ -84,7 +104,7 @@ for _pkg in ${@}; do
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)
+ missing_deps+=($_dep)
fi
else
msg2 "$_dep is on repos"
diff --git a/buildenv b/buildenv
new file mode 100755
index 0000000..84a1fc2
--- /dev/null
+++ b/buildenv
@@ -0,0 +1,28 @@
+#!/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/chcleanup b/chcleanup
new file mode 100755
index 0000000..83c9f3f
--- /dev/null
+++ b/chcleanup
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+[ ! -f ~/cleansystem ] && exit 1
+
+sudo pacman --noconfirm -Rcs $(comm -23 <(pacman -Qq | sort) <(sort ~/cleansystem))
+
+exit $?
diff --git a/fullpkg b/fullpkg
index fe74432..bccd816 100755
--- a/fullpkg
+++ b/fullpkg
@@ -27,6 +27,7 @@ done
shift $(( OPTIND - 1 ))
-fullpkg-find "$1" && fullpkg-build -N "$1"
+build_dir="${1:-$(mktemp -d /tmp/fullpkg.XXXXXX)}"
+fullpkg-find "$build_dir" && fullpkg-build -N "$build_dir"
exit 0
diff --git a/fullpkg-find b/fullpkg-find
index 25565ae..8c0c063 100644
--- a/fullpkg-find
+++ b/fullpkg-find
@@ -11,6 +11,14 @@ guess_repo() {
basename $(dirname $(pwd))
}
+# Finds a PKGBUILD on toru's path cache
+# Look in all caches but pick the first one
+# TODO move to a toru flag (-p?)
+where_is() {
+ grep -m1 "^${1}:" "${TORUPATH}/paths" 2>/dev/null| \
+ cut -d: -f2 2>/dev/null
+}
+
# return : full version spec, including epoch (if necessary), pkgver, pkgrel
# usage : get_fullver( ${epoch:-0}, $pkgver, $pkgrel )
get_fullver() {
@@ -39,7 +47,7 @@ find_deps() {
fi
fi
- if is_built "${pkgbase}>=${fullver}"; then
+ if is_built "${pkgbase}" "${fullver}"; then
exit 0 # pkg is built and updated
fi
@@ -71,6 +79,7 @@ find_deps() {
for _dep in ${deps[@]}; do
local found=false
+# TODO change for where_is or toru-path
local pkgdir=$(toru -p ${_dep})
if [ -n "$pkgdir" -a -d "${pkgdir}" ]; then
diff --git a/is_built b/is_built
index 60f24e9..1fa79d2 100755
--- a/is_built
+++ b/is_built
@@ -2,9 +2,10 @@
usage() {
echo "$0 "
echo
- echo "Detect is a package is installed or in a database"
+ echo "Detect if a given package version is already in repos"
+ echo "Assuming you want greater or equal"
echo
- echo "Example usage: is_built \"pcre>=20\""
+ echo "Example usage: is_built 'pcre' '20'"
}
while getopts 'h' arg; do
@@ -14,12 +15,22 @@ while getopts 'h' arg; do
esac
done
-# Checks for package, if -T returns non-zero output, egrep will return 0
-# because it finds it, so we negate the value to say it's not built.
-# -Sp works backwards, it will print output only when the package already
-# exists
+ver=${2}
+pkg=${1}
+pver=$(LC_ALL=C pacman -Sddp --print-format "%v" "${pkg}" 2>/dev/null)
-!(sudo pacman -T "$1" | egrep "*" >/dev/null) || \
-sudo pacman -Sp "$1" --print-format "%n-%v" 2>/dev/null | egrep "*" >/dev/null
+# if pacman fails or returns nothing
+r=$?
+[ "${pver}" = " there is nothing to do" ] && r=1
-exit $?
+result=$(vercmp "${pver}" "${ver}")
+
+# if vercmp > 1 means our version is bigger
+if [ ${result} -ge 0 -a ${r} -eq 0 ]; then
+ exit 0
+else
+ exit 1
+fi
+
+# just in case
+exit 1
diff --git a/is_unfree b/is_unfree
new file mode 100755
index 0000000..f32c193
--- /dev/null
+++ b/is_unfree
@@ -0,0 +1,11 @@
+#!/bin/bash
+# Checks if a package is on blacklist
+
+# fail immediately on error
+set -E
+
+blacklist="$XDG_CONFIG_HOME/libretools/blacklist.txt"
+
+egrep -q "^${1}:" "${blacklist}"
+
+exit $?
diff --git a/libremakepkg b/libremakepkg
index 06500d2..44c0d29 100755
--- a/libremakepkg
+++ b/libremakepkg
@@ -55,7 +55,7 @@ function usage {
echo ''
echo 'cd to a dir containing a PKGBUILD and run:'
- echo '$0 [options] [-- makechrootpkg args] [-- makepkg args]'
+ echo '$0 [options] [-- makechrootpkg args [-- makepkg args]]'
echo 'This script will build your package on a chroot.'
echo ''
echo 'OPTIONS:'
@@ -118,7 +118,7 @@ fi
unset CLEANFIRST UPDATEFIRST LIBRECHROOT_ARGS
-makechrootpkg -d -r "$CHROOTDIR" -l "$CHROOT" "$MAKEPKG_ARGS"
+makechrootpkg -d -r "$CHROOTDIR" -l "$CHROOT" $MAKEPKG_ARGS
ev="$?" # exit value
copy_log
diff --git a/pkgbuild-check-nonfree b/pkgbuild-check-nonfree
index bd6fa4b..df0ff36 100755
--- a/pkgbuild-check-nonfree
+++ b/pkgbuild-check-nonfree
@@ -161,7 +161,7 @@ while getopts 'h' arg; do
esac
done
-if (( ! EUID )); then
+if [ -w / ]; then
error "Run as normal user"
fi
diff --git a/prtools/prfullpkg b/prtools/prfullpkg
index dd2ba3a..bbb8d73 100755
--- a/prtools/prfullpkg
+++ b/prtools/prfullpkg
@@ -85,7 +85,7 @@ function find_deps { # Checks ABSROOT and look for target pkg deps. Adds them i
local epoch=${epoch:-0}
local fullver=$(get_fullver ${epoch} ${pkgver} ${pkgrel})
- if is_built "${pkgbase}>=${fullver}"; then
+ if is_built "${pkgbase}" "${fullver}"; then
exit 0 # pkg is built and updated
fi
@@ -316,7 +316,7 @@ fi
if [ $level -eq 0 ]; then
if [ ! -d ${build_dir} ]; then # in case of custom -d option
- mkdir -p ${build_dir}
+ mkdir -p ${build_dir}
else
cleanup # files already there can screw find_deps
fi
diff --git a/toru b/toru
index 5867bfe..9616119 100755
--- a/toru
+++ b/toru
@@ -12,28 +12,7 @@
# * Possibility to hook up ABS dirs besides ABSROOT (low priority)
# * Tell updates and non available binary packages (working on this)
-source /etc/abs.conf
-source /etc/libretools.conf
-
-if [ ! -w "$TORUPATH" ]; then
- error "Toru's path isn't writable. Please check $TORUPATH"
- exit 1
-fi
-
-# Stores the lastsync date
-lastsync() {
- local lastsyncfile
-
- lastsyncfile=$1
-
- [ -e ${lastsyncfile} -a ! -w ${lastsyncfile} ] && {
- error "The sync date can't be saved. ${lastsyncfile} isn't writable."
- return 1
- }
-
- date +%s > ${lastsyncfile}
- touch ${lastsyncfile}
-}
+source $(dirname $0)/toru-utils
# Saves contents on a named cache
# $1 cache name (repo)
@@ -252,7 +231,9 @@ update() {
# See above FIXME
# print_package_array "${updates[@]}" > ${TMPDIR}/updates
- store_cache ${_repo}.updates ${TMPDIR}/updates
+ if [ -r ${TMPDIR}/updates ]; then
+ store_cache ${_repo}.updates ${TMPDIR}/updates
+ fi
else
$quiet || msg "Reading updates from cache..."
diff --git a/toru-path b/toru-path
new file mode 100755
index 0000000..7500aed
--- /dev/null
+++ b/toru-path
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+source $(dirname $0)/toru-utils
+
+LASTSYNCFILE=${TORUPATH}/lastsync.paths
+
+# TODO pass other paths via flags
+pkgbuilds=($(get_pkgbuilds ${ABSROOT}))
+paths=()
+
+msg "Updating path cache"
+msg2 "${#pkgbuilds[@]} PKGBUILDs to update"
+for _pkgbuild in ${pkgbuilds[@]}; do
+ $DEBUG && plain "$_pkgbuild"
+ source ${_pkgbuild} || {
+ error "${_pkgbuild} contains errors, skipping"
+ continue
+ }
+
+ fullpath=$(dirname $(readlink -f ${_pkgbuild}))
+
+ for _pkg in ${pkgname[@]} ${provides[@]}; do
+ paths+=(${_pkg/[<>=]*}:${fullpath})
+ done
+
+ unset pkgname provides
+done
+
+# TODO remove old paths
+echo ${paths[@]} | tr ' ' "\n" | sort >> ${TORUPATH}/paths
+
+lastsync ${LASTSYNCFILE}
diff --git a/toru-utils b/toru-utils
new file mode 100755
index 0000000..bb0aef4
--- /dev/null
+++ b/toru-utils
@@ -0,0 +1,86 @@
+#!/bin/bash
+#!/bin/bash
+
+
+source /etc/abs.conf
+source /etc/libretools.conf
+
+if [ ! -w "$TORUPATH" ]; then
+ error "Toru's path isn't writable. Please check $TORUPATH"
+ exit 1
+fi
+
+LASTSYNCFILE=${TORUPATH}/lastsync
+FORCE=false
+QUIET=false
+DEBUG=false
+
+# usage : in_array( $needle, $haystack )
+function 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
+}
+
+# Stores the lastsync date
+lastsync() {
+ local lastsyncfile
+
+ lastsyncfile=$1
+
+ [ -e ${lastsyncfile} -a ! -w ${lastsyncfile} ] && {
+ error "The sync date can't be saved. ${lastsyncfile} isn't writable."
+ return 1
+ }
+
+ date +%s > ${lastsyncfile}
+ touch ${lastsyncfile}
+}
+
+get_dbs() {
+ local _db
+ for _db in /var/lib/pacman/sync/*.db; do
+ bsdtar tf ${_db} | cut -d'/' -f1 | sort -u
+ done
+}
+
+# repo paths
+get_pkgbuilds() {
+ pkgbuilds=()
+
+ if [[ $FORCE = true || ! -e ${LASTSYNCFILE} ]]; then
+
+ $QUIET || warning "Forcing upgrade"
+# Get all PKGBUILDs
+ pkgbuilds=($(find $@ -mindepth 2 -maxdepth 3 -type f -name 'PKGBUILD'))
+
+ else
+
+# Only find newer than lastsyncfile and read everything else from cache
+ pkgbuilds=($(find $@ -mindepth 2 -maxdepth 3 -type f -name 'PKGBUILD' -newer ${LASTSYNCFILE}))
+
+ fi
+
+# Return all PKGBUILDs found
+ echo ${pkgbuilds[@]}
+}
+
+# End inmediately but print a useful message
+trap_exit() {
+ error "$@"
+
+ exit 1
+}
+
+# Trap signals from makepkg
+set -E
+trap 'trap_exit "(prfullpkg:${level}) TERM signal caught. Exiting..."' TERM HUP QUIT
+trap 'trap_exit "(prfullpkg:${level}) Aborted by user! Exiting..."' INT
+trap 'trap_exit "(prfullpkg:${level}) An unknown error has occurred. Exiting..."' ERR