Vagrant up - execute sh file fails - vagrant

I have a simple vagrant file which calls sh file in the provision phase:
Inside script.sh I have wget command that fails with error 403 (Forbidden).
Same error I get when running the script manually from the VM. But If I create new sh file with the SAME CONTENT, then wget will pass successfully!
*I know there is several ways in vagrant to do provisions, but please stick on this specific use case.
Your help is much appreciated.

I found the root cause of this strange behaviour.
Since I have created the sh file in MAC env it was not compatible with unix line endings format. running "dos2unix script.sh".
For detialed information visit:
http://dos2unix.sourceforge.net/

Related

Ros Environment in root

I have a ros (kinetic) environment set up on a raspberry pi 3 and am trying to get ros to execute upon startup via a simple bash script which calls roslaunch. Ros works in the user domain but fails when called from root.
Here is my launch_ros.sh script:
#!/bin/bash
source /home/pi/ros_catkin_ws/devel/setup.bash
export PYTHONPATH=/opt/ros/kinetic/lib/python2.7/dist-packages
roslaunch my_pkg pkg_launch.launch
When I run sudo /home/pi/Desktop/ros_launch.sh the roscore crashes with
ERROR: cannot launch node of type [rosout/rosout]: can't locate node
[rosout] in package [rosout] failed to start core service [/rosout]
The traceback for the exception was written to the log file
But, if I comment out
source /home/pi/ros_catkin_ws/devel/setup.bash
and execute /home/pi/Desktop/ros_launch.sh, ros works fine.
Also worthy of noting is if I leave the above source line uncommented when running in the user domain I get the same error as I do in the root. I think this might be pointing me to the solution but I am still very new to ros.
Has anyone come across this issue and found a solution?
In order to run a node as root after changing your shell to root using commands like sudo -i, You can source your current bash profile thats located inside your normal user .bashrc and use it inside root shell.
Try the following code:
#!/bin/bash
source /opt/ros/kinetic/setup.bash
source /home/pi/ros_catkin_ws/devel/setup.bash
export PYTHONPATH=/opt/ros/kinetic/lib/python2.7/dist-packages
roslaunch my_pkg pkg_launch.launch
You need to source your workspace devel to be able to find your own package.
But, you need to source ROS devel to be able to use roscd, roslaunch, ...
In the code below I added:
source /opt/ros/kinetic/setup.bash
to source ROS and be able to use it.
PS: If it's still not working you should try a short delay before running roslaunch.
I was accidentally in a conda environment (base only) and it was messing up big-time. Try disabling any Python virtual environments.
It really worked and it inspired me to report that I didn't have rosnode as a program when I was planning to call ROS scripts in my own applications. Calling source .bashrc directly from the Raspberry Pi's system would refresh the terminal, but there was no way for my program to take over. The solution was to place the required ROS environment scripts in a separate script like name init_env.sh and then call source init_env.sh before any other ROS scripts were executed.

Jenkins Blue Ocean ./gradlew: No such file or directory

I am having trouble getting Blue Ocean to recognize where my default gradle folder is on my Mac OSX. I have GRADLE_HOME set to /opt/gradle.
I keep getting the following error message when running my shell script ./gradlew assembleDebug:
/Users/me/.jenkins/workspace/project#tmp/durable-d97717dc/script.sh:
line 2: ./gradlew: No such file or directory
script returned exit code 1
I could see two reasons for that error:
Your script is not executed in the folder where your gradlew lays.
The gradlew has not set the correct permissions set for the calling user.
Adding a check for existing and the correct permissions on the file to execute could help you to sort these problems out.

Alias to open file on Windows using CygWin

I have a windows machine with CygWin installed on it. I do not hold any admin privileges, so, forget about changing environment variables which apply to all user and etc...
Scenario:
When I execute CygWin and type the following command to execute Maven, it works perfectly:
/cygdrive/c/maven/apache-maven-3.5.0/bin/mvn
However, when I create the file .profile as below:
alias mvn="cygdrive/c/maven/apache-maven-3.5.0/bin/mvn"
After restarting CygWing and executing the command "mvn", the following message is sent: No such file or directory.
Any suggestions?
Thanks in advance.
For any of you who may have the same problem, the way I solved this was basically adding a "sh" at the beginning of the command:
elias mvn="sh /cygdrive/c/maven/apache-maven-3.5.0/bin/mvn"
Cheers.

Windows GitLab CI Runner using Bash

