You are not logged in.

#1 2021-09-11 17:31:57

eight.bit.al
Member
From: Prison
Registered: 2015-10-01
Posts: 1,088

The BL Welcome Script - Scroll Back Mod

In this thread:
https://forums.bunsenlabs.org/viewtopic … 30#p117230
I suggested there might be a need to scroll back the BL Welcome script so users could see what happened.
I was curious to see what was installed by the script.

Here's what I have so far:

/usr/bin/bl-welcome stock:

setupPage() {
    sleep 1
    tput clear
    header
    say "${1^^}
${1//?/-}

$2
"
    [[ ${3-} ]] || { sleep 1;return 0;}
    prompt "  $3" "${4:-}"
    return $?
}

My changes:

setupPage() {
    sleep 1    
    for value in {1..25}    #default termainl is 24 lines high
    do    
    tput cud1               # line feed (crsr down)
    done
    tput home
    header
    say "${1^^}
${1//?/-}

$2
"
    [[ ${3-} ]] || { sleep 1;return 0;}
    prompt "  $3" "${4:-}"
    return $?
}

It works well except if the user has changed the size of the terminal.
Shorter terminal height is no problem, but longer height is.
I've been looking for how to put the terminal height into a variable to include in the for/do loop.
So far what I've tried has failed. Any help? Maybe a whole new approach is needed.
Several ways to get terminal height; (tput lines), etc
I think the variable definition should be right after sleep1, in case the terminal size has been changed between pages of the welcome script.

Also - line 1 of /usr/lib/bunsen/fini needs the clear command removed.

Also/Also - the default terminal when bl-welcome runs is 24 lines high and the output of /usr/lib/bunsen/fini is 29 lines long, which make for less than favorable aesthetics.

TIA
8bit

Last edited by eight.bit.al (2021-09-11 22:31:15)


If art is how we decorate space, music is how we decorate time.

Online

#2 2021-09-11 20:06:34

eight.bit.al
Member
From: Prison
Registered: 2015-10-01
Posts: 1,088

Re: The BL Welcome Script - Scroll Back Mod

Okay, I have it working for any size terminal:

setupPage() {
    sleep 1
    start=0
    end=$(tput lines)
    for  (( c=$start; c<=$end; c++ ))
    do    
    tput cud1               # line feed
    done
    tput home
    header
    say "${1^^}
${1//?/-}

$2
"
    [[ ${3-} ]] || { sleep 1;return 0;}
    prompt "  $3" "${4:-}"
    return $?
}

Works like a champ on any terminal height. smile
Even works if one resizes the terminal while running bl-welcome big_smile

Next step is have fini expand the terminal by 5 or 6 lines before echoing to the terminal. Not my first choice.
Or set the default terminal in BL to 30 lines.
Or redo fini's output to 24 lines or less.

8bit

Last edited by eight.bit.al (2021-09-12 00:09:42)


If art is how we decorate space, music is how we decorate time.

Online

#3 2021-09-11 20:37:42

eight.bit.al
Member
From: Prison
Registered: 2015-10-01
Posts: 1,088

Re: The BL Welcome Script - Scroll Back Mod

Original fini:

clear        #change to "tput cud1" for the scrolling script
header
say '
 _____ ___ _   _ ___ ____  _   _ _____ ____  _
|  ___|_ _| \ | |_ _/ ___|| | | | ____|  _ \| |
| |_   | ||  \| || |\___ \| |_| |  _| | | | | |
|  _|  | || |\  || | ___) |  _  | |___| |_| |_|
|_|   |___|_| \_|___|____/|_| |_|_____|____/(_)


THANK YOU FOR SELECTING BUNSENLABS! :)

Please visit us on the web when you have a chance:
https://forums.bunsenlabs.org/

There are many ways you can tweak this system to suit your needs.

You might find these forum sections interesting:
"Getting Started": https://forums.bunsenlabs.org/viewforum.php?id=21
"Help & Support": https://forums.bunsenlabs.org/viewforum.php?id=2
"Scripts, Tutorials & Tips": https://forums.bunsenlabs.org/viewforum.php?id=9

And the BunsenLabs menu has a "Help" section too...

You can rerun this script at any time with
    bl-welcome

Hit any key to exit.'

read -srn1
clear

Suggested fini:

tput cud1
header
say '
 _____ ___ _   _ ___ ____  _   _ _____ ____  _
|  ___|_ _| \ | |_ _/ ___|| | | | ____|  _ \| |
| |_   | ||  \| || |\___ \| |_| |  _| | | | | |
|  _|  | || |\  || | ___) |  _  | |___| |_| |_|
|_|   |___|_| \_|___|____/|_| |_|_____|____/(_)

     THANK YOU FOR SELECTING BUNSENLABS! :)

There are many ways you can tweak this system to suit your needs:

"Getting Started": https://forums.bunsenlabs.org/viewforum.php?id=21
"Help & Support": https://forums.bunsenlabs.org/viewforum.php?id=2
"Scripts, Tutorials & Tips": https://forums.bunsenlabs.org/viewforum.php?id=9

And the BunsenLabs menu has a "Help" section too...

You can rerun this script at any time with - bl-welcome

Hit any key to exit.'

read -srn1
clear

8bit

Last edited by eight.bit.al (2021-09-11 23:28:17)


If art is how we decorate space, music is how we decorate time.

Online

