DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Glossword WAMP Source Code (NSIS)

06.13.2007
| 11630 views |
  • submit to reddit
        // NSIS (http://nsis.sourceforge.net/)
// Glossword WAMP (http://sourceforge.net/projects/glossword/)
// Apache, MySQL and PHP are stored in archive usr.exe, directory /usr/local
// phpMyAdmin is in archive htdocs.exe, directory /htdocs/phpmyadmin
// Additionaly you need files with phrases: English.nsh and Russian.nsh
// ------------------------------------------
// English.nsh:
// LangString SECT_01 ${LANG_ENGLISH} "Glossword ${PRODUCT_VERSION}"
// LangString TXT_02 ${LANG_ENGLISH} "Thank you for installing Glossword.\r\nFor news and updates go to http://sourceforge.net/projects/glossword/"
// LangString DESC_SecGw ${LANG_ENGLISH} "Glossword program core files."
// ------------------------------------------
// install.bat
// @echo on
// cls
// SET ipath=%1
// cd "%ipath%/usr/local/apache2/bin"
// httpd.exe -k install -n Apache2_GW
// httpd.exe -k start -n Apache2_GW
// cd "%ipath%/usr/local/mysql5/bin"
// mysqld-nt.exe --install MySQL50_GW --defaults-file="%ipath%/usr/local/mysql5/bin/my-custom.cnf"
// net start MySQL50_GW
// ------------------------------------------
// uninstall.bat
// @echo off
// cls
// SET ipath=%1
// cd "%ipath%/usr/local/apache2/bin"
// httpd.exe -k stop -n Apache2_GW
// httpd.exe -k uninstall -n Apache2_GW
// net stop MySQL50_GW
// cd "%ipath%/usr/local/mysql5/bin"
// mysqld-nt.exe --remove MySQL50_GW
// ------------------------------------------
// unpack.bat
// @echo off
// usr.exe -y
// htdocs.exe -y
// del usr.exe
// del htdocs.exe
// del unpack.bat


Now you can create your own WAMP package.

; Glossword Desktop edition: Apache, MySQL, PHP
; Written by Dmitry Shilnikov (c) 2002-2007
; tty01@rambler.ru
;--------------------------------
;Include Modern UI

  	!include "MUI.nsh"

; replace in file with count of changes
	!include "FileFunc.nsh"
	
;--------------------------------
;Custom variables

	!define PRODUCT_NAME "Apache, MySQL, PHP"
	!define PRODUCT_VERSION "Apache/2.2.4, MySQL 5.0.41-community-nt, PHP 5.2.3 for Windows"
	!define DIR_SRC "."
	!define THIS_DIR_INSTALLTO "Glossword-WAMP"

;--------------------------------
;General

	Name "${PRODUCT_NAME}"
	OutFile "glossword-wamp.exe"

	;Folder selection page
	InstallDir "$PROGRAMFILES\Glossword-WAMP"

;--------------------------------
;Interface Settings

	!define MUI_ABORTWARNING
	!define MUI_UI ${NSISDIR}\Contrib\UIs\modern.exe
	!define MUI_ICON ${DIR_SRC}\install\gw_new.ico
	!define MUI_UNICON ${DIR_SRC}\install\gw_remove.ico
	!define MUI_FINISHPAGE_TEXT $(TXT_02)
	
;--------------------------------
;Pages

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

;Uninstaller pages
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

;--------------------------------
;Languages

!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "Russian"

;--------------------------------
;Installer Sections

