Skip to content

Commit

Permalink
0.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cyr committed Oct 27, 2024
1 parent 49461ce commit 598a317
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "aptmirs"
description = "A simple tool for mirroring apt/deb repositories"
version = "0.12.0"
version = "0.13.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,32 @@ deb http://ftp.se.debian.org/debian bookworm-backports main contrib
deb http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
```

Architecture can be specified with [arch=value]. The default value is *amd64*.
### Config options

|Key|Value|
|---|------|
| arch | The architecture to download packages for, e.g: `amd64`, `arm64`, etc. The default value is `amd64`. |
| di_arch | The debian installer image architecture to download, e.g. `amd64`, `arm64`, etc. |
| udeb | Whether or not to download udeb packages. The arch used for this is the same as for normal packages. The only recognized value is `true` |
| pgp_verify | Whether or not to verify the PGP signature of the release file. If no signature is available, requiring verification will make the mirroring operation fail. This will also require you to provide a source of keys, usually via the `--pgp-key-path` option. The only recognized value is `true`. |
| pgp_pub_key | Specify a PGP signing key to verify the repository. Any other key provided via the `--pgp-key-path` option will not be used. `pgp_verify` will be set to true if this option is set. |

```
deb [arch=amd64] http://ftp.se.debian.org/debian bookworm main contrib non-free non-free-firmware
```

To download debian installer image data, specify *di_arch* with the appropriate architecture.
### Examples

Mirror debian repository for *amd64* packages.

```
deb [di_arch=amd64] http://ftp.se.debian.org/debian bookworm main contrib non-free non-free-firmware
deb [arch=amd64] http://ftp.se.debian.org/debian bookworm main contrib non-free non-free-firmware
```

Multiple options can be added inside the same bracket.
Mirror debian repository for *arm64* and *amd64* packages, and also download debian installer image for *amd64*.

```
deb [arch=amd64 arch=arm64 di_arch=amd64] http://ftp.se.debian.org/debian bookworm main contrib non-free non-free-firmware
deb [arch=arm64 arch=amd64 di_arch=amd64] http://ftp.se.debian.org/debian bookworm main contrib non-free non-free-firmware
```

If you want to require PGP signature verification, either use the `--pgp-key-path` option and set pgp_verify=true on the repository
Mirror debian repository for *amd64* and verify the PGP signature.

```
deb [arch=amd64 pgp_verify=true] http://ftp.se.debian.org/debian bookworm main contrib non-free non-free-firmware
Expand All @@ -50,14 +57,12 @@ deb [arch=amd64 pgp_verify=true] http://ftp.se.debian.org/debian bookworm main
./aptmirs --config ./mirror.list --output /opt/mirror-root --pgp-key-path /etc/apt/trusted.gpg.d/
```

Or add the pgp_pub_key option pointing at the correct PGP public key.
Mirror debian repository for *amd64* and verify the PGP signature with a specified key.

```
deb [arch=amd64 pgp_pub_key=/etc/apt/trusted.gpg.d/debian-archive-bookworm-stable.asc] http://ftp.se.debian.org/debian bookworm main contrib non-free non-free-firmware
```

On failed verification the mirroring process will abort.

## Usage

```
Expand Down
6 changes: 5 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub struct MirrorOpts {
pub source: bool,
pub pgp_pub_key: Option<CompactString>,
pub pgp_verify: bool,
pub udeb: bool,
}

impl Ord for MirrorOpts {
Expand Down Expand Up @@ -135,6 +136,7 @@ impl MirrorOpts {
let mut debian_installer_arch = Vec::new();
let mut pgp_pub_key: Option<CompactString> = None;
let mut pgp_verify = false;
let mut udeb = false;

let mut source = false;

Expand Down Expand Up @@ -170,6 +172,7 @@ impl MirrorOpts {
pgp_verify = true;
},
"pgp_verify" => pgp_verify = opt_val.to_lowercase() == "true",
"udeb" => udeb = opt_val.to_lowercase() == "true",
_ => ()
}

Expand Down Expand Up @@ -208,7 +211,8 @@ impl MirrorOpts {
debian_installer_arch,
source,
pgp_pub_key,
pgp_verify
pgp_verify,
udeb
})
}

Expand Down
7 changes: 0 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ async fn main() -> Result<()> {
let mut downloader = Downloader::build(cli_opts.dl_threads);

let pgp_key_store = if let Some(key_path) = &cli_opts.pgp_key_path {

eprintln!("key store online");
Some(PgpKeyStore::build_from_path(key_path)?)
} else {
eprintln!("no key store possible");
None
};

Expand All @@ -52,10 +49,6 @@ struct CliOpts {
help = "The directory where the mirrors will be downloaded into")]
output: FilePath,

#[arg(short, long, env, value_name = "UDEB", default_value_t = false,
help = "Download packages for debian-installer")]
pub udeb: bool,

