-
Notifications
You must be signed in to change notification settings - Fork 1
/
HOMELY.py
214 lines (184 loc) · 6.32 KB
/
HOMELY.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import os
import platform
import shutil
import tempfile
import time
from pathlib import Path
from homely.files import symlink, mkdir, download
from homely.install import installpkg
from homely.system import execute, haveexecutable
from homely.ui import head, note
home_dir = Path.home()
emacs_init_dir = home_dir / ".emacs.d"
dotfiles_old_dir = home_dir / "dotfiles.old"
iterm2_dir = home_dir / ".iterm2"
mkdir("~/.emacs.d")
mkdir("~/.emacs.d/snippets")
mkdir("~/.pip")
mkdir(str(iterm2_dir))
if not dotfiles_old_dir.exists():
dotfiles_old_dir.mkdir()
install_system = platform.system()
PYDEV_PACKAGES = """
make build-essential libssl-dev zlib1g-dev
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm
libncursesw5-dev xz-utils libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev tk-dev
"""
PG_PACKAGES = """
libpq-dev python3-dev python3-psycopg2
"""
if install_system == "Linux":
note("printing sudo environment")
execute(["sudo", "DEBIAN_FRONTEND=noninteractive", "printenv"])
note("custom install tzdata")
execute(
[
"sudo",
"DEBIAN_FRONTEND=noninteractive",
"apt-get",
"install",
"-y",
"--quiet",
"tzdata",
]
)
for pkg in PYDEV_PACKAGES.split():
installpkg(pkg.strip(), brew=False)
for pkg in PG_PACKAGES.split():
installpkg(pkg.strip(), brew=False)
installpkg("emacs", apt="emacs-nox")
installpkg("black")
installpkg("htop")
installpkg("svn", apt="subversion")
installpkg("ispell")
installpkg("aspell")
installpkg("tree")
if install_system == "Darwin":
installpkg("coreutils")
if install_system == "Linux":
installpkg("net-tools")
HOMEBREW_INSTALL_SCRIPT = (
"https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
)
def brew_executable():
brew_dirs = [
Path("~/.linuxbrew").expanduser(),
Path("/home/linuxbrew/.linuxbrew"),
]
for brew_dir in brew_dirs:
brew_binary = brew_dir / "bin" / "brew"
if brew_binary.exists() and brew_binary.is_file():
return str(brew_binary)
return ""
with head("homebrew"):
if not (haveexecutable("brew") or brew_executable()):
if install_system == "Linux":
note("need to install personal Linux homebrew, executing install script")
execute(
[
"/bin/bash",
str(Path("~/dotfiles/install_personal_linuxbrew.sh").expanduser()),
]
)
elif install_system == "Darwin":
note("need to install Mac homebrew")
with tempfile.NamedTemporaryFile() as install_sh_tmp:
note(f"Downloading brew install script to: {install_sh_tmp}")
download(HOMEBREW_INSTALL_SCRIPT, install_sh_tmp)
note("Executing brew install script")
execute(["/bin/bash", "-c", install_sh_tmp])
else:
note("Unknown brew platform")
else:
note("homebrew already installed")
with head("pyenv"):
note("Installing pyenv")
pyenv_root = Path(os.environ["HOME"]) / ".pyenv"
if not pyenv_root.exists():
note("Installing pyenv")
execute(["git", "clone", "https://github.com/pyenv/pyenv.git", str(pyenv_root)])
else:
note(f"pyenv dir: {pyenv_root} already exists. Skipping clone.")
pyenv_virtualenv_root = pyenv_root / "plugins" / "pyenv-virtualenv"
if not (pyenv_virtualenv_root.exists()):
note("Installing pyenv-virtualenv")
execute(
[
"git",
"clone",
"https://github.com/pyenv/pyenv-virtualenv.git",
str(pyenv_virtualenv_root),
]
)
else:
note(
f"pyenv plugin dir: {pyenv_virtualenv_root} already exists. Skipping clone."
)
with head("pipx"):
installpkg("pipx")
execute(["pipx", "install", "httpie"])
execute(["pipx", "install", "xonsh"])
execute(["pipx", "install", "cookiecutter"])
execute(["pipx", "install", "black"])
execute(["pipx", "install", "pgcli"])
execute(
[
str(home_dir / ".local" / "bin" / "xonsh"),
"-c" "xpip install -U 'xonsh[full]'",
]
)
execute(
[
str(home_dir / ".local" / "bin" / "xonsh"),
"-c",
"xpip install vox",
]
)
execute(
[
str(home_dir / ".local" / "bin" / "xonsh"),
"-c",
"xpip install packaging xontrib-powerline2 xontrib-homebrew",
]
)
with head("neofetch"):
installpkg("neofetch")
with head("nerdfonts"):
if haveexecutable("brew") and install_system == "Darwin":
execute(["brew", "install", "font-3270-nerd-font"])
execute(["brew", "install", "font-droid-sans-mono-for-powerline"])
execute(["brew", "install", "font-fira-code"])
execute(["brew", "install", "font-fira-sans"])
execute(["brew", "install", "font-fira-mono"])
execute(["brew", "install", "font-fira-mono-for-powerline"])
INSTALL_DOTFILES = [
("screenrc", ".screenrc"),
("bashrc", ".bashrc"),
("bash_profile", ".bash_profile"),
("gitconfig", ".gitconfig"),
("gitignore", ".gitignore"),
("emacs_init.el", "~/.emacs.d/init.el"),
("xonshrc", ".xonshrc"),
("xonsh_iterm2.json", "~/.iterm2/xonsh.json"),
("pelicandev", "~/.local/bin/pelicandev"),
(
"pyenv_virtualenv_after_bash",
"~/.pyenv/plugins/pyenv-virtualenv/etc/pyenv.d/virtualenv/after.bash",
),
("pip.conf", "~/.pip/pip.conf"),
]
mkdir("~/.pyenv/plugins/pyenv-virtualenv/etc/pyenv.d/virtualenv")
with head("Processing potentially preexisting targets."):
for dot_file, orig_file in INSTALL_DOTFILES:
orig_file_path = Path(orig_file).expanduser()
dot_file_path = Path("~/dotfiles").expanduser() / dot_file
note(f"Checking {orig_file_path}")
if orig_file_path.exists() and not (orig_file_path.samefile(dot_file_path)):
dst_file_path = (
dotfiles_old_dir / f"{orig_file_path.name}_{int(time.time())}"
)
note(f"Original file: {orig_file_path} -> {dst_file_path}")
shutil.move(orig_file_path, dst_file_path)
with head("Installing dotfiles."):
for dot_file, orig_file in INSTALL_DOTFILES:
symlink(dot_file, orig_file)