Section "$(SECT_01)" SecGw

	SetDetailsPrint textonly
	DetailPrint "Installing server files..."
    SetOverwrite ifnewer
	
	DetailPrint "htdocs..."
	CreateDirectory "$INSTDIR\htdocs"
	CreateDirectory "$INSTDIR\htdocs\glossword"

	SetOutPath "$INSTDIR"
	File "usr.exe"
	File "htdocs.exe"
	File "unpack.bat"
	File "install.bat"
	File "uninstall.bat"
	File "localhost.url"
	File "phpinfo.url"
    File "phpmyadmin.url"
    File "news.url"
    File "glossword-wamp224_5041_523.txt"
	
	ExecWait '"unpack.bat"'

	SetOutPath "$INSTDIR"
	; change configuraiton files
	DetailPrint "httpd.conf..."
	ClearErrors
	FileOpen $0 "$INSTDIR\usr\local\apache2\conf\httpd.conf" "r"
	GetTempFileName $R0
	FileOpen $1 $R0 "w"
	loop1:
		FileRead $0 $2
		IfErrors done1
		StrCmp $2 "# Created by install$\r$\n" 0 +2
		StrCpy $2 "# Created by glossword-amp.exe$\r$\n"
		StrCmp $2 "DocumentRoot $\"E:/usr/httpdocs/svn/Glossword Desktop/htdocs$\"$\r$\n" 0 +2
		StrCpy $2 "DocumentRoot $\"$INSTDIR\htdocs$\"$\r$\n"
		StrCmp $2 "ServerRoot $\"E:/usr/httpdocs/svn/Glossword Desktop/usr/local/apache2$\"$\r$\n" 0 +2
		StrCpy $2 "ServerRoot $\"$INSTDIR\usr\local\apache2$\"$\r$\n"
		FileWrite $1 $2
	Goto loop1
	done1:
		FileClose $0
		FileClose $1
		Delete "$INSTDIR\usr\local\apache2\conf\httpd.conf"
		CopyFiles /SILENT $R0 "$INSTDIR\usr\local\apache2\conf\httpd.conf"
		Delete $R0
	;		
	DetailPrint "my-custom.cnf..."
	ClearErrors
	FileOpen $0 "$INSTDIR\usr\local\mysql5\bin\my-custom.cnf" "r"
	GetTempFileName $R0
	FileOpen $1 $R0 "w"
	loop2:
		FileRead $0 $2
		IfErrors done2
		StrCmp $2 "basedir=$\"../mysql5/$\"$\r$\n" 0 +2
		StrCpy $2 "basedir=$\"$INSTDIR\usr\local\mysql5\$\"$\r$\n"
		StrCmp $2 "datadir=$\"../mysql5/data/$\"$\r$\n" 0 +2
		StrCpy $2 "datadir=$\"$INSTDIR\usr\local\mysql5\data\$\"$\r$\n"
		FileWrite $1 $2
	Goto loop2
	done2:
		FileClose $0
		FileClose $1
		Delete "$INSTDIR\usr\local\mysql5\bin\my-custom.cnf"
		CopyFiles /SILENT $R0 "$INSTDIR\usr\local\mysql5\bin\my-custom.cnf"
		Delete $R0
	;
	DetailPrint "php.ini..."
	ClearErrors
	FileOpen $0 "$INSTDIR\usr\local\php5\php.ini" "r"
	GetTempFileName $R0
	FileOpen $1 $R0 "w"
	loop5:
		FileRead $0 $2
		IfErrors done5
		StrCmp $2 "extension_dir = $\"../../php5/ext$\"$\r$\n" 0 +2
		StrCpy $2 "extension_dir = $\"$INSTDIR\usr\local\php5\ext$\"$\r$\n"
		StrCmp $2 "session.save_path = $\"c:/temp$\"$\r$\n" 0 +2
		StrCpy $2 "session.save_path = $\"$TEMP$\"$\r$\n"
		FileWrite $1 $2
	Goto loop5
	done5:
		FileClose $0
		FileClose $1
		Delete "$INSTDIR\usr\local\php5\php.ini"
		CopyFiles /SILENT $R0 "$INSTDIR\usr\local\php5\php.ini"
		Delete $R0
	;	
	DetailPrint "install.bat..."
	ClearErrors
	FileOpen $0 "$INSTDIR\install.bat" "r"
	GetTempFileName $R0
	FileOpen $1 $R0 "w"
	loop3:
		FileRead $0 $2
		IfErrors done3
		StrCmp $2 "set ipath=%1$\r$\n" 0 +2
		StrCpy $2 "set ipath=$INSTDIR$\r$\n"
		FileWrite $1 $2
	Goto loop3
	done3:
		FileClose $0
		FileClose $1
		Delete "$INSTDIR\install.bat"
		CopyFiles /SILENT $R0 "$INSTDIR\install.bat"
		Delete $R0
	;
	DetailPrint "uninstall.bat..."
	ClearErrors
	FileOpen $0 "$INSTDIR\uninstall.bat" "r"
	GetTempFileName $R0
	FileOpen $1 $R0 "w"
	loop4:
		FileRead $0 $2
		IfErrors done4
		StrCmp $2 "set ipath=%1$\r$\n" 0 +2
		StrCpy $2 "set ipath=$INSTDIR$\r$\n"
		FileWrite $1 $2
	Goto loop4
	done4:
		FileClose $0
		FileClose $1
		Delete "$INSTDIR\uninstall.bat"
		CopyFiles /SILENT $R0 "$INSTDIR\uninstall.bat"
		Delete $R0
	ExecWait '"install.bat"'
	;nsExec::ExecToStack '"install.bat"'

	SetOverwrite off

	CreateDirectory "$SMPROGRAMS\${THIS_DIR_INSTALLTO}"
	CreateShortCut "$SMPROGRAMS\${THIS_DIR_INSTALLTO}\Glossword at localhost.lnk" "$INSTDIR\localhost.url"
	CreateShortCut "$SMPROGRAMS\${THIS_DIR_INSTALLTO}\Glossword development news.lnk" "$INSTDIR\news.url"
	CreateShortCut "$SMPROGRAMS\${THIS_DIR_INSTALLTO}\phpinfo().lnk" "$INSTDIR\phpinfo.url"
    CreateShortCut "$SMPROGRAMS\${THIS_DIR_INSTALLTO}\phpMyAdmin.lnk" "$INSTDIR\phpmyadmin.url"
	CreateShortCut "$SMPROGRAMS\${THIS_DIR_INSTALLTO}\Apache Monitor.lnk" "$INSTDIR\usr\local\apache2\bin\ApacheMonitor.exe"
	CreateShortCut "$SMPROGRAMS\${THIS_DIR_INSTALLTO}\Remove Glossword WAMP.lnk" "$INSTDIR\uninstall.exe"
    CreateShortCut "$SMPROGRAMS\${THIS_DIR_INSTALLTO}\Release notes.lnk" "$INSTDIR\glossword-wamp224_5041_523.txt"

  	WriteUninstaller "$INSTDIR\uninstall.exe"
