Skip to content

Commit

Permalink
Merge branch 'master' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
vpetersson committed Apr 27, 2019
2 parents 57dbde3 + da3eb18 commit 618864d
Show file tree
Hide file tree
Showing 31 changed files with 773 additions and 191 deletions.
3 changes: 3 additions & 0 deletions Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ RUN apt-get update && \
python-imaging \
python-netifaces \
python-simplejson \
libraspberrypi0 \
ifupdown \
sqlite3 \
uzbl \
x11-xserver-utils \
Expand Down Expand Up @@ -70,4 +72,5 @@ RUN chown -R pi:pi /home/pi

WORKDIR /home/pi/screenly

CMD ["bash", "chmod 777 /dev/vchiq"]
CMD ["bash", "bin/start_resin.sh"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ To learn more about Screenly, please visit the official website at [Screenly.io]
Quick links:

* [FAQ](https://support.screenly.io/hc/en-us/sections/202652366-Frequently-Asked-Questions-FAQ-)
* [Support Forum](https://support.screenly.io)
* [Screenly OSE Forum](https://forums.screenly.io/c/screenly-ose)
* [Screenly OSE Home](https://www.screenly.io/ose/)
* [Live Demo](http://ose.demo.screenlyapp.com/)
* [QA Checklist](https://www.forgett.com/checklist/1789089623)
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/network/files/wifi-connect.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
Description=Wifi Connect
Wants=network-online.target
After=network-online.target
ConditionPathExists=!/home/pi/.screenly/initialized

[Service]
WorkingDirectory=/home/pi/screenly
User=pi
Type=oneshot

ExecStartPre=/bin/rm -f /home/pi/.screenly/initialized
ExecStart=/usr/bin/python /home/pi/screenly/start_resin_wifi.py
ExecStartPost=/usr/bin/touch /home/pi/.screenly/initialized

Expand Down
13 changes: 13 additions & 0 deletions ansible/roles/nginx/files/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ server {
proxy_set_header Host $http_host;
}

location ~ ^/api/[0-9a-z]+/backup$ {
proxy_pass http://ose;
proxy_connect_timeout 1800;
proxy_send_timeout 1800;
proxy_read_timeout 1800;
send_timeout 1800;

client_max_body_size 4G;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}

location /static {
proxy_pass http://ose/static;
}
Expand Down
4 changes: 2 additions & 2 deletions ansible/roles/screenly/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@
copy:
src: plymouth-quit-wait.service
dest: /lib/systemd/system/plymouth-quit-wait.service
mode: 0755
mode: 0644
owner: root
group: root

- name: Copy plymouth-quit.service
copy:
src: plymouth-quit.service
dest: /lib/systemd/system/plymouth-quit.service
mode: 0755
mode: 0644
owner: root
group: root

Expand Down
14 changes: 14 additions & 0 deletions ansible/roles/ssl/files/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ server {
proxy_set_header X-Forwarded-Protocol https;
}

location ~ ^/api/[0-9a-z]+/backup$ {
proxy_pass http://ose;
proxy_connect_timeout 1800;
proxy_send_timeout 1800;
proxy_read_timeout 1800;
send_timeout 1800;

client_max_body_size 4G;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Protocol https;
}

location /static {
proxy_pass http://ose/static;
}
Expand Down
14 changes: 14 additions & 0 deletions ansible/roles/ssl/files/nginx_resin.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ server {
proxy_set_header X-Forwarded-Protocol https;
}

location ~ ^/api/[0-9a-z]+/backup$ {
proxy_pass http://ose;
proxy_connect_timeout 1800;
proxy_send_timeout 1800;
proxy_read_timeout 1800;
send_timeout 1800;

client_max_body_size 4G;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Protocol https;
}

location /ws/ {
proxy_pass http://websocket;
proxy_read_timeout 24d;
Expand Down
12 changes: 9 additions & 3 deletions bin/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,27 @@ if [ "$INSTALL" != 'y' ]; then
exit 1
fi

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
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
if [ "$EXP" != 'y' ]; then
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
if [ "$DEV" != 'y' ]; then
export DOCKER_TAG="production"
echo "Screenly OSE version: Production" > ~/OSE_version.md
BRANCH="production"
else
export DOCKER_TAG="latest"
echo "Screenly OSE version: Development" > ~/OSE_version.md
BRANCH="master"
fi
else
export DOCKER_TAG="experimental"
echo "Screenly OSE version: Experimental" > ~/OSE_version.md
BRANCH="experimental"
fi

#Add reference of what linux flavor is running to OSE_version file
cat /etc/os-release | grep "PRETTY_NAME" >> ~/OSE_version.md

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
if [ "$NETWORK" == 'n' ]; then
export MANAGE_NETWORK=false
Expand All @@ -53,7 +59,7 @@ else
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."
exit 1
fi

export MANAGE_NETWORK=true
fi

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

sudo pip install ansible==2.6.3
sudo pip install ansible==2.7.10

ansible localhost -m git -a "repo=${1:-https://github.com/screenly/screenly-ose.git} dest=/home/pi/screenly version=$BRANCH"
cd /home/pi/screenly/ansible
Expand Down
12 changes: 6 additions & 6 deletions lib/assets_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ def delete(conn, asset_id):

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

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

# Set the play order to a high value for all inactive assets.
for asset in assets:
if asset['asset_id'] not in ids:
update(db_conn, asset['asset_id'], {'asset_id': asset['asset_id'], 'play_order': len(ids)})
with db.commit(db_conn) as c:
c.execute(queries.multiple_update_not_in(['play_order', ], len(ids)), [len(ids)] + ids)
147 changes: 147 additions & 0 deletions lib/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sh
import socket
import sqlite3
import re
import utils
from pprint import pprint
from uptime import uptime
Expand Down Expand Up @@ -111,6 +112,34 @@ def get_load_avg():
return load_avg


def get_git_branch():
screenly_path = os.path.join(os.getenv('HOME'), 'screenly', '.git')
try:
get_hash = sh.git(
'--git-dir={}'.format(screenly_path),
'rev-parse',
'--abbrev-ref',
'HEAD'
)
return get_hash.stdout.strip()
except:
return 'Unable to get git branch.'


def get_git_short_hash():
screenly_path = os.path.join(os.getenv('HOME'), 'screenly', '.git')
try:
get_hash = sh.git(
'--git-dir={}'.format(screenly_path),
'rev-parse',
'--short',
'HEAD'
)
return get_hash.stdout.strip()
except:
return 'Unable to get git hash.'


def get_git_hash():
screenly_path = os.path.join(os.getenv('HOME'), 'screenly', '.git')
try:
Expand Down Expand Up @@ -159,6 +188,124 @@ def get_debian_version():
return 'Unable to get Debian version.'


def get_raspberry_code():
matches = re.findall(r'\:(.*)', sh.grep('Revision', '/proc/cpuinfo').stdout)
if matches:
return matches[0].strip()


def get_raspberry_model():
"""
Data source
https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
"""
models = {
'900021': 'Model A+',
'900032': 'Model B+',
'900092': 'Model Zero',
'920092': 'Model Zero',
'900093': 'Model Zero',
'9000c1': 'Model Zero W',
'920093': 'Model Zero',
'a01040': 'Model 2B',
'a01041': 'Model 2B',
'a02082': 'Model 3B',
'a020a0': 'Model CM3',
'a21041': 'Model 2B',
'a22042': 'Model 2B (with BCM2837)',
'a22082': 'Model 3B',
'a32082': 'Model 3B',
'a52082': 'Model 3B',
'a020d3': 'Model 3B+',
'9020e0': 'Model 3A+'
}
return models.get(get_raspberry_code())


def get_raspberry_revision():
"""
Data source
https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
"""
revisions = {
'900021': '1.1',
'900032': '1.2',
'900092': '1.2',
'920092': '1.2',
'900093': '1.3',
'9000c1': '1.1',
'920093': '1.3',
'a01040': '1.0',
'a01041': '1.1',
'a02082': '1.2',
'a020a0': '1.0',
'a21041': '1.1',
'a22042': '1.2',
'a22082': '1.2',
'a32082': '1.2',
'a52082': '1.2',
'a020d3': '1.3',
'9020e0': '1.0'
}
return revisions.get(get_raspberry_code())


def get_raspberry_ram():
"""
Data source
https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
"""
rams = {
'900021': '512 MB',
'900032': '512 MB',
'900092': '512 MB',
'920092': '512 MB',
'900093': '512 MB',
'9000c1': '512 MB',
'920093': '512 MB',
'a01040': '1 GB',
'a01041': '1 GB',
'a02082': '1 GB',
'a020a0': '1 GB',
'a21041': '1 GB',
'a22042': '1 GB',
'a22082': '1 GB',
'a32082': '1 GB',
'a52082': '1 GB',
'a020d3': '1 GB',
'9020e0': '512 MB'
}
return rams.get(get_raspberry_code())


def get_raspberry_manufacturer():
"""
Data source
https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
"""
manufacturers = {
'900021': 'Sony UK',
'900032': 'Sony UK',
'900092': 'Sony UK',
'920092': 'Embest',
'900093': 'Sony UK',
'9000c1': 'Sony UK',
'920093': 'Embest',
'a01040': 'Sony UK',
'a01041': 'Sony UK',
'a02082': 'Sony UK',
'a020a0': 'Sony UK',
'a21041': 'Embest',
'a22042': 'Embest',
'a22082': 'Embest',
'a32082': 'Sony Japan',
'a52082': 'Stadium',
'a020d3': 'Sony UK',
'9020e0': 'Sony UK'
}
return manufacturers.get(get_raspberry_code())


def compile_report():
report = {}
report['cpu_info'] = parse_cpu_info()
Expand Down
6 changes: 6 additions & 0 deletions lib/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class SigalrmException(Exception):
pass


class ZmqCollectorTimeout(Exception):
pass
9 changes: 9 additions & 0 deletions lib/queries.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

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

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

Expand All @@ -9,3 +10,11 @@
create = lambda keys: 'insert into assets (' + comma(keys) + ') values (' + comma(['?'] * len(keys)) + ')'
remove = 'delete from assets where asset_id=?'
update = lambda keys: 'update assets set ' + quest(keys) + ' where asset_id=?'

multiple_update = lambda keys, count: \
'UPDATE assets SET ' + quest(keys) + ' WHERE asset_id IN (' + comma(['?'] * count) + ')'
multiple_update_not_in = lambda keys, count: \
'UPDATE assets SET ' + quest(keys) + ' WHERE asset_id NOT IN (' + comma(['?'] * count) + ')'

multiple_update_with_case = lambda keys, count: 'UPDATE assets SET ' + quest_2(keys, count) + \
' WHERE asset_id IN (' + comma(['?'] * count) + ')'
Loading

0 comments on commit 618864d

Please sign in to comment.