I want to let users write an ISO to a USB pen drive from within Thunar or Dolphin.
For this I've created a bash script which uses dd, pv and zenity.
Currently I'm using pkexec to ask for a password before the dd command is executed, but the pkexec window and the zenity progress window are both opened at the same time. I'd like to open a window for the root password first after which the zenity progress window should be opened.
I tried to ask for the password with zenity first after which I pipe the password to sudo but wherever I put the "echo $PWD", the password is not piped into sudo.
#!/bin/bash
TITLE='Zenity Progress Test'
PASSWORD=$(zenity --password \
--width=300 \
--title="$TITLE")
if [ ! -z "$PASSWORD" ]; then
echo "Your password: $PASSWORD"
dd if=/dev/zero of="$PWD/testfile1" bs=1M count=100
pv -n testfile1 2> >(zenity --progress \
--width=300 \
--title="$TITLE" \
--percentage=0 \
--auto-close \
--auto-kill) | echo "$PASSWORD" | sudo -S dd of="$PWD/testfile2" bs=64k oflag=dsync
echo "$PASSWORD" | sudo -S rm "$PWD/testfile1" "$PWD/testfile2"
else
echo 'No password provided'
exit 1
fi
The zenity progress window just flashes by and nothing is transferred, most likely because the password is not piped into sudo.
If you replace "echo $PASSWORD | sudo -S" with "pkexec" the code functions but with both the pkexec window and the zenity progress window opened together.
Any ideas on how to solve this puzzle?