Bookworm Build script

a very small Live CD shaped to look and act like Puppy Linux.

Moderator: fredx181

tosim
Posts: 480
Joined: Thu Jul 23, 2020 1:13 pm
Has thanked: 928 times
Been thanked: 57 times

Re: Bookworm Build script

Post by tosim »

@fredx181
@wanderer
I placed a folder in my "home", ext4. Thank you both for the help; will try again.

wanderer
Posts: 760
Joined: Mon Jul 13, 2020 7:15 pm
Been thanked: 138 times

Re: Bookworm Build script

Post by wanderer »

hi fredx181

continue to play with debiandog

the more you look at it the more amazing it is

a masterpiece

perfect system

incredible asset to puppy world

thanks again

wanderer

wanderer
Posts: 760
Joined: Mon Jul 13, 2020 7:15 pm
Been thanked: 138 times

Re: Bookworm Build script

Post by wanderer »

hi fredx181

i just wanted you to know
that your script is so well written and clear
that i do not expect to need any help in achieving my goal

which will really just be a version of debiandog (or whatever you really would like to call it)

thank you so much for creating this masterpiece

it is just what i have been looking for

wanderer

AndresC2
Posts: 10
Joined: Wed Feb 17, 2021 10:08 pm
Been thanked: 1 time

Re: Bookworm Build script

Post by AndresC2 »

Hi fred

wanderer wrote:
"each time the build script runs
does it have to download everything again

is there any way to keep the debs in a local repository on your hard drive"

first make your local-repositories, in my case:
/run/live/persistence/sdb2/local-repositories/x86/packages-deb-bullseye

then run this script

#!/bin/bash

#Put here yours apps

BASE_INSTALL="firefox"

apt-get install -o dir::cache=/run/live/persistence/sdb2/local-repositories/x86/packages-deb-bullseye $BASE_INSTALL

firefox will download all its deb in this path /run/live/persistence/sdb2/local-repositories/x86/packages-deb-bullseye
(make your own path) then if you need firefox again, only run this script no need internet.

wanderer
Posts: 760
Joined: Mon Jul 13, 2020 7:15 pm
Been thanked: 138 times

Re: Bookworm Build script

Post by wanderer »

hi AndreasC2

will do

very useful

thanks very much

wanderer

User avatar
fredx181
Posts: 3051
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 371 times
Been thanked: 1297 times
Contact:

Re: Bookworm Build script

Post by fredx181 »

AndresC2 wrote: Fri May 24, 2024 11:04 pm

Hi fred

wanderer wrote:
"each time the build script runs
does it have to download everything again

is there any way to keep the debs in a local repository on your hard drive"

first make your local-repositories, in my case:
/run/live/persistence/sdb2/local-repositories/x86/packages-deb-bullseye

then run this script
.....
.....

Hi Andres . On itself your suggestion is good, but the question from wanderer was not about that, I think it was basically:
Will all the downloaded deb files from previous run be deleted when running the mklive script more than once ?.
And I answered something like:
No, these deb files from previous run will be kept and used, not needed to download again.

I just like clarity about things ;) Hopefully it is now.

wanderer
Posts: 760
Joined: Mon Jul 13, 2020 7:15 pm
Been thanked: 138 times

Re: Bookworm Build script

Post by wanderer »

hi fredx181 and AndresC2

thanks for all your help

fredx181 i understood what you meant
the debs are in archive (found them) also saw where its done in the script

but if i understand right Andreas is giving me a way to run mklive offline

im not sure about it yet ( still testing and reading the script )
but doesnt the script have to reconnect and get some stuff online each time
like a new debootstrap

anyway like i said the script is so clear
i will be able to figure it all out just by testing and reading the script

thanks again

wanderer

User avatar
fredx181
Posts: 3051
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 371 times
Been thanked: 1297 times
Contact:

Re: Bookworm Build script

Post by fredx181 »

wanderer wrote:

but doesnt the script have to reconnect and get some stuff online each time
like a new debootstrap

Also the deb packages that were earlier downloaded by debootstrap are being used again without downloading, so then debootstrap only has to unpack the packages (unless there's a new version of some package, but that's often exception).
For some other stuff it will re-download, yes, but is mostly small size.

wanderer
Posts: 760
Joined: Mon Jul 13, 2020 7:15 pm
Been thanked: 138 times

Re: Bookworm Build script

Post by wanderer »

hi fredx181

thank you so much for that info

and like i said for this masterpiece

wanderer

superhik
Posts: 38
Joined: Mon Jun 19, 2023 7:56 pm
Has thanked: 5 times
Been thanked: 17 times

Re: Bookworm Build script

Post by superhik »

Hey Fredx181 of the under-the-sea lands. :D
Command line version has less options.
I'd like to extend them and provide a way to add packages by searching for package names.
The part which selects graphical environment is unreadable to me.
When trying to read I was thinking: fuck the terminal, fuck the bash and fuck the command line. :lol:

So I had to make a fresh start and came up with this little script:

Code: Select all

#!/bin/bash

# List of preselected packages
preselected_packages=("curl" "git" "vim")

# Initialize an array to hold selected packages
selected_packages=("${preselected_packages[@]}")
selected_for_removal=()  # Track packages marked for removal
search_results=()
search_term=""
cursor=0
error_message=""
RESULTS_PER_PAGE=10
current_page=0
total_pages=0
mode="selected"  # Modes: search, selected

