Update docker-setup.sh

jkbkb
This commit is contained in:
Alireza Jahanshahlou 2025-11-15 13:31:34 +03:30
parent 76d55e5557
commit 9b9d3ba5e0

View file

@ -57,7 +57,7 @@ check_whiptail() {
echo "Installing whiptail..." echo "Installing whiptail..."
apt update apt update
apt install -y whiptail apt install -y whiptail
be fi
} }
check_whiptail check_whiptail
@ -79,7 +79,7 @@ esac
if [ $EUID -ne 0 ]; then if [ $EUID -ne 0 ]; then
whiptail --title "Permission error" --msgbox "Please run this script with root privileges" 10 50 whiptail --title "Permission error" --msgbox "Please run this script with root privileges" 10 50
exit 1 exit 1
be fi
# Check system version # Check system version
if [ -f /etc/os-release ]; then if [ -f /etc/os-release ]; then
@ -87,11 +87,11 @@ if [ -f /etc/os-release ]; then
if [ "$ID" != "debian" ] && [ "$ID" != "ubuntu" ]; then if [ "$ID" != "debian" ] && [ "$ID" != "ubuntu" ]; then
whiptail --title "System Error" --msgbox "This script only supports Debian/Ubuntu systems" 10 60 whiptail --title "System Error" --msgbox "This script only supports Debian/Ubuntu systems" 10 60
exit 1 exit 1
be fi
else else
whiptail --title "System Error" --msgbox "Unable to determine system version. This script only supports Debian/Ubuntu systems" 10 60 whiptail --title "System Error" --msgbox "Unable to determine system version. This script only supports Debian/Ubuntu systems" 10 60
exit 1 exit 1
be fi
# Download configuration file function # Download configuration file function
check_and_download() { check_and_download() {
@ -101,10 +101,10 @@ check_and_download() {
if ! curl -fL --progress-bar "$url" -o "$filepath"; then if ! curl -fL --progress-bar "$url" -o "$filepath"; then
whiptail --title "Error" --msgbox "Download of file ${filepath} failed" 10 50 whiptail --title "Error" --msgbox "Download of file ${filepath} failed" 10 50
exit 1 exit 1
be fi
else else
echo "The file ${filepath} already exists; skip downloading." echo "The file ${filepath} already exists; skip downloading."
be fi
} }
# Check if it is installed # Check if it is installed
@ -114,21 +114,21 @@ check_installed() {
DIR_CHECK=1 DIR_CHECK=1
else else
DIR_CHECK=0 DIR_CHECK=0
be fi
# Check if the container exists # Check if the container exists
if docker inspect xiaozhi-esp32-server > /dev/null 2>&1; then if docker inspect xiaozhi-esp32-server > /dev/null 2>&1; then
CONTAINER_CHECK=1 CONTAINER_CHECK=1
else else
CONTAINER_CHECK=0 CONTAINER_CHECK=0
be fi
# Both checks passed # Both checks passed
if [ $DIR_CHECK -eq 1 ] && [ $CONTAINER_CHECK -eq 1 ]; then if [ $DIR_CHECK -eq 1 ] && [ $CONTAINER_CHECK -eq 1 ]; then
return 0 # Installed return 0 # Installed
else else
return 1 # Not installed return 1 # Not installed
be fi
} }
# Update related # Update related
@ -155,7 +155,7 @@ if check_installed; then
echo "Container successfully removed: $container" echo "Container successfully removed: $container"
else else
echo "Container does not exist, skip: $container" echo "Container does not exist, skip: $container"
be fi
done done
# Delete a specific image (considering the possibility that the image may not exist). # Delete a specific image (considering the possibility that the image may not exist).
@ -170,7 +170,7 @@ if check_installed; then
echo "Mirror image successfully deleted: $image" echo "Mirror image successfully deleted: $image"
else else
echo "Image does not exist, skip: $image" echo "Image does not exist, skip: $image"
be fi
done done
echo "All cleanup operations completed" echo "All cleanup operations completed"
@ -180,7 +180,7 @@ if check_installed; then
if [ -f /opt/xiaozhi-server/data/.config.yaml ]; then if [ -f /opt/xiaozhi-server/data/.config.yaml ]; then
cp /opt/xiaozhi-server/data/.config.yaml /opt/xiaozhi-server/backup/.config.yaml cp /opt/xiaozhi-server/data/.config.yaml /opt/xiaozhi-server/backup/.config.yaml
echo "The original configuration file has been backed up to /opt/xiaozhi-server/backup/.config.yaml" echo "The original configuration file has been backed up to /opt/xiaozhi-server/backup/.config.yaml"
be fi
# Download the latest configuration file # Download the latest configuration file
check_and_download "/opt/xiaozhi-server/docker-compose_all.yml" "https://ghfast.top/https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/refs/heads/main/main/xiaozhi-server/docker-compose_all.yml" check_and_download "/opt/xiaozhi-server/docker-compose_all.yml" "https://ghfast.top/https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/refs/heads/main/main/xiaozhi-server/docker-compose_all.yml"
@ -194,8 +194,8 @@ if check_installed; then
else else
whiptail --title "Skip upgrade" --msgbox "Upgrade canceled, will continue using the current version." 10 50 whiptail --title "Skip upgrade" --msgbox "Upgrade canceled, will continue using the current version." 10 50
# Skip the upgrade and continue with the subsequent installation process. # Skip the upgrade and continue with the subsequent installation process.
be fi
be fi
# Check curl installation # Check curl installation
@ -207,7 +207,7 @@ if ! command -v curl &> /dev/null; then
else else
echo "------------------------------------------------------------" echo "------------------------------------------------------------"
echo "curl is already installed, skip the installation steps" echo "curl is already installed, skip the installation steps"
be fi
# Check Docker installation # Check Docker installation
if ! command -v docker &> /dev/null; then if ! command -v docker &> /dev/null; then
@ -250,10 +250,10 @@ if ! command -v docker &> /dev/null; then
else else
whiptail --title "Error" --msgbox "Docker installation failed, please check the logs." 10 50 whiptail --title "Error" --msgbox "Docker installation failed, please check the logs." 10 50
exit 1 exit 1
be fi
else else
echo "Docker is already installed, skip the installation steps" echo "Docker is already installed, skip the installation steps"
be fi
# Docker image source configuration # Docker image source configuration
MIRROR_OPTIONS=( MIRROR_OPTIONS=(
@ -288,7 +288,7 @@ if [ -n "$MIRROR_URL" ]; then
mkdir -p /etc/docker mkdir -p /etc/docker
if [ -f /etc/docker/daemon.json ]; then if [ -f /etc/docker/daemon.json ]; then
cp /etc/docker/daemon.json /etc/docker/daemon.json.bak cp /etc/docker/daemon.json /etc/docker/daemon.json.bak
be fi
cat > /etc/docker/daemon.json <<EOF cat > /etc/docker/daemon.json <<EOF
{ {
"dns": ["8.8.8.8", "114.114.114.114"], "dns": ["8.8.8.8", "114.114.114.114"],
@ -299,7 +299,7 @@ EOF
echo "------------------------------------------------------------" echo "------------------------------------------------------------"
echo "Starting to restart Docker service..." echo "Starting to restart Docker service..."
systemctl restart docker.service systemctl restart docker.service
be fi
# Create installation directory # Create installation directory
echo "------------------------------------------------------------" echo "------------------------------------------------------------"
@ -310,7 +310,7 @@ if [ ! -d /opt/xiaozhi-server/data ]; then
echo "Data directory created: /opt/xiaozhi-server/data" echo "Data directory created: /opt/xiaozhi-server/data"
else else
echo "Directory xiaozhi-server/data already exists, skip creation" echo "Directory xiaozhi-server/data already exists, skip creation"
be fi
# Check and create the model catalog # Check and create the model catalog
if [ ! -d /opt/xiaozhi-server/models/SenseVoiceSmall ]; then if [ ! -d /opt/xiaozhi-server/models/SenseVoiceSmall ]; then
@ -318,7 +318,7 @@ if [ ! -d /opt/xiaozhi-server/models/SenseVoiceSmall ]; then
echo "Model directory created: /opt/xiaozhi-server/models/SenseVoiceSmall" echo "Model directory created: /opt/xiaozhi-server/models/SenseVoiceSmall"
else else
echo "Directory xiaozhi-server/models/SenseVoiceSmall already exists, skipping creation" echo "Directory xiaozhi-server/models/SenseVoiceSmall already exists, skipping creation"
be fi
echo "------------------------------------------------------------" echo "------------------------------------------------------------"
echo "Start downloading speech recognition model" echo "Start downloading speech recognition model"
@ -337,13 +337,13 @@ if [ ! -f "$MODEL_PATH" ]; then
} }
else else
echo "model.pt file already exists, skip downloading" echo "model.pt file already exists, skip downloading"
be fi
# Download will only proceed if the upgrade is not complete. # Download will only proceed if the upgrade is not complete.
if [ -z "$UPGRADE_COMPLETED" ]; then if [ -z "$UPGRADE_COMPLETED" ]; then
check_and_download "/opt/xiaozhi-server/docker-compose_all.yml" "https://ghfast.top/https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/refs/heads/main/main/xiaozhi-server/docker-compose_all.yml" check_and_download "/opt/xiaozhi-server/docker-compose_all.yml" "https://ghfast.top/https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/refs/heads/main/main/xiaozhi-server/docker-compose_all.yml"
check_and_download "/opt/xiaozhi-server/data/.config.yaml" "https://ghfast.top/https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/refs/heads/main/main/xiaozhi-server/config_from_api.yaml" check_and_download "/opt/xiaozhi-server/data/.config.yaml" "https://ghfast.top/https://raw.githubusercontent.com/xinnan-tech/xiaozhi-esp32-server/refs/heads/main/main/xiaozhi-server/config_from_api.yaml"
be fi
# Start Docker service # Start Docker service
( (
@ -355,7 +355,7 @@ docker compose -f /opt/xiaozhi-server/docker-compose_all.yml up -d
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
whiptail --title "Error" --msgbox "Docker service failed to start. Please try changing the image source and re-execute this script." 10 60 whiptail --title "Error" --msgbox "Docker service failed to start. Please try changing the image source and re-execute this script." 10 60
exit 1 exit 1
be fi
echo "------------------------------------------------------------" echo "------------------------------------------------------------"
echo "Checking service startup status..." echo "Checking service startup status..."
@ -366,11 +366,11 @@ while true; do
if [ $((CURRENT_TIME - START_TIME)) -gt $TIMEOUT ]; then if [ $((CURRENT_TIME - START_TIME)) -gt $TIMEOUT ]; then
whiptail --title "Error" --msgbox "Service startup timed out, expected log content not found within the specified time" 10 60 whiptail --title "Error" --msgbox "Service startup timed out, expected log content not found within the specified time" 10 60
exit 1 exit 1
be fi
if docker logs xiaozhi-esp32-server-web 2>&1 | grep -q "Started AdminApplication in"; then if docker logs xiaozhi-esp32-server-web 2>&1 | grep -q "Started AdminApplication in"; then
break break
be fi
sleep 1 sleep 1
done done
@ -398,7 +398,7 @@ with open(config_path, 'w') as f:
yaml.dump(config, f); yaml.dump(config, f);
" "
docker restart xiaozhi-esp32-server docker restart xiaozhi-esp32-server
be fi
# Get and display address information # Get and display address information
LOCAL_IP=$(hostname -I | awk '{print $1}') LOCAL_IP=$(hostname -I | awk '{print $1}')