Skip to content

Commit

Permalink
fix: add network in linux installation script (#1566)
Browse files Browse the repository at this point in the history
* fix: add netwoek in linux

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: add network in docker]

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: add sudo for mac

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: add darwin

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: remove && condition

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

---------

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>
  • Loading branch information
charankamarapu committed Feb 22, 2024
1 parent 2484073 commit c24d16e
Showing 1 changed file with 55 additions and 14 deletions.
69 changes: 55 additions & 14 deletions keploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ installKeploy (){
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin/keploybin

set_alias 'sudo -E env PATH="$PATH" keploybin'

check_docker_status_for_linux
dockerStatus=$?
if [ "$dockerStatus" -eq 0 ]; then
return
fi
add_network
}

check_sudo(){
Expand All @@ -36,6 +43,13 @@ installKeploy (){
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin/keploybin

set_alias 'sudo -E env PATH="$PATH" keploybin'

check_docker_status_for_linux
dockerStatus=$?
if [ "$dockerStatus" -eq 0 ]; then
return
fi
add_network
}

append_to_rc() {
Expand Down Expand Up @@ -96,21 +110,59 @@ installKeploy (){
fi
}

check_docker_status_for_linux() {
check_sudo
sudoCheck=$?
network_alias=""
if [ "$sudoCheck" -eq 0 ]; then
# Add sudo to docker
network_alias="sudo"
fi
if ! $network_alias which docker &> /dev/null; then
echo -n "Docker not found on device, please install docker and reinstall keploy if you have applications running on docker"
return 0
fi
if ! $network_alias docker info &> /dev/null; then
echo "Please start Docker and reinstall keploy if you have applications running on docker"
return 0
fi
return 1
}


install_docker() {
check_docker_status_for_Darwin() {
check_sudo
sudoCheck=$?
network_alias=""
if [ "$sudoCheck" -eq 0 ] && [ $OS_NAME = "Linux" ]; then
if [ "$sudoCheck" -eq 0 ]; then
# Add sudo to docker
network_alias="sudo"
fi
if ! $network_alias which docker &> /dev/null; then
echo -n "Docker not found on device, please install docker to use Keploy"
return 0
fi
# Check if docker is running
if ! $network_alias docker info &> /dev/null; then
echo "Keploy only supports intercepting and replaying docker containers on macOS, and requires Docker to be installed and running. Please start Docker and try again."
return 0
fi
return 1
}

add_network() {
if ! $network_alias docker network ls | grep -q 'keploy-network'; then
$network_alias docker network create keploy-network
fi
}

install_docker() {
if [ "$OS_NAME" = "Darwin" ]; then
check_docker_status_for_Darwin
dockerStatus=$?
if [ "$dockerStatus" -eq 0 ]; then
return
fi
add_network
if ! docker volume inspect debugfs &>/dev/null; then
docker volume create --driver local --opt type=debugfs --opt device=debugfs debugfs
fi
Expand All @@ -126,19 +178,8 @@ installKeploy (){
if [ "$IS_CI" = false ]; then
OS_NAME="$(uname -s)"
if [ "$OS_NAME" = "Darwin" ]; then
if ! which docker &> /dev/null; then
echo -n "Docker not found on device, please install docker to use Keploy"
return
fi

# Check if docker is running
if ! docker info &> /dev/null; then
echo "Keploy only supports intercepting and replaying docker containers on macOS, and requires Docker to be installed and running. Please start Docker and try again."
return
fi
install_docker
return

elif [ "$OS_NAME" = "Linux" ]; then
if ! sudo mountpoint -q /sys/kernel/debug; then
sudo mount -t debugfs debugfs /sys/kernel/debug
Expand Down

0 comments on commit c24d16e

Please sign in to comment.