Mozilla pre script: initial version

This commit is contained in:
2026-04-21 18:50:21 +02:00
parent 026367b06b
commit 21fcd6aa49
4 changed files with 88 additions and 0 deletions
@@ -0,0 +1,9 @@
[Profile0]
Name=default
IsRelative=1
Path=default
Default=1
[General]
StartWithLastProfile=1
Version=2
+78
View File
@@ -0,0 +1,78 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: Daniel Pätzold
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# Will prepare local mozilla and thunderbird folders with given tar.files
#
import sys
import subprocess
import certifi
import tarfile
import shutil
import os
from os import environ
# See https://pypi.org/project/webdavclient3/
# needs pip install webdavclient3
from webdav3.client import Client
#Variables
firefox_tar = os.path.dirname(__file__) + '/firefox.tar.zst'
firefoxhome_path = environ['HOME'] + "/.config/mozilla/firefox"
firefoxhome_profile_src = os.path.dirname(__file__) + '/profiles.ini'
firefoxhome_profile_dst = firefoxhome_path + '/profiles.ini'
#Check Env
if not 'DAVTOKEN_USER' in environ:
print("Error: Script cannot be executed standalone and needs a prereserved Environment. Quit.")
sys.exit(1)
options = {
'webdav_hostname': "https://nextcloud.obel1x.de/remote.php/dav/files/unbrot",
'webdav_login': environ['DAVTOKEN_USER'],
'webdav_password': environ['DAVTOKEN_PASS']
}
client = Client(options)
#client.verify = False # To not check SSL certificates (Default = True)
if 'PROFILE_FIREFOX_RESET_LOCAL' in environ:
#Remove all files in ~/mozilla
print("Removing " + firefoxhome_path)
shutil.rmtree(firefoxhome_path)
print("Extracting " + firefox_tar + " to " + firefoxhome_path)
if not os.path.exists(firefoxhome_path): # Recreate
os.makedirs(firefoxhome_path)
tar = tarfile.open(firefox_tar)
tar.extractall(path = firefoxhome_path, filter = 'data')
tar.close()
shutil.copyfile(firefoxhome_profile_src, firefoxhome_profile_dst) # Copy initial profiles.ini to dir
print("Done.")
if 'PROFILE_FIREFOX_SRC' in environ: # Check and setup mozilla
pathstr = environ['PROFILE_FIREFOX_SRC'] + "/default"
if not client.check(pathstr):
print("Path " + pathstr + " was not found on Server. Creating it.")
i = 0
while i >= 0: #Dive into subfolders of string
i = pathstr.find("/", i + 1)
if i >= 0:
#print("/" + pathstr[:i])
if not client.check(pathstr[:i]):
client.execute_request("mkdir", "/" + pathstr[:i])
#print("/" + pathstr)
client.execute_request("mkdir", "/" + pathstr)
print("Done.")
#Check and create local Folder
if not os.path.exists(environ['PROFILE_FIREFOX_DST'] + "/default"):
os.makedirs(environ['PROFILE_FIREFOX_DST'] + "/default")
#First sync to initialise sync-db
print("Call " + environ['SYSCONFIGPATH'] + "/system_setup/mozilla_starter.sh firefox sync")
retstr = subprocess.call(['sh', environ['SYSCONFIGPATH'] + '/system_setup/mozilla_starter.sh', 'firefox', 'sync'])
#Extract empty firefox profile to Folder
print("Extracting " + firefox_tar + " to " + environ['PROFILE_FIREFOX_DST'])
tar = tarfile.open(firefox_tar)
tar.extractall(path=environ['PROFILE_FIREFOX_DST'],filter='data')
tar.close()
print("Done.")
#Next sync will be executed by logon script
sys.exit(0)
+1
View File
@@ -57,6 +57,7 @@ if [ "$EUID" -ne 0 ]; then
#End of Sync Folder for nextcloud client #End of Sync Folder for nextcloud client
#Firefox Profiles of the User #Firefox Profiles of the User
export PROFILE_FIREFOX_RESET_LOCAL="true" # Set this to wipe ~/.mozilla each time if you don't want users to setup their own firefox profile
export PROFILE_FIREFOX_SRC="mozilla_profiles/firefox" export PROFILE_FIREFOX_SRC="mozilla_profiles/firefox"
export PROFILE_FIREFOX_DST="${DECRYPTEDDATADIR}/firefox" export PROFILE_FIREFOX_DST="${DECRYPTEDDATADIR}/firefox"