0

I am using preseed to auto install debian.
I want to be able to run a script called "run.sh" at the end of the Debian installation:

#!/bin/bash
touch /root/example.txt
echo $(hostname -I | cut -d"." -f 4) > /root/example.txt

I have tried several models that I have found by google (I add these commands to preseed.cfg):

d-i late_command string cp -a /cdrom/preseed/run.sh /target/root; chmod 777 /root/run.sh; /root/run.sh;

d-i preseed/late_command string \
  in-target cp run.sh /root/ && in-target chmod 755 /root/run.sh \
  cd /target; \
  chmod +x ./run.sh; \
  chroot ./ ./run.sh;

I have tried everything I have seen and it has occurred to me, on none of the occasions have I been successful. The most I have achieved is a red screen with an error that the file "run.sh" is corrupt

I just saw a similar question from 2015

UPDATE:

These commands work

d-i preseed/late_command string mkdir -p /target/root/one

d-i preseed/late_command string cp /cdrom/files/jitsi/run.sh /target/root/; chmod +x /target/root/run.sh;
ICIM
  • 139
  • 1
  • 10
  • I haven't tried anything the like before, so can't verify that my assumptions are correct; but to me the `in-target cp run.sh /root/` makes no sense, because it assumes that the *run.sh* already exists somewhere in the target environment. Have you tried `cp run.sh /target/root/` and `chmod 755 /target/root/run.sh` (without **in-target**)? – tink Jul 14 '21 at 17:53
  • In theory it should be the same as `d-i late_command string cp -a /cdrom/preseed/run.sh /target/root` and yes, I have tried it. On Ubuntu it works, but on Debian it doesn't – ICIM Jul 14 '21 at 18:21

1 Answers1

1

Surely the reason that it does not work when trying to execute is because the route has not been declared. You can use this failing that:

  d-i preseed/late_command string cp /cdrom/files/jitsi/run.sh /target/root/; chmod +x /target/root/run.sh; in-target /bin/bash /root/run.sh

JuDy94
  • 26
  • 4