You are not logged in.

#1 2010-07-27 14:59:00

skodabenz
Banned
From: Tamilnadu, India
Registered: 2010-04-11
Posts: 382

[SOLVED] Pass Environment variables from PKGBUILD to .INSTALL script

Hi everyone,
                   I am trying to modify the grub2-efi-bzr (http://aur.archlinux.org/packages.php?ID=38369) package making some changes in the PKGBUILD and the post-install script. I want to pass few environment variables from the PKGBUILD to the install script. How do I do that?

Some code from the PKGBUILD

_bzrtrunk="lp:grub/grub2" # GRUB2 BZR Main Trunk
# _bzrtrunk="lp:~skodabenz/grub/grub2-bzr-exp" # GRUB2 BZR Experimental Branch

_bzrmod="grub2"

if [ ${_bzrtrunk} = "lp:~skodabenz/grub/grub2-bzr-exp" ]
then
    _bzrmod="grub2_exp"
    pkgver="exp_${pkgver}"
fi

# grub-extras bzr repo locations
_bzrtrunk_zfs="lp:~skodabenz/grub/grub2-extras-zfs"
_bzrtrunk_lua="lp:~skodabenz/grub/grub2-extras-lua"

if [ "$CARCH" = 'i686' ]
then
    _EFI_ARCH=i386
elif [ "$CARCH" = 'x86_64' ]
then
    _EFI_ARCH=x86_64
fi

# _EFI_ARCH=x86_64 # Uncomment if you want to override the if condition for _EFI_ARCH above, incase the EFI ARCH does not match the Linux Kernel ARCH.

# $CARCH=x86_64 and _EFI_ARCH=i386 requires gcc-multilib with lib32-glibc installed in the system.
# I do not know about $CARCH=i686 and _EFI_ARCH=x86_64

if [ ${_EFI_ARCH} = "i386" ]
then
    pkgver="${pkgver}_x86"
    _trns_name="grub2_efi_x86"
elif [ ${_EFI_ARCH} = "x86_64" ] 
then
    pkgver="${pkgver}_x64"
    _trns_name="grub2_efi_x64"
fi

Now the post-install script needs the values of _EFI_ARCH and _trns_name env variables. I do not want to copy the if statements to that script as these are decided at compile time but needed while setting up grub2-efi. This is due to the fact that EFI-ARCH need not match the Linux Kernel ARCH. How do I do that.

Code from the post-install script

${_trns_name}-install --root-directory=/ --no-floppy --recheck --debug

cp /usr/lib/${_trns_name}/${_EFI_ARCH}-efi/lua.mod /boot/${_trns_name}/
cp /usr/lib/${_trns_name}/${_EFI_ARCH}-efi/zfs.mod /boot/${_trns_name}/
cp /usr/lib/${_trns_name}/${_EFI_ARCH}-efi/zfsinfo.mod /boot/${_trns_name}/

cp /usr/lib/${_trns_name}/${_EFI_ARCH}-efi/unifont.pf2 /boot/${_trns_name}/
cp /usr/lib/${_trns_name}/${_EFI_ARCH}-efi/ascii.pf2 /boot/${_trns_name}/

${_trns_name}-mkimage --verbose --directory=/usr/lib/${_trns_name}/${_EFI_ARCH}-efi --prefix="" --output=/boot/${_trns_name}/grub2.efi --format=${_EFI_ARCH}-efi ${_EFI_APP_MODULES}

Thank in advance.

Last edited by skodabenz (2010-07-27 15:46:40)


My new forum user/nick name is "the.ridikulus.rat" .

Offline

#2 2010-07-27 15:12:48

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] Pass Environment variables from PKGBUILD to .INSTALL script

I recommend looking at kernel26's PKGBUILD to see how this is done elsewhere.

Short version: edit the install scriptlet with sed when the package is built.

Offline

#3 2010-07-27 15:45:21

skodabenz
Banned
From: Tamilnadu, India
Registered: 2010-04-11
Posts: 382

Re: [SOLVED] Pass Environment variables from PKGBUILD to .INSTALL script

Thanks. I used sed as you suggested and it works. If possible can you check whether the PKGBUILD is correct.


My new forum user/nick name is "the.ridikulus.rat" .

Offline

#4 2010-07-27 16:29:38

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] Pass Environment variables from PKGBUILD to .INSTALL script

