inst-resources/mysql.nsh
author Dan
Sat, 11 Jul 2009 10:07:32 -0400
changeset 3 0cce88c7cf7c
parent 0 67e1cc6cd929
child 10 014d58335b6d
permissions -rw-r--r--
Added Makefile
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     1
/**
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     2
 * Verify credentials for a MySQL database. Assumes we are connecting to BitNami's DB.
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     3
 * @param string Username
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     4
 * @param string Password
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     5
 * @return int 0 if successful, >0 on error. Will push an error string to the stack if >0.
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     6
 */
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     7
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     8
Function mysql_connect
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     9
  Pop $R1 ; Password
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    10
  Pop $R0 ; Username
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    11
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    12
  SetOutPath $PLUGINSDIR
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    13
  File "inst-resources\mysqlutil.php"
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    14
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    15
  nsExec::ExecToLog '"$stack_instdir\php\php.exe" "$PLUGINSDIR\mysqlutil.php" $db_port "$R0" "$R1"'
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    16
  Delete "$PLUGINSDIR\mysqlutil.php"
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    17
  ; just be done; nsExec's result is on the top of the stack.
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    18
FunctionEnd
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    19
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    20
/**
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    21
 * Create a MySQL database and grant privileges on it to the given user.
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    22
 * @param string User to connect with
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    23
 * @param string Password to connect with
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    24
 * @param string Database name
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    25
 * @param string New user
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    26
 * @param string New user's password
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    27
 */
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    28
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    29
Function mysql_create_db
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    30
  Pop $R5 ; Password
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    31
  Pop $R4 ; User
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    32
  Pop $R3 ; Database
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    33
  Pop $R1 ; Password
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    34
  Pop $R0 ; Username
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    35
  
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    36
  ReadINIStr $R2 "$stack_instdir\properties.ini" "MySQL" "mysql_root_directory"
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    37
  IfFileExists "$R2\data\$R3" 0 DatabaseDoesNotExist
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    38
    MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "The database $\"$R3$\" already exists. Do you want to delete and recreate it?$\n$\nIf you choose No, Setup will not alter MySQL's permissions, and you may need to set up permissions manually." IDYES +2
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    39
      Return
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    40
    
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    41
  DatabaseDoesNotExist:
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    42
  
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    43
  SetOutPath $PLUGINSDIR
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    44
  File "inst-resources\mysqlutil.php"
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    45
  
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    46
  nsExec::ExecToLog '"$stack_instdir\php\php.exe" "$PLUGINSDIR\mysqlutil.php" $db_port "$R0" "$R1" \
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    47
                     "DROP DATABASE IF EXISTS `$R3`; \
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    48
                      CREATE DATABASE `$R3`; \
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    49
                      GRANT ALL PRIVILEGES ON `$R3`.* TO `$R4`@localhost \
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    50
                        IDENTIFIED BY $\'$R5$\' WITH GRANT OPTION;"'
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    51
  Delete "$PLUGINSDIR\mysqlutil.php"
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    52
FunctionEnd
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    53