Is it possible to create users or do other post-install steps by customizing the ISO ?

Asked by Stefan Seefeld

I'd like to be able to script various post-installation tasks, such as the creation of user accounts. Is it possible to do that via cubic ?

Question information

Language:
English Edit question
Status:
Solved
For:
Cubic Edit question
Assignee:
No assignee Edit question
Solved by:
Stefan Seefeld
Solved:
Last query:
Last reply:
Revision history for this message
Stefan Seefeld (s8efan) said :
#1

I'd like to be able to script various post-installation tasks, such as the creation of user accounts. Is it possible to do that via cubic ?

Revision history for this message
Cubic PPA (cubic-wizard) said :
#2

When you say "post install" steps, are you referring to the situation when ubiquity is still running, or has just finished, but you are still in the Live environment?

Or are you referring to wen you've booted into the installed customized system (for the 1st time) on your computer?

Revision history for this message
Stefan Seefeld (s8efan) said :
#3

I'm talking about the latter, i.e. after the installation (on disk) is complete. We need a custom installation that includes some configurations that can only be done once user accounts are created. And as in our use-case we only want a single user account, all that could be fully scripted, so the install process would be (mostly) non-interactive.

Revision history for this message
Cubic PPA (cubic-wizard) said :
#4

Have you considered using an autostart script?

Something like...

Place the script in the /opt directory while you are using Cubic.
    /opt/custom_setup/setup_script.sh

Also, place a not_done_flag.txt file there as well.
    /opt/custom_setup/not_done_flag.txt

Place a launcher in all new user's home directory.
    /etc/.skel/.config/autostart/setup_script.desktop

Once a user logs in, the setup_script.desktop launcher will automatically launch and start setup_script.sh.
The script checks for the existence of opt/custom_setup/not_done_flag.txt.
If this file does not exist, the script should exit.
If this file exists, the script should continue.
(Your script can ask for sudo credentials to run. Otherwise, you can use PolicyKit to allow the script to perform root functions without requiring a sudo password. (https://wiki.debian.org/PolicyKit)).
Once the script completes successfully, it should delete /opt/custom_setup/not_done_flag.txt.

-------

If you don't want to use autostart, another option that may be viable for you is to execute your script each time apt is used to install software or updates. (You may want still to use the flag technique above to make sure your script only runs once).

Add an entry to `/etc/apt/apt.conf.d/80update`.
This entry should invoke your script that makes the updates/changes that you want.

For example, to the file:
    /etc/apt/apt.conf.d/80update
Add:
    DPkg::Post-Invoke {"/opt/custom_setup/setup_script.sh";};

Make the change to 80update only after you've finished executing all of your other apt based changes in Cubic's Terminal page; otherwise your script will try to run each time you use apt inside Cubic.

-------

Note: I think you might also need to put a check in your script to ensure it doesn't run while in the Live Environment.

Revision history for this message
Cubic PPA (cubic-wizard) said :
#5

Correction:

There was a typo in the following pah:

    /etc/.skel/.config/autostart/setup_script.desktop

It should have been (without the "." in front of "skel":

    /etc/skel/.config/autostart/setup_script.desktop

Revision history for this message
Stefan Seefeld (s8efan) said :
#6

Thanks, that's very helpful information indeed !
Is there an environment variable or other flag I can check to detect that I'm in the Live Environment ?

Revision history for this message
Cubic PPA (cubic-wizard) said :
#7

If you don't change the default live session user in Cubic, it will always be "ubuntu".

So one suggestion is that you could just check for one of these environment variables in your script:

LOGNAME=ubuntu
HOME=/home/ubuntu
USERNAME=ubuntu
USER=ubuntu

Revision history for this message
Stefan Seefeld (s8efan) said :
#8

That would work indeed. Thanks !