[RESOLVED] WAPT package for Brave

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
SeiyaGame
Messages: 13
Registration: May 25, 2023 - 3:19 p.m.

July 7, 2023 - 10:28

Good morning,

I would like to offer you a package I designed for installing the Brave browser. Its creation was inspired by the tis-chrome package, given that the two browsers share the same foundation.

I have performed the installation, uninstallation and update of the package.

In this package, I have also integrated the ADMX files for GPOs, a feature that might interest some users.

Since I cannot upload the archive .waptI'm going to share the function code with you.

Here is the file code setup.py :

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

app_scheduled_tasks = ["BraveSoftwareUpdateTaskMachineCore", "BraveSoftwareUpdateTaskMachineUA"]
app_services = ["BraveElevationService", "brave", "bravem", "BraveVpnService"]


def install():

    # Declaring local variables
    package_version = control.version.split("-", 1)[0]
    bin_name = glob.glob("brave_installer_*.exe")[0]
    skip = False
    if isdir(makepath(programfiles32, "BraveSoftware", "Brave-Browser", "Application")):
        brave_app_path = makepath(programfiles32, "BraveSoftware", "Brave-Browser", "Application")
    else:
        brave_app_path = makepath(programfiles, "BraveSoftware", "Brave-Browser", "Application")
    brave_bin_path = makepath(brave_app_path, "brave.exe")
    app_uninstallkey = "BraveSoftware Brave-Browser"
    
    def get_version_brave():
        return get_file_properties(brave_bin_path)["ProductVersion"]

    if windows_version() < WindowsVersions.Windows10:
        
        # Uninstalling newer versions of the software
        for to_uninstall in installed_softwares(name="^Brave$"):
            
            if Version(to_uninstall["version"]) > Version(control.get_software_version()) or force:
                print("Removing: %s (%s)" % (to_uninstall["name"], to_uninstall["version"]))
                try:
                    killalltasks(control.get_impacted_process_list())
                    run(uninstall_cmd(to_uninstall["key"]))
                    wait_uninstallkey_absent(to_uninstall["key"])
                except Exception as e:
                    print(e)
                    print("Remove failed: %s (%s)\nContinuing..." % (to_uninstall["name"], to_uninstall["version"]))

    # Installing the package
    if isfile(brave_bin_path):
        if Version(get_version_brave()) >= Version(package_version):
            if uninstall_key_exists(app_uninstallkey):
                uninstallkey.append(app_uninstallkey)
            skip = True
    
    if (not skip) or force:
        print("Installing: %s" % bin_name)
        install_exe_if_needed(
            bin_name,
            silentflags="--install --silent --system-level --qn",
            key=app_uninstallkey,
            min_version=package_version,
        )

    # Disabling application scheduled tasks
    for task in get_all_scheduled_tasks():
        if task.split("{")[0] in app_scheduled_tasks:
            if task_exists(task):
                try:
                    disable_task(task)
                except:
                    print("Unable to disable the task: %s" % task)

    # Changing default start mode of the application services
    for service_name in app_services:
        set_service_start_mode(service_name, "Manual")


    # Disabling Brave Auto-Update and Reporting
    registry_setstring(HKEY_LOCAL_MACHINE, r"SOFTWARE\Policies\BraveSoftware\Brave", "ComponentUpdatesEnabled", 0, type=REG_DWORD)
    registry_setstring(HKEY_LOCAL_MACHINE, r"SOFTWARE\Policies\BraveSoftware\Brave", "MetricsReportingEnabled",  0, type=REG_DWORD)

    # # Adding master preferences file (instead, we recommend that you to create a package like tis-brave-config)
    # filecopyto("master_preferences", brave_app_path)


def uninstall():

    if isdir(makepath(programfiles32, "BraveSoftware", "Brave-Browser", "Application")):
        brave_app_path = makepath(programfiles32, "BraveSoftware", "Brave-Browser", "Application")
    else:
        brave_app_path = makepath(programfiles, "BraveSoftware", "Brave-Browser", "Application")
    brave_bin_path = makepath(brave_app_path, "brave.exe")
    app_uninstallkey = "BraveSoftware Brave-Browser"

    # Uninstalling the package
    if uninstall_key_exists(app_uninstallkey):
        if not "msiexec" in " ".join(list(uninstall_cmd(app_uninstallkey))).lower():
            versionsoft = get_file_properties(brave_bin_path)["ProductVersion"]
            run(
                '"%s" --uninstall --system-level --force-uninstall --qn'
                % makepath(install_location(app_uninstallkey), versionsoft, "Installer", "setup.exe"),
                accept_returncodes=[19],
            )

def session_setup():
    
    # Needed on Brave ??
    swreporter_path = makepath(user_local_appdata, "BraveSoftware", "Brave-Browser", "User Data", "SwReporter")
    if isdir(swreporter_path):
        print("Removing: %s" % swreporter_path)
        remove_tree(swreporter_path)

Here is the file code update_package.py :

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *
from setupdevhelpers import *
import re
import json


