forked from boyska/freepto-buildtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
164 lines (129 loc) · 3.94 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
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
import os
from fabric.api import *
from fabric.colors import green, red, blue
from fabric.decorators import runs_once
from fabtools import require, deb, service
from cuisine import file_update, text_ensure_line
#from fabric.contrib.files import append, exists
#from fabric.colors import green
import iputils
if os.path.exists('conf.py'):
import conf
### UTILITIES
def pkg(*args):
"""
Package installation
"""
l = []
for p in args:
if ' ' in p:
l.extend(p.split())
else:
l.append(p)
require.deb.packages(l)
@runs_once
def keyrings():
"""
Refresh apt keys
"""
deb.install(['debian-keyring', 'debian-archive-keyring'],
options=["-y", "--force-yes"])
sudo('apt-key update')
@runs_once
def devel():
"""
Developer tools installation
"""
# TODO: gitconfig
deb.install(['build-essential', 'git'])
require.file('/etc/gitconfig', source='files/gitconfig', use_sudo=True)
@runs_once
def aptcacher():
pkg('apt-cacher-ng')
run('update-rc.d apt-cacher-ng defaults')
service.start('apt-cacher-ng')
@runs_once
def livebuild(proxy):
print green("Livebuild with " + proxy)
pkg('openssh-server live-build python git-core zsh',
'debootstrap')
require.directory('/var/build/')
require.file('/etc/http_proxy', contents="http://%s/" % proxy,
owner='root', group='root', mode='644',
verify_remote=True)
require.file('/etc/profile.d/proxy.sh',
contents='export http_proxy="http://%s/"' % proxy,
owner='root', group='root', mode='644',
verify_remote=True)
require.file('/usr/local/bin/manualbuild.sh',
source='files/bin/manualbuild.sh', owner='root', group='root',
mode='755',
verify_remote=True)
@runs_once
def webserver():
pkg('nginx-light')
require.file('/etc/nginx/sites-enabled/default',
source='files/nginx', owner='root', group='root',
mode='644')
@runs_once
def doc():
pkg('live-boot-doc live-config-doc')
#pkg('live-manual-txt')
def auto_build(url, repository, branch='master'):
'''
this should start a build "reacting" to a github webhook
'''
pass
@runs_once
def sys_utils():
"""
Sysadmin tools installation
"""
pkg('zsh', 'psmisc', 'psutils', 'vim', 'less', 'most', 'screen', 'lsof',
'htop', 'strace', 'ltrace')
# TODO: screenrc (escape!)
require.file('/etc/vim/vimrc.local',
"syntax enable\nset modeline si ai ic scs bg=dark\n",
owner='root', group='root', use_sudo=True)
require.file('/etc/zsh/zshrc', source='files/shell/zshrc', owner='root',
group='root', use_sudo=True)
require.file('/etc/zsh/zshrc.local', source='files/shell/zshrc.local',
owner='root', group='root', use_sudo=True)
require.user('root', shell='/usr/bin/zsh')
def net_utils():
"""
Networking tools installation
"""
pkg('nethogs', 'bwm-ng', 'iptables', 'iptables-persistent', 'curl',
'dnsutils', 'vnstat', 'iptraf', 'iotop')
# TASKS
@task
def base(proxy='127.0.0.1:3142'):
require.file("/etc/apt/apt.conf",
contents='Acquire::http { Proxy "http://%s"; };' % proxy)
keyrings()
devel()
if iputils.is_my_ip(proxy.split(':')[0]):
aptcacher()
livebuild(proxy)
@task
def update():
deb.update_index()
@task
def fulloptional():
sys_utils()
net_utils()
doc()
webserver()
def mount_line(line):
if file_update('/etc/fstab', lambda _: text_ensure_line(_, line)):
run('mount -a')
@task
def qemu(central='127.0.0.1'):
if iputils.is_my_ip(central):
pkg('libvirt0 qemu-kvm')
else:
pkg('nfs-common')
# TODO: aggiungere questa riga a fstab
mount_line('%s:/var/lib/libvirt/images /var/www nfs defaults 0 0' %
central)