NSIS Wiki:Sandbox: Difference between revisions
Seg telltale (talk | contribs) m (Cleaning up my sandboxing; Added horizontal rule to clearly divide the constant note and sandbox content;) |
(trying ..) |
||
Line 9: | Line 9: | ||
<hr /> | <hr /> | ||
<!-- keep the note above intact and put the page content right below --> | <!-- keep the note above intact and put the page content right below --> | ||
Ok Lets try the following script for installing an ASP.NET site: | |||
<code> | |||
; SITENAMESITE_INSTALL.nsi | |||
; THIS INSTALLER INSTALLS THE APPLICATION LAYER OF THE SITENAME-Tool | |||
;2008.11.19 Yordan Georgiev | |||
;Purpose: This NSI script packs all the nessessary source files for running the SITENAME site | |||
;-------------------------------- | |||
!include "FileFunc.nsh" | |||
!include "MUI2.nsh" | |||
!include "WordFunc.nsh" | |||
!include "Time.nsh" | |||
!include "Sections.nsh" | |||
!insertmacro WordFind | |||
!insertmacro MUI_LANGUAGE "English" | |||
!define /date MYDATE "%Y%b%d.%H%M%S" ;not really needed but yet | |||
!define SERVER $R0 ;Temp variable for holding the option chosen for server | |||
!define CHOSENSERVER $R9 ;Temp variable for holding the NOTE : | |||
LangString MUI_TEXT_INSTALLING_TITLE ${LANG_ENGLISH} "SITENAME SITE Installation" | |||
LangString MUI_TEXT_INSTALLING_SUBTITLE ${LANG_ENGLISH} "Installing SITENAME SITE" | |||
LangString MUI_TEXT_FINISH_TITLE ${LANG_ENGLISH} "SITENAME SITE Ready" | |||
LangString MUI_TEXT_FINISH_SUBTITLE ${LANG_ENGLISH} "SITENAME SITE Installed" | |||
LangString MUI_TEXT_ABORT_TITLE ${LANG_ENGLISH} "Abort SITENAME SITE Installation ?!" | |||
LangString MUI_TEXT_ABORT_SUBTITLE ${LANG_ENGLISH} "Abort SITENAME SITE Installation ?!" | |||
XPStyle On | |||
AutoCloseWindow false | |||
ShowInstDetails show | |||
;Things that need to be extracted on startup (keep these lines before any File command!) | |||
;Only useful for BZIP2 compression | |||
;Use ReserveFile for your own InstallOptions INI files too! | |||
ReserveFile "${NSISDIR}\Plugins\InstallOptions.dll" | |||
ReserveFile "SITENAMEsite_conf.ini" | |||
Name "SITENAME-Tool Application Layer installer for Any Environment" | |||
; THIS IS THE SETUP.EXE FILE PRODUCED BY THE SCRIPT | |||
OutFile "G:\Setup_SITENAME.exe" | |||
InstallDir "D:\SITENAME" ; CHANGE THIS PATH AS THE DEFAULT ONE TO PROVIDE THE USER TO INSTALL | |||
;Prompt for Vista Admin Rights | |||
RequestExecutionLevel admin | |||
;-------------------------------- | |||
;Pages | |||
;Order of pages | |||
Page custom SetCustom ValidateCustom "Choose the right server to install t" ;Custom page. | |||
Page directory | |||
Page instfiles | |||
Page custom CustomPage | |||
UninstPage uninstConfirm | |||
UninstPage instfiles | |||
;-------------------------------- | |||
; Declaration of user variables (Var command), allowed charaters for variables names : [a-z][A-Z][0-9] and copy_' | |||
Var "Info" | |||
Var "InfoOK" | |||
;-------------------------------- | |||
; Installer | |||
;************************************************************************************************** | |||
Section "Components" | |||
;Get Install Options dialog user input | |||
ReadINIStr ${SERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 2" "State" | |||
DetailPrint "Install option=${SERVER}" | |||
ReadINIStr ${SERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 3" "State" | |||
DetailPrint "Install option=${SERVER}" | |||
ReadINIStr ${SERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 4" "State" | |||
DetailPrint "Install option=${SERVER}" | |||
ReadINIStr ${SERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 5" "Text" | |||
DetailPrint "Info=${SERVER}" | |||
DetailPrint "CHOSENSERVER=${CHOSENSERVER}" | |||
SectionEnd | |||
;************************************************************************************************** | |||
Section | |||
;CREATE BACKUP OF THE EXISTING SITE IF ANY | |||
${time::GetLocalTime} $R0 | |||
${time::TimeString} "$R0" $0 $1 $2 $3 $4 $5 | |||
/* | |||
0 - date | |||
1 - month | |||
2 - year | |||
3 - hour | |||
4 - minute | |||
5 - seconds | |||
*/ | |||
;CREATE THE BACKUP DIRECTORY BASED ON THE TIMESTAMP | |||
CreateDirectory "$INSTDIR.$2$1$0.$3$4$5" | |||
Rename $INSTDIR "$INSTDIR.$2$1$0.$3$4$5" | |||
;CopyFiles "$INSTDIR\*.*" "$INSTDIR.$2$1$0.$3$4$5" 0 | |||
SectionEnd | |||
;************************************************************************************************** | |||
;************************************************************************************************** | |||
Section "Unpacking" SecDummy | |||
; MessageBox MB_OK "The installation directory you choosed is $INSTDIR . Press OK to proceed" | |||
CreateDirectory $INSTDIR | |||
SetOutPath $INSTDIR | |||
; HERE UNZIP ACTUALLY THE FILES | |||
; DO NOT INCLUDE FILES CONTAINING "test" *.MDF *.ldf | |||
File /r /x *.MDF /x *.exclude /x *.ldf /x *.pl /x *.nsis /x *.cmd *.cs *.aspx *.aspx.cs *.dll *.css *.resx *.config *.dll *.pdb *.js *.bmp *.gif *.jpg *.png *.master *.master.cs | |||
SectionEnd | |||
;************************************************************************************************** | |||
;************************************************************************************************** | |||
Section "Unpacking bin folder" SecUnpackBin | |||
; HERE WE UNZIP THE FILES FOR THE BIN DIRECTOR | |||
;CreateDirectory "D:\bin\SITENAME_TEST\" | |||
;SetOutPath "D:\bin\SITENAME_TEST\" | |||
;File /r *.cmd *.dll *.exe | |||
;DELETE ALL EXE FILES | |||
SectionEnd | |||
;************************************************************************************************** | |||
;************************************************************************************************** | |||
Section | |||
;FIND OUT WHICH APPLICATION ARE WE INSTALLING | |||
;NOTE THIS ASSUMES INSTALLATION IN THE D:\ DRIVE | |||
;SO LETS ASSUME INSTALLING D:\SITENAME | |||
StrCpy $R0 "$INSTDIR" | |||
${WordFind} $R0 "\" "-02" $R1 | |||
DetailPrint "I saw $R1" | |||
WriteUninstaller "$R1\Uninstall_SITENAMESITE.exe" | |||
SectionEnd | |||
;$R1=D: | |||
Section | |||
StrCpy $R2 "$INSTDIR" | |||
${WordFind} $R2 "\" "-01" $R3 | |||
DetailPrint "I saw $R3" | |||
SectionEnd | |||
;$R3=SITENAME | |||
Section "SETUPCONNECTION ENVIRONMENT" | |||
;INFORM THE STARTING OF THE COPY | |||
DetailPrint "Setting up the resource file for the server " | |||
;COPY THE SERVER CONFIG FILES FOR THIS APPLICATION | |||
;COPY THE SERVER FILE AS FROM SERVER.FILE TO FILE | |||
;Delete the Web.config file from the development | |||
Delete "$INSTDIR\Web.config" | |||
;server = heitv156lab.devlab.nokia.com | |||
DetailPrint "I saw ${CHOSENSERVER} Followed by space" | |||
CopyFiles "$INSTDIR\INSTALL\${CHOSENSERVER}.$R3.Web.config" "$INSTDIR\Web.config" | |||
;${CHOSENSERVER} | |||
;COPY THE App_GlobalResources folder | |||
;Delete the App_GlobalResources from the development | |||
Delete "$INSTDIR\App_GlobalResources\*.*" | |||
;Copy the server.app.App_GlobalResources to it's correct place | |||
CopyFiles "$INSTDIR\INSTALL\${CHOSENSERVER}.$R3.App_GlobalResources\*.*" "$INSTDIR\App_GlobalResources\" | |||
;NOW DELETE THE INSTALL DIRECTORY CONTAINING THE DIFFERENT SETUP FILES | |||
; Var /GLOBAL "AnotherVar" | |||
; StrCpy $AnotherVar "test" | |||
SectionEnd | |||
;-------------------------------- | |||
; Uninstaller | |||
Section "Uninstall" | |||
StrCpy $Info "SITENAME SITE uninstalled successfully." | |||
Delete "$R1\Uninst.exe" | |||
RmDir $INSTDIR | |||
SectionEnd | |||
Function un.OnUninstSuccess | |||
HideWindow | |||
MessageBox MB_OK "$Info" | |||
FunctionEnd | |||
Function OnInstSuccess | |||
StrCpy $Info "SITENAME SITE installed successfully !!!" | |||
HideWindow | |||
MessageBox MB_OK "$InfoOK" | |||
FunctionEnd | |||
;------------------------------------------------------------------------------------ | |||
Function CustomPage | |||
SectionGetFlags ${Section_Name} $R0 | |||
IntOp $R0 $R0 & ${SF_SELECTED} | |||
IntCmp $R0 ${SF_SELECTED} show | |||
Abort | |||
show: | |||
FunctionEnd | |||
Function .onInit | |||
;Extract InstallOptions files | |||
;$PLUGINSDIR will automatically be removed when the installer closes | |||
InitPluginsDir | |||
File /oname=$PLUGINSDIR\SITENAMEsite_conf.ini "SITENAMEsite_conf.ini" | |||
FunctionEnd | |||
Function SetCustom | |||
;Display the InstallOptions dialog | |||
Push ${SERVER} | |||
InstallOptions::dialog "$PLUGINSDIR\SITENAMEsite_conf.ini" | |||
Pop ${SERVER} | |||
Pop ${SERVER} | |||
FunctionEnd | |||
Function ValidateCustom | |||
ReadINIStr ${SERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 2" "State" | |||
ReadINIStr ${CHOSENSERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 2" "Text" | |||
StrCmp ${SERVER} 1 done | |||
ReadINIStr ${SERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 3" "State" | |||
ReadINIStr ${CHOSENSERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 3" "Text" | |||
StrCmp ${SERVER} 1 done | |||
ReadINIStr ${SERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 4" "State" | |||
ReadINIStr ${CHOSENSERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 4" "Text" | |||
StrCmp ${SERVER} 1 done | |||
MessageBox MB_ICONEXCLAMATION|MB_OK "You must select at least one install option!" | |||
Abort | |||
done: | |||
FunctionEnd | |||
Function .onInstSuccess | |||
MessageBox MB_OK "SITENAME site installed correctly" | |||
FunctionEnd | |||
Function un.onUserAbort | |||
MessageBox MB_YESNO "Abort uninstall?" IDYES NoCancelAbort | |||
Abort ; causes uninstaller to not quit. | |||
NoCancelAbort: | |||
FunctionEnd | |||
Function un.onInit | |||
MessageBox MB_YESNO "This will uninstall. Continue?" IDYES NoAbort | |||
Abort ; causes uninstaller to quit. | |||
NoAbort: | |||
FunctionEnd | |||
</code> |
Revision as of 14:20, 20 November 2008
This is where test stuff should be posted, if you don't know how things appear, or want to test if something works which can't be seen by just previewing the page.
Right now, there is nothing being done to this page regularly to delete contents. Maybe a bot or the server will be used for the task, but nothing is sure.
Keep the page content below this note.
Ok Lets try the following script for installing an ASP.NET site:
- SITENAMESITE_INSTALL.nsi
- THIS INSTALLER INSTALLS THE APPLICATION LAYER OF THE SITENAME-Tool
- 2008.11.19 Yordan Georgiev
- Purpose
- This NSI script packs all the nessessary source files for running the SITENAME site
- --------------------------------
!include "FileFunc.nsh"
!include "MUI2.nsh"
!include "WordFunc.nsh"
!include "Time.nsh"
!include "Sections.nsh"
!insertmacro WordFind
!insertmacro MUI_LANGUAGE "English"
!define /date MYDATE "%Y%b%d.%H%M%S" ;not really needed but yet
!define SERVER $R0 ;Temp variable for holding the option chosen for server
!define CHOSENSERVER $R9 ;Temp variable for holding the NOTE :
LangString MUI_TEXT_INSTALLING_TITLE ${LANG_ENGLISH} "SITENAME SITE Installation"
LangString MUI_TEXT_INSTALLING_SUBTITLE ${LANG_ENGLISH} "Installing SITENAME SITE"
LangString MUI_TEXT_FINISH_TITLE ${LANG_ENGLISH} "SITENAME SITE Ready"
LangString MUI_TEXT_FINISH_SUBTITLE ${LANG_ENGLISH} "SITENAME SITE Installed"
LangString MUI_TEXT_ABORT_TITLE ${LANG_ENGLISH} "Abort SITENAME SITE Installation ?!"
LangString MUI_TEXT_ABORT_SUBTITLE ${LANG_ENGLISH} "Abort SITENAME SITE Installation ?!"
XPStyle On
AutoCloseWindow false
ShowInstDetails show
- Things that need to be extracted on startup (keep these lines before any File command!)
- Only useful for BZIP2 compression
- Use ReserveFile for your own InstallOptions INI files too!
ReserveFile "${NSISDIR}\Plugins\InstallOptions.dll"
ReserveFile "SITENAMEsite_conf.ini"
Name "SITENAME-Tool Application Layer installer for Any Environment"
; THIS IS THE SETUP.EXE FILE PRODUCED BY THE SCRIPT
OutFile "G:\Setup_SITENAME.exe"
InstallDir "D:\SITENAME" ; CHANGE THIS PATH AS THE DEFAULT ONE TO PROVIDE THE USER TO INSTALL
- Prompt for Vista Admin Rights
RequestExecutionLevel admin
- --------------------------------
;Pages
;Order of pages
Page custom SetCustom ValidateCustom "Choose the right server to install t" ;Custom page.
Page directory
Page instfiles
Page custom CustomPage
UninstPage uninstConfirm
UninstPage instfiles
- --------------------------------
- Declaration of user variables (Var command), allowed charaters for variables names
- [a-z][A-Z][0-9] and copy_'
Var "Info"
Var "InfoOK"
- --------------------------------
- Installer
Section "Components"
;Get Install Options dialog user input
ReadINIStr ${SERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 2" "State"
DetailPrint "Install option=${SERVER}"
ReadINIStr ${SERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 3" "State"
DetailPrint "Install option=${SERVER}"
ReadINIStr ${SERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 4" "State"
DetailPrint "Install option=${SERVER}"
ReadINIStr ${SERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 5" "Text"
DetailPrint "Info=${SERVER}"
DetailPrint "CHOSENSERVER=${CHOSENSERVER}"
SectionEnd
Section
- CREATE BACKUP OF THE EXISTING SITE IF ANY
${time::GetLocalTime} $R0
${time::TimeString} "$R0" $0 $1 $2 $3 $4 $5
/*
0 - date
1 - month
2 - year
3 - hour
4 - minute
5 - seconds
- /
- CREATE THE BACKUP DIRECTORY BASED ON THE TIMESTAMP
CreateDirectory "$INSTDIR.$2$1$0.$3$4$5"
Rename $INSTDIR "$INSTDIR.$2$1$0.$3$4$5"
- CopyFiles "$INSTDIR\*.*" "$INSTDIR.$2$1$0.$3$4$5" 0
SectionEnd
Section "Unpacking" SecDummy
- MessageBox MB_OK "The installation directory you choosed is $INSTDIR . Press OK to proceed"
CreateDirectory $INSTDIR
SetOutPath $INSTDIR
- HERE UNZIP ACTUALLY THE FILES
- DO NOT INCLUDE FILES CONTAINING "test" *.MDF *.ldf
File /r /x *.MDF /x *.exclude /x *.ldf /x *.pl /x *.nsis /x *.cmd *.cs *.aspx *.aspx.cs *.dll *.css *.resx *.config *.dll *.pdb *.js *.bmp *.gif *.jpg *.png *.master *.master.cs
SectionEnd
Section "Unpacking bin folder" SecUnpackBin
- HERE WE UNZIP THE FILES FOR THE BIN DIRECTOR
- CreateDirectory "D
- \bin\SITENAME_TEST\"
- SetOutPath "D
- \bin\SITENAME_TEST\"
- File /r *.cmd *.dll *.exe
- DELETE ALL EXE FILES
SectionEnd
Section
- FIND OUT WHICH APPLICATION ARE WE INSTALLING
- NOTE THIS ASSUMES INSTALLATION IN THE D
- \ DRIVE
- SO LETS ASSUME INSTALLING D
- \SITENAME
StrCpy $R0 "$INSTDIR"
${WordFind} $R0 "\" "-02" $R1
DetailPrint "I saw $R1"
WriteUninstaller "$R1\Uninstall_SITENAMESITE.exe"
SectionEnd
- $R1=D
Section
StrCpy $R2 "$INSTDIR"
${WordFind} $R2 "\" "-01" $R3
DetailPrint "I saw $R3"
SectionEnd
- $R3=SITENAME
Section "SETUPCONNECTION ENVIRONMENT"
- INFORM THE STARTING OF THE COPY
DetailPrint "Setting up the resource file for the server "
- COPY THE SERVER CONFIG FILES FOR THIS APPLICATION
- COPY THE SERVER FILE AS FROM SERVER.FILE TO FILE
- Delete the Web.config file from the development
Delete "$INSTDIR\Web.config"
- server = heitv156lab.devlab.nokia.com
DetailPrint "I saw ${CHOSENSERVER} Followed by space"
CopyFiles "$INSTDIR\INSTALL\${CHOSENSERVER}.$R3.Web.config" "$INSTDIR\Web.config"
- ${CHOSENSERVER}
- COPY THE App_GlobalResources folder
- Delete the App_GlobalResources from the development
Delete "$INSTDIR\App_GlobalResources\*.*"
- Copy the server.app.App_GlobalResources to it's correct place
CopyFiles "$INSTDIR\INSTALL\${CHOSENSERVER}.$R3.App_GlobalResources\*.*" "$INSTDIR\App_GlobalResources\"
- NOW DELETE THE INSTALL DIRECTORY CONTAINING THE DIFFERENT SETUP FILES
- Var /GLOBAL "AnotherVar"
- StrCpy $AnotherVar "test"
SectionEnd
- --------------------------------
- Uninstaller
Section "Uninstall"
StrCpy $Info "SITENAME SITE uninstalled successfully."
Delete "$R1\Uninst.exe"
RmDir $INSTDIR
SectionEnd
Function un.OnUninstSuccess
HideWindow
MessageBox MB_OK "$Info"
FunctionEnd
Function OnInstSuccess
StrCpy $Info "SITENAME SITE installed successfully !!!"
HideWindow
MessageBox MB_OK "$InfoOK"
FunctionEnd
- ------------------------------------------------------------------------------------
Function CustomPage
SectionGetFlags ${Section_Name} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show
Abort
show:
FunctionEnd
Function .onInit
;Extract InstallOptions files
;$PLUGINSDIR will automatically be removed when the installer closes
InitPluginsDir
File /oname=$PLUGINSDIR\SITENAMEsite_conf.ini "SITENAMEsite_conf.ini"
FunctionEnd
Function SetCustom
;Display the InstallOptions dialog
Push ${SERVER}
InstallOptions::dialog "$PLUGINSDIR\SITENAMEsite_conf.ini"
Pop ${SERVER}
Pop ${SERVER}
FunctionEnd
Function ValidateCustom
ReadINIStr ${SERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 2" "State"
ReadINIStr ${CHOSENSERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 2" "Text"
StrCmp ${SERVER} 1 done
ReadINIStr ${SERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 3" "State"
ReadINIStr ${CHOSENSERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 3" "Text"
StrCmp ${SERVER} 1 done
ReadINIStr ${SERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 4" "State"
ReadINIStr ${CHOSENSERVER} "$PLUGINSDIR\SITENAMEsite_conf.ini" "Field 4" "Text"
StrCmp ${SERVER} 1 done
MessageBox MB_ICONEXCLAMATION|MB_OK "You must select at least one install option!"
Abort
done:
FunctionEnd
Function .onInstSuccess
MessageBox MB_OK "SITENAME site installed correctly"
FunctionEnd
Function un.onUserAbort
MessageBox MB_YESNO "Abort uninstall?" IDYES NoCancelAbort
Abort ; causes uninstaller to not quit.
NoCancelAbort:
FunctionEnd
Function un.onInit
MessageBox MB_YESNO "This will uninstall. Continue?" IDYES NoAbort
Abort ; causes uninstaller to quit.
NoAbort:
FunctionEnd