committed by
GitHub
parent
60405e0456
commit
c4ef712b3b
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1872,6 +1872,7 @@ dependencies = [
|
|||||||
"shellexpand 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"shellexpand 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"structopt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"structopt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"strum 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"strum 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"thiserror 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"thiserror 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
"tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"tokio-process 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"tokio-process 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ glob = "0.3.0"
|
|||||||
strum = { version = "0.16.0", features = ["derive"]}
|
strum = { version = "0.16.0", features = ["derive"]}
|
||||||
thiserror = "1.0.9"
|
thiserror = "1.0.9"
|
||||||
anyhow = "1.0.25"
|
anyhow = "1.0.25"
|
||||||
|
tempfile = "3.1.0"
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
nix = "0.15.0"
|
nix = "0.15.0"
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ pub enum Step {
|
|||||||
Vcpkg,
|
Vcpkg,
|
||||||
Pipx,
|
Pipx,
|
||||||
Stack,
|
Stack,
|
||||||
|
Tlmgr,
|
||||||
Myrepos,
|
Myrepos,
|
||||||
Pearl,
|
Pearl,
|
||||||
Jetpack,
|
Jetpack,
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ pub enum TopgradeError {
|
|||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
ProcessFailed(ExitStatus),
|
ProcessFailed(ExitStatus),
|
||||||
|
|
||||||
|
#[error("Sudo is required for this step")]
|
||||||
|
SudoRequired,
|
||||||
|
|
||||||
#[error("Unknown Linux Distribution")]
|
#[error("Unknown Linux Distribution")]
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
UnknownLinuxDistribution,
|
UnknownLinuxDistribution,
|
||||||
|
|||||||
19
src/main.rs
19
src/main.rs
@@ -90,7 +90,7 @@ fn run() -> Result<()> {
|
|||||||
|
|
||||||
let mut report = Report::new();
|
let mut report = Report::new();
|
||||||
|
|
||||||
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
let sudo = utils::sudo();
|
let sudo = utils::sudo();
|
||||||
let run_type = executor::RunType::new(config.dry_run());
|
let run_type = executor::RunType::new(config.dry_run());
|
||||||
|
|
||||||
@@ -411,6 +411,23 @@ fn run() -> Result<()> {
|
|||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.should_run(Step::Tlmgr) {
|
||||||
|
execute(
|
||||||
|
&mut report,
|
||||||
|
"tlmgr",
|
||||||
|
|| {
|
||||||
|
generic::run_tlmgr_update(
|
||||||
|
#[cfg(unix)]
|
||||||
|
&sudo,
|
||||||
|
#[cfg(windows)]
|
||||||
|
&None,
|
||||||
|
run_type,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
config.no_retry(),
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
if config.should_run(Step::Myrepos) {
|
if config.should_run(Step::Myrepos) {
|
||||||
execute(
|
execute(
|
||||||
&mut report,
|
&mut report,
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
use crate::error::SkipStep;
|
use crate::error::{SkipStep, TopgradeError};
|
||||||
use crate::executor::{CommandExt, RunType};
|
use crate::executor::{CommandExt, RunType};
|
||||||
use crate::terminal::{print_separator, shell};
|
use crate::terminal::{print_separator, shell};
|
||||||
use crate::utils::{self, PathExt};
|
use crate::utils::{self, PathExt};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use directories::BaseDirs;
|
use directories::BaseDirs;
|
||||||
|
use log::debug;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
use tempfile::tempfile_in;
|
||||||
|
|
||||||
pub fn run_cargo_update(run_type: RunType) -> Result<()> {
|
pub fn run_cargo_update(run_type: RunType) -> Result<()> {
|
||||||
let cargo_update = utils::require("cargo-install-update")?;
|
let cargo_update = utils::require("cargo-install-update")?;
|
||||||
@@ -109,6 +111,41 @@ pub fn run_stack_update(run_type: RunType) -> Result<()> {
|
|||||||
run_type.execute(&stack).arg("upgrade").check_run()
|
run_type.execute(&stack).arg("upgrade").check_run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn run_tlmgr_update(sudo: &Option<PathBuf>, run_type: RunType) -> Result<()> {
|
||||||
|
let tlmgr = utils::require("tlmgr")?;
|
||||||
|
let kpsewhich = utils::require("kpsewhich")?;
|
||||||
|
let tlmgr_directory = {
|
||||||
|
let mut d = PathBuf::from(
|
||||||
|
std::str::from_utf8(
|
||||||
|
&Command::new(&kpsewhich)
|
||||||
|
.arg("-var-value=SELFAUTOPARENT")
|
||||||
|
.output()?
|
||||||
|
.stdout,
|
||||||
|
)?
|
||||||
|
.trim(),
|
||||||
|
);
|
||||||
|
d.push("tlpkg");
|
||||||
|
d
|
||||||
|
}
|
||||||
|
.require()?;
|
||||||
|
|
||||||
|
let directory_writable = tempfile_in(&tlmgr_directory).is_ok();
|
||||||
|
debug!("{:?} writable: {}", tlmgr_directory, directory_writable);
|
||||||
|
|
||||||
|
print_separator("TeX Live package manager");
|
||||||
|
|
||||||
|
let mut command = if directory_writable {
|
||||||
|
run_type.execute(&tlmgr)
|
||||||
|
} else {
|
||||||
|
let mut c = run_type.execute(sudo.as_ref().ok_or(TopgradeError::SudoRequired)?);
|
||||||
|
c.arg(&tlmgr);
|
||||||
|
c
|
||||||
|
};
|
||||||
|
command.args(&["update", "--self", "--all"]);
|
||||||
|
|
||||||
|
command.check_run()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run_myrepos_update(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
pub fn run_myrepos_update(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||||
let myrepos = utils::require("mr")?;
|
let myrepos = utils::require("mr")?;
|
||||||
base_dirs.home_dir().join(".mrconfig").require()?;
|
base_dirs.home_dir().join(".mrconfig").require()?;
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ pub fn which<T: AsRef<OsStr> + Debug>(binary_name: T) -> Option<PathBuf> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
pub fn sudo() -> Option<PathBuf> {
|
pub fn sudo() -> Option<PathBuf> {
|
||||||
which("sudo").or_else(|| which("pkexec"))
|
which("sudo").or_else(|| which("pkexec"))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user