Files
ghostnet-openclaw/ghostnet.sh
T

67 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# Path to the .env file
ENV_FILE="./.env"
# 1. Determine GPU_TYPE: Shell-Env first, then .env file
if [ -z "$GPU_TYPE" ]; then
if [ -f "$ENV_FILE" ]; then
GPU_TYPE=$(grep '^GPU_TYPE=' "$ENV_FILE" | cut -d '=' -f2)
fi
fi
# 2. Validation: Is the variable now set?
if [ -z "$GPU_TYPE" ]; then
echo "ERROR: 'GPU_TYPE' is not defined!"
echo "💡 Please set it in your shell (export GPU_TYPE=amd) or create an .env file."
exit 1
fi
# 3. Validation: Is the value allowed?
case "$GPU_TYPE" in
amd|intel|nvidia)
COMPOSE_FILE="compose.$GPU_TYPE.yaml"
;;
*)
echo "ERROR: Invalid GPU_TYPE '$GPU_TYPE'!"
echo "Allowed values are: amd, intel, nvidia"
exit 1
esac
# 4. Check if YAML file exists
if [ ! -f "$COMPOSE_FILE" ]; then
echo "ERROR: The file '$COMPOSE_FILE' was not found!"
exit 1
fi
# 5. Execute the command based on user input
COMMAND=$1
case "$COMMAND" in
up)
echo "🚀 Starting Ghostnet ($GPU_TYPE)..."
podman-compose -f "$COMPOSE_FILE" up -d
;;
down)
echo "🛑 Stopping Ghostnet ($GPU_TYPE)..."
podman-compose -f "$COMPOSE_FILE" down
;;
restart)
echo "🔄 Restarting Ghostnet ($GPU_TYPE)..."
podman-compose -f "$COMPOSE_FILE" restart
;;
logs)
podman-compose -f "$COMPOSE_FILE" logs -f
;;
attached)
echo "🔍 Checking for running instances..."
podman-compose -f "$COMPOSE_FILE" down > /dev/null 2>&1
echo "🔍 Starting Ghostnet in foreground ($GPU_TYPE)..."
podman-compose -f "$COMPOSE_FILE" up
;;
*)
echo "Usage: ./ghostnet.sh [up|down|restart|logs|attached]"
echo "Current environment: $GPU_TYPE"
exit 1
;;
esac