|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
| 3 | +# |
| 4 | +# Reads the config file /vagrant/.wplib.box.json and returns a value |
| 5 | +# |
| 6 | +# $1 - String |
| 7 | +# $2 - String Optional if "require" then error if not there. |
| 8 | +# |
| 9 | +# Usage: git_url=$(read_config ".path.test.git_url") |
| 10 | +# Result: $git_url ==> "ssh://..." |
| 11 | +# |
| 12 | +# |
| 13 | +function read_config() { |
| 14 | + require="$2" |
| 15 | + property=$(cat "${WPLIB_BOX_CONFIG_FILE}" | jq --raw-output "$1") |
| 16 | + if [ "null" == "${property}" ]; then |
| 17 | + if [ "require" == "${require}" ]; then |
| 18 | + echo -e "\tERROR:" |
| 19 | + echo -e "\tThe config file ${WPLIB_BOX_CONFIG_FILE} does" |
| 20 | + echo -e "\tnot have a value for ${property}." |
| 21 | + return 1 |
| 22 | + fi |
| 23 | + else |
| 24 | + echo "${property}"; |
| 25 | + fi |
| 26 | +} |
| 27 | + |
3 | 28 | # |
4 | 29 | # Outputs the file extension given a file name |
5 | 30 | # |
@@ -173,6 +198,18 @@ function exit_if_no_force_option() { |
173 | 198 | fi |
174 | 199 | } |
175 | 200 |
|
| 201 | +function find_composer_vendor_dir() { |
| 202 | + if [ -d "${WPLIB_BOX_WEB_ROOT_DIR}/vendor" ]; then |
| 203 | + echo "${WPLIB_BOX_WEB_ROOT_DIR}/vendor" |
| 204 | + return |
| 205 | + fi |
| 206 | + |
| 207 | + if [ -d "${WPLIB_BOX_DIR}/vendor" ]; then |
| 208 | + echo "${WPLIB_BOX_DIR}/vendor" |
| 209 | + return |
| 210 | + fi |
| 211 | +} |
| 212 | + |
176 | 213 | function find_wp_content_dir() { |
177 | 214 | if [ -d "${WPLIB_BOX_WEB_ROOT_DIR}/content" ]; then |
178 | 215 | echo "${WPLIB_BOX_WEB_ROOT_DIR}/content" |
@@ -216,3 +253,58 @@ function how_to_install_wp() { |
216 | 253 | echo |
217 | 254 | } |
218 | 255 |
|
| 256 | +function delete_exclude_items() { |
| 257 | + root_dir="$1" |
| 258 | + index=0 |
| 259 | + while :; do |
| 260 | + item_to_exclude=$(read_config ".deployment.exclude[${index}]") |
| 261 | + if [ "" == "${item_to_exclude}" ]; then |
| 262 | + break |
| 263 | + fi |
| 264 | + item_to_exclude="${root_dir}/${item_to_exclude}" |
| 265 | + if [[ ! -f "${item_to_exclude}" && ! -d "${item_to_exclude}" ]];then |
| 266 | + echo "NOTICE: ${item_to_exclude} is in exclude list in ${WPLIB_BOX_CONFIG_FILE} but does not exist on disk." |
| 267 | + else |
| 268 | + basename=$(basename "${item_to_exclude}") |
| 269 | + echo_if_not_quiet "$*", "=Deleting ${basename}..." |
| 270 | + rm -rf "${item_to_exclude}" |
| 271 | + fi |
| 272 | + index=$(( $index+1 )) |
| 273 | + done |
| 274 | + |
| 275 | +} |
| 276 | + |
| 277 | +# |
| 278 | +# Echos the substring after a character |
| 279 | +# |
| 280 | +# $1 - String |
| 281 | +# $2 - Character |
| 282 | +# |
| 283 | +# Usage: vendor_dir=$(substring_after "www/vendor" "/") |
| 284 | +# Result: $vendor_dir ==> "vendor" |
| 285 | +# |
| 286 | +# |
| 287 | +function substring_after() { |
| 288 | + string="$1" |
| 289 | + character="$2" |
| 290 | + echo "${string#*${character}}" |
| 291 | +} |
| 292 | + |
| 293 | +# |
| 294 | +# Runs Git commands, quietly, unless they fail |
| 295 | +# |
| 296 | +# See http://stackoverflow.com/a/8944284/102699 |
| 297 | +# |
| 298 | +function quiet_git() { |
| 299 | + stdout=$(tempfile) |
| 300 | + stderr=$(tempfile) |
| 301 | + |
| 302 | + if ! git "$@" </dev/null >$stdout 2>$stderr; then |
| 303 | + cat $stderr >&2 |
| 304 | + rm -f $stdout $stderr |
| 305 | + return 1 |
| 306 | + fi |
| 307 | + |
| 308 | + rm -f $stdout $stderr |
| 309 | +} |
| 310 | + |
0 commit comments