diff --git a/client_software/0050_nextcloud_mozilla_pre/firefox.tar.zst b/client_software/0050_nextcloud_mozilla_pre/firefox.tar.zst new file mode 100644 index 0000000..7af26c8 Binary files /dev/null and b/client_software/0050_nextcloud_mozilla_pre/firefox.tar.zst differ diff --git a/client_software/0050_nextcloud_mozilla_pre/profiles.ini b/client_software/0050_nextcloud_mozilla_pre/profiles.ini new file mode 100644 index 0000000..e25d687 --- /dev/null +++ b/client_software/0050_nextcloud_mozilla_pre/profiles.ini @@ -0,0 +1,9 @@ +[Profile0] +Name=default +IsRelative=1 +Path=default +Default=1 + +[General] +StartWithLastProfile=1 +Version=2 diff --git a/client_software/0050_nextcloud_mozilla_pre/user_run.sh b/client_software/0050_nextcloud_mozilla_pre/user_run.sh new file mode 100755 index 0000000..930ea25 --- /dev/null +++ b/client_software/0050_nextcloud_mozilla_pre/user_run.sh @@ -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) diff --git a/system_setup/setup_system.conf.dist b/system_setup/setup_system.conf.dist index ca12afe..b72247e 100644 --- a/system_setup/setup_system.conf.dist +++ b/system_setup/setup_system.conf.dist @@ -57,6 +57,7 @@ if [ "$EUID" -ne 0 ]; then #End of Sync Folder for nextcloud client #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_DST="${DECRYPTEDDATADIR}/firefox"