35 lines
974 B
Python
Executable file
35 lines
974 B
Python
Executable file
#!/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):
|
|
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()
|