rebuild.sh 5.52 KB
Newer Older
1
#!/bin/bash
2
3
4
5
6
phpversion="$(php --version | head -n 1 | cut -d ' ' -f 2 | cut -c 1,3)"
if (( phpversion < 70 ));  then
  echo 'PHP is too old to continue. If in Vagrant, run "defaultphp71" to change versions.'
  exit 1
fi
7

8
9
10
for i in "$@"
do
case $i in
11
12
13
14
  1|2|3 )
    build_option="${i#*=}"
    shift # past argument=value
    ;;
Eric Bremner's avatar
Eric Bremner committed
15
  -h|--help)
16
17
18
    use_help="1"
    shift
    ;;
Eric Bremner's avatar
Eric Bremner committed
19
  --build-option=*)
20
21
22
    build_option="${i#*=}"
    shift # past argument=value
    ;;
23
24
25
26
  --build-type=*)
    build_type="${i#*=}"
    shift # past argument=value
    ;;
Eric Bremner's avatar
Eric Bremner committed
27
  --gesso-branch-tag=*)
28
29
30
    gesso_branch_tag="${i#*=}"
    shift # past argument=value
    ;;
Eric Bremner's avatar
Eric Bremner committed
31
32
33
34
35
36
37
38
  --gesso-root-dir=*)
    gesso_root_dir="${i#*=}"
    shift # past argument=value
    ;;
  --drupal-root-dir=*)
    drupal_root_dir="${i#*=}"
    shift # past argument=value
    ;;
Eric Bremner's avatar
Eric Bremner committed
39
40
  *)
    # unknown option
41
42
43
    ;;
esac
done
44

45
46
47
if [[ ! -z $use_help ]]; then
  printf "./rebuild.sh will accept the following switches:\n"
  printf "\n --build-option [#] (required)"
48
  printf "\n 1 = rebuild profile only (non-development)"
49
50
  printf "\n 2 = rebuild profile and gesso (for development)"
  printf "\n 3 = rebuild gesso only (for development)"
51
  printf "\n 4 = update gesso in theme (non-development)"
52
  printf "\n"
53
54
55
56
  printf "\n --build-type [#] (defaulted)"
  printf "\n Provide a build before the script runs."
  printf "\n If none given as a parameter, defaulted to vagrant, no options are given."
  printf "\n"
57
58
59
60
  printf "\n --gesso-branch-tag [branch/tag] (optional)"
  printf "\n Provide a Git branch or tag name for uw_wcms_gesso."
  printf "\n Defaults to 8.x-3.x branch."
  printf "\n"
61
62
  printf "\n --gesso-root-dir [directory] (optional)"
  printf "\n Provide the directory where gesso is to be installed."
63
  printf "\n Defaults to /var/www/html unless build-type is lando in which case it defaults to /app."
64
65
66
67
68
  printf "\n"
  printf "\n --drupal-root-dir [directory] (optional)"
  printf "\n Provide the directory where Drupal is installed."
  printf "\n Defaults to /var/www/drupal8."
  printf "\n"
69
  printf "\n Example usage:"
70
  printf "\n ./rebuild.sh --build-option=2 --gesso-branch-tag=8.x-3.x --gesso-root-dir=/var/www/html --drupal-root-dir=/var/www/drupal8"
71
72
73
74
75
  printf "\n"
  printf "\n If there are no switches used then interactivity will being asking questions to get inputs but also allowing for the defaults."
  printf "\n"
  exit 1
fi
76

77
if [[ -z $build_option ]] && [[ -z $drupal_root_dir ]] && [[ -z $gesso_branch_tag ]] && [[ -z $gesso_root_dir ]]; then
Eric Bremner's avatar
Eric Bremner committed
78
  interactivity=1
79
elif [ ${build_option} = null ] && [[ ${drupal_root_dir} = null ]] && [ ${gesso_branch_tag} = null ]; then
Eric Bremner's avatar
Eric Bremner committed
80
  interactivity=1
81
else
Eric Bremner's avatar
Eric Bremner committed
82
  interactivity=0
83
fi
84

85
if [ ${interactivity} == 1 ]; then
86
87
88
89
90
91
92
93
94
95
96
97
  # Set up defaults.
  script_path=`pwd`
  gesso_root_default='/var/www/html'
  if [[ "$script_path" == *"app"* ]]; then
    drupal_root_default='/app'
    gesso_root_default='/app'
  elif [[ "$script_path" == *"alt"* ]]; then
    drupal_root_default='/var/www/drupal8alt'
  else
    drupal_root_default='/var/www/drupal8'
  fi
  # Ask install questions.
