1

I'm working on a script that installs the new cross platform DNX runtime on an Ubuntu box. I'm scripting the whole installation, so that it runs unattended after provisioning the machine.

Here's the relevant part of the script:

#!/bin/bash

admin_username=$1

wget -q https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh -P /home/${admin_username}/dnvm
bash /home/${admin_username}/dnvm/dnvminstall.sh
source /home/${admin_username}/dnvm/dnvm.sh

dnvm ## <-- Error: post_deployment.sh: 34: post_deployment.sh: dnvm: not found

The script will execute as root on the machine after provisioning. The ${admin_username} is passed in correctly - and /home/${admin_username}/dnvm/dnvm.sh does exist on the filesystem after the dnvminstall.sh execution.

The problem is that the dnvm command is defined inside the dnvm.sh file, but is not available in the calling script ( post_deployment.sh ) - after sourcing the file.

From what I've read - if I would have used bash /home/${admin_username}/dnvm/dnvm.sh - it would have run that script in a subshell, not exposing any of the functions inside. But using source should, right?

UPDATE

Below the excution trace of the script:

2016/05/18 07:19:33 Downloading DNVM installation script ...
2016/05/18 07:19:33 Running installation script ...
2016/05/18 07:19:33 Downloading dnvm as script to '/home/serveradmin/dnvm'
2016/05/18 07:19:33
2016/05/18 07:19:33 Appending source string to /home/serveradmin/.profile
2016/05/18 07:19:33 Type 'source /home/serveradmin/dnvm/dnvm.sh' to start using dnvm
2016/05/18 07:19:33 Sourcing DNVM commands ...
2016/05/18 07:19:33 Downloading coreclr DNX runtime ...
2016/05/18 07:19:33
2016/05/18 07:19:33 ---errout---
Extracting templates from packages: 100%
2016/05/18 07:19:33 + source /home/serveradmin/dnvm/dnvm.sh
2016/05/18 07:19:33 post_deployment.sh: 33: post_deployment.sh: source: not found
2016/05/18 07:19:33 + dnvm
2016/05/18 07:19:33 post_deployment.sh: 34: post_deployment.sh: dnvm: not found

With actual source:

...
echo "Sourcing DNVM commands ..."
set -x
source /home/${admin_username}/dnvm/dnvm.sh
dnvm
...

So then - it seems the command source is not found. Which makes this question a duplicate of this question on StackOverflow. However - I don't have solution yet, because I need to use Ubuntu 14.04 ( only version supported in DNX right now ).

Community
  • 1
  • 1
Jochen van Wylick
  • 5,303
  • 4
  • 42
  • 64
  • 2
    How is the "command" defined? – choroba May 16 '16 at 08:32
  • `dnvm() { ...stuff... }` - Full source here: [https://github.com/aspnet/Home/blob/dev/dnvm.sh](https://github.com/aspnet/Home/blob/dev/dnvm.sh) - at the bottom of the script, there's one more line: `$_DNVM_COMMAND_NAME alias default >/dev/null && $_DNVM_COMMAND_NAME use default >/dev/null || true` , is that relevant? ( `$_DNVM_COMMAND_NAME` value is 'dnvm' ) – Jochen van Wylick May 16 '16 at 08:39
  • Have you tried exporting the function with `export -f dnvm`? – Mark Setchell May 16 '16 at 09:45
  • @MarkSetchell So then I first append this line to the script and then source it, right? Because the script gets downloaded. – Jochen van Wylick May 16 '16 at 13:28
  • @MarkSetchell: Exporting should not be necessary, as no subprocess is involved. – user1934428 May 17 '16 at 05:19
  • 1
    Does it work, if you run it manually from the command line (sourcing the script, calling dnvm)? You could also check the exit code of the `source` command, and turn on debug trace (`set -x`) before the `source`. I bet for some reason, the function does not get defined. – user1934428 May 17 '16 at 05:21
  • @user1934428 - yes it does. I will check the tracing. – Jochen van Wylick May 17 '16 at 11:49
  • @user1934428 - thanks - tracing helped. I updated the question – Jochen van Wylick May 18 '16 at 16:43
  • Are you sure that this is running under **bash**? The error message *source: not found* suggests that this might not be the case. – user1934428 May 19 '16 at 11:36
  • @user1934428 Nope - indeed - I found out that the script was called by `sh whatever.sh` which defaulted to `dash`. Changing that to `/bin/bash whatever.sh` fixed the problem. I'll update the post accordingly! Thanks though. – Jochen van Wylick May 19 '16 at 12:06

0 Answers0