simo 2.2.13__py3-none-any.whl → 2.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of simo might be problematic. Click here for more details.

@@ -55,7 +55,18 @@ class LatestHubOSVersionAvailable(StringPreference):
55
55
  class AutoUpdate(BooleanPreference):
56
56
  section = core
57
57
  name = 'auto_update'
58
- default = True
58
+ default = False
59
+
60
+ def validate(self, value):
61
+ if value:
62
+ with open(os.path.join(settings.VAR_DIR, 'auto_update'), 'w') as f:
63
+ f.write("YES!")
64
+ else:
65
+ try:
66
+ os.remove(os.path.join(settings.VAR_DIR, 'auto_update'))
67
+ except:
68
+ pass
69
+ return
59
70
 
60
71
 
61
72
  @global_preferences_registry.register
@@ -2,8 +2,9 @@ from django.core.management.base import BaseCommand
2
2
  import os
3
3
  import pwd
4
4
  import grp
5
+ import sys
5
6
  import subprocess
6
- import pkg_resources
7
+ from crontab import CronTab
7
8
  from django.conf import settings
8
9
  from django.template.loader import render_to_string
9
10
 
@@ -55,6 +56,25 @@ def prepare_mosquitto():
55
56
  )
56
57
 
57
58
 
59
+ def update_auto_update():
60
+
61
+ if os.geteuid() != 0:
62
+ print("You are not a root user!")
63
+ return
64
+
65
+ executable_path = f'{os.path.dirname(sys.executable)}/simo-auto-update'
66
+ cron = CronTab(user='root')
67
+ for item in cron:
68
+ if executable_path in str(item):
69
+ return
70
+
71
+ job = cron.new(command=executable_path)
72
+ job.hour.every(1)
73
+ job.enable()
74
+ cron.write()
75
+
76
+
77
+
58
78
 
59
79
  class Command(BaseCommand):
60
80
 
@@ -1,22 +1,31 @@
1
- #!/usr/bin/python3
2
- # -*- coding: utf-8 -*-
3
1
  import requests
4
2
  import sys
5
3
  import os
6
4
  import subprocess
7
5
  import pkg_resources
8
6
 
7
+
9
8
  HUB_DIR = '/etc/SIMO/hub'
10
9
 
11
10
 
12
- def perform_update():
11
+ def install_dependencies():
13
12
 
