I am writing an installer for a piece of Windows software that requires a certain minimum version of Ruby (along with some Ruby Gems) to be installed on the target machine. I have been reading various tutorials and got lots of useful stuff from example files, but I am still stuck on how to process this elegantly using NSIS.
Here is what I would like NSIS to accomplish:
1. Check if Ruby is installed (by executing `ruby --version` and interpreting the output).
1a. If Ruby is not installed, then NSIS will need to install a compatible version (by showing an NSIS RO section for Ruby).
1b. If Ruby is installed, then find out which version.
1bi. If version >= 2.3, then no need to do anything further (by not showing/executing the Ruby section).
1bii. If version < 2.3, then install a compatible version (by showing an NSIS RO section for Ruby).
2. Check if MyGem is installed (by executing `gem list --local MyGem` and interpreting the output).
2a. If MyGem is not installed, then NSIS will need to install it (by showing an NSIS RO section for MyGem, which executes `gem install MyGem`, which will retrieve the gem from the internet).
2b. If MyGem is installed, then find out which version.
2bi. If version >= 0.5.2, then no need to do anything further.
2bii. If version < 0.5.2, then install the latest version (by showing an NSIS RO section for MyGem, which executes `gem install MyGem`, which will retrieve the gem from the internet).
Here is the part of my NSIS script that should check the version number (just focussing on Ruby itself for now):
Function InitComponents
ExpandEnvStrings $0 %COMSPEC%
nsExec::ExecToStack '"$0" /C ruby --version'
; If Ruby is installed, the expected output contains something like this:
; ruby 2.4.3p205 (2017-12-14 revision 61247) [x64-mingw32]
pop $0
pop $1
${StrContains} $2 "ruby " "$1"
StrCmp $2 "" notfound
MessageBox MB_OK 'Ruby was found, not installing it'
Goto done
notfound:
MessageBox MB_OK 'Did not find string "ruby ". Therefore Ruby should be installed.'
SectionSetText ${SectionRuby} "Ruby"
${SelectSection} ${SectionRuby}
done:
FunctionEnd
The above code works in that it will properly tell me that it will install Ruby or not. The problem is, I cannot seem to work out how to do the version check. For the equivalent Linux installer, I have used awk to concatenate the first and second number of the version ("2.4.3p205", resulting in the number 24) and compare that to the number 23 (representing the minimum version 2.3).
Any tips on how I can accomplish the same or similar with NSIS?
Thank you.