summaryrefslogtreecommitdiff
path: root/toru
diff options
context:
space:
mode:
Diffstat (limited to 'toru')
-rwxr-xr-xtoru144
1 files changed, 79 insertions, 65 deletions
diff --git a/toru b/toru
index 3304491..2d42abc 100755
--- a/toru
+++ b/toru
@@ -81,7 +81,7 @@ get_full_version() {
# Outputs an ordered package-fullpkgver array
print_package_array() {
- echo "$@" | tr " " "\n" | sort -V -u
+ echo "$@" | tr " " "\n" | sort -u
}
@@ -90,18 +90,31 @@ print_package_array() {
get_db_contents() {
[ ! -r /var/lib/pacman/sync/$1.db ] && return 0
- bsdtar -tf /var/lib/pacman/sync/$1.db | cut -d'/' -f1
+ bsdtar -tf /var/lib/pacman/sync/$1.db | cut -d'/' -f1 | sort -u
}
# Get the pkgname
+# pkgname from pkgver separator can be either '-' or ' '
extract_pkgname() {
- echo "$@" | tr " " "\n" | sed "s/^\(.\+\)-[^-]\+-[^-]\+$/\1/"
+ echo "$@" | tr " " "\n" | sed "s/^\(.\+\)[- ][^-]\+-[^-]\+$/\1/"
+}
+
+# Get all the pkgnames from a file
+# pkgname from pkgver separator can be either '-' or ' '
+extract_pkgname_from_file() {
+ sed "s/^\(.\+\)[- ][^-]\+-[^-]\+$/\1/" $1
+}
+
+# Split pkgnames from pkgvers
+split_pkgname_from_pkgver() {
+ sed "s/^\(.\+\)-\([^-]\+-[^-]\+\)$/\1 \2/" $1
}
# Get the fullpkgver
+# pkgname from pkgver separator can be either '-' or ' '
extract_fullpkgver() {
- echo "$@" | tr " " "\n" | sed "s/^.\+-\([^-]\+-[^-]\+\)$/\1/"
+ echo "$@" | tr " " "\n" | sed "s/^.\+[ -]\([^-]\+-[^-]\+\)$/\1/"
}
@@ -111,105 +124,106 @@ 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_in_abs=()
+ local packages_in_sync=()
+ local need_update=()
# Traverse all specified repos
- for _repo in $@; do
- if ! in_array ${_repo} ${REPOS[@]}; then
- warning "You don't have access to this repo (check REPOS at libretools.conf)"
- continue
- fi
+ for _repo in $@; do
+ if ! in_array ${_repo} ${REPOS[@]}; then
+ warning "You don't have access to this repo (check REPOS at libretools.conf)"
+ continue
+ fi
# Find all the PKGBUILDs newer than the last update
# Update newer, otherwise everything
- if [[ $force = true || ! -e ${lastsyncfile} ]]; then
- $quiet || msg "Forcing upgrade"
- pkgbuilds=($(find ${_repo} -maxdepth 2 -type f -name 'PKGBUILD'))
- else
- pkgbuilds=($(find ${_repo} -maxdepth 2 -type f -name 'PKGBUILD' -newer ${lastsyncfile}))
- packages_to_sync=($(read_cache ${_repo}))
- msg2 "Getting ${#packages_to_sync[@]} packages from cache"
- fi
+ if [[ $force = true || ! -e ${lastsyncfile} ]]; then
+ $quiet || warning "Forcing upgrade"
+ pkgbuilds=($(find ${_repo} -maxdepth 2 -type f -name 'PKGBUILD'))
+ else
+ pkgbuilds=($(find ${_repo} -maxdepth 2 -type f -name 'PKGBUILD' -newer ${lastsyncfile}))
+ packages_in_abs=($(read_cache ${_repo}))
+ $quiet || msg2 "Getting ${#packages_in_abs[@]} packages from cache"
+ 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)) PKGBUILDs to update"
+ if [ ${#pkgbuilds[*]} -eq 1 ]; then
+ $quiet || msg2 "There's nothing to be done. Phew!"
+ exit 0
+ fi
# Traverse all found PKGBUILDs
- for _pkgbuild in ${pkgbuilds[@]}; do
+ for _pkgbuild in ${pkgbuilds[@]}; do
# The repo name is guessed
# You *must* use repo/pkgbase structure
- _pkgpath=$(dirname "${_pkgbuild}")
- _pkgbase=$(basename "${_pkgpath}")
+ _pkgpath=$(dirname "${_pkgbuild}")
+ _pkgbase=$(basename "${_pkgpath}")
# Load PKGBUILD's metadata
- source ${_pkgbuild}
+ source ${_pkgbuild}
# We won't need this
- unset build package url md5sums install pkgdesc backup options
+ unset build package url md5sums install pkgdesc backup options
# TODO fill a license list
- unset license
+ unset license
# TODO create source tarballs?
- unset mksource
+ unset mksource
# TODO solve dependency tree?
- unset depends makedepends
+ unset depends makedepends
- for _pkg in ${pkgname[@]}; do
+ for _pkg in ${pkgname[@]}; do
# Keep removing unneeded stuff
- unset package_${_pkg} >/dev/null 2>&1
+ unset package_${_pkg} >/dev/null 2>&1
# Fill the list of packages to find
- packages_to_sync+=($_pkg-$(get_full_version ${epoch:-0} $pkgver $pkgrel))
- done
+ packages_in_abs+=($_pkg-$(get_full_version ${epoch:-0} $pkgver $pkgrel))
+ done # end pkgnames
- unset pkgbase pkgname pkgver pkgrel source epoch
- done
+ unset pkgbase pkgname pkgver pkgrel source epoch
+ done # end pkgbuilds
# Get repo database contents
packages_in_sync=($(get_db_contents ${_repo}))
- print_package_array "${packages_to_sync[@]}" > ${TMPDIR}/packages_to_sync
+# Drops arrays into files
+ print_package_array "${packages_in_abs[@]}" > ${TMPDIR}/packages_in_abs
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))
+ unset packages_in_abs package_in_sync
- $quiet || msg "This packages are available to update"
- for _update in ${needed_updates[@]}; do
- pkg=$(extract_pkgname $_update)
+# Use a different separator for pkgnames and pkvers
+# so we can join them by pkgname
+ split_pkgname_from_pkgver ${TMPDIR}/packages_in_abs | sort -k1b,1 > ${TMPDIR}/in_abs
+ split_pkgname_from_pkgver ${TMPDIR}/packages_in_sync | sort -k1b,1 > ${TMPDIR}/in_sync
-# Only print pkgnames when in quiet mode (useful for scripts)
- $quiet && echo $pkg
- $quiet || {
- ver=$(extract_fullpkgver $_update)
- oldver=$(extract_fullpkgver $(grep -w $pkg ${TMPDIR}/packages_in_sync))
+ $quiet || msg "This packages are available to update"
+# Join both files by pkgname, the end result is:
+# pkgname syncver absver
+ join ${TMPDIR}/in_sync ${TMPDIR}/in_abs | \
+ while read need_line; do
+ _pkg=$(echo "${need_line}" | cut -d' ' -f1)
+ _syncver=$(echo "${need_line}" | cut -d' ' -f2)
+ _absver=$(echo "${need_line}" | cut -d' ' -f3)
- msg2 "$pkg $oldver => $ver"
- }
+# If the versions differ we need an update
+ if [ "${_syncver}" != "${_absver}" ]; then
+ $quiet || msg2 "$_pkg update from $_syncver to $_absver"
+ $quiet && echo "$_pkg"
+ fi
+ done # end need_line
- done
+ unset _pkg _syncver _absver need_line
# Save the cache
- store_cache ${_repo} ${TMPDIR}/packages_to_sync
-
- unset packages_to_sync packages_in_sync needed_updates old_versions pkg \
- ver oldver
+ store_cache ${_repo} ${TMPDIR}/packages_in_abs
- done
+ done # end repos
lastsync
-
}
# Find all the packages that are missing from the repo dbs (aka not built)
@@ -249,6 +263,6 @@ msg2 "read lastsync: $([ -e $lastsyncfile ])"
${commands[0]} ${@}
-rm -rf ${TMPDIR}
+#rm -rf ${TMPDIR}
exit $?