Don't rely on %foo% existing -- it won't after the first build and this will prevent the PKGBUILD from being reentrant. I would use something like this (untested):

sed -i "s|^\(_EFI_ARCH\)=.*|\1=${_EFI_ARCH}|; \
        s|^\(_trns_name\)=.*|\1=${_trns_name}|; \
        s|^\(export _EFI_APP_MODULES\)=.*|\1=${_EFI_APP_MODULES}|" \
        ${startdir}/grub2-efi-bzr.install

Offline

#5 2010-07-28 08:48:06

skodabenz
Banned
From: Tamilnadu, India
Registered: 2010-04-11
Posts: 382

Re: [SOLVED] Pass Environment variables from PKGBUILD to .INSTALL script

falconindy wrote:

Don't rely on %foo% existing -- it won't after the first build and this will prevent the PKGBUILD from being reentrant. I would use something like this (untested):

sed -i "s|^\(_EFI_ARCH\)=.*|\1=${_EFI_ARCH}|; \
        s|^\(_trns_name\)=.*|\1=${_trns_name}|; \
        s|^\(export _EFI_APP_MODULES\)=.*|\1=${_EFI_APP_MODULES}|" \
        ${startdir}/grub2-efi-bzr.install

Your code works except for 1 problem in the install script I want

export __EFI_APP_MODULES="${_EFI_APP_MODULES}" (the passed ${_EFI_APP_MODULES} value should again come inside double quotes).


right now

export _EFI_APP_MODULES=ata part_gpt part_msdos fat ntfs ntfscomp ext2 iso9660 udf hfsplus fshelp normal chain linux ls search search_fs_file search_fs_uuid search_label help loopback boot configfile echo efi_gop efi_uga xnu xnu_uuid lvm

which is equivalent to

export _EFI_APP_MODULES=ata

I want

export _EFI_APP_MODULES="ata part_gpt part_msdos fat ntfs ntfscomp ext2 iso9660 udf hfsplus fshelp normal chain linux ls search search_fs_file search_fs_uuid search_label help loopback boot configfile echo efi_gop efi_uga xnu xnu_uuid lvm"

How to do it with sed since sed already uses double quotes?


My new forum user/nick name is "the.ridikulus.rat" .

Offline

#6 2010-07-28 11:18:10

skodabenz
Banned
From: Tamilnadu, India
Registered: 2010-04-11
Posts: 382

Re: [SOLVED] Pass Environment variables from PKGBUILD to .INSTALL script

I used Double quotes inside single quotes for _EFI_APP_MODULES in the PKGBUILD and that solved the problem. Thanks for the help. Can you check the PKGBUILD now?

_EFI_APP_MODULES='"ata part_gpt part_msdos fat ntfs ntfscomp ext2 iso9660 udf hfsplus fshelp normal chain linux ls search search_fs_file search_fs_uuid search_label help loopback boot configfile echo efi_gop efi_uga xnu xnu_uuid lvm"'

Solution from : http://www.tek-tips.com/viewthread.cfm? … 6&page=101

Last edited by skodabenz (2010-07-28 11:36:43)


My new forum user/nick name is "the.ridikulus.rat" .

Offline

#7 2010-07-28 14:26:27

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] Pass Environment variables from PKGBUILD to .INSTALL script

Escaping double quotes inside the sed expression would work as well. This might be a bit cleaner, as an overly curious user might be tempted to remove the single quotes.

Rest of it looks fine by me, but I'm by no means a proper substitute for a Bash interpreter, or makepkg. Does it build? Does it rebuild correctly?

Offline

#8 2010-07-28 14:29:56

skodabenz
Banned
From: Tamilnadu, India
Registered: 2010-04-11
Posts: 382

Re: [SOLVED] Pass Environment variables from PKGBUILD to .INSTALL script

The package build very well and the versioning occurs as I intended. I know next to nothing about sed and such commands. That's why I started this topic. Do you know any site where hints like the one you gave me, are available. Thank you.


My new forum user/nick name is "the.ridikulus.rat" .

Offline

#9 2010-07-28 15:20:04

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] Pass Environment variables from PKGBUILD to .INSTALL script

googling for "sed one liners" can be an educational experience. Seeing sed in action in conjunction with a man page to translate (and some files to test) is probably a good way to start.

Offline

Board footer

Powered by FluxBB