1

I am trying to do the following with a shortcut on the Desktop :

echo "dtoverlay=pi3-miniuart-bt" >> /boot/config.txt
systemctl disable hciuart

I have tried to put it in a script but when I double click it,it just does nothing.

The above also needs to be run as sudo to be able to append the config.txt file.

This is my shortcut file:

[Desktop Entry]
Version=1.0
Type=Application
Name=RPi3 Serial Fix
Comment=RPi3 Serial Fix
Exec=sudo ./007B-RPi3-config.sh
Icon=bCNC.png
Terminal=true
StartupNotify=false

The Terminal window opens and closes very quickly when I double click on the shortcut. (Is there a way to keep it open to see what has been run?)

3
  • 1
    Why are you trying to do this from a shortcut, IIRC it is going to need a restart so what is the advntabe of a desktop shortcut? Commented Mar 21, 2016 at 1:56
  • I am building an RPi image that can be run on Rpi V1-3. It has pre-installed software but because the RPi3 changed the serial pins this script needs to be run by the user to configure the pins if they have a RPi3 Commented Mar 21, 2016 at 2:33
  • 1
    The simple way to do this would be to make a script bash or the like and then make the shortcut call the script. This will also get around the sudo issue (sudo will be required to modify the file in /dev. I would probably have two files in the directory and mv the correct file into place. You may also want to look at doing some device detecting and let it self configure based on the Pi model it is running on, To call all deep on this you could use something like puppet (configuration management software) I use this on my Pi's for quick setup etc. Commented Mar 21, 2016 at 2:36

1 Answer 1

2

You should use one of kdesu, kdesudo or gtksudo (depending on your desktop environment) to run the script as root. It will give you a gui prompt for your password rather than just sudo which wants an interactive terminal.

Also need to specify the full path to your script. eg $HOME/Desktop/007B-RPi3-config.sh as the desktop entry will not execute things from the desktop folder.

The terminal closes when the script exit, which your does very quickly so the terminal will just flicker on screen briefly before disappearing. You can get around this by appending read to your script which will cause it to hang waiting for some input. This should give you enough time to read the output.

As an aside, you echo line will keep appending the line to the file, which will slowly increase in size. You may want to use the following instead:

grep "^dtoverlay=" /boot/config.txt && sed -i 's/dtoverlay=.*/dtoverlay=pi3-miniuart-bt/' /boot/config.txt || echo "dtoverlay=pi3-miniuart-bt" >> /boot/config.txt

This will append the option if it does not exist or replace it if it already exists.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.