-
Notifications
You must be signed in to change notification settings - Fork 0
/
raspi-config.py
211 lines (185 loc) · 6.84 KB
/
raspi-config.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
#!/usr/bin/env python
# @file raspi-config.py
# @author Albert Puig (albert.puig@epfl.ch)
# @date 17.03.2013
import os
# Fabric stuff
from fabric.api import task, local, env, run, sudo, settings#, abort
from fabric.context_managers import hide, cd
# My stuff
from utils import dir_exists, file_exists, to_boolean
############################################################
# Configuration
############################################################
env.hosts = ['pi@192.168.1.120']
simple_install = True
dirs_to_make = ['~/src', '~/runtime', '~/runtime/watch']
things_to_download = []
apt_repos = []
packages_to_install = ['git',
'python-software-properties',
'python-pip',
'python-dev',
'ca-certificates',
'lsof',
'python-lxml',
'mailutils',
'sendmail',
'smartmontools',
'curl',
'nmon',
'deluge-console',
'python3-dev',
'libffi-dev',
'libssl-dev',
'build-essential',
'libffi6',
'libffi-dev'
]
# For psutil
# http://raspberrypi.stackexchange.com/questions/8566/peerguardian-moblock-installation-on-raspbmc
easy_install_list = ['-e "git+git://github.com/seatgeek/fuzzywuzzy.git#egg=fuzzywuzzy"',
"speedtest-cli",
"xbmc-json",
"validictory",
"pebble",
"python-Levenshtein",
'"git+git://github.com/apuignav/pibullet.git"',
#"psutil",
]
git_repositories = [#'https://github.com/MilhouseVH/bcmstat.git',
#'https://github.com/pilluli/service.xbmc.callbacks.git',
#'https://github.com/amet/script.xbmc.subtitles.git',
'https://github.com/apuignav/raspi-config.git',
'https://github.com/apuignav/expense-bot.git']
if not simple_install:
apt_repos = ['ppa:keithw/mosh']
# For monitorix
# wget http://apt.izzysoft.de/izzysoft.asc
# sudo apt-key add izzysoft.asc
# add
# deb [arch=all] http://apt.izzysoft.de/ubuntu generic universe
# to /etc/apt/sources.list
# sudo apt-get update
# sudo apt-get install monitorix
############################################################
# Tasks
############################################################
@task
def deploy_ssh(remove_banner=True):
with settings(warn_only=True):
# Remove annoying Debian banner
if remove_banner:
run('touch $HOME/.hushlogin')
# Add our public keys
if not dir_exists('~/.ssh'):
for host in env.hosts:
local('ssh-copy-id %s' % host)
@task
def prepare_dirs():
dir_list = []
for d in dirs_to_make:
if not dir_exists(d):
dir_list.append(d)
if dir_list:
run("mkdir {0}".format(" ".join(['%s' % dir_ for dir_ in dir_list])))
with cd('/home/pi'):
run('ln -sf /media/RaspiHD/ .')
@task
def download_things():
for url in things_to_download:
with cd('/home/pi/src'):
run('wget --no-check-certificate %s' % url)
@task
def prepare_apt_repos():
for repo in apt_repos:
sudo('sudo add-apt-repository %s' % repo)
@task
def install_packages(update=True):
update = to_boolean(update)
if update:
with hide('stdout'):
sudo('apt-get update')
print "Installing software"
with hide('stdout'):
sudo('apt-get install -y {0}'.format(' '.join(packages_to_install)))
@task
def install_python_packages():
# Now install packages
for package in easy_install_list:
print "Installing %s" % package
with hide('stdout'):
sudo('pip install {0}'.format(package))
@task
def clone_git_repos():
with settings(warn_only=True):
with cd('$HOME/src'):
for repo in git_repositories:
name = os.path.splitext(os.path.split(repo)[1])[0]
if run('test -d {0}'.format(name)).failed:
run('git clone {0}'.format(repo))
#@task
#def configure_xbmc():
#with settings(warn_only=True):
#with cd('$HOME'):
#run('ln -sf $HOME/src/script.xbmc.subtitles/script.xbmc.subtitles ~/.xbmc/addons/')
#if file_exists('/media/RaspiHD/backup/backup.tar.gz'):
#run('python src/raspi-config/scripts/backup.py restore /media/RaspiHD/backup/backup.tar.gz')
@task
def configure_deluge():
# sudo cp $HOME/src/raspi-config/deluge/logrotate.d_deluge /etc/logrotate.d/deluge
with settings(warn_only=True):
sudo("cp /home/pi/src/raspi-config/deluge/deluge.conf /etc/init/")
sudo("cp /home/pi/src/raspi-config/deluge/deluge-webui.conf /etc/init/")
sudo("mkdir -p /var/log/deluge && sudo chown -R pi:pi /var/log/deluge && sudo chmod -R 750 /var/log/deluge")
sudo("cp /home/pi/src/raspi-config/deluge/logrotate.d_deluge /etc/logrotate.d/deluge")
run("ln -sf /media/RaspiHD/torrent/completo/ /home/pi/runtime/")
run("ln -sf /media/RaspiHD/torrent/download/ /home/pi/runtime/")
run("ln -sf /media/RaspiHD/torrent/tv_shows.cache /home/pi/runtime/")
sudo("systemctl start deluge")
sudo("systemctl stop deluge")
if file_exists('/media/RaspiHD/backup/backup.deluge.tar.gz'):
run('python $HOME/src/raspi-config/scripts/backup.py restore /media/RaspiHD/backup/ deluge')
@task
def configure_mail():
with settings(warn_only=True):
sudo('echo "djkarras@gmail.com" > ~root/.forward')
run('echo "djkarras@gmail.com" > ~/.forward')
@task
def configure_crontab():
run("crontab /home/pi/src/raspi-config/config/crontab.pi")
@task
def configure_expensebot():
with settings(warn_only=True):
sudo('cp $HOME/src/expense-bot/service/expensebot.service /lib/systemd/system/')
sudo('systemctl daemon-reload')
sudo('systemctl start expensebot')
@task
def configure_samba():
with settings(warn_only=True):
sudo('cp $HOME/src/raspi-config/config/smb-shares.conf /etc/samba/smb-shares.conf')
sudo('systemctl restart samba')
@task
def deploy_software(update=True):
prepare_dirs()
download_things()
prepare_apt_repos()
install_packages(update)
install_python_packages()
clone_git_repos()
@task
def deploy_configuration():
#configure_xbmc()
configure_deluge()
configure_mail()
configure_crontab()
configure_expensebot()
configure_samba()
@task
def deploy(update=True):
deploy_ssh()
deploy_software(update)
deploy_configuration()
if __name__ == '__main__':
deploy()
# EOF