Joomla Addon วุดทำไว้สำหรับ Joomla ใช้ NSIS ทำ เซฟโค้ดเก็บไว้หน่อย เผื่อได้ลอกมาทำของ Drupal เล่นมั่ง
ตะก่อนเคยทำตัว Install ของชุดเสริม Blender เล่นอยู่ นานจนลืมไปล๊ะ ถ้าทำอีกคงต้องฟื้นใหม่
โค้ด
;AppServ Addons NSIS Script
;Powered by wutthipron
;AddOns Version
!define APPNAME "AppServ AddOn"
!define VERSION "Joomla 1.5"
!define ADNDIR "joomla"
!define DBDIR "joomla"
!define /date DATE "%Y-%m-%d"
;--------------------------------
;Include Modern UI
!include "MUI.nsh"
!include "LogicLib.nsh"
!include "WordFunc.nsh"
!include "..\NSIS Plugins\StrRep.nsh"
!include "..\NSIS Plugins\ReplaceInFile.nsh"
;--------------------------------
; Main Install settings
Name "${APPNAME} ${VERSION}"
InstallDirRegKey HKCU "Software\AppServ" "AppServDir"
OutFile "joomla1.5-win32-setup.exe"
ShowInstDetails show
ShowUninstDetails show
; Use compression
SetCompressor LZMA
; Style
XPStyle on
;--------------------------------
;Interface Configuration
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "joomla_header.bmp" ; optional
!define MUI_ABORTWARNING
;--------------------------------
;Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "COPYING.txt"
Page custom MySQLDialog ValidMySQL
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
Page custom AddOnsDesc
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "Thai"
;Variables
;Var InsDirShort
Var InsDirSlash
Var MySQLPasswd1
Var MySQLPasswd2
var output
;--------------------------------
; Macro Functions
!insertmacro WordReplace
;--------------------------------
;Installer Functions
LangString TEXT_IO_TITLE ${LANG_ENGLISH} "InstallOptions page"
LangString TEXT_IO_SUBTITLE ${LANG_ENGLISH} "This is a page created using the InstallOptions plug-in."
Function .onInit
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "MySQLDialog.ini"
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "AddOnsDesc.ini"
;Appserv Splash Screen
InitPluginsDir
File /oname=$PLUGINSDIR\splash.bmp "splash-joomla.bmp"
advsplash::show 1000 600 400 -1 $PLUGINSDIR\splash
Pop $0 ; $0 has '1' if the user closed the splash screen early,
; '0' if everything closed normally, and '-1' if some error occurred.
Delete $PLUGINSDIR\splash.bmp
FunctionEnd
Function AddOnsDesc
!insertmacro MUI_HEADER_TEXT "AddOns Instruction" ""
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "AddOnsDesc.ini"
FunctionEnd
Function MySQLDialog
!insertmacro MUI_HEADER_TEXT "MySQL Database Configuration" "Configure user access to MySQL Database."
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "MySQLDialog.ini"
FunctionEnd
Function ValidMySQL
!insertmacro MUI_INSTALLOPTIONS_READ $MySQLPasswd1 "MySQLDialog.ini" "Field 3" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $MySQLPasswd2 "MySQLDialog.ini" "Field 5" "State"
${WordReplace} "$MySQLPasswd1" " " "" "+" $MySQLPasswd1
${WordReplace} "$MySQLPasswd2" " " "" "+" $MySQLPasswd2
${If} $MySQLPasswd1 == ''
MessageBox MB_ICONEXCLAMATION|MB_OK "Please enter root password."
Abort
${EndIf}
${If} $MySQLPasswd2 == ''
MessageBox MB_ICONEXCLAMATION|MB_OK "¡ÃسÒãÊèÃËÑÊŒèÒ¹ÊÓËÃѺ root àŸ×èÍàª×èÍÁµèͰҹ¢éÍÁÙÅ."
Abort
${EndIf}
${if} $MySQLPasswd1 == $MySQLPasswd2
ExecWait '"$INSTDIR\MySQL\bin\mysqladmin" -u root -p$MySQLPasswd1 reload' $output
StrCmp $output 1 0 +7
;MessageBox MB_ICONEXCLAMATION|MB_OK "¡ÃسÒÃÍÊÑ¡€ÃÙè¡ÓÅѧàª×èÍÁµèͰҹ¢éÍÁÙÅÍÂÙè"
;MessageBox MB_ICONEXCLAMATION|MB_OK "€èÒÃËÑÊŒèÒ¹ root ŒÔŽ"
Abort
${Endif}
${If} $MySQLPasswd1 != $MySQLPasswd2
MessageBox MB_ICONEXCLAMATION|MB_OK "€èÒÃËÑÊŒèÒ¹¢Í§ root ÊÓËÃѺ°Ò¹¢éÍÁÙÅ Mysql äÁèµÃ§¡Ñ¹"
Abort
${EndIf}
FunctionEnd
;--------------------------------
;Installer Sections
Section "AddOns Section" SecAddOns
GetFullPathName /SHORT $InsDirSlash $INSTDIR
${WordReplace} "$InsDirSlash" "\" "\\" "+" $InsDirSlash
;System files
SetOutPath "$INSTDIR\www\${ADNDIR}"
File /a /r /x *.db "${ADNDIR}\*.*"
${WordReplace} "$MySQLPasswd1" `'` `\'` "+" $MySQLPasswd1
${WordReplace} "$MySQLPasswd1" `"` `\"` "+" $MySQLPasswd1
!insertmacro ReplaceInFile "$INSTDIR\www\${ADNDIR}\configuration.php" "@@MySQLROOT@@" "$MySQLPasswd1"
!insertmacro ReplaceInFile "$INSTDIR\www\${ADNDIR}\configuration.php" "@@JoomlaPath@@" "$InsDirSlash\\www\\${ADNDIR}"
;MessageBox MB_ICONEXCLAMATION|MB_OK "$MySQLPasswd1"
;Database files
SetOutPath "$INSTDIR\mysql\data\${DBDIR}"
File /a /r "data\${DBDIR}\*.*"
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall-${VERSION}.exe"
SectionEnd
;--------------------------------
;Uninstaller Section
Section "Uninstall"
;Delete System file
RMDir /r "$INSTDIR\www\${ADNDIR}"
;Delete Database file
RMDir /r "$INSTDIR\mysql\data\${DBDIR}"
Delete "$INSTDIR\Uninstall-${VERSION}.exe"
SectionEnd




Post new comment