wapt-firefox-config/setup.py

63 lines
2.4 KiB
Python
Raw Normal View History

2018-12-05 15:50:00 +01:00
# -*- coding: utf-8 -*-
from setuphelpers import *
import os
from jinja2 import Environment, FileSystemLoader
uninstallkey = []
variables = {
'firefox_config_url': 'https://server/mcd/firefox.cfg',
'firefox_config_append_domain': ''
}
# 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')
2018-12-20 13:15:20 +01:00
from cryptography.fernet import Fernet
import yaml
2018-12-05 15:50:00 +01:00
f = Fernet(open(makepath(programfiles32,'wapt','private','symetric.txt'),'r').read())
2018-12-20 13:15:20 +01:00
variables.update(yaml.safe_load(f.decrypt(open(makepath(programfiles32,'wapt','private','variables.txt'),'r').read())))
2018-12-05 15:50:00 +01:00
def install():
2020-08-27 18:19:49 +02:00
if isdir(makepath(programfiles,'Mozilla Firefox ESR')):
dest=makepath(programfiles,'Mozilla Firefox ESR')
elif isdir(makepath(programfiles,'Mozilla Firefox')):
dest=makepath(programfiles,'Mozilla Firefox')
else:
error('Firefox installation dir not found')
filecopyto('autoconf.js',makepath(dest,'defaults','pref'))
filecopyto('override.ini',dest)
2018-12-05 17:04:48 +01:00
jinja2 = Environment(
2018-12-20 13:15:20 +01:00
loader=FileSystemLoader(os.getcwd()),
2018-12-05 17:04:48 +01:00
trim_blocks=True
)
2020-08-27 18:19:49 +02:00
open(makepath(dest,'firefox.cfg'),'w').write(
2018-12-05 15:50:00 +01:00
jinja2.get_template('firefox.cfg.j2').render(
firefox_config_url = variables['firefox_config_url'],
firefox_config_append_domain = variables['firefox_config_append_domain']
)
)
def uninstall():
2020-08-27 18:19:49 +02:00
for dir in ['Mozilla Firefox', 'Mozilla Firefox ESR']:
remove_file(makepath(programfiles,dir,'defaults','pref','autoconf.js'))
remove_file(makepath(programfiles,dir,'override.ini'))
remove_file(makepath(programfiles,dir,'firefox.cfg'))
2018-12-05 15:50:00 +01:00
def audit():
2020-08-27 18:19:49 +02:00
if isdir(makepath(programfiles,'Mozilla Firefox ESR')):
dest=makepath(programfiles,'Mozilla Firefox ESR')
elif isdir(makepath(programfiles,'Mozilla Firefox')):
dest=makepath(programfiles,'Mozilla Firefox')
else:
print('Firefox installation dir not found')
return "ERROR"
2018-12-05 15:50:00 +01:00
if (
2020-08-27 18:19:49 +02:00
not isfile(makepath(dest,'defaults','pref','autoconf.js')) or
not isfile(makepath(dest,'override.ini')) or
not isfile(makepath(dest,'firefox.cfg'))
2018-12-05 15:50:00 +01:00
):
print('At least one config file is missing')
return "ERROR"
return "OK"