From 216e046d4f985c4122206f3fa2ba07a638381bfe Mon Sep 17 00:00:00 2001 From: root Date: Thu, 30 Jan 2020 01:47:54 -0500 Subject: [PATCH 1/3] Add script file. --- frp_install.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 frp_install.sh diff --git a/frp_install.sh b/frp_install.sh new file mode 100755 index 0000000..0d19a71 --- /dev/null +++ b/frp_install.sh @@ -0,0 +1,53 @@ +#Detect the arch. + +case $(uname -m) in + "x86_64") + ARCH="amd64" + ;; + "i*86") + ARCH="i386" + ;; + "armv8") + ARCH="arm64" + ;; + "arm") + ARCH="arm" + ;; + "mips64") + ARCH="mips64" + ;; + "mips64le") + ARCH="mips64le" + ;; + "mips") + ARCH="mips" + ;; + *) + echo "Unsupport architecture." && exit +esac +#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/bin && chmod +x /usr/bin/frps + cp ./frp_${FRP_VERSION}_linux_${ARCH}/frpc /usr/bin && chmod +x /usr/bin/frpc + setcap cap_net_bind_service=ep /usr/bin/frps #Give frps binary access to well-known ports(smbd,NetBIOS,etc). + echo "Installing configuration files......" + test -e /etc/frp/frpc.ini && echo "Configuration files exist." || 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 ." + cp ./frp_${FRP_VERSION}_linux_${ARCH}/systemd/* /lib/systemd/system + 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." + #systemctl enable frps + #systemctl enable frpc + rm -rf /tmp/frp_${FRP_VERSION}_linux_${ARCH}* \ No newline at end of file From 51279de30d0bcf52b541c497a458f928f6df4f38 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 30 Jan 2020 01:52:09 -0500 Subject: [PATCH 2/3] Rebased. Show detected architecture. Fix systemctl warning. Fix systemctl warning again. Force stop service before upgrade. Support hot update. Add shebang. Fix arch strings. Fix bug when determining whether to copy configuration file templetes. Add quick deploy command. Change URL in usage to main repository. --- README.md | 4 +++- frp_install.sh => frp_deploy.sh | 41 +++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 6 deletions(-) rename frp_install.sh => frp_deploy.sh (68%) diff --git a/README.md b/README.md index a2c4cc0..eac0ffe 100644 --- a/README.md +++ b/README.md @@ -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 ) diff --git a/frp_install.sh b/frp_deploy.sh similarity index 68% rename from frp_install.sh rename to frp_deploy.sh index 0d19a71..f4832b4 100755 --- a/frp_install.sh +++ b/frp_deploy.sh @@ -1,3 +1,16 @@ +#!/bin/bash + +#Set flags for hot update. + +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 + +systemctl stop frpc + #Detect the arch. case $(uname -m) in @@ -5,12 +18,12 @@ case $(uname -m) in ARCH="amd64" ;; "i*86") - ARCH="i386" + ARCH="386" ;; - "armv8") + "arm64") ARCH="arm64" ;; - "arm") + "armhf") ARCH="arm" ;; "mips64") @@ -23,13 +36,15 @@ case $(uname -m) in ARCH="mips" ;; *) - echo "Unsupport architecture." && exit + 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......" @@ -42,12 +57,28 @@ cd /tmp cp ./frp_${FRP_VERSION}_linux_${ARCH}/frpc /usr/bin && chmod +x /usr/bin/frpc setcap cap_net_bind_service=ep /usr/bin/frps #Give frps binary access to well-known ports(smbd,NetBIOS,etc). echo "Installing configuration files......" - test -e /etc/frp/frpc.ini && echo "Configuration files exist." || echo "Configuration files do not exist. Copy templetes." && cp ./frp_${FRP_VERSION}_linux_${ARCH}/frp*.ini /etc/frp + 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 + 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}* \ No newline at end of file From 8feb12da48792f148dbd082435b0568a45819e6b Mon Sep 17 00:00:00 2001 From: hathlife Date: Sat, 23 May 2020 16:46:50 +0800 Subject: [PATCH 3/3] Change binary files path to /usr/local/bin fix typo in usage. check if git is installed before start. --- README.md | 2 +- frp_deploy.sh | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index eac0ffe..aadfecc 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # deploy Deploy scripts for frp. Usage: -> bash < ( curl -s -L https://github.com/gofrp/deploy/raw/master/frp_deploy.sh ) +> bash <( curl -s -L https://github.com/gofrp/deploy/raw/master/frp_deploy.sh ) diff --git a/frp_deploy.sh b/frp_deploy.sh index f4832b4..ae24c4b 100755 --- a/frp_deploy.sh +++ b/frp_deploy.sh @@ -1,5 +1,11 @@ #!/bin/bash +#Check if git is installed. +type git +if [ $? != 0 ]; then +echo "git is required for installation, exit." +exit 1 +fi #Set flags for hot update. frps_FLAG=`ps -ef |grep -w frps|grep -v grep|wc -l` @@ -53,9 +59,9 @@ cd /tmp echo "Unpacking......" tar xzf frp_${FRP_VERSION}_linux_${ARCH}.tar.gz echo "Installing binary files......" - cp ./frp_${FRP_VERSION}_linux_${ARCH}/frps /usr/bin && chmod +x /usr/bin/frps - cp ./frp_${FRP_VERSION}_linux_${ARCH}/frpc /usr/bin && chmod +x /usr/bin/frpc - setcap cap_net_bind_service=ep /usr/bin/frps #Give frps binary access to well-known ports(smbd,NetBIOS,etc). + 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). 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 ."