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

[autopatch] Automatic patch attempt for helpers 2.1 #191

Draft
wants to merge 3 commits into
base: testing
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ multi_instance = false
ram.build = "200M"
ram.runtime = "200M"
sso = false
yunohost = ">= 11.2"
yunohost = ">= 11.2.18"
helpers_version = "2.1"

[install]
[install.domain]
Expand Down
28 changes: 9 additions & 19 deletions scripts/_common.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/bin/bash

#=================================================
# COMMON VARIABLES
#=================================================

#=================================================
# PERSONAL HELPERS
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================

get_network_interface(){
Expand All @@ -18,7 +14,8 @@ get_network_interface(){
# shellcheck disable=SC2005
echo "$(echo "$(ip -4 route get 1.2.3.4 2> /dev/null)" | head -n1 | grep -oP '(?<=dev )\w+' || true)"
else
# shellcheck disable=SC2005
# shellcheck disable=SC2005

echo "$(echo "$(ip -6 route get ::1.2.3.4 2> /dev/null)" | head -n1 | grep -oP '(?<=dev )\w+' || true)"
fi
}
Expand All @@ -30,7 +27,7 @@ configure_network_interface_dnsmasq(){
local ipv6_interface="$2"

if [ -z "$ipv4_interface" ] && [ -z "$ipv6_interface" ]; then
ynh_die --message="Impossible to find the main network interface, please report this issue."
ynh_die "Impossible to find the main network interface, please report this issue."
elif [ "$ipv4_interface" != "$ipv6_interface" ]; then
if [ -z "$ipv4_interface" ]; then
echo -e "bind-interfaces\nexcept-interface=$ipv6_interface" > "/etc/dnsmasq.d/$app"
Expand All @@ -45,7 +42,7 @@ configure_network_interface_dnsmasq(){

systemctl restart dnsmasq

ynh_store_file_checksum --file="/etc/dnsmasq.d/$app"
ynh_store_file_checksum "/etc/dnsmasq.d/$app"
}

is_public_ip(){
Expand Down Expand Up @@ -79,7 +76,7 @@ process_ips(){
# for each IP
for ip in $ips; do
# check if the so-called IP really is one
if ynh_validate_ip4 --ip_address="$ip" || ynh_validate_ip6 --ip_address="$ip"; then
if ynh_validate_ip --family=4 --ip_address="$ip" || ynh_validate_ip6 --ip_address="$ip"; then
# we can't use IPv6 LLA for DNS: https://github.com/AdguardTeam/AdGuardHome/issues/2926#issuecomment-1284489380
# if we try to bind port 53 on a fe80:: address, AGH crashes
if ! [[ "$ip" =~ ^fe80:* ]]; then
Expand All @@ -105,11 +102,12 @@ if [ -z "${ipv4_addr:-}" ] && [ -z "${ipv6_addr:-}" ]; then
if [ -z "${expose_port_53:-}" ] || [[ "$expose_port_53" = "false" ]]; then
# if the variable 'expose_port_53' is unset or false, maybe the machine
# doesn't have any private IP? User guidance is relevant...
ynh_die --message="At leat one IP adress is required to run AdGuard Home. Please report this error.
ynh_die "At leat one IP adress is required to run AdGuard Home. Please report this error.

(You can refer to [the troubleshooting page](https://github.com/YunoHost-Apps/adguardhome_ynh/blob/master/doc/TROUBLESHOOTING.md) to get help)"
else
# else, do not show the message under parenthesis, because it's irrelevant
ynh_die --message="At leat one IP adress is required to run AdGuard Home. Please report this error."
ynh_die "At leat one IP adress is required to run AdGuard Home. Please report this error."
fi
fi

Expand All @@ -132,11 +130,3 @@ with open(\"$install_dir/AdGuardHome.yaml\", 'w') as file:
yaml.dump(conf_file, file)
"
}

#=================================================
# EXPERIMENTAL HELPERS
#=================================================

#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
22 changes: 6 additions & 16 deletions scripts/backup
Original file line number Diff line number Diff line change
@@ -1,48 +1,38 @@
#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers

#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================

ynh_print_info --message="Declaring files to be backed up..."
ynh_print_info "Declaring files to be backed up..."

#=================================================
# BACKUP THE APP MAIN DIR
#=================================================

ynh_backup --src_path="$install_dir"
ynh_backup "$install_dir"

#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================

ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"

#=================================================
# BACKUP SYSTEMD
#=================================================

ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup "/etc/systemd/system/$app.service"

#=================================================
# BACKUP VARIOUS FILES
#=================================================

# backup the kernel config file for DoQ
ynh_backup --src_path="/etc/sysctl.d/10-adguardhome.conf"
ynh_backup "/etc/sysctl.d/10-adguardhome.conf"

#=================================================
# END OF SCRIPT
#=================================================

ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
26 changes: 8 additions & 18 deletions scripts/change_url
Original file line number Diff line number Diff line change
@@ -1,50 +1,40 @@
#!/bin/bash

#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_script_progression "Stopping $app's systemd service..."

ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd"
ynh_systemctl --service="$app" --action="stop" --log_path="systemd"

#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
ynh_script_progression "Updating NGINX web server configuration..."

ynh_change_url_nginx_config
ynh_config_change_url_nginx

#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring permissions..."
ynh_script_progression "Configuring permissions..."

# Temporary fix for the API permission (workaround for https://github.com/YunoHost/issues/issues/2294 )
ynh_permission_url --permission="api" --url="re:$new_domain\/control" --auth_header="false" --clear_urls
ynh_permission_url --permission="doh" --url="re:$new_domain\/dns-query" --auth_header="false" --clear_urls

#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."

ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd"
ynh_systemctl --service="$app" --action="start" --log_path="systemd"

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Change of URL completed for $app" --last
ynh_script_progression "Change of URL completed for $app"
46 changes: 19 additions & 27 deletions scripts/config
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#!/bin/bash

#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

ynh_abort_if_errors
#REMOVEME? ynh_abort_if_errors

# import needed settings
port_dns_over_tls=$(ynh_app_setting_get --app="$app" --key=port_dns_over_tls)
port_dns_over_quic=$(ynh_app_setting_get --app="$app" --key=port_dns_over_quic)
port_dns_over_tls=$(ynh_app_setting_get --key=port_dns_over_tls)
port_dns_over_quic=$(ynh_app_setting_get --key=port_dns_over_quic)

#=================================================
# SPECIFIC SETTERS
Expand All @@ -23,7 +17,7 @@ set__expose_port_53() {

# regenerate config, needed to add or delete public IPs following the user's choice

ynh_print_info --message="Obtaining IP addresses for the AGH config file..."
ynh_print_info "Obtaining IP addresses for the AGH config file..."

# get the name of the network interface in IPv4 and IPv6
ipv4_interface="$(get_network_interface 4)"
Expand All @@ -37,11 +31,11 @@ set__expose_port_53() {
ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")

# update the IP adresses in the AGH config file
ynh_print_info --message="Updating the AGH config file..."
ynh_print_info "Updating the AGH config file..."
update_agh_ip_config

# declare needs_exposed_ports according to real user need
ynh_print_info --message="Updating the YunoHost service for AdGuard Home..."
ynh_print_info "Updating the YunoHost service for AdGuard Home..."
if [ "$dns_over_https" == "true" ] && [ "$expose_port_53" == "true" ]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_tls"
elif [ "$dns_over_https" == "true" ]; then
Expand All @@ -53,28 +47,28 @@ set__expose_port_53() {
fi

# save the new setting
ynh_app_setting_set --app="$app" --key=expose_port_53 --value="$expose_port_53"
ynh_app_setting_set --key=expose_port_53 --value="$expose_port_53"
}

set__dns_over_https() {

if [ "$dns_over_https" == "true" ]; then
ynh_print_info --message="Opening DoH and DoQ ports..."
ynh_print_info "Opening DoH and DoQ ports..."
# if DNS over HTTPS/QUIC is activated, open the associated ports
ynh_exec_warn_less yunohost firewall allow Both "$port_dns_over_tls" --no-reload
ynh_exec_warn_less yunohost firewall allow UDP "$port_dns_over_quic"
ynh_hide_warnings yunohost firewall allow Both "$port_dns_over_tls" --no-reload
ynh_hide_warnings yunohost firewall allow UDP "$port_dns_over_quic"
elif [ "$dns_over_https" == "false" ]; then
# else if false, close them
ynh_print_info --message="Closing DoH and DoQ ports..."
ynh_exec_warn_less yunohost firewall disallow Both "$port_dns_over_tls" --no-reload
ynh_exec_warn_less yunohost firewall disallow UDP "$port_dns_over_quic"
ynh_print_info "Closing DoH and DoQ ports..."
ynh_hide_warnings yunohost firewall disallow Both "$port_dns_over_tls" --no-reload
ynh_hide_warnings yunohost firewall disallow UDP "$port_dns_over_quic"
else
# else, throw error
ynh_print_warn --message="The variable 'dns_over_https' should be 'true' or 'false' but isn't, please report this."
ynh_print_warn "The variable 'dns_over_https' should be 'true' or 'false' but isn't, please report this."
fi

# declare needs_exposed_ports according to real user need
ynh_print_info --message="Updating the YunoHost service for AdGuard Home..."
ynh_print_info "Updating the YunoHost service for AdGuard Home..."
if [ "$dns_over_https" == "true" ] && [ "$expose_port_53" == "true" ]; then
yunohost service add "$app" --description="Ads & trackers blocking DNS server" --needs_exposed_ports "53" "$port_dns_over_tls"
elif [ "$dns_over_https" == "true" ]; then
Expand All @@ -89,23 +83,21 @@ set__dns_over_https() {
ynh_write_var_in_file --file="$install_dir/AdGuardHome.yaml" --key="enabled" --after="tls:" --value="$dns_over_https"

# save the new setting in YNH
ynh_app_setting_set --app="$app" --key=dns_over_https --value="$dns_over_https"
ynh_app_setting_set --key=dns_over_https --value="$dns_over_https"
}

set__new_password() {

# user's password encryption
ynh_print_info --message="Encrypting the new password..."
ynh_print_info "Encrypting the new password..."
password=$(python3 -c "import bcrypt; print(bcrypt.hashpw(b\"$new_password\", bcrypt.gensalt(rounds=10)).decode())")
ynh_app_setting_set --app="$app" --key=password --value="$password"
ynh_app_setting_set --key=password --value="$password"

# save the new setting in the AGH config file
ynh_print_info --message="Saving the new password in the AGH configuration..."
ynh_print_info "Saving the new password in the AGH configuration..."
ynh_write_var_in_file --file="$install_dir/AdGuardHome.yaml" --key="password" --value="$password"
}

#=================================================
# GENERIC FINALIZATION
#=================================================

ynh_app_config_run "$1"
Loading