You are not logged in.

#1 2013-06-02 20:32:02

adam777
Member
Registered: 2012-05-28
Posts: 161

repcheck - A Simple Bash Script To Monitor Remote Repos Commits

Hello all,
I'm using a few git/svn packages from the AUR, and only recently realized that while to PKGBUILD itself is able to pull and build the latest version, the package version in the AUR will not update, unless a new PKGBUILD is pushed by the maintainer, and so my update monitor isn't aware of those remote updates.
I've looked for a convenient way to track such changes, but all I could find were "live" monitors that run constantly and check for updates in a given repo in a set interval.
It didn't fit my needs, so I wrote a script myself.

The script basically maintains a file containing repo address and current revision number (for SVN) or hash (for GIT).
Whenever an update operation is done, all remote hashes are compared to those stored in the file and if updates are found, a notification is sent.
In case of GIT repos, the script also tries to find corresponding AUR package (I couldn't find a standard for SVN addresses...).
It is up to the user to update currently installed version to latest remote version if he wants, script only displays notification.

Dependencies:
- bash
- git
- subversion
- libnotify

* EDIT *
Updated script in next post.

Last edited by adam777 (2013-06-14 11:55:29)

Offline

#2 2013-06-14 11:56:07

adam777
Member
Registered: 2012-05-28
Posts: 161

Re: repcheck - A Simple Bash Script To Monitor Remote Repos Commits

#!/bin/bash

RepVersionsFile=~/repversions
TempRepVersionsFile=~/repversionsupd
TempRepUpdatesFile=~/repupdates

function add_to_list()
{
  if [ -f $RepVersionsFile ]
  then
    tmp=$(cat $RepVersionsFile | grep $1)
    if [ -n "$tmp" ]
    then
      exit
    fi
  fi
  tmp=$(echo $2 | grep ".git")
  if [ -z "$tmp" ]
  then
    current_hash=$(svn info $2 | grep Revision | awk '{ print $NF }')
  else
    current_hash=$(git ls-remote $2 | grep HEAD | awk '{ print $(NF-1) }')
  fi
  echo -e "$1	$2	$current_hash" >> $RepVersionsFile
}

function remove_from_list()
{
  if [ ! -f $RepVersionsFile ]
  then
    exit
  fi
  tmp=$(cat $RepVersionsFile | grep -v $1)
  if [ -z "$tmp" ]
  then
    rm $RepVersionsFile
    exit
  fi
  echo -e "$tmp" > $RepVersionsFile
}

function check_all()
{
  while read pkgname address hash
  do
    tmp=$(echo $address | grep ".git")
    if [ -z "$tmp" ]
    then
      remote_hash=$(svn info $address | grep Revision | awk '{ print $NF }')
    else
      remote_hash=$(git ls-remote $address | grep HEAD | awk '{ print $(NF-1) }')
    fi
    if [ $remote_hash != $hash ]
    then
      echo -e "$pkgname" >> $TempRepUpdatesFile
    fi
    echo -e "$pkgname	$address	$remote_hash" >> $TempRepVersionsFile
  done < $RepVersionsFile
  if [ -f $TempRepUpdatesFile ]
  then
    notify-send "Updates Found On Remote Repos" "`cat $TempRepUpdatesFile`"
    rm $TempRepUpdatesFile
  fi
  rm $RepVersionsFile
  mv $TempRepVersionsFile $RepVersionsFile
}

case $1 in
  add-address)
  add_to_list $2 $3
  ;;
  remove-address)
  remove_from_list $2
  ;;
  update)
  check_all
  ;;
  *)
  echo "Enter Your Choice:";
  echo "1 For Adding A Repository";
  echo "2 For Removing A Repository";
  read userchoice
  if [ "$userchoice" == "1" ]
  then
    echo "Please Enter Package Name";
    read pkgname
    echo "Please Enter Repository Address";
    read repaddress
    repcheck add-address $pkgname $repaddress
  fi
  if [ "$userchoice" == "2" ]
  then
    echo "Please Enter Package Name";
    read pkgname
    repcheck remove-address $pkgname
  fi
esac

Last edited by adam777 (2013-08-07 16:09:00)

Offline

#3 2013-06-14 15:32:48

Spyhawk
Member
Registered: 2006-07-07
Posts: 485

Re: repcheck - A Simple Bash Script To Monitor Remote Repos Commits

In case you are interested: I implemented something similar in pacaur, when checking for devel packages (-Su --devel), but in a different manner. The relevant commit is here.

In a nutshell,
- retrieve the list of foreign packages (-Qm) that end with "-git, -svn, -cvs, -hg, -bzr, -darcs",
- download the relevant PKGBUILDs,
- run makepkg -o (nobuild). Latest commits will be fetched, and the version number in the PKGBUILD will be automatically updated,
- compare that version with the version in the local database,
- if the updated version number is newer, build with makepkg -e (no extract), else skip.

Offline

#4 2013-06-14 23:12:04

adam777
Member
Registered: 2012-05-28
Posts: 161

Re: repcheck - A Simple Bash Script To Monitor Remote Repos Commits

Thanks for the heads up, Spyhawk.
One question, though, are the source files always downloaded from scratch, and only than checked for updates?

Offline

#5 2013-06-15 12:09:50

Spyhawk
Member
Registered: 2006-07-07
Posts: 485

Re: repcheck - A Simple Bash Script To Monitor Remote Repos Commits

Yes, --devel downloads all -git, -svn, etc. PKGBUILDs (parallel download using cower), and then check for update.

Offline

Board footer

Powered by FluxBB