forked from ddev/ddev-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-drupal-regex-function.sh
55 lines (45 loc) · 1.93 KB
/
install-drupal-regex-function.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# Installs the Regex database function for compatibility with Drupal version 9 or higher.
# This script only needs to be run once for a database.
usage() { echo "./install-drupal-regex-function.sh -u <username> -p <password> -d <database>" 1>&2; exit 1; }
# The password for the database defaults to ""
password=""
# The username for the database defaults to "SA"
username="SA"
# The database name defaults to "master"
database="master"
while getopts ":u:p:d:h:" arg; do
case $arg in
u)
username=${OPTARG}
;;
p)
password=${OPTARG}
;;
d)
database=${OPTARG}
;;
h)
usage
;;
*)
usage
;;
esac
done
if [ -z $password ]
then
echo "The parameter -p for the password is not set."
exit 1
fi
if ! ddev exec -s sqlsrv test -e "/RegEx.dll" &>/dev/null;
then
# Download the Regex.dll file and copy it to the right location.
ddev exec -s sqlsrv wget https://github.com/Beakerboy/drupal-sqlsrv-regex/releases/download/1.0/RegEx.dll
fi
# The following are changed to allow the installation and execution of the user provided database function.
ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'EXEC sp_configure \"show advanced options\", 1; RECONFIGURE; EXEC sp_configure \"clr strict security\", 0; RECONFIGURE; EXEC sp_configure \"clr enable\", 1; RECONFIGURE;'"
# Create the assambly and the function for the Regex helper.
ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'CREATE ASSEMBLY Regex from \"/RegEx.dll\" WITH PERMISSION_SET = SAFE'"
ddev exec -s sqlsrv "/opt/mssql-tools/bin/sqlcmd -P $password -S localhost -U $username -d $database -Q 'CREATE FUNCTION dbo.REGEXP(@pattern NVARCHAR(100), @matchString NVARCHAR(100)) RETURNS bit EXTERNAL NAME Regex.RegExCompiled.RegExCompiledMatch'"
# **Contributed by [@drupal-daffie](https://github.com/drupal-daffie)**