-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.py
More file actions
62 lines (46 loc) · 1.69 KB
/
install.py
File metadata and controls
62 lines (46 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python
import os
import re
import shutil
import hashlib
from optparse import OptionParser
re_dot = re.compile(r'^\.[^\.]+$')
HOME = os.environ["HOME"]
IGNORE = ['.git', '.gitmodules']
def file_hash(f):
return "D" if os.path.isdir(f) else hashlib.md5(open(f).read()).hexdigest()
if __name__ == '__main__':
parser = OptionParser()
parser.add_option("-l", "--link-only", dest="link_only",
action="store_true", default=False,
help="just link the .dotfiles")
parser.add_option("-f", "--force", dest="force",
action="store_true", default=False,
help="don't back up")
parser.add_option("-c", "--clean", dest="clean",
action="store_true", default=False,
help="cleanup backups")
options, args = parser.parse_args()
d = os.path.dirname(os.path.abspath(__file__))
for f in os.listdir(d):
if re_dot.match(f) and f not in IGNORE:
new_f = os.path.join(d, f)
old_f = os.path.join(HOME, f)
print "[%s]" % old_f
if os.path.exists(old_f):
if options.force:
os.remove(old_f)
else:
if file_hash(new_f) == file_hash(old_f):
print " ...ignoring"
continue
else:
print " ...backing up"
shutil.move(old_f, old_f+'.old')
if options.clean and os.path.exists(old_f+'.old'):
os.remove(old_f+'.old')
print " ...symlinking"
os.symlink(new_f, old_f)
if not options.link_only:
print "Switching to zsh!"
os.system("chsh -s /bin/zsh")