diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh new file mode 100644 index 0000000..8777d7a --- /dev/null +++ b/.github/workflows/updater.sh @@ -0,0 +1,139 @@ +#!/bin/bash + +#================================================= +# PACKAGE UPDATING HELPER +#================================================= + +# This script is meant to be run by GitHub Actions +# The YunoHost-Apps organisation offers a template Action to run this script periodically +# Since each app is different, maintainers can adapt its contents so as to perform +# automatic actions when a new upstream release is detected. + +#================================================= +# FETCHING LATEST RELEASE AND ITS ASSETS +#================================================= + +# Fetching information +current_version=$(cat manifest.json | jq -j '.version|split("~")[0]') +repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]') +# Some jq magic is needed, because the latest upstream release is not always the latest version (e.g. security patches for older versions) +version=$(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '.[] | select( .prerelease != true ) | .tag_name' | sort -V | tail -1) +assets=($(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '[ .[] | select(.tag_name=="'$version'").assets[].browser_download_url ] | join(" ") | @sh' | tr -d "'")) + +# Later down the script, we assume the version has only digits and dots +# Sometimes the release name starts with a "v", so let's filter it out. +# You may need more tweaks here if the upstream repository has different naming conventions. +if [[ ${version:0:1} == "v" || ${version:0:1} == "V" ]]; then + version=${version:1} +fi + +# Setting up the environment variables +echo "Current version: $current_version" +echo "Latest release from upstream: $version" +echo "VERSION=$version" >> $GITHUB_ENV +# For the time being, let's assume the script will fail +echo "PROCEED=false" >> $GITHUB_ENV + +# Proceed only if the retrieved version is greater than the current one +if ! dpkg --compare-versions "$current_version" "lt" "$version" ; then + echo "::warning ::No new version available" + exit 0 +# Proceed only if a PR for this new version does not already exist +elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-v$version ; then + echo "::warning ::A branch already exists for this update" + exit 0 +fi + +# Each release can hold multiple assets (e.g. binaries for different architectures, source code, etc.) +echo "${#assets[@]} available asset(s)" + +#================================================= +# UPDATE SOURCE FILES +#================================================= + +# Here we use the $assets variable to get the resources published in the upstream release. +# Here is an example for Grav, it has to be adapted in accordance with how the upstream releases look like. + +# Let's loop over the array of assets URLs +for asset_url in ${assets[@]}; do + +echo "Handling asset at $asset_url" + +# Assign the asset to a source file in conf/ directory +# Here we base the source file name upon a unique keyword in the assets url (admin vs. update) +# Leave $src empty to ignore the asset +case $asset_url in + *"linux-amd64.tar.gz") + src="amd64" + ;; + *"linux-arm64.tar.gz") + src="arm64" + ;; + *"linux-arm.tar.gz") + src="armhf" + ;; + *"linux-386.tar.gz") + src="i386" + ;; + *) + src="" + ;; +esac + +# If $src is not empty, let's process the asset +if [ ! -z "$src" ]; then + +# Create the temporary directory +tempdir="$(mktemp -d)" + +# Download sources and calculate checksum +filename=${asset_url##*/} +curl --silent -4 -L $asset_url -o "$tempdir/$filename" +checksum=$(sha256sum "$tempdir/$filename" | head -c 64) + +# Delete temporary directory +rm -rf $tempdir + +# Get extension +if [[ $filename == *.tar.gz ]]; then + extension=tar.gz +else + extension=${filename##*.} +fi + +# Rewrite source file +cat < conf/$src.src +SOURCE_URL=$asset_url +SOURCE_SUM=$checksum +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=$extension +SOURCE_IN_SUBDIR=false +SOURCE_FILENAME= +EOT +echo "... conf/$src.src updated" + +else +echo "... asset ignored" +fi + +done + +#================================================= +# SPECIFIC UPDATE STEPS +#================================================= + +# Any action on the app's source code can be done. +# The GitHub Action workflow takes care of committing all changes after this script ends. + +#================================================= +# GENERIC FINALIZATION +#================================================= + +# Replace new version in manifest +echo "$(jq -s --indent 4 ".[] | .version = \"$version~ynh1\"" manifest.json)" > manifest.json + +# No need to update the README, yunohost-bot takes care of it + +# The Action will proceed only if the PROCEED environment variable is set to true +echo "PROCEED=true" >> $GITHUB_ENV +exit 0 diff --git a/README.md b/README.md index 4a134fe..1710f1d 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in WireGuard® is fast and modern VPN that utilizes state-of-the-art cryptography. It aims to be faster, simpler, leaner, and more useful than IPsec. It intends to be considerably more performant than OpenVPN. WireGuard is designed as a general purpose VPN. -**Shipped version:** 0.3.2~ynh2 +**Shipped version:** 0.3.6~ynh1 diff --git a/README_fr.md b/README_fr.md index 02e5506..caabf52 100644 --- a/README_fr.md +++ b/README_fr.md @@ -13,7 +13,7 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour WireGuard® is fast and modern VPN that utilizes state-of-the-art cryptography. It aims to be faster, simpler, leaner, and more useful than IPsec. It intends to be considerably more performant than OpenVPN. WireGuard is designed as a general purpose VPN. -**Version incluse :** 0.3.2~ynh2 +**Version incluse :** 0.3.6~ynh1 diff --git a/conf/amd64.src b/conf/amd64.src index a720292..20318c7 100644 --- a/conf/amd64.src +++ b/conf/amd64.src @@ -1,5 +1,6 @@ -SOURCE_URL=https://github.com/ngoduykhanh/wireguard-ui/releases/download/v0.3.2/wireguard-ui-v0.3.2-linux-amd64.tar.gz -SOURCE_SUM=71972b81f2d2ade50484cc1501a5896c8a08cfd82297f81c1d6279d7e0ff1f35 +SOURCE_URL=https://github.com/ngoduykhanh/wireguard-ui/releases/download/v0.3.6/wireguard-ui-v0.3.6-linux-amd64.tar.gz +SOURCE_SUM=2dfd266f0e58a96d8d59757dae7405d503bd8ea0ed91d0ae061549278d1b0445 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=false +SOURCE_FILENAME= diff --git a/conf/arm64.src b/conf/arm64.src index 97638b8..4726cf8 100644 --- a/conf/arm64.src +++ b/conf/arm64.src @@ -1,5 +1,6 @@ -SOURCE_URL=https://github.com/ngoduykhanh/wireguard-ui/releases/download/v0.3.2/wireguard-ui-v0.3.2-linux-arm64.tar.gz -SOURCE_SUM=8d31fc39495f8a6480531859f225f0fee36788515532d75d9cfaaa866000f52f +SOURCE_URL=https://github.com/ngoduykhanh/wireguard-ui/releases/download/v0.3.6/wireguard-ui-v0.3.6-linux-arm64.tar.gz +SOURCE_SUM=783ab9e190c0028dfd1f58593ec30bf210691d02e4dd106ac5b0b756688ac461 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=false +SOURCE_FILENAME= diff --git a/conf/armhf.src b/conf/armhf.src index 2b32887..aad28c6 100644 --- a/conf/armhf.src +++ b/conf/armhf.src @@ -1,5 +1,6 @@ -SOURCE_URL=https://github.com/ngoduykhanh/wireguard-ui/releases/download/v0.3.2/wireguard-ui-v0.3.2-linux-arm.tar.gz -SOURCE_SUM=4632fd96c7574321031907695fbbe6535884a8006b517c7f7d3ab289fb94be5f +SOURCE_URL=https://github.com/ngoduykhanh/wireguard-ui/releases/download/v0.3.6/wireguard-ui-v0.3.6-linux-arm.tar.gz +SOURCE_SUM=37c0235e0a2c30545874e640a339adf99ac950b9e9ad7e27e3b59c1cdaec5cd1 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=false +SOURCE_FILENAME= diff --git a/conf/i386.src b/conf/i386.src index 8fb5f9a..e57919c 100644 --- a/conf/i386.src +++ b/conf/i386.src @@ -1,5 +1,6 @@ -SOURCE_URL=https://github.com/ngoduykhanh/wireguard-ui/releases/download/v0.3.2/wireguard-ui-v0.3.2-linux-386.tar.gz -SOURCE_SUM=f76fc030d54e735977236d1984a906e749abb038208f410b406a2972498e3b9e +SOURCE_URL=https://github.com/ngoduykhanh/wireguard-ui/releases/download/v0.3.6/wireguard-ui-v0.3.6-linux-386.tar.gz +SOURCE_SUM=1ad205bb884062954bac33bb700242b2f06636743e824c61821d5ed0ba16cd8c SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=false +SOURCE_FILENAME= diff --git a/conf/wireguard-ui.env b/conf/wireguard-ui.env new file mode 100644 index 0000000..f56a87f --- /dev/null +++ b/conf/wireguard-ui.env @@ -0,0 +1,8 @@ +SMTP_HOST=127.0.0.1 +SMTP_PORT=25 +SMTP_NO_TLS_CHECK=true +SMTP_AUTH_TYPE=None +EMAIL_FROM_NAME=WireGuard +EMAIL_FROM_ADDRESS=wireguard-ui@__MAIN_DOMAIN__ +BIND_ADDRESS=127.0.0.1:__PORT__ +DISABLE_LOGIN=true diff --git a/conf/wireguard_ui.service b/conf/wireguard_ui.service index a98c57f..8ac6385 100644 --- a/conf/wireguard_ui.service +++ b/conf/wireguard_ui.service @@ -7,7 +7,8 @@ Type=simple User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__/ -ExecStart=__FINALPATH__/wireguard-ui --bind-address="127.0.0.1:__PORT__" --disable-login +EnvironmentFile=__FINALPATH__/wireguard-ui.env +ExecStart=__FINALPATH__/wireguard-ui # Sandboxing options to harden security # Depending on specificities of your service/app, you may need to tweak these diff --git a/manifest.json b/manifest.json index 7b12086..c7741d8 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Web user interface to manage your WireGuard setup", "fr": "Interface utilisateur Web pour gérer votre configuration WireGuard" }, - "version": "0.3.2~ynh2", + "version": "0.3.6~ynh1", "url": "https://github.com/ngoduykhanh/wireguard-ui", "upstream": { "license": "MIT", @@ -26,7 +26,7 @@ "nginx" ], "arguments": { - "install" : [ + "install": [ { "name": "warning", "type": "display_text", diff --git a/scripts/_common.sh b/scripts/_common.sh index 990df43..283eb68 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -17,6 +17,8 @@ pkg_dependencies="$pkg_headers wireguard-dkms wireguard" interface=$(ip route | awk '/default/ { print $5 }') +main_domain=$(cat /etc/yunohost/current_host) + #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/change_url b/scripts/change_url index 1fdf39e..f77be7b 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -69,7 +69,7 @@ fi #================================================= ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped WireGuard UI" --log_path="systemd" --timeout=30 +ynh_systemd_action --service_name=wireguard_ui --action="stop" --line_match="Stopped WireGuard UI" --log_path="systemd" --timeout=30 #================================================= # MODIFY URL IN NGINX CONF @@ -113,7 +113,7 @@ fi #================================================= ynh_script_progression --message="Starting a systemd service..." --time --weight=1 -ynh_systemd_action --service_name=$app --action="start" --line_match="http server started" --log_path="systemd" --timeout=30 +ynh_systemd_action --service_name=wireguard_ui --action="start" --line_match="http server started" --log_path="systemd" --timeout=30 #================================================= # RELOAD NGINX diff --git a/scripts/install b/scripts/install index 8aa2e1f..d95861d 100644 --- a/scripts/install +++ b/scripts/install @@ -131,6 +131,9 @@ mkdir -p $final_path/db/server ynh_add_config --template="../conf/interfaces.json" --destination="$final_path/db/server/interfaces.json" ynh_delete_file_checksum --file="$final_path/db/server/interfaces.json" +# Add configuration for the Web UI +ynh_add_config --template="../conf/wireguard-ui.env" --destination="$final_path/wireguard-ui.env" + # Create WireGuard configuration directory mkdir -p /etc/wireguard diff --git a/scripts/upgrade b/scripts/upgrade index fc4b08c..480b2ac 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -129,6 +129,14 @@ then ynh_setup_source --dest_dir="$final_path" --source_id="$architecture" fi +#================================================= +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Updating a configuration file..." --weight=1 + +# Update configuration for the Web UI +ynh_add_config --template="../conf/wireguard-ui.env" --destination="$final_path/wireguard-ui.env" + #================================================= # NGINX CONFIGURATION #=================================================