Eric Bremner's avatar
Eric Bremner committed
98
  echo "What would you like to do?"
99
  echo "1 = Rebuild profile (non-development)."
Eric Bremner's avatar
Eric Bremner committed
100
101
  echo "2 = Rebuild profile and gesso (for development)."
  echo "3 = Rebuild gesso (for development)."
102
  echo "4 = Update gesso in theme (non-development)."
Eric Bremner's avatar
Eric Bremner committed
103
104
  echo "[x] Exit and do nothing"

105
  while ! [[ "$build_option" =~ ^(1|2|3|4|x)$ ]]
Eric Bremner's avatar
Eric Bremner committed
106
107
108
109
110
111
  do
    printf "\nBuild option [1]: "
    read -r build_option

    if [[ -z $build_option ]]; then
      build_option=1
112
    fi
Eric Bremner's avatar
Eric Bremner committed
113
  done
114

115
  if [ ${build_option} == "x" ]; then
Eric Bremner's avatar
Eric Bremner committed
116
117
118
    exit 1;
  fi

119
  if [[ -z $build_type ]]; then
120
    build_type='vagrant'
121
122
  fi

123
  printf "\nDrupal root directory: [$drupal_root_default]: "
124
  read -r drupal_root_dir
Eric Bremner's avatar
Eric Bremner committed
125

126
127
128
  printf "\nGesso branch/tag: [8.x-3.x]: "
  read -r gesso_branch_tag

129
  if [ ${build_option} == "2" ] || [ ${build_option} == "3" ]; then
130
    printf "\nGesso root directory: [$gesso_root_default]: "
Eric Bremner's avatar
Eric Bremner committed
131
132
133
    read -r gesso_root_dir
  fi

134
135
136
137
138
139
140
141
142
143
144
fi

if [[ -z $build_option ]]; then
  printf "You must specify a build option, it is a required switch.\n"
  exit 1;
fi

if [[ -z $gesso_branch_tag ]]; then
  gesso_branch_tag=8.x-3.x
fi

Eric Bremner's avatar
Eric Bremner committed
145
if [[ -z $drupal_root_dir ]]; then
146
  drupal_root_dir="$drupal_root_default"
Eric Bremner's avatar
Eric Bremner committed
147
148
149
fi

if [[ -z $gesso_root_dir ]]; then
150
  gesso_root_dir="$gesso_root_default"
Eric Bremner's avatar
Eric Bremner committed
151
152
fi

153
if [ ${build_option} == "1" ]; then
Eric Bremner's avatar
Eric Bremner committed
154
155
156
157
158
  printf "Using gesso profile branch/tag: $gesso_branch_tag\n"
else
  printf "Using gesso profile branch/tag: $gesso_branch_tag in directory $gesso_root_dir.\n"
  printf "Building in Drupal root directory: $drupal_root_dir.\n"
fi
159
160

case $build_option in
161
  1 )
162
    echo ""
163
    echo "You have chosen to rebuild the profile (non-development).";
164
    echo ""
165

166
167
168
    if [[ $? -ne 0 ]] ; then
      exit 1
    else
169
      sh ./scripts/rebuild_profile.sh $build_option $drupal_root_dir $gesso_tag_branch
170
171
172
    fi
    ;;
  2 )
Eric Bremner's avatar
Eric Bremner committed
173
    echo ""
174
    echo "You have chosen to rebuild the profile and gesso (for development).";
Eric Bremner's avatar
Eric Bremner committed
175
176
177
178
179
    echo ""

    if [[ $? -ne 0 ]] ; then
      exit 1
    else
180
      sh ./scripts/rebuild_profile.sh $build_option $drupal_root_dir $gesso_branch_tag $gesso_root_dir
Eric Bremner's avatar
Eric Bremner committed
181
182
183
    fi
    ;;
  3 )
184
    echo ""
185
    echo "You have chosen to rebuild gesso only (for development)."
186
    echo ""
187

188
189
190
    if [[ $? -ne 0 ]] ; then
      exit 1
    else
191
      sh ./scripts/build_gesso_devel.sh $drupal_root_dir $gesso_branch_tag $gesso_root_dir
192
193
    fi
    ;;
194
195
196
197
198
199
200
201
202
203
204
  4 )
    echo ""
    echo "You have chosen to update gesso in theme (non-development).";
    echo ""

    if [[ $? -ne 0 ]] ; then
      exit 1
    else
      sh ./scripts/get_gesso_files.sh $drupal_root_dir $gesso_tag_branch
    fi
    ;;
Liam Morland's avatar
Liam Morland committed
205
esac
206
207

echo "Done all tasks."