#!/bin/bash INSTALL_DIR="/usr/local/proxylite" DOTNET_DIR="$INSTALL_DIR/dotnet60" SERVICE_DIR="$INSTALL_DIR/service" DOTNET_URL="https://app.proxylite.ru/thirdparty/dotnet-runtime-6.0.10-linux-x64.tar.gz" PROXYSERVICE_URL="https://app.proxylite.ru/netcoreapp-latest.tar" PID_FILE="/var/run/proxylite.pid" function check_root() { if [[ $(id -u) -ne 0 ]]; then echo "This script must be run as root" exit 1 fi } function check_dependencies() { for cmd in wget tar; do if ! command -v $cmd &> /dev/null; then echo "Error: $cmd is not installed" exit 1 fi done } function install_proxylite() { local user_id=$1 echo "Installing ProxyLite" mkdir -p $DOTNET_DIR $SERVICE_DIR echo "Downloading .NET 6.0" wget $DOTNET_URL -O /tmp/dotnet.tar.gz echo "Unpacking .NET 6.0" tar xzf /tmp/dotnet.tar.gz -C $DOTNET_DIR rm /tmp/dotnet.tar.gz chmod +x $DOTNET_DIR/dotnet echo "Downloading ProxyService" wget $PROXYSERVICE_URL -O /tmp/proxyservice.tar echo "Unpacking ProxyService" tar xf /tmp/proxyservice.tar -C $SERVICE_DIR rm /tmp/proxyservice.tar echo $user_id > $SERVICE_DIR/userid.ini echo "ProxyLite installed successfully" } function start_proxylite() { if [[ -f $PID_FILE ]]; then echo "ProxyLite is already running" return fi echo "Starting ProxyLite" nohup $DOTNET_DIR/dotnet $SERVICE_DIR/ProxyService.Core.dll > /dev/null 2>&1 & echo $! > $PID_FILE echo "ProxyLite started with PID $(cat $PID_FILE)" } function stop_proxylite() { if [[ ! -f $PID_FILE ]]; then echo "ProxyLite is not running" return fi echo "Stopping ProxyLite" kill $(cat $PID_FILE) rm $PID_FILE echo "ProxyLite stopped" } function uninstall_proxylite() { echo "Uninstalling ProxyLite" stop_proxylite rm -rf $INSTALL_DIR echo "ProxyLite uninstalled" } function update_user_id() { local user_id=$1 echo "Updating user ID to $user_id" echo $user_id > $SERVICE_DIR/userid.ini if [[ -f $PID_FILE ]]; then stop_proxylite start_proxylite fi } check_root check_dependencies if [[ $1 =~ ^[0-9]+$ ]]; then # If the first argument is a number, treat it as an install command install_proxylite $1 start_proxylite elif [[ $1 == "uninstall" ]]; then uninstall_proxylite elif [[ $1 == "stop" ]]; then stop_proxylite elif [[ $1 == "start" ]]; then start_proxylite elif [[ $1 == "restart" ]]; then stop_proxylite start_proxylite elif [[ $1 == "update" && $2 =~ ^[0-9]+$ ]]; then update_user_id $2 else echo "Usage: $0 (to install and start)" echo " $0 {start|stop|restart|uninstall}" echo " $0 update " exit 1 fi exit 0