[pacman-dev] new script: repo-local-cleaner

Alessio 'mOLOk' Bolognino themolok.ml at gmail.com
Fri Mar 23 18:26:02 EDT 2007


Sorry guys, 
I sent the old version :(
here is the right one:

------------------------8<--------------------8<--------------8<-------
#!/bin/bash

#   repo-local-cleaner : delete old packages in local repo 
#  
#   Copyright (c) 2007 Alessio 'mOLOk' Bolognino <themolok at gmail.com>
#  
#   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; either version 2 of the License, or
#   (at your option) any later version.
# 
#   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.
#  
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
#   USA.

myver='3.0.0'

source /etc/makepkg.conf # for $CARCH and $USE_COLOR

# default settings:
PKGEXT="pkg.tar.gz"
LOCAL_REPO_DIR="/home/custompkgs"
LOCAL_SRCROOT="/var/abs/local"
LOCAL_REPO_NAME="custom"
RUN_GENSYNC="n"

if [ -r /etc/repo-local-cleaner.conf ]; then
  source /etc/repo-local-cleaner.conf
fi


msg() {
  if [ ! "$USE_COLOR" = "n" ]; then
    echo -e "\033[1;32m==>\033[1;0m \033[1;1m$1\033[1;0m" >&2
  else
    echo "==> $1" >&2
  fi
}

error() {
  if [ ! "$USE_COLOR" = "n" ]; then
    echo -e "\033[1;31m==> ERROR:\033[1;0m \033[1;1m$1\033[1;0m" >&2
  else
    echo "==> ERROR: $1" >&2
  fi
}

usage() {
	echo "repo-local-cleaner $myver"
	echo 
	echo "usage: repo-local-cleaner"
	echo 
	echo "repo-local-cleaner will delete old packages from the local repository."
	echo "If setted in the configuration file, it can run gensync."
	echo "It takes no options."
	echo
}

if [ $# -ne 0 -o "$1" = "-h" -o "$1" = "--help" ]; then
	usage
	exit 0
fi


cd $LOCAL_REPO_DIR
count_rm=0
count_all=0

mkdir -p XXX/

for pack in $(ls -v *-${CARCH}.${PKGEXT}) ; do
  pkgname=${pack%-*-*-${CARCH}.${PKGEXT}}
  if [ "$p_pkgname" = "$pkgname" ]; then
    mv ${p_pack} XXX/${p_pack}
    let count_rm++
  fi
  let count_all++
  p_pack=${pack}
  p_pkgname=${pkgname}
done 

size_removed=$(ls -sh1 XXX/ | awk '{ print $2 }' | head -1)

msg "Checking for old packages..."

if [ "$count_rm" = "0" ]; then
  msg "No package removed"
else
  msg "Removed $count_rm/$count_all old package(s) ( - ${size_removed} )"
fi

rm -fr XXX/

if [ ! "$RUN_GENSYNC" = "n" ]; then
  msg "Running gensync..."
  gensync $LOCAL_SRCROOT $LOCAL_REPO_DIR/$LOCAL_REPO_NAME.db.tar.gz $LOCAL_REPO_DIR/
  if [ "$?" = "0" ]; then
    msg "done!"
  else
    error "gensync failed :("
  fi
fi

# vim: set ts=2 sw=2 noet:
------------------------8<--------------------8<--------------8<-------
Cheers,

-- 
Alessio 'mOLOk' Bolognino
Arch Linux Trusted User
http://www.archlinux.org





More information about the pacman-dev mailing list