BBC BASIC desktop shortcut (Linux)

discuss PC<>Acorn file transfer issues & the use of FDC, XFER, Omniflop/disk etc.
User avatar
Richard Russell
Posts: 528
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

BBC BASIC desktop shortcut (Linux)

Post by Richard Russell » Thu Oct 18, 2018 11:42 am

Cross-posted from the BBC BASIC discussion group

An annoying feature of the Linux (including Raspberry Pi) editions of BBC BASIC for SDL 2.0 is the awkwardness of creating a desktop shortcut. I supply (with the RPi edition) a template .desktop file which can be edited to contain the correct paths to the icon and executable (these are of course determined by the user on installation, so aren't known in advance) but it's a pain. I feel sure that it should be possible to create a shell script, that I could supply with BBCSDL, which would automatically create and deploy the .desktop file (or whatever is necessary for the current GUI) without the user needing to do it manually.

Would somebody here be able to write such a script for me?

Soruk
Posts: 216
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Soruk » Thu Oct 18, 2018 12:25 pm

Try this:

Code: Select all

#!/bin/bash
MYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
echo "[Desktop Entry]
Name=BBC BASIC
Comment=BBC BASIC for Raspberry Pi
Icon=$MYDIR/bbc256x.png
Exec=$MYDIR/bbcsdl
Type=Application
Encoding=UTF-8
Terminal=false
Categories=None;" > $HOME/Desktop/bbcsdl.desktop
as something like "mkdesktopicon.sh", placed in the same directory as bbcsdl and bbc256x.png
Last edited by Soruk on Thu Oct 18, 2018 12:26 pm, edited 2 times in total.

User avatar
Richard Russell
Posts: 528
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Richard Russell » Thu Oct 18, 2018 12:48 pm

Soruk wrote:
Thu Oct 18, 2018 12:25 pm
Try this:
Wow, that was quick! I'll definitely try it. :D

User avatar
Richard Russell
Posts: 528
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Richard Russell » Thu Oct 18, 2018 1:16 pm

It works beautifully on a Raspberry Pi - thank you - but sadly not on Ubuntu 18.04 (reports 'Untrusted application launcher'). Do you happen to know the correct incantation for Ubuntu? Can I assume that it's not going to be possible to create a 'universal' script that will run on all popular Linux distros and desktops?

Soruk
Posts: 216
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Soruk » Thu Oct 18, 2018 1:24 pm

Richard Russell wrote:
Thu Oct 18, 2018 1:16 pm
It works beautifully on a Raspberry Pi - thank you - but sadly not on Ubuntu 18.04 (reports 'Untrusted application launcher'). Do you happen to know the correct incantation for Ubuntu? Can I assume that it's not going to be possible to create a 'universal' script that will run on all popular Linux distros and desktops?
Try doing:

Code: Select all

chmod +x $HOME/Desktop/bbcsdl.desktop
If that fixes it, add that as the last line of the script.

User avatar
Richard Russell
Posts: 528
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Richard Russell » Thu Oct 18, 2018 3:29 pm

Soruk wrote:
Thu Oct 18, 2018 1:24 pm
If that fixes it, add that as the last line of the script.
I initially thought it had made no difference, but then I spotted that a 'Trust and Launch' button had appeared which wasn't there previously; clicking that just once is all that's required to remove the warning permanently. Thanks!

Soruk
Posts: 216
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Soruk » Thu Oct 18, 2018 4:08 pm

Richard Russell wrote:
Thu Oct 18, 2018 3:29 pm
Soruk wrote:
Thu Oct 18, 2018 1:24 pm
If that fixes it, add that as the last line of the script.
I initially thought it had made no difference, but then I spotted that a 'Trust and Launch' button had appeared which wasn't there previously; clicking that just once is all that's required to remove the warning permanently. Thanks!
You're welcome! Just glad I was able to help.

User avatar
Richard Russell
Posts: 528
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Richard Russell » Thu Oct 18, 2018 5:16 pm

Soruk wrote:
Thu Oct 18, 2018 4:08 pm
You're welcome! Just glad I was able to help.
One more question, if I may. As discussed in another thread, some incompatibility requires the 32-bit Linux edition of BBCSDL to be executed using:

Code: Select all

env IBUS_ADDRESS=0 ./bbcsdl
I haven't managed to find a way of running that from the desktop shortcut. I put the command string in a separate file and specified it as the 'executable' in the .desktop file, but it doesn't work (although running it from a command prompt does).

Soruk
Posts: 216
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Soruk » Thu Oct 18, 2018 6:46 pm

Richard Russell wrote:
Thu Oct 18, 2018 5:16 pm
Soruk wrote:
Thu Oct 18, 2018 4:08 pm
You're welcome! Just glad I was able to help.
One more question, if I may. As discussed in another thread, some incompatibility requires the 32-bit Linux edition of BBCSDL to be executed using:

Code: Select all

env IBUS_ADDRESS=0 ./bbcsdl
I haven't managed to find a way of running that from the desktop shortcut. I put the command string in a separate file and specified it as the 'executable' in the .desktop file, but it doesn't work (although running it from a command prompt does).
Can you share the script you were using to start it, in its entirety?

User avatar
Richard Russell
Posts: 528
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Richard Russell » Thu Oct 18, 2018 8:25 pm

Soruk wrote:
Thu Oct 18, 2018 6:46 pm
Can you share the script you were using to start it, in its entirety?
It's literally just that one line. Generally that kind of 'naked' script seems to work for me, and does if I simply execute it from the command line, but maybe it needs more when called from the shortcut.

Soruk
Posts: 216
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Soruk » Thu Oct 18, 2018 8:32 pm

Richard Russell wrote:
Thu Oct 18, 2018 8:25 pm
Soruk wrote:
Thu Oct 18, 2018 6:46 pm
Can you share the script you were using to start it, in its entirety?
It's literally just that one line. Generally that kind of 'naked' script seems to work for me, and does if I simply execute it from the command line, but maybe it needs more when called from the shortcut.
Try this:

Code: Select all

#!/bin/bash
IBUS_ADDRESS=0 ./bbcsdl

Coeus
Posts: 1079
Joined: Mon Jul 25, 2016 11:05 am
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Coeus » Thu Oct 18, 2018 8:52 pm

Soruk wrote:
Thu Oct 18, 2018 8:32 pm
Try this:

Code: Select all

#!/bin/bash
IBUS_ADDRESS=0 ./bbcsdl
Did that work. It is not clear from the Desktop File Specification, but I suspect the Exec key is only similar to a shell command line and isn't actually parsed by a shell so some shell features won't work. Invoking a wrapper shell script is one option but running the env program to set the environment variable and then launch the application is a reasonable solution. It may be necessary to specify the full path to bbcsdl, though i.e. the line to generate the Eexec= line in the script that generates the .desktop file becomes:

Code: Select all

Exec=env IBUS_ADDRESS=0 $MYDIR/bbcsdl

Soruk
Posts: 216
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Soruk » Thu Oct 18, 2018 9:01 pm

Coeus wrote:
Thu Oct 18, 2018 8:52 pm
Soruk wrote:
Thu Oct 18, 2018 8:32 pm
Try this:

Code: Select all

#!/bin/bash
IBUS_ADDRESS=0 ./bbcsdl
Did that work. It is not clear from the Desktop File Specification, but I suspect the Exec key is only similar to a shell command line and isn't actually parsed by a shell so some shell features won't work. Invoking a wrapper shell script is one option but running the env program to set the environment variable and then launch the application is a reasonable solution. It may be necessary to specify the full path to bbcsdl, though i.e. the line to generate the Eexec= line in the script that generates the .desktop file becomes:

Code: Select all

Exec=env IBUS_ADDRESS=0 $MYDIR/bbcsdl
My suggestion was to be entered as a separate script, e.g. start.sh, which the .desktop file would call.

User avatar
Richard Russell
Posts: 528
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Richard Russell » Thu Oct 18, 2018 9:35 pm

Coeus wrote:
Thu Oct 18, 2018 8:52 pm
It may be necessary to specify the full path to bbcsdl
Yes, that was it. Somehow I assumed that the 'current directory' would be the directory containing the script, but evidently not. Specifying it absolutely worked (adding the #!/bin/bash didn't seem to make a difference, but perhaps I should include it for safety). Thanks again.

User avatar
Richard Russell
Posts: 528
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Richard Russell » Thu Oct 18, 2018 9:53 pm

For the record, here's the script I ended up with:

Code: Select all

#!/bin/bash
MYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
echo "[Desktop Entry]
Name=BBC BASIC
Comment=BBC BASIC for Linux
Icon=$MYDIR/bbc256x.png
Exec=$MYDIR/bbclaunch
Type=Application
Encoding=UTF-8
Terminal=false
Categories=None;" > $HOME/Desktop/bbcsdl.desktop
chmod +x $HOME/Desktop/bbcsdl.desktop
echo "env IBUS_ADDRESS=0 $MYDIR/bbcsdl" > $MYDIR/bbclaunch
chmod +x $MYDIR/bbclaunch

User avatar
sweh
Posts: 1969
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by sweh » Fri Oct 19, 2018 2:34 am

Richard Russell wrote:
Thu Oct 18, 2018 9:53 pm
For the record, here's the script I ended up with:

Code: Select all

echo "env IBUS_ADDRESS=0 $MYDIR/bbcsdl" > $MYDIR/bbclaunch
chmod +x $MYDIR/bbclaunch
From a packaging aspect, that is really nasty. You should just have "bbclaunch" work out where it is and so have the file already in the archive.

Something like (untested)

Code: Select all

#!/bin/bash
MYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
export IBUS_ADDRESS=0
exec $MYDIR/bbcsdl
Now you don't need to generate this file at installation time; it can be part of the package.
Last edited by sweh on Fri Oct 19, 2018 2:34 am, edited 1 time in total.
Rgds
Stephen

User avatar
Richard Russell
Posts: 528
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Richard Russell » Fri Oct 19, 2018 8:39 am

sweh wrote:
Fri Oct 19, 2018 2:34 am
Now you don't need to generate this file at installation time; it can be part of the package.
Since (presumably) there's no alternative but to generate the bbcsdl.desktop file at installation time, I don't really understand what the problem is with generating the bbclaunch file as well. Is your concern where it's generated? If so perhaps there's a better place.

Soruk
Posts: 216
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Soruk » Fri Oct 19, 2018 9:56 am

Richard Russell wrote:
Fri Oct 19, 2018 8:39 am
sweh wrote:
Fri Oct 19, 2018 2:34 am
Now you don't need to generate this file at installation time; it can be part of the package.
Since (presumably) there's no alternative but to generate the bbcsdl.desktop file at installation time, I don't really understand what the problem is with generating the bbclaunch file as well. Is your concern where it's generated? If so perhaps there's a better place.
I think it's fine for a personal installation, but someone packaging up as a .deb or .rpm would probably install into known, defined locations (and probably add to the menus rather than drop a desktop icon) so the packager would sort this out (and, since the packages would install to defined locations the dynamic desktop button thing wouldn't be needed).

User avatar
sweh
Posts: 1969
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by sweh » Fri Oct 19, 2018 10:38 am

Richard Russell wrote:
Fri Oct 19, 2018 8:39 am
sweh wrote:
Fri Oct 19, 2018 2:34 am
Now you don't need to generate this file at installation time; it can be part of the package.
Since (presumably) there's no alternative but to generate the bbcsdl.desktop file at installation time, I don't really understand what the problem is with generating the bbclaunch file as well. Is your concern where it's generated? If so perhaps there's a better place.
Desktop icons can be considered "configuration" and are expected to be variable. Application files... aren't.
Rgds
Stephen

User avatar
Richard Russell
Posts: 528
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Richard Russell » Fri Oct 19, 2018 11:56 am

sweh wrote:
Fri Oct 19, 2018 10:38 am
Application files... aren't.
Since I supply BBC BASIC for SDL 2.0 as a zip file I really can't see what the fundamental difference is between creating hundreds of files as a result of unpacking the zip and creating one more file to assist with launching from a desktop shortcut. They both happen at 'installation time' and if I could automate the latter as a result of the former I would, but I can't.

User avatar
sweh
Posts: 1969
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by sweh » Fri Oct 19, 2018 3:18 pm

Not everything is necessarily done as the same user that "installed" the software. It's common, on Unix like systems, to put executables in an area where they can't be overwritten by mistake. It's one reason why malware has less impact; the user you run programs as just doesn't have the permission needed to break things!

e.g.

Code: Select all

% su - root
# mkdir /usr/local/bbcbasic
# cd /usr/local/bbcbasic
# unzip /tmp/bbclinux.zip
# exit
% /usr/local/bbcbasic/create_desktop_shortcut
The desktop shortcut is "my" personal configuration and I can not write to /usr/local/bbcbasic while it is running.
Rgds
Stephen

User avatar
Richard Russell
Posts: 528
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Richard Russell » Fri Oct 19, 2018 3:47 pm

sweh wrote:
Fri Oct 19, 2018 3:18 pm
It's common, on Unix like systems, to put executables in an area where they can't be overwritten by mistake.
Wow, so it's gradually catching up with Windows then (a few decades late)?! It's just a shame that there's no such thing as a universal binary format that will install on every Linux machine (c.f. Windows PE format) and no such thing as an installer that can package an app and take care of all the things that need to be done on installation (c.f. Inno Setup and many others). I admit to being a Linux hater, but can you blame me when every other platform I support (Windows, MacOS, Android, iOS) allows me to ship a self-installing package that 'just works' (and, yes, I know about Snaps)? :x

I needed to get that off my chest! But seriously, in Windows the app itself is of course stored in a non-user-writable place so certainly it would be unacceptable to create a file there (other than during installation itself). But there's a specific place where such files can be written: %APPDATA%; is there an equivalent in Linux?

Soruk
Posts: 216
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Soruk » Fri Oct 19, 2018 4:44 pm

Richard Russell wrote:
Fri Oct 19, 2018 3:47 pm
sweh wrote:
Fri Oct 19, 2018 3:18 pm
It's common, on Unix like systems, to put executables in an area where they can't be overwritten by mistake.
Wow, so it's gradually catching up with Windows then (a few decades late)?! It's just a shame that there's no such thing as a universal binary format that will install on every Linux machine (c.f. Windows PE format) and no such thing as an installer that can package an app and take care of all the things that need to be done on installation (c.f. Inno Setup and many others). I admit to being a Linux hater, but can you blame me when every other platform I support (Windows, MacOS, Android, iOS) allows me to ship a self-installing package that 'just works' (and, yes, I know about Snaps)? :x

I needed to get that off my chest! But seriously, in Windows the app itself is of course stored in a non-user-writable place so certainly it would be unacceptable to create a file there (other than during installation itself). But there's a specific place where such files can be written: %APPDATA%; is there an equivalent in Linux?
Usually, $HOME/.<appname>/

User avatar
Richard Russell
Posts: 528
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Richard Russell » Fri Oct 19, 2018 5:24 pm

Soruk wrote:
Fri Oct 19, 2018 4:44 pm
Usually, $HOME/.<appname>/
Thanks. So it would be better to create the bbclaunch file there, when one is necessary?

If I was to adopt the alternative technique of shipping the bbclaunch file with the app, I'm unclear how (or if) using 'export' differs from using 'env' on the same line as the bbcsdl command. Are they equivalent?

User avatar
Elminster
Posts: 3137
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Elminster » Fri Oct 19, 2018 5:31 pm

Richard Russell wrote:
Fri Oct 19, 2018 3:47 pm
sweh wrote:
Fri Oct 19, 2018 3:18 pm
It's common, on Unix like systems, to put executables in an area where they can't be overwritten by mistake.
Wow, so it's gradually catching up with Windows then (a few decades late)?!
Think you have that the wrong way around. UNIX did that from day one, decades before Windows was invented.

User avatar
sydney
Posts: 2249
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by sydney » Fri Oct 19, 2018 5:37 pm

Elminster wrote:
Fri Oct 19, 2018 5:31 pm
Richard Russell wrote:
Fri Oct 19, 2018 3:47 pm
sweh wrote:
Fri Oct 19, 2018 3:18 pm
It's common, on Unix like systems, to put executables in an area where they can't be overwritten by mistake.
Wow, so it's gradually catching up with Windows then (a few decades late)?!
Think you have that the wrong way around. UNIX did that from day one, decades before Windows was invented.
When did Windows introduce it? I'm pretty sure typing 'deltree *.*' would have been pretty catastrophic on the earlier versions.

User avatar
dhg2
Posts: 97
Joined: Tue Oct 25, 2016 7:37 pm
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by dhg2 » Fri Oct 19, 2018 6:02 pm

sydney wrote:
Fri Oct 19, 2018 5:37 pm
When did Windows introduce it? I'm pretty sure typing 'deltree *.*' would have been pretty catastrophic on the earlier versions.
I'm not a windows expert, but I think it would have been introduced with Windows NT. But I have the impression that a lot of people used Windows 2000 and XP (which are NT based) with admin accounts all the time, and it wasn't until Windows Vista that most people started using user accounts with normal privileges.

I could be completely wrong, and I don't have a lot of recent experience as I've been a full-time Linux user since 2005.
Regards,
- Patrick

User avatar
Elminster
Posts: 3137
Joined: Wed Jun 20, 2012 8:09 am
Location: Essex, UK
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Elminster » Fri Oct 19, 2018 6:21 pm

And windows NT security model owes more to VMS than win 3.1, or so they say.

Soruk
Posts: 216
Joined: Mon Jul 09, 2018 10:31 am
Location: Basingstoke, Hampshire
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by Soruk » Fri Oct 19, 2018 9:09 pm

Please let's not have this thread degenerate into a Windows vs UNIX argument.

(I'm a professional Linux sysadmin, so no surprises where my loyalties lie, but I try to remain impartial.)

If bbclaunch needs to be in the same place as the executable then it should stay with it, rather being in a local configuration directory. As the script is something that is run, it's classed as an executable, not configuration.

As for the difference with env and export, env <var>=<value> <process>, the environment variable is set for the subprocess but not the current shell. export <var>=<value> [<process>] sets the variable for the current shell in addition to the subprocess.

User avatar
sweh
Posts: 1969
Joined: Sat Mar 10, 2012 12:05 pm
Location: New York, New York
Contact:

Re: BBC BASIC desktop shortcut (Linux)

Post by sweh » Fri Oct 19, 2018 10:27 pm

Richard Russell wrote:
Fri Oct 19, 2018 3:47 pm
sweh wrote:
Fri Oct 19, 2018 3:18 pm
It's common, on Unix like systems, to put executables in an area where they can't be overwritten by mistake.
Wow, so it's gradually catching up with Windows then (a few decades late)?!
not-sure-if-trolling.jpg
not-sure-if-trolling.jpg (12.31 KiB) Viewed 123 times
Unix was doing this before Windows even existed.
Rgds
Stephen

Post Reply