-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathserver.sh
executable file
·127 lines (110 loc) · 3.56 KB
/
server.sh
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
#!/bin/bash
# Define colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RESET='\033[0m'
# Determine script location to find application root
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
APP_ROOT="$SCRIPT_DIR"
CONFIG_DIR="$APP_ROOT/config"
# Default values
PORT="8080" # Default port
DEBUG_MODE=false
# Miniconda installation path
MINICONDA_DIR=~/miniconda3
# Source configuration if available
if [ -f "$CONFIG_DIR/config.env" ]; then
source "$CONFIG_DIR/config.env"
# Apply values from config.env if available
if [ -n "$RKLLAMA_SERVER_PORT" ]; then
PORT="$RKLLAMA_SERVER_PORT"
fi
if [ "$RKLLAMA_SERVER_DEBUG" = "true" ]; then
DEBUG_MODE=true
fi
fi
# Parse command line arguments (override config)
USE_CONDA=true
for arg in "$@"; do
if [[ "$arg" == "--no-conda" ]]; then
USE_CONDA=false
elif [[ "$arg" == "--debug" ]]; then
DEBUG_MODE=true
elif [[ "$arg" == --port=* ]]; then
PORT="${arg#*=}"
# Validate that port is not empty
if [[ -z "$PORT" ]]; then
echo -e "${YELLOW}Warning: Empty port specified, using default port 8080${RESET}"
PORT="8080"
fi
fi
done
# Update the configuration
CONFIG_ARGS=()
if [ -n "$PORT" ]; then
CONFIG_ARGS+=("--port" "$PORT")
fi
if $DEBUG_MODE; then
CONFIG_ARGS+=("--debug")
fi
# If Miniconda is enabled, check if it exists and activate it
if $USE_CONDA; then
if [ -d "$MINICONDA_DIR" ]; then
echo -e "${GREEN}Starting the environment with Miniconda3.${RESET}"
source "$MINICONDA_DIR/bin/activate" ""
else
echo -e "${YELLOW}Launching the installation file...${RESET}"
# Download and install Miniconda
bash "$APP_ROOT/setup.sh"
fi
else
echo -e "${YELLOW}Miniconda is disabled. Running without it.${RESET}"
fi
# Function to prompt for processor selection
select_processor() {
echo -e "${YELLOW}Processor type not detected automatically.${RESET}"
echo "Please select your processor type:"
echo "1) rk3588"
echo "2) rk3576"
while true; do
read -p "Enter selection (1-2): " selection
case $selection in
1) PROCESSOR="rk3588"; break;;
2) PROCESSOR="rk3576"; break;;
*) echo "Invalid selection. Please try again.";;
esac
done
echo -e "${GREEN}Selected processor: $PROCESSOR${RESET}"
}
# First check if PROCESSOR or CPU_MODEL is set in the environment
if [ -z "$PROCESSOR" ]; then
if [ -n "$CPU_MODEL" ]; then
# Use CPU_MODEL if available for backward compatibility
PROCESSOR="$CPU_MODEL"
elif [ -n "$RKLLAMA_PLATFORM_PROCESSOR" ]; then
# Use platform.processor setting from config
PROCESSOR="$RKLLAMA_PLATFORM_PROCESSOR"
else
# Try to extract the processor type from cpuinfo if not defined
PROCESSOR=$(grep -i "cpu model" /proc/cpuinfo | head -n 1 | sed 's/.*Rockchip \(RK[0-9]*\).*/\1/' | tr '[:upper:]' '[:lower:]')
fi
echo "Processor: $PROCESSOR"
fi
# If still not detected, prompt for selection (only in interactive mode)
if [ -z "$PROCESSOR" ]; then
# Check if we're running in a container (non-interactive)
if [ -f "/.dockerenv" ]; then
echo -e "${YELLOW}Running in Docker without processor specified. Defaulting to rk3588.${RESET}"
PROCESSOR="rk3588"
else
select_processor
fi
fi
# Build full command with all arguments
COMMAND=("python3" "$APP_ROOT/server.py" "--processor" "$PROCESSOR" "--port" "$PORT")
# Add debug flag if enabled
if $DEBUG_MODE; then
COMMAND+=("--debug")
fi
# Execute the Python script
"${COMMAND[@]}"