# Running a script relative to ${STAGEDIR}



## mix_room (Oct 31, 2014)

I am in the process of attempting to create a new port. So far so good. However I get stuck at the following problem: the install process has an install script, located in ${SOMEDIR}/bin/install, which when called references ${SOMEDIR}/config.file in order to determine the path to install it to. This works great when running from ports, however I can't get it to stage properly. 

I would like to pass ${STAGEDIR} as a prefix to all the commands in ${SOMEDIR}/bin/install, however the file doesn't support this. I don't want to add ${STAGEDIR} directly to the configuration file, as it is also installed, and contains some things that are used later on.

Is there an option/solution to do this in the normal ports framework, or do I have to patch the configuration files in some odd way, i.e. add and then remove ${STAGEDIR}?


----------



## amdmi3@ (Oct 31, 2014)

The best way would be to patch the install script to support DESTDIR natively (e.g. it should read it from the environment and prepend to each destination path it touches). This patch may be also submitted upstream, as it's not FreeBSD-specific and would benefit all packagers.


----------



## mix_room (Nov 1, 2014)

I was afraid that that might be the best solution. Now I have to learn enough Ruby to manage that.


----------



## Chris_H (Nov 4, 2014)

Aouple of questions:

If the (install) script is run without ${STAGEDIR} influence, does it do the "right thing"(tm)?
Does the (install) script simply _copy_ the files to their intended destination?
If the above are largely true. It might be as simple as `(cd ${WRKSRC}/bin/install ${STAGEDIR}${PREFIX}${yada,yada})`
I could provide an exact solution, but I'd need more information/details about your port.

--Chris


----------



## mix_room (Nov 6, 2014)

It does do the "right thing(tm)" if it is run from a port, and yes, it basically just copies files.

I tried the `cd ${WRKSRC}` thing, but it didn't work, the install script has an internal variable for where it installs to, I would need to adjust that one.


----------



## Chris_H (Nov 6, 2014)

Ahh. Perhaps bypassing the install script altogether, and defining a label for file groups:

```
BINFILES= file1, file2, file3, ...
LIBFILES= lib1, lib2, lib3,...

@install (cd ${WRKSRC}/bin && ${CP} ${BINFILES} ${STAGEDIR}${PREFIX}/bin \
{effectively repeat same scheme for ${LIBFILES})
```
Otherwise, I think you're stuck using ${SED}. Something along the lines of `@${REINPLACE_CMD} -e "s,/usr/bin,${PREFIX}/bin,g ; " ${WRKSRC}/some/dir/some.file`.

If you're worried about compromising the original configuration file. You could simply copy it to a backup:

```
pre-install:
CONFFILE= someconf.file
CONFBAK= someconf.file.bak

(cd ${WRKSRC} && cp ${CONFFILE} ${CONFBAK})
```
Then later, you can still use the macros/labels ${CONFFILE} and ${CONFBAK} to insure you get the unaltered configuration file into its final destination. Overwriting the altered version is used only for install purposes. Honestly. I'm kind of groping in the dark, not having the source to examine. But maybe this will give you some thoughts that you maybe hadn't already considered.

All the best.

--Chris


----------



## mix_room (Nov 8, 2014)

I'll give those things a try when I get time. It seems like they could work.


----------

