You are not logged in.

#1 2007-08-15 16:26:30

dninja
Member
From: Sheffield, UK
Registered: 2006-04-29
Posts: 374
Website

can you run a script before a package is upgraded?

For security I have my boot partition set not to automatically mount on boot. This causes a problem when pacman comes to upgrade the kernel as it puts the files for the upgrade into the mount directory, not onto the real boot partition.

Is there any way to get pacman to run a script before and after it upgrades certain packages? In my case I would get it to mount /boot, upgrade the kernel, then unmount it.

Offline

#2 2007-08-15 16:39:22

FeatherMonkey
Member
Registered: 2007-02-26
Posts: 313

Re: can you run a script before a package is upgraded?

Couldn't you just use an alias seems to work fine here, not elegant but minimalist, No check just mount and no umount, just mounts on pacman call but seems to pass the other bits fine. ie pacman -Ss foo will mount then search.

alias pacman='mount /dev/hda? /mnt & pacman'

Offline

#3 2007-08-15 16:43:57

dninja
Member
From: Sheffield, UK
Registered: 2006-04-29
Posts: 374
Website

Re: can you run a script before a package is upgraded?

I could do but it would be nice if pacman had the facility to do this kind of thing.

Also, if pacman fails then the umount may not get ran.

Offline

#4 2007-08-15 16:49:39

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: can you run a script before a package is upgraded?

add to your bashrc:

function mount_pm()
{
    mount /boot
    pacman $*
    umount /boot
}
alias pacman="mount_pm"

Unfortunately, pacman doesn't have that facility - it could, theoretically, be built into the kernel packages directly.  Might be worth consideration.

Offline

#5 2007-08-15 16:52:28

dninja
Member
From: Sheffield, UK
Registered: 2006-04-29
Posts: 374
Website

Re: can you run a script before a package is upgraded?

Does that function guarantee to run the umount even if pacman bombs out?

Offline

#6 2007-08-15 16:54:19

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: can you run a script before a package is upgraded?

dninja wrote:

Does that function guarantee to run the umount even if pacman bombs out?

I'm pretty sure - I'm not at my home box right now so I can't try.  You could always just try it yourself - run a pacman operation that fails (pacman -S asdfasdfasdf) and see if the dir's unmounted.

Offline

#7 2007-08-15 16:57:48

dninja
Member
From: Sheffield, UK
Registered: 2006-04-29
Posts: 374
Website

Re: can you run a script before a package is upgraded?

I was thinking more about if pacman actually crashed rather than just a command that fails.

I haven't had pacman crash on me so I'm  not too worried about it but it is something to consider.

Offline

#8 2007-08-15 17:15:52

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: can you run a script before a package is upgraded?

Yeah, the unmount should happen even if pacman crashes horribly.  I did this to test (programmers might get a laugh out of this):

Added this to .bashrc:

function mount_pm()
{
    echo "a"
    ./segfault
    echo "b"
}

Then did the following on the command line:

$ source ~/.bashrc
$ cat > segfault.c  
int main() { int * a = 0; (*a)++; }
$ gcc -o segfault segfault.c 
$ mount_pm
a
Segmentation fault (core dumped)
b
$

So, as you can see, I built a program designed to do nothing but crash, and echo "b" still executed. wink

Offline

#9 2007-08-15 17:24:31

dninja
Member
From: Sheffield, UK
Registered: 2006-04-29
Posts: 374
Website

Re: can you run a script before a package is upgraded?

nice, thanks.

Offline

Board footer

Powered by FluxBB