|
1 |
| -#!/bin/sh |
| 1 | +#!/bin/bash |
2 | 2 | # @configure_input@
|
3 | 3 |
|
4 | 4 | # This script allows one to perform DOMjudge database setup actions.
|
@@ -52,32 +52,43 @@ not have to pass any of the options above.
|
52 | 52 | EOF
|
53 | 53 | }
|
54 | 54 |
|
| 55 | +urlencode() |
| 56 | +{ |
| 57 | + php -r "echo rawurlencode('$1');" |
| 58 | +} |
| 59 | + |
55 | 60 | mysql_options()
|
56 | 61 | {
|
57 | 62 | local user pass
|
| 63 | + declare -a _mysql_options=() |
58 | 64 |
|
59 | 65 | # shellcheck disable=SC2153
|
60 | 66 | if [ -n "$DBUSER" ]; then
|
61 |
| - user="-u $DBUSER" |
62 |
| - else |
63 |
| - user="${DBA_USER:+-u ${DBA_USER}}" |
| 67 | + result+=('-u', "$DBUSER") |
| 68 | + elif [ -n "$DBA_USER" ]; then |
| 69 | + result+=('-u', "$DBUSER") |
64 | 70 | fi
|
65 | 71 | # shellcheck disable=SC2153
|
66 | 72 | if [ -n "$PASSWD" ]; then
|
67 |
| - pass="-p$PASSWD" |
68 |
| - else |
69 |
| - [ -n "$PROMPT_PASSWD" ] && pass="-p" |
70 |
| - [ -n "$DBA_PASSWD" ] && pass="-p$DBA_PASSWD" |
| 73 | + result+=("-p$PASSWD") |
| 74 | + elif [ -n "$DBA_PASSWD" ]; then |
| 75 | + result+=("-p$DBA_PASSWD") |
| 76 | + elif [ -n "$PROMPT_PASSWD" ]; then |
| 77 | + result+=('-p') |
71 | 78 | fi
|
72 | 79 |
|
73 |
| - [ -z "$USE_SOCKET" ] && port="-P$DBPORT" |
74 |
| - echo $user ${pass:+"$pass"} -h "$DBHOST" ${port:+"$port"} |
| 80 | + results+=('-h', "$DBHOST") |
| 81 | + |
| 82 | + if [ -z "$USE_SOCKET" ]; then |
| 83 | + results+=("-P$DBPORT") |
| 84 | + fi |
75 | 85 | }
|
76 | 86 |
|
77 | 87 | # Wrapper around mysql command to allow setting options, user, etc.
|
78 | 88 | mysql()
|
79 | 89 | {
|
80 |
| - command mysql $(mysql_options) --silent --skip-column-names "$@" |
| 90 | + mysql_options |
| 91 | + command mysql "${_mysql_options[@]}" --silent --skip-column-names "$@" |
81 | 92 | }
|
82 | 93 |
|
83 | 94 | # Quick shell hack to get a key from an INI file.
|
@@ -129,9 +140,9 @@ symfony_console()
|
129 | 140 |
|
130 | 141 | if [ -n "$DBA_USER" ]; then
|
131 | 142 | if [ -n "$DBA_PASSWD" ]; then
|
132 |
| - DATABASE_URL=mysql://${DBA_USER}:${DBA_PASSWD}@${domjudge_DBHOST}:${domjudge_DBPORT}/${domjudge_DBNAME} |
| 143 | + DATABASE_URL="mysql://$(urlencode '${DBA_USER}'):$(urlencode '${DBA_PASSWD}')@$(urlencode '${domjudge_DBHOST}'):${domjudge_DBPORT}/$(urlencode '${domjudge_DBNAME}')" |
133 | 144 | else
|
134 |
| - DATABASE_URL=mysql://${DBA_USER}@${domjudge_DBHOST}:${domjudge_DBPORT}/${domjudge_DBNAME} |
| 145 | + DATABASE_URL="mysql://$(urlencode '${DBA_USER}')@$(urlencode '${domjudge_DBHOST}'):${domjudge_DBPORT}/$(urlencode '${domjudge_DBNAME}')" |
135 | 146 | fi
|
136 | 147 | fi
|
137 | 148 | fi
|
|
0 commit comments