Skip to content

Commit

Permalink
Merge pull request #112 from mvscode/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mvscode authored Jun 26, 2024
2 parents f324a3e + 07be762 commit b68b0d1
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 77 deletions.
59 changes: 38 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,43 @@ Usage: /etc/init.d/frps {start|stop|restart|status|config|version}

## Script ChangeLog
---------------------------------------
### [1.0.1] - 2024-06-07
### [1.0.6] - 2024-06-25

#### Added
* Add new server os to support, RHEL,Rocky,AlmaLinux OS.

* Add new server os on frps.init file

#### Fixed
* fix check server os version script bug

### [1.0.5] - 2024-06-19

#### Added
* Add quic of transport protocol support,server port default same as https port.

* Add user-defined functions for the kcp bind port,server port default same as bind port.

#### Fixed
* Fix the script under frps server start faild still install complete bug.

### [1.0.4] - 2024-06-18

#### Updated
* Add trace option at log level, default is info

* Update shell update function, ask the user if they want to update

#### New
* frps support transport heartbeatTimeout = 90, default is enable

### [1.0.3] - 2024-06-16

#### Amendment
* Amend function name to frps

#### Changed
* frps program config file change to frps.toml from frps.int
* Change curl common to get server ip from wget common

### [1.0.2] - 2024-06-13

