summaryrefslogtreecommitdiffstats
path: root/scripts/pacman-optimize.in
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/pacman-optimize.in')
-rw-r--r--scripts/pacman-optimize.in40
1 files changed, 23 insertions, 17 deletions
diff --git a/scripts/pacman-optimize.in b/scripts/pacman-optimize.in
index 2bfec40e..cce4a5c1 100644
--- a/scripts/pacman-optimize.in
+++ b/scripts/pacman-optimize.in
@@ -21,6 +21,11 @@
#
myver='@PACKAGE_VERSION@'
+#TODO replace with configure-time db location
+dbroot="/var/lib/pacman"
+#TODO replace with configure-time lockfile location
+lockfile="/tmp/pacman.lck"
+
error() {
if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then
@@ -30,11 +35,12 @@ error() {
fi
}
-source /etc/rc.conf #for USECOLOR
-source /etc/rc.d/functions
+# determine current USECOLOR setting
+#[ -f "/etc/rc.conf" ] && source /etc/rc.conf
+#[ -f "/etc/rc.d/functions" ] && source /etc/rc.d/functions
usage() {
- echo "pacman-optimize $myver"
+ echo "pacman-optimize (pacman) $myver"
echo "usage: $0 [pacman_db_root]"
echo
echo "pacman-optimize is a little hack that should improve the performance"
@@ -64,26 +70,26 @@ die() {
}
die_r() {
- rm -f /tmp/pacman.lck
+ rm -f $lockfile
die $@
}
-dbroot="/var/lib/pacman"
+if [ "$1" = "-h" -o "$1" = "--help" ]; then
+ usage
+ exit 0
+fi
+
+if [ "$1" = "-V" -o "$1" = "--version" ]; then
+ version
+ exit 0
+fi
if [ "$1" != "" ]; then
- if [ "$1" = "-h" -o "$1" = "--help" ]; then
- usage
- exit 0
- fi
- if [ "$1" = "-V" -o "$1" = "--version" ]; then
- version
- exit 0
- fi
dbroot="$1"
fi
# make sure pacman isn't running
-if [ -f /tmp/pacman.lck ]; then
+if [ -f $lockfile ]; then
die "Pacman lockfile was found. Cannot run while pacman is running."
fi
@@ -96,7 +102,7 @@ if [ ! -w "$dbroot" ]; then
fi
# do not let pacman run while we do this
-touch /tmp/pacman.lck
+touch $lockfile
# step 1: sum the old db
stat_busy "Md5sum'ing the old database"
@@ -134,7 +140,7 @@ if [ $? -ne 0 ]; then
# failed
stat_fail
# leave /tmp/pacsums.old and .new for checking to see what doesn't match up
- rm -rf "$dbroot.new" /tmp/pacman.lck /tmp/pacmanDB.tgz
+ rm -rf "$dbroot.new" $lockfile /tmp/pacmanDB.tgz
die_r "integrity check FAILED, reverting to old database"
fi
stat_done
@@ -147,7 +153,7 @@ tar -zxpf /tmp/pacmanDB.tgz -C "$dbroot"/
stat_done
# remove the lock file, sum files, and .tgz of database
-rm -f /tmp/pacman.lck /tmp/pacsums.old /tmp/pacsums.new /tmp/pacmanDB.tgz
+rm -f $lockfile /tmp/pacsums.old /tmp/pacsums.new /tmp/pacmanDB.tgz
echo
echo "Finished. Your pacman database has been optimized."