committed by
GitHub
parent
6021a551ac
commit
8ce55f4c31
@@ -25,6 +25,9 @@
|
|||||||
# Arguments to pass Git when pulling Repositories
|
# Arguments to pass Git when pulling Repositories
|
||||||
#git_arguments = "--rebase --autostash"
|
#git_arguments = "--rebase --autostash"
|
||||||
|
|
||||||
|
# Arguments to pass tmux when pulling Repositories
|
||||||
|
#tmux_arguments = "-S /var/tmux.sock"
|
||||||
|
|
||||||
# Arguments to pass yay when updating packages
|
# Arguments to pass yay when updating packages
|
||||||
#yay_arguments = "--nodevel"
|
#yay_arguments = "--nodevel"
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ pub struct ConfigFile {
|
|||||||
remote_topgrades: Option<Vec<String>>,
|
remote_topgrades: Option<Vec<String>>,
|
||||||
ssh_arguments: Option<String>,
|
ssh_arguments: Option<String>,
|
||||||
git_arguments: Option<String>,
|
git_arguments: Option<String>,
|
||||||
|
tmux_arguments: Option<String>,
|
||||||
set_title: Option<bool>,
|
set_title: Option<bool>,
|
||||||
assume_yes: Option<bool>,
|
assume_yes: Option<bool>,
|
||||||
yay_arguments: Option<String>,
|
yay_arguments: Option<String>,
|
||||||
@@ -289,6 +290,11 @@ impl Config {
|
|||||||
&self.config_file.git_arguments
|
&self.config_file.git_arguments
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Extra Tmux arguments
|
||||||
|
pub fn tmux_arguments(&self) -> &Option<String> {
|
||||||
|
&self.config_file.tmux_arguments
|
||||||
|
}
|
||||||
|
|
||||||
/// Prompt for a key before exiting
|
/// Prompt for a key before exiting
|
||||||
pub fn keep_at_end(&self) -> bool {
|
pub fn keep_at_end(&self) -> bool {
|
||||||
self.opt.keep_at_end || env::var("TOPGRADE_KEEP_END").is_ok()
|
self.opt.keep_at_end || env::var("TOPGRADE_KEEP_END").is_ok()
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ fn run() -> Result<(), Error> {
|
|||||||
if config.run_in_tmux() && env::var("TOPGRADE_INSIDE_TMUX").is_err() {
|
if config.run_in_tmux() && env::var("TOPGRADE_INSIDE_TMUX").is_err() {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
tmux::run_in_tmux();
|
tmux::run_in_tmux(config.tmux_arguments());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,6 +142,7 @@ fn run() -> Result<(), Error> {
|
|||||||
remote_topgrade,
|
remote_topgrade,
|
||||||
config.ssh_arguments(),
|
config.ssh_arguments(),
|
||||||
config.run_in_tmux(),
|
config.run_in_tmux(),
|
||||||
|
config.tmux_arguments(),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
config.no_retry(),
|
config.no_retry(),
|
||||||
|
|||||||
@@ -149,13 +149,14 @@ pub fn run_remote_topgrade(
|
|||||||
hostname: &str,
|
hostname: &str,
|
||||||
ssh_arguments: &Option<String>,
|
ssh_arguments: &Option<String>,
|
||||||
run_in_tmux: bool,
|
run_in_tmux: bool,
|
||||||
|
_tmux_arguments: &Option<String>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let ssh = utils::require("ssh")?;
|
let ssh = utils::require("ssh")?;
|
||||||
|
|
||||||
if run_in_tmux && !run_type.dry() {
|
if run_in_tmux && !run_type.dry() {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
crate::tmux::run_remote_topgrade(hostname, &ssh)?;
|
crate::tmux::run_remote_topgrade(hostname, &ssh, _tmux_arguments)?;
|
||||||
Err(ErrorKind::SkipStep.into())
|
Err(ErrorKind::SkipStep.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use failure::ResultExt;
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::os::unix::process::CommandExt;
|
use std::os::unix::process::CommandExt;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::{exit, Command};
|
use std::process::{exit, Command};
|
||||||
|
|
||||||
pub fn run_tpm(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
pub fn run_tpm(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||||
@@ -21,39 +21,61 @@ pub fn run_tpm(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
|||||||
run_type.execute(&tpm).arg("all").check_run()
|
run_type.execute(&tpm).arg("all").check_run()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_session(tmux: &Path, session_name: &str) -> Result<bool, io::Error> {
|
struct Tmux {
|
||||||
Ok(Command::new(tmux)
|
tmux: PathBuf,
|
||||||
.args(&["has-session", "-t", session_name])
|
args: Option<Vec<String>>,
|
||||||
.env_remove("TMUX")
|
|
||||||
.output()?
|
|
||||||
.status
|
|
||||||
.success())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_session(tmux: &Path, session_name: &str) -> Result<bool, io::Error> {
|
impl Tmux {
|
||||||
Ok(Command::new(tmux)
|
fn new(args: &Option<String>) -> Self {
|
||||||
.args(&["new-session", "-d", "-s", session_name, "-n", "dummy"])
|
Self {
|
||||||
.env_remove("TMUX")
|
tmux: which("tmux").expect("Could not find tmux"),
|
||||||
.spawn()?
|
args: args
|
||||||
.wait()?
|
.as_ref()
|
||||||
.success())
|
.map(|args| args.split_whitespace().map(String::from).collect()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build(&self) -> Command {
|
||||||
|
let mut command = Command::new(&self.tmux);
|
||||||
|
if let Some(args) = self.args.as_ref() {
|
||||||
|
command.args(args).env_remove("TMUX");
|
||||||
|
}
|
||||||
|
command
|
||||||
|
}
|
||||||
|
|
||||||
|
fn has_session(&self, session_name: &str) -> Result<bool, io::Error> {
|
||||||
|
Ok(self
|
||||||
|
.build()
|
||||||
|
.args(&["has-session", "-t", session_name])
|
||||||
|
.output()?
|
||||||
|
.status
|
||||||
|
.success())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_session(&self, session_name: &str) -> Result<bool, io::Error> {
|
||||||
|
Ok(self
|
||||||
|
.build()
|
||||||
|
.args(&["new-session", "-d", "-s", session_name, "-n", "dummy"])
|
||||||
|
.spawn()?
|
||||||
|
.wait()?
|
||||||
|
.success())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_in_session(&self, command: &str) -> Result<(), Error> {
|
||||||
|
self.build()
|
||||||
|
.args(&["new-window", "-a", "-t", "topgrade:1", command])
|
||||||
|
.spawn()
|
||||||
|
.context(ErrorKind::ProcessExecution)?
|
||||||
|
.wait()
|
||||||
|
.context(ErrorKind::ProcessExecution)?
|
||||||
|
.check()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_in_session(tmux: &Path, command: &str) -> Result<(), Error> {
|
pub fn run_in_tmux(args: &Option<String>) -> ! {
|
||||||
Command::new(tmux)
|
|
||||||
.args(&["new-window", "-a", "-t", "topgrade:1", command])
|
|
||||||
.env_remove("TMUX")
|
|
||||||
.spawn()
|
|
||||||
.context(ErrorKind::ProcessExecution)?
|
|
||||||
.wait()
|
|
||||||
.context(ErrorKind::ProcessExecution)?
|
|
||||||
.check()?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run_in_tmux() -> ! {
|
|
||||||
let tmux = which("tmux").expect("Could not find tmux");
|
|
||||||
let command = {
|
let command = {
|
||||||
let mut command = vec![
|
let mut command = vec![
|
||||||
String::from("env"),
|
String::from("env"),
|
||||||
@@ -64,18 +86,20 @@ pub fn run_in_tmux() -> ! {
|
|||||||
command.join(" ")
|
command.join(" ")
|
||||||
};
|
};
|
||||||
|
|
||||||
if !has_session(&tmux, "topgrade").expect("Error launching tmux") {
|
let tmux = Tmux::new(args);
|
||||||
new_session(&tmux, "topgrade").expect("Error launching tmux");
|
|
||||||
|
if !tmux.has_session("topgrade").expect("Error launching tmux") {
|
||||||
|
tmux.new_session("topgrade").expect("Error launching tmux");
|
||||||
}
|
}
|
||||||
|
|
||||||
run_in_session(&tmux, &command).expect("Error launching tmux");
|
tmux.run_in_session(&command).expect("Error launching tmux");
|
||||||
Command::new(&tmux)
|
tmux.build()
|
||||||
.args(&["kill-window", "-t", "topgrade:dummy"])
|
.args(&["kill-window", "-t", "topgrade:dummy"])
|
||||||
.output()
|
.output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
if env::var("TMUX").is_err() {
|
if env::var("TMUX").is_err() {
|
||||||
let err = Command::new(tmux).args(&["attach", "-t", "topgrade"]).exec();
|
let err = tmux.build().args(&["attach", "-t", "topgrade"]).exec();
|
||||||
panic!("{:?}", err);
|
panic!("{:?}", err);
|
||||||
} else {
|
} else {
|
||||||
println!("Topgrade launched in a new tmux session");
|
println!("Topgrade launched in a new tmux session");
|
||||||
@@ -83,13 +107,14 @@ pub fn run_in_tmux() -> ! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_remote_topgrade(hostname: &str, ssh: &Path) -> Result<(), Error> {
|
pub fn run_remote_topgrade(hostname: &str, ssh: &Path, tmux_args: &Option<String>) -> Result<(), Error> {
|
||||||
let command = format!(
|
let command = format!(
|
||||||
"{ssh} -t {hostname} env TOPGRADE_PREFIX={hostname} TOPGRADE_KEEP_END=1 topgrade",
|
"{ssh} -t {hostname} env TOPGRADE_PREFIX={hostname} TOPGRADE_KEEP_END=1 topgrade",
|
||||||
ssh = ssh.display(),
|
ssh = ssh.display(),
|
||||||
hostname = hostname
|
hostname = hostname
|
||||||
);
|
);
|
||||||
Command::new(which("tmux").unwrap())
|
Tmux::new(tmux_args)
|
||||||
|
.build()
|
||||||
.args(&["new-window", "-a", "-t", "topgrade:1", &command])
|
.args(&["new-window", "-a", "-t", "topgrade:1", &command])
|
||||||
.env_remove("TMUX")
|
.env_remove("TMUX")
|
||||||
.spawn()
|
.spawn()
|
||||||
|
|||||||
Reference in New Issue
Block a user