14
- proc = subprocess.Popen(
15
- ['pip', 'install', 'setuptools==65.7.0']
13
+ status = subprocess.call(
14
+ 'apt install postgresql libpq-dev postgresql-client '
15
+ 'postgresql-client-common python3-pip redis-server supervisor '
16
+ 'mosquitto libopenjp2-7 libtiff5-dev pkg-config libcairo2-dev '
17
+ 'libgirepository1.0-dev libcairo2 libudev-dev gdal-bin net-tools '
18
+ 'nginx postgis openvpn ffmpeg libsm6 libxext6 ssh keychain -y',
19
+ shell=True
16
20
  )
17
- out, err = proc.communicate()
18
- if proc.returncode:
19
- raise Exception(err.decode())
21
+ if status != 0:
22
+ print("Unable install required packages.")
23
+ return
24
+
25
+ return True
26
+
27
+
28
+ def perform_update():
20
29
 
21
30
  proc = subprocess.Popen(
22
31
  ['pip', 'install', 'simo', '--upgrade'],
@@ -26,7 +35,6 @@ def perform_update():
26
35
  if proc.returncode:
27
36
  raise Exception(err.decode())
28
37
 
29
- from simo.management.install import install_dependencies
30
38
  install_dependencies()
31
39
 
32
40
  proc = subprocess.Popen(
@@ -59,7 +67,7 @@ def perform_update():
59
67
  print("Update completed!")
60
68
 
61
69
 
62
- if __name__ == "__main__":
70
+ def maybe_update():
63
71
  if not os.path.exists('/etc/SIMO/_var/auto_update'):
64
72
  print("Auto updates are disabled")
65
73
  else:
@@ -73,4 +81,4 @@ if __name__ == "__main__":
73
81
  print("Let's GO!")
74
82
  perform_update()
75
83
  else:
76
- print("Already up to date. Version: %s" % latest)
84
+ print("Already up to date. Version: %s" % latest)
simo/core/tasks.py CHANGED
@@ -321,12 +321,10 @@ def vacuum_full():
321
321
 
322
322
  @celery_app.task
323
323
  def update():
324
- from simo.management.auto_update import perform_update
324
+ from simo.core.management.update import perform_update
325
325
  perform_update()
326
326
 
327
327
 
328
-
329
-
330
328
  @celery_app.task
331
329
  def drop_fingerprints_learn():
332
330
  Instance.objects.filter(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: simo
3
- Version: 2.2.13
3
+ Version: 2.3.2
4
4
  Summary: Smart Home on Steroids!
5
5
  Author-email: Simanas Venčkauskas <simanas@simo.io>
6
6
  Project-URL: Homepage, https://simo.io
@@ -33,7 +33,7 @@ Requires-Dist: itsdangerous ==2.0.1
33
33
  Requires-Dist: redis ==3.5.3
34
34
  Requires-Dist: django-redis ==4.12.1
35
35
  Requires-Dist: webservices ==0.7
36
- Requires-Dist: numpy ==1.26.4
36
+ Requires-Dist: numpy >=1.24.4
37
37
  Requires-Dist: geopy ==2.2.0
38
38
  Requires-Dist: requests ==2.26.0
39
39
  Requires-Dist: suntime ==1.2.5
@@ -48,4 +48,5 @@ Requires-Dist: Pillow ==9.5.0
48
48
  Requires-Dist: django-markdownify ==0.9.5
49
49
  Requires-Dist: django-activity-stream ==2.0.0
50
50
  Requires-Dist: gunicorn ==23.0.0
51
+ Requires-Dist: python-crontab ==3.2.0
51
52
 
@@ -24,7 +24,7 @@ simo/core/autocomplete_views.py,sha256=JT5LA2_Wtr60XYSAIqaXFKFYPjrmkEf6yunXD9y2z
24
24
  simo/core/base_types.py,sha256=qVh6MrXZEfN7bFOyFftC7u0yyz0PkvpsjllLBc6SCp4,616
25
25
  simo/core/context.py,sha256=98PXAMie43faRVBFkOG22uNpvGRNprcGhzjBFkrxaRY,1367
26
26
  simo/core/controllers.py,sha256=rLgJqnEMzRC0GpZnQb0m_Cz43Gp2zaYbODU7UUxE5oA,29602
27
- simo/core/dynamic_settings.py,sha256=txfRcU2QA_WF6-7Ykc4Hl5gpTkZzi94N8gmmvEolezM,1549
27
+ simo/core/dynamic_settings.py,sha256=bUs58XEZOCIEhg1TigR3LmYggli13KMryBZ9pC7ugAQ,1872
28
28
  simo/core/events.py,sha256=LvtonJGNyCb6HLozs4EG0WZItnDwNdtnGQ4vTcnKvUs,4438
29
29
  simo/core/filters.py,sha256=ghtOZcrwNAkIyF5_G9Sn73NkiI71mXv0NhwCk4IyMIM,411
30
30
  simo/core/form_fields.py,sha256=9tIjiEN3IE55GPyB4tOlfkd51JDne3-h8pKhpL3tLFE,2220
@@ -40,7 +40,7 @@ simo/core/serializers.py,sha256=quXznnTKCm57rvRgke0mBnlWmaO8C5scJ8R251wa1jY,2086
40
40
  simo/core/signal_receivers.py,sha256=9-qFCCeSLcMFEMg6QUtKOVgUsoNoqhzGoI98nuNSTEo,6228
41
41
  simo/core/socket_consumers.py,sha256=n7VE2Fvqt4iEAYLTRbTPOcI-7tszMAADu7gimBxB-Fg,9635
42
42
  simo/core/storage.py,sha256=_5igjaoWZAiExGWFEJMElxUw55DzJG1jqFty33xe8BE,342
43
- simo/core/tasks.py,sha256=HE3VsVGJjLKtlZyjYF-TQ2-9vChxZ2EtY6A5vNkZl-0,14235
43
+ simo/core/tasks.py,sha256=jMDuutrzPpKc-7hhjEnsw93CaedumPKLJU7LoXhGz6k,14233
44
44
  simo/core/todos.py,sha256=eYVXfLGiapkxKK57XuviSNe3WsUYyIWZ0hgQJk7ThKo,665
45
45
  simo/core/types.py,sha256=WJEq48mIbFi_5Alt4wxWMGXxNxUTXqfQU5koH7wqHHI,1108
46
46
  simo/core/views.py,sha256=VVqfEPzK0EdbVMMarkG8rd7cODG5QHpXnr3e8UdrTQE,2600
@@ -127,12 +127,20 @@ simo/core/drf_braces/tests/serializers/test_enforce_validation_serializer.py,sha
127
127
  simo/core/drf_braces/tests/serializers/test_form_serializer.py,sha256=IE2xQ1SzhSsOy2BFsBYw_Po-ujKBgIuNoTRxCzhyilE,12995
128
128
  simo/core/drf_braces/tests/serializers/test_swapping.py,sha256=o-B5YV5HDxHCVrXYGODeF7lB3rPDGtafNgClx97d6w4,1220
129
129
  simo/core/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
130
+ simo/core/management/update.py,sha256=D8siHc9EFSJGUYcyw6hZqlYMm5HUzSnud4Ajm-noQCo,2365
130
131
  simo/core/management/__pycache__/__init__.cpython-38.pyc,sha256=Ptf1WzljXMt3wP1tzOy6q3JfLERYDs66wSHBVdrzjHg,169
132
+ simo/core/management/_hub_template/hub/asgi.py,sha256=ElN_fdeSkf0Ysa7pS9rJVmZ1HmLhFxb8jFaMLqe1220,126
133
+ simo/core/management/_hub_template/hub/celeryc.py,sha256=3ksDXftIZKJ4Cq9WNKJERdZdQlDEnjTQXycweRFmsSQ,27
134
+ simo/core/management/_hub_template/hub/manage.py,sha256=PNNlw3EVeIJDgkG0l-klqoxsKWfTYWG9jzRG0upmAaI,620
135
+ simo/core/management/_hub_template/hub/nginx.conf,sha256=40hvXL42MeiqqkLURNcDQsRudv1dNFLJnvb2-Y3RCkk,2394
136
+ simo/core/management/_hub_template/hub/settings.py,sha256=4QhvhbtLRxHvAntwqG_qeAAtpDUqKvN4jzw9u3vqff8,361
137
+ simo/core/management/_hub_template/hub/supervisor.conf,sha256=tl1nW95DrVwcGxgLXAOgIn5ow1p_-LRNNE1bCEoq00k,1888
138
+ simo/core/management/_hub_template/hub/urls.py,sha256=Ydm-1BkYAzWeEF-MKSDIFf-7aE4qNLPm48-SA51XgJQ,25
139
+ simo/core/management/_hub_template/hub/wsgi.py,sha256=Lo-huLHnMDTxSmMBOodVFMWBls9poddrV2KRzXU0xGo,280
131
140
  simo/core/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
132
141
  simo/core/management/commands/gateways_manager.py,sha256=a_JmUG1SPJhbhPh5QdViCT5DL0YvKQH-KsO8ptLhB34,6970
133
- simo/core/management/commands/on_http_start.py,sha256=un8r0oOwU7niC7uHf63IFvFBVWkl4GeTLEkpmDUpanA,1802
142
+ simo/core/management/commands/on_http_start.py,sha256=uOhuaKlqYAjqqU1I3Alt1vD0nYdf-5OIDzps83S1riE,2225
134
143
  simo/core/management/commands/run_gateway.py,sha256=bp0FQQoBeOSoxjHCCMicDL1fxPZZGyLgnq2QKht3bJo,645
135
- simo/core/management/commands/update.py,sha256=Y2_6EL8E757nr-MjSuIpdSsEItI0yN42DT5P1e1zkno,175
136
144
  simo/core/management/commands/__pycache__/__init__.cpython-38.pyc,sha256=WKpfZZpAB9D7U4X6oWQIrU_H-6rUmq8Gl9fj9XaY2fw,178
137
145
  simo/core/management/commands/__pycache__/gateways_manager.cpython-38.pyc,sha256=pgEJdchhOcqKCpjdRMeF0_QKJfMmfSkl_W4TUwcgS9o,6031
138
146
  simo/core/management/commands/__pycache__/on_http_start.cpython-38.pyc,sha256=LQeFW3oYYRrEPEcGghyeahFE114-4VbnKH4XaVGcQcg,3235
@@ -10343,20 +10351,6 @@ simo/generic/templates/admin/controller_widgets/thermostat.html,sha256=iH7j631AY
10343
10351
  simo/generic/templates/admin/controller_widgets/weather_forecast.html,sha256=UuvXM6XONknAHxn3DF0CP8aGrrfng92n0iTgXkHg7QI,500
10344
10352
  simo/generic/templates/generic/controllers_info/dummy.md,sha256=DcdkpYXpK7sroINukZZPUQs9uekN9kkE7p5hfnArgFo,147
10345
10353
  simo/generic/templates/generic/controllers_info/stateselect.md,sha256=T0w3vJg02W3RMSsljN1EPRnkVaeRW5acSZaSq9FYvZw,135
10346
- simo/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10347
- simo/management/auto_update.py,sha256=4MDrJHdtC5LxEJM258Y0kc5yI4yloeKhDjh-S2BN-ZQ,2115
10348
- simo/management/copy_template.py,sha256=Iehq57FYMzdHNp3LU4ue6rr6AkRiGeOthG7PoGWd88Q,2002
10349
- simo/management/install.py,sha256=hKyjqzE90cyCKYkXEyMhMToYk3xzNZgyjO7nPwrklJo,8668
10350
- simo/management/__pycache__/__init__.cpython-38.pyc,sha256=ey9k5mPsmvAHRVf5Du6QUqy40LgBCAPN_B5EaR6h9Eg,164
10351
- simo/management/__pycache__/auto_update.cpython-38.pyc,sha256=OAp7w4PdXY0xeo7Yof7O_x9y7qNMyZV4ZerRlswjQ2I,1681
10352
- simo/management/_hub_template/hub/asgi.py,sha256=ElN_fdeSkf0Ysa7pS9rJVmZ1HmLhFxb8jFaMLqe1220,126
10353
- simo/management/_hub_template/hub/celeryc.py,sha256=3ksDXftIZKJ4Cq9WNKJERdZdQlDEnjTQXycweRFmsSQ,27
10354
- simo/management/_hub_template/hub/manage.py,sha256=PNNlw3EVeIJDgkG0l-klqoxsKWfTYWG9jzRG0upmAaI,620
10355
- simo/management/_hub_template/hub/nginx.conf,sha256=40hvXL42MeiqqkLURNcDQsRudv1dNFLJnvb2-Y3RCkk,2394
10356
- simo/management/_hub_template/hub/settings.py,sha256=4QhvhbtLRxHvAntwqG_qeAAtpDUqKvN4jzw9u3vqff8,361
10357
- simo/management/_hub_template/hub/supervisor.conf,sha256=tl1nW95DrVwcGxgLXAOgIn5ow1p_-LRNNE1bCEoq00k,1888
10358
- simo/management/_hub_template/hub/urls.py,sha256=Ydm-1BkYAzWeEF-MKSDIFf-7aE4qNLPm48-SA51XgJQ,25
10359
- simo/management/_hub_template/hub/wsgi.py,sha256=Lo-huLHnMDTxSmMBOodVFMWBls9poddrV2KRzXU0xGo,280
10360
10354
  simo/multimedia/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10361
10355
  simo/multimedia/admin.py,sha256=GgXiKTLfi3omjBurU-bKgneJRK-tAeiR8o2jo3zD7zs,1002
10362
10356
  simo/multimedia/api.py,sha256=mZ5BTggWdc_kL8P70JGC3rTCiZKPnxWYoyNcAQkFnX4,285
@@ -10513,9 +10507,9 @@ simo/users/templates/invitations/expired_msg.html,sha256=47DEQpj8HBSa-_TImW-5JCe
10513
10507
  simo/users/templates/invitations/expired_suggestion.html,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10514
10508
  simo/users/templates/invitations/taken_msg.html,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10515
10509
  simo/users/templates/invitations/taken_suggestion.html,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10516
- simo-2.2.13.dist-info/LICENSE.md,sha256=M7wm1EmMGDtwPRdg7kW4d00h1uAXjKOT3HFScYQMeiE,34916
10517
- simo-2.2.13.dist-info/METADATA,sha256=Z6M5AAPNQXdgYtIFIw6AtPY4hFizxJxXGWnW4gpO3ww,1841
10518
- simo-2.2.13.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
10519
- simo-2.2.13.dist-info/entry_points.txt,sha256=SJBxiDpH7noO0STxVI_eRIsGR-nLgdXXeqCDe8cXlbM,65
10520
- simo-2.2.13.dist-info/top_level.txt,sha256=GmS1hrAbpVqn9OWZh6UX82eIOdRLgYA82RG9fe8v4Rs,5
10521
- simo-2.2.13.dist-info/RECORD,,
10510
+ simo-2.3.2.dist-info/LICENSE.md,sha256=M7wm1EmMGDtwPRdg7kW4d00h1uAXjKOT3HFScYQMeiE,34916
10511
+ simo-2.3.2.dist-info/METADATA,sha256=8X6asyzMnCXBDSzz6WWtkxAxwJTk9HrOnXsshAZnwRY,1878
10512
+ simo-2.3.2.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
10513
+ simo-2.3.2.dist-info/entry_points.txt,sha256=S9PwnUYmTSW7681GKDCxUbL0leRJIaRk6fDQIKgbZBA,135
10514
+ simo-2.3.2.dist-info/top_level.txt,sha256=GmS1hrAbpVqn9OWZh6UX82eIOdRLgYA82RG9fe8v4Rs,5
10515
+ simo-2.3.2.dist-info/RECORD,,
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ simo-auto-update = simo.core.management.update:maybe_update
3
+ simo-update = simo.core.management.update:perform_update
@@ -1,8 +0,0 @@
1
- from django.core.management.base import BaseCommand
2
- from simo.core.tasks import update
3
-
4
-
5
- class Command(BaseCommand):
6
-
7
- def handle(self, *args, **options):
8
- update()
File without changes
@@ -1,53 +0,0 @@
1
- #!/usr/bin/env python
2
- import sys
3
- import os
4
- import shutil
5
- import simo
6
- from django.template import Context, Engine
7
- from django.core.management.utils import get_random_secret_key
8
-
9
-
10
- def copy_template(to_directory='/etc/SIMO'):
11
- template_file_extensions = ['.py', '.conf']
12
-
13
- context = Context({
14
- 'secret_key': get_random_secret_key(),
15
- 'project_dir': to_directory,
16
- 'base_dir': to_directory
17
- }, autoescape=False)
18
- template_dir = os.path.join(
19
- os.path.dirname(simo.__file__), '_hub_template'
20
- )
21
- prefix_length = len(template_dir) + 1
22
- for root, dirs, files in os.walk(template_dir):
23
- relative_dir = root[prefix_length:]
24
- target_dir = os.path.join(to_directory, relative_dir)
25
- os.makedirs(target_dir, exist_ok=True)
26
- for filename in files:
27
- if filename.endswith(('.pyo', '.pyc', '.py.class')):
28
- # Ignore some files as they cause various breakages.
29
- continue
30
- old_path = os.path.join(root, filename)
31
- new_path = os.path.join(target_dir, filename)
32
- os.makedirs(target_dir, exist_ok=True)
33
- fn, file_extension = os.path.splitext(new_path)
34
- if file_extension in template_file_extensions:
35
- with open(old_path, encoding='utf-8') as template_file:
36
- content = template_file.read()
37
- template = Engine().from_string(content)
38
- content = template.render(context)
39
- with open(new_path, 'w', encoding='utf-8') as new_file:
40
- new_file.write(content)
41
- else:
42
- shutil.copyfile(old_path, new_path)
43
- shutil.copymode(old_path, new_path)
44
- for dirname in dirs[:]:
45
- if dirname.startswith('.') or dirname == '__pycache__':
46
- dirs.remove(dirname)
47
- else:
48
- os.makedirs(os.path.join(root, dirname), exist_ok=True)
49
-
50
-
51
-
52
- if __name__ == "__main__":
53
- sys.exit(copy_template())
@@ -1,264 +0,0 @@
1
- #!/usr/bin/env python
2
-
3
- """
4
- This should be called after simo has just been installed.
5
- It prepares and powers up SIMO.io hub.
6
- However it is not guaranteed to be fully operational.
7
- """
8
- import os, sys, json, subprocess, socket, shutil, traceback
9
- import simo
10
- from django.template import Context, Engine
11
- from django.core.management.utils import get_random_secret_key
12
-
13
-
14
-
15
- def install_dependencies():
16
-
17
- status = subprocess.call(
18
- 'apt install postgresql libpq-dev postgresql-client '
19
- 'postgresql-client-common python3-pip redis-server supervisor '
20
- 'mosquitto libopenjp2-7 libtiff5 pkg-config libcairo2-dev '
21
- 'libgirepository1.0-dev libcairo2 libudev-dev gdal-bin net-tools '
22
- 'nginx postgis openvpn ffmpeg libsm6 libxext6 ssh keychain -y',
23
- shell=True
24
- )
25
- if status != 0:
26
- print("Unable install required packages.")
27
- return
28
-
29
- return True
30
-
31
-
32
- def get_ip():
33
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
34
- try:
35
- # doesn't even have to be reachable
36
- s.connect(('10.255.255.255', 1))
37
- IP = s.getsockname()[0]
38
- except Exception:
39
- IP = '127.0.0.1'
40
- finally:
41
- s.close()
42
- return IP
43
-
44
-
45
- def copy_template(to_directory='/etc/SIMO'):
46
- template_file_extensions = ['.py', '.conf']
47
-
48
- context = Context({
49
- 'secret_key': get_random_secret_key(),
50
- 'project_dir': to_directory,
51
- 'base_dir': to_directory,
52
- 'venv_path': os.path.dirname(sys.executable),
53
- }, autoescape=False)
54
- template_dir = os.path.join(
55
- os.path.dirname(simo.__file__), 'management', '_hub_template'
56
- )
57
- prefix_length = len(template_dir) + 1
58
- for root, dirs, files in os.walk(template_dir):
59
- relative_dir = root[prefix_length:]
60
- target_dir = os.path.join(to_directory, relative_dir)
61
- os.makedirs(target_dir, exist_ok=True)
62
- for filename in files:
63
- if filename.endswith(('.pyo', '.pyc', '.py.class')):
64
- # Ignore some files as they cause various breakages.
65
- continue
66
- old_path = os.path.join(root, filename)
67
- new_path = os.path.join(target_dir, filename)
68
- os.makedirs(target_dir, exist_ok=True)
69
- fn, file_extension = os.path.splitext(new_path)
70
- if file_extension in template_file_extensions:
71
- with open(old_path, encoding='utf-8') as template_file:
72
- content = template_file.read()
73
- template = Engine().from_string(content)
74
- content = template.render(context)
75
- with open(new_path, 'w', encoding='utf-8') as new_file:
76
- new_file.write(content)
77
- else:
78
- shutil.copyfile(old_path, new_path)
79
- shutil.copymode(old_path, new_path)
80
- for dirname in dirs[:]:
81
- if dirname.startswith('.') or dirname == '__pycache__':
82
- dirs.remove(dirname)
83
- else:
84
- os.makedirs(os.path.join(root, dirname), exist_ok=True)
85
-
86
- manage_py_path = os.path.join(to_directory, 'hub', 'manage.py')
87
- st = os.stat(manage_py_path)
88
- os.chmod(manage_py_path, st.st_mode | 0o111)
89
-
90
-
91
- def install():
92
- # this must be performed on a host machine before simo could be installed.
93
- #
94
- # apt install python3-pip libpq-dev python3-dev -y
95
-
96
- simo_directory = '/etc/SIMO'
97
- installed_flag_file_path = os.path.join(simo_directory, 'is_installed.json')
98
- HUB_DIR = os.path.join(simo_directory, 'hub')
99
-
100
- if os.path.exists(installed_flag_file_path):
101
- print("SIMO.io hub is already installed. ")
102
- print(f"Please delete {installed_flag_file_path} file manually if you want to force this.")
103
- return
104
-
105
- step = 1
106
- print(f"{step}.___________Install dependencies__________________")
107
- status = subprocess.call(
108
- 'apt-add-repository ppa:mosquitto-dev/mosquitto-ppa -y', shell=True
109
- )
110
- if status != 0:
111
- print("Unable to add mosquitto-dev dependency")
112
- print("Installation failed!")
113
- return
114
-
115
- status = subprocess.call('apt-get update -y', shell=True)
116
- if status != 0:
117
- print("Unable to apt-update")
118
- print("Installation failed!")
119
- return
120
- success = install_dependencies()
121
- if not success:
122
- print("Installation failed!")
123
- return
124
-
125
- step += 1
126
- print(f"{step}.___________Copy default template__________________")
127
-
128
- shutil.rmtree(simo_directory, ignore_errors=True)
129
- try:
130
- copy_template(simo_directory)
131
- except Exception as e:
132
- print(traceback.format_exc(), file=sys.stderr)
133
- shutil.rmtree(simo_directory, ignore_errors=True)
134
- return
135
-
136
- step += 1
137
- print(f"{step}.___________Create database__________________")
138
- subprocess.call(
139
- 'sudo -u postgres createuser -s -i -d -r -l -w root',
140
- shell=True
141
- )
142
- subprocess.call('createdb SIMO', shell=True)
143
-
144
- step += 1
145
- print(f"{step}.___________Apply migrations__________________")
146
-
147
- proc = subprocess.Popen(
148
- [os.path.join(HUB_DIR, 'manage.py'), 'migrate'],
149
- cwd=HUB_DIR,
150
- stderr=subprocess.PIPE
151
- )
152
- out, err = proc.communicate()
153
- if proc.returncode:
154
- raise Exception(err.decode())
155
-
156
- step += 1
157
- print(f"{step}.___________Collect statics__________________")
158
- proc = subprocess.Popen(
159
- [os.path.join(HUB_DIR, 'manage.py'), 'collectstatic',
160
- '--noinput'],
161
- cwd=HUB_DIR, stderr=subprocess.PIPE
162
- )
163
- out, err = proc.communicate()
164
- if proc.returncode:
165
- raise Exception(err.decode())
166
-
167
- step += 1
168
- print(f"{step}.___________Configure supervisor__________________")
169
-
170
- try:
171
- os.remove('/etc/supervisor/conf.d/SIMO.conf')
172
- except:
173
- pass
174
-
175
- os.symlink(
176
- f'{simo_directory}/hub/supervisor.conf',
177
- '/etc/supervisor/conf.d/SIMO.conf'
178
- )
179
- os.makedirs('/var/log/simo')
180
- status = subprocess.call(['supervisorctl', 'update', 'all'])
181
- if status != 0:
182
- sys.exit("INSTALLATION FAILED! Unable to start supervisord")
183
-
184
-
185
- step += 1
186
- print("%d._____________ Configure NGINX _________________________" % step)
187
-
188
- try:
189
- os.remove('/etc/nginx/sites-enabled/default')
190
- except:
191
- pass
192
-
193
- os.symlink(
194
- '/etc/SIMO/hub/nginx.conf', '/etc/nginx/sites-enabled/SIMO'
195
- )
196
-
197
- try:
198
- os.remove('/etc/ssl/private/localhost.key')
199
- except:
200
- pass
201
- try:
202
- os.remove('/etc/ssl/certs/localhost.crt')
203
- except:
204
- pass
205
-
206
- status = subprocess.call([
207
- 'openssl', 'req', '-x509', '-nodes', '-days', '36500',
208
- '-newkey', 'rsa:2048',
209
- '-subj', '/C=US/ST=Denial/L=Springfield/O=Dis/CN=simo.io',
210
- '-keyout', '/etc/ssl/private/localhost.key',
211
- '-out', '/etc/ssl/certs/localhost.crt'
212
- ])
213
- if status != 0:
214
- sys.exit(
215
- "INSTALLATION FAILED! Unable to prepare self signed certificate.")
216
-
217
- status = subprocess.call(['service', 'nginx', 'reload'])
218
- if status != 0:
219
- sys.exit("INSTALLATION FAILED! Something is wrong witn NGINX conf.")
220
-
221
- step += 1
222
- print("%d._____________ Configure SSH and Firewall_____________" % step)
223
- new_ssh_conf = ''
224
- with open('/etc/ssh/sshd_config', 'r') as ssh_conf:
225
- line = ssh_conf.readline()
226
- while line:
227
- if line.startswith('PasswordAuthentication'):
228
- line.replace(' yes', ' no')
229
- new_ssh_conf += line
230
-
231
- line = ssh_conf.readline()
232
- with open('/etc/ssh/sshd_config', 'w') as ssh_conf:
233
- ssh_conf.write(new_ssh_conf)
234
-
235
- status = subprocess.call(['service', 'ssh', 'restart'])
236
- if status != 0:
237
- sys.exit("INSTALLATION FAILED! Unable to restart SSH")
238
-
239
- stats = []
240
- stats.append(subprocess.call(['ufw', 'allow', 'ssh']))
241
- stats.append(subprocess.call(['ufw', 'allow', 'http']))
242
- stats.append(subprocess.call(['ufw', 'allow', 'https']))
243
- stats.append(subprocess.call(['ufw', 'allow', '1194']))
244
- stats.append(subprocess.call(['ufw', 'allow', '1883']))
245
- if any(stats):
246
- sys.exit("INSTALLATION FAILED! Unable to update UFW rules")
247
-
248
- status = subprocess.call('echo y | ufw enable', shell=True)
249
- if status != 0:
250
- sys.exit("INSTALLATION FAILED! Unable to enable UFW")
251
-
252
- step += 1
253
- print("%d.__________ PUT UP INSTALL COMPLETE FLAG! _____________________" % step)
254
-
255
- with open(installed_flag_file_path, 'w') as f:
256
- f.write(json.dumps(True))
257
-
258
- print("--------------------------------------------------------------")
259
- print("DONE!")
260
- print("Your SIMO.io Hub is Up and running at: https://%s/" % get_ip())
261
-
262
-
263
- if __name__ == "__main__":
264
- sys.exit(install())
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- simo-install = simo.management.install:install
File without changes