[pacman-dev] pacman-optimize updates
Ok, after testing it, some changes needed to be made and so they were made. Now it works (at least for me it worked). This is just an idea, but wouldn't it be interesting if we used the stat_busy, stat_done, and stat_fail stuff from /etc/rc.d/functions for the messages in pacman-optimize? Anyway, here is the patch for FS #5009 (woops, just caught another bug.........it wouldn't be able to work after a successful one but it would work after the failure ('cause pacman.new was still haning around.........fixed). It is below as usual. ~ Jamie / yankees26
On 12/31/06, James Rosten <seinfeld90@gmail.com> wrote:
Ok, after testing it, some changes needed to be made and so they were made. Now it works (at least for me it worked).
This is just an idea, but wouldn't it be interesting if we used the stat_busy, stat_done, and stat_fail stuff from /etc/rc.d/functions for the messages in pacman-optimize?
I like this, using tar. However, I would prefer if this actually went with this approach all the time, so that we could just get rid of the "mounted" check altogether. That is, instead of "if mounted, do this, else do this" we could, fairly easilly, just use the tarball approach to satisfy both conditions. Do you think you could modify the patch like that? If not, I could do it. Thanks alot for your work!
* Aaron Griffin <aaronmgriffin@gmail.com> [070102 11:27]:
I like this, using tar. However, I would prefer if this actually went with this approach all the time, so that we could just get rid of the "mounted" check altogether. That is, instead of "if mounted, do this, else do this" we could, fairly easilly, just use the tarball approach to satisfy both conditions. Do you think you could modify the patch like that? If not, I could do it.
Thanks alot for your work!
Sure, I'll do that. What did you think of the stat_* from /etc/rc.d/functions usage idea? I like it mostly 'cause when running the script makes you know something is happening (plus it looks pretty cool). ~ Jamie / yankees26
On 1/2/07, James Rosten <seinfeld90@gmail.com> wrote:
What did you think of the stat_* from /etc/rc.d/functions usage idea? I like it mostly 'cause when running the script makes you know something is happening (plus it looks pretty cool).
I agree it's a great idea. I think we should use those functions more often to unify the look and feel of official script output.
* Aaron Griffin <aaronmgriffin@gmail.com> [070102 19:58]:
On 1/2/07, James Rosten <seinfeld90@gmail.com> wrote:
What did you think of the stat_* from /etc/rc.d/functions usage idea? I like it mostly 'cause when running the script makes you know something is happening (plus it looks pretty cool).
I agree it's a great idea. I think we should use those functions more often to unify the look and feel of official script output.
I'll add those into the patch. ~ Jamie / yankees26
Ok, here is the patch. I've been unable to test it yet due to being away from my Arch box (if someone else wants to test it, make sure you have a backup of /var/lib/pacman). I'm not even sure if I did the tar method the way the tar method should be done. I've also added the stat_* stuff. The patch is below as usual. ~ Jamie / yankees26
On 1/2/07, James Rosten <seinfeld90@gmail.com> wrote:
Ok, here is the patch. I've been unable to test it yet due to being away from my Arch box (if someone else wants to test it, make sure you have a backup of /var/lib/pacman). I'm not even sure if I did the tar method the way the tar method should be done.
This is in CVS. I haven't tested it, so let me know if it all looks ok from your end.
On 1/3/07, Aaron Griffin <aaronmgriffin@gmail.com> wrote:
This is in CVS. I haven't tested it, so let me know if it all looks ok from your end.
Okay, testing it from CVS showed me some bugs (mostly in how I did error checking). But I fixed it and now it works. Also, I noticed that I did not get colors from the stat_* functions so I added USECOLOR="YES" to get colors before sourcing /etc/rc.d/functions. I expect if an Arch user does not want colors they are capable enough to edit that one line. I am not entirely sure on where to put the "Signed Off" message mentioned in submitting-patches. ~ Jamie / yankees26 Signed-off-by: James Rosten <seinfeld90@gmail.com> Index: pacman-optimize =================================================================== RCS file: /home/cvs-pacman/pacman-lib/scripts/pacman-optimize,v retrieving revision 1.5 diff -u -p -r1.5 pacman-optimize --- ORIG/scripts/pacman-optimize 3 Jan 2007 05:45:18 -0000 1.5 +++ NEW/scripts/pacman-optimize 4 Jan 2007 00:34:17 -0000 @@ -23,9 +23,11 @@ myver='3.0.0' error() { - echo -e "\033[1;31m:: ERROR:\033[1;0m\033[1;1m$@\033[1;0m" >&2 + echo -e "\033[1;31m:: ERROR: \033[1;0m\033[1;1m$@\033[1;0m" >&2 } +# Set USECOLOR so the stat_* functions from /etc/rc.d/functions use color +USECOLOR=YES source /etc/rc.d/functions usage() { @@ -88,16 +90,24 @@ stat_done # step 2: tar it up stat_busy "Tar'ing up $dbroot" cd $dbroot -tar -czf /tmp/pacmanDB.tgz ./ || \ - stat_fail && die_r "tar'ing up $dbroot failed" +tar -czf /tmp/pacmanDB.tgz ./ +if [ $? -ne 0 ]; then + stat_fail + rm -f /tmp/pacmanDB.tgz /tmp/pacsums.old + die_r "tar'ing up $dbroot failed" +fi stat_done # step 3: make and sum the new db stat_busy "Making and md5sum'ing the new db" mkdir $dbroot.new -tar -zxpf /tmp/pacmanDB.tgz -C $dbroot.new/ || \ - stat_fail && die_r "untar'ing $dbroot failed" -find $dbroot.new -type -f | sort | xargs md5sum > /tmp/pacsums.new +tar -zxpf /tmp/pacmanDB.tgz -C $dbroot.new/ +if [ $? -ne 0 ]; then + rm -f /tmp/pacmanDB.tgz /tmp/pacsums.old + rm -rf "$dbroot.new" + die_r "untar'ing $dbroot failed" +fi +find $dbroot.new -type f | sort | sed -e 's/pacman.new/pacman/g' | xargs md5sum > /tmp/pacsums.new stat_done # step 4: compare the sums @@ -110,6 +120,7 @@ if [ $? -ne 0 ]; then rm -rf "$dbroot.new" /tmp/pacman.lck /tmp/pacmanDB.tgz die_r "integrity check FAILED, reverting to old database" fi +stat_done # step 5: remove the new temporary database and the old one # and use the .tgz to replace the old one @@ -119,7 +130,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/pacmsums.old /tmp/pacmsums.new /tmp/pacmanDB.tgz +rm -f /tmp/pacman.lck /tmp/pacsums.old /tmp/pacsums.new /tmp/pacmanDB.tgz echo echo "Finished. Your pacman database has been optimized."
Another patch for cleanup purposes, and a better way to fix the USECOLOR problem- use the user's setting. This should be applied concurrently with the above changes; basically just move the sourcing above the errror function, and use the new error function instead of the old. This revised error function allows for a no-color choice. -Dan Index: pacman-optimize =================================================================== RCS file: /home/cvs-pacman/pacman-lib/scripts/pacman-optimize,v retrieving revision 1.5 diff -u -u -r1.5 pacman-optimize --- pacman-optimize 3 Jan 2007 05:45:18 -0000 1.5 +++ pacman-optimize 6 Jan 2007 05:47:22 -0000 @@ -22,12 +22,17 @@ myver='3.0.0' +source /etc/rc.conf +source /etc/rc.d/functions + error() { - echo -e "\033[1;31m:: ERROR:\033[1;0m\033[1;1m$@\033[1;0m" >&2 + if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then + echo -e "\033[1;31m:: ERROR:\033[1;0m \033[1;1m$@\033[1;0m" >&2 + else + echo ":: ERROR: $@" >&2 + fi } -source /etc/rc.d/functions - usage() { echo "pacman-optimize $myver" echo "usage: $0 [pacman_db_root]"
Applied. Thanks alot guys - sorry for the delay, I was on vacation, and expected to get more computer time than I did (which was 0). I added the rc.conf USECOLOR stuff before I saw Dan's patch, but not for the error function, so that's there as well. - aaron
participants (3)
-
Aaron Griffin
-
Dan McGee
-
James Rosten