tis-wsl-debian

1.3.0.0-22
Debian Windows Subsystem for Linux
1195 downloads
Download
tis-wsl-debian icon

  Description 

  • package : tis-wsl-debian
  • version : 1.3.0.0-22
  • architecture : all
  • categories : System and network
  • maintainer : WAPT Team,Tranquil IT,Jimmy PELE
  • description : Debian Windows Subsystem for Linux
  • locale : all
  • target_os : windows
  • min_wapt_version : 2.0
  • sources : https://www.microsoft.com/p/debian/9msvkqc78pk6
  • installed_size :
  • impacted_process :
  • description_fr :
  • description_pl :
  • description_de :
  • description_es :
  • description_pt :
  • description_it :
  • description_nl :
  • description_ru :
  • editor :
  • licence :
  • signature_date : 2021-08-20T17:26:44.981192
  • Depends :
  • Conflicts :

  Setup.py 

# -*- coding: utf-8 -*-
from setuphelpers import *
import platform
import requests
try:
    from waptenterprise.waptservice.enterprise import get_active_sessions,start_interactive_process
except:
    from waptservice.enterprise import get_active_sessions,start_interactive_process
import win32ts
import tempfile
import time

# Usable WAPT package functions: install(), uninstall(), session_setup(), audit(), update_package()
# Declaring global variables - Warnings: 1) WAPT context is only available in package functions; 2) Global variables are not persistent between calls
bin_contains = 'TheDebianProject.DebianGNULinux_'
package_name = 'TheDebianProject.DebianGNULinux'
app_name = 'WSL Debian'


def install():
    # Declaring local variables
    package_version = control.get_software_version()
    bin_name = glob.glob('*%s*.AppxBundle' % bin_contains)[0]
    app_dir = makepath(programfiles, 'WSL')
    wsl_debian = makepath(app_dir, bin_name)

    # Installing the package
    if not isdir(app_dir):
        mkdirs(app_dir)
    for bin_in_dir in glob.glob(makepath(app_dir, '*%s*' % bin_contains)):
        if bin_in_dir != wsl_debian:
            print("Removing %s" % bin_in_dir)
            remove_file(bin_in_dir)

    if not isfile(wsl_debian):
        print("Copying: %s in: %s" % (bin_name, app_dir))
        filecopyto(bin_name, app_dir)


def uninstall():
    # Declaring local variables
    app_dir = makepath(programfiles, 'WSL')

    # Uninstalling the package
    print("Removing: %s (%s) for all users" % (package_name, app_name))
    run_powershell('Get-AppxPackage -Name %s -AllUsers | Remove-AppxPackage' % package_name)

    if not WAPT.list('wsl'):
        if isdir(app_dir):
            print("Removing: %s" % app_dir)
            mkdirs(app_dir)


def session_setup():
    # Declaring local variables
    package_version = control.get_software_version()
    app_dir = makepath(programfiles, 'WSL')
    bin_path = glob.glob(makepath(app_dir, '*%s*.AppxBundle' % bin_contains))[0]

    # Installing the Appx in user environment
    try:
        installed_wsl_debian_version = run_powershell('Get-AppxPackage -Name "%s" | Select-Object version' % package_name)['Version']
    except:
        installed_wsl_debian_version = '0.0.0.0'

    if package_version > installed_wsl_debian_version:
        print("Installing: %s (%s) for the current user" % (app_name, package_version))
        run_powershell('Add-AppxPackage -Path "%s"' % bin_path)