# Function to display the menu
show_menu() {
    clear
    if [ "$mode" == "search" ]; then
        echo "Search: $search_term"
        echo "Use arrow keys to navigate, space to toggle selection, and Enter to search."
        echo "--------------------------------------------------"
        if [[ -n "$error_message" ]]; then
            echo "Error: $error_message"
            echo "--------------------------------------------------"
        elif [[ ${#search_results[@]} -eq 0 ]]; then
            echo "No results found."
        else
            start_index=$((current_page * RESULTS_PER_PAGE))
            end_index=$((start_index + RESULTS_PER_PAGE))
            if [ $end_index -gt ${#search_results[@]} ]; then
                end_index=${#search_results[@]}
            fi
            for ((i = start_index; i < end_index && i < ${#search_results[@]}; i++)); do
                pkg=${search_results[i]}
                if [[ " ${selected_packages[@]} " =~ " ${pkg} " ]]; then
                    status="[X]"
                else
                    status="[ ]"
                fi
                if [ $i -eq $((cursor + current_page * RESULTS_PER_PAGE)) ]; then
                    echo -e "> $status $pkg"
                else
                    echo "  $status $pkg"
                fi
            done
            total_pages=$(((${#search_results[@]} + RESULTS_PER_PAGE - 1) / RESULTS_PER_PAGE))
            echo "--------------------------------------------------"
            echo "Page $((current_page + 1)) of $total_pages"
        fi
    else
        echo "Selected Packages:"
        echo "Use arrow keys to navigate, space to request unselection, Enter to confirm."
        echo "--------------------------------------------------"
        if [[ ${#selected_packages[@]} -eq 0 ]]; then
            echo "No packages selected."
        else
            start_index=$((current_page * RESULTS_PER_PAGE))
            end_index=$((start_index + RESULTS_PER_PAGE - 1))
            for ((i = start_index; i <= end_index && i < ${#selected_packages[@]}; i++)); do
                pkg=${selected_packages[i]}
                if [[ -z "$pkg" ]]; then
                    continue
                fi
                if [[ " ${selected_for_removal[@]} " =~ " ${pkg} " ]]; then
                    status="[ ]"
                else
                    status="[X]"
                fi
                if [ $i -eq $((cursor + current_page * RESULTS_PER_PAGE)) ]; then
                    echo -e "> $status $pkg"
                else
                    echo "  $status $pkg"
                fi
            done
            total_pages=$(((${#selected_packages[@]} + RESULTS_PER_PAGE - 1) / RESULTS_PER_PAGE))
            echo "--------------------------------------------------"
            echo "Page $((current_page + 1)) of $total_pages"
        fi
    fi
}

# Function to read keyboard input
read_input() {
    IFS= read -rsn1 input
    if [[ $input == $'\x1b' ]]; then
        read -rsn2 -t 0.1 input
    fi
    echo "$input"
}

# Function to handle keyboard input
handle_input() {
    input=$1
    case "$input" in
        '[A') # Up arrow
            if [ $cursor -gt 0 ]; then
                cursor=$((cursor - 1))
            else
                if [ $current_page -gt 0 ]; then
                    current_page=$((current_page - 1))
                    cursor=$((RESULTS_PER_PAGE - 1))
                else
                    cursor=0
                fi
            fi
            ;;
        '[B') # Down arrow
            if [ $cursor -lt $((RESULTS_PER_PAGE - 1)) ]; then
                cursor=$((cursor + 1))
                if [ "$mode" == "selected" ] && [ $((cursor + current_page * RESULTS_PER_PAGE)) -ge ${#selected_packages[@]} ]; then
                    cursor=$((cursor - 1))
                fi
            else
                if [ $((current_page + 1)) -lt $total_pages ]; then
                    current_page=$((current_page + 1))
                    cursor=0
                else
                    cursor=$((RESULTS_PER_PAGE - 1))
                fi
            fi
            ;;
        '[C') # Right arrow (Next page)
            if [ $((current_page + 1)) -lt $total_pages ]; then
                current_page=$((current_page + 1))
                cursor=0
            fi
            ;;
        '[D') # Left arrow (Previous page)
            if [ $current_page -gt 0 ]; then
                current_page=$((current_page - 1))
                cursor=0
            fi
            ;;
       ' '|$'\x20') # Space bar
            if [ "$mode" == "search" ]; then
                local idx=$((cursor + current_page * RESULTS_PER_PAGE))
                pkg=${search_results[idx]}
                if [[ -z "$pkg" ]]; then
                    return
                fi
                found=false
                for ((i=0; i<${#selected_packages[@]}; i++)); do
                    if [[ "${selected_packages[i]}" == "$pkg" ]]; then
                        unset 'selected_packages[i]'
                        selected_packages=("${selected_packages[@]}")
                        found=true
                        break
                    fi
                done
                if ! $found; then
                    selected_packages+=("$pkg")
                fi
            else
                mark_for_removal
            fi
            ;;
        ''|'\r') # Enter key
            if [ "$mode" == "search" ]; then
                search_packages
            else
                confirm_proceed
                [ $? == 1 ] && return 1
            fi
            ;;
        '^?'|$'\x7f') # Backspace key
            if [ "$mode" == "search" ]; then
                search_term="${search_term%?}"
            fi
            ;;
        '[3'|$'\e[3~'|"\e[1;5D"|"\e[3;5~"|"\e[127;5;5~")  # Delete key
            if [ "$mode" == "search" ]; then
                search_term=""
            fi
            ;;
        $'\t') # Tab key
            if [ "$mode" == "search" ]; then
                mode="selected"
                cursor=0
                current_page=0
                total_pages=$(((${#selected_packages[@]} + RESULTS_PER_PAGE - 1) / RESULTS_PER_PAGE))
            else
                mode="search"
                cursor=0
                current_page=0
                total_pages=$(((${#search_results[@]} + RESULTS_PER_PAGE - 1) / RESULTS_PER_PAGE))
            fi
            ;;
        [A-Za-z0-9_.+-]*) # Allow only alphanumeric characters and _.+- (assuming it's a character for the search term)
            if [ "$mode" == "search" ]; then
                search_term+="$input"
            fi
            ;;
        *) # Ignore all other inputs
            ;;
    esac

    # Ensure cursor is within bounds
    if [ "$mode" == "search" ]; then
        total_items=${#search_results[@]}
    else
        total_items=${#selected_packages[@]}
    fi

    if [ $cursor -ge $total_items ]; then
        cursor=$((total_items - 1))
    fi

    if [ $cursor -lt 0 ]; then
        cursor=0
    fi

    if [ $total_items -eq 0 ]; then
        cursor=0
        current_page=0
    fi

    if [ $((current_page * RESULTS_PER_PAGE + cursor)) -ge $total_items ]; then
        cursor=$((total_items % RESULTS_PER_PAGE - 1))
        current_page=$((total_items / RESULTS_PER_PAGE))
    fi

    return 0
}

# Function to search for packages using apt-cache
search_packages() {
    cursor=0
    current_page=0
    search_results=()
    error_message=""
    if [[ -z "$search_term" ]]; then
        return
    fi

    # Search for packages using apt-cache and filter the results to include only those that start with the search term
    results=$(apt-cache search "$search_term" 2>&1 | grep -E "^$search_term")
    if [[ $? -ne 0 ]]; then
        error_message="$results"
        return
    fi
    # Loop through the filtered results and get the package name and description
    while IFS= read -r result; do
        pkg="${result%% - *}"
        if [[ -z "$pkg" ]]; then
            continue
        fi
        desc="${result#*- }"
        # Limit description to 45 characters and append "..." if it exceeds the limit
        if [ "${#desc}" -gt 45 ]; then
            desc="${desc:0:42}..."
        fi
        search_results+=("$pkg - $desc")
    done <<< "$results"
    total_pages=$(((${#search_results[@]} + RESULTS_PER_PAGE - 1) / RESULTS_PER_PAGE))
}

# Function to mark a package for removal or selection
mark_for_removal() {
    local idx=$((cursor + current_page * RESULTS_PER_PAGE))
    pkg=${selected_packages[idx]}
    if [[ -z "$pkg" ]]; then
        return
    fi
    found=false
    for ((i=0; i<${#selected_for_removal[@]}; i++)); do
        if [[ "${selected_for_removal[i]}" == "$pkg" ]]; then
            unset 'selected_for_removal[i]'
            found=true
            break
        fi
    done
    if ! $found; then
        selected_for_removal+=("$pkg")
    fi
}

# Function to confirm proceeding
confirm_proceed() {
    local proceed=false 
    if [[ ${#selected_for_removal[@]} -gt 0 ]]; then
        echo "Are you sure you want to proceed with the selected action? (y/n)"
        while true; do
            read -rsn1 confirm
            case "$confirm" in
                'y' | 'Y')
                    for pkg in "${selected_for_removal[@]}"; do
                        found=false
                        for ((i=0; i<${#selected_packages[@]}; i++)); do
                            if [[ "${selected_packages[i]}" == "$pkg" ]]; then
                                unset 'selected_packages[i]'
                                selected_packages=("${selected_packages[@]}")
                                found=true
                                break
                            fi
                        done
                        if ! $found; then
                            selected_packages+=("$pkg")
                        fi
                    done
                    selected_for_removal=()
                    rebuild_selected_packages
                    break
                    ;;
                'n' | 'N')
                    selected_for_removal=()
                    break
                    ;;
            esac
        done
    else
        echo "Do you want to proceed with the installation of selected packages? (y/n)"
        while true; do
            read -rsn1 confirm
            case "$confirm" in
                'y' | 'Y')
                    proceed=true
                    break 1
                    ;;
                'n' | 'N')
                    break
                    ;;
            esac
        done
    fi
    if $proceed; then
        echo proceed >> debug.log
        return 1
    fi
}

# Function to adjust cursor and page after changes
adjust_cursor_and_page() {
    total_pages=$(((${#selected_packages[@]} + RESULTS_PER_PAGE - 1) / RESULTS_PER_PAGE))

    # Adjust cursor if it goes out of bounds
    if [ $cursor -ge ${#selected_packages[@]} ]; then
        cursor=$(( ${#selected_packages[@]} - 1 ))
    fi

    # Adjust current page based on new cursor position
    current_page=$((cursor / RESULTS_PER_PAGE))
}

# Function to rebuild the selected_packages array
rebuild_selected_packages() {
    new_selected_packages=()
    for pkg in "${selected_packages[@]}"; do
        if [[ -n "$pkg" ]]; then
            new_selected_packages+=("$pkg")
        fi
    done
    selected_packages=("${new_selected_packages[@]}")
    adjust_cursor_and_page
}

# Main loop
while true; do
    show_menu
    input=$(read_input)
    handle_input "$input"
    if [ $? -ne 0 ]; then
        break
    fi
done

# Install selected packages
if [ ${#selected_packages[@]} -gt 0 ]; then
    echo "Installing selected packages: ${selected_packages[@]}"
    sudo apt-get update
    sudo apt-get install -y "${selected_packages[@]}"
else
    echo "No packages selected."
fi

This Bash script allows users to select packages for installation or removal interactively using a terminal interface. It provides two modes: select and search.

Select Mode: Displays a list of preselected packages along with the option to mark packages for removal. Users can navigate through the list using arrow keys, toggle package selection with the space bar, and confirm their selections with the Enter key.

Search Mode: Enables users to search for packages using keywords. As users type in their search term, the script dynamically displays matching packages. Again, users can navigate the search results, toggle selections, and confirm their choices.

Usage:

Navigation Controls:
Use the Up and Down arrow keys to move the cursor up and down the list.
Use the Right and Left arrow keys to navigate between pages in search results.
Press Tab to switch between Select Mode and Search Mode.

Package Selection:
In Select Mode, press the Space bar to toggle the selection of a package.
In Search Mode, press Space to select or deselect a package from the search results.

Confirmations:
Press Enter to confirm your selections or initiate a search.
When prompted, use y to confirm an action and n to cancel.

Installation:
Once selections are finalized, the script proceeds with the installation or removal of the chosen packages.
Keyboard Controls:

Navigation Controls:
Up Arrow: Move the cursor upward in the list of packages.
Down Arrow: Move the cursor downward in the list of packages.
Right Arrow: Navigate to the next page (for search results).
Left Arrow: Navigate to the previous page (for search results).
Tab: Toggle between Select Mode and Search Mode.

Package Selection:
Space Bar: Toggle the selection of a package.
In Select Mode, toggles the selection status of the highlighted package.
In Search Mode, selects or deselects the highlighted package from the search results.

Search Input:
Characters: Type characters to enter search terms. Results dynamically update as you type.
Backspace: Remove the last character from the search term.

Confirmations:
Enter: Confirm selections or initiate a search based on the current mode.
In Select Mode, confirms selected packages or initiates a search with the entered search term.
In Search Mode, initiates a search with the entered search term.
y (or Y): Confirm an action (e.g., proceeding with selected packages or selected action).
n (or N): Cancel the action or exit the script without proceeding.

Edit: A little demo on how it works:

demo.gif
demo.gif (80.07 KiB) Viewed 2366 times

If you wish you could integrate something like this in the build script.

Stealing from the poor to give to the rich!
bslit - Block Splitter Custom Calendar Widget + Diary

User avatar
wiak
Posts: 4077
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 65 times
Been thanked: 1206 times
Contact:

Re: Bookworm Build script

Post by wiak »

superhik wrote: Wed May 29, 2024 10:58 am

...
Edit: A little demo on how it works:
demo.gif
If you wish you could integrate something like this in the build script.

That looks pretty neat. Interesting.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

User avatar
fredx181
Posts: 3051
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 371 times
Been thanked: 1297 times
Contact:

Re: Bookworm Build script

Post by fredx181 »

superhik wrote:

Hey Fredx181 of the under-the-sea lands. :D
Command line version has less options.
I'd like to extend them and provide a way to add packages by searching for package names.
The part which selects graphical environment is unreadable to me.

Thanks ! Looks very nice, do you think possible that ..., or are you able..., to integrate it in the build script ?

The part which selects graphical environment is unreadable to me

edit: misunderstood...
Don't understand what exactly, the bash menu when running with -cli OR do you mean when running with -gui :?:
EDIT: Oh well, probably you mean with -cli, what's the problem being unreadable, can you show screenshot perhaps ?
Btw, when running with -cli you're supposed to edit the .conf file in /tmp, to add/remove packages.

2024-05-29_18-51-38.png
2024-05-29_18-51-38.png (73.53 KiB) Viewed 2303 times

(as opposed to when running with -gui where you can edit the package list directly in the GUI)

User avatar
fredx181
Posts: 3051
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 371 times
Been thanked: 1297 times
Contact:

Re: Bookworm Build script

Post by fredx181 »

superhik wrote:

The part which selects graphical environment is unreadable to me.

I misunderstood earlier, see what you mean now, the code part in the script for the bash-menu, it works ok, but yes it's a bit weird :? (edit: but your code isn't very easy to read too, btw ;) ).

Tried your script and found that added packages to the list by search fail to install. Probably because the variable for these contain the package description.
Package apt-config-icons for example:

Code: Select all

> [X] curl
  [X] git
  [X] vim
  [X] apt-config-icons - APT configuration snippet to enable icon d...
--------------------------------------------------

E: Unable to locate package apt-config-icons - APT configuration snippet to enable icon d...

EDIT:
Fixed that problem, I think, see below modified code, on itself I like it being a sort of simple cli package manager, but how to integrate in the build script is another thing, perhaps at the point when running in the chroot, something like this could be useful.

Code: Select all

#!/bin/bash

# List of preselected packages
preselected_packages=("curl" "git" "vim")

# Initialize an array to hold selected packages
selected_packages=("${preselected_packages[@]}")
selected_for_removal=()  # Track packages marked for removal
search_results=()
search_term=""
cursor=0
error_message=""
RESULTS_PER_PAGE=10
current_page=0
total_pages=0
mode="selected"  # Modes: search, selected

# Function to display the menu
show_menu() {
    clear
    if [ "$mode" == "search" ]; then
        echo "Search: $search_term"
        echo "Use arrow keys to navigate, space to toggle selection, and Enter to search."
	echo "When done, press tab to continue"
        echo "--------------------------------------------------"
        if [[ -n "$error_message" ]]; then
            echo "Error: $error_message"
            echo "--------------------------------------------------"
        elif [[ ${#search_results[@]} -eq 0 ]]; then
            echo "No results found."
        else
            start_index=$((current_page * RESULTS_PER_PAGE))
            end_index=$((start_index + RESULTS_PER_PAGE))
            if [ $end_index -gt ${#search_results[@]} ]; then
                end_index=${#search_results[@]}
            fi
            for ((i = start_index; i < end_index && i < ${#search_results[@]}; i++)); do
                pkg=${search_results[i]}
#                if [[ " ${selected_packages[@]} " =~ " ${pkg} " ]]; then
                if [[ " ${selected_packages[@]} " =~ " ${pkg%% - *} " ]]; then
                    status="[X]"
                else
                    status="[ ]"
                fi
                if [ $i -eq $((cursor + current_page * RESULTS_PER_PAGE)) ]; then
                    echo -e "> $status $pkg"
                else
                    echo "  $status $pkg"
                fi
            done
            total_pages=$(((${#search_results[@]} + RESULTS_PER_PAGE - 1) / RESULTS_PER_PAGE))
            echo "--------------------------------------------------"
            echo "Page $((current_page + 1)) of $total_pages"
        fi
    else
        echo "Selected Packages:"
        echo "Use arrow keys to navigate, space to request unselection, Enter to confirm."
        echo "Press tab to search"
        echo "--------------------------------------------------"
        if [[ ${#selected_packages[@]} -eq 0 ]]; then
            echo "No packages selected."
        else
            start_index=$((current_page * RESULTS_PER_PAGE))
            end_index=$((start_index + RESULTS_PER_PAGE - 1))
            for ((i = start_index; i <= end_index && i < ${#selected_packages[@]}; i++)); do
                pkg=${selected_packages[i]}
                if [[ -z "$pkg" ]]; then
                    continue
                fi
                if [[ " ${selected_for_removal[@]} " =~ " ${pkg} " ]]; then
                    status="[ ]"
                else
                    status="[X]"
                fi
                if [ $i -eq $((cursor + current_page * RESULTS_PER_PAGE)) ]; then
                    echo -e "> $status $pkg"
                else
                    echo "  $status $pkg"
                fi
            done
            total_pages=$(((${#selected_packages[@]} + RESULTS_PER_PAGE - 1) / RESULTS_PER_PAGE))
            echo "--------------------------------------------------"
            echo "Page $((current_page + 1)) of $total_pages"
        fi
    fi
}

# Function to read keyboard input
read_input() {
    IFS= read -rsn1 input
    if [[ $input == $'\x1b' ]]; then
        read -rsn2 -t 0.1 input
    fi
    echo "$input"
}

# Function to handle keyboard input
handle_input() {
    input=$1
    case "$input" in
        '[A') # Up arrow
            if [ $cursor -gt 0 ]; then
                cursor=$((cursor - 1))
            else
                if [ $current_page -gt 0 ]; then
                    current_page=$((current_page - 1))
                    cursor=$((RESULTS_PER_PAGE - 1))
                else
                    cursor=0
                fi
            fi
            ;;
        '[B') # Down arrow
            if [ $cursor -lt $((RESULTS_PER_PAGE - 1)) ]; then
                cursor=$((cursor + 1))
                if [ "$mode" == "selected" ] && [ $((cursor + current_page * RESULTS_PER_PAGE)) -ge ${#selected_packages[@]} ]; then
                    cursor=$((cursor - 1))
                fi
            else
                if [ $((current_page + 1)) -lt $total_pages ]; then
                    current_page=$((current_page + 1))
                    cursor=0
                else
                    cursor=$((RESULTS_PER_PAGE - 1))
                fi
            fi
            ;;
        '[C') # Right arrow (Next page)
            if [ $((current_page + 1)) -lt $total_pages ]; then
                current_page=$((current_page + 1))
                cursor=0
            fi
            ;;
        '[D') # Left arrow (Previous page)
            if [ $current_page -gt 0 ]; then
                current_page=$((current_page - 1))
                cursor=0
            fi
            ;;
       ' '|$'\x20') # Space bar
            if [ "$mode" == "search" ]; then
                local idx=$((cursor + current_page * RESULTS_PER_PAGE))
                #pkg=${search_results[idx]}
		pkg=${search_results[idx]%% - *}
                if [[ -z "$pkg" ]]; then
                    return
                fi
                found=false
                for ((i=0; i<${#selected_packages[@]}; i++)); do
                    if [[ "${selected_packages[i]}" == "$pkg" ]]; then
                        unset 'selected_packages[i]'
                        selected_packages=("${selected_packages[@]}")
                        found=true
                        break
                    fi
                done
                if ! $found; then
                    selected_packages+=("$pkg")
                fi
            else
                mark_for_removal
            fi
            ;;
        ''|'\r') # Enter key
            if [ "$mode" == "search" ]; then
                search_packages
            else
                confirm_proceed
                [ $? == 1 ] && return 1
            fi
            ;;
        '^?'|$'\x7f') # Backspace key
            if [ "$mode" == "search" ]; then
                search_term="${search_term%?}"
            fi
            ;;
        '[3'|$'\e[3~'|"\e[1;5D"|"\e[3;5~"|"\e[127;5;5~")  # Delete key
            if [ "$mode" == "search" ]; then
                search_term=""
            fi
            ;;
        $'\t') # Tab key
            if [ "$mode" == "search" ]; then
                mode="selected"
                cursor=0
                current_page=0
                total_pages=$(((${#selected_packages[@]} + RESULTS_PER_PAGE - 1) / RESULTS_PER_PAGE))
            else
                mode="search"
                cursor=0
                current_page=0
                total_pages=$(((${#search_results[@]} + RESULTS_PER_PAGE - 1) / RESULTS_PER_PAGE))
            fi
            ;;
        [A-Za-z0-9_.+-]*) # Allow only alphanumeric characters and _.+- (assuming it's a character for the search term)
            if [ "$mode" == "search" ]; then
                search_term+="$input"
            fi
            ;;
        *) # Ignore all other inputs
            ;;
    esac

    # Ensure cursor is within bounds
    if [ "$mode" == "search" ]; then
        total_items=${#search_results[@]}
    else
        total_items=${#selected_packages[@]}
    fi

    if [ $cursor -ge $total_items ]; then
        cursor=$((total_items - 1))
    fi

    if [ $cursor -lt 0 ]; then
        cursor=0
    fi

    if [ $total_items -eq 0 ]; then
        cursor=0
        current_page=0
    fi

    if [ $((current_page * RESULTS_PER_PAGE + cursor)) -ge $total_items ]; then
        cursor=$((total_items % RESULTS_PER_PAGE - 1))
        current_page=$((total_items / RESULTS_PER_PAGE))
    fi

    return 0
}

# Function to search for packages using apt-cache
search_packages() {
    cursor=0
    current_page=0
    search_results=()
    error_message=""
    if [[ -z "$search_term" ]]; then
        return
    fi

    # Search for packages using apt-cache and filter the results to include only those that start with the search term
    results=$(apt-cache search "$search_term" 2>&1 | grep -E "^$search_term")
    if [[ $? -ne 0 ]]; then
        error_message="$results"
        return
    fi
    # Loop through the filtered results and get the package name and description
    while IFS= read -r result; do
        pkg="${result%% - *}"
        if [[ -z "$pkg" ]]; then
            continue
        fi
        desc="${result#*- }"
        # Limit description to 45 characters and append "..." if it exceeds the limit
        if [ "${#desc}" -gt 45 ]; then
            desc="${desc:0:42}..."
        fi
        search_results+=("$pkg - $desc")
    done <<< "$results"
    total_pages=$(((${#search_results[@]} + RESULTS_PER_PAGE - 1) / RESULTS_PER_PAGE))
}

# Function to mark a package for removal or selection
mark_for_removal() {
    local idx=$((cursor + current_page * RESULTS_PER_PAGE))
    pkg=${selected_packages[idx]}
    if [[ -z "$pkg" ]]; then
        return
    fi
    found=false
    for ((i=0; i<${#selected_for_removal[@]}; i++)); do
        if [[ "${selected_for_removal[i]}" == "$pkg" ]]; then
            unset 'selected_for_removal[i]'
            found=true
            break
        fi
    done
    if ! $found; then
        selected_for_removal+=("$pkg")
    fi
}

# Function to confirm proceeding
confirm_proceed() {
    local proceed=false 
    if [[ ${#selected_for_removal[@]} -gt 0 ]]; then
        echo "Are you sure you want to proceed with the selected action? (y/n)"
        while true; do
            read -rsn1 confirm
            case "$confirm" in
                'y' | 'Y')
                    for pkg in "${selected_for_removal[@]}"; do
                        found=false
                        for ((i=0; i<${#selected_packages[@]}; i++)); do
                            if [[ "${selected_packages[i]}" == "$pkg" ]]; then
                                unset 'selected_packages[i]'
                                selected_packages=("${selected_packages[@]}")
                                found=true
                                break
                            fi
                        done
                        if ! $found; then
                            selected_packages+=("$pkg")
                        fi
                    done
                    selected_for_removal=()
                    rebuild_selected_packages
                    break
                    ;;
                'n' | 'N')
                    selected_for_removal=()
                    break
                    ;;
            esac
        done
    else
        echo "Do you want to proceed with the installation of selected packages? (y/n)"
        while true; do
            read -rsn1 confirm
            case "$confirm" in
                'y' | 'Y')
                    proceed=true
                    break 1
                    ;;
                'n' | 'N')
                    break
                    ;;
            esac
        done
    fi
    if $proceed; then
        echo proceed >> debug.log
        return 1
    fi
}

# Function to adjust cursor and page after changes
adjust_cursor_and_page() {
    total_pages=$(((${#selected_packages[@]} + RESULTS_PER_PAGE - 1) / RESULTS_PER_PAGE))

    # Adjust cursor if it goes out of bounds
    if [ $cursor -ge ${#selected_packages[@]} ]; then
        cursor=$(( ${#selected_packages[@]} - 1 ))
    fi

    # Adjust current page based on new cursor position
    current_page=$((cursor / RESULTS_PER_PAGE))
}

# Function to rebuild the selected_packages array
rebuild_selected_packages() {
    new_selected_packages=()
    for pkg in "${selected_packages[@]}"; do
        if [[ -n "$pkg" ]]; then
            new_selected_packages+=("$pkg")
        fi
    done
    selected_packages=("${new_selected_packages[@]}")
    adjust_cursor_and_page
}

# Main loop
while true; do
    show_menu
    input=$(read_input)
    handle_input "$input"
    if [ $? -ne 0 ]; then
        break
    fi
done

# Install selected packages
if [ ${#selected_packages[@]} -gt 0 ]; then
    echo "Installing selected packages: ${selected_packages[@]}"
    sudo apt-get update
    sudo apt-get install -y "${selected_packages[@]}"
else
    echo "No packages selected."
fi
superhik
Posts: 38
Joined: Mon Jun 19, 2023 7:56 pm
Has thanked: 5 times
Been thanked: 17 times

Re: Bookworm Build script

Post by superhik »

I messed up in the end, forgot to test the install part. :D
You removed the description and now it works.
I'll see when I have time to add the description to the "selected" view.

Stealing from the poor to give to the rich!
bslit - Block Splitter Custom Calendar Widget + Diary

User avatar
fredx181
Posts: 3051
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 371 times
Been thanked: 1297 times
Contact:

Re: Bookworm Build script

Post by fredx181 »

superhik wrote: Sat Jun 01, 2024 4:17 pm

I messed up in the end, forgot to test the install part. :D

What ?!! You do some brilliant coding (yes :thumbup: ) and forget the following most important thing: TEST !!? :shock: ;)

I'll see when I have time to add the description to the "selected" view.

I think it's nice to see the description when searching, but IMO not really necessary to show in the select view.

wanderer
Posts: 760
Joined: Mon Jul 13, 2020 7:15 pm
Been thanked: 138 times

Re: Bookworm Build script

Post by wanderer »

hi everyone

i am using bookworm

but am not able to connect to the internet sometimes
even though i am on a wired connection
one computer will work
another will not
any ideas why this is happening

thanks

wanderer

User avatar
fredx181
Posts: 3051
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 371 times
Been thanked: 1297 times
Contact:

Re: Bookworm Build script

Post by fredx181 »

wanderer wrote: Wed Jun 12, 2024 3:42 pm

hi everyone

i am using bookworm

but am not able to connect to the internet sometimes
even though i am on a wired connection
one computer will work
another will not
any ideas why this is happening

thanks

wanderer

Can you provide more info about what exact configuration you used to build bookworm ? For example, with or without systemd and/or which network manager, e.g. frisbee or peasywifi is included .
And what you get on the problematic machine when you type in terminal: ifconfig -a

wanderer
Posts: 760
Joined: Mon Jul 13, 2020 7:15 pm
Been thanked: 138 times

Re: Bookworm Build script

Post by wanderer »

hi fredx181

i built everything on a compaq laptop with 2 gigs of ram

the computer that will not access the wired internet is a dell desktop with 4 gigs of ram

on my build
no systemd
peasywifi

the original iso that i built everything on also will not access wired internet

peasywifi and ifconfig -a seem to give pretty much the same message on both computers
but i dont know what i am looking for in their output
and its pretty long

not a big deal since i can use the laptop
so i will try to gather more data
and ask again when i have more info

could there be a module missing that is needed for the slightly newer dell desktop ?

and thanks again for all your help and for making this masterpiece

wanderer

User avatar
rcrsn51
Posts: 1383
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 357 times

Re: Bookworm Build script

Post by rcrsn51 »

Open the Ethernet section. Click I/F. Do you have eth0?
Click on Reconnect. Then click on Info. Does eth0 get an IP address?

wanderer
Posts: 760
Joined: Mon Jul 13, 2020 7:15 pm
Been thanked: 138 times

Re: Bookworm Build script

Post by wanderer »

hi rcrsn51

thanks for your help

edit

i/f
does not list eth0
its blank

on the computer that works it lists eth0

the dell that doesnt work
with upup32
lists the interface as enp2s0
type wired
driver tg3
bus pci
hardware BC:30:5B:A9:E0:71

maybe it doesnt have the right driver for the dell hardware

wanderer

User avatar
fredx181
Posts: 3051
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 371 times
Been thanked: 1297 times
Contact:

Re: Bookworm Build script

Post by fredx181 »

wanderer wrote: Thu Jun 13, 2024 3:06 am

the dell that doesnt work
with upup32
lists the interface as enp2s0
type wired
driver tg3
bus pci
hardware BC:30:5B:A9:E0:71

Hi wanderer,
Is it listed as enp2s0 on upup32 only and not on bookworm ?

If also on bookworm, the wired interface seems to be recognized but with other name, often interfaces have these "cryptic" names like enp2s0 when booted with systemd, anyway, two options:
1) add net.ifnames=0 to your grub? kernel boot command line, then the wired interface should be named eth0 at reboot
Or:
2) edit the peasywifi config: /etc/pwf/interfaces and change ETH0="eth0" to ETH0="enp2s0"

If there's no wired interface listed on bookworm then 1) or 2) have no effect, and the problem may be because of missing firmware.

When doing a new bookworm build you can try adding firmware-linux-nonfree to the packages install list (not sure though if that fixes the problem).
edit: firmware-misc-nonfree should be ok too, see next posts (firmware-linux-nonfree contains it also, but has a bit more).

User avatar
rcrsn51
Posts: 1383
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 357 times

Re: Bookworm Build script

Post by rcrsn51 »

The "tg3" driver needs firmware: firmware-misc-nonfree

User avatar
fredx181
Posts: 3051
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 371 times
Been thanked: 1297 times
Contact:

Re: Bookworm Build script

Post by fredx181 »

@wanderer , here's a firmware sfs module 99-firmware-bookworm.squashfs , just place it in the frugal install "live" folder and reboot.
https://drive.google.com/uc?export=down ... 6HaMRL4g5l
It contains lots of firmware, also from the package firmware-misc-nonfree .
Note: this is for a usr-merged filesystem (where e.g. /bin and /lib are symlinks, not regular folders), does not work if you have chosen "no-merged-usr" at build time.
edit: or, make a new build and add firmware-misc-nonfree to the package install list.
edit: or download from other system and install on your Dell the deb package https://packages.debian.org/bookworm/al ... e/download
dpkg -i firmware-misc-nonfree_20230210-5_all.deb

wanderer
Posts: 760
Joined: Mon Jul 13, 2020 7:15 pm
Been thanked: 138 times

Re: Bookworm Build script

Post by wanderer »

thanks so much guys
for all your help

will follow up
and report back

edit
just wanted to report that i finally had the opportunity to try your suggestions
have had no luck yet
however i am comparing the distros that do work with the offending machine with debiandog
to isolate the issue
and as i said debiandog works on my laptop
so i will build and study it on that machine

so no further requests for help at this time

and thanks again for your patience
and for making this masterpiece

wanderer

Last edited by wanderer on Tue Jun 18, 2024 10:07 pm, edited 4 times in total.
User avatar
fredx181
Posts: 3051
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 371 times
Been thanked: 1297 times
Contact:

Updated: Bookworm Build script

Post by fredx181 »

*** Updated: Bookworm Build script ***
New attachment at first post
Fixed that the build got stuck recently on installing latest debootstrap version, to prevent such problem in the future, now it will install a slightly older version (1.0.134) from the custom MakeLive repo at github.

trister
Posts: 103
Joined: Mon Sep 28, 2020 6:52 am
Has thanked: 27 times
Been thanked: 17 times

Re: Bookworm Build script

Post by trister »

As always nice work fred181 :)
I decided to try again with bookworm. I planned to do it after you added the option for non-merged filesystem.

I have an issue and I don't know if it has been mentioned before. It is too simple to describe so the results are thousands.

I have a brand new i5-14600k with Asus Motherboard and m2 SSD.
I used the appimage and generated the files needed for a frugal install.
My problem is that when I select the bookworm boot option the screen goes completely blank (no messages -no anything), caps lock works (=PC is not stuck) and nothing else happens. I tried with nomodeset parameter but didn't change anything. Note: I boot with the files generated by the boot image . I do not load any save file or any extra squashfs files.

I must mention that my normal bulleye frugal install in the same PC when booting debian it also shows a blank screen for a few seconds but the image re-appears a bit after all the squashfs are loaded and everything works normal.

I believe this is related to the specific PC but I can't think of what else to do. I'll try running bookworm tomorrow in my old e8600 core2 and see what happens.

Thanks again for your effort

Attachments
build_setup__240730bookworm02.conf.txt
conf file test 2
(5.24 KiB) Downloaded 19 times
dancytron
Posts: 721
Joined: Fri Dec 13, 2019 6:26 pm
Has thanked: 518 times
Been thanked: 215 times

Re: Bookworm Build script

Post by dancytron »

I don't know if it helps, but I have a Core Duo E8400 HP Desktop and it won't run any kernel much past Stretch.

https://oldforum.puppylinux.com/search. ... sf=msgonly

trister
Posts: 103
Joined: Mon Sep 28, 2020 6:52 am
Has thanked: 27 times
Been thanked: 17 times

Re: Bookworm Build script

Post by trister »

dancytron wrote: Tue Jul 30, 2024 7:43 pm

I don't know if it helps, but I have a Core Duo E8400 HP Desktop and it won't run any kernel much past Stretch.

https://oldforum.puppylinux.com/search. ... sf=msgonly

In my lab I have e4400+ (and some older) PCs. They all run bullseye dog 64bit . A few months ago I copied the 6.1( or higher) kernel that @fredx181 send me. They all run very well. I have Dells,HPs and Lenovo core duos and core2duo (my main home PC is an i3 13th gen)

Last edited by trister on Wed Jul 31, 2024 7:04 am, edited 1 time in total.
trister
Posts: 103
Joined: Mon Sep 28, 2020 6:52 am
Has thanked: 27 times
Been thanked: 17 times

Re: Bookworm Build script

Post by trister »

Update2 : Adding kernel parameter "i915.modeset=1" starts the system but again the monitor shows the end of the boot process. Any ideas (kernel parameter on how to see the boot process from the start?

Update1:
I booted again (let it a minute just to make sure the system is booted) and while the screen was still black I presses Ctrl+Alt+F7 (new linux session terminal) . I then typed (blindly) root/root (to login to the terminal) and the login window showed up.
So, I guess the problem is display related. I have no idea what I should do since the screen goes black at the millisecond I select the specific boot option from grub2.
Is there a kernel option I could use? nomodeset did not had any effect.

trister wrote: Tue Jul 30, 2024 2:14 pm

...
My problem is that when I select the bookworm boot option the screen goes completely blank (no messages -no anything), caps lock works (=PC is not stuck) and nothing else happens. I tried with nomodeset parameter but didn't change anything. Note: I boot with the files generated by the boot image . I do not load any save file or any extra squashfs files.
...

User avatar
fredx181
Posts: 3051
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 371 times
Been thanked: 1297 times
Contact:

Re: Bookworm Build script

Post by fredx181 »

@trister

I used the appimage

Tested making a build with mklive-bookworm64 (appimage) using your attached config "build_setup__240730bookworm02.conf.txt" and it boots fine for me, so, no idea what can be the problem for you.

I planned to do it after you added the option for non-merged filesystem.

Btw, I noticed in your config that it's containing NMU="TRUE" (no-merged-usr) but the appimage can only build with merged-usr.
The mklive-bookworm script from first post does have the choice for no-merged-usr though .

EDIT: You may want to try booting with a different (older?) kernel, but be sure it's usr-merged or no-usr-merged matching with the filesystem.

Post Reply

Return to “DebianDogs”