You are not logged in.

#1 2016-08-05 05:53:00

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,661
Website

A bl-install script?

This is something I was wondering about a while ago, and forgot, till @xaos52 reminded me. It might be handy to have a self-standing executable that other scripts, menus etc can call to get a terminal-based but somewhat nice-looking installer for Debian packages. ie pretty much what the pipemenus bring up when installing a new app. The difference is that this can be called even by a python script, or anything really. If it works well it can also replace some of the duplicated --install code in the pipemenus, or even some of the installation pages in bl-welcome.

There are already some functions in /usr/lib/bunsen/common/bl-include.cfg which can be easily re-used, the main one being promptInstall(). This script is just a wrapper round that function really, with a bit of option handling tacked on, so it's quite small.

If anyone would like to test it out, put this code in ~/bin/bl-install, make it executable, and run 'bl-install --help' in a terminal to see the options. They are just --name, to define some name other than the actual package name, and --message for some text to display to the user. (If those are not defined the script will make something up.) Other arguments are the names of packages to install.

It doesn't have to be run from a terminal (that's the whole point really) - to test that you can use Alt+F2 and launch it from there. (You might have to logout/in to get the new command detected.) A terminal window should pop up and go to work, just like in the pipemenus.

Please report any bugs, and this is still a proof-of-concept so suggestions for improvements are also gratefully considered.

If it works OK it would be easy to throw it into bunsen-utilities so any future developers would be able to use it.

#!/bin/bash

HELP='bl-install: a wrapper round the promptInstall() function in bl-include.cfg

Usage:
bl-install -n "name of app(s)" -m "message text" -f "/path/to/file" package [package...]

    -h --help                   show this message and exit
    -n --name       <string>    descriptive name of package(s) to be installed
    -m --message    <string>    message to display to user before installing
    -f --file       <filepath>  file to hold return value of script on exit

Specified options may be provided in any order.
If -n, -m or -f are used, they must be followed by an argument.
If -n or -m are absent they will be generated automatically.
If -f is set, the script will write its exit return value there,
so a calling script can test for success.
All other arguments are taken as package names to install.
'

BL_COMMON_LIBDIR='/usr/lib/bunsen/common'

trap 'send_return' EXIT

send_return(){
    local retval=$?
    [[ -w "$retfile" ]] && echo "$retval" > "$retfile"
}

if ! . "$BL_COMMON_LIBDIR/bl-include.cfg" 2> /dev/null; then
    echo $"Error: Failed to locate bl-include.cfg in $BL_COMMON_LIBDIR" >&2
    exit 1
fi

name=
message=
retfile=
packages=()

while [[ ${1+x} ]]
do
    case "$1" in
    -n|--name)
        name="$2"
        shift 2
        ;;
    -m|--message)
        message="$2"
        shift 2
        ;;
    -f|--file)
        retfile="$2"
        shift 2
        ;;
    -h|--help)
        echo "$HELP"
        exit 0
        ;;
    -*)
        echo "$0: $1: no such option"$'\n' >&2
        echo "$HELP"
        exit 1
        ;;
    *)
        packages+=($1)
        shift
        ;;
    esac
done

