Created
August 29, 2020 11:29
-
-
Save TheDcoder/88772939b31f5baec6daca5942130c63 to your computer and use it in GitHub Desktop.
Portable syncthing helper tool to create portable and isolated instances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import xml.etree.ElementTree as ET | |
HOME_DIR_NAME = '.syncport' | |
CMD_PARAMS = ['-no-restart'] | |
def main(): | |
print("Setting up portable syncthing...") | |
if not os.path.exists(HOME_DIR_NAME): | |
init_home_dir() | |
else: | |
CMD_PARAMS.append('-no-browser') | |
CMD_PARAMS.insert(0, '-home=' + HOME_DIR_NAME) | |
syncthing(CMD_PARAMS) | |
def init_home_dir(): | |
print("Creating syncthing home in " + HOME_DIR_NAME) | |
syncthing(['-generate=' + HOME_DIR_NAME]) | |
config_file_path = os.path.join(HOME_DIR_NAME, 'config.xml') | |
config_file = open(config_file_path, 'rb+') | |
tree = ET.parse(config_file) | |
root = tree.getroot(); | |
print("Removing default sync directory...") | |
def_dir = root.find('./folder[@id="default"]') | |
root.remove(def_dir) | |
print("Denying usage details collection consent...") | |
consent = root.find('./options/urAccepted') | |
consent.text = '-1' | |
print("Writing changes to config.xml...") | |
config_file.seek(0) | |
tree.write(config_file, 'utf-8') | |
config_file.truncate() | |
def syncthing(args): | |
args = ' '.join(args) | |
return os.system('syncthing ' + args) | |
if __name__ == '__main__': main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment