forked from ADicksonLab/wepy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
135 lines (97 loc) · 3.25 KB
/
fabfile.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
from fabric import task
from patchwork.transfers import rsync
import os
import os.path as osp
from pathlib import Path
import json
## START EDIT: Edit these values to your profiles
# name of the bimhaw profile used in the bootstrapping process
PHASE1_PROFILE = "scooter"
# name of the bimhaw profile that is the end state target
FINAL_PROFILE = "bronco"
# name of the loadout (collection of installed programs) to install
FINAL_LOADOUT = "humvee"
## END EDIT
@task
def packages_bootstrap(cx):
"""Install the main distro provided packages"""
packages = [
'git',
'rsync',
'mg',
'python3-venv',
]
cx.run(f"sudo apt install -y {' '.join(packages)}")
@task
def bimhaw_bootstrap(cx):
"""Configure bimhaw and shells in system to PHASE 1.
PHASE 1 is a loadout profile which is used to then install more
advanced environments.
"""
# make a python virtual env to install it at first and set the
# shells
cx.run("mkdir -p $HOME/tmp")
cx.run("python3 -m venv ~/tmp/py_bootstrap_env")
# run the bimhaw initialization stuff
with cx.prefix(". tmp/py_bootstrap_env/bin/activate"):
cx.run("rm -rf $HOME/.bimhaw")
cx.run("pip install git+https://github.com/salotz/bimhaw.git")
cx.run("python -m bimhaw.init "
"--config ~/.salotz.d/bimhaw/config.py "
"--lib ~/.salotz.d/bimhaw/lib")
# cx.run("rm $HOME/.profile ~/.bashrc ~/.bash_logout")
cx.run("bimhaw link-shells --force && "
f"bimhaw profile -n {PHASE1_PROFILE}"
)
@task
def pyenv_bootstrap(cx):
with cx.cd("$HOME/.salotz.d"):
cx.run("/bin/bash -l -c './lib/installers/python_sys.sh'")
cx.run("/bin/bash -l -c './lib/installers/python_pyenv.bash'")
cx.run("/bin/bash -l -c './lib/setups/python_pyenv.bash'")
cx.run("/bin/bash -l -c 'pip3 install invoke'")
cx.run("/bin/bash -l -c './lib/setups/python_virtualenv.sh'")
@task
def install_loadout(cx):
with cx.cd(f"$HOME/.salotz.d"):
cx.run(f"/bin/bash -l -c 'make -f lib/loadouts/{{FINAL_LOADOUT}}.mk all'")
# load the bimhaw profile
cx.run(f"/bin/bash -l -c './lib/setups/bimhaw.sh && bimhaw profile -n {FINAL_PROFILE}'")
@task()
def bootstrap(cx):
"""Take a container from blank to loaded out."""
packages_bootstrap(cx)
push_profile(cx)
bimhaw_bootstrap(cx)
pyenv_bootstrap(cx)
install_loadout(cx)
@task
def push_profile(cx):
"""Push my configuration from local user. Assumes bootstrap install is
done."""
homedir = osp.expandvars('$HOME')
rsync(cx,
f"{homedir}/.salotz.d",
f"{homedir}/",
rsync_opts="-ahi --stats",
)
@task
def push_project(cx, target_dir=None):
# get the directory to push to
if target_dir is None:
target_dir = Path(os.getcwd()).parent
cx.run(f"mkdir -p {target_dir}")
rsync(cx,
os.getcwd(),
target_dir,
rsync_opts="-ahi --stats --filter=':- .gitignore'",
)
@task
def pull_project(cx):
# get the directory to push to
target_dir = Path(os.getcwd()).parent
rsync(cx,
os.getcwd(),
target_dir,
rsync_opts="-ahi --stats --filter=':- .gitignore' --update",
)