mirror of
https://github.com/danog/ytop.git
synced 2024-11-30 04:29:10 +01:00
Add package publisher
This commit is contained in:
parent
1a145d22a0
commit
0e25d2c0b6
2
package-publisher/.gitignore
vendored
Normal file
2
package-publisher/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target
|
||||
**/*.rs.bk
|
1318
package-publisher/Cargo.lock
generated
Normal file
1318
package-publisher/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
package-publisher/Cargo.toml
Normal file
12
package-publisher/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "package-publisher"
|
||||
version = "0.1.0"
|
||||
authors = ["Caleb Bassi <calebjbassi@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
git2 = "0.11.0"
|
||||
reqwest = { version = "0.10" }
|
||||
sha2 = "0.8.1"
|
||||
hex = "0.4.0"
|
||||
tokio = { version = "0.2", features = ["full"] }
|
123
package-publisher/src/main.rs
Normal file
123
package-publisher/src/main.rs
Normal file
@ -0,0 +1,123 @@
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::fs;
|
||||
use std::process::Command;
|
||||
|
||||
const VERSION: &str = "0.3.0";
|
||||
|
||||
async fn fetch_archive(url: &str) -> Vec<u8> {
|
||||
reqwest::get(url)
|
||||
.await
|
||||
.unwrap()
|
||||
.bytes()
|
||||
.await
|
||||
.unwrap()
|
||||
.to_vec()
|
||||
}
|
||||
|
||||
fn hash_archive(archive: &[u8]) -> String {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.input(archive);
|
||||
hex::encode(&hasher.result()[..])
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let aur_dir = "/home/cjbassi/playground/packages/ytop";
|
||||
let aur_bin_dir = "/home/cjbassi/playground/packages/ytop-bin";
|
||||
let homebrew_dir = "/home/cjbassi/playground/packages/homebrew-ytop";
|
||||
|
||||
let aur_template = include_str!("../templates/aur");
|
||||
let aur_bin_template = include_str!("../templates/aur-bin");
|
||||
let homebrew_template = include_str!("../templates/homebrew");
|
||||
|
||||
let macos_url = format!(
|
||||
"https://github.com/cjbassi/ytop/releases/download/{}/ytop-{}-x86_64-apple-darwin.tar.gz",
|
||||
VERSION, VERSION
|
||||
);
|
||||
let linux_url = format!("https://github.com/cjbassi/ytop/releases/download/{}/ytop-{}-x86_64-unknown-linux-gnu.tar.gz", VERSION, VERSION);
|
||||
let repo_url = format!("https://github.com/cjbassi/ytop/archive/{}.tar.gz", VERSION);
|
||||
|
||||
let macos_archive = fetch_archive(&macos_url).await;
|
||||
let linux_archive = fetch_archive(&linux_url).await;
|
||||
let repo_archive = fetch_archive(&repo_url).await;
|
||||
|
||||
let macos_hash = hash_archive(&macos_archive);
|
||||
let linux_hash = hash_archive(&linux_archive);
|
||||
let repo_hash = hash_archive(&repo_archive);
|
||||
|
||||
std::env::set_current_dir(homebrew_dir).unwrap();
|
||||
fs::write(
|
||||
"ytop.rb",
|
||||
homebrew_template
|
||||
.replace("{{ VERSION }}", VERSION)
|
||||
.replace("{{ MACOS_SHA256 }}", &macos_hash)
|
||||
.replace("{{ LINUX_SHA256 }}", &linux_hash),
|
||||
)
|
||||
.unwrap();
|
||||
Command::new("git")
|
||||
.args(&["add", "."])
|
||||
.status()
|
||||
.expect("failed to execute process");
|
||||
Command::new("git")
|
||||
.args(&["commit", "-m", VERSION])
|
||||
.status()
|
||||
.expect("failed to execute process");
|
||||
Command::new("git")
|
||||
.args(&["push"])
|
||||
.status()
|
||||
.expect("failed to execute process");
|
||||
|
||||
std::env::set_current_dir(aur_dir).unwrap();
|
||||
fs::write(
|
||||
"PKGBUILD",
|
||||
aur_template
|
||||
.replace("{{ VERSION }}", VERSION)
|
||||
.replace("{{ SHA256 }}", &repo_hash),
|
||||
)
|
||||
.unwrap();
|
||||
let output = Command::new("makepkg")
|
||||
.args(&["--printsrcinfo"])
|
||||
.output()
|
||||
.expect("failed to execute process")
|
||||
.stdout;
|
||||
fs::write(".SRCINFO", output).unwrap();
|
||||
Command::new("git")
|
||||
.args(&["add", "."])
|
||||
.status()
|
||||
.expect("failed to execute process");
|
||||
Command::new("git")
|
||||
.args(&["commit", "-m", VERSION])
|
||||
.status()
|
||||
.expect("failed to execute process");
|
||||
Command::new("git")
|
||||
.args(&["push"])
|
||||
.status()
|
||||
.expect("failed to execute process");
|
||||
|
||||
std::env::set_current_dir(aur_bin_dir).unwrap();
|
||||
fs::write(
|
||||
"PKGBUILD",
|
||||
aur_bin_template
|
||||
.replace("{{ VERSION }}", VERSION)
|
||||
.replace("{{ SHA256 }}", &linux_hash),
|
||||
)
|
||||
.unwrap();
|
||||
let output = Command::new("makepkg")
|
||||
.args(&["--printsrcinfo"])
|
||||
.output()
|
||||
.expect("failed to execute process")
|
||||
.stdout;
|
||||
fs::write(".SRCINFO", output).unwrap();
|
||||
Command::new("git")
|
||||
.args(&["add", "."])
|
||||
.status()
|
||||
.expect("failed to execute process");
|
||||
Command::new("git")
|
||||
.args(&["commit", "-m", VERSION])
|
||||
.status()
|
||||
.expect("failed to execute process");
|
||||
Command::new("git")
|
||||
.args(&["push"])
|
||||
.status()
|
||||
.expect("failed to execute process");
|
||||
}
|
25
package-publisher/templates/aur
Normal file
25
package-publisher/templates/aur
Normal file
@ -0,0 +1,25 @@
|
||||
# Maintainer: Caleb Bassi <calebjbassi@gmail.com>
|
||||
|
||||
# https://wiki.archlinux.org/index.php/Rust_package_guidelines
|
||||
|
||||
pkgname=ytop
|
||||
pkgver={{ VERSION }}
|
||||
pkgrel=1
|
||||
pkgdesc="A TUI system monitor written in Rust"
|
||||
arch=(x86_64)
|
||||
url="https://github.com/cjbassi/ytop"
|
||||
license=("MIT")
|
||||
makedepends=("cargo")
|
||||
provides=(${pkgname})
|
||||
conflicts=(${pkgname})
|
||||
source=("${pkgname}-${pkgver}.tar.gz::${url}/archive/${pkgver}.tar.gz")
|
||||
sha256sums=("{{ SHA256 }}")
|
||||
|
||||
build() {
|
||||
cd "${pkgname}-${pkgver}"
|
||||
cargo build --release --locked --all-features
|
||||
}
|
||||
|
||||
package() {
|
||||
install -Dm755 "${pkgname}-${pkgver}/target/release/${pkgname}" "${pkgdir}/usr/bin/${pkgname}"
|
||||
}
|
18
package-publisher/templates/aur-bin
Normal file
18
package-publisher/templates/aur-bin
Normal file
@ -0,0 +1,18 @@
|
||||
# Maintainer: Caleb Bassi <calebjbassi@gmail.com>
|
||||
|
||||
pkgname=ytop-bin
|
||||
_pkgname=${pkgname%-bin}
|
||||
pkgver={{ VERSION }}
|
||||
pkgrel=1
|
||||
pkgdesc="A TUI system monitor written in Rust"
|
||||
arch=(x86_64)
|
||||
url="https://github.com/cjbassi/ytop"
|
||||
license=("MIT")
|
||||
provides=(${_pkgname})
|
||||
conflicts=(${_pkgname})
|
||||
source=("${_pkgname}::${url}/releases/download/${pkgver}/${_pkgname}-${pkgver}-${arch}-unknown-linux-gnu.tar.gz")
|
||||
sha256sums=("{{ SHA256 }}")
|
||||
|
||||
package() {
|
||||
install -Dm755 "${_pkgname}" "${pkgdir}/usr/bin/${_pkgname}"
|
||||
}
|
16
package-publisher/templates/homebrew
Normal file
16
package-publisher/templates/homebrew
Normal file
@ -0,0 +1,16 @@
|
||||
class Ytop < Formula
|
||||
desc "A TUI system monitor written in Rust"
|
||||
homepage "https://github.com/cjbassi/ytop"
|
||||
version "{{ VERSION }}"
|
||||
url "https://github.com/cjbassi/ytop/releases/download/{{ VERSION }}/ytop-{{ VERSION }}-x86_64-apple-darwin.tar.gz"
|
||||
sha256 "{{ MACOS_SHA256 }}"
|
||||
|
||||
if OS.linux?
|
||||
url "https://github.com/cjbassi/ytop/releases/download/{{ VERSION }}/ytop-{{ VERSION }}-x86_64-unknown-linux-gnu.tar.gz"
|
||||
sha256 "{{ LINUX_SHA256 }}"
|
||||
end
|
||||
|
||||
def install
|
||||
bin.install "ytop"
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user