[RESOLU] Paquet WAPT pour Brave

Questions about WAPT Packaging / Requêtes et aides autour des paquets Wapt.
Règles du forum
Règles du forum communautaire
* English support on www.reddit.com/r/wapt
* Le support communautaire en français se fait sur ce forum
* Merci de préfixer le titre du topic par [RESOLU] s'il est résolu.
* Merci de ne pas modifier un topic qui est taggé [RESOLU]. Ouvrez un nouveau topic en référençant l'ancien
* Préciser version de WAPT installée, version complète ET numéro de build (2.2.1.11957 / 2.2.2.12337 / etc.) AINSI QUE l'édition Enterprise / Discovery
* Les versions 1.8.2 et antérieures ne sont plus maintenues. Les seules questions acceptées vis à vis de la version 1.8.2 sont liés à la mise à jour vers une version supportée (2.1, 2.2, etc.)
* Préciser OS du serveur (Linux / Windows) et version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019)
* Préciser OS de la machine d'administration/création des paquets et de la machine avec l'agent qui pose problème le cas échéant (Windows 7 / 10 / 11 / Debian 11 / etc.)
* Eviter de poser plusieurs questions lors de l'ouverture de topic, sinon il risque d'être ignorer. Si plusieurs sujet, ouvrir plusieurs topic, et de préférence les uns après les autres et pas tous en même temps (ie ne pas spammer le forum).
* Inclure directement les morceaux de code, les captures d'écran et autres images directement dans le post. Les liens vers les pastebin, les bitly et autres sites tierces seront systématiquement supprimés.
* Comme tout forum communautaire, le support est fait bénévolement par les membres. Si vous avez besoin d'un support commercial, vous pouvez contacter le service commercial Tranquil IT au 02.40.97.57.55
SeiyaGame
Messages : 12
Inscription : 25 mai 2023 - 15:19

07 juil. 2023 - 10:28

Bonjour,

Je me permets de vous proposer un paquet que j'ai conçu, destiné à l'installation du navigateur Brave. Pour sa réalisation, je me suis inspiré du paquet tis-chrome, compte tenu du fait que les deux navigateurs partagent la même base.

J'ai effectué l'installation, la désinstallation ainsi que la mise à jour du paquet.

Dans ce paquet, j'ai également intégré les fichiers ADMX pour les GPO, une fonctionnalité qui pourrait intéresser certains utilisateurs.

Comme je ne peux pas téléverser l'archive .wapt, je vais vous partager le code des fonctions.

Voici le code du fichier setup.py :

Code : Tout sélectionner

# -*- 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)

Voici le code du fichier update_package.py :

Code : Tout sélectionner

# -*- 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
Et pour finir le fichier control :

Code : Tout sélectionner

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
Informations générales :

Serveur WAPT : Debian 11, version 2.4.0.14080, Édition Entreprise
Machine d'administration : Windows 11, version WAPT 2.4.0.14080
Avatar de l’utilisateur
jpele
Messages : 156
Inscription : 04 mars 2019 - 12:01
Localisation : Nantes

24 juil. 2023 - 14:50

Bonjour Flavien,

Merci pour le partage.
Le paquet avait été archivé de notre coté car les binaires du dépôt GitHub ne nous permettaient pas de le packager.
Je suis curieux de savoir où vous avez trouvé ce lien de téléchargement.
J'ai pu corriger le remove(), le paquet sera prochainement disponible sur le Store :)

Cordialement,
Jimmy
Verrouillé