Score:0

Run script after Debian installation is complete

mq flag

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

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

djdomi avatar
za flag
you should run this script by /path/to/bash /path/to/script IMHO
mq flag
Thanks for the help, but I have managed to solve the problem (I have reused the answer from the other forum, but it is equally valid)
djdomi avatar
za flag
and to be honestly, it is that what i told,. use bash and the script with the native path to run it :-)
mq flag
In debian it is understood that the path is `/cdrom/` when the manual does not say that, in the examples it says that it is `/hd-media/`. And the `in-target /bin/bash` is also an intuitive thing ...
Score:1
mq flag

This solution is based on the fact that you use a USB to install the OS, and that you will have in the root of the USB a folder called files where you will have the file preseed.cfg and an executable called run.sh.

This command will copy the file run.sh to the root of the user root and there it will execute the script.

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

After this you can use rm to delete the file. You can also run the script directly from the USB (without copying it), but after some tests I have verified that it can induce human errors

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.