#4 2021-09-11 21:27:11

rbh
Moderator
From: Sweden/Vasterbotten/Rusfors
Registered: 2016-08-11
Posts: 1,189

Re: The BL Welcome Script - Scroll Back Mod

Nice!


// Regards rbh

Please read before requesting help: Guide to getting help,
Introduction to the Bunsenlabs Lithium Desktop and other help topics under "Help Resources" on the BunsenLabs menu

Offline

#5 2021-09-11 23:25:13

DeepDayze
Like sands through an hourglass...
From: In Linux Land
Registered: 2017-05-28
Posts: 1,329

Re: The BL Welcome Script - Scroll Back Mod

Now that's so well done.  Indeed it makes it easier to see output of a bl-welcome installation step as well as having a clear finish page when it's all done so that user will see that script is done and can exit.


Real Men Use Linux

Offline

#6 2021-09-11 23:58:43

sleekmason
zoom
Registered: 2018-05-22
Posts: 608
Website

Re: The BL Welcome Script - Scroll Back Mod

Nice adjustments!

Offline

#7 2021-09-12 03:05:29

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 8,283
Website

Re: The BL Welcome Script - Scroll Back Mod

@eight.bit.al these are great suggestions. (That fini page had been bothering me for a while)

Many thanks!

With any luck, this should get into bl-welcome in time for Beryllium. smile


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#8 2021-09-12 04:29:45

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 8,283
Website

Re: The BL Welcome Script - Scroll Back Mod

eight.bit.al wrote:

line 1 of /usr/lib/bunsen/fini needs the clear command removed

Yes, I  see that, but then I think we need to use that same tput cud1 stuff as in setupPage to make sure all the previous page is scrolled away. In fact separate-out a scrollup() function both places can use.

Another idea - when bl-welcome is launched we could store away the current screen with tput smcup, and restore it when the script exits with tput rmcup, the way man pages do. Might be nice, but a frill.

Last edited by johnraff (2021-09-12 04:33:32)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#9 2021-09-12 14:21:19

eight.bit.al
Member
From: Prison
Registered: 2015-10-01
Posts: 1,088

Re: The BL Welcome Script - Scroll Back Mod

johnraff wrote:
eight.bit.al wrote:

line 1 of /usr/lib/bunsen/fini needs the clear command removed

Yes, I  see that, but then I think we need to use that same tput cud1 stuff as in setupPage to make sure all the previous page is scrolled away. In fact separate-out a scrollup() function both places can use.

Yes, yes. This ↑  Thanks for the direction.

I've separated the scrolling routine to a stand alone function. Relevant sections are:

# funtion to scroll previous page off the screen
scrollScreen() {
    start=1
    end=$(tput lines)
     for  (( c=$start; c<=$end; c++ )) 
    do    
    tput cud1               # line feed
    done
    tput home
    return 1
}
setupPage() {
    sleep 1
    scrollScreen
    header
    say "${1^^}
${1//?/-}

$2
"
    [[ ${3-} ]] || { sleep 1;return 0;}
    prompt "  $3" "${4:-}"
    return $?
}
sourcePage deferred-actions
STEP=$STEPS
scrollScreen
sourcePage fini



The entire script:

#!/bin/bash
# Post installation script

set -o nounset # do not accept unset variables

HELP='    bl-welcome an interactive system configuration script

Options:
    -h --help   show this message

If bl-welcome is called in a terminal with no options (the usual method),
it will start an interactive process whereby the user can
adjust system configurations and install packages.
'

grep -q '\<boot=live\>' /proc/cmdline && { echo "$0: This script is not meant to be run in a live session." >&2; exit 0;}

# Contents of these arrays will be executed at the "deferred-actions" page.
pkgs_to_install=()
pkgs_to_install_norecs=()
pkgs_to_remove=()
pre_functions_to_execute=() # executed before package installs
post_functions_to_execute=() # executed after package installs

restart=false

for i in "$@"
do
    case "$i" in
    -h|--help)
        echo "$HELP"
        exit 0
        ;;
    --firstrun)
        [[ -e $HOME/.config/bunsen/bl-welcome ]] && exit 0
        ;;
    --restart)
        restart=true
        ;;
    '')
        ;;
    *)
        echo "${i}: no such option" >&2
        exit 1
        ;;
    esac
done

TEXTDOMAIN=bl-welcome # might be used in future for translations

BL_COMMON_LIBDIR='/usr/lib/bunsen/common'
BL_WELCOME_LIBDIR='/usr/lib/bunsen/welcome'
#BL_COMMON_LIBDIR='./'
#BL_WELCOME_LIBDIR='./welcome'

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

# Debian release that this BunsenLabs system is based on
debian_base=buster

# default url for added Debian backports etc.
default_mirror='https://deb.debian.org/debian'

# url for added BunsenLabs backports
bunsen_mirror='https://pkg.bunsenlabs.org/debian'

# matches most mirrors
# add (?=.*debian) at beginning to insist on 'debian' somewhere (needs PCRE)
mirror_regex='https?://([[:alnum:]_-]+\.)+[[:alnum:]]+(/[[:alnum:]._-]+)*/?'

# matches BunsenLabs url, http or https
bunsen_regex='https?://pkg.bunsenlabs.org/debian'

