| 
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,30 +52,47 @@ 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 | + | 
 | 60 | +# This is global variable to be able to return the output from  | 
 | 61 | +# mysql_options() below as an array, which is not possible otherwise.  | 
 | 62 | +declare -a _mysql_options  | 
 | 63 | + | 
55 | 64 | mysql_options()  | 
56 | 65 | {  | 
 | 66 | +	local user pass  | 
 | 67 | +	_mysql_options=()  | 
 | 68 | + | 
57 | 69 | 	# shellcheck disable=SC2153  | 
58 | 70 | 	if [ -n "$DBUSER" ]; then  | 
59 |  | -		_user="-u $DBUSER"  | 
60 |  | -	else  | 
61 |  | -		_user="${DBA_USER:+-u ${DBA_USER}}"  | 
 | 71 | +		_mysql_options+=('-u' "$DBUSER")  | 
 | 72 | +	elif [ -n "$DBA_USER" ]; then  | 
 | 73 | +		_mysql_options+=('-u' "$DBA_USER")  | 
62 | 74 | 	fi  | 
63 | 75 | 	# shellcheck disable=SC2153  | 
64 | 76 | 	if [ -n "$PASSWD" ]; then  | 
65 |  | -		_pass="-p$PASSWD"  | 
66 |  | -	else  | 
67 |  | -		[ -n "$PROMPT_PASSWD" ] && _pass="-p"  | 
68 |  | -		[ -n "$DBA_PASSWD" ]    && _pass="-p$DBA_PASSWD"  | 
 | 77 | +		_mysql_options+=("-p$PASSWD")  | 
 | 78 | +	elif [ -n "$DBA_PASSWD" ]; then  | 
 | 79 | +		_mysql_options+=("-p$DBA_PASSWD")  | 
 | 80 | +	elif [ -n "$PROMPT_PASSWD" ]; then  | 
 | 81 | +		_mysql_options+=('-p')  | 
69 | 82 | 	fi  | 
70 | 83 | 
 
  | 
71 |  | -	[ -z "$USE_SOCKET" ] && port="-P$DBPORT"  | 
72 |  | -	echo $_user ${_pass:+"$_pass"} -h "$DBHOST" ${port:+"$port"}  | 
 | 84 | +	_mysql_options+=('-h' "$DBHOST")  | 
 | 85 | + | 
 | 86 | +	if [ -z "$USE_SOCKET" ]; then  | 
 | 87 | +		_mysql_options+=("-P$DBPORT")  | 
 | 88 | +	fi  | 
73 | 89 | }  | 
74 | 90 | 
 
  | 
75 | 91 | # Wrapper around mysql command to allow setting options, user, etc.  | 
76 | 92 | mysql()  | 
77 | 93 | {  | 
78 |  | -	command mysql $(mysql_options) --silent --skip-column-names "$@"  | 
 | 94 | +	mysql_options  | 
 | 95 | +	command mysql "${_mysql_options[@]}" --silent --skip-column-names "$@"  | 
79 | 96 | }  | 
80 | 97 | 
 
  | 
81 | 98 | # Quick shell hack to get a key from an INI file.  | 
@@ -126,10 +143,13 @@ symfony_console()  | 
126 | 143 | 		fi  | 
127 | 144 | 
 
  | 
128 | 145 | 		if [ -n "$DBA_USER" ]; then  | 
 | 146 | +			user=$(urlencode "${DBA_USER}")  | 
 | 147 | +			host=$(urlencode "${domjudge_DBHOST}")  | 
 | 148 | +			db=$(urlencode "${domjudge_DBNAME}")  | 
129 | 149 | 			if [ -n "$DBA_PASSWD" ]; then  | 
130 |  | -				DATABASE_URL=mysql://${DBA_USER}:${DBA_PASSWD}@${domjudge_DBHOST}:${domjudge_DBPORT}/${domjudge_DBNAME}  | 
 | 150 | +				DATABASE_URL="mysql://$user:$(urlencode "${DBA_PASSWD}")@$host:${domjudge_DBPORT}/$db"  | 
131 | 151 | 			else  | 
132 |  | -				DATABASE_URL=mysql://${DBA_USER}@${domjudge_DBHOST}:${domjudge_DBPORT}/${domjudge_DBNAME}  | 
 | 152 | +				DATABASE_URL="mysql://$user@$host:${domjudge_DBPORT}/$db"  | 
133 | 153 | 			fi  | 
134 | 154 | 		fi  | 
135 | 155 | 	fi  | 
 | 
0 commit comments