From 6dcbc7321d71df85eccd162dddc63c963b0ae389 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Thu, 26 Jun 2025 11:21:33 +0200 Subject: [PATCH] custom pkgbuild init --- PKGBUILDS/PKGBUILD.init | 52 +++++++++++++++++++++++++++++++++++++++++ src/cli.rs | 18 +++++++------- src/main.rs | 21 +++++++++++++++-- src/pkg/repo.rs | 7 ++++++ 4 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 PKGBUILDS/PKGBUILD.init diff --git a/PKGBUILDS/PKGBUILD.init b/PKGBUILDS/PKGBUILD.init new file mode 100644 index 0000000..9aff797 --- /dev/null +++ b/PKGBUILDS/PKGBUILD.init @@ -0,0 +1,52 @@ +# This is an example PKGBUILD file. Use this as a start to creating your own, +# and remove these comments. For more information, see 'man PKGBUILD'. +# NOTE: Please fill out the license field for your package! If it is unknown, +# then please put 'unknown'. + +# Maintainer: Your Name +pkgname=NAME +pkgver=VERSION +pkgrel=1 +epoch= +pkgdesc="" +arch=() +url="" +license=('GPL') +groups=() +depends=() +makedepends=() +checkdepends=() +optdepends=() +provides=() +conflicts=() +replaces=() +backup=() +options=() +install= +changelog= +source=("$pkgname-$pkgver.tar.gz" + "$pkgname-$pkgver.patch") +noextract=() +sha256sums=() +validpgpkeys=() + +prepare() { + cd "$pkgname-$pkgver" + patch -p1 -i "$srcdir/$pkgname-$pkgver.patch" +} + +build() { + cd "$pkgname-$pkgver" + ./configure --prefix=/usr + make +} + +check() { + cd "$pkgname-$pkgver" + make -k check +} + +package() { + cd "$pkgname-$pkgver" + make DESTDIR="$pkgdir/" install +} diff --git a/src/cli.rs b/src/cli.rs index fce453b..a3b36e1 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,5 +1,3 @@ -// TODO : pacco cli - use argh::FromArgs; #[derive(FromArgs, PartialEq, Debug)] @@ -73,7 +71,15 @@ pub enum PackageCommands { #[derive(FromArgs, PartialEq, Debug)] #[argh(subcommand, name = "init")] /// Init a template PKGBUILD -pub struct PackageInitCommand {} +pub struct PackageInitCommand { + #[argh(positional)] + /// PKGBUILD template + pub kind: Option, + + #[argh(option)] + /// base PKGBUILD from a package + pub from: Option, +} #[derive(FromArgs, PartialEq, Debug)] #[argh(subcommand, name = "info")] @@ -149,9 +155,3 @@ pub struct RepoIndex { /// repository pub repo: Option, } - -// TODO : new cli cmd - -// conf through env vars -> build container - -// TODO : move serving fn to pacco serve diff --git a/src/main.rs b/src/main.rs index 34980a9..05618bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -317,8 +317,23 @@ async fn main() { } } cli::PaccoCLICommands::Package(package_command) => match package_command.cmd { - cli::PackageCommands::Init(_) => { - std::fs::copy("/usr/share/pacman/PKGBUILD.proto", "PKGBUILD").unwrap(); + cli::PackageCommands::Init(init_args) => { + if let Some(from) = init_args.from { + unimplemented!() + } else { + let kind = init_args.kind.unwrap_or("init".to_string()); + + match kind.as_str() { + "init" => { + std::fs::write("PKGBUILD", include_str!("../PKGBUILDS/PKGBUILD.init")) + .unwrap(); + } + _ => { + println!("Unknown PKGBUILD kind {kind}"); + std::process::exit(1); + } + } + } } cli::PackageCommands::Info(_) => { #[rustfmt::skip] @@ -351,10 +366,12 @@ async fn main() { let archs = repo.arch(); for a in archs { let db = repo.db_path(a); + #[rustfmt::skip] run_cmd!(repo-add $db $pkg).unwrap(); } } else { let db = repo.db_path(arch); + #[rustfmt::skip] run_cmd!(repo-add $db $pkg).unwrap(); } } diff --git a/src/pkg/repo.rs b/src/pkg/repo.rs index 999ad40..99244a7 100644 --- a/src/pkg/repo.rs +++ b/src/pkg/repo.rs @@ -3,6 +3,13 @@ use std::{collections::HashSet, path::PathBuf}; use super::{Package, arch::Architecture}; /// Package Repository +/// +/// # Structure +/// This repository assumes a repository structure under `directory`. +/// +/// The structure is typically: +/// - RepoDBs under `/.db` +/// - Packages under `//pkgfile.tar.zst` pub struct Repository { pub name: String, pub directory: std::path::PathBuf,