diff --git a/deploy.cmd b/deploy.cmd new file mode 100644 index 0000000..e69de29 diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..f8e604c --- /dev/null +++ b/deploy.sh @@ -0,0 +1,103 @@ +#!/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 + +# clone repo +repo1="https://github.com/snowykami/server-status-client" +repo2="https://git.liteyuki.icu/snowykami/server-status-client" +# try 1 if failed try 2 +git clone "$repo1" "$install_dir/server-status-client" || 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" + +# activate the virtual environment + + +# install the required packages +echo "Installing the required packages" +$python_exe -m pip install pdm +$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 < /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" + diff --git a/deploy/server-status-client.service b/deploy/server-status-client.service new file mode 100644 index 0000000..893091e --- /dev/null +++ b/deploy/server-status-client.service @@ -0,0 +1,13 @@ +[Unit] +Description=Server Status Client +After=network-online.target + +[Service] +Type=simple +ExecStart=/opt/server-status-client/.venv/bin/python /opt/server-status-client/main.py http://192.168.31.149:8091 lts114514 localhost run -n Kami --labels physical ubuntu --location Chongqing --link http://kslan.liteyuki.icu:53851 +WorkingDirectory=/opt/server-status-client +Restart=on-failure +RestartSec=10 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/test_tz.py b/test_tz.py deleted file mode 100644 index 121e66f..0000000 --- a/test_tz.py +++ /dev/null @@ -1,3 +0,0 @@ -from server_status.timezone import get_timezone - -print(get_timezone()) \ No newline at end of file