mirror of
https://github.com/snowykami/server-status-client.git
synced 2024-11-28 16:25:48 +08:00
✨ 修复脚本执行错误
This commit is contained in:
parent
e0aa6adbeb
commit
22feee38ee
@ -31,9 +31,9 @@ _✨ 服务器状态 - 客户端 ✨_
|
|||||||
```shell
|
```shell
|
||||||
sudo bash -c "$(curl -sSL https://raw.githubusercontent.com/snowykami/server-status-client/refs/heads/main/deploy.sh)"
|
sudo bash -c "$(curl -sSL https://raw.githubusercontent.com/snowykami/server-status-client/refs/heads/main/deploy.sh)"
|
||||||
```
|
```
|
||||||
如果无法访问 GitHub,可以使用以下地址
|
如果位于中国大陆,可使用国内镜像
|
||||||
```shell
|
```shell
|
||||||
sudo bash -c "$(curl -sSL https://git.liteyuki.icu/snowykami/server-status-client/raw/branch/main/deploy.sh)"
|
sudo bash -c "$(curl -sSL https://git.liteyuki.icu/snowykami/server-status-client/raw/branch/main/deploy-cn.sh)"
|
||||||
```
|
```
|
||||||
|
|
||||||
- 或手动部署
|
- 或手动部署
|
||||||
|
100
deploy-cn.sh
Executable file
100
deploy-cn.sh
Executable file
@ -0,0 +1,100 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 部署脚本中国大陆可用版本
|
||||||
|
|
||||||
|
# check if sudo is used
|
||||||
|
if [ "$EUID" -ne 0 ]; then
|
||||||
|
echo "Please run as root"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check install dir
|
||||||
|
install_dir="/opt"
|
||||||
|
echo -n "Install directory? (default: $install_dir/server-status-client): " && read -r install_dir_input
|
||||||
|
if [ -n "$install_dir_input" ]; then
|
||||||
|
install_dir="$install_dir_input"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check server
|
||||||
|
echo -n "Server? (required): " && read -r server
|
||||||
|
if [ -z "$server" ]; then
|
||||||
|
echo "Server is required"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check token
|
||||||
|
echo -n "Token? (required): " && read -r token
|
||||||
|
if [ -z "$token" ]; then
|
||||||
|
echo "Token is required"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check hostname
|
||||||
|
hostname=$(hostname)
|
||||||
|
echo -n "Hostname? (default: $hostname): " && read -r hostname_input
|
||||||
|
if [ -n "$hostname_input" ]; then
|
||||||
|
hostname="$hostname_input"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# labels
|
||||||
|
echo -n "Labels? (space separated): " && read -r labels_input
|
||||||
|
if [ -n "$labels_input" ]; then
|
||||||
|
labels="$labels_input"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# location
|
||||||
|
echo -n "Location? (optional): " && read -r location_input
|
||||||
|
if [ -n "$location_input" ]; then
|
||||||
|
location="$location_input"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
repo2="https://git.liteyuki.icu/snowykami/server-status-client"
|
||||||
|
# try 1 if failed try 2
|
||||||
|
git clone "$repo2" "$install_dir/server-status-client"
|
||||||
|
cd "$install_dir/server-status-client" || { echo "Failed to clone repo"; exit 1; }
|
||||||
|
|
||||||
|
# create venv
|
||||||
|
python3 -m venv venv
|
||||||
|
python_exe="./venv/bin/python"
|
||||||
|
|
||||||
|
# check if venv is created
|
||||||
|
if [ ! -f "$python_exe" ]; then
|
||||||
|
echo "Failed to create venv"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "venv created successfully"
|
||||||
|
|
||||||
|
# install the required packages
|
||||||
|
echo "Installing the required packages"
|
||||||
|
$python_exe -m pip install pdm -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
|
$python_exe -m pdm install
|
||||||
|
|
||||||
|
# create the systemd service
|
||||||
|
echo "Creating the systemd service"
|
||||||
|
|
||||||
|
# generate random id
|
||||||
|
# shellcheck disable=SC2002
|
||||||
|
id=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
|
||||||
|
|
||||||
|
bash -c "cat <<EOF > /etc/systemd/system/server-status-client.service
|
||||||
|
[Unit]
|
||||||
|
Description=Server Status Client
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=$install_dir/server-status-client/venv/bin/python main.py $server $token $id run -n $hostname --labels $labels --location $location
|
||||||
|
WorkingDirectory=$install_dir/server-status-client
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=10
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF"
|
||||||
|
|
||||||
|
# enable and start the service
|
||||||
|
systemctl enable server-status-client
|
||||||
|
systemctl start server-status-client
|
||||||
|
|
||||||
|
echo "server-status-client installed successfully"
|
@ -64,9 +64,6 @@ if [ ! -f "$python_exe" ]; then
|
|||||||
fi
|
fi
|
||||||
echo "venv created successfully"
|
echo "venv created successfully"
|
||||||
|
|
||||||
# activate the virtual environment
|
|
||||||
source "$python_exe"
|
|
||||||
|
|
||||||
# install the required packages
|
# install the required packages
|
||||||
echo "Installing the required packages"
|
echo "Installing the required packages"
|
||||||
$python_exe -m pip install pdm
|
$python_exe -m pip install pdm
|
||||||
|
Loading…
Reference in New Issue
Block a user