init: scripts can now use #!

This commit is contained in:
Mark Poliakov 2023-12-08 17:52:21 +02:00
parent 440c89efaf
commit 3370b35811
6 changed files with 9 additions and 2 deletions

View File

@ -64,6 +64,7 @@ pack_initrd() {
cp ${build_dir}/red ${root_dir}/bin/red cp ${build_dir}/red ${root_dir}/bin/red
cp -r ${workspace_dir}/etc ${root_dir}/ cp -r ${workspace_dir}/etc ${root_dir}/
chmod +x ${root_dir}/etc/rc.d/*
cd "${root_dir}" cd "${root_dir}"
mkdir -p dev mkdir -p dev

View File

@ -1,3 +1,3 @@
init:1:wait:/sbin/rc default init:1:wait:/sbin/rc default
user:1:once:/sbin/login /dev/ttyS0 user:1:once:/sbin/login /dev/tty0

2
etc/rc.d/00-mount Normal file → Executable file
View File

@ -1,2 +1,4 @@
#!/bin/sh
/sbin/mount -t devfs /dev /sbin/mount -t devfs /dev
/sbin/mount -t sysfs /sys /sbin/mount -t sysfs /sys

0
etc/rc.d/99-motd Normal file → Executable file
View File

View File

@ -42,7 +42,7 @@ fn exec_script<P: AsRef<Path>>(path: P, arg: &str) -> Result<(), Error> {
// TODO run those in parallel, if allowed // TODO run those in parallel, if allowed
// TODO binfmt guessing // TODO binfmt guessing
let mut process = Command::new("/bin/sh").arg(path).arg(arg).spawn()?; let mut process = Command::new(path).arg(arg).spawn()?;
if !process.wait()?.success() { if !process.wait()?.success() {
eprintln!("{:?}: Failed", path); eprintln!("{:?}: Failed", path);

View File

@ -141,6 +141,10 @@ fn run(mut input: Input, vars: &mut HashMap<String, String>) -> io::Result<ExitC
} }
let line = line.trim(); let line = line.trim();
let line = match line.split_once('#') {
Some((line, _)) => line.trim(),
None => line
};
let cmd = parser::parse_line(vars, line).unwrap(); let cmd = parser::parse_line(vars, line).unwrap();
match exec(input.is_interactive(), &cmd, vars) { match exec(input.is_interactive(), &cmd, vars) {