-
Notifications
You must be signed in to change notification settings - Fork 381
/
Copy pathincludes.sh
executable file
·128 lines (115 loc) · 2.82 KB
/
includes.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
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
127
128
#!/bin/bash
# Common variables.
DOCKER_COMPOSE_FILE_OPTIONS="-f $(dirname "$0")/docker-compose.yml"
# These are the containers and values for the development site.
CLI='cli'
CONTAINER='wordpress'
DATABASE='mysql'
SITE_TITLE='AMP Dev'
##
# Download from a remote source.
#
# Checks for the existence of curl and wget, then downloads the remote file using the first available option.
#
# @param {string} remote The remote file to download.
# @param {string} [local] Optional. The local filename to use. If it isn't passed, STDOUT is used.
#
# @return {bool} Whether the download succeeded or not.
##
download() {
if command_exists "curl"; then
curl -s -o "${2:--}" "$1"
elif command_exists "wget"; then
wget -nv -O "${2:--}" "$1"
fi
}
##
# Add error message formatting to a string, and echo it.
#
# @param {string} message The string to add formatting to.
##
error_message() {
echo -en "\033[31mERROR\033[0m: $1"
}
##
# Add warning message formatting to a string, and echo it.
#
# @param {string} message The string to add formatting to.
##
warning_message() {
echo -en "\033[33mWARNING\033[0m: $1"
}
##
# Add status message formatting to a string, and echo it.
#
# @param {string} message The string to add formatting to.
##
status_message() {
echo -en "\033[32mSTATUS\033[0m: $1"
}
##
# Add formatting to an action string.
#
# @param {string} message The string to add formatting to.
##
action_format() {
echo -en "\033[32m$1\033[0m"
}
##
# Check if the command exists as some sort of executable.
#
# The executable form of the command could be an alias, function, builtin, executable file or shell keyword.
#
# @param {string} command The command to check.
#
# @return {bool} Whether the command exists or not.
##
command_exists() {
type -t "$1" >/dev/null 2>&1
}
##
# Docker Compose helper
#
# Calls docker-compose with common options.
##
dc() {
docker compose $DOCKER_COMPOSE_FILE_OPTIONS "$@"
}
##
# WP CLI
#
# Executes a WP CLI request in the CLI container.
##
wp() {
dc exec -T -u www-data $CONTAINER wp "$@"
}
##
# MySQL CLI.
#
# Executes the given MySQL client command in the database container.
##
mysql() {
dc exec -T -e MYSQL_PWD=example $DATABASE mysql "$@"
}
##
# WordPress Container helper.
#
# Executes the given command in the wordpress container.
##
container() {
dc exec -T $CONTAINER "$@"
}
##
# Download specific version of Gutenberg plugin.
#
# @param {string} version The version of Gutenberg to download.
##
download_gutenberg() {
local version="$1"
# by default save as gutenberg.$version.zip
local download_path="${2:-gutenberg.${version}.zip}"
local url="https://downloads.wordpress.org/plugin/gutenberg.${version}.zip"
echo -e $(status_message "Downloading Gutenberg ${version} from ${url}...")
download "$url" "$download_path"
echo -e $(status_message "Downloaded Gutenberg ${version} to ${download_path}")
}