feat: Actually working auto updater
This commit is contained in:
parent
f63d3b89a5
commit
1199449a88
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"x86_64-unknown-linux-gnu": {
|
||||||
|
"versions": {
|
||||||
|
"17": {
|
||||||
|
"major_version": "17",
|
||||||
|
"version": "17.0.0+35",
|
||||||
|
"url": "https://github.com/adoptium/temurin17-binaries/releases/download/jdk17u-2021-10-25-08-48-beta/OpenJDK17U-jdk_x64_linux_hotspot_2021-10-25-08-48.tar.gz",
|
||||||
|
"sha256": "0lb5mkh752x6d5yvlkcgdr60pas1qxk00jwlr7rm3566ry852vgf"
|
||||||
|
},
|
||||||
|
"18": {
|
||||||
|
"major_version": "18",
|
||||||
|
"version": "18.0.0+28",
|
||||||
|
"url": "https://github.com/adoptium/temurin18-binaries/releases/download/jdk18-2021-12-17-07-56-beta/OpenJDK18-jdk_x64_linux_hotspot_2021-12-17-07-56.tar.gz",
|
||||||
|
"sha256": "05jb4qdzb7v8arm1ysghrkyj53k2qaxsb2gnzlkgivgpnv91jbll"
|
||||||
|
},
|
||||||
|
"11": {
|
||||||
|
"major_version": "11",
|
||||||
|
"version": "11.0.13+8",
|
||||||
|
"url": "https://github.com/adoptium/temurin11-binaries/releases/download/jdk11u-2021-11-05-11-35-beta/OpenJDK11U-jdk_x64_linux_hotspot_2021-11-05-11-35.tar.gz",
|
||||||
|
"sha256": "09p60182vz31wxnp43ghlp1q928xfql0wnk7g852s1wiwjr26dm0"
|
||||||
|
},
|
||||||
|
"16": {
|
||||||
|
"major_version": "16",
|
||||||
|
"version": "16.0.1+9",
|
||||||
|
"url": "https://github.com/adoptium/temurin16-binaries/releases/download/jdk16u-2021-07-22-01-18-beta/OpenJDK16U-jdk_x64_linux_hotspot_2021-07-22-01-18.tar.gz",
|
||||||
|
"sha256": "0rgyp5jrwqjxz0ajk94vmwvagk88p5a41sm2ynckq3p7sg992ym0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
use color_eyre::{
|
use color_eyre::{
|
||||||
eyre::{bail, Context, ContextCompat, Result},
|
eyre::{bail, Context, ContextCompat, Result},
|
||||||
|
@ -26,7 +27,7 @@ fn main() -> Result<()> {
|
||||||
versions: HashMap::new(),
|
versions: HashMap::new(),
|
||||||
};
|
};
|
||||||
for (_slug, (version, url)) in slugs {
|
for (_slug, (version, url)) in slugs {
|
||||||
sources.add_release(&version, &url);
|
sources.add_release(&version, &url)?;
|
||||||
}
|
}
|
||||||
let mut output: HashMap<String, Sources> = HashMap::new();
|
let mut output: HashMap<String, Sources> = HashMap::new();
|
||||||
output.insert("x86_64-unknown-linux-gnu".to_string(), sources);
|
output.insert("x86_64-unknown-linux-gnu".to_string(), sources);
|
||||||
|
@ -43,14 +44,16 @@ struct Sources {
|
||||||
versions: HashMap<String, Source>,
|
versions: HashMap<String, Source>,
|
||||||
}
|
}
|
||||||
impl Sources {
|
impl Sources {
|
||||||
fn add_release(&mut self, release: &Release, url: &str) {
|
fn add_release(&mut self, release: &Release, url: &str) -> Result<()> {
|
||||||
let version = release.to_java_version();
|
let version = release.to_java_version();
|
||||||
let source = Source {
|
let source = Source {
|
||||||
major_version: release.major.to_string(),
|
major_version: release.major.to_string(),
|
||||||
version,
|
version,
|
||||||
url: url.to_string(),
|
url: url.to_string(),
|
||||||
|
sha256: get_sha256(url)?,
|
||||||
};
|
};
|
||||||
self.versions.insert(release.major.to_string(), source);
|
self.versions.insert(release.major.to_string(), source);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
|
@ -58,6 +61,7 @@ struct Source {
|
||||||
major_version: String,
|
major_version: String,
|
||||||
version: String,
|
version: String,
|
||||||
url: String,
|
url: String,
|
||||||
|
sha256: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serde formatting struct
|
/// Serde formatting struct
|
||||||
|
@ -138,7 +142,7 @@ fn get_versions_page(page: usize) -> Result<Vec<Release>> {
|
||||||
.query("image_type", "jdk")
|
.query("image_type", "jdk")
|
||||||
.query("os", "linux")
|
.query("os", "linux")
|
||||||
.query("page", &page)
|
.query("page", &page)
|
||||||
.query("page_size", "10")
|
.query("page_size", "50")
|
||||||
.query("project", "jdk");
|
.query("project", "jdk");
|
||||||
let url = request.url().to_string();
|
let url = request.url().to_string();
|
||||||
let response = request
|
let response = request
|
||||||
|
@ -198,7 +202,7 @@ fn get_url(version: &Release) -> Result<String> {
|
||||||
.query("image_type", "jdk")
|
.query("image_type", "jdk")
|
||||||
.query("os", "linux")
|
.query("os", "linux")
|
||||||
.query("page", "0")
|
.query("page", "0")
|
||||||
.query("page_size", "10")
|
.query("page_size", "1")
|
||||||
.query("project", "jdk");
|
.query("project", "jdk");
|
||||||
let url = request.url().to_string();
|
let url = request.url().to_string();
|
||||||
let response = request
|
let response = request
|
||||||
|
@ -219,3 +223,15 @@ fn get_url(version: &Release) -> Result<String> {
|
||||||
None => bail!("Binary was missing!"),
|
None => bail!("Binary was missing!"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the nix sha256 for a url
|
||||||
|
fn get_sha256(url: &str) -> Result<String> {
|
||||||
|
let output = Command::new("nix-prefetch-url")
|
||||||
|
.args([url, "--type", "sha256"])
|
||||||
|
.output()
|
||||||
|
.with_section(|| format!("Failed to prefetch url: {}", url).header("Prefetch Failure"))
|
||||||
|
.context("Failed to prefetch")?;
|
||||||
|
let output = String::from_utf8(output.stdout).context("Invalid utf-8 from nix pre fetch")?;
|
||||||
|
// Trim the trailing new line
|
||||||
|
Ok(output.trim().to_string())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue