RPIB (Raspberry Pi Backup Script for the home folder)


#!/bin/sh

datum=$(date +%d_%m_%y)
source=$(hostname)

# Create local share point
mkdir -p ~/RPI_Backups

# Mount the remote backup folder
sudo mount -t cifs -o rw,guest,vers=3.0 //myserver.local/myshare/myfolder ~/RPI_Backups

# Create a subfolder for this host
sudo mkdir -p ~/RPI_Backups/$source

# Create the backup with tar, excluding the backup folder itself
sudo tar --warning=no-file-changed \
--exclude=/home/pi/RPI_Backups \
-czvf /home/pi/RPI_Backups/$source/home_backup_$datum.tar.gz /home/pi

# Unmount the remote share
sudo umount ~/RPI_Backups

quotes-rss (Videos from RSS-Feeds)

Der Anstoss für dieses RPiOS-Projekt kam von Adafruit Quotes, das ist mehr ein Demo-Projekt für diverse Apps und Geräte. Eine deutsche Variante musste her, und auch ein bisschen strukturierter, da ich Zitat und Autor getrennt haben wollte, um gestaltungstechnisch mehr Möglichkeiten zu haben. Und ich wollte Video_looper verwenden, um die Videos automatisch abzuspielen.
Mein Feed liegt hier:http://cargologo.com/feed/quotes/data_rss.xml. Und er lässt sich auch in einen RSS-Viewer einfügen, wie NetNewsWire oder Vienna.
Das Skript lädt den Feed runter, wählt einen Eintrag zufällig aus und erstellt ein Video (anhand eines Hintergrund-Videos und einer Schrift, siehe Assets-Folder). Das Hintergrund-Video (input.mp4) bestimmt die Länge und die Bild-Grösse der erstellten Video-Datei und es könnte auch Bild-Elemente beinhalten. Meine Testumgebung hier ist das ArgonPod-Video-Case mit RPi Zero 2, der ganz gut kleine FFMPEG-Aufgaben erledigen kann, im Gegensatz zum RPi Zero 1. Die Bildschirmgrösse und die Videobildgrösse hier ist 640×480, durch entsprechende Einstellungen bei FFMPEG kann man auch HD-Videos für andere Ausgabegeräte erstellen.
Extension: mit dem Command-Argument ./quotes-rss latest kann man den letzten Eintrag forciert anzeigen lassen.
BTW: jeder andere Feed, der title- und description-entries enthält, geht natürlich auch.


#!/bin/bash
# Usage: ./quotes-rss.sh [latest]

# Home Dir
cd /home/pi/quotes-rss/

# Delete old file
#rm ./data_rss.xml* 2> /dev/null

# Download the latest quotes file
wget http://cargologo.com/feed/quotes/data_rss.xml

# Clean up old videos in video_looper Master Dir
#rm /home/pi/video/*_output.mp4 2> /dev/null

# -- Variables
newstimescreen=$(date '+%A %H-%M')
newstimefile=$(date '+%H%M%S')
modificationtime=$(stat ./data_rss.xml | grep "Modify" | sed 's/Modify:/XML Last Modified/g' | cut -c 1-29 | sed 's/:/\\:/g')

# -- Extraction
xml_file="data_rss.xml"
temp_file=$(mktemp)

# Extract quotes and authors using awk
awk '
BEGIN { RS=""; FS="\n" }
// {
title=""; description=""
for(i=1; i<=NF; i++) { if ($i ~ //) {<br /> sub(".*<title>[ \t]*", "", $i)<br /> sub("[ \t]*.*", "", $i)
title=$i
}
if ($i ~ //) {
sub(".*[ \t]*", "", $i)
sub("[ \t]*
.*", "", $i)
gsub("", "", $i)
description=$i }
}
if (title && description) {
print title "|" description >> "'"$temp_file"'"
last_title = title
last_author = description
}
}
END {
if (last_title && last_author) {
print last_title "|" last_author > "'"$temp_file"'.latest"
}
}
' "$xml_file"

