aethernal-agent 0.1.10

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.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.gitlab-ci.yml +23 -0
  4. data/.rspec +2 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/Gemfile +6 -0
  8. data/Gemfile.lock +107 -0
  9. data/README.md +35 -0
  10. data/Rakefile +31 -0
  11. data/Vagrantfile +32 -0
  12. data/aethernal-agent.gemspec +45 -0
  13. data/bin/console +14 -0
  14. data/bin/run-aa-for-test +35 -0
  15. data/bin/setup +8 -0
  16. data/exe/aa-web +7 -0
  17. data/lib/aethernal_agent.rb +34 -0
  18. data/lib/aethernal_agent/apache/apache.rb +70 -0
  19. data/lib/aethernal_agent/apache/templates/aa-user.conf.erb +21 -0
  20. data/lib/aethernal_agent/app.rb +317 -0
  21. data/lib/aethernal_agent/apt.rb +30 -0
  22. data/lib/aethernal_agent/errors.rb +17 -0
  23. data/lib/aethernal_agent/filesystem.rb +178 -0
  24. data/lib/aethernal_agent/loader.rb +56 -0
  25. data/lib/aethernal_agent/manifest.rb +6 -0
  26. data/lib/aethernal_agent/operation.rb +51 -0
  27. data/lib/aethernal_agent/operation_pool.rb +46 -0
  28. data/lib/aethernal_agent/plugins/deluge/deluge.rb +65 -0
  29. data/lib/aethernal_agent/plugins/deluge/manifest.yml +51 -0
  30. data/lib/aethernal_agent/plugins/deluge/meta/deluge.png +0 -0
  31. data/lib/aethernal_agent/plugins/deluge/templates/auth.erb +2 -0
  32. data/lib/aethernal_agent/plugins/deluge/templates/core.conf.erb +95 -0
  33. data/lib/aethernal_agent/plugins/deluge/templates/deluge-web.service.erb +12 -0
  34. data/lib/aethernal_agent/plugins/deluge/templates/deluge.apache.conf.erb +9 -0
  35. data/lib/aethernal_agent/plugins/deluge/templates/deluged.service.erb +12 -0
  36. data/lib/aethernal_agent/plugins/deluge/templates/hostlist.conf.erb +14 -0
  37. data/lib/aethernal_agent/plugins/deluge/templates/web.conf.erb +24 -0
  38. data/lib/aethernal_agent/plugins/filebrowser/filebrowser.rb +45 -0
  39. data/lib/aethernal_agent/plugins/filebrowser/files/filebrowser.service +12 -0
  40. data/lib/aethernal_agent/plugins/filebrowser/manifest.yml +51 -0
  41. data/lib/aethernal_agent/plugins/filebrowser/meta/filebrowser.png +0 -0
  42. data/lib/aethernal_agent/plugins/filebrowser/templates/filebrowser.apache.conf.erb +6 -0
  43. data/lib/aethernal_agent/plugins/gitea/files/gitea.service +12 -0
  44. data/lib/aethernal_agent/plugins/gitea/gitea.rb +64 -0
  45. data/lib/aethernal_agent/plugins/gitea/manifest.yml +53 -0
  46. data/lib/aethernal_agent/plugins/gitea/meta/gitea.png +0 -0
  47. data/lib/aethernal_agent/plugins/gitea/templates/app.ini.erb +68 -0
  48. data/lib/aethernal_agent/plugins/gitea/templates/gitea.apache.conf.erb +6 -0
  49. data/lib/aethernal_agent/plugins/olaris/manifest.yml +52 -0
  50. data/lib/aethernal_agent/plugins/olaris/meta/olaris.png +0 -0
  51. data/lib/aethernal_agent/plugins/olaris/olaris.rb +35 -0
  52. data/lib/aethernal_agent/plugins/olaris/templates/olaris.apache.conf.erb +6 -0
  53. data/lib/aethernal_agent/plugins/olaris/templates/olaris.service.erb +12 -0
  54. data/lib/aethernal_agent/plugins/ombi/manifest.yml +57 -0
  55. data/lib/aethernal_agent/plugins/ombi/meta/ombi.jpeg +0 -0
  56. data/lib/aethernal_agent/plugins/ombi/ombi.rb +81 -0
  57. data/lib/aethernal_agent/plugins/ombi/templates/ombi.apache.conf.erb +6 -0
  58. data/lib/aethernal_agent/plugins/ombi/templates/ombi.service.erb +14 -0
  59. data/lib/aethernal_agent/plugins/plex/files/plex.service +26 -0
  60. data/lib/aethernal_agent/plugins/plex/manifest.yml +49 -0
  61. data/lib/aethernal_agent/plugins/plex/meta/plex.png +0 -0
  62. data/lib/aethernal_agent/plugins/plex/plex.rb +65 -0
  63. data/lib/aethernal_agent/plugins/plex/templates/Preferences.xml.erb +2 -0
  64. data/lib/aethernal_agent/plugins/radarr/files/radarr.service +13 -0
  65. data/lib/aethernal_agent/plugins/radarr/manifest.yml +68 -0
  66. data/lib/aethernal_agent/plugins/radarr/meta/radarr.png +0 -0
  67. data/lib/aethernal_agent/plugins/radarr/radarr.rb +72 -0
  68. data/lib/aethernal_agent/plugins/radarr/templates/config.xml.erb +16 -0
  69. data/lib/aethernal_agent/plugins/radarr/templates/radarr.apache.conf.erb +6 -0
  70. data/lib/aethernal_agent/plugins/sonarr/files/sonarr.service +13 -0
  71. data/lib/aethernal_agent/plugins/sonarr/manifest.yml +66 -0
  72. data/lib/aethernal_agent/plugins/sonarr/meta/sonarr.jpeg +0 -0
  73. data/lib/aethernal_agent/plugins/sonarr/sonarr.rb +70 -0
  74. data/lib/aethernal_agent/plugins/sonarr/templates/config.xml.erb +16 -0
  75. data/lib/aethernal_agent/plugins/sonarr/templates/sonarr.apache.conf.erb +6 -0
  76. data/lib/aethernal_agent/plugins/vnc/files/xstartup +9 -0
  77. data/lib/aethernal_agent/plugins/vnc/manifest.yml +41 -0
  78. data/lib/aethernal_agent/plugins/vnc/meta/vnc.png +0 -0
  79. data/lib/aethernal_agent/plugins/vnc/templates/vnc.service.erb +14 -0
  80. data/lib/aethernal_agent/plugins/vnc/vnc.rb +41 -0
  81. data/lib/aethernal_agent/systemd.rb +123 -0
  82. data/lib/aethernal_agent/template.rb +57 -0
  83. data/lib/aethernal_agent/utils.rb +107 -0
  84. data/lib/aethernal_agent/version.rb +3 -0
  85. data/lib/aethernal_agent/webserver/api.rb +77 -0
  86. data/lib/aethernal_agent/webserver/core.rb +32 -0
  87. metadata +257 -0
