5 # Copyright (c) 2002-2006 by Andrew Rose <rose.andrew@gmail.com>
6 # I used Judds pacman-optimise as a framework.
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,
25 dbroot
="/var/lib/pacman"
26 pacmandb
="/var/lib/pacman.db"
29 echo "pacman-cage $myver"
30 echo "usage: $0 [pacman_db_root]"
32 echo "pacman-cage creates a loopbacked filesystem in a contigious file."
33 echo "This will give better response times when using pacman"
38 echo "pacman-cage: $*" >&2
47 if [ "$1" != "" ]; then
48 if [ "$1" = "-h" -o "$1" = "--help" ]; then
55 if [ "`id -u`" != 0 ]; then
56 die
"You must be root to cage the database"
59 # make sure pacman isn't running
60 if [ -f /tmp
/pacman.lck
]; then
61 die
"Pacman lockfile was found. Cannot run while pacman is running."
63 # make sure pacman.db hasnt already been made
64 if [ -f $pacmandb ]; then
65 die
"$pacmandb already exists!."
68 if [ ! -d $dbroot ]; then
69 die
"$dbroot does not exist or is not a directory"
72 # don't let pacman run while we do this
75 # step 1: sum the old db
76 echo "==> md5sum'ing the old database..."
77 find $dbroot -type f |
sort |
xargs md5sum >/tmp
/pacsums.old
79 echo "==> creating pacman.db loopback file..."
80 dd if=/dev
/zero of
=$pacmandb bs
=1M count
=150 > /dev
/null
2>&1
82 echo "==> creating ext2 -O dir_index -b 1024 -m 0 on $pacmandb..."
83 yes | mkfs.ext2
-O dir_index
-b 1024 -m 0 $pacmandb > /dev
/null
2>&1
85 echo "==> creating temporary mount point /mnt/tmp-pacman.."
88 echo "==> mounting pacman.db to temporary mount point..."
89 mount
-o loop
$pacmandb /mnt
/tmp-pacman
91 echo "==> copying pacman database to temporary mount point..."
92 cp -a /var
/lib
/pacman
/.
/mnt
/tmp-pacman
94 echo "==> unmounting temporary mount point..."
95 umount
/mnt
/tmp-pacman
97 echo "==> removing temporary mount point..."
100 echo "==> moving old /var/lib/pacman to /var/lib/pacman.bak..."
101 mv /var
/lib
/pacman
/var
/lib
/pacman.bak
103 echo "==> createing new pacman db mount point @ $dbroot..."
106 echo "==> Mounting new pacman db..."
107 mount
-o loop
$pacmandb $dbroot
109 echo "==> md5sum'ing the new database..."
110 find $dbroot -type f |
sort |
xargs md5sum >/tmp
/pacsums.new
112 echo "==> checking integrity..."
113 diff /tmp
/pacsums.old
/tmp
/pacsums.new
>/dev
/null
2>&1
114 if [ $?
-ne 0 ]; then
115 # failed, move the old one back into place
118 mv $dbroot.bak
$dbroot
119 die_r
"integrity check FAILED, reverting to old database"
122 echo "==> Updating /etc/fstab to reflect changes..."
123 echo "$pacmandb $dbroot ext2 loop,defaults 0 0" >> /etc
/fstab
125 rm -f /tmp
/pacman.lck
/tmp
/pacsums.old
/tmp
/pacsums.new
128 echo "Finished. Your pacman database has been caged!. May the speedy pacman be with you."