Skip to content

Commit

Permalink
v9.9
Browse files Browse the repository at this point in the history
- DietPi-Software | frp: Inform about new toml config file and leave old ini as backup in place. Do not offer client inputs, if the config exists already (and is hence not generated anyway). Allow an empty token input, which is generally possible. Allow unattended installs, using both server and client as default, and applying default values to all inputs and menus.
- DietPi-Globals | G_WHIP: Return default value for inputbox, checkbox and menu, if not interactive, but keep returning error code, so that it can be handled in parent script. Minor coding enhancements.
- CI | DietPi-Software: Enable frp checks now that it can be installed unattended
  • Loading branch information
MichaIng committed Dec 1, 2024
1 parent 619aa32 commit 90d871b
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dietpi-software.bash
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ Process_Software()
167) (( $arch < 3 )) || aSERVICES[i]='raspotify';; # 32-bit ARM fails with: "arm-binfmt-P: /usr/bin/librespot: Unable to find a guest_base to satisfy all guest address mapping requirements"
#169) aSERVICES[i]='voice-recognizer';; "RuntimeError: This module can only be run on a Raspberry Pi!"
170) aCOMMANDS[i]='unrar -V';;
#171) aSERVICES[i]='frps frpc' aTCP[i]='7000 7400 7500';; Interactive install with service and ports depending on server/client/both choice
171) aSERVICES[i]='frps frpc' aTCP[i]='7000 7400 7500';;
172) aSERVICES[i]='wg-quick@wg0' aUDP[i]='51820';;
174) aCOMMANDS[i]='gimp -v';;
176) aSERVICES[i]='mycroft';;
Expand Down
76 changes: 52 additions & 24 deletions dietpi/dietpi-software
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,6 @@ Available commands:
aSOFTWARE_DESC[$software_id]='reverse proxy'
aSOFTWARE_CATX[$software_id]=16
aSOFTWARE_DOCS[$software_id]='https://dietpi.com/docs/software/advanced_networking/#frp'
aSOFTWARE_INTERACTIVE[$software_id]=1

# Home Automation
#--------------------------------------------------------------------------------
Expand Down Expand Up @@ -6538,18 +6537,16 @@ _EOF_

G_EXEC cd frp_*

local choice_required=
while :
do
G_WHIP_MENU_ARRAY=(
'Server' ': Use this machine as a server, with a public IP'
'Client' ': Use this machine as a client, without a public IP'
'Both' ': Run the reverse proxy only on this machine'
)
# Mode choice
G_WHIP_MENU_ARRAY=(
'Server' ': Use this machine as a server, with a public IP'
'Client' ': Use this machine as a client, without a public IP'
'Both' ': Run the reverse proxy only on this machine'
)

G_WHIP_MENU "${choice_required}Please choose how you are going to run frp." && break
choice_required='[ERROR] A choice is required to finish the frp install.\n\n'
done
G_WHIP_NOCANCEL=1
G_WHIP_DEFAULT_ITEM='Both'
G_WHIP_MENU 'Please choose how you are going to run frp:'
local mode=$G_WHIP_RETURNED_VALUE

G_EXEC mkdir -p /etc/frp
Expand Down Expand Up @@ -6577,6 +6574,18 @@ RestartSec=5s
[Install]
WantedBy=multi-user.target
_EOF_
# Pre-v9.9: Inform about config file migration
if [[ -f '/etc/frp/frps.ini' ]]
then
G_WHIP_MSG '[WARNING] New toml config file will be generated
\nfrp deprecated the ini format for its config files, hence /etc/frp/frps.toml will be generated and used from now on.
\nAn automated conversion is not possible and hence need to be done manually, if you did changes. A backup of the ini config it kept in place:
- /etc/frp/frps.ini.bak
\nA full overview of all config keys can be found here:
- https://github.com/fatedier/frp/blob/dev/conf/frps_full_example.toml'
G_EXEC mv /etc/frp/frps.ini{,.bak}
fi

# Pre-create config file to turn on dashboard
token=$(openssl rand -hex 15)
[[ -f '/etc/frp/frps.toml' ]] || cat << _EOF_ > /etc/frp/frps.toml
Expand Down Expand Up @@ -6617,22 +6626,39 @@ RestartSec=5s
[Install]
WantedBy=multi-user.target
_EOF_
local server_addr='127.0.0.1' server_port=7000
if [[ $G_WHIP_RETURNED_VALUE == 'Client' ]]
# Pre-v9.9: Inform about config file migration
if [[ -f '/etc/frp/frpc.ini' ]]
then
G_WHIP_DEFAULT_ITEM="$server_addr:$server_port"
G_WHIP_INPUTBOX_REGEX='^[0-9.:]+$'
G_WHIP_INPUTBOX_REGEX_TEXT='be a valid IP address, optionally with appended network port number, like "192.168.1.100:7000"'
G_WHIP_INPUTBOX 'Please enter the IP address of your frp server, optionally including port (default 7000):'
server_addr=${G_WHIP_RETURNED_VALUE%:*}
[[ $G_WHIP_RETURNED_VALUE =~ : ]] && server_port=${G_WHIP_RETURNED_VALUE##*:}

G_WHIP_INPUTBOX 'Please enter the authentication token of your frp server:'
token=$G_WHIP_RETURNED_VALUE
G_WHIP_MSG '[WARNING] New toml config file will be generated
\nfrp deprecated the ini format for its config files, hence /etc/frp/frpc.toml will be generated and used from now on.
\nAn automated conversion is not possible and hence need to be done manually, if you did changes. A backup of the ini config it kept in place:
- /etc/frp/frpc.ini.bak
\nA full overview of all config keys can be found here:
- https://github.com/fatedier/frp/blob/dev/conf/frpc_full_example.toml'
G_EXEC mv /etc/frp/frpc.ini{,.bak}
fi

# Pre-create config file to turn on admin UI
[[ -f '/etc/frp/frpc.toml' ]] || cat << _EOF_ > /etc/frp/frpc.toml
if [[ ! -f '/etc/frp/frpc.toml' ]]
then
local server_addr='127.0.0.1' server_port=7000
if [[ $G_WHIP_RETURNED_VALUE == 'Client' ]]
then
G_WHIP_NOCANCEL=1
G_WHIP_DEFAULT_ITEM="$server_addr:$server_port"
G_WHIP_INPUTBOX_REGEX='^[0-9.:]+$'
G_WHIP_INPUTBOX_REGEX_TEXT='be a valid IP address, optionally with appended network port number, like "192.168.1.100:7000"'
G_WHIP_INPUTBOX 'Please enter the IP address of your frp server, optionally including port (default 7000):'
server_addr=${G_WHIP_RETURNED_VALUE%:*}
[[ $G_WHIP_RETURNED_VALUE =~ : ]] && server_port=${G_WHIP_RETURNED_VALUE##*:}

G_WHIP_NOCANCEL=1
G_WHIP_INPUTBOX_REGEX='*'
G_WHIP_INPUTBOX 'Please enter the authentication token of your frp server:'
token=$G_WHIP_RETURNED_VALUE
fi

cat << _EOF_ > /etc/frp/frpc.toml
serverAddr = "$server_addr"
serverPort = $server_port

Expand All @@ -6644,6 +6670,8 @@ webServer.password = "$GLOBAL_PW"
auth.method = "token"
auth.token = "$token"
_EOF_
fi

G_EXEC chmod 0660 /etc/frp/frpc.toml
G_EXEC chown root:frp /etc/frp/frpc.toml
aENABLE_SERVICES+=('frpc')
Expand Down
Loading

0 comments on commit 90d871b

Please sign in to comment.