pt-pacman-uncage 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.
  12. #
  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.
  17. #
  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.
  22. #
  23. myver='2.9.8'
  24. dbroot="/var/lib/pacman"
  25. tmproot="/var/lib/pacman.new"
  26. pacmandb="/var/lib/pacman.db"
  27. usage() {
  28. echo "pacman-uncage $myver"
  29. echo "usage: $0 [pacman_db_root]"
  30. echo
  31. echo "pacman-uncage returns your pacman db to the generic style."
  32. echo
  33. }
  34. die() {
  35. echo "pacman-uncage: $*" >&2
  36. exit 1
  37. }
  38. die_r() {
  39. rm -f /tmp/pacman.lck
  40. die $*
  41. }
  42. if [ "$1" != "" ]; then
  43. if [ "$1" = "-h" -o "$1" = "--help" ]; then
  44. usage
  45. exit 0
  46. fi
  47. dbroot=$1
  48. fi
  49. if [ "`id -u`" != 0 ]; then
  50. die "You must be root to uncage the database"
  51. fi
  52. # make sure pacman isn't running
  53. if [ -f /tmp/pacman.lck ]; then
  54. die "Pacman lockfile was found. Cannot run while pacman is running."
  55. fi
  56. if [ ! -d $dbroot ]; then
  57. die "$dbroot does not exist or is not a directory"
  58. fi
  59. # don't let pacman run while we do this
  60. touch /tmp/pacman.lck
  61. # step 1: sum the old db
  62. echo "==> md5sum'ing the old database..."
  63. find $dbroot -type f | sort | xargs md5sum >/tmp/pacsums.old
  64. echo "==> copying pacman.db contents back, note: the time needed to get a brew is now."
  65. mkdir $tmproot
  66. cp -a $dbroot/. $tmproot
  67. echo "==> unmounting old dbroot and moving new one in"
  68. umount $dbroot
  69. rmdir $dbroot
  70. mv $tmproot $dbroot
  71. echo "==> md5sum'ing the new database..."
  72. find $dbroot -type f | sort | xargs md5sum >/tmp/pacsums.new
  73. echo "==> checking integrity..."
  74. diff /tmp/pacsums.old /tmp/pacsums.new >/dev/null 2>&1
  75. if [ $? -ne 0 ]; then
  76. # failed, move the old one back into place
  77. rm -rf $dbroot
  78. mkdir $dbroot
  79. mount -a
  80. die_r "integrity check FAILED, reverting to old database"
  81. fi
  82. echo "==> Removing old pacman.db"
  83. rm $pacmandb
  84. rm -f /tmp/pacman.lck /tmp/pacsums.old /tmp/pacsums.new
  85. echo
  86. echo "Finished. Your pacman database has been uncaged!. Welcome home."
  87. echo "You will need to remove the old mount line from your /etc/fstab"
  88. echo
  89. exit 0