From 3937fbee65cfca905c32d24dd5908ab31da10e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Sun, 4 Sep 2016 14:34:28 +0200 Subject: [PATCH] install script --- install.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 install.py diff --git a/install.py b/install.py new file mode 100755 index 0000000..df276a3 --- /dev/null +++ b/install.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +import os +import sys + +BASE_DIRECTORY = 'files' +HOME_DIRECTORY = os.getenv("HOME") + + +def recurseInstall(path='/'): + def homepath(entry): + return HOME_DIRECTORY + path + entry.name + + def gitpath(entry): + return BASE_DIRECTORY + path + entry.name + + def link(entry): + print(entry.path) + os.symlink(os.getcwd()+'/'+gitpath(entry), homepath(entry)) + + for entry in os.scandir(BASE_DIRECTORY+path): + if os.path.exists(homepath(entry)): + # The file/directory already exists + if entry.is_dir(): # Directory: recurse on it + recurseInstall(path+entry.name+'/') + else: # File: backup it, symlink it + os.rename(homepath(entry), homepath(entry)+'.bck') + link(entry) + else: + link(entry) + +if __name__ == '__main__': + if not HOME_DIRECTORY: + print("Couldn't find home directory.", file=sys.stderr) + sys.exit(1) + recurseInstall()