#[arg(short, long, env, value_name = "DL_THREADS", default_value_t = 8_u8,
help = "The maximum number of concurrent downloading tasks")]
dl_threads: u8,
Expand Down
12 changes: 6 additions & 6 deletions src/metadata/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{path::{Path, Component}, collections::{BTreeMap, BTreeSet}};
use compact_str::{format_compact, CompactString, ToCompactString};
use tokio::{fs::File, io::{BufReader, AsyncBufReadExt}};

use crate::{error::{Result, MirsError}, config::MirrorOpts, CliOpts};
use crate::{error::{Result, MirsError}, config::MirrorOpts};

use super::{checksum::Checksum, FilePath};

Expand Down Expand Up @@ -127,8 +127,8 @@ impl Release {
self.map.get("Components")
}

pub fn into_filtered_files<'a>(self, opts: &'a MirrorOpts, cli_opts: &'a CliOpts) -> ReleaseFileIterator<'a> {
ReleaseFileIterator::new(self, opts, cli_opts)
pub fn into_filtered_files(self, opts: &MirrorOpts) -> ReleaseFileIterator {
ReleaseFileIterator::new(self, opts)
}

pub fn deduplicate(&mut self, mut old_release: Release) {
Expand All @@ -154,7 +154,7 @@ pub struct ReleaseFileIterator<'a> {
}

impl<'a> ReleaseFileIterator<'a> {
pub fn new(release: Release, opts: &'a MirrorOpts, cli_opts: &'a CliOpts) -> Self {
pub fn new(release: Release, opts: &'a MirrorOpts) -> Self {
let (file_prefix_filter, dir_filter) = if opts.source {
let file_prefix_filter = Vec::from([
CompactString::const_new("Release"),
Expand Down Expand Up @@ -187,7 +187,7 @@ impl<'a> ReleaseFileIterator<'a> {
CompactString::const_new("Packages.diff"),
]);

if cli_opts.udeb {
if opts.udeb {
file_prefix_filter.push(CompactString::const_new("Contents-udeb-all"));
dir_filter.insert(CompactString::const_new("debian-installer"));
}
Expand All @@ -200,7 +200,7 @@ impl<'a> ReleaseFileIterator<'a> {
file_prefix_filter.push(format_compact!("Contents-{arch}"));
file_prefix_filter.push(format_compact!("Commands-{arch}"));

if cli_opts.udeb {
if opts.udeb {
file_prefix_filter.push(format_compact!("Contents-udeb-{arch}"));
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/mirror.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub async fn mirror(opts: &MirrorOpts, cli_opts: &CliOpts, downloader: &mut Down

progress.next_step("Downloading indices").await;

let (indices, diff_indices, di_indices) = match download_indices(release, opts, cli_opts, &mut progress, &repo, downloader).await {
let (indices, diff_indices, di_indices) = match download_indices(release, opts, &mut progress, &repo, downloader).await {
Ok((indices, diff_indices, di_indices)) if indices.is_empty() && diff_indices.is_empty() && di_indices.is_empty() => {
repo.finalize(Vec::new()).await?;
return Ok(MirrorResult::IrrelevantChanges)
Expand Down Expand Up @@ -149,14 +149,14 @@ pub async fn mirror(opts: &MirrorOpts, cli_opts: &CliOpts, downloader: &mut Down
})
}

async fn download_indices(release: Release, opts: &MirrorOpts, cli_opts: &CliOpts, progress: &mut Progress, repo: &Repository, downloader: &mut Downloader) -> Result<(Vec<FilePath>, Vec<FilePath>, Vec<FilePath>)> {
async fn download_indices(release: Release, opts: &MirrorOpts, progress: &mut Progress, repo: &Repository, downloader: &mut Downloader) -> Result<(Vec<FilePath>, Vec<FilePath>, Vec<FilePath>)> {
let mut indices = Vec::new();
let mut index_files = Vec::new();
let mut debian_installer_sumfiles = Vec::new();

let by_hash = release.acquire_by_hash();

for (path, file_entry) in release.into_filtered_files(opts, cli_opts) {
for (path, file_entry) in release.into_filtered_files(opts) {
let mut add_by_hash = by_hash;
let url = repo.to_url_in_dist(&path);

Expand Down
4 changes: 2 additions & 2 deletions src/pgp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl PgpKeyStore {
};

let fingerprint = hex::encode(public_key.fingerprint().as_bytes());
let key_id = hex::encode(&public_key.key_id());
let key_id = hex::encode(public_key.key_id());

primary_fingerprints.insert(fingerprint, public_key.clone());
primary_key_ids.insert(key_id, public_key.clone());
Expand All @@ -59,7 +59,7 @@ impl PgpKeyStore {
let sub_key = Arc::new(sub_key.clone());

let fingerprint = hex::encode(sub_key.fingerprint().as_bytes());
let key_id = hex::encode(&sub_key.key_id());
let key_id = hex::encode(sub_key.key_id());

sub_fingerprints.insert(fingerprint, sub_key.clone());
sub_key_ids.insert(key_id, sub_key);
Expand Down

0 comments on commit 598a317

Please sign in to comment.