Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit 6ff50db

Browse files
committed
Multithreading
1 parent a505a49 commit 6ff50db

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

FireMotD

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# Script name: FireMotD
3-
# Version: v11.01.190105
3+
# Version: v11.02.190106
44
# Created on: 10/02/2014
55
# Author: Willem D'Haese
66
# Contributors: Thomas Dietrich, Dmitry Romanenko
@@ -654,17 +654,38 @@ v\"."
654654
}
655655

656656
LoadData () {
657-
WriteLog Verbose Info "Logon data refresh start"
658-
if [[ -s "$ExportFile" ]] ; then
659-
while read -r val ; do
660-
WriteLog Verbose Info "Exploring ${val}"
661-
$(Explore${val})
662-
done < <(jq -r 'to_entries[] | select(.value.Generated == "@logon") | .key' $ExportFile)
663-
else
664-
WriteLog Output Info "No FireMotD ExportFile detected. Please generate with \"sudo .\/FireMotD -S\""
665-
exit 2
657+
WriteLog Verbose Info "Logon data refresh start"
658+
if [[ -s "$ExportFile" ]] ; then
659+
i=0
660+
if [[ "$MultiThreaded" == "1" ]] ; then
661+
Procs=$(nproc --all)
662+
let Procs++
663+
fi
664+
while read -r val ; do
665+
if [[ "$MultiThreaded" == "1" ]] ; then
666+
WriteLog Verbose Info "Exploring ${val} in background job $i"
667+
$(Explore${val}) &
668+
RunningJobs=$(jobs -r | wc -l | tr -d " ")
669+
WriteLog Verbose Info "$RunningJobs jobs running."
670+
while [ $(jobs -r | wc -l | tr -d " ") -gt $Procs ] ; do
671+
WriteLog Debug Info "More then $Procs jobs running. Waiting for completion"
672+
sleep 0.1
673+
done
674+
let i++
675+
else
676+
WriteLog Verbose Info "Exploring ${val}"
677+
$(Explore${val})
678+
fi
679+
done < <(jq -r 'to_entries[] | select(.value.Generated == "@logon") | .key' $ExportFile)
680+
if [[ "$MultiThreaded" == "1" ]] ; then
681+
WriteLog Verbose Info "Waiting for all background explorers to finish"
682+
wait
666683
fi
667-
WriteLog Verbose Info "Logon Data refresh for end"
684+
else
685+
WriteLog Output Info "No FireMotD ExportFile detected. Please generate with \"sudo .\/FireMotD -S\""
686+
exit 2
687+
fi
688+
WriteLog Verbose Info "Logon Data refresh for end"
668689
}
669690

670691
StartOriginalBlue () {
@@ -1105,6 +1126,9 @@ Options:
11051126
-C | --colortest Prints color test to screen
11061127
-M | --colormap Prints color test including color numbers
11071128
-S | --save Saves data to /usr/share/firemotd/data/FireMotD.json
1129+
-R | --RenderTime Time to render FireMotD. Values van be cache (default) or live
1130+
-G | --GenerateCache Generates cache for give theme. Values can be 'all' or a theme name
1131+
-MT | --MultiThreaded Enable multithreaded Exploring. Experimental feature!
11081132
-HV | --hideversion Hides version number (legacy themes)
11091133
-sru | --skiprepoupdate Skip repository package update (apt only)
11101134
@@ -1810,7 +1834,7 @@ InitializeArgs () {
18101834
Action="help" ; shift ;;
18111835
-P|--Presentation)
18121836
Action="present" ; shift ;;
1813-
-G|--GenerateCaches)
1837+
-G|--GenerateCache)
18141838
shift ; Action="caches" ; Theme="$1" ; shift ;;
18151839
-I|--install|--Install)
18161840
Action="install" ; shift ;;
@@ -1834,6 +1858,8 @@ InitializeArgs () {
18341858
shift ; Action="template" ; Template="$1" ; shift ;;
18351859
-R|--RenderTime)
18361860
shift ; RenderTime="$1" ; shift ;;
1861+
-MT|--MultiThreaded)
1862+
MultiThreaded=1 ; shift ;;
18371863
-*) echo "You specified a non-existant option: $1" ; exit 2 ;;
18381864
*) break ;;
18391865
esac

0 commit comments

Comments
 (0)