Skip to content

Instantly share code, notes, and snippets.

@robinsound
Last active November 3, 2021 01:00
Show Gist options
  • Save robinsound/6096999 to your computer and use it in GitHub Desktop.
Save robinsound/6096999 to your computer and use it in GitHub Desktop.
NSIS script for Ruby, Git and DevKit installers. Then install a gem
!include LogicLib.nsh ;IF ELSE
!include "StrContains.nsh"
AutoCloseWindow true
OutFile "SimpleGemInstaller.exe"
;here you can reference to any other ruby version and set you prefer path
;you can use !define for compile time substitution
;Example:
; instead of using :
; File "Git-1.8.3-preview20130601.exe"
; you can use its macro :
; File "${git_installer}" ; << note the quotes!!!, nsis compiler will replace ${git_installer} with Git-1.8.3-preview20130601.exe
!define ruby_installer 'rubyinstaller-1.9.3-p448.exe'
!define ruby_path 'c:\Ruby193\bin'
!define git_installer 'Git-1.8.3-preview20130601.exe'
!define git_path 'c:\git'
!define devkit_installer 'DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe'
!define devkit_path 'C:\DevKit'
!define gem_to_install 'activesupport' ;<< put your gem here!!!!!
Section "ruby" SEC01
SetOutPath "$TEMP"
ReadEnvStr $R0 "PATH"
${StrContains} $1 "${ruby_path}" $R0
${If} $1 != "${ruby_path}"
File "${ruby_installer}"
DetailPrint "Starting Ruby installation"
StrCpy $0 ''
ExecWait '"$TEMP\${ruby_installer}" /silent /noreboot /nocancel /noicons /tasks="assocfiles,modpath"' $0
${If} $0 == ''
;execution of installer failed
MessageBox MB_OK "Ruby install failed. Please install Ruby manually"
${EndIf}
${EndIf}
SectionEnd
Section "git" SEC02
SetOutPath "$TEMP"
ReadEnvStr $R0 "PATH"
${StrContains} $1 "\Git\" $R0
${If} $1 != "\Git\"
File "${git_installer}"
StrCpy $0 ''
;rum the installer
DetailPrint "Starting Git installation"
ExecWait '"$TEMP\${git_installer}" /VERYSILENT /SUPPRESSMSGBOXES /noreboot /nocancel /noicons /DIR="${git_path}"' $0
${If} $0 == ''
;execution of installer failed
MessageBox MB_OK "Git install failed. Please install git manually"
${Else}
;We need update PATH for git because no tasks "modpath"
ReadRegStr $1 ${env_hklm} "PATH"
WriteRegExpandStr ${env_hklm} "PATH" "${git_path}\bin;$1"
;make sure windows knows about the change
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
${EndIf}
${EndIf}
SectionEnd
Section "devkit" SEC03
SetOutPath "$TEMP"
File "${devkit_installer}"
DetailPrint "Starting Ruby Dev Kit installation"
ExecWait '"$TEMP\${devkit_installer}" x -o"${devkit_path}" -y /silent /noreboot /nocancel /noicons' $1
${If} $1 == ''
MessageBox MB_OK "Ruby Dev Kit install failed. Please install it manually"
${EndIf}
ExecWait "${ruby_path}\ruby ${devkit_path}\dk.rb init" $1
${If} $1 == ''
MessageBox MB_OK "Ruby Dev Kit extracted to ${devkit_path} but installation failed. Please install it manually"
${EndIf}
ExecWait "${ruby_path}\ruby ${devkit_path}\dk.rb install --force" $1
${If} $1 == ''
MessageBox MB_OK "Ruby Dev Kit extracted to ${devkit_path} but installation failed. Please install it manually"
${EndIf}
SectionEnd
Section "gems" SEC04
StrCpy $1 ''
;install gems locally
ExecWait '"${ruby_path}\gem.bat" install ${gem_to_install}' $1
${If} $1 == ''
MessageBox MB_OK "gem install ${gem_to_install} failed. Please install it manually"
${EndIf}
SectionEnd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment