aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/src
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-20 04:42:10 +0000
committertv <tv@krebsco.de>2026-11-20 04:42:10 +0000
commit2aa54d9cb0399371a72a768cb5657a2bfebfde9e (patch)
treebcde33db3c3f07b0eec80e1f365c81de2cf0ad61 /pkgs/populate/src
parent7e4597a38a29f66fd8bbc7415973caeaa9442bde (diff)
populate: run shell code with /bin/sh
populate runs shell code on the deploying machine and on the target with /bin/sh, so neither needs a shell in PATH, as the PATH a CI job runs populate with may lack one.
Diffstat (limited to 'pkgs/populate/src')
-rw-r--r--pkgs/populate/src/rsync.rs2
-rw-r--r--pkgs/populate/src/run.rs17
-rw-r--r--pkgs/populate/src/sh.rs6
-rw-r--r--pkgs/populate/src/shell.rs2
4 files changed, 15 insertions, 12 deletions
diff --git a/pkgs/populate/src/rsync.rs b/pkgs/populate/src/rsync.rs
index 1b46723..05eb126 100644
--- a/pkgs/populate/src/rsync.rs
+++ b/pkgs/populate/src/rsync.rs
@@ -187,7 +187,7 @@ fn insecure_links(context: &Context, config: &Config, source: &str) -> Result<bo
}
// A dry run of the same transfer, as far as filtering goes.
let log = run::output(
- Command::new("sh")
+ Command::new(run::SH)
.arg("-c")
.arg(r#"rsync "$@" 2>&1 || :"#)
.arg("sh")
diff --git a/pkgs/populate/src/run.rs b/pkgs/populate/src/run.rs
index 9817b78..113bcf9 100644
--- a/pkgs/populate/src/run.rs
+++ b/pkgs/populate/src/run.rs
@@ -10,6 +10,10 @@ use std::path::{Path, PathBuf};
use std::process::{Child, Command, ExitStatus, Stdio};
use std::sync::atomic::{AtomicI32, Ordering};
+/// The shell running shell code, on the deploying machine and on the
+/// target, by its path, so neither needs a shell in PATH.
+pub const SH: &str = "/bin/sh";
+
/// Why populate stops before delivering everything.
#[derive(Debug)]
pub enum Failure {
@@ -158,7 +162,7 @@ impl Context {
/// now, so the script can be ssh in PATH itself, as for nix copy.
fn write_ssh(&self, path: &Path, options: &[String]) -> Result<()> {
let ssh = which("ssh").unwrap_or_else(|| PathBuf::from("ssh"));
- let mut script = format!("#!/bin/sh\nexec {}", quote(&ssh.to_string_lossy()));
+ let mut script = format!("#!{SH}\nexec {}", quote(&ssh.to_string_lossy()));
for word in options {
script.push(' ');
script.push_str(&quote(word));
@@ -257,17 +261,16 @@ impl Context {
.collect();
let args = args.as_slice();
if self.local {
- let mut command = Command::new("sh");
+ let mut command = Command::new(SH);
command.arg("-c").arg(script).arg("sh").args(args);
Ok(command)
} else {
let mut words = vec![
if self.target.sudo {
- "sudo sh -c"
+ format!("sudo {SH} -c")
} else {
- "sh -c"
- }
- .to_string(),
+ format!("{SH} -c")
+ },
quote(&script),
"sh".to_string(),
];
@@ -438,7 +441,7 @@ impl Context {
/// A command running shell code on the deploying machine, in dir, with
/// args as its positional parameters.
pub fn local_shell(script: &str, args: &[&str], dir: &Path) -> Command {
- let mut command = Command::new("sh");
+ let mut command = Command::new(SH);
command
.arg("-c")
.arg(format!("set -efu\n{script}"))
diff --git a/pkgs/populate/src/sh.rs b/pkgs/populate/src/sh.rs
index 040ec0a..7a61d92 100644
--- a/pkgs/populate/src/sh.rs
+++ b/pkgs/populate/src/sh.rs
@@ -106,7 +106,7 @@ remove_others() {
shift
n=$((n - 1))
done
- find "$dir" -mindepth 1 -maxdepth 1 "$@" -exec sh -c '
+ find "$dir" -mindepth 1 -maxdepth 1 "$@" -exec /bin/sh -c '
log=$1
shift
for path; do
@@ -282,7 +282,7 @@ pub fn break_hard_links() -> String {
+ r#"
remove_link "$1" "$2"
if test -d "$1"; then
- find "$1" -type f -links +1 -exec sh -c '
+ find "$1" -type f -links +1 -exec /bin/sh -c '
for file; do
copy=$(mktemp "$file.XXXXXX")
cp -p "$file" "$copy"
@@ -348,7 +348,7 @@ git_problems() (
exit
fi
nested=$(
- find "$path" -path "$git_dir" -prune -o -name .git -exec sh -c '
+ find "$path" -path "$git_dir" -prune -o -name .git -exec /bin/sh -c '
modules=$1
shift
for git; do
diff --git a/pkgs/populate/src/shell.rs b/pkgs/populate/src/shell.rs
index befd4aa..4093ed7 100644
--- a/pkgs/populate/src/shell.rs
+++ b/pkgs/populate/src/shell.rs
@@ -32,7 +32,7 @@ pub fn shell(options: ShellOptions) -> ExitCode {
words.push("sudo".to_string());
}
words.extend([
- "/bin/sh".to_string(),
+ run::SH.to_string(),
"-c".to_string(),
options.script,
"sh".to_string(),