Skip to content

Instantly share code, notes, and snippets.

@xiaojueguan
Last active February 17, 2024 05:51
Show Gist options
  • Save xiaojueguan/598af7f5a658fd21821064fff27ce45e to your computer and use it in GitHub Desktop.
Save xiaojueguan/598af7f5a658fd21821064fff27ce45e to your computer and use it in GitHub Desktop.
#!/bin/bash
version=$1
service=$2
function print_help()
{
echo "Usage:"
echo "./installFrp.sh version serviceName"
echo "example ./installFrp.sh 0.49.0 frps"
echo "refer to https://github.com/fatedier/frp"
}
function preare_frp_package()
{
version=$1
if [ -f /tmp/frp_${version}_linux_amd64.tar.gz ] ; then
echo "/tmp/frp_${version}_linux_amd64.tar.gz exists, skip download frp package"
else
wget https://github.com/fatedier/frp/releases/download/v${version}/frp_${version}_linux_amd64.tar.gz --directory-prefix=/tmp
fi
tar -zxvf /tmp/frp_${version}_linux_amd64.tar.gz -C /tmp
}
function install_frpc_service()
{
version=$1
if [ -d /tmp/frp_${version}_linux_amd64 ]; then
echo "/tmp/frp_${version}_linux_amd64 exists, skip download frp package"
else
preare_frp_package $version
fi
mkdir -p /etc/frp
cp /tmp/frp_${version}_linux_amd64/frpc.toml /etc/frp/frpc.toml
cp /tmp/frp_${version}_linux_amd64/frpc /usr/bin/frpc
# write frpc service file
cat <<EOF> /etc/systemd/system/frpc.service
[Unit]
Description=Frp Client Service
After=network.target
[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/frpc -c /etc/frp/frpc.toml
ExecReload=/usr/bin/frpc reload -c /etc/frp/frpc.toml
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl status frpc --no-pager
echo "Modify /etc/frp/frpc.toml"
echo "And then run"
echo " systemctl enable frpc"
echo " systemctl start frpc"
echo "to start the services"
}
function install_frps_service()
{
version=$1
if [ -d /tmp/frp_${version}_linux_amd64 ]; then
echo "/tmp/frp_${version}_linux_amd64 exists, skip download frp package"
else
preare_frp_package $version
fi
mkdir -p /etc/frp
cp /tmp/frp_${version}_linux_amd64/frps.toml /etc/frp/frps.toml
cp /tmp/frp_${version}_linux_amd64/frps /usr/bin/frps
# write frps service file
cat <<EOF> /etc/systemd/system/frps.service
[Unit]
Description=Frp Server Service
After=network.target
[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/frps -c /etc/frp/frps.toml
ExecReload=/usr/bin/frpc reload -c /etc/frp/frps.toml
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl status frps --no-pager
echo "Modify /etc/frp/frpc.toml or /etc/frp/frps.toml"
echo "And then run"
echo " systemctl enable frps"
echo " systemctl start frps"
echo "to start the services"
}
case ${service} in
"frpc") install_frpc_service $version
;;
"frps") install_frps_service $version
;;
*) print_help
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment