custom pkgbuild init

This commit is contained in:
JMARyA 2025-06-26 11:21:33 +02:00
parent fe3c2c98d3
commit 6dcbc7321d
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 87 additions and 11 deletions

52
PKGBUILDS/PKGBUILD.init Normal file
View file

@ -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 <youremail@domain.com>
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
}

View file

@ -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<String>,
#[argh(option)]
/// base PKGBUILD from a package
pub from: Option<String>,
}
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "info")]
@ -149,9 +155,3 @@ pub struct RepoIndex {
/// repository
pub repo: Option<String>,
}
// TODO : new cli cmd
// conf through env vars -> build container
// TODO : move serving fn to pacco serve <config>

View file

@ -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();
}
}

View file

@ -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 `<arch>/<repo>.db`
/// - Packages under `<arch>/<pkg>/pkgfile.tar.zst`
pub struct Repository {
pub name: String,
pub directory: std::path::PathBuf,