Skip to content

Commit 618864d

Browse files
committed
Merge branch 'master' into production
2 parents 57dbde3 + da3eb18 commit 618864d

31 files changed

+773
-191
lines changed

Dockerfile.template

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ RUN apt-get update && \
1717
python-imaging \
1818
python-netifaces \
1919
python-simplejson \
20+
libraspberrypi0 \
21+
ifupdown \
2022
sqlite3 \
2123
uzbl \
2224
x11-xserver-utils \
@@ -70,4 +72,5 @@ RUN chown -R pi:pi /home/pi
7072

7173
WORKDIR /home/pi/screenly
7274

75+
CMD ["bash", "chmod 777 /dev/vchiq"]
7376
CMD ["bash", "bin/start_resin.sh"]

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ To learn more about Screenly, please visit the official website at [Screenly.io]
3232
Quick links:
3333

3434
* [FAQ](https://support.screenly.io/hc/en-us/sections/202652366-Frequently-Asked-Questions-FAQ-)
35-
* [Support Forum](https://support.screenly.io)
35+
* [Screenly OSE Forum](https://forums.screenly.io/c/screenly-ose)
3636
* [Screenly OSE Home](https://www.screenly.io/ose/)
3737
* [Live Demo](http://ose.demo.screenlyapp.com/)
3838
* [QA Checklist](https://www.forgett.com/checklist/1789089623)

ansible/roles/network/files/wifi-connect.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
Description=Wifi Connect
33
Wants=network-online.target
44
After=network-online.target
5-
ConditionPathExists=!/home/pi/.screenly/initialized
65

76
[Service]
87
WorkingDirectory=/home/pi/screenly
98
User=pi
109
Type=oneshot
1110

11+
ExecStartPre=/bin/rm -f /home/pi/.screenly/initialized
1212
ExecStart=/usr/bin/python /home/pi/screenly/start_resin_wifi.py
1313
ExecStartPost=/usr/bin/touch /home/pi/.screenly/initialized
1414

ansible/roles/nginx/files/nginx.conf

+13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ server {
2424
proxy_set_header Host $http_host;
2525
}
2626

27+
location ~ ^/api/[0-9a-z]+/backup$ {
28+
proxy_pass http://ose;
29+
proxy_connect_timeout 1800;
30+
proxy_send_timeout 1800;
31+
proxy_read_timeout 1800;
32+
send_timeout 1800;
33+
34+
client_max_body_size 4G;
35+
proxy_set_header X-Real-IP $remote_addr;
36+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
37+
proxy_set_header Host $http_host;
38+
}
39+
2740
location /static {
2841
proxy_pass http://ose/static;
2942
}

ansible/roles/screenly/tasks/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@
8888
copy:
8989
src: plymouth-quit-wait.service
9090
dest: /lib/systemd/system/plymouth-quit-wait.service
91-
mode: 0755
91+
mode: 0644
9292
owner: root
9393
group: root
9494

9595
- name: Copy plymouth-quit.service
9696
copy:
9797
src: plymouth-quit.service
9898
dest: /lib/systemd/system/plymouth-quit.service
99-
mode: 0755
99+
mode: 0644
100100
owner: root
101101
group: root
102102

ansible/roles/ssl/files/nginx.conf

+14
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ server {
4242
proxy_set_header X-Forwarded-Protocol https;
4343
}
4444

45+
location ~ ^/api/[0-9a-z]+/backup$ {
46+
proxy_pass http://ose;
47+
proxy_connect_timeout 1800;
48+
proxy_send_timeout 1800;
49+
proxy_read_timeout 1800;
50+
send_timeout 1800;
51+
52+
client_max_body_size 4G;
53+
proxy_set_header X-Real-IP $remote_addr;
54+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
55+
proxy_set_header Host $http_host;
56+
proxy_set_header X-Forwarded-Protocol https;
57+
}
58+
4559
location /static {
4660
proxy_pass http://ose/static;
4761
}

ansible/roles/ssl/files/nginx_resin.conf

+14
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ server {
1919
proxy_set_header X-Forwarded-Protocol https;
2020
}
2121

22+
location ~ ^/api/[0-9a-z]+/backup$ {
23+
proxy_pass http://ose;
24+
proxy_connect_timeout 1800;
25+
proxy_send_timeout 1800;
26+
proxy_read_timeout 1800;
27+
send_timeout 1800;
28+
29+
client_max_body_size 4G;
30+
proxy_set_header X-Real-IP $remote_addr;
31+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
32+
proxy_set_header Host $http_host;
33+
proxy_set_header X-Forwarded-Protocol https;
34+
}
35+
2236
location /ws/ {
2337
proxy_pass http://websocket;
2438
proxy_read_timeout 24d;

bin/install.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,27 @@ if [ "$INSTALL" != 'y' ]; then
2929
exit 1
3030
fi
3131

32-
echo && read -p "Would you like to use the experimental branch? It contains the last major changes, such as the new browser and migrating to the docker (y/N)" -n 1 -r -s EXP && echo
32+
echo && read -p "Would you like to use the experimental branch? It contains the last major changes, such as the new browser and migrating to Docker (y/N)" -n 1 -r -s EXP && echo
3333
if [ "$EXP" != 'y' ]; then
3434
echo && read -p "Would you like to use the development branch? You will get the latest features, but things may break. (y/N)" -n 1 -r -s DEV && echo
3535
if [ "$DEV" != 'y' ]; then
3636
export DOCKER_TAG="production"
37+
echo "Screenly OSE version: Production" > ~/OSE_version.md
3738
BRANCH="production"
3839
else
3940
export DOCKER_TAG="latest"
41+
echo "Screenly OSE version: Development" > ~/OSE_version.md
4042
BRANCH="master"
4143
fi
4244
else
4345
export DOCKER_TAG="experimental"
46+
echo "Screenly OSE version: Experimental" > ~/OSE_version.md
4447
BRANCH="experimental"
4548
fi
4649

50+
#Add reference of what linux flavor is running to OSE_version file
51+
cat /etc/os-release | grep "PRETTY_NAME" >> ~/OSE_version.md
52+
4753
echo && read -p "Do you want Screenly to manage your network? This is recommended for most users. (Y/n)" -n 1 -r -s NETWORK && echo
4854
if [ "$NETWORK" == 'n' ]; then
4955
export MANAGE_NETWORK=false
@@ -53,7 +59,7 @@ else
5359
echo -e "\n\nIt looks like NetworkManager is not installed. Please install it by running 'sudo apt install -y network-manager' and then re-run the installation."
5460
exit 1
5561
fi
56-
62+
5763
export MANAGE_NETWORK=true
5864
fi
5965

@@ -89,7 +95,7 @@ sudo apt-get purge -y python-setuptools python-pip python-pyasn1
8995
sudo apt-get install -y python-dev git-core libffi-dev libssl-dev
9096
curl -s https://bootstrap.pypa.io/get-pip.py | sudo python
9197

92-
sudo pip install ansible==2.6.3
98+
sudo pip install ansible==2.7.10
9399

94100
ansible localhost -m git -a "repo=${1:-https://github.com/screenly/screenly-ose.git} dest=/home/pi/screenly version=$BRANCH"
95101
cd /home/pi/screenly/ansible

lib/assets_helper.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ def delete(conn, asset_id):
130130

131131
def save_ordering(db_conn, ids):
132132
"""Order assets. Move to last position assets which not presented in list of id"""
133-
assets = read(db_conn)
134133

135-
for play_order, asset_id in enumerate(ids):
136-
update(db_conn, asset_id, {'asset_id': asset_id, 'play_order': play_order})
134+
if ids:
135+
with db.commit(db_conn) as c:
136+
c.execute(queries.multiple_update_with_case(['play_order', ], len(ids)),
137+
sum([[asset_id, play_order] for play_order, asset_id in enumerate(ids)], []) + ids)
137138

138139
# Set the play order to a high value for all inactive assets.
139-
for asset in assets:
140-
if asset['asset_id'] not in ids:
141-
update(db_conn, asset['asset_id'], {'asset_id': asset['asset_id'], 'play_order': len(ids)})
140+
with db.commit(db_conn) as c:
141+
c.execute(queries.multiple_update_not_in(['play_order', ], len(ids)), [len(ids)] + ids)

lib/diagnostics.py

+147
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sh
66
import socket
77
import sqlite3
8+
import re
89
import utils
910
from pprint import pprint
1011
from uptime import uptime
@@ -111,6 +112,34 @@ def get_load_avg():
111112
return load_avg
112113

113114

115+
def get_git_branch():
116+
screenly_path = os.path.join(os.getenv('HOME'), 'screenly', '.git')
117+
try:
118+
get_hash = sh.git(
119+
'--git-dir={}'.format(screenly_path),
120+
'rev-parse',
121+
'--abbrev-ref',
122+
'HEAD'
123+
)
124+
return get_hash.stdout.strip()
125+
except:
126+
return 'Unable to get git branch.'
127+
128+
129+
def get_git_short_hash():
130+
screenly_path = os.path.join(os.getenv('HOME'), 'screenly', '.git')
131+
try:
132+
get_hash = sh.git(
133+
'--git-dir={}'.format(screenly_path),
134+
'rev-parse',
135+
'--short',
136+
'HEAD'
137+
)
138+
return get_hash.stdout.strip()
139+
except:
140+
return 'Unable to get git hash.'
141+
142+
114143
def get_git_hash():
115144
screenly_path = os.path.join(os.getenv('HOME'), 'screenly', '.git')
116145
try:
@@ -159,6 +188,124 @@ def get_debian_version():
159188
return 'Unable to get Debian version.'
160189

161190

191+
def get_raspberry_code():
192+
matches = re.findall(r'\:(.*)', sh.grep('Revision', '/proc/cpuinfo').stdout)
193+
if matches:
194+
return matches[0].strip()
195+
196+
197+
def get_raspberry_model():
198+
"""
199+
Data source
200+
https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
201+
"""
202+
models = {
203+
'900021': 'Model A+',
204+
'900032': 'Model B+',
205+
'900092': 'Model Zero',
206+
'920092': 'Model Zero',
207+
'900093': 'Model Zero',
208+
'9000c1': 'Model Zero W',
209+
'920093': 'Model Zero',
210+
'a01040': 'Model 2B',
211+
'a01041': 'Model 2B',
212+
'a02082': 'Model 3B',
213+
'a020a0': 'Model CM3',
214+
'a21041': 'Model 2B',
215+
'a22042': 'Model 2B (with BCM2837)',
216+
'a22082': 'Model 3B',
217+
'a32082': 'Model 3B',
218+
'a52082': 'Model 3B',
219+
'a020d3': 'Model 3B+',
220+
'9020e0': 'Model 3A+'
221+
}
222+
return models.get(get_raspberry_code())
223+
224+
225+
def get_raspberry_revision():
226+
"""
227+
Data source
228+
https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
229+
"""
230+
revisions = {
231+
'900021': '1.1',
232+
'900032': '1.2',
233+
'900092': '1.2',
234+
'920092': '1.2',
235+
'900093': '1.3',
236+
'9000c1': '1.1',
237+
'920093': '1.3',
238+
'a01040': '1.0',
239+
'a01041': '1.1',
240+
'a02082': '1.2',
241+
'a020a0': '1.0',
242+
'a21041': '1.1',
243+
'a22042': '1.2',
244+
'a22082': '1.2',
245+
'a32082': '1.2',
246+
'a52082': '1.2',
247+
'a020d3': '1.3',
248+
'9020e0': '1.0'
249+
}
250+
return revisions.get(get_raspberry_code())
251+
252+
253+
def get_raspberry_ram():
254+
"""
255+
Data source
256+
https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
257+
"""
258+
rams = {
259+
'900021': '512 MB',
260+
'900032': '512 MB',
261+
'900092': '512 MB',
262+
'920092': '512 MB',
263+
'900093': '512 MB',
264+
'9000c1': '512 MB',
265+
'920093': '512 MB',
266+
'a01040': '1 GB',
267+
'a01041': '1 GB',
268+
'a02082': '1 GB',
269+
'a020a0': '1 GB',
270+
'a21041': '1 GB',
271+
'a22042': '1 GB',
272+
'a22082': '1 GB',
273+
'a32082': '1 GB',
274+
'a52082': '1 GB',
275+
'a020d3': '1 GB',
276+
'9020e0': '512 MB'
277+
}
278+
return rams.get(get_raspberry_code())
279+
280+
281+
def get_raspberry_manufacturer():
282+
"""
283+
Data source
284+
https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
285+
"""
286+
manufacturers = {
287+
'900021': 'Sony UK',
288+
'900032': 'Sony UK',
289+
'900092': 'Sony UK',
290+
'920092': 'Embest',
291+
'900093': 'Sony UK',
292+
'9000c1': 'Sony UK',
293+
'920093': 'Embest',
294+
'a01040': 'Sony UK',
295+
'a01041': 'Sony UK',
296+
'a02082': 'Sony UK',
297+
'a020a0': 'Sony UK',
298+
'a21041': 'Embest',
299+
'a22042': 'Embest',
300+
'a22082': 'Embest',
301+
'a32082': 'Sony Japan',
302+
'a52082': 'Stadium',
303+
'a020d3': 'Sony UK',
304+
'9020e0': 'Sony UK'
305+
}
306+
return manufacturers.get(get_raspberry_code())
307+
308+
162309
def compile_report():
163310
report = {}
164311
report['cpu_info'] = parse_cpu_info()

lib/errors.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class SigalrmException(Exception):
2+
pass
3+
4+
5+
class ZmqCollectorTimeout(Exception):
6+
pass

lib/queries.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
comma = ','.join
33
quest = lambda l: '=?,'.join(l) + '=?'
4+
quest_2 = lambda l, c: ', '.join([('%s=CASE ' % x) + ("WHEN asset_id=? THEN ? " * c) + 'ELSE asset_id END' for x in l])
45

56
exists_table = "SELECT name FROM sqlite_master WHERE type='table' AND name='assets'"
67

@@ -9,3 +10,11 @@
910
create = lambda keys: 'insert into assets (' + comma(keys) + ') values (' + comma(['?'] * len(keys)) + ')'
1011
remove = 'delete from assets where asset_id=?'
1112
update = lambda keys: 'update assets set ' + quest(keys) + ' where asset_id=?'
13+
14+
multiple_update = lambda keys, count: \
15+
'UPDATE assets SET ' + quest(keys) + ' WHERE asset_id IN (' + comma(['?'] * count) + ')'
16+
multiple_update_not_in = lambda keys, count: \
17+
'UPDATE assets SET ' + quest(keys) + ' WHERE asset_id NOT IN (' + comma(['?'] * count) + ')'
18+
19+
multiple_update_with_case = lambda keys, count: 'UPDATE assets SET ' + quest_2(keys, count) + \
20+
' WHERE asset_id IN (' + comma(['?'] * count) + ')'

0 commit comments

Comments
 (0)