Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add my script. #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# deploy
Deploy scripts for frp.
Deploy scripts for frp.
Usage:
> bash <( curl -s -L https://github.com/gofrp/deploy/raw/master/frp_deploy.sh )
90 changes: 90 additions & 0 deletions frp_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash

#Check if git is installed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space

Copy link

@blizard863 blizard863 May 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type git
if [ $? != 0 ]; then
echo "git is required for installation, exit."
exit 1
fi
#Set flags for hot update.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space


frps_FLAG=`ps -ef |grep -w frps|grep -v grep|wc -l`
frpc_FLAG=`ps -ef |grep -w frpc|grep -v grep|wc -l`

#Force stop services before upgrade.

systemctl stop frps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deploy.sh may not need to start or stop service now. We can just display start and stop command after successful installed.


systemctl stop frpc

#Detect the arch.

case $(uname -m) in
"x86_64")
ARCH="amd64"
;;
"i*86")
ARCH="386"
;;
"arm64")
ARCH="arm64"
;;
"armhf")
ARCH="arm"
;;
"mips64")
ARCH="mips64"
;;
"mips64le")
ARCH="mips64le"
;;
"mips")
ARCH="mips"
;;
*)
echo "Unsupport architecture." && exit 0
esac
echo "Detected ${ARCH} architecture."
#Get latest release tag
RELEASETAG=$(git ls-remote --tags https://github.com/fatedier/frp | sort -t '/' -k 2 -V | sed -e '/\^/d')
export FRP_VERSION=${RELEASETAG:0-6}
echo "The latest frp release is ${FRP_VERSION}"
mkdir -p /etc/frp

rm -rf /tmp/frp_${FRP_VERSION}_linux_${ARCH}*
cd /tmp
echo "Downloading tar package from Github......"
wget -q "https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/frp_${FRP_VERSION}_linux_${ARCH}.tar.gz"
echo "Download complete."
echo "Unpacking......"
tar xzf frp_${FRP_VERSION}_linux_${ARCH}.tar.gz
echo "Installing binary files......"
cp ./frp_${FRP_VERSION}_linux_${ARCH}/frps /usr/local/bin && chmod +x /usr/local/bin/frps
cp ./frp_${FRP_VERSION}_linux_${ARCH}/frpc /usr/local/bin && chmod +x /usr/local/bin/frpc
setcap cap_net_bind_service=ep /usr/local/bin/frps #Give frps binary access to well-known ports(smbd,NetBIOS,etc).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看了一下下面说的,如果认为有些发行版不会使用 systemd 的话,或许可以试试用 capsh 来为 frp 进程加特权而不是为执行文件后的所有进程加特权

echo "Installing configuration files......"
test -e /etc/frp/frpc.ini && echo "Configuration files exist. Do not copy templetes." || (echo "Configuration files do not exist. Copy templetes." && cp ./frp_${FRP_VERSION}_linux_${ARCH}/frp*.ini /etc/frp)
echo "Configuration file is installed to /etc/frp ."

#Fix systemctl warning.
cp ./frp_${FRP_VERSION}_linux_${ARCH}/systemd/* /lib/systemd/system
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all linux os support systemd?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we can copy systemd configurefiles to this repo, it will not managed in frp repo.

Copy link
Author

@hathlife hathlife May 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all linux os support systemd?

Gentoo / Slackware are affected. For gentoo, we can use systemd over the openRC. For slackware, I don't have such environment / knowledge to test.
It make take me some time to figure out traditional init.d method.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we can copy systemd configurefiles to this repo, it will not managed in frp repo.

Not necessarily,Keeping systemd unit files with binaries can make install script simpler, or we need to download them from this repo separately.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we can copy systemd configurefiles to this repo, it will not managed in frp repo.

Not necessarily,Keeping systemd unit files with binaries can make install script simpler, or we need to download them from this repo separately.

Upload the init.d script to frp repo?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The process should be:

  1. Detect system arch and os.
  2. Download corresponding scripts(systemd configs) or others.
  3. Download binary files.
  4. Move files to correct locations.
  5. Display usage message.

We can only support specified os you tested and comment it.

systemctl daemon-reload

echo "Install complete."
echo "See https://github.com/fatedier/frp/blob/master/README.md for configuration."
echo "Use \"systemctl start frps\" or \"systemctl start frpc\" to start frpc\frps service."

#Auto restart services.

if [ $frps_FLAG ]
then
systemctl start frps
elif [ $frpc_FLAG ]
then
systemctl start frpc
fi

#systemctl enable frps
#systemctl enable frpc

rm -rf /tmp/frp_${FRP_VERSION}_linux_${ARCH}*