# Verify that temp_file is populated
num_items=$(wc -l < "$temp_file") if [ "$num_items" -eq 0 ]; then echo "No items found with both title and description." rm "$temp_file" exit 1 fi # Choose latest or random quote if [[ "$1" == "latest" ]]; then echo "Showing latest entry..." latest_item=$(cat "$temp_file.latest") random_item=$latest_item else # Load lines from temp_file into an array mapfile -t items < "$temp_file" rm "$temp_file" # Select a random item random_index=$((RANDOM % num_items)) random_item=${items[$random_index]} fi # Split title and description quote=$(echo "$random_item" | cut -d'|' -f1) author=$(echo "$random_item" | cut -d'|' -f2) # Format text with line breaks (2 line breaks between title & author) This is ! formatted_text=$(echo -e "$quote\n\n$author" | fold -s -w 30) # Escape special characters and preserve newlines for ffmpeg ! This is ! # this creates \u0027 formatted_text_escaped=$(echo "$formatted_text" | sed "s/'/\\\u0027/g; s/:/\\\\:/g; s/\n/\\\x0A/g") # create video with ffmpeg ffmpeg -i ./Assets/input.mp4 -vf \ "drawtext=text='${formatted_text_escaped}':fontfile='./Assets/NotoSans_Condensed-Black.ttf':fontcolor=white:fontsize=42:x=10:y=20:box=1:boxcolor=black@0.5:boxborderw=15, \ drawtext=text='${modificationtime}':fontfile='./Assets/NotoSans_Condensed-Black.ttf':fontcolor=yellow:fontsize=30:x=10:y=420" \ -codec:a copy "${newstimefile}_output.mp4" # Debug Output echo "Formatted Text: $formatted_text_escaped" # echo "Modification Time: $modificationtime" # Move file to video folder mv *_output.mp4 /home/pi/video/

Files: Download quotes-rss and Assets

Undervoltage-LED, external

Über dmesg kann man den „Undervoltage“-Status auslesen und an eine externe LED anzeigen lassen. Das macht Sinn bei Custom Cases, bei der die Onboard-LED nicht zu sehen ist. Ausserdem kann man seinen eigenen „Alert Mode“ definieren: blinken, leuchten, blinken-leuchten, flimmern, flackern. Testen kann man das mit diversen Netzteilen und/oder Stromversorgung über Computer-USB, die in der Regel zu gering definiert ist, um einen Raspberry Pi zu betreiben. Liegt natürlich auch am jeweiligen Modell. Achtung: die Schreibweise von „Undervoltage detected!“ ändert sich auch mal entsprechend der Raspberry-Pi-OS-Versionen, z.B. „Under-voltage detected“, dieser String muss natürlich passen.


#!/bin/bash
while [ $loop 1 ] ; do
dmesg | grep -iC 3 "Undervoltage detected!"
if [ $? != 0 ]
then
    echo "normal voltage" &>/dev/null
else
    sh /home/pi/LED/voltage-led
    echo "under voltage" &>/dev/null
fi
sleep 1
done
sleep 0
done

VideoLooper: Timer

Play one file at full hour and change back to normal one („b.mp4“) 🙂
timer.sh

#/bin/bash
mv /home/pi/video/b.mp4 /home/pi/video_off
mv /home/pi/video_off/a.mp4 /home/pi/video
# videoduration a.mp4
sleep 300
mv /home/pi/video/a.mp4 /home/pi/video_off
mv /home/pi/video_off/b.mp4 /home/pi/video

crontab

0 13 * * * /bin/bash /home/pi/timer.sh >> /home/pi/timer.log 2>&1
0 14 * * * /bin/bash /home/pi/timer.sh >> /home/pi/timer.log 2>&1
0 15 * * * /bin/bash /home/pi/timer.sh >> /home/pi/timer.log 2>&1
0 16 * * * /bin/bash /home/pi/timer.sh >> /home/pi/timer.log 2>&1

Videolooper Netvideo: play videos from SMB-Sources

„Netvideo“ ist eine elegante Erweiterung, um Videos nicht von USB-Stick oder dem internen Verzeichnis abzuspielen, sondern über das Netzwerk. Vorteil: jede Änderung in dem Netzwerkverzeichnis wird unmittelbar erkannt und die Datei oder die Dateien werden ganz easy, vom Schreibtisch aus gesteuert, abgespielt. Macht richtig viel Sinn für mittlere und grosse Ausstellungsflächen.
Continue reading „Videolooper Netvideo: play videos from SMB-Sources“

Video Picture Stitcher


#!/bin/bash
echo "--------------------------------"
echo "Video Picture Stitcher V1.0"
echo "requ. ffmpeg"
echo "--------------------------------"
echo "What is the name of your input movie (with suffix:mov/mp4/mkv but without spaces)?"
read theSource
echo "How should the output named?"
read theTarget
echo "Please wait .."
ffmpeg -hide_banner -loglevel error -i ./SourceMovie/$theSource -r 0.009 -s 640x360 -f image2 ./Stills/$theTarget-%03d.jpeg
ls -lR ./Stills/$theTarget* | wc -l
echo "Files created."
echo "... Stitching."
ffmpeg -framerate 10 -pattern_type glob -i "./Stills/$theTarget*.jpeg" ./Stitched/$theTarget.mp4
echo ".... Finished."