/**************************************************************** * Copyright (C) 2006 LAMS Foundation (http://lamsfoundation.org) * ============================================================= * License Information: http://lamsfoundation.org/licensing/lams/2.0/ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2.0 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA * * http://www.gnu.org/licenses/gpl.txt * **************************************************************** * Coded by Luke Foxton (lfoxton@melcoe.mq.edu.au) */ # includes !include "MUI.nsh" !include "LogicLib.nsh" !include "backup.nsh" #defines !define REG_HEAD "Software\LAMS Foundation\LAMSv2" !define MUI_ICON "..\graphics\lams2.ico" # Installer attributes Name "LAMS Backup Utility" BrandingText "LAMS Backup Utility" OutFile "..\build\lams-backup.exe" InstallDir "C:\lams" Icon ..\graphics\lams2.ico InstallDirRegKey HKLM "${REG_HEAD}" "" VIProductVersion 2.0.0.0 VIAddVersionKey ProductName "LAMS Backup Utility" VIAddVersionKey ProductVersion "1.0" VIAddVersionKey CompanyName "LAMS International" VIAddVersionKey CompanyWebsite "lamscommunity.org" VIAddVersionKey FileVersion "" VIAddVersionKey FileDescription "" VIAddVersionKey LegalCopyright "" !define MUI_FINISHPAGE_TEXT "LAMS has been successfully backed up on your computer" # set warning when cancelling install !define MUI_ABORTWARNING Page custom PreBackupDir PostBackupDir !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH !insertmacro MUI_LANGUAGE "English" # variables Var DB_NAME Var DB_USER Var DB_PASS Var MYSQL_DIR Var BACKUP_DIR ReserveFile "backup.ini" Section backup ;make the section compulsory SectionIn RO setoutpath $BACKUP_DIR file "..\backup.txt" clearerrors DetailPrint "Backing up lams at: $BACKUP_DIR. This may take a few minutes" SetDetailsPrint listonly createdirectory $BACKUP_DIR copyfiles /SILENT $INSTDIR $BACKUP_DIR SetDetailsPrint both iferrors error1 continue1 error1: DetailPrint "Backup failed" MessageBox MB_OK|MB_ICONSTOP "LAMS backup to $BACKUP_DIR failed. Check that all other applications are closed and LAMS is not running." Abort continue1: DetailPrint 'Dumping database to: $BACKUP_DIR' setoutpath "$BACKUP_DIR" Strcpy $4 '"$MYSQL_DIR\bin\mysqldump" -r "$BACKUP_DIR\dump.sql" $DB_NAME -u $DB_USER -p$DB_PASS' DetailPrint $4 nsExec::ExecToStack $4 Pop $0 Pop $1 ${If} $0 == "yes" goto error ${EndIf} goto done error: DetailPrint "Database dump failed" MessageBox MB_OK|MB_ICONSTOP "Database dump failed $\r$\nError:$\r$\n$\r$\n$1" Abort "Database dump failed" done: SectionEnd Function .onInit ReadRegStr $INSTDIR HKLM "${REG_HEAD}" "dir_inst" ReadRegStr $DB_NAME HKLM "${REG_HEAD}" "db_name" ReadRegStr $DB_USER HKLM "${REG_HEAD}" "db_user" ReadRegStr $DB_PASS HKLM "${REG_HEAD}" "db_pass" ReadRegStr $MYSQL_DIR HKLM "${REG_HEAD}" "dir_mysql" call CheckMySQL Call GetLocalTime Pop "$0" ;Variable (for day) Pop "$1" ;Variable (for month) Pop "$2" ;Variable (for year) Pop "$3" ;Variable (for day of week name) Pop "$4" ;Variable (for hour) Pop "$5" ;Variable (for minute) Pop "$6" ;Variable (for second) strlen $7 $0 ${if} $7 == 1 strcpy $0 "0$0" ${endif} strlen $7 $1 ${if} $7 == 1 strcpy $1 "0$1" ${endif} strlen $7 $4 ${if} $7 == 1 strcpy $4 "0$4" ${endif} strlen $7 $5 ${if} $7 == 1 strcpy $1 "0$5" ${endif} strcpy $BACKUP_DIR "$INSTDIR-$2$1$0$4$5.bak" !insertmacro MUI_INSTALLOPTIONS_EXTRACT "backup.ini" FunctionEnd Function PreBackupDir !insertmacro MUI_INSTALLOPTIONS_WRITE "backup.ini" "Field 1" "State" "$BACKUP_DIR" !insertmacro MUI_HEADER_TEXT "LAMS Backup Dir" "Enter a directory in the space provided" !insertmacro MUI_INSTALLOPTIONS_DISPLAY "backup.ini" FunctionEnd Function PostBackupDir !insertmacro MUI_INSTALLOPTIONS_READ $BACKUP_DIR "backup.ini" "Field 1" "State" ${if} $BACKUP_DIR == "" MessageBox MB_OK|MB_ICONEXCLAMATION "The directory entered is not valid: $\r$\n$BACKUP_DIR" Abort ${endif} iffileexists $BACKUP_DIR exists continue iffileexists "$BACKUP_DIR\*" exists continue goto continue exists: MessageBox MB_OK|MB_ICONEXCLAMATION "The file name for the directory entered is already in use: $\r$\n$BACKUP_DIR" continue: FunctionEnd Function CheckMySQL # Checking if the given database name already exists in the mysql database list ifFileExists "$MYSQL_DIR\data\$DB_NAME\*.*" continue NoDatabaseNameExists NoDatabaseNameExists: MessageBox MB_OK|MB_ICONSTOP "Could not find database $DB_NAME. Please check your database settings and try again" quit continue: # check mysql version is 5.0.x nsExec::ExecToStack '$MYSQL_DIR\bin\mysqladmin --version' Pop $0 Pop $1 ${If} $1 == "" ; if mySQL install directory field is empty, do not continue MessageBox MB_OK|MB_ICONSTOP "Your MySQL directory does not appear to be valid, please enter a valid MySQL directory before continuing.$\r$\n$\r$\n$1" Abort ${EndIf} ${StrStr} $0 $1 "5.0" ${If} $0 == "" ; if not 5.0.x, check 5.1.x ${StrStr} $0 $1 "5.1" ${If} $0 == "" MessageBox MB_OK|MB_ICONSTOP "Your MySQL version does not appear to be compatible with LAMS (5.0.x or 5.1.x): $\r$\n$\r$\n$1" MessageBox MB_OK|MB_ICONSTOP "Your MySQL directory does not appear to be valid, please enter a valid MySQL directory before continuing.$\r$\n$\r$\n$1" Abort ${endif} ${EndIf} FunctionEnd