# pages (in BL_WELCOME_LIBDIR) that bl-welcome will run through
STEPS_FIRST=('intro' 'warning' 'apt-update-upgrade')
STEPS_UNDERSTOOD=('intro' 'apt-update-upgrade')
STEPS_RESTART=('restart')
STEPS_BASIC=('system-tweaks' 'install-images-extra' 'add-debian-backports' 'add-bunsen-backports' 'install-bluetooth' 'install-java-packages' 'install-dropbox' 'devel')
STEPS_DEVEL=('devel-install-version-control-tools' 'devel-install-lamp-stack' 'devel-install-packaging-tools')

log_dir="$HOME/.cache/bunsen-welcome"
mkdir -p "$log_dir"
logfile="$log_dir"/bl-welcome.log

####### functions #######

log() {
    echo "
${1-}
" >> "$logfile"
}

warnlog() {
    echo "######## WARNING ########
${1-}
------------------------------------------------" >> "$logfile"
}

sourcePage() {
    if [[ ! -r "$BL_WELCOME_LIBDIR/$1" ]]; then
        echo $"Error: Unable to read $1 in $BL_WELCOME_LIBDIR" >&2
        exit 1
    fi
    . "$BL_WELCOME_LIBDIR/$1"
}

# prints something like: -------[ page 1 of 10 ]-------
header() {
    local width=$(tput cols 2>/dev/tty)
    local headerLength=$((width - 8)) # 8 is for '[  ]' and 2 spaces margins
    local headerText=$(printf $"page %d of %d" "$STEP" "$STEPS")
    local dashesStart=$( printf "%$(( (headerLength - ${#headerText}) / 2 ))s" )
    local dashesEnd=$( printf "%$(( (headerLength - ${#headerText}) / 2 + (headerLength - ${#headerText}) % 2 ))s" )
    echo "  ${dashesStart// /-}[ ${headerText} ]${dashesEnd// /-}"$'\n'
}

# Usage: setupPage title text [prompt [prompt-extra-arg]]
# Omit prompt for noninteractive page.
setupPage() {
    sleep 1
    scrollScreen
    header
    say "${1^^}
${1//?/-}

$2
"
    [[ ${3-} ]] || { sleep 1;return 0;}
    prompt "  $3" "${4:-}"
    return $?
}

# trigger* functions prepare lists for actions at the "deferred-actions" step.

# This is the easiest function to use for a page installing one package.
# Usage: triggerInstallPage title text package...
# example: triggerInstallPage 'LibreOffice suite' 'This will install libreoffice' 'libreoffice'
# Returns 0 if package added to install list,
# 2 if package(s) already installed or install declined,
# 1 if there was an error.
triggerInstallPage() {
    local title=$"install"" $1"
    local text="$1 has already been installed."
    allInstalled "${@:3}" && {
        setupPage "$title" "$text"
        return 2
    }
    text="$2"$'\n\n'$"If you choose to do this, the following packages will be installed:""

    ${*:3}

"$"Note: additional packages listed as dependencies will also be installed."

    local prompt=$"Would you like to install"" ${1}?"

    if setupPage "$title" "$text" "$prompt" 'N'
    then
        if triggerInstall "${@:3}"
        then
            return 0
        else
            say '...going to next page.' 1
        fi
    else
        return 2
    fi
    return 1
}

# usage: triggerInstall [--apt-get-option] <package> [<packages>]
triggerInstall() {
    local norecs=false
    case ${1-} in
    --no-install-recommends)
        norecs=true
        shift
        ;;
    -*)
        echo "${1}: this apt option is not supported by triggerInstall()" >&2
        return 1
        ;;
    '')
        echo "No package has been sent to triggerInstall()" >&2
        return 1
        ;;
    esac
    if [[ $norecs = true ]]
    then
        pkgs_to_install_norecs+=("$@")
    else
        pkgs_to_install+=("$@")
    fi
    say "$* has been added to the install list for execution later." 2
}

# usage: triggerRemove <package> [<packages>]
triggerRemove() {
    [[ -n ${1-} ]] || { echo "No package has been sent to triggerRemove()" >&2; return 1;}
    pkgs_to_remove+=("$@")
    say "$* has been added to the removal list for execution later." 2
}

# usage: triggerRunPreFunction <function> [<functions>]
triggerRunPreFunction(){
    [[ -n ${1-} ]] || { echo "No function passed to triggerRunPreFunction()" >&2; return 1;}
    pre_functions_to_execute+=("$@")
    say "function(s) $* will be run later, before installing packages." 2
}

# usage: triggerRunPostFunction <function> [<functions>]
triggerRunPostFunction(){
    [[ -n ${1-} ]] || { echo "No function passed to triggerRunPostFunction()" >&2; return 1;}
    post_functions_to_execute+=("$@")
    say "function(s) $* will be run later, after installing packages." 2
}

# Usage: promptTriggerInstall name description [--apt-get-option] package [package...]
# To have some defined function - functionname - run first, use:
# promptTriggerInstall --setup functionname name desc...
# This function is only needed in cases when triggerInstallPage is inappropriate.
promptTriggerInstall() {
    local setupFunction=
    if [[ $1 = '--setup' ]]; then
        if [[ -n ${2-} && $(type -t "$2") = 'function'  ]]; then
            setupFunction="$2"
            shift 2
        else
            say "Error: ${2-} is not a function."
            return 1
        fi
    fi

    tput clear
    local title="INSTALL ${1^^}"
    say "
$title
${title//?/-}

$2
"

    prompt '  Add to the install list?' || return 1

    if [[ -n $setupFunction ]]; then
        triggerRunPreFunction "$setupFunction" || return 1 # run setup function later, if it exists
    fi

    triggerInstall "${@:3}" || return 1
}

# Returns 0 if a line in 'apt-cache policy' contains all the terms provided.
# Terms can be in any order, quote terms containing spaces.
# eg: checkSources c=main 'l=Debian Backports'
checkSources() {
    local re=
    for term in "$@"
    do
        re+="(?=.*$term(,|\s*$))"
    done
    apt-cache policy | grep -Pq "$re" && return 0
    return 1
}

# wrapper function in case future scripts want to do the test differently
usingDebStable() {
    checkSources "n=$debian_base" l=Debian c=main && return 0
    return 1
}

# funtion to scroll previous page off the screen
scrollScreen() {
 sleep 1
    start=1
    end=$(tput lines)
     for  (( c=$start; c<=$end; c++ )) 
    do    
    tput cud1               # line feed
    done
    tput home
    return 1
}

####### end functions #######

if [[ $restart = true ]]
then
    log "Restarting bl-welcome for $USER at $(date)"
else
    terminalCheck -T 'WELCOME!'
    exec > >( tee -ia "$logfile" ) 2>&1
    log "Starting bl-welcome for $USER at $(date)"
fi

if [[ $( id -u ) -eq 0 ]]; then
    echo $"Error: This script should not be run directly by root." >&2
    exit 1
fi

usingDebStable || {
    echo "Error: This script should be run only on Debian ${debian_base^}." >&2
    exit 1
}

createFlag 'bl-welcome'

if [[ $restart = true ]]; then
    STEPS_BASIC=("${STEPS_RESTART[@]}" "${STEPS_BASIC[@]}")
elif [[ -e $HOME/.config/bunsen/bl-welcome-understood ]]; then
    STEPS_BASIC=("${STEPS_UNDERSTOOD[@]}" "${STEPS_BASIC[@]}")
else
    STEPS_BASIC=("${STEPS_FIRST[@]}" "${STEPS_BASIC[@]}")
fi

(( STEPS = ${#STEPS_BASIC[@]} + ${#STEPS_DEVEL[@]} + 2 )) # +2 is for deferred-actions and fini

# Run through steps
STEP=1

DEVEL=false

for curStep in "${STEPS_BASIC[@]}"; do
    sourcePage "$curStep"
    ((STEP++))
done

if $DEVEL; then
    for curStep in "${STEPS_DEVEL[@]}"; do
        sourcePage "$curStep"
        ((STEP++))
    done
fi

sourcePage deferred-actions
STEP=$STEPS
scrollScreen
sourcePage fini

exit 0

Another idea - when bl-welcome is launched we could store away the current screen with tput smcup, and restore it when the script exits with tput rmcup, the way man pages do. Might be nice, but a frill.

A sweet idea. smile

Also, a delay step in the scrolling routine to slow it down so the user can see the text scroll up.

8bit

Last edited by eight.bit.al (2021-09-12 15:35:12)


If art is how we decorate space, music is how we decorate time.

Online

#10 2021-09-13 04:59:32

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 8,283
Website

Re: The BL Welcome Script - Scroll Back Mod

eight.bit.al wrote:
# funtion to scroll previous page off the screen
scrollScreen() {
    start=1
    end=$(tput lines)
     for  (( c=$start; c<=$end; c++ )) 
    do    
    tput cud1               # line feed
    done
    tput home
    return 1
}

Looks good, except for: why return 1? That indicates failure. With no explicit return command, functions will return whatever the last executed command returns, which seems OK in this case, no? (Especially as the script probably won't be checking for the success of scrollScreen().)

Also, a delay step in the scrolling routine to slow it down so the user can see the text scroll up.

Yes, yes another nice idea. A little bit of sleep inside the loop. cool

I've got some Real Life for a few days, but should be able to get this new code pushed to GitHub before long, ready for the next release of bunsen-welcome. And almost certainly in time for Beryllium, thanks to your having done most of the work!


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#11 2021-09-13 10:01:15

eight.bit.al
Member
From: Prison
Registered: 2015-10-01
Posts: 1,088

Re: The BL Welcome Script - Scroll Back Mod

johnraff wrote:

Looks good, except for: why return 1? That indicates failure. With no explicit return command, functions will return whatever the last executed command returns, which seems OK in this case, no? (Especially as the script probably won't be checking for the success of scrollScreen().)

Shows my ignorance. I've never programed in bash before, and haven't done any programing in 40+ years. Since the days of 6502 assembler.

I've got some Real Life for a few days, but should be able to get this new code pushed to GitHub before long, ready for the next release of bunsen-welcome. And almost certainly in time for Beryllium, thanks to your having done most of the work!

Happy to give back a little. Thanks to all the BL team for their fine work.

8bit

Last edited by eight.bit.al (2021-09-13 10:02:08)


If art is how we decorate space, music is how we decorate time.

Online

#12 2021-09-13 15:29:41

DeepDayze
Like sands through an hourglass...
From: In Linux Land
Registered: 2017-05-28
Posts: 1,329

Re: The BL Welcome Script - Scroll Back Mod

Nice work 8-bit now you should be promoted to 16-bit big_smile


Real Men Use Linux

Offline

#13 2021-09-19 14:18:28

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 8,283
Website

Re: The BL Welcome Script - Scroll Back Mod

OK I added the sleep to slow the rollup down a bit. Tried a few values and ended up with 0.006s per line. If you'd like to try it and confirm whether that's about right or not - slow enough that it will be noticed, but not so slow as to be irritating.

# scroll previous page off the screen
scrollScreen() {
    start=1
    end=$(tput lines)
     for  (( c=start; c<=end; c++ ))
    do
    tput cud1               # line feed
    sleep 0.006
    done
    tput home
}

(And shellcheck told me to leave out the $  in arithmetic expansion.)

That made the sleep at the start of setupPage superfluous, except when there's a message at the end to read, so I stretched the sleep at that point from 1 to 2:

# Usage: setupPage title text [prompt [prompt-extra-arg]]
# Omit prompt for noninteractive page.
setupPage() {
    scrollScreen
    header
    say "${1^^}
${1//?/-}

$2
"
    [[ ${3-} ]] || { sleep 2;return 0;}
    prompt "  $3" "${4:-}"
    return $?
}

I moved fini's scrollscreen from the calling script to the top of the fini file, and took out the header - seemed unnecessary for the last page - which left a free line to drop the 'bl-welcome' command down again:

scrollScreen
say '
 _____ ___ _   _ ___ ____  _   _ _____ ____  _
|  ___|_ _| \ | |_ _/ ___|| | | | ____|  _ \| |
| |_   | ||  \| || |\___ \| |_| |  _| | | | | |
|  _|  | || |\  || | ___) |  _  | |___| |_| |_|
|_|   |___|_| \_|___|____/|_| |_|_____|____/(_)

     THANK YOU FOR SELECTING BUNSENLABS! :)

There are many ways you can tweak this system to suit your needs:

"Getting Started": https://forums.bunsenlabs.org/viewforum.php?id=21
"Help & Support": https://forums.bunsenlabs.org/viewforum.php?id=2
"Scripts, Tutorials & Tips": https://forums.bunsenlabs.org/viewforum.php?id=9

And the BunsenLabs menu has a "Help" section too...

You can rerun this script at any time with:
    bl-welcome

Hit any key to exit.'

read -srn1
tput clear

---
Also tried adding this to bl-welcome:

tput smcup # stash current terminal contents
trap 'tput rmcup' EXIT # restore on exit

It worked beautifully except that in the 'cup' screen scrolling doesn't work. neutral
That was the whole idea of this mod, so drop that and go back to 'tput clear' at the top of intro and end of fini.

If that 0.006 sleep looks OK I'll commit this to git.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#14 2021-09-19 18:13:38

eight.bit.al
Member
From: Prison
Registered: 2015-10-01
Posts: 1,088

Re: The BL Welcome Script - Scroll Back Mod

^ I don't have BL currently installed on any of my test machines; give me a couple of hours. smile

8bit

P.S. I wanted to test/play with theming on Openbox before Beryllium's release anyway.

Last edited by eight.bit.al (2021-09-19 18:18:46)


If art is how we decorate space, music is how we decorate time.

Online

#15 2021-09-19 21:42:53

eight.bit.al
Member
From: Prison
Registered: 2015-10-01
Posts: 1,088

Re: The BL Welcome Script - Scroll Back Mod

johnraff wrote:

---
Also tried adding this to bl-welcome:

tput smcup # stash current terminal contents
trap 'tput rmcup' EXIT # restore on exit

It worked beautifully except that in the 'cup' screen scrolling doesn't work. neutral
That was the whole idea of this mod, so drop that and go back to 'tput clear' at the top of intro and end of fini.

If that 0.006 sleep looks OK I'll commit this to git.

I thought about it and didn't see any value to swapping terminal screen buffers, at least on the first run. There's nothing in the terminal to store. Now if the user is using the terminal and decides to call bl-welcome, there's something to restore.

I found 0.006 way to fast, almost unperceivable. I think it depends on the speed of the machine? I liked 0.03/0.02. 0.01 was too fast.
And I wasn't real happy watching the crsr scroll to the bottom of the terminal before any text begins to move; but it wasn't a deal breaker. Just before the scroll loop:

tput   ll   -   Go to last line, first column (if no `cup')

0.00X to 0.0X is a big difference, no? Order of magnitude. Here's 0.03.

https://streamable.com/05c2dz


8bit

Last edited by eight.bit.al (2021-09-19 22:14:39)


If art is how we decorate space, music is how we decorate time.

Online

#16 2021-09-19 22:26:11

eight.bit.al
Member
From: Prison
Registered: 2015-10-01
Posts: 1,088

Re: The BL Welcome Script - Scroll Back Mod

eight.bit.al wrote:

And I wasn't real happy watching the crsr scroll to the bottom of the terminal before any text begins to move; but it wasn't a deal breaker. Just before the scroll loop:

tput   ll   -   Go to last line, first column (if no `cup')

8bit

tput ll didn't make a difference. And I still get the "FINISHED" pushed off the top of the terminal.

Also, I get two scrolls before fini.

Please paste your bl-welcome here or somewhere for me to use. TIA.

8bit


If art is how we decorate space, music is how we decorate time.

Online

#17 2021-09-22 14:37:14

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 8,283
Website

Re: The BL Welcome Script - Scroll Back Mod

eight.bit.al wrote:
johnraff wrote:

---
Also tried adding this to bl-welcome:

tput smcup # stash current terminal contents
trap 'tput rmcup' EXIT # restore on exit

It worked beautifully except that in the 'cup' screen scrolling doesn't work. neutral
That was the whole idea of this mod, so drop that and go back to 'tput clear' at the top of intro and end of fini.

I thought about it and didn't see any value to swapping terminal screen buffers, at least on the first run. There's nothing in the terminal to store. Now if the user is using the terminal and decides to call bl-welcome, there's something to restore.

Yes indeed. 90% of the runs of bl-welcome (I guess) will be the autorun after first login, when there's no terminal data to store anyway. The other 10% - we'll just have to live with 'tput clear' at start of intro and end of fini. Not such a big deal.

If that 0.006 sleep looks OK I'll commit this to git.

I found 0.006 way to fast, almost unperceivable. I think it depends on the speed of the machine?

Not sure I get that. Surely a millisecond is a millisecond, regardless of the machine's speed?

But anyway, I did find the scrolling on your posted video a bit slow. Almost finger-tapping get-on-with-it slow, also even with 0.02 on my VM. Another case of De gustibus non est disputandum I guess. Can we compromise on 0.01s? As long as the user is aware that scrolling has taken place, the job is done, right?

And I wasn't real happy watching the crsr scroll to the bottom of the terminal before any text begins to move; but it wasn't a deal breaker.

I noticed that too - another reason to get it done quickly I'd say...

And I still get the "FINISHED" pushed off the top of the terminal.

That is fixed in your/our amended 'fini' I think.

Also, I get two scrolls before fini.

I don't see that.

Anyway, the two files that need to be edited are /usr/bin/bl-welcome and /usr/lib/bunsen/welcome/fini

Pasting them here:

bl-welcome

#!/bin/bash
# Post installation script

set -o nounset # do not accept unset variables

HELP='    bl-welcome an interactive system configuration script

Options:
    -h --help   show this message

If bl-welcome is called in a terminal with no options (the usual method),
it will start an interactive process whereby the user can
adjust system configurations and install packages.
'

grep -q '\<boot=live\>' /proc/cmdline && { echo "$0: This script is not meant to be run in a live session." >&2; exit 0;}

# Contents of these arrays will be executed at the "deferred-actions" page.
pkgs_to_install=()
pkgs_to_install_norecs=()
pkgs_to_remove=()
pre_functions_to_execute=() # executed before package installs
post_functions_to_execute=() # executed after package installs

restart=false

for i in "$@"
do
    case "$i" in
    -h|--help)
        echo "$HELP"
        exit 0
        ;;
    --firstrun)
        [[ -e $HOME/.config/bunsen/bl-welcome ]] && exit 0
        ;;
    --restart)
        restart=true
        ;;
    '')
        ;;
    *)
        echo "${i}: no such option" >&2
        exit 1
        ;;
    esac
done

TEXTDOMAIN=bl-welcome # might be used in future for translations

BL_COMMON_LIBDIR='/usr/lib/bunsen/common'
BL_WELCOME_LIBDIR='/usr/lib/bunsen/welcome'
#BL_COMMON_LIBDIR='./'
#BL_WELCOME_LIBDIR='/home/john/Projects/welcome/welcome'

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

# Debian release that this BunsenLabs system is based on
debian_base=bullseye

# default url for added Debian backports etc.
default_mirror='https://deb.debian.org/debian'

# url for added BunsenLabs backports
bunsen_mirror='https://pkg.bunsenlabs.org/debian'

# matches most mirrors
# add (?=.*debian) at beginning to insist on 'debian' somewhere (needs PCRE)
mirror_regex='https?://([[:alnum:]_-]+\.)+[[:alnum:]]+(/[[:alnum:]._-]+)*/?'

# matches BunsenLabs url, http or https
bunsen_regex='https?://pkg.bunsenlabs.org/debian'

# pages (in BL_WELCOME_LIBDIR) that bl-welcome will run through
STEPS_FIRST=('intro' 'warning' 'apt-update-upgrade')
STEPS_UNDERSTOOD=('intro' 'apt-update-upgrade')
STEPS_RESTART=('restart')
STEPS_BASIC=('system-tweaks' 'install-images-extra' 'add-debian-backports' 'add-bunsen-backports' 'install-bluetooth' 'install-java-packages' 'install-dropbox' 'devel')
STEPS_DEVEL=('devel-install-version-control-tools' 'devel-install-lamp-stack' 'devel-install-packaging-tools')

log_dir="$HOME/.cache/bunsen-welcome"
mkdir -p "$log_dir"
logfile="$log_dir"/bl-welcome.log

####### functions #######

log() {
    echo "
${1-}
" >> "$logfile"
}

warnlog() {
    echo "######## WARNING ########
${1-}
------------------------------------------------" >> "$logfile"
}

sourcePage() {
    if [[ ! -r "$BL_WELCOME_LIBDIR/$1" ]]; then
        echo $"Error: Unable to read $1 in $BL_WELCOME_LIBDIR" >&2
        exit 1
    fi
    . "$BL_WELCOME_LIBDIR/$1"
}

# prints something like: -------[ page 1 of 10 ]-------
header() {
    local width=$(tput cols 2>/dev/tty)
    local headerLength=$((width - 8)) # 8 is for '[  ]' and 2 spaces margins
    local headerText=$(printf $"page %d of %d" "$STEP" "$STEPS")
    local dashesStart=$( printf "%$(( (headerLength - ${#headerText}) / 2 ))s" )
    local dashesEnd=$( printf "%$(( (headerLength - ${#headerText}) / 2 + (headerLength - ${#headerText}) % 2 ))s" )
    echo "  ${dashesStart// /-}[ ${headerText} ]${dashesEnd// /-}"$'\n'
}

# scroll previous page off the screen
scrollScreen() {
    start=1
    end=$(tput lines)
     for  (( c=start; c<=end; c++ ))
    do
    tput cud1               # line feed
    sleep 0.006
    done
    tput home
}

# Usage: setupPage title text [prompt [prompt-extra-arg]]
# Omit prompt for noninteractive page.
setupPage() {
#    sleep 0.5
#    tput clear
    scrollScreen
    header
    say "${1^^}
${1//?/-}

$2
"
    [[ ${3-} ]] || { sleep 2;return 0;}
    prompt "  $3" "${4:-}"
    return $?
}

# trigger* functions prepare lists for actions at the "deferred-actions" step.

# This is the easiest function to use for a page installing one package.
# Usage: triggerInstallPage title text package...
# example: triggerInstallPage 'LibreOffice suite' 'This will install libreoffice' 'libreoffice'
# Returns 0 if package added to install list,
# 2 if package(s) already installed or install declined,
# 1 if there was an error.
triggerInstallPage() {
    local title=$"install"" $1"
    local text="$1 has already been installed."
    allInstalled "${@:3}" && {
        setupPage "$title" "$text"
        return 2
    }
    text="$2"$'\n\n'$"If you choose to do this, the following packages will be installed:""

    ${*:3}

"$"Note: additional packages listed as dependencies will also be installed."

    local prompt=$"Would you like to install"" ${1}?"

    if setupPage "$title" "$text" "$prompt" 'N'
    then
        if triggerInstall "${@:3}"
        then
            return 0
        else
            say '...going to next page.' 1
        fi
    else
        return 2
    fi
    return 1
}

# usage: triggerInstall [--apt-get-option] <package> [<packages>]
triggerInstall() {
    local norecs=false
    case ${1-} in
    --no-install-recommends)
        norecs=true
        shift
        ;;
    -*)
        echo "${1}: this apt option is not supported by triggerInstall()" >&2
        return 1
        ;;
    '')
        echo "No package has been sent to triggerInstall()" >&2
        return 1
        ;;
    esac
    if [[ $norecs = true ]]
    then
        pkgs_to_install_norecs+=("$@")
    else
        pkgs_to_install+=("$@")
    fi
    say "$* has been added to the install list for execution later." 2
}

