diff --git a/README.md b/README.md index 1e52db1..9d29779 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Language : 🇺🇸 English | [🇨🇳 简体中文](./README.zh-CN.md) Backend for iOS application named [ServerBee](https://apps.apple.com/us/app/serverbee/id6443553714) -ServerBee - Monitor and manage all your desktop systems | Product Hunt +Web-based Single-Node, Multi-Node Monitoring and Terminal Management Tools ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ZingerLittleBee/server_bee-backend?style=for-the-badge) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/ZingerLittleBee/server_bee-backend/release.yml?style=for-the-badge) @@ -24,7 +24,10 @@ Mono repository for ServerBee - serverbee-recorder - [ServerBee Backend](./web/README.md) (The backend of serverbee, can be used as a standalone application) - serverbee-web (provide data from server) - - serverbee-deploy (provide **AutoLaunch**、**AutoUpdate**、**DownloadWebModule** for serverbee-web) + - ~~serverbee-deploy (provide **AutoLaunch**、**AutoUpdate**、**DownloadWebModule** for serverbee-web)~~(Deprecated) + - Linux use startup.sh to replace + - `bash <(curl -s https://raw.githubusercontent.com/ZingerLittleBee/server_bee-backend/main/script/startup.sh)` + - macOS、Windows use [ServerMilk](https://github.com/ZingerLittleBee/ServerMilk) to replace # Documentation diff --git a/README.zh-CN.md b/README.zh-CN.md index e64df60..c957176 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -6,7 +6,7 @@ Language : [🇺🇸 English](./README.md) | 🇨🇳 简体中文 iOS 应用 [ServerBee](https://apps.apple.com/us/app/serverbee/id6443553714) 的后端 -ServerBee - Monitor and manage all your desktop systems | Product Hunt +Web 单机、多机版监控、终端管理工具 ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ZingerLittleBee/server_bee-backend?style=for-the-badge) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/ZingerLittleBee/server_bee-backend/release.yml?style=for-the-badge) @@ -24,7 +24,10 @@ ServerBee 的单一代码库 - serverbee-recorder - [ServerBee Backend](web/README.zh-CN.md) (**ServerBee** 的后端可以作为独立应用程序使用) - serverbee-web (模块提供来自机器的数据) - - serverbee-deploy (模块提供 **开机启动**、**自动更新**、**下载 Web 模块** 的功能) + - ~~serverbee-deploy (模块提供 **开机启动**、**自动更新**、**下载 Web 模块** 的功能)~~(已弃用) + - Linux 使用 startup.sh 替换 + - `bash <(curl -s https://raw.githubusercontent.com/ZingerLittleBee/server_bee-backend/main/script/startup.sh)` + - macOS、Windows 使用 [ServerMilk](https://github.com/ZingerLittleBee/ServerMilk) 替换 ## 文档 diff --git a/script/startup.sh b/script/startup.sh index 29be78e..5752ef9 100644 --- a/script/startup.sh +++ b/script/startup.sh @@ -2,45 +2,220 @@ BASE_URL="https://db.serverbee.app/cli" -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[0;33m' +ERROR='\033[0;31m' +INFO='\033[0;32m' +WARNING='\033[0;33m' # No Color NC='\033[0m' OS="$(uname)" ARCH="$(uname -m)" +tuple="" if [[ "$OS" == "Linux" ]]; then - echo -e "Your operating system is ${GREEN}Linux${NC}" + echo -e "OS: ${INFO}Linux${NC}" tuple="unknown-linux-musl" elif [[ "$OS" == "Darwin" ]]; then - echo -e "Your operating system is ${GREEN}MacOS${NC}" + echo -e "OS: ${INFO}macOS${NC}" tuple="apple-darwin" else - echo -e "Your operating system is ${RED}not identified${NC}" && exit 1 + echo -e "OS ${ERROR}not identified${NC}" && exit 1 fi if [[ "$ARCH" == "x86_64" ]]; then - echo -e "Your architecture is ${GREEN}AMD${NC}" + echo -e "Architecture: ${INFO}AMD${NC}" ARCH="x86_64" elif [[ "$ARCH" == "arm64" || "$ARCH" == *"armv"* ]]; then - echo -e "Your architecture is ${GREEN}ARM${NC}" + echo -e "Architecture: ${INFO}ARM${NC}" ARCH="aarch64" else - echo -e "Your architecture is ${RED}not identified${NC}" && exit 1 + echo -e "Architecture ${ERROR}not identified${NC}" && exit 1 fi -version=$(curl -s https://status.serverbee.app/api/version) -echo -e "Latest version is ${GREEN}$version${NC}" +start_on_boot() { + if [[ $is_start_on_boot == "y" ]]; then + echo -e "Starting on boot..." +cat > /etc/systemd/system/serverbee-web.service < /dev/null; then + echo -e "netstat exists, checking if port $port is available..." + # check if port is available, if not, input another port + while true; do + if [[ $(netstat -an | grep -c "$port") -eq 0 ]]; then + break + else + echo -e "${ERROR}Port $port is already in use, please try another port.${NC}" + read -r port + if [[ -z $port ]]; then + echo -e "${ERROR}Port is empty, please try again.${NC}" + read -r port + fi + fi + done + fi + + echo -e "Enable auto start on boot? (y/n)" + read -r is_start_on_boot + + if [[ "$OS" == "Linux" ]]; then + start_on_boot + fi + + nohup ./serverbee-web -p $port >/dev/null 2>&1 & + echo -e "Installation completed." + echo -e "======================= End ===========================" + echo -e "\n" + echo -e "======================= Tips ==========================" + echo -e "1. Website UI: http://localhost:$port" + echo -e "2. If server is not running, please check the ${INFO}web.log${NC} in serverbee directory." + echo -e "3. If want to stop the server, please use ${INFO}ps -ef | grep serverbee-web | grep -v grep | awk '{print $2}' | xargs kill -9${NC} to stop the server." + echo -e "=========================================================" +} + +stop() { + echo -e "======================= Stop ==========================" + echo -e "Stopping the service..." + ps -ef | grep serverbee-web | grep -v grep | awk '{print $2}' | xargs kill -9 + echo -e "Stopped successfully." + echo -e "======================= End ===========================" +} + +update() { + echo -e "======================= Update ==========================" + echo -e "Updating the service..." + cd serverbee || { echo -e "${ERROR}Directory serverbee not found. Please run installation.${NC}" && exit 1; } + + stop + + echo -e "Getting the latest version of ServerBee" + version=$(curl -s https://status.serverbee.app/api/version) + echo -e "Latest version: ${INFO}$version${NC}" + + echo -e "\nPress ${INFO}Enter to update ${NC}, or ${ERROR}Ctrl+C to cancel${NC}" + read -r + + url="$BASE_URL/$version/serverbee-web-$ARCH-$tuple.zip" + echo -e "Downloading ${INFO}$url${NC}" + + curl -s -L "$url" -o serverbee-web.zip + unzip -o serverbee-web.zip + rm serverbee-web.zip + + echo -e "Updated successfully." + echo -e "======================= End ==========================" +} + +uninstallation() { + echo -e "======================= Uninstallation ==========================" + + echo -e "${INFO}Starting uninstallation...${NC}" + stop + + echo -e "Do you want to execute the following steps?" + echo -e "1. Remove ${INFO}the directory of serverbee (including data)${NC}" + echo -e "${WARNING}rm -rf serverbee${NC}" + echo -e "2. Remove ${INFO}the service of serverbee${NC} (if exist)" + echo -e "${WARNING}rm -f /etc/systemd/system/serverbee-web.service${NC}" + + echo -e "\nPress ${INFO}Enter to execute ${NC}, or ${ERROR}Ctrl+C to cancel${NC}" + read -r + + if [[ -d serverbee ]]; then + rm -rf serverbee + rm -f /etc/systemd/system/serverbee-web.service + + else + echo -e "${ERROR}Directory serverbee not found.${NC}" && exit 1 + fi + + echo -e "${INFO}Uninstallation completed.${NC}" + echo -e "======================= End ==========================" +} + +log() { + echo -e "======================= Log ==========================" + echo -e "Log file: ${INFO}web.log${NC}" + + if [ -e "web.log" ]; then + tail -n 200 web.log + else + [ -d "serverbee" ] || { echo -e "${ERROR}Directory serverbee not found.${NC}" && exit 1; } + tail -n 200 serverbee/web.log + fi + + echo -e "======================= End ==========================" +} + +echo "======================= Commands ==========================" +echo "Welcome to use ServerBee automatic installation, please select an option:" +options=("Installation" "Update" "Uninstallation" "Log" "Stop" "Exit") +select opt in "${options[@]}"; do + case $opt in + "Installation") + installation + ;; + "Update") + update + ;; + "Uninstallation") + uninstallation + ;; + "Log") + log + ;; + "Stop") + stop + ;; + "Exit") + break + ;; + *) echo "Invalid selection, please try again" ;; + esac +done