def update_package():
    # Declaring local variables
    result = False
    proxies = get_proxies()
    if not proxies:
        proxies = get_proxies_from_wapt_console()
    app_name = control.name

    url_api = "https://api.github.com/repos/brave/brave-browser/releases/latest"
    url_dl = "https://brave-browser-downloads.s3.brave.com/latest/brave_installer-x64.exe"

    # Getting latest informations from official Google API
    json_load = json.loads(wgets(url_api))

    tag_version = json_load['tag_name'][1:]
    chromium_version = re.search(r"Chromium (\d+(?:\.\d+)+)", json_load['name']).group(1)

    version = f"{chromium_version.split('.')[0]}.{tag_version}"
    
    latest_bin = f"brave_installer_x64_{version}.exe"

    print(f"Latest {app_name} version is: {version}")
    print(f"Download url is: {url_dl}")

    # Downloading latest binaries
    if not isfile(latest_bin):
        print("Downloading: " + latest_bin)
        wget(url_dl, latest_bin, proxies=proxies)

        # Get version from description exe
        exe_version = get_version_from_binary(latest_bin)

        if exe_version != version:
            remove_file(latest_bin)
            error("The version returned by the API and the version returned by the exe does not match")

    # Changing version of the package
    if Version(version) > control.get_software_version():
        print("Software version updated from: %s to: %s" % (control.get_software_version(), Version(version)))
        result = True
    else:
        print("Software version up-to-date (%s)" % Version(version))
    control.version = "%s-%s" % (Version(version), control.version.split("-", 1)[-1])
    # control.set_software_version(Version(version))
    control.save_control_to_wapt()

    # Deleting outdated binaries
    remove_outdated_binaries(version)

    # Validating update-package-sources
    return result
And finally, the file control :

Code: Select all

package           : loq-brave
version           : 114.1.52.129-3
architecture      : x64
section           : base
priority          : optional
name              : Brave
categories        : Internet
maintainer        : Flavien Schelfaut (Loquidy)
description       : Brave is a free and open-source web browser developed by Brave Software, Inc. It blocks ads and website trackers, and provides a way for users to send cryptocurrency contributions in the form of Basic Attention Tokens to websites and content creators
depends           : 
conflicts         : 
maturity          : PROD
locale            : all
target_os         : windows
min_wapt_version  : 2.1
sources           : https://laptop-updates.brave.com/latest/winx64
installed_size    : 684132243
impacted_process  : brave,chrome_proxy,chrome_pwa_launcher,chrmstp
description_fr    : Brave est un navigateur web gratuit et open-source développé par Brave Software, Inc. Il bloque les publicités et les traqueurs de sites web, et permet aux utilisateurs d'envoyer des contributions en crypto-monnaie sous la forme de jetons d'attention de base à des sites web et à des créateurs de contenu.
description_pl    : 
description_de    : Brave ist ein freier und quelloffener Webbrowser, der von Brave Software, Inc. entwickelt wurde. Er blockiert Werbung und Website-Tracker und bietet Nutzern die Möglichkeit, Kryptowährungsbeiträge in Form von Basic Attention Tokens an Websites und Inhaltsersteller zu senden
description_es    : Brave es un navegador web gratuito y de código abierto desarrollado por Brave Software, Inc. Bloquea los anuncios y los rastreadores de sitios web, y permite a los usuarios enviar contribuciones en criptomoneda en forma de Basic Attention Tokens a sitios web y creadores de contenidos.
description_pt    : 
description_it    : 
description_nl    : 
description_ru    : 
audit_schedule    : 
editor            : Brave Software, Inc.
keywords          : browser,navigateur,brave,chromium
licence           : MPL-2.0
homepage          : https://brave.com/
package_uuid      : 4774f883-f37e-4cba-8e8d-3843983f4836
valid_from        : 
valid_until       : 
forced_install_on : 
changelog         : https://brave.com/latest/
min_os_version    : 10.0
max_os_version    : 
icon_sha256sum    : 6795ee5386706c0b9b19fa54c995beebe9f986612b31f5ab8311afe3be34e614
signer            : loqwapt
signer_fingerprint: b4bf538731a5e9de85fe3a5014052844fe130cb54afab01cd1aaf90f284bd72e
signature         : ibLdu+pbcsnoy1DPJUd7sEOPdcIxzmBTrFb/PzzwyWndc2VVvI9UI33sX3riHA8yxsqvKfegnz3vuGSqhfHHoaOYfFkninw7zn2l0J0AwBzR6n1Elxc9Axrj/ToDL2ZGx0eJYnGRy7omgAQtEjl8e7PU4eRMTtliftpE16hb2elbtcGncmgQ10D/Jsmfwmu+JZXhVGtwDYhWs8ataFn5DD3kBSNrR7vPbsX1L7gY15hDHq9FmOhX8yJdT+ZgHq3oxQ+yR+Opzdmrq5g8C4zL3Fs/r70pbypCXLwyiEYptP0/JxfB+vl8AIjYounw2tc10SsARFl13Nvc+ckii71+5Q==
signature_date    : 2023-07-07T09:46:57.730886
signed_attributes : package,version,architecture,section,priority,name,categories,maintainer,description,depends,conflicts,maturity,locale,target_os,min_wapt_version,sources,installed_size,impacted_process,description_fr,description_pl,description_de,description_es,description_pt,description_it,description_nl,description_ru,audit_schedule,editor,keywords,licence,homepage,package_uuid,valid_from,valid_until,forced_install_on,changelog,min_os_version,max_os_version,icon_sha256sum,signer,signer_fingerprint,signature_date,signed_attributes
General information:

WAPT Server: Debian 11, version 2.4.0.14080, Enterprise Edition
Administration machine: Windows 11, WAPT version 2.4.0.14080
User avatar
jpele
Messages: 156
Registration: March 4, 2019 - 12:01
Location: Nantes

July 24, 2023 - 2:50 PM

Hi Flavien,

Thanks for sharing.
The package had been archived on our end because the binaries in the GitHub repository didn't allow us to package it.
I'm curious to know where you found the download link.
I was able to fix the remove() function; the package will be available on the Store soon :)

. Best regards,
Jimmy
Locked