#!/bin/bash # # pacman-uncage # # Copyright (c) 2002-2006 by Andrew Rose # I used Judds pacman-optimise as a framework. # # 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='2.9.9' dbroot="/var/lib/pacman" tmproot="/var/lib/pacman.new" pacmandb="/var/lib/pacman.db" pacmanlog=$(pacman -Qv | grep "Log File" | cut -d ":" -f2) usage() { echo "pacman-uncage $myver" echo "usage: $0 [pacman_db_root]" echo echo "pacman-uncage returns your pacman db to the generic style." echo } die() { echo "pacman-uncage: $*" >&2 exit 1 } die_r() { rm -f /tmp/pacman.lck die $* } if [[ "$1" != "" ]]; then if [[ "$1" == "-h" || "$1" == "--help" ]]; then usage exit 0 fi dbroot=$1 fi [[ $(id -u) != 0 ]] && die "You must be root to uncage the database" # added by wain: make sure pacmandb is mounted if ! mount -l | grep $dbroot >/dev/null; then die "Pacmandb must be mounted" fi # make sure pacman isn't running [[ -f /tmp/pacman.lck ]] && die "Pacman lockfile was found. Cannot run while pacman is running." [[ ! -d $dbroot ]] && die "$dbroot does not exist or is not a directory" # don't let pacman run while we do this touch /tmp/pacman.lck # write to pacman.log echo "[ $(date '+%Y-%m-%d %H:%M ')] Pacman-cage [cmd] >> Starting and preparing pacmandb uncaging process ..." >> $pacmanlog # step 1: sum the old db echo "==> md5sum'ing the old database..." find $dbroot -type f | sort | xargs md5sum >/tmp/pacsums.old echo "==> copying pacman.db contents back, note: the time needed to get a brew is now." mkdir $tmproot cp -a $dbroot/. $tmproot echo "==> unmounting old dbroot and moving new one in" umount $dbroot rmdir $dbroot mv $tmproot $dbroot echo "==> md5sum'ing the new database..." find $dbroot -type f | sort | xargs md5sum >/tmp/pacsums.new echo "==> checking integrity..." diff /tmp/pacsums.old /tmp/pacsums.new &>/dev/null if [[ $? != 0 ]]; then # failed, move the old one back into place rm -rf $dbroot mkdir $dbroot mount -o loop $pacmandb $dbroot echo "[ $(date '+%Y-%m-%d %H:%M ')] Pacman-cage [cmd] >> Something went wrong. $pacmandb remounted to $dbroot." >> $pacmanlog die_r "integrity check FAILED, reverting to old database" fi echo "==> Removing old pacman.db" rm $pacmandb rm -f /tmp/pacman.lck /tmp/pacsums.old /tmp/pacsums.new echo "[ $(date '+%Y-%m-%d %H:%M ')] Pacman-cage [cmd] >> Pacman database has been uncaged." >> $pacmanlog echo echo "Finished. Your pacman database has been uncaged! Welcome home." echo exit 0