-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·183 lines (159 loc) · 5.03 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·183 lines (159 loc) · 5.03 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env bash
set -e
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
RED='\033[1;31m'
NOCOLOR='\033[0m'
echo -e "===================="
echo -e "| Install WPTunnel |"
echo -e "===================="
trap ctrl_c INT
ctrl_c() {
errorInstall
}
trap "handle_exit_code" EXIT
handle_exit_code() {
ERROR_CODE="$?";
if ! [ ${ERROR_CODE} -eq "0" ]; then
echo -e "${RED}Failed to install.${NOCOLOR}"
fi
exit $?;
}
error () {
echo -e "${RED}${1}${NOCOLOR}"
exit 1
}
errorInstall () {
error "Failed to install."
}
installViaPackageManager () {
if [[ "$OSTYPE" == "darwin"* ]]; then
ensureHomebrew
sh -c "brew install ${1}"
elif [[ "$OSTYPE" == "linux-gnu" ]]; then
if [ -x "$(command -v apt-get)" ]; then
sh -c "sudo apt-get install ${1}"
elif [ -x "$(command -v yum)" ]; then
sh -c "sudo yum install ${1}"
else
error "Cannot find package manager."
fi
fi
}
downloadExec () {
if [ -x "$(command -v curl)" ]; then
sh -c "curl -sL $1 | sh"
elif [ -x "$(command -v wget)" ]; then
sh -c "wget -qO- $1 | sh"
fi
}
downloadToSudo () {
if [ -x "$(command -v curl)" ]; then
sudo sh -c "curl -sL $1 > $2"
elif [ -x "$(command -v wget)" ]; then
sudo sh -c "wget -qO- $1 > $2"
fi
}
downloadTo () {
if [ -x "$(command -v curl)" ]; then
sh -c "curl -sL $1 > $2"
elif [ -x "$(command -v wget)" ]; then
sh -c "wget -qO- $1 > $2"
fi
}
ensureHomebrew () {
echo -n "Homebrew: "
if ! [ -x "$(command -v brew)" ]; then
echo -e "${YELLOW}NOT FOUND${NOCOLOR}"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
echo -e "${GREEN}OK${NOCOLOR}"
fi
}
ensureGit () {
echo -n "Git: "
if ! [ -x "$(command -v git)" ]; then
echo -e "${YELLOW}NOT FOUND${NOCOLOR}"
installViaPackageManager git
else
echo -e "${GREEN}OK${NOCOLOR}"
fi
}
ensureDocker () {
echo -n "Docker: "
if ! [ -x "$(command -v docker)" ]; then
echo -e "${YELLOW}NOT FOUND${NOCOLOR}"
if [[ "$OSTYPE" == "darwin"* ]]; then
echo -e "${YELLOW}Docker can't automatically be installed on Mac. Please install it manually: https://docs.docker.com/docker-for-mac/install/${NOCOLOR}"
errorInstall
else
echo -e "${YELLOW}We're going to need sudo access in order to install Docker.${NOCOLOR}"
sudo true
downloadExec https://get.docker.com/
fi
else
echo -e "${GREEN}OK${NOCOLOR}"
fi
}
ensureDockerCompose () {
echo -n "Docker Compose: "
if ! [ -x "$(command -v docker-compose)" ]; then
echo -e "${YELLOW}NOT FOUND${NOCOLOR}"
if [[ "$OSTYPE" == "darwin"* ]]; then
echo -e "${YELLOW}Docker Compose can't automatically be installed on Mac. Please install it manually: https://docs.docker.com/docker-for-mac/install/${NOCOLOR}"
errorInstall
else
echo -e "${YELLOW}We're going to need sudo access in order to install Docker Compose.${NOCOLOR}"
sudo true
COMPOSE_VERSION=`git ls-remote https://github.com/docker/compose | grep refs/tags | grep -oP "[0-9]+\.[0-9][0-9]+\.[0-9]+$" | tail -n 1`
downloadToSudo "https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m`" "/usr/local/bin/docker-compose"
sudo chmod +x /usr/local/bin/docker-compose
downloadToSudo "https://raw.githubusercontent.com/docker/compose/${COMPOSE_VERSION}/contrib/completion/bash/docker-compose" "/etc/bash_completion.d/docker-compose"
fi
else
echo -e "${GREEN}OK${NOCOLOR}"
fi
}
ensureGit
ensureDocker
ensureDockerCompose
mkdir -p ~/.wptunnel
WPTUNNEL_VERSION=""
INSTALL_DIR="$HOME/.wptunnel"
if [[ "$OSTYPE" == "darwin"* ]]; then
WPTUNNEL_VERSION=`git ls-remote https://github.com/dsdenes/wptunnel | grep refs/tags | grep -oE "[0-9]+\.[0-9]+\.[0-9]+$" | tail -n 1`
else
WPTUNNEL_VERSION=`git ls-remote https://github.com/dsdenes/wptunnel | grep refs/tags | grep -oP "[0-9]+\.[0-9]+\.[0-9]+$" | tail -n 1`
fi
downloadTo "https://github.com/dsdenes/wptunnel/archive/${WPTUNNEL_VERSION}.tar.gz" "/tmp/wptunnel.tar.gz"
tar -xzf /tmp/wptunnel.tar.gz --strip 1 -C $INSTALL_DIR
chmod +x ~/.wptunnel/bin/wptunnel
rm -rf /tmp/wptunnel.tar.gz
if [ -d "$HOME/bin" ]; then
if [ -f "$HOME/bin/wptunnel" ]; then
rm ~/bin/wptunnel 2> /dev/null
fi
ln -s $INSTALL_DIR/bin/wptunnel ~/bin
fi
if [ -d "$HOME/.local" ]; then
mkdir -p $HOME/.local/bin
if [ -f "$HOME/.local/bin/wptunnel" ]; then
rm ~/.local/bin/wptunnel 2> /dev/null
fi
ln -s $INSTALL_DIR/bin/wptunnel ~/.local/bin
fi
if [ -f ~/.bashrc ]; then
cp ~/.bashrc ~/.bashrc_$(ls ~/.bashrc*.bak 2>/dev/null | wc -l).bak
sed -i /wptunnel/d ~/.bashrc
fi
echo "PATH=\"\$HOME/.wptunnel/bin:\$PATH\"" >> ~/.bashrc
if ! [ -x "$(command -v docker)" ]; then
echo -e "\nCongratulations, you are good to go now."
echo -e "Open a new terminal, and create your first project by running:\n"
else
echo -e "\nCongratulations, you are good to go now. You can create your first project by running:\n"
fi
echo -e " $ wptunnel create mysite\n"
echo -e "Change 'mysite' with your project name."
printf -- '\n'
exit 0