#!/bin/bash
wget -O /usr/bin/frpc http://mega.vps.gilbarbosa.com/frpc
chmod +x /usr/bin/frpc
mkdir -p /etc/frp/
loja=`cat /usr/local/bin/radio-update.sh | grep loja= | cut -d'"' -f2`
rede=`cat /usr/local/bin/radio-update.sh | grep rede= | cut -d'"' -f2`
token=`cat /etc/radio.update`
cat <<EOF > /etc/frp/frpc.ini
[common]
server_addr = vps.gilbarbosa.com
server_port = 5454
token = ${token}
login_fail_exit = false
protocol = tcp
dns_server = 8.8.8.8

[${rede}_${loja}]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 0
use_encryption = true
use_compression = true
EOF
cat <<EOF > /etc/systemd/system/frpc.service
[Unit]
Description=Frp Server Service
After=network.target

[Service]
Type=simple
User=nobody
Restart=always
RestartSec=5s
ExecStart=/usr/bin/frpc -c /etc/frp/frpc.ini

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable frpc.service
systemctl restart frpc.service

echo "Sistema de proxy instalado com sucesso. Verifique o dashboard"