# usage: triggerRemove <package> [<packages>]
triggerRemove() {
    [[ -n ${1-} ]] || { echo "No package has been sent to triggerRemove()" >&2; return 1;}
    pkgs_to_remove+=("$@")
    say "$* has been added to the removal list for execution later." 2
}

# usage: triggerRunPreFunction <function> [<functions>]
triggerRunPreFunction(){
    [[ -n ${1-} ]] || { echo "No function passed to triggerRunPreFunction()" >&2; return 1;}
    pre_functions_to_execute+=("$@")
    say "function(s) $* will be run later, before installing packages." 2
}

# usage: triggerRunPostFunction <function> [<functions>]
triggerRunPostFunction(){
    [[ -n ${1-} ]] || { echo "No function passed to triggerRunPostFunction()" >&2; return 1;}
    post_functions_to_execute+=("$@")
    say "function(s) $* will be run later, after installing packages." 2
}

# Usage: promptTriggerInstall name description [--apt-get-option] package [package...]
# To have some defined function - functionname - run first, use:
# promptTriggerInstall --setup functionname name desc...
# This function is only needed in cases when triggerInstallPage is inappropriate.
promptTriggerInstall() {
    local setupFunction=
    if [[ $1 = '--setup' ]]; then
        if [[ -n ${2-} && $(type -t "$2") = 'function'  ]]; then
            setupFunction="$2"
            shift 2
        else
            say "Error: ${2-} is not a function."
            return 1
        fi
    fi

    tput clear
    local title="INSTALL ${1^^}"
    say "
$title
${title//?/-}

$2
"

    prompt '  Add to the install list?' || return 1

    if [[ -n $setupFunction ]]; then
        triggerRunPreFunction "$setupFunction" || return 1 # run setup function later, if it exists
    fi

    triggerInstall "${@:3}" || return 1
}

# Returns 0 if a line in 'apt-cache policy' contains all the terms provided.
# Terms can be in any order, quote terms containing spaces.
# eg: checkSources c=main 'l=Debian Backports'
checkSources() {
    local re=
    for term in "$@"
    do
        re+="(?=.*$term(,|\s*$))"
    done
    apt-cache policy | grep -Pq "$re" && return 0
    return 1
}

# wrapper function in case future scripts want to do the test differently
usingDebStable() {
# Debian apt line is missing if installed without network, so this test fails:
#    checkSources "n=$debian_base" l=Debian c=main && return 0
# but base-files are installed from the iso, so lsb_release should work
    local reported_codename=$( lsb_release -cs )
    [[ $reported_codename = "$debian_base" ]] && return 0
    log "'lsb_release -cs' reported wrong codename: $reported_codename"
    return 1
}

####### end functions #######

if [[ $restart = true ]]
then
    log "Restarting bl-welcome for $USER at $(date)"
else
    terminalCheck -T 'WELCOME!'
    exec > >( tee -ia "$logfile" ) 2>&1
    log "Starting bl-welcome for $USER at $(date)"
fi

if [[ $( id -u ) -eq 0 ]]; then
    echo $"Error: This script should not be run directly by root." >&2
    exit 1
fi

usingDebStable || {
    echo "Error: This script should be run only on Debian ${debian_base^}." >&2
    exit 1
}

#tput smcup # stash current terminal contents
#trap 'tput rmcup' EXIT # restore on exit

createFlag 'bl-welcome'

if [[ $restart = true ]]; then
    STEPS_BASIC=("${STEPS_RESTART[@]}" "${STEPS_BASIC[@]}")
elif [[ -e $HOME/.config/bunsen/bl-welcome-understood ]]; then
    STEPS_BASIC=("${STEPS_UNDERSTOOD[@]}" "${STEPS_BASIC[@]}")
else
    STEPS_BASIC=("${STEPS_FIRST[@]}" "${STEPS_BASIC[@]}")
fi

(( STEPS = ${#STEPS_BASIC[@]} + ${#STEPS_DEVEL[@]} + 2 )) # +2 is for deferred-actions and fini

# Run through steps
STEP=1

DEVEL=false

for curStep in "${STEPS_BASIC[@]}"; do
    sourcePage "$curStep"
    ((STEP++))
done

if $DEVEL; then
    for curStep in "${STEPS_DEVEL[@]}"; do
        sourcePage "$curStep"
        ((STEP++))
    done
fi

sourcePage deferred-actions
STEP=$STEPS
sourcePage fini

exit 0

fini

scrollScreen
say '
 _____ ___ _   _ ___ ____  _   _ _____ ____  _
|  ___|_ _| \ | |_ _/ ___|| | | | ____|  _ \| |
| |_   | ||  \| || |\___ \| |_| |  _| | | | | |
|  _|  | || |\  || | ___) |  _  | |___| |_| |_|
|_|   |___|_| \_|___|____/|_| |_|_____|____/(_)

     THANK YOU FOR SELECTING BUNSENLABS! :)

There are many ways you can tweak this system to suit your needs:

"Getting Started": https://forums.bunsenlabs.org/viewforum.php?id=21
"Help & Support": https://forums.bunsenlabs.org/viewforum.php?id=2
"Scripts, Tutorials & Tips": https://forums.bunsenlabs.org/viewforum.php?id=9

And the BunsenLabs menu has a "Help" section too...

You can rerun this script at any time with:
    bl-welcome

Hit any key to exit.'

read -srn1
tput clear

Last edited by johnraff (2021-09-23 13:18:24)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#18 2021-09-23 01:07:47

eight.bit.al
Member
From: Prison
Registered: 2015-10-01
Posts: 1,088

Re: The BL Welcome Script - Scroll Back Mod

johnraff wrote:

Can we compromise on 0.01s? As long as the user is aware that scrolling has taken place, the job is done, right?
...

I noticed that too - another reason to get it done quickly I'd say...

Yes, please. The fact that there's scrollback at all floats my boat.
Thanks for spending the time to steer me in the right directions.
First thing in the morning with coffee. Best time of the day.

8bit

P.S. I found a problem and I did my best to fix it. big_smile

Last edited by eight.bit.al (2021-09-23 01:40:10)


If art is how we decorate space, music is how we decorate time.

Online

#19 2021-09-23 01:52:54

hhh
Meep!
Registered: 2015-09-17
Posts: 12,203
Website

Re: The BL Welcome Script - Scroll Back Mod

The best part of waking up?

Fuck, I hate advertising.

Offline

#20 2021-09-23 03:20:09

eight.bit.al
Member
From: Prison
Registered: 2015-10-01
Posts: 1,088

Re: The BL Welcome Script - Scroll Back Mod

hhh wrote:

Fuck, I hate advertising.

"You don't always set out to be a rock star..."

Thanks to the whole BL team for their fine work.

8bit


If art is how we decorate space, music is how we decorate time.

Online

#21 2021-09-23 13:21:14

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 8,283
Website

Re: The BL Welcome Script - Scroll Back Mod

eight.bit.al wrote:

I found a problem and I did my best to fix it. big_smile

If you spot anything else, input is always welcome!


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#22 Yesterday 04:37:09

hhh
Meep!
Registered: 2015-09-17
Posts: 12,203
Website

Re: The BL Welcome Script - Scroll Back Mod

eight.bit.al wrote:

Since the days of 6502 assembler.

https://sites.google.com/site/gogleoops … 2assembler

Offline

#23 Yesterday 13:49:06

eight.bit.al
Member
From: Prison
Registered: 2015-10-01
Posts: 1,088

Re: The BL Welcome Script - Scroll Back Mod

hhh wrote:
eight.bit.al wrote:

Since the days of 6502 assembler.

https://sites.google.com/site/gogleoops … 2assembler

Eight bit registers. big_smile
And every bite of free memory in zero page was used 'till it cried uncle.
Say-Uncle-Final-1.th.jpg

eight.bit.al

Last edited by eight.bit.al (Yesterday 13:53:23)


If art is how we decorate space, music is how we decorate time.

Online

Board footer

Powered by FluxBB