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_size(MB)"
32 echo "pacman-cage creates a loopbacked filesystem in a contigious file."
33 echo "This will give better response times when using pacman"
34 echo "A safe value for pacman_db_size should be > 40"
36 echo "If you are unsure, use this:"
42 echo "pacman-cage: $*" >&2
51 loop_check
=`zcat /proc/config.gz | grep CONFIG_BLK_DEV_LOOP | cut -d\= -f2`
53 if [ "$loop_check" == "m" ]; then
54 if [ `lsmod | grep loop | cut -d\ -f1` != "loop" ]; then
55 echo "Error. You have to load the module 'loop' in rc.conf."
60 if [ "$loop_check" == "CONFIG_BLK_DEV_LOOP" ]; then
61 echo "Error. Your kernel config doesn't include CONFIG_BLK_DEV_LOOP."
66 if [ "$#" != "1" ]; then echo "wrong number of parameters" 1>&2 ; usage
; exit 0; fi
68 if [ "$1" != "" ]; then
69 if [ "$1" = "-h" -o "$1" = "--help" ]; then
76 if [ "`id -u`" != 0 ]; then
77 die
"You must be root to cage the database"
80 # make sure pacman isn't running
81 if [ -f /tmp
/pacman.lck
]; then
82 die
"Pacman lockfile was found. Cannot run while pacman is running."
84 # make sure pacman.db hasnt already been made
85 if [ -f $pacmandb ]; then
86 die
"$pacmandb already exists!."
89 if [ ! -d $dbroot ]; then
90 die
"$dbroot does not exist or is not a directory"
93 # don't let pacman run while we do this
96 # step 1: sum the old db
97 echo "==> md5sum'ing the old database..."
98 find $dbroot -type f |
sort |
xargs md5sum >/tmp
/pacsums.old
100 echo "==> creating pacman.db loopback file..."
101 dd if=/dev
/zero of
=$pacmandb bs
=1M count
=$dbsize > /dev
/null
2>&1
103 echo "==> creating ext2 -O dir_index -b 1024 -m 0 on $pacmandb..."
104 yes | mkfs.ext2
-O dir_index
-b 1024 -i 1024 -m 0 -F $pacmandb > /dev
/null
2>&1
106 echo "==> creating temporary mount point /mnt/tmp-pacman.."
107 mkdir
/mnt
/tmp-pacman
109 echo "==> mounting pacman.db to temporary mount point..."
110 mount
-o loop
$pacmandb /mnt
/tmp-pacman
112 echo "==> copying pacman database to temporary mount point..."
113 cp -a /var
/lib
/pacman
/.
/mnt
/tmp-pacman
115 echo "==> unmounting temporary mount point..."
116 umount
/mnt
/tmp-pacman
118 echo "==> removing temporary mount point..."
119 rmdir /mnt
/tmp-pacman
121 echo "==> moving old /var/lib/pacman to /var/lib/pacman.bak..."
122 mv /var
/lib
/pacman
/var
/lib
/pacman.bak
124 echo "==> createing new pacman db mount point @ $dbroot..."
127 echo "==> Mounting new pacman db..."
128 mount
-o loop
$pacmandb $dbroot
130 echo "==> md5sum'ing the new database..."
131 find $dbroot -type f |
sort |
xargs md5sum >/tmp
/pacsums.new
133 echo "==> checking integrity..."
134 diff /tmp
/pacsums.old
/tmp
/pacsums.new
>/dev
/null
2>&1
135 if [ $?
-ne 0 ]; then
136 # failed, move the old one back into place
139 mv $dbroot.bak
$dbroot
140 die_r
"integrity check FAILED, reverting to old database"
143 echo "==> Updating /etc/fstab to reflect changes..."
144 echo "$pacmandb $dbroot ext2 loop,defaults 0 0" >> /etc
/fstab
146 rm -f /tmp
/pacman.lck
/tmp
/pacsums.old
/tmp
/pacsums.new
149 echo "Finished. Your pacman database has been caged!. May the speedy pacman be with you."