I'm trying to add a context menu option to Nautilus so that when I right click on a file, I can choose to run srm to securely overwrite it with zeros instead of moving it to /Trash or rm'ing it. I have the following executable in ~/.local/share/nautilus/scripts
#!/bin/bash
#Make local Nautilus filepath variable global
export srmthis=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
#Copy the above variable to a log
echo "$srmthis" >> logfile.txt
#Now, please srm secure-delete the file indicated in the filepath
sudo -E /usr/bin/srm -flz "$srmthis"
$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS is a variable set by Nautilus when a file is selected within it. My thinking is that I'd grab that into my own variable $srmthis and then pass it to srm as its target file with options "-flz" for a faster, albeit more insecure wipe.
But it doesn't work. No output, no popup warning.
When I echo "$filetosrm" >> somefile.txt
I do get an output so I know the variable is set. I can also use srm by itself in the terminal no problem.
What am I doing wrong?
Many thanks!
P.S. Tried running srm with gksu, pkexec, | xargs, etc to no avail.
Figured this out. Here's the new code that works:
#!/bin/bash
#Make local Nautilus filepath variable global
srmthis=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
#Copy the above variable to a log
echo "$srmthis" >> srmtemp.txt
#Get the first line from temp file to get rid of annoying newline
line=$(head -n1 srmtemp.txt)
#Wipe the file with srm: -fllz fast mode, -r recursively for any subdirectories
/usr/bin/srm -fllzr "$line"
#Clean up
/usr/bin/srm -l srmtemp.txt
Also, instead of using sudo /usr/bin/srm
I ended up adding srm
to my /etc/sudoers
for my username with whiterabbit ALL = (root) NOPASSWD: /usr/bin/srm
which allowed it to run without having to have the command sudo
in the script.
This adds srm as a Nautilus script. I can now rightclick on a file and then go to Scripts -> SRM and wipe-delete the file with zeros right in the GUI instead of rm'ing it or moving it to trash.