This repository has been archived by the owner on Oct 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noisebox_setup.py
151 lines (102 loc) · 4.89 KB
/
noisebox_setup.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
import subprocess
import os
from shutil import copy
import socket
import enquiries
from colored import fg, attr
green = fg(2)
res = attr('reset')
root = '/home/pi/autonomous-noise-unit-install/'
# CONFIGURE NOISEBOX
if 'noisebox' not in socket.gethostname():
print(green + '\nDefault RPi password not safe, please choose a new one: ' + res)
subprocess.run('sudo passwd pi', shell=True)
id = input(green + '\nPlease enter the ID no. of this noisebox (1, 2, 3, 4 etc...): ' + res)
soundcards = ['pisound', 'hifiberry-dacplusadc', 'none']
print(green + '\nWhich audio device do you want to use?:' + res)
soundcard = enquiries.choose('', soundcards)
print(green + '\nAudio interface:', soundcard + res)
# NOISEBOX DEPENDENCIES
subprocess.run('sudo bash ' + root + 'dependencies/noisebox.sh', shell=True)
# NOISEBOX CONFIG FILE
if os.path.isfile(root + 'custom_config/noisebox/config.ini'):
subprocess.run('sudo rm /home/pi/autonomous-noise-unit/config.ini', shell=True)
copy(root + 'custom_config/noisebox/config.ini', '/home/pi/autonomous-noise-unit/config.ini')
subprocess.run('sudo chown pi:pi /home/pi/autonomous-noise-unit/config.ini', shell=True)
# SYSTEMD
print(green + '\nConfiguring Noisebox daemon...' + res)
subprocess.run('sudo cp ' + root + 'rpi_config/noisebox.service /lib/systemd/system/noisebox.service', shell=True)
subprocess.run('sudo systemctl daemon-reload', shell=True)
subprocess.run('sudo systemctl enable noisebox.service', shell=True)
# RPi AUDIO
print(green + 'Configuring RPi soundcard and audio...' + res)
copy(root + 'rpi_config/config.txt', '/boot')
copy(root + 'rpi_config/profile', '/etc/profile')
with open('/etc/profile', 'a') as profile:
profile.write('export JACK_NO_AUDIO_RESERVATION=1')
# SOUNDCARD > PISOUND
if soundcard == 'pisound':
print(green + 'Configuring pisound soundcard...' + res)
print(green + 'Installing pisound software...' + res)
subprocess.call('curl -s https://blokas.io/pisound/install.sh | sh', shell=True)
with open('/boot/config.txt', 'a') as config:
config.write('dtparam=audio=off\n')
config.write('dtoverlay=pisound\n')
# disable pisound services
subprocess.run('sudo systemctl daemon-reload', shell=True)
subprocess.run('sudo systemctl disable pisound-btn', shell=True)
subprocess.run('sudo systemctl disable pisound-ctl', shell=True)
# SOUNDCARD > HIFIBERRY
if soundcard == 'hifiberry-dacplusadc':
print(green + 'Configuring Hifiberry soundcard...' + res)
with open('/boot/config.txt', 'a') as config:
config.write('dtparam=audio=off\n')
config.write('dtoverlay=hifiberry-dacplusadc\n')
# SOUNDCARD > NONE
if soundcard == 'none':
print(green + 'Configuring inbuilt audio...' + res)
with open('/boot/config.txt', 'a') as config:
config.write('dtparam=audio=on\n')
# OLED
print(green + 'Configuring OLED...' + res)
copy(root + 'rpi_config/modules', '/etc/modules')
# RPi HOSTNAME
print(green + 'Configuring RPi hostname...' + res)
print('127.0.1.' + id + ' noisebox' + id)
with open('/etc/hostname', 'w') as hostname:
hostname.write('noisebox' + id)
copy(root + 'rpi_config/hosts', '/etc/hosts')
with open('/etc/hosts', 'a') as hosts:
hosts.write('127.0.1.' + id + ' noisebox' + id + '\n')
# VPN
if os.path.isfile(root + 'custom_config/vpncloud/vpncloud.txt'):
print(green + 'Configuring vpncloud for remote access...' + res)
subprocess.run('sudo bash ' + root + 'dependencies/vpncloud.sh', shell=True)
copy('/etc/vpncloud/example.net.disabled', '/etc/vpncloud/mynet.net')
f = open(root + 'custom_config/vpncloud/vpncloud.txt', mode='r')
vpncloud_append = f.read()
f.close()
with open('/etc/vpncloud/mynet.net', 'a') as vpncloud_config:
vpncloud_config.write(str(vpncloud_append))
vpncloud_config.write("ifup: 'ifconfig $IFNAME 10.0.0." + id + "/24 mtu 1500'\n")
vpncloud_config.write('statsd_prefix: noisebox' + id + '\n')
f = open(root + 'custom_config/vpncloud/hosts.txt', mode='r')
vpncloud_hosts = f.read()
f.close()
with open('/etc/hosts', 'a') as hosts:
hosts.write(str(vpncloud_hosts))
subprocess.run('sudo systemctl enable vpncloud@mynet', shell=True)
else:
print(green + 'Skipping vpncloud configuration.' + res)
# TELEGRAF METRICS
if os.path.isfile(root + 'custom_config/telegraf/telegraf.conf'):
print(green + 'Configuring telegraf metrics server...' + res)
subprocess.run('sudo bash ' + root + 'dependencies/telegraf.sh', shell=True)
subprocess.run('usermod -aG video telegraf', shell=True)
subprocess.run("setcap 'cap_net_admin,cap_net_raw+ep' $(which ping)", shell=True)
copy(root + 'custom_config/telegraf/telegraf.conf', '/etc/telegraf/telegraf.conf')
else:
print(green + 'Skipping telegraf configuration.' + res)
print(green + '\nInstallation complete!' + res)
print(green + '\nRebooting system.' + res)
subprocess.run('sudo reboot', shell=True)