@@ -0,0 +1,57 @@
1
+ name: Ombi
2
+ script_name: ombi.rb
3
+ version: 0.1
4
+ required_aethernal_agent_version: "~> 0.1.0"
5
+ description: Ombi is a self-hosted web application that automatically gives your shared Plex or Emby users the ability to request content by themselves!
6
+ installation_type: local_install
7
+ configuration_type: multi_user
8
+ apache_configuration: ombi.apache.conf.erb
9
+ icon:
10
+ name: ombi.jpeg
11
+ sha256sum: 1cc73f52ebff93f11c0a54c9743d084016f1b7567ee60ddd9107169702ae0b73
12
+ plain_name: ombi
13
+ services:
14
+ - ombi
15
+ actions:
16
+ restart:
17
+ user:
18
+ required: true
19
+ linux_user: true
20
+ uninstall:
21
+ nothing: true
22
+ install_packages:
23
+ user:
24
+ required: true
25
+ linux_user: true
26
+ remove_app_user:
27
+ user:
28
+ required: true
29
+ linux_user: true
30
+ configure_app_user:
31
+ port:
32
+ auto_generate_port: true
33
+ min: 7900
34
+ max: 7999
35
+ user:
36
+ required: true
37
+ linux_user: true
38
+ password:
39
+ required: false
40
+ auto_generate: true
41
+ return_values:
42
+ - password
43
+ - port
44
+ estimated_size_mb: 23
45
+ package:
46
+ folder_name: ombi
47
+ direct_download:
48
+ url: https://github.com/tidusjar/Ombi/releases/download/v3.0.4892/linux.tar.gz
49
+ target_name: linux.tar.gz
50
+ auto_extract: true
51
+ always_latest: false
52
+ apt:
53
+ "18.04":
54
+ packages:
55
+ - libicu-dev
56
+ - libunwind8
57
+ - libcurl4-openssl-dev
@@ -0,0 +1,81 @@
1
+ require 'httparty'
2
+
3
+ class AethernalAgent::Ombi < AethernalAgent::App
4
+
5
+ def initialize(options = {})
6
+ super(options)
7
+ end
8
+
9
+ def install_packages(options = {})
10
+ remove_app_user
11
+ directory(ombi_config_path, action: :create)
12
+ super(options)
13
+ end
14
+
15
+ def remove_app_user(options = {})
16
+ super(options) do |opts|
17
+ directory(app_path, action: :delete)
18
+ directory(ombi_config_path, action: :delete)
19
+ end
20
+ end
21
+
22
+ def configure_app_user(options = {})
23
+ self.install_packages(options)
24
+ super(options) do |opts|
25
+ ensure_permissions
26
+ @timer = 0
27
+ @opts = opts
28
+ end
29
+ add_user_to_db
30
+ return create_return_args(@opts)
31
+ end
32
+
33
+ protected
34
+
35
+ def ombi_config_path(path ="/")
36
+ File.join(home_folder_path(".config/ombi"), path)
37
+ end
38
+
39
+ def source_name
40
+ self.manifest.package['direct_download']['target_name']
41
+ end
42
+
43
+ def ensure_permissions
44
+ file(app_path("Ombi"), chmod: 0755, owner: self.user)
45
+ file(app_path, owner: self.user)
46
+ file(ombi_config_path, owner: self.user)
47
+ end
48
+
49
+ def add_user_to_db
50
+ begin
51
+ AethernalAgent.logger.info("Calling Ombi API to create our initial user for #{self.user}")
52
+ url = URI(ombi_api_url(@opts["port"], "Identity/Wizard"))
53
+ AethernalAgent.logger.info(url)
54
+ body = {username: self.user, password: @opts["password"], usePlexAdminAccount: false}.to_json
55
+ update_ombi_db(url, body)
56
+ rescue
57
+ @timer += 1
58
+ sleep 60
59
+ if @timer < 6
60
+ add_user_to_db
61
+ end
62
+ end
63
+ end
64
+
65
+ def ombi_api_url(web_port, path)
66
+ return "http://127.0.0.1:#{web_port}/api/v1/#{path}"
67
+ end
68
+
69
+ def update_ombi_db(url, body, token=nil)
70
+ HTTParty.post(url, headers: headers(token), body: body)
71
+ end
72
+
73
+ def headers(token=nil)
74
+ if token
75
+ { 'Content-Type' => 'application/json',
76
+ 'Authorization' => "Bearer #{token}"}
77
+ else
78
+ { 'Content-Type' => 'application/json'}
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,6 @@
1
+ Redirect "/ombi" "/ombi/app"
2
+ <Location /ombi/>
3
+ ProxyPass http://localhost:<%= @port %>
4
+ ProxyPassReverse http://localhost:<%= @port %>
5
+ Require all granted
6
+ </Location>
@@ -0,0 +1,14 @@
1
+ [Unit]
2
+ Description=Ombi - PMS Requests System
3
+ After=network-online.target
4
+
5
+ [Service]
6
+ WorkingDirectory=%h/apps/ombi/
7
+ ExecStart=%h/apps/ombi/Ombi --host "http://*:<%= @port %>"
8
+ Type=simple
9
+ TimeoutStopSec=30
10
+ Restart=on-failure
11
+ RestartSec=5
12
+
13
+ [Install]
14
+ WantedBy=multi-user.target
@@ -0,0 +1,26 @@
1
+ [Unit]
2
+ Description=Plex Media Server
3
+ After=network.target network-online.target
4
+
5
+ [Service]
6
+ Environment="PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/var/lib/plexmediaserver/Library/Application Support"
7
+ Environment=PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver
8
+ Environment=PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
9
+ Environment=PLEX_MEDIA_SERVER_TMPDIR=/tmp
10
+ ExecStartPre=/bin/sh -c '/usr/bin/test -d "${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}" || /bin/mkdir -p "${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}"'
11
+ ExecStart=/bin/sh -c '\
12
+ export PLEX_MEDIA_SERVER_INFO_VENDOR="$(grep ^NAME= /etc/os-release | awk -F= "{print \\$2}" | tr -d \\" )"; \
13
+ export PLEX_MEDIA_SERVER_INFO_DEVICE="PC"; \
14
+ export PLEX_MEDIA_SERVER_INFO_MODEL="$(uname -m)"; \
15
+ export PLEX_MEDIA_SERVER_INFO_PLATFORM_VERSION="$(grep ^VERSION= /etc/os-release | awk -F= "{print \\$2}" | tr -d \\" )"; \
16
+ export LD_LIBRARY_PATH=/usr/lib/plexmediaserver/lib; \
17
+ exec "/usr/lib/plexmediaserver/Plex Media Server"'
18
+ Type=simple
19
+ Restart=on-failure
20
+ RestartSec=5
21
+ StartLimitInterval=60s
22
+ StartLimitBurst=3
23
+ SyslogIdentifier=Plex Media Server
24
+
25
+ [Install]
26
+ WantedBy=multi-user.target
@@ -0,0 +1,49 @@
1
+ name: Plex Media Server
2
+ script_name: plex.rb
3
+ version: 0.1
4
+ required_aethernal_agent_version: "~> 0.1.0"
5
+ description: Plex is plex, I guess
6
+ installation_type: global_install
7
+ configuration_type: server_wide
8
+ plain_name: plex
9
+ built_in_updater: false
10
+ icon:
11
+ name: plex.png
12
+ sha256sum: 2c35c38cb223826938c96faff20bee4fc32df728a34028119a61832657f8f997
13
+ services:
14
+ - plex
15
+ actions:
16
+ claim:
17
+ claim_token:
18
+ required: true
19
+ user:
20
+ required: true
21
+ linux_user: true
22
+ restart:
23
+ user:
24
+ required: true
25
+ linux_user: true
26
+ configure_app_user:
27
+ claim_token:
28
+ required: true
29
+ hint: You can grab your claim token from https://plex.tv/claim
30
+ port:
31
+ value: 32400
32
+ external_port: plex_port
33
+ read_only: true
34
+ host_port:
35
+ required: false
36
+ user:
37
+ required: true
38
+ linux_user: true
39
+ display_values:
40
+ estimated_size_mb: 30
41
+ package:
42
+ apt:
43
+ "18.04":
44
+ add_sources:
45
+ plex:
46
+ source_url: "deb https://downloads.plex.tv/repo/deb public main"
47
+ key_url: "https://downloads.plex.tv/plex-keys/PlexSign.key"
48
+ packages:
49
+ - plexmediaserver
@@ -0,0 +1,65 @@
1
+ class AethernalAgent::Plex < AethernalAgent::App
2
+ def initialize(options = {})
3
+ super(options)
4
+ end
5
+
6
+ def install_packages(options = {})
7
+ super(options)
8
+ end
9
+
10
+ def uninstall_packages(options = {})
11
+ super(options)
12
+
13
+ directory("/var/lib/plexmediaserver", action: :delete)
14
+ directory("/usr/lib/plexmediaserver", action: :delete)
15
+ end
16
+
17
+ def remove_app_user(options = {})
18
+ super(options) do |opts|
19
+ directory("/var/lib/plexmediaserver/", action: :delete)
20
+ directory("/usr/lib/plexmediaserver/", action: :delete)
21
+ end
22
+ end
23
+
24
+ def configure_app_user(options = {})
25
+ #TODO: Do error handling here.
26
+ install_packages(options)
27
+
28
+ # Plex runs automatically after installing so let's stop it.
29
+ run_command("systemctl daemon-reload")
30
+ run_command("service plexmediaserver stop")
31
+
32
+ directory("/var/lib/plexmediaserver", owner: self.user)
33
+ directory("/usr/lib/plexmediaserver", owner: self.user)
34
+ file("/lib/systemd/system/plexmediaserver.service", action: :delete)
35
+
36
+
37
+ result = super(options) do |opts|
38
+ container_domain = "#{get_global_config(:container_name)}.#{get_global_config(:hostname)}"
39
+ write_template(template_path('Preferences.xml.erb'),
40
+ '/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Preferences.xml',
41
+ opts.merge(domain: container_domain),
42
+ {owner: self.user})
43
+ end
44
+
45
+ return result if result[:errors].present?
46
+
47
+ # We will have to do this after the service files have been created so we can't do this inside the super itself
48
+ reload_systemd_config
49
+ start
50
+
51
+ AethernalAgent.logger.debug("Sleeping to wait for Plex server start-up")
52
+ sleep 30
53
+ self.claim(result[:options])
54
+
55
+ return create_return_args(result[:options])
56
+ end
57
+
58
+ def claim(options = {})
59
+ AethernalAgent.logger.info("Claiming server")
60
+ ensure_action_options('claim', options)
61
+ run_command("curl -v -X POST http://127.0.0.1:32400/myplex/claim?token=#{options['claim_token']}")
62
+ AethernalAgent.logger.info("Done claiming server")
63
+ return create_return_args(options)
64
+ end
65
+ end
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Preferences ManualPortMappingPort="<%= @host_port %>" PublishServerOnPlexOnlineKey="1" ManualPortMappingMode="1" customConnections="http://<%= @domain%>:<%= @host_port %>" MetricsEpoch="0"/>
@@ -0,0 +1,13 @@
1
+ [Unit]
2
+ Description=Radarr Daemon
3
+ After=syslog.target network.target
4
+
5
+ [Service]
6
+ Type=simple
7
+ ExecStart=/usr/bin/mono --debug %h/apps/radarr/Radarr.exe -nobrowser
8
+ TimeoutStopSec=20
9
+ KillMode=process
10
+ Restart=on-failure
11
+
12
+ [Install]
13
+ WantedBy=multi-user.target
@@ -0,0 +1,68 @@
1
+ name: Radarr
2
+ script_name: radarr.rb
3
+ version: 0.1
4
+ required_aethernal_agent_version: "~> 0.1.0"
5
+ description: Radarr is an independent fork of Sonarr reworked for automatically downloading movies via Usenet and BitTorrent.
6
+ installation_type: local_install
7
+ configuration_type: multi_user
8
+ apache_configuration: radarr.apache.conf.erb
9
+ icon:
10
+ name: radarr.png
11
+ sha256sum: aadfe91299aa9fbf4a027566fdd0102fc455e7d2224c22ea886c22520e039a51
12
+ plain_name: radarr
13
+ services:
14
+ - radarr
15
+ actions:
16
+ restart:
17
+ user:
18
+ required: true
19
+ linux_user: true
20
+ uninstall:
21
+ nothing: true
22
+ install_packages:
23
+ user:
24
+ required: true
25
+ linux_user: true
26
+ remove_app_user:
27
+ user:
28
+ required: true
29
+ linux_user: true
30
+ configure_app_user:
31
+ port:
32
+ auto_generate_port: true
33
+ min: 6900
34
+ max: 6999
35
+ ssl_port:
36
+ auto_generate_port: true
37
+ min: 7900
38
+ max: 7999
39
+ user:
40
+ required: true
41
+ linux_user: true
42
+ password:
43
+ required: false
44
+ auto_generate: true
45
+ return_values:
46
+ - password
47
+ - port
48
+ display_values:
49
+ - user
50
+ - password
51
+ estimated_size_mb: 23
52
+ package:
53
+ folder_name: Radarr
54
+ direct_download:
55
+ url: https://github.com/Radarr/Radarr/releases/download/v0.2.0.1450/Radarr.develop.0.2.0.1450.linux.tar.gz
56
+ target_name: Radarr.develop.0.2.0.1450.linux.tar.gz
57
+ auto_extract: true
58
+ always_latest: false
59
+ apt:
60
+ "18.04":
61
+ add_sources:
62
+ mono_stable:
63
+ source_url: "deb https://download.mono-project.com/repo/ubuntu stable-bionic main"
64
+ key_id: "3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"
65
+ packages:
66
+ - gnupg
67
+ - ca-certificates
68
+ - mono-devel
@@ -0,0 +1,72 @@
1
+ class AethernalAgent::Radarr < AethernalAgent::App
2
+ def initialize(options = {})
3
+ super(options)
4
+ end
5
+
6
+ def install_packages(options = {})
7
+ remove_app_user
8
+
9
+ super(options)
10
+
11
+ file(app_path, chmod: 711, owner: self.user)
12
+ FileUtils.mv(app_path + "/Radarr", app_path + "/radarr")
13
+ FileUtils.mv(app_path + "/radarr", home_folder_path(File.join("apps")))
14
+ directory(app_path, action: :delete)
15
+ end
16
+
17
+ def remove_app_user(options = {})
18
+ super(options) do |opts|
19
+ directory(home_folder_path("/apps/radarr"), action: :delete)
20
+ directory(home_folder_path("/apps/Radarr"), action: :delete)
21
+ directory(home_folder_path("/.config/Radarr"), action: :delete)
22
+ end
23
+ end
24
+
25
+ def configure_app_user(options = {})
26
+ self.install_packages(options)
27
+
28
+ super(options) do |opts|
29
+ @vars = {
30
+ api_key: Digest::SHA256.hexdigest(Time.now.to_i.to_s + "aethernal")[0..32],
31
+ port: opts['port'],
32
+ ssl_port: opts['ssl_port'],
33
+ password: opts['password'],
34
+ user: self.user}
35
+
36
+ write_template(template_path('config.xml.erb'),
37
+ radarr_config_path('config.xml'),
38
+ @vars,
39
+ {owner: @vars[:user]})
40
+ end
41
+ # If we run this within the super we have no systemd scripts yet so we need to do this after everything has been setup except the user.
42
+ add_user_to_db
43
+ return create_return_args(@vars)
44
+ end
45
+
46
+ protected
47
+
48
+ def radarr_config_path(path ="/")
49
+ File.join(home_folder_path(".config/Radarr"), path)
50
+ end
51
+
52
+ def add_user_to_db
53
+ # We need to start it for the database and migrations to be created
54
+ start
55
+ # Let's sleep a bit so we have some guarantee that the database has been migrated properly
56
+ sleep 120
57
+ # Let's stop it so we can mess with the database, not sure this is needed
58
+ stop
59
+ begin
60
+ db = SQLite3::Database.open(home_folder_path(".config/Radarr/nzbdrone.db"))
61
+ # Add default user
62
+ db.execute "INSERT INTO Users VALUES (1, 'e852a6bb-6812-4e6c-8f99-f8c3c5201594', '#{self.user}', '#{Digest::SHA256.hexdigest(@vars[:password])}');"
63
+ rescue SQLite3::Exception => e
64
+ raise "Error setting up Radarr: #{e}"
65
+ ensure
66
+ db.close if db
67
+ end
68
+
69
+ start
70
+ end
71
+
72
+ end