inst-resources/postgresql.nsh
author Dan
Sat, 11 Jul 2009 10:08:22 -0400
changeset 4 ea7b100e5de6
parent 0 67e1cc6cd929
permissions -rw-r--r--
Got some basic uninstaller code in
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 PostgreSQL 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
!macro postgresql_get_bin_dir
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     9
  StrCpy $R2 "$stack_instdir\postgresql\bin"
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    10
!macroend
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    11
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    12
Function postgresql_connect
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    13
  Pop $R1 ; Password
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    14
  Pop $R0 ; Username
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    15
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    16
  SetOutPath $PLUGINSDIR
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    17
  File "inst-resources\postgresqlutil.php"
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    18
  
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    19
  nsExec::ExecToLog '"$stack_instdir\php\php.exe" "$PLUGINSDIR\postgresqlutil.php" "$R0" "$R1"'
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    20
  Delete "$PLUGINSDIR\postgresqlutil.php"
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    21
  ; just be done; nsExec's result is on the top of the stack.
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    22
FunctionEnd
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    23
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    24
/**
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    25
 * Create a postgresql database and grant privileges on it to the given user.
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    26
 * @param string User to connect with
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    27
 * @param string Password to connect with
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    28
 * @param string Database name
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    29
 * @param string New user
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    30
 * @param string New user's password
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    31
 */
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    32
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    33
Function postgresql_create_db
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    34
  Pop $R5 ; Password
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    35
  Pop $R4 ; User
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    36
  Pop $R3 ; Database
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    37
  Pop $R1 ; Password
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    38
  Pop $R0 ; Username
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    39
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    40
  /*
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    41
  ; This isn't a working feature in PostgreSQL.
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    42
  IfFileExists "$stack_instdir\postgresql\data\$R3" 0 DatabaseDoesNotExist
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    43
    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 PostgreSQL's permissions, and you may need to set up permissions manually." IDYES +2
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    44
      Return
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    45
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    46
  DatabaseDoesNotExist:
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    47
  */
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    48
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    49
  SetOutPath $PLUGINSDIR
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    50
  File "inst-resources\postgresqlutil.php"
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    51
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    52
  nsExec::ExecToLog '"$stack_instdir\php\php.exe" "$PLUGINSDIR\postgresqlutil.php" "$R0" "$R1" \
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    53
                     "DROP DATABASE IF EXISTS $R3; \
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    54
                      DROP ROLE IF EXISTS $R4; \
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    55
                      CREATE ROLE $R4 WITH PASSWORD $\'$R5$\' LOGIN; \
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    56
                      CREATE DATABASE $R3 WITH OWNER $R4;"'
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    57
  Delete "$PLUGINSDIR\postgresqlutil.php"
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    58
FunctionEnd
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    59