You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
6.1 KiB
144 lines
6.1 KiB
5 years ago
|
# -*- coding: utf-8 -*-
|
||
|
from setuphelpers import *
|
||
|
from jinja2 import Environment, FileSystemLoader
|
||
|
|
||
|
uninstallkey = []
|
||
|
|
||
|
variables = {
|
||
|
'web_home_page': 'https://google.fr'
|
||
|
}
|
||
|
|
||
|
# Declaring specific app values (TO CHANGE)
|
||
|
chrome_app_path=makepath(programfiles32,'Google','Chrome','Application')
|
||
|
chrome_bin_path=makepath(chrome_app_path,'chrome.exe')
|
||
|
bin_name = 'googlechromestandaloneenterprise64.msi' if iswin64() else 'googlechromestandaloneenterprise.msi'
|
||
|
|
||
|
# Read local variables file if available
|
||
|
if isfile(makepath(programfiles32,'wapt','private','symetric.txt')) and isfile(makepath(programfiles32,'wapt','private','variables.txt')):
|
||
|
print('Reading local encrypted variables file')
|
||
|
from cryptography.fernet import Fernet
|
||
|
import yaml
|
||
|
f = Fernet(open(makepath(programfiles32,'wapt','private','symetric.txt'),'r').read())
|
||
|
variables.update(yaml.safe_load(f.decrypt(open(makepath(programfiles32,'wapt','private','variables.txt'),'r').read())))
|
||
|
|
||
|
def install():
|
||
|
print('Installing %s' % control.asrequirement())
|
||
|
|
||
|
# Specific app values
|
||
|
package_version = control['version'].split('-',1)[0]
|
||
|
skip = False
|
||
|
|
||
|
# Getting the used storage on programfiles before installation (place it on the top)
|
||
|
get_disk_free_space_before = get_disk_free_space(programfiles)
|
||
|
|
||
|
if isfile(chrome_bin_path):
|
||
|
if Version(get_file_properties(chrome_bin_path)['ProductVersion']) >= Version(package_version):
|
||
|
print('File %s version is : %s ' % (chrome_bin_path,get_file_properties(chrome_bin_path)['ProductVersion']))
|
||
|
print('Package version is : %s ' % package_version)
|
||
|
uninstallkey_from_file = get_msi_properties(bin_name)['ProductCode']
|
||
|
if uninstall_key_exists(uninstallkey_from_file):
|
||
|
uninstallkey.append(uninstallkey_from_file)
|
||
|
skip = True
|
||
|
|
||
|
if (not skip) or (force == True) :
|
||
|
def get_version_chrome(key):
|
||
|
return get_file_properties(chrome_bin_path)['ProductVersion']
|
||
|
install_msi_if_needed(bin_name
|
||
|
,min_version=package_version
|
||
|
,get_version=get_version_chrome)
|
||
|
|
||
|
# Disabling Google Chrome auto updates
|
||
|
for task in ['GoogleUpdateTaskMachineCore', 'GoogleUpdateTaskMachineUA']:
|
||
|
if task_exists(task):
|
||
|
disable_task(task)
|
||
|
|
||
|
registry_setstring(HKEY_LOCAL_MACHINE,'SOFTWARE\\Policies\\Google\\Update','UpdateDefault',0,type=REG_DWORD)
|
||
|
registry_setstring(HKEY_LOCAL_MACHINE,'SOFTWARE\\Policies\\Google\\Update','DisableAutoUpdateChecksCheckboxValue',1,type=REG_DWORD)
|
||
|
registry_setstring(HKEY_LOCAL_MACHINE,'SOFTWARE\\Policies\\Google\\Update','AutoUpdateCheckPeriodMinutes',0,type=REG_DWORD)
|
||
|
if iswin64():
|
||
|
registry_setstring(HKEY_LOCAL_MACHINE,'SOFTWARE\\Wow6432Node\\Google\\Update','UpdateDefault',0,type=REG_DWORD)
|
||
|
registry_setstring(HKEY_LOCAL_MACHINE,'SOFTWARE\\Wow6432Node\\Google\\Update','DisableAutoUpdateChecksCheckboxValue',1,type=REG_DWORD)
|
||
|
registry_setstring(HKEY_LOCAL_MACHINE,'SOFTWARE\\Wow6432Node\\Google\\Update','AutoUpdateCheckPeriodMinutes',0,type=REG_DWORD)
|
||
|
|
||
|
# Disabling Google Chrome telemtry
|
||
|
registry_setstring(HKEY_LOCAL_MACHINE,'SOFTWARE\\Policies\\Explorer\\DisallowRun','chrome_telemetry','Software_Reporter_Tool.exe',type=REG_SZ)
|
||
|
|
||
|
# Adding master preferences file
|
||
|
jinja2 = Environment(
|
||
|
loader=FileSystemLoader(os.getcwd()),
|
||
|
trim_blocks=True
|
||
|
)
|
||
|
open(makepath(chrome_app_path,'master_preferences'),'w').write(
|
||
|
jinja2.get_template('master_preferences.j2').render(
|
||
|
web_home_page = variables['web_home_page']
|
||
|
)
|
||
|
)
|
||
|
|
||
|
# Return used storage of the program. (place it on the bottom)
|
||
|
get_disk_free_space_after = get_disk_free_space(programfiles)
|
||
|
free_space_after_diff = get_disk_free_space_before - get_disk_free_space_after
|
||
|
print("Storage used: " + str(free_space_after_diff))
|
||
|
|
||
|
|
||
|
def uninstall():
|
||
|
print('uninstalling %s' % control.asrequirement())
|
||
|
|
||
|
if uninstall_key_exists('Google Chrome'):
|
||
|
if not "msiexec" in ' '.join(list(uninstall_cmd('Google Chrome'))).lower():
|
||
|
versionsoft = get_file_properties(chrome_bin_path)['ProductVersion']
|
||
|
run('"%s" --uninstall --system-level --force-uninstall --qn' % makepath(install_location('Google Chrome'),versionsoft,'Installer','setup.exe'),accept_returncodes=[19])
|
||
|
|
||
|
|
||
|
def session_setup():
|
||
|
print('Session setup for %s' % control.asrequirement())
|
||
|
print('Disabling Telemetry')
|
||
|
|
||
|
swreporter_path=makepath(user_local_appdata,'Google','Chrome','User Data','SwReporter')
|
||
|
|
||
|
if isdir(swreporter_path):
|
||
|
remove_tree(swreporter_path)
|
||
|
|
||
|
|
||
|
def update_package():
|
||
|
print('Update package content from upstream binary sources')
|
||
|
from waptpackage import PackageEntry
|
||
|
import requests
|
||
|
import json
|
||
|
|
||
|
# Get latest version number from official website
|
||
|
latest_version = json.loads(wgets('http://omahaproxy.appspot.com/all.json?os=win64&channel=stable'))[0]['versions'][0]['version']
|
||
|
pe = PackageEntry()
|
||
|
control = pe.load_control_from_wapt(os.getcwd())
|
||
|
current_version = control['version'].split('-',1)[0]
|
||
|
|
||
|
base_url = 'https://dl.google.com/tag/s/dl/chrome/install/'
|
||
|
if Version(latest_version) > Version(current_version):
|
||
|
print('Latest ' + control.name + ' version is: ' + latest_version)
|
||
|
|
||
|
for file in ['googlechromestandaloneenterprise64.msi', 'googlechromestandaloneenterprise.msi']:
|
||
|
url_dl = base_url + file
|
||
|
|
||
|
# Downloading latest binaries
|
||
|
if isfile(file):
|
||
|
remove_file(file)
|
||
|
|
||
|
print('Downloading ' + file + ' from ' + url_dl)
|
||
|
wget(url_dl, file)
|
||
|
|
||
|
pe.version = latest_version + '-0'
|
||
|
pe.maturity = 'PREPROD'
|
||
|
pe.save_control_to_wapt(os.getcwd())
|
||
|
print('Package updated to %s' % latest_version)
|
||
|
|
||
|
else:
|
||
|
print('This package is already up-to-date')
|
||
|
for file in ['googlechromestandaloneenterprise64.msi', 'googlechromestandaloneenterprise.msi']:
|
||
|
if not isfile(file):
|
||
|
url_dl = base_url + file
|
||
|
print('%s file is missing, downloading it from %s' % (file, url_dl))
|
||
|
wget(url_dl, file)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
update_package()
|
||
|
|