summaryrefslogtreecommitdiff
path: root/toru
diff options
context:
space:
mode:
authorNicolas Reynolds <fauno@kiwwwi.com.ar>2011-06-30 19:35:07 -0300
committerNicolas Reynolds <fauno@kiwwwi.com.ar>2011-06-30 19:35:07 -0300
commit0bdf0e254112eae0332b4ae85f417abb7091f690 (patch)
tree0778e5d2b94fb31c3238a0d19c870ac7ef9abc9c /toru
parent8a97ce469507f3c4c0ea06ad0025b57405e42283 (diff)
parent8a385be009f51b1af2cd8fd82c08b6b7c2c7f8b0 (diff)
Merge branch 'master' of ssh://vparabola/srv/git/projects/libretools
Conflicts: toru
Diffstat (limited to 'toru')
-rwxr-xr-xtoru143
1 files changed, 68 insertions, 75 deletions
diff --git a/toru b/toru
index 84608ea..332f42d 100755
--- a/toru
+++ b/toru
@@ -13,49 +13,43 @@
# * 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
-
-#[ ! -w / ] && {
-# error "This script must be run as root."
-# exit 1
-#}
-
+ source /etc/abs.conf
+ source /etc/libretools.conf
# Stores the lastsync date
-lastsync() {
- [ -e ${lastsyncfile} -a ! -w ${lastsyncfile} ] && {
- error "The sync date can't be saved. ${lastsyncfile} isn't writable."
- return 1
- }
-
- date +%s > ${lastsyncfile}
- touch ${lastsyncfile}
-}
+ lastsync() {
+ [ -e ${lastsyncfile} -a ! -w ${lastsyncfile} ] && {
+ error "The sync date can't be saved. ${lastsyncfile} isn't writable."
+ return 1
+ }
+
+ date +%s > ${lastsyncfile}
+ touch ${lastsyncfile}
+ }
##
# usage : get_full_version( $epoch, $pkgver, $pkgrel )
# return : full version spec, including epoch (if necessary), pkgver, pkgrel
##
-get_full_version() {
- if [[ $1 -eq 0 ]]; then
- # zero epoch case, don't include it in version
- echo $2-$3
- else
- echo $1:$2-$3
- fi
-}
+ get_full_version() {
+ if [[ $1 -eq 0 ]]; then
+ # zero epoch case, don't include it in version
+ echo $2-$3
+ else
+ echo $1:$2-$3
+ fi
+ }
-# Outputs an ordered package-fullpkgver array
-print_package_array() {
- echo "$@" | tr " " "\n" | sort -V -u
-}
+# Outputs an ordered package-fullpkgver array
+ print_package_array() {
+ echo "$@" | tr " " "\n" | sort -V -u
+ }
# Gets repo.db contents (unordered)
# $1 repo
-get_db_contents() {
- [ ! -r /var/lib/pacman/sync/$1.db ] && return 0
+ get_db_contents() {
+ [ ! -r /var/lib/pacman/sync/$1.db ] && return 0
bsdtar -tf /var/lib/pacman/sync/$1.db | cut -d'/' -f1
}
@@ -78,63 +72,62 @@ extract_fullpkgver() {
# * Get all packages already on package repos
# * Compare them
# Args:
-update() {
+ update() {
# The PKGBUILDs found
- local pkgbuilds=()
+ local pkgbuilds=()
# The list of pkgname-fullpkgver
- local packages_to_sync=()
- local packages_in_sync=()
- local needed_updates=()
- local old_versions=()
+ local packages_to_sync=()
+ local packages_in_sync=()
+ local needed_updates=()
+ local old_versions=()
# Find all the PKGBUILDs newer than the last update
# Update newer, otherwise everything
- if [ $force ] || [ ! -e ${lastsyncfile} ]; then
- $quiet || msg "Forcing upgrade"
- pkgbuilds=($(find ${@} -maxdepth 2 -type f -name 'PKGBUILD'))
- else
- pkgbuilds=($(find ${@} -maxdepth 2 -type f -name 'PKGBUILD' -newer ${lastsyncfile}))
- fi
+ if [ $force ] || [ ! -e ${lastsyncfile} ]; then
+ $quiet || msg "Forcing upgrade"
+ pkgbuilds=($(find ${@} -maxdepth 2 -type f -name 'PKGBUILD'))
+ else
+ pkgbuilds=($(find ${@} -maxdepth 2 -type f -name 'PKGBUILD' -newer ${lastsyncfile}))
+ fi
# Inform how many PKGBUILDS were found and quit immediately if none
- $quiet || msg "Found $((${#pkgbuilds[*]}-1)) packages to update"
- [ ${#pkgbuilds[*]} -eq 1 ] && {
- $quiet || msg2 "There's nothing to be done. Phew!"
- exit 0
- }
+ $quiet || msg "Found $((${#pkgbuilds[*]}-1)) packages to update"
+ [ ${#pkgbuilds[*]} -eq 1 ] && {
+ $quiet || msg2 "There's nothing to be done. Phew!"
+ exit 0
+ }
-# Traverse all PKGBUILDs found
- for _pkgbuild in ${pkgbuilds[@]}; do
+ for _pkgbuild in ${pkgbuilds[@]}; do
# The repo name is guessed
-# You *must* use a repo/pkgbase structure
- _pkgpath=$(dirname "${_pkgbuild}")
- _pkgbase=$(basename "${_pkgpath}")
- _pkgrepo=$(basename $(dirname "${_pkgpath}"))
+# You *must* use repo/pkgbase structure
+ _pkgpath=$(dirname "${_pkgbuild}")
+ _pkgbase=$(basename "${_pkgpath}")
+ _pkgrepo=$(basename $(dirname "${_pkgpath}"))
- source ${_pkgbuild}
+ source ${_pkgbuild}
- for _pkg in ${pkgname[@]}; do
+ for _pkg in ${pkgname[@]}; do
# Fill the list of packages to find
- packages_to_sync+=($_pkg-$(get_full_version ${epoch:-0} $pkgver $pkgrel))
- done
+ packages_to_sync+=($_pkg-$(get_full_version ${epoch:-0} $pkgver $pkgrel))
+ done
- unset pkgbase pkgname pkgver pkgrel source epoch
- done
+ unset pkgbase pkgname pkgver pkgrel source epoch
+ done
# Get repo database contents
- packages_in_sync=($(get_db_contents ${_pkgrepo}))
- print_package_array "${packages_to_sync[@]}" > ${TMPDIR}/packages_to_sync
- print_package_array "${packages_in_sync[@]}" > ${TMPDIR}/packages_in_sync
+ packages_in_sync=($(get_db_contents ${_pkgrepo}))
+ print_package_array "${packages_to_sync[@]}" > ${TMPDIR}/packages_to_sync
+ print_package_array "${packages_in_sync[@]}" > ${TMPDIR}/packages_in_sync
# We've orderer the files!
needed_updates=($(comm --nocheck-order -32 ${TMPDIR}/packages_to_sync ${TMPDIR}/packages_in_sync))
old_versions=($(comm --nocheck-order -31 ${TMPDIR}/packages_to_sync ${TMPDIR}/packages_in_sync))
missing_packages=($(comm --nocheck-order -12 ${TMPDIR}/packages_to_sync ${TMPDIR}/packages_in_sync))
- $quiet || msg "This packages are available to update"
- for _update in ${needed_updates[@]}; do
- pkg=$(extract_pkgname $_update)
+ $quiet || msg "This packages are available to update"
+ for _update in ${needed_updates[@]}; do
+ pkg=$(extract_pkgname $_update)
# Only print pkgnames when in quiet mode (useful for scripts)
$quiet && echo $pkg
@@ -142,14 +135,14 @@ update() {
ver=$(extract_fullpkgver $_update)
oldver=$(extract_fullpkgver $(grep -w $pkg ${TMPDIR}/packages_in_sync))
- msg2 "$pkg $oldver => $ver"
- }
+ msg2 "$pkg $oldver => $ver"
+ }
- done
+ done
# lastsync
-}
+ }
# Find all the packages that are missing from the repo dbs (aka not built)
missing() {
@@ -178,12 +171,12 @@ done
# This is the syncfile, stores the last date as content and mtime
#lastsyncfile=${ABSROOT}/toru.lastsync
-TMPDIR=$(mktemp -d)
+ TMPDIR=$(mktemp -d)
-[[ -z ${TMPDIR} ]] && exit 1
+ [[ -z ${TMPDIR} ]] && exit 1
-${commands[0]} ${@}
+ ${commands[0]} ${@}
-rm -rf ${TMPDIR}
+ rm -rf ${TMPDIR}
-exit $?
+ exit $?