Since @innei ships multiple updates a day, a script to automatically update Mix-Space and Shiro every day felt absolutely necessary so I could always experience the latest features.
Update Script
My Mix-Space backend is deployed with Docker Compose, while the frontend is Shiroi, the closed-source version of Shiro, which I compile before deploying.
Here's the script that updates both the backend and frontend:
Shell
#!/usr/bin/zsh
# 定义路径和版本变量
BACKEND_PATH="/root/mix-space/core"
FRONTEND_PATH="/root/mix-space/Shiroi"
NODE_VERSION="/root/.nvm/versions/node/v20.12.2/bin"
DATE=$(date)
# 清除冗余的 Docker 镜像
/usr/bin/docker system prune -af
# 更新后端
echo "开始更新后端..."
cd $BACKEND_PATH
if docker compose pull && docker compose up -d; then
echo "后端更新完毕。"
else
echo "后端更新失败。"
exit 1
fi
echo "---------------------------------------------"
# 更新前端
cd $FRONTEND_PATH
export PATH="$NODE_VERSION:$PATH"
output=$(git pull)
if [[ $output == *"Already up to date."* ]]; then
echo "前端已经最新啦,不需要更新。"
else
echo "开始更新前端..."
npm install -g pm2
npm install -g pnpm
echo "pnpm 和 pm2 更新完成。"
echo "开始安装依赖..."
if pnpm i; then
echo "依赖安装完毕。"
else
echo "依赖安装失败。"
exit 1
fi
echo "开始编译..."
if pnpm build; then
echo "编译结束。"
else
echo "编译失败。"
exit 1
fi
echo "正在重启前端..."
if pm2 reload ecosystem.config.cjs; then
echo "重启前端完毕"
else
echo "前端重启失败。"
exit 1
fi
fi
echo "最后更新时间:$DATE"
Scheduling
I set it to run automatically at 01:10 every day and write the log to /root/sh/update.log. You can use it as a reference.
Shell
crontab -e
CRON
10 1 * * * /root/sh/mix-space-shiroi-update.sh >> /root/sh/update.log 2>&1
I'm a complete beginner at writing shell scripts. They're pretty rough, but they get the job done.
If you have better ideas, feel free to discuss them with me in the comment section.