Expand All @@ -68,34 +101,18 @@ Usage: /etc/init.d/frps {start|stop|restart|status|config|version}
etc..
```

### [1.0.3] - 2024-06-16

#### Amendment
* Amend function name to frps
### [1.0.1] - 2024-06-07

#### Changed
* Change curl common to get server ip from wget common


### [1.0.4] - 2024-06-18
* frps program config file change to frps.toml from frps.int

#### Updated
* Add trace option at log level, default is info

* Update shell update function, ask the user if they want to update

#### New
* frps support transport heartbeatTimeout = 90, default is enable

### [1.0.5] - 2024-06-19

#### ADDED
* Add quic of transport protocol support,server port default same as https port.

* Add user-defined functions for the kcp bind port,server port default same as bind port.

#### Fixed
* Fix the script under frps server start faild still install complete bug.




30 changes: 17 additions & 13 deletions frps.init
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
ProgramName="Frps"
ProgramName="frps"
ProgramPath="/usr/local/frps"
NAME=frps
BIN=${ProgramPath}/${NAME}
CONFIGFILE=${ProgramPath}/frps.toml
SCRIPTNAME=/etc/init.d/${NAME}
version="2023"
version="2024"
program_version=`${BIN} --version`
RET_VAL=0

[ -x ${BIN} ] || exit 0
strLog=""
fun_clangcn()
fun_frps()
{
echo ""
echo "+---------------------------------------------------------+"
Expand All @@ -57,7 +57,7 @@ fun_load_config(){
fun_start()
{
if [ "${arg1}" = "start" ]; then
fun_clangcn
fun_frps
fi
if fun_check_run; then
echo "${ProgramName} (pid $PID) already running."
Expand All @@ -78,7 +78,7 @@ fun_start()

fun_stop(){
if [ "${arg1}" = "stop" ] || [ "${arg1}" = "restart" ]; then
fun_clangcn
fun_frps
fi
if fun_check_run; then
echo -n "Stoping ${ProgramName} (pid $PID)... "
Expand Down Expand Up @@ -108,19 +108,23 @@ fun_status(){
fi
}
checkos(){
if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
OS=CentOS
elif grep -Eqi "Red Hat Enterprise Linux" /etc/issue || grep -Eq "Red Hat Enterprise Linux" /etc/*-release; then
OS=RHEL
elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then
OS=Fedora
elif grep -Eqi "Rocky" /etc/issue || grep -Eq "Rocky" /etc/*-release; then
OS=Rocky
elif grep -Eqi "AlmaLinux" /etc/issue || grep -Eq "AlmaLinux" /etc/*-release; then
OS=AlmaLinux
elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then
OS=Debian
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then
OS=Ubuntu
elif grep -Eqi "Alpine" /etc/issue || grep -Eq "Alpine" /etc/*-release; then
OS=Alpine
elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then
OS=Fedora
else
echo "Not support OS, Please reinstall OS and retry!"
return 1
echo "Unsupported OS. Please use a supported Linux distribution and retry!"
exit 1
fi
}
fun_config(){
Expand Down Expand Up @@ -156,7 +160,7 @@ case "${arg1}" in
fun_help
;;
*)
fun_clangcn
fun_frps
echo "Usage: $SCRIPTNAME {start|stop|restart|status|config|version}"
RET_VAL=1
;;
Expand Down
105 changes: 62 additions & 43 deletions install-frps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export github_latest_version_api="https://api.github.com/repos/fatedier/frp/rele

# Program information
program_name="frps"
version="1.0.5"
version="1.0.6"
str_program_dir="/usr/local/${program_name}"
program_init="/etc/init.d/${program_name}"
program_config_file="frps.toml"
Expand Down Expand Up @@ -81,7 +81,7 @@ fun_frps(){
fi
echo ""
echo "+------------------------------------------------------------+"
echo "| frps for Linux Server, Author ClangMender MvsCode |"
echo "| frps for Linux Server, Author Clang, Mender MvsCode |"
echo "| A tool to auto-compile & install frps on Linux |"
echo "+------------------------------------------------------------+"
echo ""
Expand Down Expand Up @@ -113,38 +113,55 @@ get_char(){
stty echo
stty $SAVEDSTTY
}
# Check OS
# Check Server OS
checkos(){
if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
OS=CentOS
elif grep -Eqi "Red Hat Enterprise Linux" /etc/issue || grep -Eq "Red Hat Enterprise Linux" /etc/*-release; then
OS=RHEL
elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then
OS=Fedora
elif grep -Eqi "Rocky" /etc/issue || grep -Eq "Rocky" /etc/*-release; then
OS=Rocky
elif grep -Eqi "AlmaLinux" /etc/issue || grep -Eq "AlmaLinux" /etc/*-release; then
OS=AlmaLinux
elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then
OS=Debian
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then
OS=Ubuntu
elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then
OS=Fedora
else
echo "Not support OS, Please reinstall OS and retry!"
echo "Unsupported OS. Please use a supported Linux distribution and retry!"
exit 1
fi
}
# Get version
getversion(){
if [[ -s /etc/redhat-release ]];then
grep -oE "[0-9.]+" /etc/redhat-release
local version
if [[ -f /etc/os-release ]]; then
source /etc/os-release
version="$VERSION_ID"
elif [[ -f /etc/redhat-release ]]; then
version=$(grep -oE "[0-9.]+" /etc/redhat-release)
else
version=$(grep -oE "[0-9.]+" /etc/issue)
fi

if [[ -z "$version" ]]; then
echo "Unable to determine version" >&2
return 1
else
grep -oE "[0-9.]+" /etc/issue
echo "$version"
fi
}
# CentOS version
centosversion(){
local code=$1
local version="`getversion`"
local main_ver=${version%%.*}
if [ $main_ver == $code ];then
return 0
# Check server os version
check_os_version(){
local required_version=$1
local current_version=$(getversion)

if [[ "$(echo -e "$current_version\n$required_version" | sort -V | head -n1)" == "$required_version" ]]; then
return 0 # when current version > required version
else
return 1
return 1 # when current version < required version
fi
}
# Check OS bit
Expand All @@ -165,12 +182,6 @@ check_os_bit() {
*) echo "Unknown architecture";;
esac
}
check_centosversion(){
if centosversion 5; then
echo "Not support CentOS 5.x, please change to CentOS 6,7 or Debian or Ubuntu or Fedora and try again."
exit 1
fi
}
# Disable selinux
disable_selinux(){
if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
Expand Down Expand Up @@ -413,26 +424,30 @@ fun_input_quic_bind_port(){
pre_install_frps(){
fun_frps
echo -e "Check your server setting, please wait..."
echo ""
disable_selinux

# Check if the frps service is already running
if pgrep -x "${program_name}" >/dev/null; then
echo -e "${COLOR_GREEN}${program_name} is already installed and running.${COLOR_END}"
else
echo -e "${COLOR_YELLOW}${program_name} is not running or not install.${COLOR_END}"
echo -e "${COLOR_YELOW}${program_name} is not running or not install.${COLOR_END}"
echo ""
read -p "Do you want to re-install ${program_name}? (y/n) " choice
echo ""
case "$choice" in
y|Y)
echo "Re-installing ${program_name}..."
install_frps
echo -e "${COLOR_GREEN} Re-installing ${program_name}...${COLOR_END}"
;;
n|N)
echo "Skipping installation."
echo -e "${COLOR_YELOW} Skipping installation.${COLOR_END}"
echo ""
exit 1
;;
*)
echo "Invalid choice. Skipping installation."
echo -e "${COLOR_YELOW}Invalid choice. Skipping installation. ${COLOR_END}"
echo ""
exit 1
;;
esac
clear
Expand Down Expand Up @@ -481,15 +496,15 @@ else
[ -n "${input_number}" ] && set_max_pool_count="${input_number}"
echo -e "${program_name} max_pool_count: ${COLOR_YELOW}${set_max_pool_count}${COLOR_END}"
echo -e ""
echo -e "Please select ${COLOR_GREEN}log_level${COLOR_END}"
echo "1: info (default)"
echo "2: warn"
echo "3: error"
echo "4: debug"
echo "5: trace"
echo "-------------------------"
read -e -p "Enter your choice (1, 2, 3, 4, 5 or exit. default [1]): " str_log_level
case "${str_log_level}" in
echo -e "Please select ${COLOR_GREEN}log_level${COLOR_END}"
echo "1: info (default)"
echo "2: warn"
echo "3: error"
echo "4: debug"
echo "5: trace"
echo "-------------------------"
read -e -p "Enter your choice (1, 2, 3, 4, 5 or exit. default [1]): " str_log_level
case "${str_log_level}" in
1|[Ii][Nn][Ff][Oo])
str_log_level="info"
;;
Expand Down Expand Up @@ -613,7 +628,7 @@ else
echo -e "Dashboard password : ${COLOR_GREEN}${set_dashboard_pwd}${COLOR_END}"
echo -e "token : ${COLOR_GREEN}${set_token}${COLOR_END}"
echo -e "subdomain_host : ${COLOR_GREEN}${set_subdomain_host}${COLOR_END}"
echo -e "tcp_mux : ${COLOR_GREEN}${set_tcp_mux}${COLOR_END}"
echo -e "tcp mux : ${COLOR_GREEN}${set_tcp_mux}${COLOR_END}"
echo -e "Max Pool count : ${COLOR_GREEN}${set_max_pool_count}${COLOR_END}"
echo -e "Log level : ${COLOR_GREEN}${str_log_level}${COLOR_END}"
echo -e "Log max days : ${COLOR_GREEN}${set_log_max_days}${COLOR_END}"
Expand Down Expand Up @@ -789,16 +804,20 @@ EOF
echo " done"

echo -n "setting ${program_name} boot..."

[ ! -x ${program_init} ] && chmod +x ${program_init}

if [ "${OS}" == 'CentOS' ]; then
chmod +x ${program_init}
chkconfig --add ${program_name}
else
chmod +x ${program_init}
update-rc.d -f ${program_name} defaults
fi

echo " done"
[ -s ${program_init} ] && ln -s ${program_init} /usr/bin/${program_name}

[ -s ${program_init} ] && ln -sf ${program_init} /usr/bin/${program_name}

# Start the frps service
${program_init} start
Expand Down Expand Up @@ -842,7 +861,7 @@ fi
echo -e "vhost https port : ${COLOR_GREEN}${set_vhost_https_port}${COLOR_END}"
echo -e "token : ${COLOR_GREEN}${set_token}${COLOR_END}"
echo -e "subdomain_host : ${COLOR_GREEN}${set_subdomain_host}${COLOR_END}"
echo -e "tcp_mux : ${COLOR_GREEN}${set_tcp_mux}${COLOR_END}"
echo -e "tcp mux : ${COLOR_GREEN}${set_tcp_mux}${COLOR_END}"
echo -e "Max Pool count : ${COLOR_GREEN}${set_max_pool_count}${COLOR_END}"
echo -e "Log level : ${COLOR_GREEN}${str_log_level}${COLOR_END}"
echo -e "Log max days : ${COLOR_GREEN}${set_log_max_days}${COLOR_END}"
Expand Down Expand Up @@ -1015,7 +1034,7 @@ update_program_server_frps() {
echo "============== Update $program_name =============="
update_config_frps
checkos
check_centosversion
check_os_version
check_os_bit
fun_getVer

Expand Down Expand Up @@ -1077,7 +1096,7 @@ strPath=$(pwd)
rootness
fun_set_text_color
checkos
check_centosversion
check_os_version
check_os_bit
pre_install_packs
shell_update
Expand Down

0 comments on commit b68b0d1

Please sign in to comment.