-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit
executable file
·126 lines (98 loc) · 3.06 KB
/
init
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
## Initialize a Docksal powered Drupal 8 site
##
## Usage: fin init
# Abort if anything fails
set -e
#-------------------------- Settings --------------------------------
# PROJECT_ROOT is passed from fin.
# The following variables are configured in the '.env' file: DOCROOT, VIRTUAL_HOST.
SITE_DIRECTORY="default"
DOCROOT_PATH="${PROJECT_ROOT}/${DOCROOT}"
SITEDIR_PATH="${DOCROOT_PATH}/sites/${SITE_DIRECTORY}"
#-------------------------- END: Settings --------------------------------
#-------------------------- Helper functions --------------------------------
# Console colors
red='\033[0;31m'
green='\033[0;32m'
green_bg='\033[42m'
yellow='\033[1;33m'
NC='\033[0m'
echo-red () { echo -e "${red}$1${NC}"; }
echo-green () { echo -e "${green}$1${NC}"; }
echo-green-bg () { echo -e "${green_bg}$1${NC}"; }
echo-yellow () { echo -e "${yellow}$1${NC}"; }
is_windows ()
{
local res=$(uname | grep 'CYGWIN_NT')
if [[ "$res" != "" ]]; then
return 0
else
return 1
fi
}
# Copy a settings file.
# Skips if the destination file already exists.
# @param $1 source file
# @param $2 destination file
copy_settings_file()
{
local source="$1"
local dest="$2"
if [[ ! -f $dest ]]; then
echo "Copying ${dest}..."
cp $source $dest
else
echo-yellow "${dest} already in place."
fi
}
#-------------------------- END: Helper functions --------------------------------
#-------------------------- Functions --------------------------------
# Initialize local settings files
init_settings ()
{
# Copy from settings templates
copy_settings_file "${SITEDIR_PATH}/default.settings.local.php" "${SITEDIR_PATH}/settings.local.php"
}
# Fix file/folder permissions
fix_permissions ()
{
echo-green "Making site directory writable..."
chmod 755 "${SITEDIR_PATH}"
}
# Install site
site_install ()
{
cd $DOCROOT_PATH
# We disable email sending here so site-install does not return an error
fin exec "PHP_OPTIONS="'"-d sendmail_path=`which true`"'" drush site-install -y --site-name='My Drupal 8 Site'"
}
#-------------------------- END: Functions --------------------------------
#-------------------------- Execution --------------------------------
if [[ "$PROJECT_ROOT" == "" ]]; then
echo-red "\$PROJECT_ROOT is not set"
exit 1
fi
# Project initialization steps
echo -e "${green_bg} Step 1 ${NC}${green} Initializing local project configuration...${NC}"
fix_permissions
init_settings
if [[ $DOCKER_RUNNING == "true" ]]; then
echo -e "${green_bg} Step 2 ${NC}${green} Recreating services...${NC}"
fin reset -f
else
echo -e "${green_bg} Step 2 ${NC}${green} Creating services...${NC}"
fin up
fi
echo "Waiting 10s for MySQL to initialize...";
sleep 10
echo -e "${green_bg} Step 3 ${NC}${green} Installing site...${NC}"
time site_install
if is_windows; then
echo-green "Add ${VIRTUAL_HOST} to your hosts file (/etc/hosts), e.g.:"
echo-green "192.168.64.100 ${VIRTUAL_HOST}"
echo
fi
echo -en "${green_bg} DONE! ${NC} "
echo -e "Open ${yellow}http://${VIRTUAL_HOST}${NC} in your browser to verify the setup."
#-------------------------- END: Execution --------------------------------