跳转到内容

Test

来自UbuntuStudioCN
Brucekomike留言 | 贡献2025年6月14日 (六) 21:12的版本 (创建页面,内容为“快速安装脚本 == 安装内容 == <pre> #!/bin/bash get_latest_release_tag() { curl -s "https://api.github.com/repos/fatedier/frp/releases/latest" | grep -Po '"tag_name": "\K[^"]*' } # Function to detect architecture detect_arch() { ARCH=$(uname -m) case "$ARCH" in x86_64) echo "amd64" ;; aarch64) echo "arm64" ;; armv7l) echo "arm" ;; *)…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

快速安装脚本

安装内容

#!/bin/bash
get_latest_release_tag() {
    curl -s "https://api.github.com/repos/fatedier/frp/releases/latest" | grep -Po '"tag_name": "\K[^"]*'
}

# Function to detect architecture
detect_arch() {
    ARCH=$(uname -m)
    case "$ARCH" in
        x86_64)
            echo "amd64"
            ;;
        aarch64)
            echo "arm64"
            ;;
        armv7l)
            echo "arm"
            ;;
        *)
            echo "unsupported"
            ;;
    esac
}

# Main script
main() {
    LATEST_TAG=$(get_latest_release_tag)
    if [ -z "$LATEST_TAG" ]; then
        echo "Error: Could not fetch the latest release tag."
        exit 1
    fi
    echo "Latest FRP release: $LATEST_TAG"

    DETECTED_ARCH=$(detect_arch)
    if [ "$DETECTED_ARCH" == "unsupported" ]; then

        echo "Error: Your architecture ($ARCH) is not directly supported by this script for FRP downloads."
        echo "Please manually download from https://github.com/fatedier/frp/releases"
        exit 1
    fi
    echo "Detected architecture: $DETECTED_ARCH"

    FILENAME="frp_${LATEST_TAG#v}_linux_${DETECTED_ARCH}.tar.gz"
    DOWNLOAD_URL="https://github.com/fatedier/frp/releases/download/${LATEST_TAG}/${FILENAME}"

    echo "Attempting to download: $DOWNLOAD_URL"

    # Use curl to download the file
    curl -L -o "$FILENAME" "$DOWNLOAD_URL"

    if [ $? -eq 0 ]; then
        echo "Download complete: $FILENAME"
        echo "You can now extract it using: tar -xzf $FILENAME"
    else
        echo "Error: Download failed."
        echo "Please check the URL or your network connection."
    fi
}


# Define variables
SERVICE_NAME="frps"
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
FRPS_DIR="$HOME/Workspace/frp" # Recommended directory for frp binaries and config

mkdir -p ~/Workspace
cd ~/Workspace
main
mv ${FILENAME%.tar.gz} frp

# Check if the frps directory exists, if not, create it
if [ ! -d "$FRPS_DIR" ]; then
    echo "Creating directory: $FRPS_DIR"
    sudo mkdir -p "$FRPS_DIR"
    sudo chown $USER:$USER "$FRPS_DIR" # Give ownership to the current user for easy management
fi

# Get the current working directory of the script
SCRIPT_DIR=$(pwd)

# Check if frps binary exists in the current directory
if [ ! -f "$SCRIPT_DIR/frps" ]; then
    echo "Error: 'frps' binary not found in the current directory ($SCRIPT_DIR)."
    echo "Please ensure the frp archive has been extracted and 'frps' is present."
    exit 1
fi

# Check if frps.toml configuration file exists in the current directory
if [ ! -f "$SCRIPT_DIR/frps.toml" ]; then
    echo "Error: 'frps.toml' configuration file not found in the current directory ($SCRIPT_DIR)."
    echo "Please ensure 'frps.toml' is present."
    exit 1
fi

# Copy frps binary and frps.toml to the designated directory
echo "Copying frps binary and frps.toml to $FRPS_DIR..."
sudo cp "$SCRIPT_DIR/frps" "$FRPS_DIR/"
sudo cp "$SCRIPT_DIR/frps.toml" "$FRPS_DIR/"

# Create the systemd service file
echo "Creating systemd service file: $SERVICE_FILE"
sudo bash -c "cat << EOF > $SERVICE_FILE
[Unit]
Description = frp server
After = network.target syslog.target
Wants = network.target

[Service]
Type = simple
User = $USER
ExecStart = $FRPS_DIR/frps -c $FRPS_DIR/frps.toml
Restart = on-failure
RestartSec = 5s

[Install]
WantedBy = multi-user.target
EOF"

# Reload systemd daemon, enable and start the service
echo "Reloading systemd daemon..."
sudo systemctl daemon-reload

echo "Enabling $SERVICE_NAME service to start on boot..."
sudo systemctl enable "$SERVICE_NAME"

echo "Starting $SERVICE_NAME service..."
sudo systemctl start "$SERVICE_NAME"

echo "Service creation complete. You can check its status with: sudo systemctl status $SERVICE_NAME"
echo "Remember to configure your frps.toml file properly."

# Define the output file
TOML_FILE="frps.toml"

# Function to generate a random token
generate_token() {
    # Generate a random string of 32 alphanumeric characters
    head /dev/urandom | tr -dc A-Za-z0-9_.- | head -c 32
}

# Generate the token
GENERATED_TOKEN=$(generate_token)

# Create the frps.toml content
cat << EOF > "$TOML_FILE"
# frps.toml - FRP Server Configuration

# Basic server settings
bindAddr = "0.0.0.0"
bindPort =12048
kcpBindPort = 12048
# Authentication settings
auth.method = "token"
auth.token = "$GENERATED_TOKEN"

# Logging settings
log.to = "./frps.log"
# trace, debug, info, warn, error
log.level = "info"
log.maxDays = 7
EOF
echo "Generated '$TOML_FILE' with a new authentication token."
echo "Authentication Token: $GENERATED_TOKEN"
echo "Please keep this token secure and use it in your frpc.toml client configuration."