updated on Sat Jan 14 12:12:45 UTC 2012
[aur-mirror.git] / pacman-cage / pacman-uncage
blob25f8a8f914b982a040bf6db2c747fb2f9ac90d63
1 #!/bin/bash
2 #
3 # pacman-uncage
4 #
5 # Copyright (c) 2002-2006 by Andrew Rose <rose.andrew@gmail.com>
6 # I used Judds pacman-optimise as a framework.
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 # USA.
24 myver='2.9.8'
25 dbroot="/var/lib/pacman"
26 tmproot="/var/lib/pacman.new"
27 pacmandb="/var/lib/pacman.db"
28 pacmanlog=$(pacman -Qv | grep "Log File" | cut -d ":" -f2)
30 usage() {
31 echo "pacman-uncage $myver"
32 echo "usage: $0 [pacman_db_root]"
33 echo
34 echo "pacman-uncage returns your pacman db to the generic style."
35 echo
38 die() {
39 echo "pacman-uncage: $*" >&2
40 exit 1
43 die_r() {
44 rm -f /tmp/pacman.lck
45 die $*
48 if [ "$1" != "" ]; then
49 if [ "$1" = "-h" -o "$1" = "--help" ]; then
50 usage
51 exit 0
52 fi
53 dbroot=$1
54 fi
56 if [ "`id -u`" != 0 ]; then
57 die "You must be root to uncage the database"
60 # added by wain: make sure pacmandb is mounted
61 if ! mount -l | grep $dbroot >/dev/null; then
62 die "Pacmandb must be mounted"
65 # make sure pacman isn't running
66 if [ -f /tmp/pacman.lck ]; then
67 die "Pacman lockfile was found. Cannot run while pacman is running."
68 fi
70 if [ ! -d $dbroot ]; then
71 die "$dbroot does not exist or is not a directory"
72 fi
74 # don't let pacman run while we do this
75 touch /tmp/pacman.lck
77 # write to pacman.log
78 echo "[ $(date "+%Y-%m-%d %H:%M ")] Pacman-cage [cmd] >> Starting and preparing pacmandb uncaging process ..." >> ${pacmanlog}
80 # step 1: sum the old db
81 echo "==> md5sum'ing the old database..."
82 find $dbroot -type f | sort | xargs md5sum >/tmp/pacsums.old
84 echo "==> copying pacman.db contents back, note: the time needed to get a brew is now."
85 mkdir $tmproot
86 cp -a $dbroot/. $tmproot
88 echo "==> unmounting old dbroot and moving new one in"
89 umount $dbroot
90 rmdir $dbroot
91 mv $tmproot $dbroot
93 echo "==> md5sum'ing the new database..."
94 find $dbroot -type f | sort | xargs md5sum >/tmp/pacsums.new
96 echo "==> checking integrity..."
97 diff /tmp/pacsums.old /tmp/pacsums.new >/dev/null 2>&1
98 if [ $? -ne 0 ]; then
99 # failed, move the old one back into place
100 rm -rf $dbroot
101 mkdir $dbroot
102 mount -o loop $pacmandb $dbroot
103 echo "[ $(date "+%Y-%m-%d %H:%M ")] Pacman-cage [cmd] >> Something went wrong. $pacmandb remounted to $dbroot." >> ${pacmanlog}
104 die_r "integrity check FAILED, reverting to old database"
107 echo "==> Removing old pacman.db"
108 rm $pacmandb
110 rm -f /tmp/pacman.lck /tmp/pacsums.old /tmp/pacsums.new
112 echo "[ $(date "+%Y-%m-%d %H:%M ")] Pacman-cage [cmd] >> Pacman database has been uncaged." >> ${pacmanlog}
113 echo
114 echo "Finished. Your pacman database has been uncaged!. Welcome home."
115 #echo "You will need to remove the old mount line from your /etc/fstab"
116 echo "You can remove 'pacmandb' from daemon's list in /etc/rc.conf file"
117 echo
119 exit 0