ansible/roles/bs_scripte/files/bashlib

67 lines
3.8 KiB
Plaintext

# Fügt einen Zeitstempel am Beginn jede Zeile an und gibt das Ergebnis aus
# Um ein einheitliches Format festzulegen einigen wir uns auf Fri Nov 18 13:01:21 CET 2022
# Das entspricht dem Befehl date +'%a %b %d %H:%M:%S %Z %Y', falls die Locale EN ist.
# Das wird bei jedem Aufruf sichergestellt, nach der Funktion ist diese LC wieder weg.
# Ist hilfreich beim Testen, falls das unter cron ausgeführt wird ist eh schon die englische LC
# durch die Einstellungen in /etc/environment vorausgewählt.
adddate() {
LC_ALL=en_US.UTF-8
while IFS= read -r line; do
printf '%s %s\n' "$(date +"%a %b %d %H:%M:%S %Z %Y")" "$line";
done
}
# Gibt den Namen der 1. aktiven NIC zurück die nicht das Loopback Interface ist und keine virtuelle NIC im KVM-Umfeld
# Funktioniert auf Ubuntu 20.04, andere Versionen ungetestet.
# Kann man sicher eleganter machen
getnic() {
echo `ip link show | grep "state UP" | grep -v "LOOPBACK" | grep -v virbr | awk '{print $2}' | sed 's/://g'`
}
#Method removes all BBB Virtual Webcam Backgrounds (except the blur thumbnail)
removeAllVBackgrounds() {
HTML5_CONFIG=/usr/share/meteor/bundle/programs/server/assets/app/config/settings.yml
cat /usr/share/meteor/bundle/programs/web.browser/program.json | jq '.manifest|=map(select( (.path|contains("virtual-backgrounds")) and (.path|contains("blur.jpg")|not) |not))' | sponge /usr/share/meteor/bundle/programs/web.browser/program.json >/dev/null
yq d -i $HTML5_CONFIG public.virtualBackgrounds.fileNames
}
#Adds a new Virtual Background image. Paramter: full path to background image
# If a file thumbnails/<filename> exists in the original location this thumbnail is used. Otherwise a scaled down image of the original is made
addVBackground() {
PROGRAMJSON=/usr/share/meteor/bundle/programs/web.browser/program.json
if [ ! -f $1 ]; then
echo "Could not find file $1 - not adding as Virtual Background"
return 1
fi
FILENAME=$(basename $1)
DIRECTORY=$(dirname $1)
HTML5_CONFIG=/usr/share/meteor/bundle/programs/server/assets/app/config/settings.yml
#Copy Files
cp $1 /usr/share/meteor/bundle/programs/web.browser/app/resources/images/virtual-backgrounds
if [ -f $DIRECTORY/thumbnails/$FILENAME ]; then
cp $DIRECTORY/thumbnails/$FILENAME /usr/share/meteor/bundle/programs/web.browser/app/resources/images/virtual-backgrounds/thumbnails
else
convert $1 -scale 50 /usr/share/meteor/bundle/programs/web.browser/app/resources/images/virtual-backgrounds/thumbnails/$FILENAME
fi
#Get SHA-1 Checksums
CHKSUM=$(sha1sum $1|cut -d" " -f1)
CHKSUM_TN=$(sha1sum /usr/share/meteor/bundle/programs/web.browser/app/resources/images/virtual-backgrounds/thumbnails/$FILENAME|cut -d" " -f1)
#Get File Sizes
SIZE=$(stat --printf="%s" $1)
SIZE_TN=$(stat --printf="%s" /usr/share/meteor/bundle/programs/web.browser/app/resources/images/virtual-backgrounds/thumbnails/$FILENAME)
#Generate JSON-Snippet to add to program.json
JSON="{ \"path\" : \"app/resources/images/virtual-backgrounds/$FILENAME\", \"where\" : \"client\", \"type\" : \"asset\", \"cacheable\": false, \"url\": \"/resources/images/virtual-backgrounds/$FILENAME\", \"size\": \"$SIZE\", \"hash\": \"$CHKSUM\", \"sri\": null }"
JSON_TN="{ \"path\" : \"app/resources/images/virtual-backgrounds/thumbnails/$FILENAME\", \"where\" : \"client\", \"type\" : \"asset\", \"cacheable\": false, \"url\": \"/resources/images/virtual-backgrounds/thumbnails/$FILENAME\", \"size\": \"$SIZE_TN\", \"hash\": \"$CHKSUM_TN\", \"sri\": null }"
#Append Metadata to program.json
cat $PROGRAMJSON |jq ".manifest += [$JSON] + [$JSON_TN]" |sponge $PROGRAMJSON
yq w -i $HTML5_CONFIG public.virtualBackgrounds.fileNames[+] "$FILENAME"
}