Add sudo_command option (#379)
This allows the user to specify the preferred sudo command to be used instead of the command chosen by Sudo::detect
This commit is contained in:
committed by
GitHub
parent
462016e51e
commit
a3628d0d49
@@ -13,6 +13,9 @@
|
|||||||
# Do not ask to retry failed steps (default: false)
|
# Do not ask to retry failed steps (default: false)
|
||||||
#no_retry = true
|
#no_retry = true
|
||||||
|
|
||||||
|
# Sudo command to be used
|
||||||
|
#sudo_command = "sudo"
|
||||||
|
|
||||||
# Run `sudo -v` to cache credentials at the start of the run; this avoids a
|
# Run `sudo -v` to cache credentials at the start of the run; this avoids a
|
||||||
# blocking password prompt in the middle of a possibly-unattended run.
|
# blocking password prompt in the middle of a possibly-unattended run.
|
||||||
#pre_sudo = false
|
#pre_sudo = false
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use tracing::debug;
|
|||||||
use which_crate::which;
|
use which_crate::which;
|
||||||
|
|
||||||
use crate::command::CommandExt;
|
use crate::command::CommandExt;
|
||||||
|
use crate::sudo::SudoKind;
|
||||||
|
|
||||||
use super::utils::{editor, hostname};
|
use super::utils::{editor, hostname};
|
||||||
|
|
||||||
@@ -293,6 +294,7 @@ pub struct Vim {
|
|||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
/// Configuration file
|
/// Configuration file
|
||||||
pub struct ConfigFile {
|
pub struct ConfigFile {
|
||||||
|
sudo_command: Option<SudoKind>,
|
||||||
pre_sudo: Option<bool>,
|
pre_sudo: Option<bool>,
|
||||||
pre_commands: Option<Commands>,
|
pre_commands: Option<Commands>,
|
||||||
post_commands: Option<Commands>,
|
post_commands: Option<Commands>,
|
||||||
@@ -1017,6 +1019,10 @@ impl Config {
|
|||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn sudo_command(&self) -> Option<SudoKind> {
|
||||||
|
self.config_file.sudo_command
|
||||||
|
}
|
||||||
|
|
||||||
/// If `true`, `sudo` should be called after `pre_commands` in order to elevate at the
|
/// If `true`, `sudo` should be called after `pre_commands` in order to elevate at the
|
||||||
/// start of the session (and not in the middle).
|
/// start of the session (and not in the middle).
|
||||||
pub fn pre_sudo(&self) -> bool {
|
pub fn pre_sudo(&self) -> bool {
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ For more information about this issue see https://askubuntu.com/questions/110969
|
|||||||
let git = git::Git::new();
|
let git = git::Git::new();
|
||||||
let mut git_repos = git::Repositories::new(&git);
|
let mut git_repos = git::Repositories::new(&git);
|
||||||
|
|
||||||
let sudo = sudo::Sudo::detect();
|
let sudo = config.sudo_command().map_or_else(sudo::Sudo::detect, sudo::Sudo::new);
|
||||||
let run_type = executor::RunType::new(config.dry_run());
|
let run_type = executor::RunType::new(config.dry_run());
|
||||||
|
|
||||||
let ctx = execution_context::ExecutionContext::new(run_type, sudo, &git, &config, &base_dirs);
|
let ctx = execution_context::ExecutionContext::new(run_type, sudo, &git, &config, &base_dirs);
|
||||||
|
|||||||
13
src/sudo.rs
13
src/sudo.rs
@@ -4,6 +4,8 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
use color_eyre::eyre::Context;
|
use color_eyre::eyre::Context;
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use strum::AsRefStr;
|
||||||
|
|
||||||
use crate::command::CommandExt;
|
use crate::command::CommandExt;
|
||||||
use crate::execution_context::ExecutionContext;
|
use crate::execution_context::ExecutionContext;
|
||||||
@@ -31,6 +33,11 @@ impl Sudo {
|
|||||||
.map(|(path, kind)| Self { path, kind })
|
.map(|(path, kind)| Self { path, kind })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create Sudo from SudoKind, if found in the system
|
||||||
|
pub fn new(kind: SudoKind) -> Option<Self> {
|
||||||
|
which(kind.as_ref()).map(|path| Self { path, kind })
|
||||||
|
}
|
||||||
|
|
||||||
/// Elevate permissions with `sudo`.
|
/// Elevate permissions with `sudo`.
|
||||||
///
|
///
|
||||||
/// This helps prevent blocking `sudo` prompts from stopping the run in the middle of a
|
/// This helps prevent blocking `sudo` prompts from stopping the run in the middle of a
|
||||||
@@ -100,8 +107,10 @@ impl Sudo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug, Deserialize, AsRefStr)]
|
||||||
enum SudoKind {
|
#[serde(rename_all = "lowercase")]
|
||||||
|
#[strum(serialize_all = "lowercase")]
|
||||||
|
pub enum SudoKind {
|
||||||
Doas,
|
Doas,
|
||||||
Please,
|
Please,
|
||||||
Sudo,
|
Sudo,
|
||||||
|
|||||||
Reference in New Issue
Block a user