-
Notifications
You must be signed in to change notification settings - Fork 4
analyse_image_names
-
Platz sparen im Dateisystem der FritzBox
- Vorwort und Motivation
- Bestandsaufnahme: Wo stecken die Platzfresser?
- Weitere Spartricks
- Schlußwort
Dieses How-To ist nicht besonders wichtig, eher ein Abfallprodukt meines Versuchs, mal herauszufinden, wie weit man kommt, wenn zur Manipulation von Zeichenketten (Strings) nicht ständig externe Werkzeuge wie grep, sed, awk oder gar Perl oder Python aufruft und somit Subprozesse erzeugt, sondern man sich innerhalb der von der Bash zur Verfügung gestellten Kommandos bewegt. Nebenbei macht mein Code-Schnipsel auch noch etwas ansatzweise Nützliches, nämlich aus Dateinamen von Firmware-Images Informationen über Hardware, Firmware-Version u.a. abzuleiten.
Wer sich schon mit Mühe an die Syntax von sed & Co. mit ihren Regulären Ausdrücken gewöhnen mußte und von Parameter-Expansion und Globbing innerhalb der Shell - ich benutze Bash, weil das unser Standard in Freetz ist - noch wenig gehört hat, möchte sich vielleicht einlesen unter:
- Parameter-Expansion
- Muster(erkennung)
- erweiterte Mustererkennung mit Shell-Option "extglob"
- Prüfen und Setzen von Shell-Optionen mit "shopt"
Jetzt aber direkt zum Skript-Code:
#!/bin/bash
analyse_image_name()
{
# Basic mode
local name
local product
local version
local fw_variant
# Verbose mode
local oem
local model
local model_no
local v_major
local v_minor
local v_labor
local annex
local language
# Helpers
local is_extglob
local verbose
[ "$1" == "-v" ] && shift && verbose=y
# Activate extended globbing if necessary (usually already active)
shopt -q extglob && is_extglob=y || shopt -s extglob
# ---------------------------------------------------------------
# Step 1: clean up file name
# ---------------------------------------------------------------
# General
name="$(basename "$1")"
name=${name%.image*}
# AVM
name=${name/[Ff][Rr][Ii][Tt][Zz]./FRITZ!}
name=${name/box/Box}
name=${name/fon/Fon}
name=${name/wlan/WLAN}
name=${name/_sl_/_SL_}
name=${name/_Labor/.Labor}
name=${name/annexa/AnnexA}
name=${name/annexb/AnnexB}
# Deutsche Telekom (ex T-Home, T-Com)
name=${name#fw_}
name=${name/V_v_/V.}
name=${name/V_v/V.}
name=${name/_W_/_W}
# ---------------------------------------------------------------
# Step 2: split into logical parts
# ---------------------------------------------------------------
product=${name%%.+([0-9]).+([0-9]).+([0-9])?(-+([0-9]))}
version=${name##$product.}
name=$product
product=${product%%.*}
fw_variant=${name##$product?(.)}
product=${product//_/ }
# Determine more detailed parameters for verbose mode
if [ "$verbose" ]; then
[ "$product" == "${product#FRITZ!}" ] && oem="Telekom" || oem="AVM"
model=${product%%?(W)+([0-9])*}
model_no=${product##$model}
v_major=${version%%.*}
v_minor=${version##$v_major.}
v_minor=${v_minor%%-*}
v_labor=${version##*$v_minor?(-)}
[ "$fw_variant" == "${fw_variant/AnnexA/}" ] && annex=B || annex=A
language=${fw_variant/@(Annex?|Labor)?(.)/}
language=${language:-de}
fi
# Reset extended globbing to previous state
[ "$is_extglob" ] || shopt -u extglob
# ---------------------------------------------------------------
# Step 3: print result
# ---------------------------------------------------------------
if [ ! "$verbose" ]; then
printf "%-30s %-15s %-22s\n" "$product" "$version" "$fw_variant"
return
fi
echo "Firmware image: $(basename "$1")"
echo "Producer/OEM: $oem"
echo "Model: $model"
echo "Model no.: $model_no"
echo "Version: $version"
echo "Version major: $v_major"
echo "Version minor: $v_minor"
echo "Version labor: $v_labor"
echo "DSL annex: $annex"
echo "Language: $language"
}
# Loop over Freetz firmware image names
for img in $(sed -nr "s/^[^#]*[\"']([^\"']+\.image)[\"'].*$/\1/p" Config.in | sort | uniq); do
# Print raw image names
echo "$img"
done
# Loop over Freetz firmware image names
for img in $(sed -nr "s/^[^#]*[\"']([^\"']+\.image)[\"'].*$/\1/p" Config.in | sort | uniq); do
# Print basic info in tabular layout
analyse_image_name "$img"
done
# Loop over Freetz firmware image names
for img in $(sed -nr "s/^[^#]*[\"']([^\"']+\.image)[\"'].*$/\1/p" Config.in | sort | uniq); do
# Print extended information in vertical layout
analyse_image_name -v "$img"
echo -e "\n-----------------------------------------------------------------------------\n"
done
So sehen aktuell die Firmware-Namen aus, welche sich in der Config.in befinden:
FRITZ.Box_2170.51.04.57.image
FRITZ.Box_6840_LTE.105.05.09.image
FRITZ.Box_7330.107.05.08.image
fritz.box_fon.06.04.33.image
fritz.box_fon_5010.annexa.48.04.43.image
fritz.box_fon_5050.12.04.31.image
FRITZ.Box_Fon_5124.AnnexA.en.57.04.76.image
FRITZ.Box_Fon_5124.AnnexB.en.56.04.76.image
FRITZ.Box_Fon_5140.AnnexB.43.04.67.image
fritz.box_fon.annexa.en.06.04.49.image
fritz.box_fon.en.06.04.49.image
fritz.box_fon_wlan.08.04.34.image
fritz.box_fon_wlan_7050.14.04.33.image
FRITZ.Box_Fon_WLAN_7112.87.04.87.image
FRITZ.Box_Fon_WLAN_7113.60.04.68.image
FRITZ.Box_Fon_WLAN_7113.AnnexA.de-en-es-it-fr.90.04.84.image
FRITZ.Box_Fon_WLAN_7140.AnnexA.39.04.76.image
FRITZ.Box_Fon_WLAN_7140.AnnexA.en.39.04.67.image
fritz.box_fon_wlan_7140.annexb.30.04.33.image
FRITZ.Box_Fon_WLAN_7140.AnnexB.en.30.04.67.image
fritz.box_fon_wlan_7141.40.04.37.image
FRITZ.Box_Fon_WLAN_7141.40.04.76.image
FRITZ.Box_Fon_WLAN_7170.29.04.87.image
FRITZ.Box_Fon_WLAN_7170.AnnexA.58.04.76.image
FRITZ.Box_Fon_WLAN_7170.AnnexA.en.58.04.84.image
FRITZ.Box_Fon_WLAN_7170.AnnexB.en.29.04.82.image
FRITZ.Box_Fon_WLAN_7240.73.05.05.image
FRITZ.Box_Fon_WLAN_7270_16.en-de-es-it-fr.54.05.06.image
FRITZ.Box_Fon_WLAN_7270_v1.54.04.88.image
FRITZ.Box_Fon_WLAN_7270_v2.54.05.05.image
FRITZ.Box_Fon_WLAN_7270_v2.en-de-es-it-fr.54.04.90.image
FRITZ.Box_Fon_WLAN_7270_v2_Labor.54.05.09-21499.image
FRITZ.Box_Fon_WLAN_7270_v3.74.05.05.image
FRITZ.Box_Fon_WLAN_7270_v3.en-de-es-it-fr.74.05.06.image
FRITZ.Box_Fon_WLAN_7270_v3_Labor.74.05.09-21499.image
FRITZ.Box_Fon_WLAN_7320.100.04.89.image
FRITZ.Box_Fon_WLAN_7340.en-de-es-it-fr.99.05.05.image
FRITZ.Box_Fon_WLAN_7390.84.05.05.image
FRITZ.Box_Fon_WLAN_7390.en-de-es-it-fr.84.05.06.image
FRITZ.Box_Fon_WLAN_7390_Labor.84.05.09-21499.image
FRITZ.Box_Fon_WLAN_7570_vDSL.en-de-fr.75.04.91.image
FRITZ.Box_Fon_WLAN.AnnexA.en.08.04.49.image
FRITZ.Box_Fon_WLAN.AnnexB.en.08.04.49.image
fritz.box_sl_wlan.09.04.34.image
fritz.box_wlan_3030.21.04.34.image
fritz.box_wlan_3130.44.04.34.image
fritz.box_wlan_3131.50.04.57.image
fritz.box_wlan_3170.49.04.58.image
fritz.box_wlan_3270.67.05.05.image
fritz.box_wlan_3270_v3.96.05.05.image
fritz.box_wlan_3370.103.05.08.image
fritz.fon_7150.annexb.38.04.71.image
fw_Speedport_W501V_v_28.04.38.image
fw_Speedport_W701V_v33.04.57.image
fw_Speedport_W900V_v34.04.57.image
Sinus_W_500V.27.04.27.image
Speedport_W_920V.AnnexB.65.04.78.image
Das ist nicht besonders übersichtlich und außerdem im Detail sehr uneinheitlich. Geht das nicht irgendwie hübscher?!
Das Ergebnis sieht für Fall 1 (grundlegende Informationen, tabellarisches Layout) so aus:
FRITZ!Box 2170 51.04.57
FRITZ!Box 6840 LTE 105.05.09
FRITZ!Box 7330 107.05.08
FRITZ!Box Fon 06.04.33
FRITZ!Box Fon 5010 48.04.43 AnnexA
FRITZ!Box Fon 5050 12.04.31
FRITZ!Box Fon 5124 57.04.76 AnnexA.en
FRITZ!Box Fon 5124 56.04.76 AnnexB.en
FRITZ!Box Fon 5140 43.04.67 AnnexB
FRITZ!Box Fon 06.04.49 AnnexA.en
FRITZ!Box Fon 06.04.49 en
FRITZ!Box Fon WLAN 08.04.34
FRITZ!Box Fon WLAN 7050 14.04.33
FRITZ!Box Fon WLAN 7112 87.04.87
FRITZ!Box Fon WLAN 7113 60.04.68
FRITZ!Box Fon WLAN 7113 90.04.84 AnnexA.de-en-es-it-fr
FRITZ!Box Fon WLAN 7140 39.04.76 AnnexA
FRITZ!Box Fon WLAN 7140 39.04.67 AnnexA.en
FRITZ!Box Fon WLAN 7140 30.04.33 AnnexB
FRITZ!Box Fon WLAN 7140 30.04.67 AnnexB.en
FRITZ!Box Fon WLAN 7141 40.04.37
FRITZ!Box Fon WLAN 7141 40.04.76
FRITZ!Box Fon WLAN 7170 29.04.87
FRITZ!Box Fon WLAN 7170 58.04.76 AnnexA
FRITZ!Box Fon WLAN 7170 58.04.84 AnnexA.en
FRITZ!Box Fon WLAN 7170 29.04.82 AnnexB.en
FRITZ!Box Fon WLAN 7240 73.05.05
FRITZ!Box Fon WLAN 7270 16 54.05.06 en-de-es-it-fr
FRITZ!Box Fon WLAN 7270 v1 54.04.88
FRITZ!Box Fon WLAN 7270 v2 54.05.05
FRITZ!Box Fon WLAN 7270 v2 54.04.90 en-de-es-it-fr
FRITZ!Box Fon WLAN 7270 v2 54.05.09-21499 Labor
FRITZ!Box Fon WLAN 7270 v3 74.05.05
FRITZ!Box Fon WLAN 7270 v3 74.05.06 en-de-es-it-fr
FRITZ!Box Fon WLAN 7270 v3 74.05.09-21499 Labor
FRITZ!Box Fon WLAN 7320 100.04.89
FRITZ!Box Fon WLAN 7340 99.05.05 en-de-es-it-fr
FRITZ!Box Fon WLAN 7390 84.05.05
FRITZ!Box Fon WLAN 7390 84.05.06 en-de-es-it-fr
FRITZ!Box Fon WLAN 7390 84.05.09-21499 Labor
FRITZ!Box Fon WLAN 7570 vDSL 75.04.91 en-de-fr
FRITZ!Box Fon WLAN 08.04.49 AnnexA.en
FRITZ!Box Fon WLAN 08.04.49 AnnexB.en
FRITZ!Box SL WLAN 09.04.34
FRITZ!Box WLAN 3030 21.04.34
FRITZ!Box WLAN 3130 44.04.34
FRITZ!Box WLAN 3131 50.04.57
FRITZ!Box WLAN 3170 49.04.58
FRITZ!Box WLAN 3270 67.05.05
FRITZ!Box WLAN 3270 v3 96.05.05
FRITZ!Box WLAN 3370 103.05.08
FRITZ!Fon 7150 38.04.71 AnnexB
Speedport W501V 28.04.38
Speedport W701V 33.04.57
Speedport W900V 34.04.57
Sinus W500V 27.04.27
Speedport W920V 65.04.78 AnnexB
Im zweiten Fall ist die Ausgabe wesentlich länger, ich gebe hier also nur exemplarische Ausschnitte wieder:
Firmware image: FRITZ.Box_6840_LTE.105.05.09.image
Producer/OEM: AVM
Model: FRITZ!Box
Model no.: 6840 LTE
Version: 105.05.09
Version major: 105
Version minor: 05.09
Version labor:
DSL annex: B
Language: de
-----------------------------------------------------------------------------
Firmware image: FRITZ.Box_Fon_WLAN_7113.AnnexA.de-en-es-it-fr.90.04.84.image
Producer/OEM: AVM
Model: FRITZ!Box Fon WLAN
Model no.: 7113
Version: 90.04.84
Version major: 90
Version minor: 04.84
Version labor:
DSL annex: A
Language: de-en-es-it-fr
-----------------------------------------------------------------------------
Firmware image: FRITZ.Box_Fon_WLAN_7270_v2_Labor.54.05.09-21499.image
Producer/OEM: AVM
Model: FRITZ!Box Fon WLAN
Model no.: 7270 v2
Version: 54.05.09-21499
Version major: 54
Version minor: 05.09
Version labor: 21499
DSL annex: B
Language: de
-----------------------------------------------------------------------------
Firmware image: fw_Speedport_W701V_v33.04.57.image
Producer/OEM: Telekom
Model: Speedport
Model no.: W701V
Version: 33.04.57
Version major: 33
Version minor: 04.57
Version labor:
DSL annex: B
Language: de
Viel Spaß beim Herumspielen.