SectionEnd

  
;--------------------------------
;Descriptions

!include "${DIR_SRC}\install\English.nsh"
!include "${DIR_SRC}\install\Russian.nsh"

!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
	!insertmacro MUI_DESCRIPTION_TEXT ${SecGw} $(DESC_SecGw)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
 
;--------------------------------
; Functions

Function .onInit
	!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd

;--------------------------------
;Uninstaller Section

Section Uninstall
	
	SetOutPath "$INSTDIR"
	ExecWait '"uninstall.bat"'

	SetShellVarContext current
	Delete "$SMPROGRAMS\${THIS_DIR_INSTALLTO}\Remove Glossword WAMP.lnk"
	Delete "$SMPROGRAMS\${THIS_DIR_INSTALLTO}\Apache Monitor.lnk"
	Delete "$SMPROGRAMS\${THIS_DIR_INSTALLTO}\Glossword at localhost.lnk"
	Delete "$SMPROGRAMS\${THIS_DIR_INSTALLTO}\Glossword development news.lnk"
	Delete "$SMPROGRAMS\${THIS_DIR_INSTALLTO}\phpinfo().lnk"
    Delete "$SMPROGRAMS\${THIS_DIR_INSTALLTO}\phpMyAdmin.lnk"
    Delete "$SMPROGRAMS\${THIS_DIR_INSTALLTO}\Release Notes.lnk"
	RMDir /r "$SMPROGRAMS\${THIS_DIR_INSTALLTO}"
	RMDir /r "$INSTDIR\usr\local\apache2"
	RMDir /r "$INSTDIR\usr\local\php5"
	RMDir /r "$INSTDIR\usr\local\mysql5\bin"
	RMDir /r "$INSTDIR\usr\local\mysql5\share"
	RMDir /r "$INSTDIR\htdocs\phpmyadmin"
	Delete "$INSTDIR\install.bat"
	Delete "$INSTDIR\uninstall.bat"
	Delete "$INSTDIR\glossword-wamp224_5041_523.txt"
	Delete "$INSTDIR\localhost.url"
	Delete "$INSTDIR\phpinfo.url"
	Delete "$INSTDIR\phpmyadmin.url"

 	;RMDir /r "$INSTDIR"
	SetAutoClose true
  
SectionEnd