Desktop shortcut which will ask for su password

My goal is to have a shortcut on my Xfce desktop, pointing to a script file in my user folder. I would like the script file to copy all of the documents located within my Documents directory onto a USB thumb drive formatted with FAT 32. Also, at the moment, whenever I click on my desktop shortcut (copy_docs_usb.desktop) it opens up a new terminal and it carries out the script, but it also seems that not all of the folders and documents located with my user Documents directory are getting backed up onto the usb.

In other words, If I become root and run the script from within a terminal, without clicking on, copy_docs_usb.desktop, I seem to get slightly different results. So, I'm thinking that I need to modify my desktop file so that it somehow asks for the super user password before it actually tries to carry out the script I have created.

Below is what I have inside the desktop file on my desktop.
Code:
[Desktop Entry]
Version=1.0
Type=Application
Name=copy_docs_usb
Comment=copy user and system folders to backup
Exec=/home/Simon/Temp/copy_docs_usb.sh
Icon=process-completed
Terminal=true
StartupNotify=false
Categories=Utility;
Path=
GenericName=short cut to script file for backups
# EOF

Also, below is what I have within the script file I use to copy my documents to a USB.

Code:
#!/bin/sh
# USING RSYNC TO BACKUP AND RESTORE SYSTEM DIRECTORIES

# +++ Copy docs to backup usb +++

rsync -r -v --progress -l -H -b -s /home/Simon/Documents /media/BACKUPUSB

echo "Script finished."
So I would like to be able to click on my desktop file, and then have a terminal open up, I enter my su password, and then it carries out the backup for me. I feel like I'm close, but I seem to have confused myself once again.
 
You can use doas which is an alternative to sudo

And then create a doas rule for your script so it will run without prompting you for your password

Install doas

Code:
sudo pkg install doas

edit the doas.conf

Code:
sudo vi /usr/local/etc/doas.conf

From your post i guess your username is Simon,
if it isnt change Simon in the code below

Replace the contents of the doas.conf with this code

Code:
#=========================================================================#
# doas.conf
#=========================================================================#

#=========================================================================#
# permit user
#=========================================================================#

permit keepenv setenv { PATH } Simon


#=========================================================================#
# allow root to switch to our user
#=========================================================================#

permit nopass keepenv setenv { PATH } root as Simon


#=========================================================================#
# script permit user - no pass
#=========================================================================#

permit nopass keepenv Simon cmd /home/Simon/Temp/copy_docs_usb.sh


#=========================================================================#
# root as root
#=========================================================================#

permit nopass keepenv root as root

This line allow you to run the script with elevated permission while keeping your enviornment settings

Code:
permit nopass keepenv Simon cmd /home/Simon/Temp/copy_docs_usb.sh

Edit your desktop entry

Code:
[Desktop Entry]
Version=1.0
Type=Application
Name=copy_docs_usb
Comment=copy user and system folders to backup
Exec=sh -c '/usr/local/bin/doas /home/Simon/Temp/copy_docs_usb.sh'
Icon=process-completed
Terminal=false
StartupNotify=false
Categories=Utility;
Path=
GenericName=short cut to script file for backups

I changed the exec line to use doas and then run your script

Code:
Exec=sh -c '/usr/local/bin/doas /home/Simon/Temp/copy_docs_usb.sh'

and this line for the Terminal to false
because you dont need to enter you password as doas is set up so you dont need to

Code:
Terminal=false

That should do the job
 
as a side issue, find out why you've got files in your home directory that are not owned by you nor being backed up. ideally everything under $HOME should be chown {myuid}, and not belong to any other user.
 
Back
Top