-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
66 lines (55 loc) 路 2.42 KB
/
Copy pathentrypoint.sh
File metadata and controls
66 lines (55 loc) 路 2.42 KB
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
#!/bin/bash
# Create the mounted directories if they don't exist
mkdir -p /app/bot-volume
mkdir -p /app/data
# Function to check if a directory is empty or doesn't exist
is_directory_empty_or_missing() {
local dir="$1"
if [ ! -d "$dir" ]; then
return 0 # Directory doesn't exist
elif [ -z "$(ls -A "$dir" 2>/dev/null)" ]; then
return 0 # Directory is empty
else
return 1 # Directory exists and has content
fi
}
# Check if both bot and data directories are empty or don't exist
if is_directory_empty_or_missing "/app/bot-volume" && is_directory_empty_or_missing "/app/data"; then
echo "Both bot and data directories are empty or don't exist. Copying default files..."
# Copy default bot files
echo "Copying default bot.py to volume..."
cp /app/bot-default/bot.py /app/bot-volume/
echo "Copying default requirements.txt to volume..."
cp /app/bot-default/requirements.txt /app/bot-volume/
echo "Copying default example_commands.py to volume..."
cp /app/bot-default/example_commands.py /app/bot-volume/
# Copy logging directory
if [ -d "/app/bot-default/bot_logging" ]; then
echo "Copying default bot_logging directory to volume..."
cp -r /app/bot-default/bot_logging /app/bot-volume/
fi
# Copy any other .py files from default
for file in /app/bot-default/*.py; do
filename=$(basename "$file")
if [ ! -f "/app/bot-volume/$filename" ]; then
echo "Copying default $filename to volume..."
cp "$file" "/app/bot-volume/"
fi
done
echo "Default files copied successfully."
else
echo "Bot or data directory already contains files. Skipping default file copy."
echo "Bot directory status: $([ -d "/app/bot-volume" ] && [ -n "$(ls -A /app/bot-volume 2>/dev/null)" ] && echo "has files" || echo "empty/missing")"
echo "Data directory status: $([ -d "/app/data" ] && [ -n "$(ls -A /app/data 2>/dev/null)" ] && echo "has files" || echo "empty/missing")"
fi
# Install/update requirements if requirements.txt exists
if [ -f "/app/bot-volume/requirements.txt" ]; then
echo "Installing/updating Python packages..."
pip install --no-cache-dir -r /app/bot-volume/requirements.txt
fi
echo "Starting bot..."
echo "Bot files in volume:"
ls -la /app/bot-volume/
echo "Running: python /app/bot-volume/bot.py"
# Run the bot from the volume
exec python -u /app/bot-volume/bot.py