Skip to content

Commit 5fe8a99

Browse files
authored
Merge pull request #3 from Ottercast/twig
Introduce Templating via Twig Ott :3
2 parents 6d38211 + 5aa34e5 commit 5fe8a99

File tree

354 files changed

+33033
-511
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

354 files changed

+33033
-511
lines changed

apply_config.php

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
require(__DIR__ . "/config.php");
3+
4+
`mount -o remount,rw /`;
5+
6+
$snapclient_config_path = "/etc/default/snapclient";
7+
$wpaconf_path = "/etc/wpa_supplicant/wpa_supplicant-wlan0.conf";
8+
$ssh_system_authorized_keys = "/root/.ssh/authorized_keys";
9+
10+
// 23 == 0dB capture gain
11+
`amixer cset name='Capture Volume' 23`;
12+
13+
if (file_exists($ssh_key_file))
14+
{
15+
if (file_get_contents($ssh_system_authorized_keys) != file_get_contents($ssh_key_file))
16+
{
17+
@mkdir(dirname($ssh_system_authorized_keys));
18+
file_put_contents($ssh_system_authorized_keys, file_get_contents($ssh_key_file));
19+
chmod($ssh_system_authorized_keys, 0700);
20+
}
21+
}
22+
23+
if ($config['software']["airplay_active"])
24+
{
25+
`systemctl start shairport-sync`;
26+
}
27+
else
28+
{
29+
`systemctl stop shairport-sync`;
30+
}
31+
32+
if ($config['software']["pulseaudio_active"])
33+
{
34+
`systemctl start pulseaudio`;
35+
}
36+
else
37+
{
38+
`systemctl stop pulseaudio`;
39+
}
40+
41+
if ($config['software']["librespot_active"])
42+
{
43+
`systemctl start librespot`;
44+
}
45+
else
46+
{
47+
`systemctl stop librespot`;
48+
}
49+
50+
if ($config['software']["linein_stream_active"])
51+
{
52+
`systemctl start snapserver`;
53+
}
54+
else
55+
{
56+
`systemctl stop snapserver`;
57+
}
58+
59+
if ($config['software']["snapcast_client_active"])
60+
{
61+
$snapclient_config = 'START_SNAPCLIENT=true' . "\n" .
62+
'SNAPCLIENT_OPTS="-h ' . escapeshellarg($config['software']["snapcast_client_hostname"]) . '"' . "\n";
63+
if (file_get_contents($snapclient_config_path) != $snapclient_config)
64+
{
65+
file_put_contents($snapclient_config_path, $snapclient_config);
66+
`systemctl restart snapclient`;
67+
}
68+
else
69+
{
70+
`systemctl start snapclient`;
71+
}
72+
}
73+
else
74+
{
75+
`systemctl stop snapclient`;
76+
}
77+
78+
$wpaconf = 'ctrl_interface=/var/run/wpa_supplicant
79+
#ap_scan=1
80+
81+
network={
82+
ssid="'. addslashes($config['network']["wifi_ssid"]) .'"
83+
scan_ssid=1
84+
key_mgmt=WPA-PSK
85+
psk="'. addslashes($config['network']["wifi_passphrase"]) .'"
86+
}
87+
';
88+
89+
if (file_get_contents($wpaconf_path) != $wpaconf)
90+
{
91+
file_put_contents($wpaconf_path, $wpaconf);
92+
`ifdown --force wlan0`;
93+
`systemctl restart network`;
94+
`ifup wlan0`;
95+
}
96+
else
97+
{
98+
`ifup wlan0`;
99+
}
100+
101+
if (trim(file_get_contents("/etc/hostname")) != trim($config['general']["hostname"]))
102+
{
103+
$cmd = 'hostnamectl set-hostname ' . escapeshellarg($config['general']["hostname"]);
104+
`$cmd`;
105+
106+
`systemctl restart avahi-daemon`;
107+
108+
if ($config['software']["pulseaudio_active"])
109+
{
110+
`systemctl restart pulseaudio`;
111+
}
112+
if ($config['software']["airplay_active"])
113+
{
114+
`systemctl restart shairport-sync`;
115+
}
116+
if ($config['software']["librespot_active"])
117+
{
118+
`systemctl restart librespot`;
119+
}
120+
if ($config['software']["snapcast_client_active"])
121+
{
122+
`systemctl restart snapclient`;
123+
}
124+
if ($config['software']["linein_stream_active"])
125+
{
126+
`systemctl restart snapserver`;
127+
}
128+
}
129+
130+
`mount -o remount,ro /`;

bootstrap.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
error_reporting(E_ALL);
3+
ini_set("display_errors", 1);
4+
5+
define("SERVER_PATH", __DIR__);
6+
7+
require_once(SERVER_PATH . '/vendor/autoload.php');
8+
require_once(SERVER_PATH . '/config.php');
9+
10+
$loader = new \Twig\Loader\FilesystemLoader(SERVER_PATH.'/templates');
11+
$twig = new \Twig\Environment($loader, [
12+
'cache' => '/tmp/twig_cache',
13+
]);
14+

cgi-bin/applyConfig.php

Lines changed: 0 additions & 117 deletions
This file was deleted.

cgi-bin/config.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)