Although Foogod's answer didn't work for me, it did lead me into the right direction, by providing half of the solution (namely, reading framebuffer data, while fbi
is showing an image on TTY screen). Therefore I've awarded his answer the bounty.
Bellow is a script that makes it easy to launch fbterm
with partial path to image as a single command line argument
Usage
Script must be saved in a directory that is listed in your $PATH
variable. Preferably it must be in your personal $HOME/bin
folder. Refer to How to add a directory to the PATH? on explanation how to add your personal bin
to $PATH
, but creating a directory called bin
in your home directory is sufficient to add it to PATH
on re-login.
The script also must have executable permission; you can set it with chmod +x /path/to/script.sh
.
Finally, it must be ran with sudo
, to allow root access for reading and writing to /dev/fb0
.
Script Source
Also available on my Github repository.
#!/bin/bash
# Author : Serg Kolo
# Date: Dec 5, 2015
# Description: Script to render image and set it as background
# in conjunction with fbterm
# Depends: fbterm,fbi, awk
# Written for: https://askubuntu.com/q/701874/295286
function printUsage
{
echo "<<< Script to set background image in TTY console"
echo "<<< Written by Serg Kolo, Dec 5 , 2015"
echo "<<< Usage: scriptName.sh /path/to/image"
echo "<<< Must be ran with root privileges, in TTY only"
echo "exiting"
}
# check if we're root, if there's at least one ARG, and it is a TTY
if [ "$(whoami)" != "root" ] || [ "$#" -eq 0 ] || [ "$( tty | awk '{gsub(/[[:digit:]]/,""); gsub(/\/dev\//,"");print}' )" != "tty" ] ;then
printUsage
exit 1
fi
# read the full path of the image
IMAGE="$( readlink -f "$@" )"
# Launch fbi with whatever image was supplied as command line arg
# then take out whatever is the data in framebuffer;
# Store that data to /tmp folder
( sleep 1; cat /dev/fb0 > /tmp/BACKGROUND.fbimg ; sleep 1; pkill fbi ) & fbi -t 2 -1 --noverbose -a "$IMAGE"
# This portion is really optional; you can comment it out
# if you choose so
echo "LAUNCH FBTERM ?(y/n)"
read ANSWER
if [ "$ANSWER" != "y" ] ; then
echo exiting
exit 1
fi
# The man page states that fbterm takes screenshot of
# what is currently in framebuffer and sets it as background
# if FBTERM_BACKGROUND_IMAGE is set to 1
# Therefore the trick is to send the framebuffer data captured
# in the last step (which will display the image on screen)
# and then launch fbterm. Note, that I send output from the command
# send to background in order to avoid the extra text displayed on
# screen. That way we have clear image in framebuffer, without
# the shell text, when we launch fbterm
export FBTERM_BACKGROUND_IMAGE=1
clear
( cat /tmp/BACKGROUND.fbimg > /dev/fb0 &) > /dev/null; sleep 0.25; fbterm
Additional info
It turns out that user doesn't necessarily need to use sudo
; /dev/fb0
belongs to video
group, so users could just add themselves to that group using
sudo usermod -a -G video $USER
Thus, the checks for root in the above script become obsolete, specifically [ "$(whoami)" != "root" ] ||
part.
framebuffer
device, but with that screen is occupied with output of some program, such asfbi
. TTY in and of itself is still a text-only device – Sergiy Kolodyazhnyy Nov 24 '15 at 09:42