How to assign a bash script for every user created with cubic and how to execute it automatically one time only

Asked by Marietto

Hello to everyine,

I'm tryng to create a custom ubuntu installation with cubic where I would like that qemu,kvm and virt-manager with all the dependencies worked like a charm. To do that,I need that every user that is created as soon as Xubuntu will start working,will execute these commands only one time :

groupadd libvirt
sudo usermod -a -G libvirt `whoami`
sudo adduser `whoami` libvirt

otherwise it will not work. So,I'm trying to figure out how to do this. I've tought to add a script like this on the /etc/skel/autostart folder within the cubic environment :

[Desktop Entry]
Type=Application Version=1.0
Name=virt-manager-preparation
Comment=virt-manager preliminary script
Exec=/opt/prepare-virt-manager.sh
StartupNotify=false
Terminal=false

and on /opt,the script called prepare-virt-manager.sh

#!/bin/bash groupadd libvirt
sudo usermod -a -G libvirt `whoami`
sudo adduser `whoami` libvirt

making it executable :

chmod +x /opt/prepare-virt-manager.sh

Soon I've realized that my script would need to be run as root. Sticking it in skel would just put it in every new user's autostart folder but none of them would be root so the local autostart would fail.

So I tried to name my script adduser.local and I've sticked it in /usr/local/sbin, which is executed after adding a new user and is run by root. adduser.local is executed after adduser runs.

/usr/local/sbin/adduser.local :

#!/bin/bash usermod -a -G libvirt $1

Unfortunately when I have installed the cubic iso image,I've realized that it is not executed. How ? I have executed it again,but this time using the username of the user created,like this:

sudo usermod -a -G libvirt john

and after a reboot,virt-manager worked like a charm. So,I would like to know why the /usr/local/sbin/adduser.local script is not executed. Keep in consideration that I tried to make it executable,but Xubuntu frozen during the boot. Thanks.

Question information

Language:
English Edit question
Status:
Answered
For:
Cubic Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Manfred Hampl (m-hampl) said :
#1

Have you considered doing this in a different way?

In the configuration file /etc/adduser.conf the option EXTRA_GROUPS defines the groups that are assigned to each user at creation time. Adding "libvirt" to it should have a similar effect.

Revision history for this message
Marietto (marietto2008) said (last edit ):
#2

ok I did that. I've re created the iso and I've tested it with qemu. Unfortunately it didn't work. The error is :

Unable to connect to libvirt qemu:///system.
Verify that the 'libvirtd' daemon is running.
Libvirt URI is: qemu:///system
Traceback (most recent call last):
  File "/usr/share/virt-manager/virtManager/connection.py", line 923, in _do_open
    self._backend.open(cb, data)
  File "/usr/share/virt-manager/virtinst/connection.py", line 153, in open
    conn = libvirt.openAuth(self._open_uri,
  File "/usr/lib/python3/dist-packages/libvirt.py", line 148, in openAuth
    raise libvirtError('virConnectOpenAuth() failed')
libvirt.libvirtError: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied

you can see here what I did :

https://ibb.co/KF81jrr

and I have removed the /usr/local/sbin/adduser.local file.

To confirm that your idea still does not work,I've installed xubuntu on a disk,I've issued this command :

usermod -a -G libvirt john

I've rebooted and boom...it worked.

Revision history for this message
Manfred Hampl (m-hampl) said (last edit ):
#3

Did you set ADD_EXTRA_GROUPS to a value different from zero?
See in your screen shot the lines below "EXTRA_GROUPS=..."

Revision history for this message
Marietto (marietto2008) said :
#4

Yesterday it didn't work even setting ADD_EXTRA_GROUPS=1 , today it works. Mysteries of faith.

Can you help with this problem?

Provide an answer of your own, or ask Marietto for more information if necessary.

To post a message you must log in.