I'm trying to use bash as the shell on Windows for a GitLab CI Runner.
concurrent = 1
check_interval = 0
[[runners]]
name = "DESKTOP-RQTQ13S"
url = "https://example.org/ci"
token = "fooooooooooooooooooobaaaaaaaar"
executor = "shell"
shell = "bash"
[runners.cache]
Unfortunately I can not find an option to specify the actual shell program that the CI Runner should use. By default, it just tries to run bash which it can not find. I don't know why, because when I open up a Windows command line and enter bash it works.
Running with gitlab-ci-multi-runner 1.9.4 (8ce22bd)
Using Shell executor...
ERROR: Build failed (system failure): Failed to start process: exec: "bash": executable file not found in %PATH%
I tried adding a file bash.cmd to my user directory containing
#"C:\Program Files\Git\usr\bin\bash.exe" -l
That gives me this strange error:
Running with gitlab-ci-multi-runner 1.9.4 (8ce22bd)
Using Shell executor...
Running on DESKTOP-RQTQ13S...
/usr/bin/bash: line 43: /c/Users/niklas/C:/Users/niklas/builds/aeb38de4/0/niklas/ci-test.tmp/GIT_SSL_CAINFO: No such file or directory
ERROR: Build failed: exit status 1
Is there a way to properly configure this?
There are two issues going on here, and both can probably be solved.
gitlab-runner cannot find bash
gitlab-runner doesn't combine unix-style and Windows-style paths very well.
You have essentially succeeded in solving the first one by creating the bash.cmd file. But if you're curious about why it didn't work without it, my guess is that bash runs in your command prompt because the directory that contains it (e.g. in your case "C:\Program Files\Git\usr\bin") is included in the PATH environment variable for your user account. But perhaps you are running the gitlab-runner in the system account, which might not have the same PATH.
So the first thing to do is just check your system's PATH variable and add the bin directory if necessary (i.e. using the System applet in the Control Panel as described here or here). Just make sure you restart your machine after you make the change, because the change isn't applied until after you restart. That should make bash work, even when called from a service running in the system or admin account.
As for the strange error you got after creating bash.cmd, that was due to the second issue. Paths are often really hard to get right when combining bash and Windows. Gitlab-runner is probably trying to determine whether the build path is relative or absolute, and ends up prepending the windows path with what it thinks is the working directory ($PWD). This looks like a bug, but gitlab still has not fixed it (as of version 9.0 of the runner!!) and probably never will. Maybe they have decided it is not a bug or that it is due to bugs in underlying software or tools that they can't fix or that it would be too difficult to fix. Anyway, I've discovered a work-around. You can specify the base path for builds in the config.toml file. If you use a unix-style path, it fixes the problem.
On windows, config.toml is usually in the same folder as your gitlab-runner.exe (or gitlab-multi-runner-amd64.exe etc). Open that file in your favorite text editor. Then find the [[runners]] section and add two lines similar to the following.
builds_dir="/c/gitlab-runner/builds/"
cache_dir="/c/gitlab-runner/cache/"
The path you use should be the "bash version" of whatever directory you want gitlab-runner to use for storing builds etc. Importantly if you are using cygwin, you would use a path similar to /cygdrive/c/... instead of just /c/... (which is appropriate for msys-git or standalone MSYS2 etc).
Here's an example of a config.toml file:
[[runners]]
name = "windows"
url = "https://your.server.name"
token = "YOUR_SECRET_TOKEN"
executor = "shell"
shell = "bash"
builds_dir="/c/gitlab-runner/builds/"
cache_dir="/c/gitlab-runner/cache/"
It looks like you're attempting to link gitlab-ci up with the Windows Subsystem for Linux (which can be accessed by typing bash at the Windows command prompt)? I doubt that this is supported directly by Gitlab's runner configuration.
Instead, I would suggest using Powershell with your shell executor.
Executor = 'shell'
Shell = 'powershell'
You can then drop down into Bash in the scripts you call from .gitlab-ci.yml.
Given that it's bad practice to execute more than very trivial shell scripts within the .gitlab-ci.yml itself (as opposed to calling out to an external script), you lose little by being forced to use a native Windows shell.

Run Vagrant Terminal As Sublime Repl on Windows Box

I have a web environment with Vagrant currently running on my local machine. What I'd like to do is to run that Vagrant development environment as a repl in Sublime.
I have Sublime Repl installed, and I edited the shell configuration file to call ssh.exe, but I keep getting errors.
I figured out I needed to run ssh -t -t to force ssh to run in a virtual terminal. However, I now get the following error when I try to execute:
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
***Repl Closed***
I also get the same error when trying to execute the code in the cmd.exe repl that is already configured.
The line of code in Vagrant Main.sublime-menu file that that is getting executed is:
"windows": ["ssh", "-t", "-t", "-p", "2222", "vagrant:vagrant#127.0.0.1"]
Any ideas?
Okay. For anyone else looking to do this, I figured out how.
I did it using plink.exe with my already existing putty.exe saved session. I created a configuration folder for Vagrant in the Sublime REPL plugin folder located in Data\Packages\SublimeRepl\config and edited the contents - the folder is a copy of the already existing folder shell. There are two files that I needed to edit. The first file is the Default.sublime-commands file.
In that line I just changed the the path to point to the second file, Main.sublime-menu.
In that file, there is an already existing section that shows the commands for all three OS's. This is the exact line I put in for windows to get it to work: (my existing putty session is named vagrant and my pw is listed as vagrant here)
"windows": ["plink", "-load", "vagrant", "-pw", "vagrant"]
And voila!

Resources