VideoJS dep manager: Add ability to skip checksum

This commit is contained in:
syeopite 2024-02-18 12:49:36 -08:00
parent 1e6ec605e8
commit 392e447969
No known key found for this signature in database
GPG Key ID: A73C186DA3955A1A
2 changed files with 31 additions and 7 deletions

View File

@ -4,11 +4,22 @@ require "digest/sha1"
require "option_parser"
require "colorize"
# Hacky solution to get separated arguments when called from invidious.cr
if ARGV.size == 1
parser_args = [] of String
ARGV[0].split(",") { |str| parser_args << str.strip }
else
parser_args = ARGV
end
# Taken from https://crystal-lang.org/api/1.1.1/OptionParser.html
minified = false
OptionParser.parse do |parser|
skip_checksum = false
OptionParser.parse(parser_args) do |parser|
parser.banner = "Usage: Fetch VideoJS dependencies [arguments]"
parser.on("-m", "--minified", "Use minified versions of VideoJS dependencies (performance and bandwidth benefit)") { minified = true }
parser.on("--skip-checksum", "Skips the checksum validation of downloaded files") { skip_checksum = true }
parser.on("-h", "--help", "Show this help") do
puts parser
@ -89,7 +100,7 @@ dependencies_to_install.each do |dep|
File.write("#{download_path}/package.tgz", data)
# https://github.com/iv-org/invidious/pull/2397#issuecomment-922375908
if `sha1sum #{download_path}/package.tgz`.split(" ")[0] != required_dependencies[dep]["shasum"]
if !skip_checksum && `sha1sum #{download_path}/package.tgz`.split(" ")[0] != required_dependencies[dep]["shasum"]
raise Exception.new("Checksum for '#{dep}' failed")
end
end

View File

@ -144,12 +144,25 @@ Invidious::Database.check_integrity(CONFIG)
# Running the script by itself would show some colorful feedback while this doesn't.
# Perhaps we should just move the script to runtime in order to get that feedback?
{% puts "\nChecking player dependencies, this may take more than 20 minutes... If it is stuck, check your internet connection.\n" %}
{% if flag?(:minified_player_dependencies) %}
{% puts run("../scripts/fetch-player-dependencies.cr", "--minified").stringify %}
{% else %}
{% puts run("../scripts/fetch-player-dependencies.cr").stringify %}
{% fetch_script_arguments = [] of StringLiteral %}
{%
potential_arguments = {
{:minified_player_dependencies, "--minified"},
{:skip_player_dependencies_checksum, "--skip-checksum"},
}
%}
{% for potential_argument in potential_arguments %}
{% flag_, script_argument = potential_argument %}
{% if flag?(flag_) %}
{% fetch_script_arguments << script_argument.id %}
{% end %}
{% end %}
{% puts "\nChecking player dependencies, this may take more than 20 minutes... If it is stuck, check your internet connection.\n" %}
{% puts run("../scripts/fetch-player-dependencies.cr", fetch_script_arguments.splat).stringify %}
{% puts "\nDone checking player dependencies, now compiling Invidious...\n" %}
{% end %}