Files
fedora-OEMDRV/client_software/0050_nextcloud_mozilla_pre/user_run.sh
T

79 lines
2.9 KiB
Bash
Executable File

#!/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)