[[ ${#packages[@]} -gt 0 ]] || {
    echo "$0: no packages specified"$'\n' >&2
    echo "$HELP"
    exit 1
}

for i in "${packages[@]}"
do
    [[ $i =~ ^[a-z0-9][a-z0-9+.-]+$ ]] || {
        echo "$i is not a valid Debian package name"$'\n' >&2
        echo "$HELP"
        exit 1
    }
done

[[ $name ]] || {
    words=(${packages[0]//-/ })
    name="${words[*]^}"
}

[[ $message ]] || {
    message="This script will install $name"
}

terminalCheck -T "Install $name" --name "$name" --message "$message" "${packages[@]}"

allInstalled "${packages[@]}" && {
    say "$name: already installed"
    sleep 2
    exit 0
}

promptInstall "$name" "$message" "${packages[@]}" || errorExit 'Install failed'

exit

EDIT: add -f|--file option

Last edited by johnraff (2016-08-11 06:26:03)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#2 2016-08-06 10:25:36

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: A bl-install script?

^ Looks OK and works OK, so it must be OK, no?

Seriously, I could not find anything wrong with it. smile

And it really helps in adapting bl-sshconfig-pipemenu - allowing to install package 'bunsen-meta-ssh' only when '/usr/sbin/sshd' doe not exist already.

IMPORTANT EDIT:

Using bl-install in bl-sshconfig-pipemenu makes the package bunsen-pipemenus DEPEND on bunsen-utilities. RECOMMEND is not sufficient any more.

Offline

#3 2016-08-07 10:22:02

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: A bl-install script?

folks, aren't you re-inventing the wheel here?

bl has been developing its own specific scripts, configs and whatnot quite a lot already. a little too much for my taste, actually.

please don't fall into the DE/distro trap.

Offline

#4 2016-08-07 12:44:55

pvsage
Internal Affairs
Registered: 2015-09-29
Posts: 1,433

Re: A bl-install script?

^ If I understand correctly, one of the ideas for this script is to lighten bl-welcome by moving optional schtuff to the pipemenus.


Be excellent to each other, and...party on, dudes!
BunsenLabs Forum Rules
Tending and defending the Flame since 2009

Offline

#5 2016-08-10 03:41:42

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,661
Website

Re: A bl-install script?

xaos52 wrote:

...it really helps in adapting bl-sshconfig-pipemenu...

This was the idea, to make it easy for writers of scripts (like new pipemenus) to get a package installed in the same way as in bl-welcome or the existing "install" pipemenus. A little bit of prettying-up and a little bit of safety-checking. Because it reuses existing functions in bl-include.cfg, the appearance and behaviour will be consistent with earlier scripts.

IMPORTANT EDIT:

Using bl-install in bl-sshconfig-pipemenu makes the package bunsen-pipemenus DEPEND on bunsen-utilities. RECOMMEND is not sufficient any more.

Good point. I'm now thinking that bunsen-common is the better package to put it in. That's already a depend of all the packages that might use bl-install. It's a smaller package than bunsen-utilities, and would leave users the choice of not installing b-u if they don't want it.

@ohnonot I understand where you're coming from. This isn't really adding anything though, it's just separating-out existing code so it can be used more widely, more easily. Without something like bl-install, pipemenu writers would have to write some code wrapped around apt-get every time. This let's them fall back on a premade solution.

I quite agree about the need to keep transparency in all our scripts, configs etc. "Handy" utilities should always be optional IMO - as, for example, you can edit openbox configs via obconf or just edit rc.xml directly. Either way works, even if you switch from one to the other midway.

@pvsage yes that's what I had in mind. It should make writing new "install" pipemenus a bit simpler.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#6 2016-08-10 08:31:12

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,661
Website

Re: A bl-install script?

The OP script has been tweaked a bit - I added a mechanism for writing the script's exit return value in some file, defined by the -f|--file option sent by the calling script. This lets the caller have a way of finding if the installer succeeded or not, even though it might be running in its own terminal. (The calling script would presumably create a tempfile, send that to 'bl-install -f $mytempfile --options stuff packagename' and remove $mytempfile afterwards.)

This won't be needed most of the time, but might be good to have occasionally. It can safely be ignored.

Last edited by johnraff (2016-08-11 08:52:07)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#7 2016-08-11 08:57:32

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,661
Website

Re: A bl-install script?

I've provisionally put bl-install into the deuterium bunsen-common. This allows xaos52's new version of bl-sshconfig-pipemenu to offer an install of bunsen-meta-ssh, so that page can now be dropped from bl-welcome.  cool


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#8 2016-08-11 09:04:26

pvsage
Internal Affairs
Registered: 2015-09-29
Posts: 1,433

Re: A bl-install script?

Sidebar:  Why isn't ssh included in the default install?  Is is just because "That's what Philip did with CrunchBang", or is it to reduce the size of the ISO-hybrid image?


Be excellent to each other, and...party on, dudes!
BunsenLabs Forum Rules
Tending and defending the Flame since 2009

Offline

#9 2016-08-11 09:54:42

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,661
Website

Re: A bl-install script?

^In fact the ssh client is included by default. Only the server is added by the metapackage. It's a minimal operation, and indeed "That's what Philip did with CrunchBang" was the guide for pretty much everything round here at first. In-your-face stuff got changed (er, improved, some of us like to think) quickly but some dusty corners have been left as-is till someone gets round to deciding what to do, or till everything else gets fixed icon_rolleyes.gif, or till something blows up...


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#10 2016-08-11 17:37:40

cloverskull
Member
Registered: 2015-10-01
Posts: 348

Re: A bl-install script?

I vote for leaving it daemons and servers out of the base iso. I am a fan of having to intentionally install things that listen on exposed ports. smile

Offline

#11 2016-08-11 17:40:31

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: A bl-install script?

cloverskull wrote:

I vote for leaving it daemons and servers out of the base iso. I am a fan of having to intentionally install things that listen on exposed ports

+1

Offline

#12 2016-08-12 01:48:43

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,661
Website

Re: A bl-install script?

^^+2


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

Board footer

Powered by FluxBB