def audit():
    # Auditing the package
    for session_id in get_active_sessions():
        username = win32ts.WTSQuerySessionInformation(win32ts.WTS_CURRENT_SERVER_HANDLE, session_id, win32ts.WTSUserName)
        #temp_file = makepath(tempfile.gettempdir(), 'wsl-%s-whoami.txt' % username)
        temp_file = r'C:\Users\%s\AppData\Local\Temp\wsl-jpadmin-whoami.txt' % username
        count = 0

        while not isfile(temp_file):
            count + 1
            if count == 30:
                error("Unable to check WSL default user for: %s" % username)
            start_interactive_process('wsl', '--distribution Debian --exec whoami > "%s"' % temp_file, session_id=session_id, hide=True) # , minimize=True
            time.sleep(1)
        wsl_username = open(temp_file, 'r').read().split('\n')[0]
        WAPT.write_audit_data('wsl-debian', '%s-default-wsl-user' % username, wsl_username, keep_days=180)
        remove_file(temp_file)
        if wsl_username == 'root':
            print("ERROR: WSL default user is: %s and should be: %s, you must remediate to it" % (wsl_username, username))
            return "ERROR"

    return "OK"


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_dl = 'https://aka.ms/wsl-debian-gnulinux'
    latest_bin = requests.head(url_dl, proxies=proxies).headers['Location'].split('/')[-1]
    version = latest_bin.split('_')[-1].rsplit('.', 1)[0]

    print("Latest %s version is: %s" % (app_name, version))
    print("Download URL is: %s" % url_dl)

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

    # Changing version of the package
    if Version(version) > Version(control.get_software_version()):
        print("Software version updated (from: %s to: %s)" % (control.get_software_version(), Version(version)))
        result = True
    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, '.AppxBundle')

    # Validating update-package-sources
    return result




def get_proxies():
    r"""Return system proxy with the urllib python library

    >>> get_proxies()
    {'http': 'http://srvproxy.ad.domain.lan:8080',
    'https': 'http://srvproxy.ad.domain.lan:8080'}

    """
    if platform.python_version_tuple()[0] == '3':
        from urllib.request import getproxies
    else:
        from urllib import getproxies
    return getproxies()


def get_proxies_from_wapt_console():
    r"""Return proxy information from the current user WAPT console

    >>> get_proxies_from_wapt_console()
    {'http': 'http://srvproxy.ad.domain.lan:8080',
    'https': 'http://srvproxy.ad.domain.lan:8080'}

    """
    proxies = {}
    if platform.system() == 'Windows':
        waptconsole_ini_path = makepath(user_local_appdata(), 'waptconsole', 'waptconsole.ini')
    else:
        waptconsole_ini_path = makepath(user_home_directory(), '.config', 'waptconsole', 'waptconsole.ini')
    if isfile(waptconsole_ini_path):
        proxy_wapt = inifile_readstring(waptconsole_ini_path, 'global', 'http_proxy')
        if proxy_wapt:
            proxies = {'http': proxy_wapt, 'https': proxy_wapt}
    return proxies


def get_version_from_binary(filename, property_name='ProductVersion'):
    r""" Get installer version from file informations, for now, only exe and msi files are compatibles

    Args:
        filename (str): path to the file
        property_name (str): selected property

    Returns:
        str: version number

     """
    if filename.endswith('.msi'):
        return get_msi_properties(filename)[property_name]
    else:
        return get_file_properties(filename)[property_name]


def remove_outdated_binaries(version, list_extensions=['exe','msi','deb','rpm','dmg','pkg'], filename_contains=None):
    r"""Remove files based on the version contained in his filename

    Args:
        version (str): version number of keeped files
        filename_contains (str or list of str): Part of the filename that must be contained (useful for distinguishing architecture and os)
        list_extensions (str or list of str): file extensions of verified files

    Returns:
        None

    .. versionadded:: 2.0

    """
    if type(list_extensions) != list:
        list_extensions = [list_extensions]
    if filename_contains:
        if type(filename_contains) != list:
            filename_contains = [filename_contains]
    list_extensions = ['.' + ext for ext in list_extensions if ext[0] != '.']
    for file_ext in list_extensions:
        for bin_in_dir in glob.glob('*%s' % file_ext):
            if not version in bin_in_dir:
                remove_file(bin_in_dir)
            if filename_contains:
                for filename_contain in filename_contains:
                    if not filename_contain in bin_in_dir:
                        remove_file(bin_in_dir)


										

  Changelog 



No changelog.txt.
									
  manifest.sha256