1

I want to install grails in my vagrant provision bootstrap bash file (which is executed as root). I tried to change the installation like shown on the grails manual:

curl -s get.gvmtool.net | sudo -u vagrant -H bash
sudo -u vagrant -H bash "$HOME/.gvm/bin/gvm-init.sh"
sudo -u vagrant -H bash gvm install grails

But this gives errors:

bash: /root/.gvm/bin/gvm-init.sh: Permission denied
bash: gvm: No such file or directory

what am I doing wrong?

Jeremiah Gowdy
  • 5,476
  • 3
  • 21
  • 33
rubo77
  • 19,527
  • 31
  • 134
  • 226
  • and what errors might that be? – cfrick May 01 '15 at 11:57
  • 2
    first of all you are not supposed to run the init script, but you have to source it. second problem is, that `gvm` is a shell function and no script. i'd make sure, that the sourcing happens in the .profile of your vagrant user and then "bash -c 'gvm install grails' could work via sudo. to try things out i'd start with `sudo -u vagrant -H bash -i` and try to make it first work within the user. – cfrick May 01 '15 at 12:47
  • `-i If the -i option is present, the shell is interactive.` why shoul that help? the vagrant provision script is not interactive at all ;) – rubo77 May 01 '15 at 13:20
  • doing so with a local account for testing would help to understand, how gvm works (it sources gvm-init and provides a function gvm). it would have to be at least something in one line: `'bash -c "source ...gvm-init.sh; gvm install grails"'` – cfrick May 01 '15 at 14:14
  • 1
    `The -i (simulate initial login) option ... This means that login-specific resource files such as .profile or .login will be read by the shell. If a command is specified, it is passed to the shell for execution.` – doelleri May 01 '15 at 14:52

1 Answers1

0

This could work:

curl -s get.sdkman.io | sudo -u vagrant -H bash -i
sudo -u vagrant -H bash -i 'source "$HOME/.sdkman/bin/sdkman-init.sh"; sdk install grails'

The -i (simulate initial login) option
... This means that login-specific resource files such as .profile or .login will be read by the shell. If a command is specified, it is passed to the shell for execution.

rubo77
  • 19,527
  • 31
  • 134
  • 226