|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative "../../parse" |
| 4 | + |
| 5 | +module RootFS |
| 6 | + module Distro |
| 7 | + module Debian |
| 8 | + extend self |
| 9 | + |
| 10 | + # https://www.debian.org/releases/ |
| 11 | + # https://wiki.debian.org/DebianReleases |
| 12 | + # https://wiki.debian.org/LTS |
| 13 | + # https://www.debian.org/doc/manuals/debian-faq/ftparchives#sourceforcodenames |
| 14 | + |
| 15 | + CODENAME_VERSION = { |
| 16 | + sid: "13", |
| 17 | + bookworm: "12", |
| 18 | + bullseye: "11", |
| 19 | + buster: "10", |
| 20 | + stretch: "9", |
| 21 | + jessie: "8" |
| 22 | + }.freeze |
| 23 | + |
| 24 | + RELEASE_VERSION = { |
| 25 | + unstable: "13", |
| 26 | + testing: "12", |
| 27 | + stable: "11", |
| 28 | + oldstable: "10", |
| 29 | + oldoldstable: "9" |
| 30 | + }.freeze |
| 31 | + |
| 32 | + CURRENT_VERSION = "11.6.0" |
| 33 | + |
| 34 | + REGULAR_BUILD = %w[ |
| 35 | + release |
| 36 | + daily |
| 37 | + weekly |
| 38 | + ].freeze |
| 39 | + |
| 40 | + EDITION = %w[ |
| 41 | + netinst |
| 42 | + desktop |
| 43 | + cloud |
| 44 | + docker |
| 45 | + slim |
| 46 | + ].freeze |
| 47 | + |
| 48 | + # https://cdimage.debian.org/debian-cd/current-live/amd64/iso-hybrid/ |
| 49 | + DESKTOP = %w[ |
| 50 | + cinnamon |
| 51 | + gnome |
| 52 | + kde |
| 53 | + lxde |
| 54 | + lxqt |
| 55 | + mate |
| 56 | + standard |
| 57 | + xfce |
| 58 | + ].freeze |
| 59 | + |
| 60 | + def archive?(semver) |
| 61 | + sem_arr = _semver_to_a(semver) |
| 62 | + curr_arr = _semver_to_a(CURRENT_VERSION) |
| 63 | + _less_than(sem_arr, curr_arr) |
| 64 | + end |
| 65 | + |
| 66 | + def parse_edition(any) |
| 67 | + RootFS::Parse._str_in_arr(any, "Debian", "edition", EDITION) |
| 68 | + end |
| 69 | + |
| 70 | + def parse_build(any) |
| 71 | + RootFS::Parse._str_in_arr(any, "Debian", "build", REGULAR_BUILD) |
| 72 | + end |
| 73 | + |
| 74 | + def parse_desktop(any) |
| 75 | + RootFS::Parse._str_in_arr(any, "Debian", "desktop", DESKTOP) |
| 76 | + end |
| 77 | + |
| 78 | + def parse_release(any, build: "release") |
| 79 | + hash = parse_build(build) |
| 80 | + return unless hash |
| 81 | + |
| 82 | + build = hash[:build] |
| 83 | + str = any.to_s |
| 84 | + sym = str.to_sym |
| 85 | + |
| 86 | + if REGULAR_BUILD.include?(str) |
| 87 | + testing_version = RELEASE_VERSION[:testing] |
| 88 | + testing_codename = CODENAME_VERSION.key(testing_version) |
| 89 | + { codename: testing_codename, version: testing_version, |
| 90 | + release: :testing, build: any, archive: false } |
| 91 | + elsif CODENAME_VERSION.key?(sym) |
| 92 | + version = CODENAME_VERSION[sym] |
| 93 | + release = RELEASE_VERSION.key(version) |
| 94 | + archive = archive?(version) |
| 95 | + |
| 96 | + { codename: sym, version: version, |
| 97 | + release: release, build: build, archive: archive } |
| 98 | + elsif RELEASE_VERSION.key?(sym) |
| 99 | + version = RELEASE_VERSION[sym] |
| 100 | + codename = CODENAME_VERSION.key(version) |
| 101 | + archive = archive?(version) |
| 102 | + |
| 103 | + { codename: codename, version: version, |
| 104 | + release: sym, build: build, archive: archive } |
| 105 | + else |
| 106 | + codename = nil |
| 107 | + version = nil |
| 108 | + |
| 109 | + version_valid = false |
| 110 | + CODENAME_VERSION.each do |code, ver| |
| 111 | + next unless str.start_with?(ver) |
| 112 | + |
| 113 | + version_valid = true |
| 114 | + codename = code |
| 115 | + version = ver |
| 116 | + break |
| 117 | + end |
| 118 | + |
| 119 | + if version_valid |
| 120 | + release = RELEASE_VERSION.key(version) |
| 121 | + archive = archive?(str) |
| 122 | + |
| 123 | + { codename: codename, version: str, |
| 124 | + release: release, build: build, archive: archive } |
| 125 | + else |
| 126 | + keys_values = CODENAME_VERSION.keys + CODENAME_VERSION.values + RELEASE_VERSION.keys |
| 127 | + puts "Valid Debian release: #{keys_values}" |
| 128 | + end |
| 129 | + end |
| 130 | + end |
| 131 | + |
| 132 | + private |
| 133 | + |
| 134 | + def _semver_to_a(str) |
| 135 | + str_arr = str.split(".") |
| 136 | + if str_arr.size < 3 |
| 137 | + (3 - str_arr.size).times do |
| 138 | + str_arr.push(0) |
| 139 | + end |
| 140 | + end |
| 141 | + str_arr |
| 142 | + end |
| 143 | + |
| 144 | + # https://tldp.org/LDP/abs/html/comparison-ops.html |
| 145 | + def _less_than(arr1, arr2) |
| 146 | + num1 = arr1.shift.to_i |
| 147 | + num2 = arr2.shift.to_i |
| 148 | + |
| 149 | + if num1 < num2 |
| 150 | + true |
| 151 | + elsif num1 > num2 |
| 152 | + false |
| 153 | + elsif arr1.empty? && !arr2.empty? |
| 154 | + true |
| 155 | + elsif !arr1.empty? && arr2.empty? |
| 156 | + false |
| 157 | + elsif arr1.empty? && arr2.empty? |
| 158 | + false |
| 159 | + else |
| 160 | + _less_than(arr1, arr2) |
| 161 | + end |
| 162 | + end |
| 163 | + end |
| 164 | + end |
| 165 | +end |
0 commit comments