Compare commits

...
3 Commits
24 changed files with 772 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
[registry]
default = "gitea"
[registries.gitea]
index = "sparse+https://git.tcraft.me/api/packages/neo/cargo/" # sparse index
Generated
+231
View File
@@ -2,6 +2,237 @@
# It is not intended for manual editing.
version = 4
[[package]]
name = "aho-corasick"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
dependencies = [
"memchr",
]
[[package]]
name = "anstream"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
[[package]]
name = "anstyle-parse"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys",
]
[[package]]
name = "clap"
version = "4.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "301b56658598e48f3648647ac6fc887be7e7108eddfa4e9b63fcf3ec58c0cadf"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94a65403d1a1bd28f7dc68eb8506e8874808ee5eecb59298de588e2e1407a078"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d012d2b9d65aca7f18f4d9878a045bc17899bba951561ba5ec3c2ba1eed9a061"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
[[package]]
name = "colorchoice"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]]
name = "log"
version = "0.4.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad"
[[package]]
name = "memchr"
version = "2.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
[[package]]
name = "once_cell_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fcfdb36bda0c880c5931cdc7a2bcdc8ba4556847b9d912bca70bc94708711ad"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
[[package]]
name = "ruport"
version = "0.1.0"
dependencies = [
"clap",
"log",
"regex",
]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "3.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]
+108
View File
@@ -3,4 +3,112 @@ name = "ruport"
version = "0.1.0"
edition = "2024"
[features]
drop-in = []
default = []
[[bin]]
name = "ruport"
path = "src/main.rs"
[[bin]]
name = "ebuild"
path = "src/ebuild.rs"
required-features = ["drop-in"]
[[bin]]
name = "egencache"
path = "src/egencache.rs"
required-features = ["drop-in"]
[[bin]]
name = "emerge"
path = "src/emerge.rs"
required-features = ["drop-in"]
[[bin]]
name = "emerge-webrsync"
path = "src/emerge-webrsync.rs"
required-features = ["drop-in"]
[[bin]]
name = "emirrordist"
path = "src/emirrordist"
required-features = ["drop-in"]
[[bin]]
name = "glsa-check"
path = "src/glsa-check.rs"
required-features = ["drop-in"]
[[bin]]
name = "gpkg-sign"
path = "src/gpkg-sign"
required-features = ["drop-in"]
[[bin]]
name = "portageq"
path = "src/portageq.rs"
required-features = ["drop-in"]
[[bin]]
name = "quickpkg"
path = "src/quickpkg.rs"
required-features = ["drop-in"]
[lib]
name = "portage"
path = "libportage/lib.rs"
crate-type = ["rlib"]
# gehen nach ${PREFIX}/sbin
[[bin]]
name = "archive-conf"
path = "src/archive-conf.rs"
required-features = ["drop-in"]
[[bin]]
name = "dispatch-conf"
path = "src/dispatch-conf.rs"
required-features = ["drop-in"]
[[bin]]
name = "emaint"
path = "src/emaint.rs"
required-features = ["drop-in"]
[[bin]]
name = "env-update"
path = "src/env-update.rs"
required-features = ["drop-in"]
[[bin]]
name = "etc-update"
path = "src/etc-update.rs"
required-features = ["drop-in"]
[[bin]]
name = "fixpackages"
path = "src/fixpackages.rs"
required-features = ["drop-in"]
[[bin]]
name = "regenworld"
path = "src/regendworld.rs"
required-features = ["drop-in"]
[dependencies]
clap = { version="4.6", features=["derive"] }
log = "0.4.33"
regex = { version="1.13" }
[profile.dev]
opt-level = "s"
debug = true
strip = false
lto = false
[profile.release]
opt-level = "z"
lto = "full"
strip = true
+50
View File
@@ -0,0 +1,50 @@
use std::fs::File;
use std::io::{Result,BufReader,Read,Seek,SeekFrom};
use std::os::unix::ffi::OsStrExt;
use std::path::PathBuf;
use log::warn;
use crate::consts::GentooBinpkgFormats;
fn get_binpkg_format(binpkg: PathBuf, check_file: Option<bool>, remote: Option<bool>) -> Option<GentooBinpkgFormats> {
let check_file = check_file.unwrap_or(false);
let remote = remote.unwrap_or(false);
let extension = &binpkg.extension().ok_or(0).unwrap();
let extension = extension.to_str().unwrap();
let file_ext_format = if GentooBinpkgFormats::XPAK.get_extension().unwrap().contains(&extension) {
Some(GentooBinpkgFormats::XPAK)
} else if GentooBinpkgFormats::GPKG.get_extension().unwrap().contains(&extension) {
Some(GentooBinpkgFormats::GPKG)
} else {
None
};
let mut file_format: Option<GentooBinpkgFormats> = if file_ext_format.is_some() && !check_file {
file_ext_format
} else {
let binpkg_file = File::open(&binpkg).expect(format!("unable to open binary file {}", &binpkg.display()).as_str());
let mut reader = BufReader::new(binpkg_file);
let mut buf = [0;100];
let _ = reader.read(&mut buf).expect(format!("cannot read file: {}", &binpkg.display()).as_str());
if buf.starts_with(b"/gpkg-1\x00") {
Some(GentooBinpkgFormats::GPKG)
} else {
reader.seek(SeekFrom::End(-16));
let mut tail = [0;16];
reader.read_exact(&mut tail);
if tail[0..8].starts_with(b"XPAKSTOP") && tail[12..16].ends_with(b"STOP") {
Some(GentooBinpkgFormats::XPAK)
} else {
None
}
}
};
if file_format.is_some() && file_ext_format.unwrap() != file_format.unwrap() {
warn!("File {} binpkg format mismatch, actial format: {}", binpkg.display(), file_format.unwrap());
}
return file_format;
}
+273
View File
@@ -0,0 +1,273 @@
use std::ffi::OsStr;
use std::path::PathBuf;
use std::sync::LazyLock;
use std::io::Result;
use crate::types::Atom;
/**
* There are two types of variables here whcih can easily be confused,
* resulting in arbitrary bugs, mainly exposed with an offset
* installation (Prefix). The two types relate to the useage of
* config_root or target_root.
* The first, config_root (PORTAGE_CONFIGROOT), can be a path somewhere,
* from which all derived paths need to be relative (e.g. USER_CONFIG_PATH)
* without EPREFIX prepended in Prefix. This means
* config_root cann for instance be set to "$HOME/my/config". Obviously,
* in such case it is not appropriate to prepend EPREFIX to derived
* constants. The default value of config_root is EPREFIX (in non-Prefix
* the empty String) -- overriding the value loses the EPREFXXI as one
* would expect.
* Second here is target_root (ROOT) which is used to install somewhere
* completely else, in Prefix of limited use. Because this is an offset
* always given, the EPREFIX should always be applied in it, hence the
* code always prefixes them with ERROT.
* The variables in this file are grouped by config_root, target_root.
*/
// variables used with config_root (these need to be relative)
static USER_CONFIG_PATH: LazyLock<PathBuf> =
LazyLock::new(|| PathBuf::from("etc/portage"));
static BINREPOS_CONF_FILE: LazyLock<PathBuf> =
LazyLock::new(|| USER_CONFIG_PATH.join("binrepos.conf"));
static MAKE_CONF_FILE: LazyLock<PathBuf> =
LazyLock::new(|| USER_CONFIG_PATH.join("make.conf"));
static MODULES_FILE_PATH: LazyLock<PathBuf> =
LazyLock::new(|| USER_CONFIG_PATH.join("modules"));
static CUSTOM_PROFILE_PATH: LazyLock<PathBuf> =
LazyLock::new(|| USER_CONFIG_PATH.join("profile"));
static USER_VIRTUAL_FILE: LazyLock<PathBuf> =
LazyLock::new(|| USER_CONFIG_PATH.join("virtuals"));
static EBUILD_SH_ENV_FILE: LazyLock<PathBuf> =
LazyLock::new(|| USER_CONFIG_PATH.join("bashrc"));
static EBUILD_SH_ENV_DIR: LazyLock<PathBuf> =
LazyLock::new(|| USER_CONFIG_PATH.join("env"));
static CUSTOM_MIRRORS_FILE: LazyLock<PathBuf> =
LazyLock::new(|| USER_CONFIG_PATH.join("mirrors"));
static COLOR_MAP_FILE: LazyLock<PathBuf> =
LazyLock::new(|| USER_CONFIG_PATH.join("color.map"));
static PROFILE_PATH: LazyLock<PathBuf> =
LazyLock::new(|| USER_CONFIG_PATH.join("make.profile"));
static MAKE_DEFAULTS_FILE: LazyLock<PathBuf> =
LazyLock::new(|| PROFILE_PATH.join("make.defaults"));
static DEPRECATED_PROFILE_FILE: LazyLock<PathBuf> =
LazyLock::new(|| PROFILE_PATH.join("deprecated"));
// variables used with targetroot (these need to be absolute, but not
// have a leading '/' since they are used directly with path.join on EROOT)
static VDB_PATH: LazyLock<PathBuf> =
LazyLock::new(|| PathBuf::from("var/db/pkg"));
static CACHE_PATH: LazyLock<PathBuf> =
LazyLock::new(|| PathBuf::from("var/cache/edb"));
static PRIVATE_PATH: LazyLock<PathBuf> =
LazyLock::new(|| PathBuf::from("var/lib/portage"));
static WORLD_FILE: LazyLock<PathBuf> =
LazyLock::new(|| PRIVATE_PATH.join("world"));
static WORLD_SETS_FILE: LazyLock<PathBuf> =
LazyLock::new(|| PRIVATE_PATH.join("world_sets"));
static CONFIG_MEMORY_FILE: LazyLock<PathBuf> =
LazyLock::new(|| PRIVATE_PATH.join("config"));
static REPO_REVISIONS: LazyLock<PathBuf> =
LazyLock::new(|| PRIVATE_PATH.join("repo_revisions"));
static NEWS_LIB_PATH: LazyLock<PathBuf> =
LazyLock::new(|| PathBuf::from("var/lib/gentoo"));
/* these variables get EPREFIX prepended automagically when they are
* translated into their lowercase variants */
static DEPCACHE_PATH: LazyLock<PathBuf> =
LazyLock::new(|| CACHE_PATH.join("dep"));
static PORTAGE_PACKAGE_ATOM: LazyLock<Atom> = LazyLock::new(|| Atom::new("sys-apps/portage"));
static LIBC_PACKAGE_ATOM: LazyLock<Atom> = LazyLock::new(|| Atom::new("virtual/libc"));
static OS_HEADERS_PACKAGE_ATOM: LazyLock<Atom> = LazyLock::new(|| Atom::new("virtual/os-headers"));
static CVS_PACKAGE_ATOM: LazyLock<Atom> = LazyLock::new(|| Atom::new("dev-vcs/cvs"));
static GIT_PACKAGE_ATOM: LazyLock<Atom> = LazyLock::new(|| Atom::new("dev-vcs/git"));
static HG_PACKAGE_ATOM: LazyLock<Atom> = LazyLock::new(|| Atom::new("dev-vcs/mercurial"));
static RSYNC_PACKAGE_ATOM: LazyLock<Atom> = LazyLock::new(|| Atom::new("net-misc/rsync"));
const INCREMENTALS: &'static [&'static str] = &[
"ACCEPT_KEYWORDS",
"CONFIG_PROTECT",
"CONFIG_PROTECT_MASK",
"ENV_UNSET",
"FEATURES",
"IUSE_IMPLICIT",
"PRELINK_PATH",
"PRELINK_PATH_MASK",
"PROFILE_ONLY_VARIABLES",
"USE",
"USE_EXPAND",
"USE_EXPAND_HIDDEN",
"USE_EXPAND_IMPLICIT",
"USE_EXPAND_UNPREFIXED",
];
const SUPPORTED_FEATURES: &'static [&'static str] = &[
"assume-digest",
"binpkg-docompress",
"binpkg-dostrip",
"binpkg-ignore-signature",
"binpkg-logs",
"binpkg-multi-instance",
"binpkg-request-signature",
"binpkg-signing",
"buildpkg",
"buildpkg-live",
"buildpkg-proactive",
"buildsyspkg",
"candy",
"case-insensitive-fs",
"ccache",
"chflags",
"clean-logs",
"collision-protect",
"compress-build-logs",
"compressdebug",
"compress-index",
"config-protect-if-modified",
"dedupdebug",
"digest",
"distcc",
"distlocks",
"downgrade-backup",
"ebuild-locks",
"fail-clean",
"fakeroot",
"fixlafiles",
"force-mirror",
"getbinpkg",
"gpg-keepalive",
"home-dir-template-copy",
"icecream",
"installsources",
"ipc-sandbox",
"jobserver-token",
"keeptemp",
"keepwork",
"lmirror",
"merge-sync",
"merge-wait",
"metadata-transfer",
"mirror",
"mount-sandbox",
"multilib-strict",
"network-sandbox",
"network-sandbox-proxy",
"news",
"noauto",
"noclean",
"nodoc",
"noinfo",
"noman",
"nostrip",
"notitles",
"packdebug",
"parallel-fetch",
"parallel-install",
"pid-sandbox",
"pkgdir-index-trusted",
"prelink-checksums",
"preserve-libs",
"protect-owned",
"python-trace",
"qa-unresolved-soname-deps",
"sandbox",
"selinux",
"sesandbox",
"sfperms",
"sign",
"skiprocheck",
"splitdebug",
"split-elog",
"split-log",
"strict",
"strict-keepdir",
"stricter",
"suidctl",
"test",
"test-fail-continue",
"unknown-features-filter",
"unknown-features-warn",
"unmerge-backup",
"unmerge-logs",
"unmerge-orphans",
"unprivileged",
"userfetch",
"userpriv",
"usersandbox",
"usersync",
"warn-on-large-env",
"webrsync-gpg",
"xattr",
];
const EAPI: usize = 9;
const HASHING_BLOCKSIZE: usize = 32768;
#[derive(Default)]
enum Manifest2HashDefaults {
#[default]
Blake2B,
SHA512,
}
const VCS_DIRS: &'static [&'static str] = &[
"CVS",
"RCS",
"SCCS",
".bzr",
".git",
".hg",
".svn"
];
const LIVE_ECLASS: &'static [&'static str] = &[
"bzr",
"cvs",
"darcs",
"git-2",
"git-r3",
"golang-vcs",
"mercurial",
"subversion",
];
enum BinpkgFormats {
Tar,
Rpm,
}
#[derive(Debug,Clone,Copy,Eq,PartialEq)]
pub(crate) enum GentooBinpkgFormats {
XPAK,
GPKG,
}
impl GentooBinpkgFormats {
pub fn to_str(self) -> &'static str {
match self {
Self::XPAK => "xpak",
Self::GPKG => "gpkg",
}
}
pub fn get_extension(&self) -> Result<Vec<&str>> {
match self {
Self::XPAK => return Ok(vec![".tbz2", ".xpak"]),
Self::GPKG => return Ok(vec![".gpkg.tar"]),
}
}
pub fn contains(&self, pat: &str) -> bool {
let extensions= self.get_extension().unwrap();
if extensions.contains(&pat) {
true
} else {
false
}
}
}
impl std::fmt::Display for GentooBinpkgFormats {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.to_str())
}
}
+36
View File
@@ -0,0 +1,36 @@
#![allow(unused)]
use std::{env, path::{Path,PathBuf}};
use std::io::Result;
mod binpkg;
mod consts;
mod types;
fn getwcd() -> Result<PathBuf> {
let cwd = match env::current_dir() {
Ok(p) => p,
Err(_) => {
env::set_current_dir("/")?;
PathBuf::from("/")
}
};
Ok(cwd)
}
fn abssymlink(symlink: &Path, target: Option<PathBuf>) -> Result<PathBuf> {
let mut mylink = if target.is_some() {
target.unwrap()
} else {
std::fs::read_link(symlink)?
};
if !mylink.has_root() {
let mydir = mylink.parent().unwrap();
let link_name = mylink.clone();
mylink = Path::new(mydir).join(link_name);
}
Ok(mylink)
}
+17
View File
@@ -0,0 +1,17 @@
pub(crate) struct Atom {
category: String,
packet: String
}
impl Atom {
pub fn new(atom: &str) -> Self {
let parts: Vec<&str> = atom.split('/').collect();
Self {
category: String::from(parts[0]),
packet: String::from(parts[1]),
}
}
}
+52
View File
@@ -0,0 +1,52 @@
EAPI=8
DESCRIPTION="Rust port of the portage package manager system"
HOMEPAGE="https://tcraft.me/?topic=ruport"
SRC_URI="https://git.tcraft.me/neo/ruport.git"
IUSE="drop-in"
RUPORT_DROP-IN_BINS=(
target/release/ebuild
target/release/egencache
target/release/emerge
target/release/emerge-webrsync
target/release/emirrordist
target/release/glsa-check
target/release/gpkg-sign
target/release/portageq
target/release/quickpkg
)
RUPORT_DROP-IN_SBINS=(
target/release/archive-conf
target/release/dispatch-conf
target/release/emaint
target/release/env-update
target/release/etc-update
target/release/fixpackages
target/release/regendworld
)
src_compile() {
local cargo_flags=""
if use drop-in ; then
cargo_flags="--features=drop-in"
fi
cargo build --release ${cargo_flags}
}
src_install() {
dobin target/release/ruport
if use drop-in ; then
for pkg in RUPORT_DROP-IN_BINS ; do
dobin $pkg
done
for pkg in RUPORT_DROP-IN_SBINS ; do
dosbin $pkg
done
fi
}
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File