
Escribí un script simple para nuestras máquinas Ubuntu en la universidad que establece algunas anulaciones de dconf para configurar el tema, el fondo, etc. Sin embargo, parece que no puedo configurar correctamente el fondo de la pantalla de inicio de sesión.
Sección del guión destinada a este fin:
#Set login background and remove dots
echo "Setting lightdm dconf settings"
xhost +SI:localuser:lightdm
su lightdm -c "gsettings set com.canonical.unity-greeter background '/background.png'"
su lightdm -c "gsettings set com.canonical.unity-greeter draw-grid false"
Estos mismos comandos funcionan si se ingresan directamente en una terminal que ha iniciado sesión como usuario de lightdm, por ejemplo:
sudo su lightdm -s /bin/bash
gsettings set com.canonical.unity-greeter background '/background.png'
gsettings set com.canonical.unity-greeter draw-grid false
Establece bien el fondo de pantalla
¿Alguna idea de por qué funcionan los comandos pero no el script?
Gracias
Respuesta1
Así es como lo resolví: en lugar de ejecutar "sudo bash" o, en su caso, ejecutar "sudo -c" (que hace que el script se detenga al cambiar de usuario o simplemente no funciona), ejecuto tres scripts pequeños.
(No olvides hacer ejecutable cada uno de los scripts con "chmod +x script_name.sh")
El primer script es mi install.sh:
sudo cp third_script.sh /tmp # Copy third_script to tmp for easier access
sudo chmod 0755 /tmp/third_script.sh # This needs to be executable by lightdm
sudo bash second_script.sh # Runs next file
sudo rm /tmp/third_script.sh # Now we can remove the third script
Luego, en second_script.sh agrego lightdm a xhost y ejecuto el tercer archivo de script como usuario lightdm:
#!/bin/bash
echo "$USER" # To see if root is running the script
xhost +SI:localuser:lightdm
su lightdm -s /tmp/third_script.sh
Y el tercer_script es donde ocurre la magia:
#!/bin/bash
echo "$USER" # To see if lightdm is running the script
gsettings set com.canonical.unity-greeter background '/background.png'
gsettings set com.canonical.unity-greeter draw-grid false
¡Esto funciona para mí! Déjame saber si hay alguna manera más fácil.