Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing GUI Not Working When There is Perviously runned instance #202

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions onix-gui/start.sh
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
#!/bin/bash

# Installing dependencies

sudo apt-get update
sudo apt-get install ca-certificates curl

sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Function to kill previous processes if they are running
kill_previous_processes() {
echo "Checking for running processes on port $PORT..."
lsof -i :$PORT | grep LISTEN | awk '{print $2}' | xargs -r kill -9
echo "Checking for running tunnel services..."
pkill -f "lt --port $PORT"
}

# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Installing dependencies

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Execute the package_manager.sh script to handle Docker installation
source "../install/scripts/package_manager.sh"

sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# Run the package_manager.sh script without passing any arguments
# The script will handle the installation of required packages
# including Docker and Docker Compose as defined within it.
# No need to call install_package function explicitly.

echo "installing node"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash &&
source ~/.bashrc &&
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
source ~/.bashrc &&
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install 20 &&
npm i -g localtunnel &&
npm i -g localtunnel &&

# Add user to the docker group and apply permissions
sudo groupadd docker &
sudo usermod -aG docker $USER &
# Add user to the docker group and apply permissions
sudo groupadd docker &
sudo usermod -aG docker $USER &
newgrp docker &

# Set script variables
PROJECT_DIR="GUI"
PORT=3005
TUNNEL_SERVICE="lt"

# Kill previous processes if they are running
kill_previous_processes

# Change to the project directory
cd "$PROJECT_DIR" || exit
nvm use 20 &&
npm i &&
npm i &&

# Build and start the Next.js app
echo "installing Dependencies"
# Build and start the Next.js app
echo "installing Dependencies"
echo "Building and starting Next.js app..."
npx next build &&
echo "Builing Web App = True"
echo "Builing Web App = True"
sleep 3
npx next start -p "$PORT" &

Expand All @@ -58,7 +58,7 @@ npx next start -p "$PORT" &
# Install the tunnel service if not installed
sleep 3
echo "Exposing local port $PORT using $TUNNEL_SERVICE..."
lt --port "$PORT" > /tmp/lt.log 2>&1 &
lt --port "$PORT" >/tmp/lt.log 2>&1 &

# Wait for the tunnel service to start
echo "Waiting for tunnel service to start..."
Expand All @@ -71,8 +71,8 @@ TUNNEL_URL=$(grep -o 'https://[^[:blank:]]*' /tmp/lt.log)
echo "Getting Tunnel Password"
TUNNEL_PASSWORD=$(curl https://loca.lt/mytunnelpassword) &&

# Print the tunnel URL and password
echo "---------------------------------------"
# Print the tunnel URL and password
echo "---------------------------------------"
echo "Next.js app is running locally on port $PORT"
echo "Tunnel Service URL: $TUNNEL_URL"
echo "Tunnel Password: $TUNNEL_PASSWORD"
Expand Down