Skip to content

Use of pre_postinstall_file in definition.rb

RodolpheB edited this page Jun 8, 2012 · 1 revision

pre_postinstall_file allows you to execute an arbitary script before each postinstall_file.

Main purpose was to allow set up of proxy environnment variable for the build of a vagrant box via veewee, without having to persist those modifications in the template box.

Principle is that before each execution of a postinstall_file :

  • if pre_postinstall_file is setted up and has not been transfered :
  • transfer it
  • append call to execution of parameter 1 ($1) of the future command line at the end of the transfered file, by executing :
    execute="\n# We must execute the script passed as the first argument\n\$1" && printf "%b\n" "$execute"
  • if pre_postinstall_file is setted up and has beean transfered :
  • modify the command to be executed for the postinstall_file by calling sh on the pre_postinstall_file with the postinstall_file as the first parameter

How To

  • Create a custom script in the definitions/ directory (i.e. pre_execute.sh)

.pre_execute.sh

# Export for proxy 
export http_proxy=http://this.is.my.proxy:8080
export https_proxy=http://this.is.my.proxy:8080
  • Edit definitions<boxname>\definition.rb to add the pre_postinstall_file property and point it to the custom script

.definition.rb

    Veewee::Definition.declare({
    ...
        :pre_postinstall_file => "pre_execute.sh",
    ...
    })
  • Check execution

At veewee post install build runtime you'll see this type of lines :

[vagrant] Executing command: echo 'vagrant'|sudo -S sh './pre_execute.sh' ./cleanup.sh
Clone this wiki locally