Skip to content

Commit

Permalink
Basic OSX version
Browse files Browse the repository at this point in the history
  • Loading branch information
dsdenes committed Jan 3, 2019
1 parent 9883d8b commit d49953e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 23 deletions.
3 changes: 3 additions & 0 deletions bin/wptunnel
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,15 @@ case "$1" in
assert_subdomain "$2"
SUBDOMAIN="$2"
PROJECT_DIR="$HOME/.wptunnel/projects/$2"
PROJECT_DATA_DIR="$HOME/wptunnel/projects/$2"
sh -c "mkdir -p $PROJECT_DIR"
sh -c "mkdir -p $PROJECT_DATA_DIR"
sh -c "cp -R $HOME/.wptunnel/docker/frp-docker $PROJECT_DIR"

PROJECT_DOCKER_COMPOSE="$PROJECT_DIR/docker-compose.yml"
sh -c "cp ~/.wptunnel/template/docker-compose.yml $PROJECT_DOCKER_COMPOSE"
sh -c "sed -i \"s/{SUBDOMAIN}/${SUBDOMAIN}/g\" $PROJECT_DOCKER_COMPOSE"
sh -c "sed -i \"s/{DATA_DIR}/${PROJECT_DATA_DIR}/g\" $PROJECT_DOCKER_COMPOSE"

PROJECT_FRPC_INI="$PROJECT_DIR/frp-docker/frpc.ini"
sh -c "sed -i \"s/{SUBDOMAIN}/${SUBDOMAIN}/g\" $PROJECT_FRPC_INI"
Expand Down
86 changes: 64 additions & 22 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,32 @@ echo -e "===================="
trap ctrl_c INT

ctrl_c() {
error "Failed to install."
errorInstall
}

error () {
echo -e "${RED}${1}${NOCOLOR}"
exit 1
}

errorInstall () {
error "Failed to install."
}

installViaPackageManager () {
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}"
elif [ -x "$(command -v brew)" ]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
ensureHomebrew
sh -c "brew install ${1}"
else
error "Cannot find package manager."
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
if [ $? -ne 0 ]; then errorInstall; fi
}

downloadExec () {
Expand All @@ -37,6 +45,7 @@ downloadExec () {
elif [ -x "$(command -v wget)" ]; then
sh -c "wget -qO- $1 | sh"
fi
if [ $? -ne 0 ]; then errorInstall; fi
}

downloadToSudo () {
Expand All @@ -45,6 +54,7 @@ downloadToSudo () {
elif [ -x "$(command -v wget)" ]; then
sudo sh -c "wget -qO- $1 > $2"
fi
if [ $? -ne 0 ]; then errorInstall; fi
}

downloadTo () {
Expand All @@ -53,6 +63,18 @@ downloadTo () {
elif [ -x "$(command -v wget)" ]; then
sh -c "wget -qO- $1 > $2"
fi
if [ $? -ne 0 ]; then errorInstall; 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)"
if [ $? -ne 0 ]; then errorInstall; fi
else
echo -e "${GREEN}OK${NOCOLOR}"
fi
}

ensureGit () {
Expand All @@ -69,9 +91,14 @@ ensureDocker () {
echo -n "Docker: "
if ! [ -x "$(command -v docker)" ]; then
echo -e "${YELLOW}NOT FOUND${NOCOLOR}"
echo -e "${YELLOW}We're going to need sudo access in order to install Docker.${NOCOLOR}"
sudo true
downloadExec https://get.docker.com/
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
Expand All @@ -81,12 +108,18 @@ ensureDockerCompose () {
echo -n "Docker Compose: "
if ! [ -x "$(command -v docker-compose)" ]; then
echo -e "${YELLOW}NOT FOUND${NOCOLOR}"
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"
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
if [ $? -ne 0 ]; then errorInstall; fi
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
Expand All @@ -97,15 +130,24 @@ ensureDocker
ensureDockerCompose

mkdir -p ~/.wptunnel
WPTUNNEL_VERSION=`git ls-remote https://github.com/dsdenes/wptunnel | grep refs/tags | grep -oP "[0-9]+\.[0-9]+\.[0-9]+$" | tail -n 1`
WPTUNNEL_VERSION=""
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 ~/.wptunnel
if [ $? -ne 0 ]; then errorInstall; fi
chmod +x ~/.wptunnel/bin/wptunnel
rm -rf /tmp/wptunnel.tar.gz

cp ~/.bashrc{,.bak}
sed -i /wptunnel/d ~/.bashrc
echo "export PATH=\$PATH:$HOME/.wptunnel/bin" >> ~/.bashrc
source ~/.bashrc
if [ -f ~/.bash_profile ]; then
cp ~/.bash_profile ~/.bash_profile_$(ls ~/.bash_profile*.bak | wc -l).bak
sed -i /wptunnel/d ~/.bash_profile
fi

echo "export PATH=\$PATH:$HOME/.wptunnel/bin" >> ~/.bash_profile
source ~/.bash_profile

echo -e "${GREEN}All done.${NOCOLOR}"
2 changes: 2 additions & 0 deletions template/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ services:
ports:
- "80:80"
restart: always
volumes:
- {DATA_DIR}:/var/www/html:rw
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.6
0.0.7

0 comments on commit d49953e

Please sign in to comment.