summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2020-03-18 22:57:24 -0400
committerbill-auger <mr.j.spam.me@gmail.com>2020-04-13 01:27:35 -0400
commitdd799580b377d623b80873d39bc0bc32b877f157 (patch)
tree25e9570f8a797e3de4af4df0d39e00f416355afb
parent36fe9082d4c703f504427ee9273bb6cbb196a3ba (diff)
wip - display metadata
-rw-r--r--app/controllers/downloads_controller.rb110
-rw-r--r--app/models/download.rb39
-rw-r--r--app/views/downloads/index.html.erb6
-rw-r--r--app/views/downloads/select.html.erb32
-rw-r--r--config/initializers/downloads_constants.rb20
5 files changed, 143 insertions, 64 deletions
diff --git a/app/controllers/downloads_controller.rb b/app/controllers/downloads_controller.rb
index 6d3741399..0231e1973 100644
--- a/app/controllers/downloads_controller.rb
+++ b/app/controllers/downloads_controller.rb
@@ -20,63 +20,75 @@
class DownloadsController < ApplicationController
- def index
- parse_params
+ before_action { parse_params ; collect_images ; }
- if all_params_satisfied?
+
+ def index
+ if @all_params_satisfied
redirect_to redirect_url
else
- @qemu_images = collect_images RELEASES_DIR , QEMUS_GLOB , RELEASES_URL
- @preview_images = collect_images PREVIEWS_DIR , PREVIEWS_GLOB , PREVIEWS_URL
-
render :index , :layout => 'download'
end
end
def select
- parse_params
-
- if all_params_satisfied?
- redirect_to redirect_url
+ if @all_params_satisfied
+ redirect_to redirect_url and return if @redirect_requested
+ elsif @nojs
+ @image_options = IMAGE_OPTIONS.deep_dup.map { | param_data | image_options param_data }
else
@image_options = IMAGE_OPTIONS.deep_dup
-
- @image_options.map! { | param_data | nojs_image_options param_data } if @nojs
-
- render :select , :layout => nil
end
+
+ render :select , :layout => nil
end
private
def parse_params
- (@arch = params['arch' ]) if (VALID_RELEASE_ARCHES .include? params['arch' ])
- (@init = params['init' ]) if (VALID_RELEASE_INITS .include? params['init' ])
- (@wmde = params['wmde' ]) if (VALID_RELEASE_WMDES .include? params['wmde' ])
- (@install = params['install']) if (VALID_RELEASE_INSTALLS.include? params['install'])
- (@nojs = true ) if params['nojs'].present?
+ # NOTE: nojs
+ # image parameters are accumulated as a "stack" of RESTful queries,
+ # in the order of the parameters below (and as defiend in IMAGE_PARAMS)
+ # the instance var corresponding to the first unset query parameter
+ # and each successive instance var will be nil,
+ # because options may depend on the selections of preceding parameters
+ # see also the note in the 'nojs_image_options' method
+ ((@arch = params['arch' ]) if (VALID_RELEASE_ARCHES .include? params['arch' ])) &&
+ ((@init = params['init' ]) if (VALID_RELEASE_INITS .include? params['init' ])) &&
+ ((@wmde = params['wmde' ]) if (VALID_RELEASE_WMDES .include? params['wmde' ])) &&
+ ((@install = params['install']) if (VALID_RELEASE_INSTALLS.include? params['install']))
# NOTE: brittle details regarding the current release-sets
# armv7h has only one release image: a systemd/cli tarball
- # i686 and x86_64 have only one release image each per init/WMDE combination: a netinstall image
- # there is only one 'complete' release image per init/WMDE combination: a dual-arch image
- if @arch == 'armv7h'
- @init = 'systemd' ; @wmde = 'cli' ; @install = 'tarball'
- elsif ([ 'i686' 'x86_64' ].include? @arch) && @install == 'complete' && all_params_satisfied?
- @arch = 'dual'
- end
+# if @arch == 'armv7h' ; @init = 'systemd' ; @wmde = 'cli' ; @install = 'tarball' ; end ;
+
+# @image_params = { :arch => @arch , :init => @init ,
+# :wmde => @wmde , :install => @install }
+# @all_params_satisfied = @image_params.values.all? &:present?
- @image_params = { :arch => @arch , :init => @init , :wmde => @wmde , :install => @install }
+ @nojs = params['nojs' ].present?
+ @redirect_requested = params['download'].present?
end
- def all_params_satisfied?
- @arch.present? && @init.present? && @wmde.present? && @install.present?
+ def collect_images
+ @release_images = Download.collect_images RELEASES_DIR , RELEASES_GLOB , RELEASES_URL
+ @qemu_images = Download.collect_images RELEASES_DIR , QEMUS_GLOB , RELEASES_URL
+ @preview_images = Download.collect_images PREVIEWS_DIR , PREVIEWS_GLOB , PREVIEWS_URL
+ @selectable_images = select_images
+ @all_params_satisfied = @selectable_images.size == 1
end
def redirect_url
parse_params unless all_params_satisfied?
+ release_image = find_release_image
+
+ (release_img.present?) ? "#{RELEASES_URL}/#{release_img}" : DOWNLOADS_URL
+ end
+
+=begin
+ def find_release_image
if all_params_satisfied?
variant = "#{@arch}-#{@init}-#{@wmde}-"
releases = Dir.children "#{RELEASES_DIR}/"
@@ -88,36 +100,32 @@ private
release_img = ''
end
- (release_img.present?) ? "#{RELEASES_URL}/#{release_img}" : DOWNLOADS_URL
+ release_img
end
-
- def collect_images base_dir , glob , base_url
- images_sigs = Dir.glob "#{base_dir}#{glob}"
- images_data = images_sigs.map do | sig |
- file_path = sig.gsub SIGS_REGEX , '\1'
-
- {
- :url => "#{base_url}/#{file_path}" ,
- :name => "#{file_path.gsub /.*\// , ''}" ,
- :size => (File.size "#{base_dir}/#{file_path}")
- }
+=end
+ def select_images
+ @release_images.select do | image_data |
+ (@arch .nil? || image_data[:arch ] == @arch ) &&
+ (@init .nil? || image_data[:init ] == @init ) &&
+ (@wmde .nil? || image_data[:wmde ] == @wmde ) &&
+ (@install.nil? || image_data[:install] == @install)
end
-
- (images_data.empty?) ? [ {} ] : images_data
end
- def nojs_image_options param_data
- param_id = param_data [:param_id]
- selected_value = @image_params[param_id ]
+ def image_options param_data
+# param_id = param_data [:param_id]
+# selected_value = @image_params[param_id ]
+ param_id = param_data[:param_id]
+ selected_value = (eval param_id) if IMAGE_PARAMS.include? param_id
- # @image_options are accumulated as a "stack" of RESTful queries,
- # in the order of the parameters defiend in IMAGE_OPTIONS
+ # NOTE: nojs
+ # image parameters are accumulated as a "stack" of RESTful queries,
+ # in the order of the parameters defiend in IMAGE_PARAMS
# the first unset query parameter becomes the @nojs_current_param_id,
# which indicates the currently visible option set to be presented
# the default selection of each successive parameter is then set to nil
- # in order to maintain that "loop invariant" in each successive request
- # any holes in the stack will cause the stack to rewind,
- # because options may depend on selections of preceding parameters
+ # because options may depend on the selections of preceding parameters
+ # see also the note in the 'parse_params' method
if @nojs_current_param_id.present?
param_data[:default] = nil
elsif selected_value.present?
diff --git a/app/models/download.rb b/app/models/download.rb
new file mode 100644
index 000000000..50d2f32ce
--- /dev/null
+++ b/app/models/download.rb
@@ -0,0 +1,39 @@
+class Download < ActiveRecord::Base
+
+ def self.collect_images base_dir , glob , base_url
+ image_sigs = Dir.glob "#{base_dir}#{glob}"
+ images_data = image_sigs.map do | sig |
+ image_rel_path = sig.gsub SIG_FILE_REGEX , '\1'
+ local_abs_path = "#{base_dir}/#{image_rel_path}"
+ image_url = "#{base_url}/#{image_rel_path}"
+ release_dir = image_rel_path.gsub /\/[^\/]*/ , ''
+ image_name = image_rel_path.gsub /.*\// , ''
+ image_params = (image_name.match IMAGE_FILE_REGEX).named_captures
+ image_size = (File.size "#{local_abs_path}") if File.exist? local_abs_path
+ pkglist = "#{release_dir}/pkglist.#{image_params['arch']}.txt"
+ kernel_ver = parse_kernel_version pkglist
+ release_dir_url = "#{base_url}/#{release_dir}"
+ pkglist_url = "#{release_dir_url}/#{pkglist}" # FIXME:
+ magnet = "#{local_abs_path}.magnet"
+ magnet_uri = (File.read magnet).trim if File.exist? magnet
+ torrent_url = "#{image_url}.torrent"
+ checksums_url = "#{release_dir_url}/SHA512SUMS"
+ signature_url = "#{image_url}.sig"
+ gpg_key = `pgpdump #{local_abs_path} | grep 'Key ID' | cut -d '-' -f 2`
+ gpg_key_url = "#{GPG_LOOKUP_URL}#{gpg_key}"
+ image_data_keys = [ :image_url , :image_name , :image_size , :kernel_ver ,
+ :pkglist_url , :magnet_uri , :torrent_url , :checksums_url ,
+ :signature_url , :gpg_key_url ]
+
+ image_data_keys.to_h { | key | ; [ key , (eval key.to_s) ] }.merge image_params
+ end
+
+ (images_data.present?) ? images_data : [ {} ]
+ end
+
+ def self.parse_kernel_version pkglist
+ kernel_line = ((File.foreach pkglist).grep KERNEL_REGEX).first if File.exist? pkglist
+ kernel_ver = (kernel_line.present?) ? (kernel_line.gsub KERNEL_REGEX , '\1').strip : ''
+ end
+
+end
diff --git a/app/views/downloads/index.html.erb b/app/views/downloads/index.html.erb
index 0adac8cc1..d95a3980e 100644
--- a/app/views/downloads/index.html.erb
+++ b/app/views/downloads/index.html.erb
@@ -29,9 +29,9 @@
<% def images_table images_data %>
<table class="releases-images-table">
<% images_data.each do | image_data | %>
- <% image_url = image_data [:url ] %>
- <% image_name = image_data [:name] %>
- <% image_size = image_data [:size] %>
+ <% image_url = image_data[:image_url ] %>
+ <% image_name = image_data[:image_name] %>
+ <% image_size = image_data[:image_size] %>
<tr>
<% if image_url.present? && image_name.present? && image_size.present? %>
<td class="releases-image-td"><a href="<%= image_url %>"><%= image_name %></a></td>
diff --git a/app/views/downloads/select.html.erb b/app/views/downloads/select.html.erb
index c9e04eae6..e10292347 100644
--- a/app/views/downloads/select.html.erb
+++ b/app/views/downloads/select.html.erb
@@ -49,18 +49,38 @@
</table>
<% end %>
-<input id="release-nojs-input" type="text" name="nojs" value="true" style="display: none ;" />
+<input id="release-nojs-input" type="text" name="nojs" value="true" style="display: none ;" />
+<input id="release-download-input" type="text" name="download" value="<%= @all_params_satisfied %>" style="display: none ;" />
<% end %>
<form id="release-select-form" action="/downloads/select" method="get">
<table id="release-select-inputs-table">
<tr>
-<% if @nojs && @nojs_current_param_id != :install %>
+<% if @nojs && ! @all_params_satisfied %>
<td><a id="release-select-bwd-a" href="/downloads/select">Back</a><br />
<button id="release-select-fwd-button" type="submit">Accept</button></td>
<% else %>
- <td><button id="release-select-fwd-button" type="submit">Download</button></td>
+ <td>
+ <% if @all_params_satisfied %>
+ <% image_size = @release_images[:image_size ] %>
+ <% kernel_ver = @release_images[:kernel_ver ] %>
+ <% pkglist_url = @release_images[:pkglist_url ] %>
+ <% magnet_uri = @release_images[:magnet_uri ] %>
+ <% torrent_url = @release_images[:torrent_url ] %>
+ <% checksums = @release_images[:checksums_url] %>
+ <% signature_url = @release_images[:signature_url] %>
+ <% gpg_key_url = @release_images[:gpg_key_url ] %>
+ Kernel: <%= kernel_ver %><br />
+ Size: <%= image_size %><br />
+ <a id="release-select-pkgs-a" href="<%= pkglist_url %>">Packages</a ><br />
+ <a id="release-select-magnet-a" href="<%= magnet_uri %>">Magnet</a ><br />
+ <a id="release-select-torrent-a" href="<%= torrent_url %>">Torrent</a ><br />
+ <a id="release-select-sums-a" href="<%= checksums %>">SHA512SUMS</a ><br />
+ <a id="release-select-sig-a" href="<%= signature_url %>">Signature</a ><br />
+ <a id="release-select-gpg-a" href="<%= gpg_key_url %>">Signing Key</a><br />
+ <% end %>
+ <button id="release-select-fwd-button" type="submit">Download</button></td>
<% end %>
<td id="nojs-inputs-td"><% inputs_table %></td>
</tr>
@@ -69,10 +89,12 @@
<script type="text/javascript">
- var nojs_input = document.getElementById ('release-nojs-input' ) ;
- var input_tables = document.getElementsByClassName('release-select-input-table') ;
+ var nojs_input = document.getElementById ('release-nojs-input' ) ;
+ var download_input = document.getElementById ('release-download-input' ) ;
+ var input_tables = document.getElementsByClassName('release-select-input-table') ;
nojs_input.parentNode.removeChild(nojs_input) ;
+ download_input.value = true ;
for (var table_n = 0 ; table_n < input_tables.length ; ++table_n)
{ input_tables[table_n].style.display = 'block' }
</script>
diff --git a/config/initializers/downloads_constants.rb b/config/initializers/downloads_constants.rb
index 35875ef6a..554ea1532 100644
--- a/config/initializers/downloads_constants.rb
+++ b/config/initializers/downloads_constants.rb
@@ -1,3 +1,9 @@
+ARCH_KEY = :arch
+INIT_KEY = :init
+WMDE_KEY = :wmde
+INSTALL_KEY = :install
+IMAGE_PARAMS = [ ARCH_KEY , INIT_KEY , WMDE_KEY , INSTALL_KEY ]
+
ARCH_ARMV7H = 'armv7h'
ARCH_I686 = 'i686'
ARCH_X8664 = 'x86_64'
@@ -39,7 +45,7 @@ VALID_RELEASE_INSTALLS = [ INSTALL_COMPLETE , INSTALL_NETINSTALL
IMAGE_ARCH_OPTIONS =
{
- :param_id => :arch ,
+ :param_id => ARCH_KEY ,
:prompt => ARCH_PROMPT ,
:default => ARCH_X8664 ,
:options => [ { :option_id => ARCH_ARMV7H , :label => ARCH_ARMV7H , :desc => ARMV7H_DESC } ,
@@ -49,7 +55,7 @@ IMAGE_ARCH_OPTIONS =
}
IMAGE_INIT_OPTIONS =
{
- :param_id => :init ,
+ :param_id => INIT_KEY ,
:prompt => INIT_PROMPT ,
:default => INIT_SYSTEMD ,
:options => [ { :option_id => INIT_OPENRC , :label => OPENRC_LABEL , :desc => OPENRC_DESC } ,
@@ -57,7 +63,7 @@ IMAGE_INIT_OPTIONS =
}
IMAGE_WMDE_OPTIONS =
{
- :param_id => :wmde ,
+ :param_id => WMDE_KEY ,
:prompt => WMDE_PROMPT ,
:default => WMDE_LXDE ,
:options => [ { :option_id => WMDE_CLI , :label => CLI_LABEL , :desc => CLI_DESC } ,
@@ -66,7 +72,7 @@ IMAGE_WMDE_OPTIONS =
}
IMAGE_INSTALL_OPTIONS =
{
- :param_id => :install ,
+ :param_id => INSTALL_KEY ,
:prompt => INSTALL_PROMPT ,
:default => INSTALL_NETINSTALL ,
:options => [ { :option_id => INSTALL_COMPLETE , :label => COMPLETE_LABEL , :desc => COMPLETE_DESC } ,
@@ -121,9 +127,12 @@ PREVIEWS_DIRNAME = 'iso-nightly'
REPO_DIR = '/srv/http/repo.parabola.nu'
RELEASES_DIR = "#{REPO_DIR}/#{RELEASES_DIRNAME}"
PREVIEWS_DIR = "#{REPO_DIR}/#{PREVIEWS_DIRNAME}"
+RELEASES_GLOB = '/*/parabola-*.iso.sig'
QEMUS_GLOB = '/*/parabola-*image.img.sig'
PREVIEWS_GLOB = '/*/parabola-*.sig'
-SIGS_REGEX = /.*\/([^\/]+\/parabola-.+).sig/
+SIG_FILE_REGEX = /^.*\/([^\/]+\/parabola-.+).sig$/
+IMAGE_FILE_REGEX = /^parabola-(?<arch>[^-]+)-(?<init>[^-]+)-(?<wmde>[^-]+)-(?<date>[^-]+)-(?<install>[^-]+)\..+$/
+KERNEL_REGEX = /^libre\/linux-libre-([0-9.]+)-.*$/
if Rails.env == 'production'
RELEASES_URL = "https://redirector.parabola.nu/#{RELEASES_DIRNAME}"
PREVIEWS_URL = "https://repo.parabola.nu/#{PREVIEWS_DIRNAME}"
@@ -133,3 +142,4 @@ else
PREVIEWS_URL = "/#{PREVIEWS_DIRNAME}"
DOWNLOADS_URL = '/downloads'
end
+GPG_LOOKUP_URL = "http://keys.gnupg.net/pks/lookup?op=vindex&search="