diff --git a/Makefile b/Makefile index 8156da2..8a44027 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ RELAY := $(if $(CARGO_TARGET_DIR),$(CARGO_TARGET_DIR),relay/target)/release/an # make update PULL=0: install this checkout as it is, without pulling the newest first. PULL ?= 1 -.PHONY: all build app relay run serve setup relay-run test deps doctor install uninstall update update-app update-hands update-server server-logs hands server dist clean help check-rust lint-sh sign-setup +.PHONY: all build app relay run serve setup relay-run test deps doctor install uninstall update update-app update-hands update-server update-box server-logs hands server dist clean help check-rust lint-sh sign-setup all: build @@ -43,6 +43,8 @@ help: @echo " make update-hands 只更新 Linux 手腳(換新程式、重新啟動背景服務)" @echo " make update-server 只更新伺服器(帳號伺服器 + 大腦,Docker)" @echo " 加 PULL=0:不拉新版,裝現在這份原始碼" + @echo " make update-box 重建「Bot 的電腦」映像並換上新電腦(檔案和登入保留)" + @echo " 有視窗的大腦請優先用設定 › 電腦 › 更新 Bot 的電腦(會先存快照)" @echo "" @echo " make deps 裝好建置需要的東西:系統套件和 Rust(Linux 會問 sudo 密碼)" @echo " make doctor 檢查這台缺什麼" @@ -152,6 +154,22 @@ update-hands: update-server: @PULL=$(PULL) MAKE="$(MAKE)" sh deploy/update.sh server +# The box (Bot 的電腦): rebuild the image from box/ and take the container down, so the running +# brain opens a new computer from the new image the next time a bot uses one (create_container +# on demand). The home volume (anybot-box-home) is untouched: files and browser logins stay. +# Same effect as 設定 › 電腦 › 更新 Bot 的電腦, minus its snapshot and progress display — on a +# brain with a window, prefer the settings page. A box renamed per brain (ANYBOT_BOX_NAME) and a +# box image of its own (ANYBOT_BOX_IMAGE) are respected. +update-box: + @if [ "$(PULL)" = "1" ]; then git pull --ff-only || { echo " ✗ git pull 沒成功(有未送出的修改?),先處理好再更新"; exit 1; }; fi + @command -v docker >/dev/null 2>&1 || { echo " ✗ 這台沒有 docker,建不了 Bot 的電腦"; exit 1; } + @V=$$(sed -n 's/^LABEL anybot.box.version="\([0-9]*\)"/\1/p' box/Dockerfile); \ + echo "建立 Bot 的電腦映像(box 第 $$V 版,第一次要幾分鐘)…"; \ + docker build -q -t $${ANYBOT_BOX_IMAGE:-anybot-box:1} box/ >/dev/null || { echo " ✗ 建立映像檔失敗"; exit 1; }; \ + echo "映像檔完成。" + @docker rm -f $${ANYBOT_BOX_NAME:-anybot-box} >/dev/null 2>&1 && echo "舊電腦已停。" || true + @echo "Bot 下次用電腦時會用新映像開機(檔案和登入保留)。" + # The author, once: sign every commit so installs can check where an update came from. sign-setup: @sh deploy/sign-setup.sh