-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.py
111 lines (91 loc) · 3.37 KB
/
install.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import os
from os.path import expanduser as eu, dirname, exists, join as pjoin
from time import time
from subprocess import call
import shutil
import sys
backup = False
def _makedirs(dirs):
# Create the folder in case it doesn't exist.
try:
os.makedirs(dirs)
except OSError as e:
if e.errno != 17: # 17 means directory already exists
raise
def link_with_backup(source, link_name, symbolic=True):
link_name = eu(link_name)
source = eu(source)
print('Installing ' + source + ' -> ' + link_name)
_makedirs(dirname(link_name))
try:
if symbolic:
os.symlink(source, link_name)
else:
os.link(source, link_name)
except OSError:
if backup:
os.rename(link_name, f'{link_name}.{int(time())}.dotfiles_backup')
else:
# Try to remove this thing. Non-empty directories don't work yet.
try:
os.remove(link_name)
except OSError as e:
os.rmdir(link_name)
os.symlink(source, link_name)
def here(f):
import inspect
me = inspect.getsourcefile(here)
return pjoin(os.path.dirname(os.path.abspath(me)), f)
def here_to_home(name, toname=None, symbolic=True):
link_with_backup(here('_' + name), '~/.' + (toname if toname else name), symbolic=symbolic)
def main(mode):
if mode != 'server':
global backup
backup = input('Delete existing files (no backs them up)? [y/N]: ') not in ('y', 'Y')
# Things I install on all machines (lin/mac laptops, servers)
here_to_home('tmux.conf')
here_to_home('gitignore')
here_to_home('pythonrc.py')
here_to_home('config/nvim/init.lua')
here_to_home('config/nvim/color')
here_to_home('config/fish/solarized.fish')
here_to_home('config/fish/config.fish')
here_to_home('config/fish/functions/fish_prompt.fish')
# My util scripts
here_to_home('local/bin/imshow')
here_to_home('local/bin/lightswitch')
here_to_home('local/bin/togif')
# Things for any desktop/laptop, but not server.
if mode != 'server':
here_to_home('config/kitty/kitty.conf')
here_to_home('config/kitty/themes/Solarized Dark Lucas.conf')
if mode == 'linux':
here_to_home('inputrc')
here_to_home('Xresources')
here_to_home('Xresources.solarized-dark')
here_to_home('Xresources.solarized-light')
link_with_backup('.Xresources.solarized-dark', '~/.Xresources.colors')
here_to_home('xinitrc')
here_to_home('gitconfig')
here_to_home('ssh_config', 'ssh/config', symbolic=False) # Can't be symlink due to permissions.
here_to_home('config/i3/config')
here_to_home('config/i3status/config')
here_to_home('config/xsettingsd/xsettingsd.conf')
here_to_home('local/bin/e-cores')
here_to_home('local/bin/reset-inputs')
elif mode == 'mac':
here_to_home('config/aerospace/aerospace.toml')
here_to_home('local/bin/aerospace_scratch')
if not shutil.which('fish'):
print("WARNING: no fish installed?")
try:
import lb_secret
lb_secret.install(mode, here_to_home)
except ImportError:
pass
if __name__ == '__main__':
if len(sys.argv) == 2:
assert sys.argv[1] in ('server', 'linux', 'mac')
else:
print("Specify install mode: server, linux, mac")
main(sys.argv[1])