bootstrap.sh: clarify what the --overwrite-profile option does
[drupal-init-tools.git] / libexec / new.sh
1 #!/bin/bash
2 # Create a new Drupal project
3 #
4 # Copyright (C) 2017  Antonio Ospite <ao2@ao2.it>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 set -e
20
21 usage() {
22   cat <<EOF
23 usage: drin $(basename "$0" .sh) [-h|--help] <destdir>
24
25 Create a new Drupal project in the 'destdir' directory.
26
27 Options:
28   -h, --help          display this usage message and exit
29 EOF
30 }
31
32 while [ $# -gt 0 ];
33 do
34   case "$1" in
35     -h|--help)
36       usage
37       exit 0
38       ;;
39     -*)
40       echo "Error: Unknown option '${1}'" 1>&2
41       ;;
42     *)
43       break
44       ;;
45   esac
46   shift
47 done
48
49 [ "x$1" = "x" ] && { usage 1>&2; exit 1; }
50
51 [ -d "$1" ] && { echo "Aborting, project directory already exists." 1>&2; exit 1; }
52
53 DESTDIR="$1"
54
55 command -v composer &> /dev/null || { echo "Aborting, 'composer' not available." 1>&2; exit 1; }
56 command -v git &> /dev/null || { echo "Aborting, 'git' not available." 1>&2; exit 1; }
57
58 # Create a new project keeping the VCS metadata so it's easier to bring in
59 # updates to drupal-composer/drupal-project itself.
60 echo "Creating a new Drupal project..."
61 composer create-project drupal-composer/drupal-project:8.x-dev@dev "$DESTDIR" --keep-vcs --stability dev --no-interaction
62
63 pushd "$DESTDIR"
64
65 git remote rename origin upstream
66 git checkout -b master
67
68 # Add some patches
69 composer config extra.patches-file "composer.patches.json"
70
71 cat > composer.patches.json <<EOF
72 {
73   "patches": {
74     "drupal/core": {
75       "drupal-do_not_disable_MultiViews_htaccess": "https://www.drupal.org/files/issues/drupal-do_not_disable_MultiViews_htaccess-2619250-24.patch"
76     }
77   }
78 }
79 EOF
80
81 # Apply the patches
82 composer update
83
84 # Add a template config file for the bootstrap script
85 cat > bootstrap.conf <<EOF
86 #DB_NAME="drupal_test_database"
87 #DB_USER="drupal_test_user"
88 #DB_PASS="drupal_test_password"
89
90 #ACCOUNT_NAME="admin"
91 #ACCOUNT_PASS="admin"
92 #ACCOUNT_MAIL="admin@example.com"
93
94 #SITE_NAME="example"
95 #SITE_MAIL="admin@example.com"
96
97 #SITE_BASE_PATH="/~${USER}/$(basename "${PWD}")/web"
98
99 #WEB_SERVER_GROUP="www-data"
100
101 #INSTALLATION_PROFILE="standard"
102
103 #TRUSTED_HOSTS=(
104 #  "localhost"
105 #  "ip4-localhost"
106 #  "ip6-localhost"
107 #  )
108
109 # See the 'drin' man page for details about database access.
110
111 # Set MYSQL_PASSWORDLESS_ACCESS to 'true' if the database is configured to
112 # allow administrative password-less access to the user who will execute the
113 # 'drin boostrap' command.
114 #MYSQL_PASSWORDLESS_ACCESS=true
115
116 # If, instead,  administrative access requires a password, uncomment and
117 # change the values of the following variables.
118 #MYSQL_SU_USER='root'
119 #MYSQL_SU_PASSWORD='password'
120 EOF
121
122 cat > .gitignore <<EOF
123 # Ignore the configuration for the bootstrap script
124 bootstrap.conf
125 EOF
126
127 echo
128 echo "Uncomment and customize the values in the bootstrap.conf file."
129
130 # Add some basic access control to protect sensitive files like bootstrap.conf
131 cat > .htaccess <<EOF
132 Options -Indexes
133 SetEnvIf Request_URI "/web(/.*)?$" access_granted
134 Order allow,deny
135 Allow from env=access_granted
136 EOF
137
138 echo
139 echo "Double check the provided .htaccess file to make sure that access to"
140 echo "'$PWD' is restricted by the web server."
141
142 popd