Skip to content

Commit

Permalink
Merge pull request #177 from r-lib/fix/embedded-certs-on-linux
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi authored Aug 24, 2023
2 parents 782ac4e + 8e210a1 commit edc019e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ rig-$(VERSION).tar.gz: target/release/rig
mkdir -p build/bin
mkdir -p build/share/bash-completion/completions
mkdir -p build/share/zsh/site-functions
ls -l target/release
cp target/release/rig build/bin
find target/release/build -name _rig -exec cp \{\} build/share/zsh/site-functions \;
find target/release/build -name rig.bash -exec cp \{\} build/share/bash-completion/completions \;
find target/release/build -name rig.bash -exec cp \{\} build/share/bash-completion/completions \;
mkdir -p build/share/rig
curl -L -o build/share/rig/cacert.pem 'https://curl.se/ca/cacert.pem'
tar cz -C build -f $@ bin share

# -------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/escalate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub fn escalate(task: &str) -> Result<(), Box<dyn Error>> {
"LC_MONETARY",
"LC_NUMERIC",
"LC_TIME",
"SSL_CERT_FILE",
"SSL_CERT_DIR",
])?;
}

Expand Down
26 changes: 24 additions & 2 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{file, line};

use clap::ArgMatches;
use simple_error::*;
use simplelog::{trace,debug, info, warn};
use simplelog::{trace, debug, info, warn};

use crate::resolve::resolve_versions;
use crate::rversion::*;
Expand Down Expand Up @@ -855,4 +855,26 @@ fn check_usr_bin_sed(rver: &str) -> Result<(), Box<dyn Error>> {
Run `ln -s /bin/sed /usr/bin/sed` as the root user to fix this,\n \
and then run rig again."
);
}
}

pub fn set_cert_envvar() {
match std::env::var("SSL_CERT_FILE") {
Ok(_) => {
debug!("SSL_CERT_FILE is already set, keeping it.");
return;
},
Err(_) => {
let scertpath = "/usr/local/share/rig/cacert.pem";
let certpath = std::path::Path::new(scertpath);
if certpath.exists() {
debug!("Using embedded SSL certificates via SSL_CERT_FILE");
std::env::set_var("SSL_CERT_FILE", scertpath);
} else {
debug!(
"{} does not exist, using system SSL certificates",
scertpath
);
}
}
};
}
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ fn main() {
}

fn main_() -> i32 {
unset_r_envvars();
let args = parse_args();

// -- set up logger output --------------------------------------------
Expand Down Expand Up @@ -87,6 +86,11 @@ fn main_() -> i32 {
_ => {}
};

unset_r_envvars();

#[cfg(target_os = "linux")]
set_cert_envvar();

// --------------------------------------------------------------------

match main__(&args) {
Expand Down

0 comments on commit edc019e

Please sign in to comment.