-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpuman-cli_v2.7.sh
592 lines (495 loc) · 23.6 KB
/
cpuman-cli_v2.7.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
#!/bin/bash
# name : cpuman-cliCPUCoreTmpAvg
# desciption : manage cpu cores and powerstatus of cpu
# autor : speefak ( [email protected] )
# licence : (CC) BY-NC-SA
# version : 2.7
# notice :
# infosource : https://askubuntu.com/questions/1185826/how-do-i-disable-a-specific-cpu-core-at-boot
# https://variwiki.com/index.php?title=CPU_freq_and_num_of_cores
#------------------------------------------------------------------------------------------------------------
############################################################################################################
####################################### define global variables ########################################
############################################################################################################
#------------------------------------------------------------------------------------------------------------
RequiredPackets="bash sed linux-cpupower bc" # libbpf-tools cpufrequtils
MailAddress=root
Timestamp=$(date "+%F %H:%M:%S")
# fixed vars
CPUModelName=$(cat /proc/cpuinfo | grep "model name" | uniq | awk -F ": " '{printf $2}' | awk -F "@" '{printf $1}')
MaxCPUs=$(($(cat /sys/devices/system/cpu/present | cut -d "-" -f2)+1))
CPUCoreTempHigh=$(sensors | grep "Package id 0:" | awk -F "[+.]" '{printf $4}')
CPUCoreTempCrit=$(sensors | grep "Package id 0:" | awk -F "[+.]" '{printf $6}')
Version=$(cat $(readlink -f $(which $0)) | grep "# version" | head -n1 | awk -F ":" '{print $2}' | sed 's/ //g')
ScriptFile=$(readlink -f $(which $0))
ScriptName=$(basename $ScriptFile)
# updateable vars
get_cpu_vars () {
Hyperthreading=$(cat /sys/devices/system/cpu/smt/control 2>/dev/null)
CPUScalingDriver=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver 2>/dev/null)
#CPUScalingDriver=$(cpufreq-info -d)
GovernorStatus=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 2>/dev/null)
CPUCoreTemps=$(sensors | grep Core | cut -d "+" -f2 | cut -d "." -f1)
CPUCoreCountPhysical=$(echo "$CPUCoreTemps" | wc -l)
CPUCoreCountLogical=$(grep ^processor /proc/cpuinfo | wc -l)
CPUCoreTmpMax=$(sensors | grep "Package id 0:" | awk -F "[+.]" '{printf $2}')
CPUCoreTmpAvg=$(($(($(echo "$CPUCoreTemps" | tr "\n" "+" | sed 's/+$//'))) / $CPUCoreCountPhysical ))
CPUMaxFreq=$(lscpu | grep "CPU max MHz" | awk '{printf $4}' | cut -d "," -f1)
CPUMinFreq=$(lscpu | grep "CPU min MHz" | awk '{printf $4}' | cut -d "," -f1)
}
#------------------------------------------------------------------------------------------------------------
############################################################################################################
######################################## set vars from options ##########################################
############################################################################################################
#------------------------------------------------------------------------------------------------------------
OptionVarList="
ShowSystemSpecs;-ss
DisableCore;-dc
DisableCPU;-dp
DisableHT;-dh
DisableAll;-da
EnableCore;-ec
EnableCPU;-ep
EnableHT;-eh
EnableAll;-ea
TempCheck;-tc
HelpDialog;-h
Monochrome;-m
ScriptInformation;-i
CheckForRequiredPackages;-cfrp
CPUInfo;-cpi
CPUfreq;-cpf
"
# set entered vars from optionvarlist
OptionAllocator=" " # for option seperator "=" use cut -d "="
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for InputOption in $(echo " $@" | sed 's/ -/\n-/g') ; do
for VarNameVarValue in $OptionVarList ; do
VarName=$(echo "$VarNameVarValue" | cut -d ";" -f1)
VarValue=$(echo "$VarNameVarValue" | cut -d ";" -f2)
# if [[ -n $(echo " $InputOption" | grep " $VarValue" 2>/dev/null) ]]; then
if [[ $InputOption == "$VarValue" ]]; then
eval $(echo "$VarName"='$InputOption') # if [[ -n Option1 ]]; then echo "Option1 set";fi
#eval $(echo "$VarName"="true")
elif [[ $(echo $InputOption | cut -d "$OptionAllocator" -f1) == "$VarValue" ]]; then
eval $(echo "$VarName"='$(echo $InputOption | cut -d "$OptionAllocator" -f 2-10)')
fi
done
done
IFS=$SAVEIFS
#------------------------------------------------------------------------------------------------------------
############################################################################################################
########################################### define functions ###########################################
############################################################################################################
#------------------------------------------------------------------------------------------------------------
load_color_codes () {
# parse required colours for echo/printf usage: printf "%s\n" "Text in ${Red}red${Reset}, white and ${Blue}blue${Reset}."
Black='\033[0;30m' && DGray='\033[1;30m'
LRed='\033[0;31m' && Red='\033[1;31m'
LGreen='\033[0;32m' && Green='\033[1;32m'
LYellow='\033[0;33m' && Yellow='\033[1;33m'
LBlue='\033[0;34m' && Blue='\033[1;34m'
LPurple='\033[0;35m' && Purple='\033[1;35m'
LCyan='\033[0;36m' && Cyan='\033[1;36m'
LLGrey='\033[0;37m' && White='\033[1;37m'
Reset='\033[0m'
BG='\033[47m'
FG='\033[0;30m'
# parse required colours for sed usage: sed 's/status=sent/'${Green}'status=sent'${Reset}'/g' |\
if [[ $1 == sed ]]; then
for ColorCode in $(cat $0 | sed -n '/^load_color_codes/,/FG/p' | tr "&" "\n" | grep "='"); do
eval $(sed 's|\\|\\\\|g' <<< $ColorCode) # sed parser '\033[1;31m' => '\\033[1;31m'
done
fi
}
#------------------------------------------------------------------------------------------------------------
usage() {
printf "\n"
printf " Usage: $(basename $0) <options> "
printf "\n"
printf " -ss <0.1-999> => show cpu specifications ( <seconds> for loop output )\n"
printf " -[e|d]c <1,2-3,4> => (e)nable (d)isable core \n"
printf " -[e|d]p <1,4-5,8> => (e)nable (d)isable processor \n"
printf " -[e|d]h => (e)nable (d)isable hyperthreading \n"
printf " -[e|d]a => (e)nable (d)isable all CPUs and hyperthreading\n"
printf " -tc <temp threshold> => cpu (t)emperature (c)heck ( send mail if threashold temp reached ) \n"
printf " -h => help dialog \n"
printf " -m => monochrome output \n"
printf " -i => show script information \n"
printf " -cfrp => check for required packets \n"
printf " -cpi => use cpuinfo output for freqenucy calculating"
printf "\n${LRed} $1 ${Reset}\n"
printf "\n"
exit
}
#------------------------------------------------------------------------------------------------------------
script_information () {
printf "\n"
printf " Scriptname: $ScriptName\n"
printf " Version: $Version \n"
printf " Location: $(pwd)/$ScriptName\n"
printf " Filesize: $(ls -lh $0 | cut -d " " -f5)\n"
printf "\n"
exit 0
}
#------------------------------------------------------------------------------------------------------------
check_for_required_packages () {
InstalledPacketList=$(dpkg -l | grep ii | awk '{print $2}' | cut -d ":" -f1)
for Packet in $RequiredPackets ; do
if [[ -z $(grep -w "$Packet" <<< $InstalledPacketList) ]]; then
MissingPackets=$(echo $MissingPackets $Packet)
fi
done
# print status message / install dialog
if [[ -n $MissingPackets ]]; then
printf "missing packets: \e[0;31m $MissingPackets\e[0m\n"$(tput sgr0)
read -e -p "install required packets ? (Y/N) " -i "Y" InstallMissingPackets
if [[ $InstallMissingPackets == [Yy] ]]; then
# install software packets
sudo apt update
sudo apt install -y $MissingPackets
if [[ ! $? == 0 ]]; then
exit
fi
else
printf "programm error: $LRed missing packets : $MissingPackets $Reset\n\n"$(tput sgr0)
exit 1
fi
else
printf "$LGreen all required packets detected$Reset\n"
fi
}
#--------------------------------------------------------------------------------------------------------------
print_parser () {
if [[ $(grep SeperatorLine <<< $@) ]]; then
printf "+----------------------------------------------------------+\n"
elif [[ $PrintParser == "info_line" ]]; then
printf "| %-97s | \n" "$1"
elif [[ $PrintParser == "print_CPU_specs" ]]; then
printf "| %-15s %-2s %-35s %-1s | \n" "$1" "$2" "$3" "$4"
elif [[ $PrintParser == "print_CPU_data" ]]; then
printf "| %-8s %-6s %-8s %-14s %10s %-5s | \n" "$1" "$2" "$3" "$4" "$5" "$6"
elif [[ $PrintParser == "print_CPU_data_info_line" ]]; then
printf "| %-8s %-6s %-8s %-14s %10s %-5s | \n" "$1" "$2" "$3" "$4" "$5" "$6"
fi
}
#------------------------------------------------------------------------------------------------------------
print_colored_output () {
# print and parse output
printf "$(echo "$1\n\n" |\
# print hyperthreading statusprint_CPU_data
sed 's/Hyperthreading => notsupported/Hyperthreading =>\'$LRed' not supported '\\$Reset'/g' |\
sed 's/Hyperthreading => on/Hyperthreading =>\'$LGreen' on'\\$Reset'/g' |\
sed 's/Hyperthreading => off/Hyperthreading =>\'$LRed' off'\\$Reset'/g' |\
# parse online/offline string
sed 's/online/\'$LGreen'online'\\$Reset'/g' |\
sed 's/offline/\'$LRed'offline'\\$Reset'/g' |\
# parse enabled/disabled string
sed 's/enabled/\'$LGreen'enabled'\\$Reset'/g' |\
sed 's/disabled/\'$LRed'disabled'\\$Reset'/g' |\
# print another var
sed 's/pattern/new/g' )"
}
#------------------------------------------------------------------------------------------------------------
print_CPU_specs () {
# update cpu vars
get_cpu_vars
PrintParser="print_CPU_specs"
print_parser SeperatorLine
print_parser "CPU Model" "=>" "$CPUModelName"
print_parser "CPU cores" "=>" "$CPUCoreCountPhysical"
print_parser "CPU processors" "=>" "$CPUCoreCountLogical"
print_parser "Hyperthreading" "=>" "$Hyperthreading"
print_parser "Governor driver" "=>" "$CPUScalingDriver"
print_parser "CPU freq max" "=>" "$CPUMaxFreq MHz"
print_parser "CPU freq min" "=>" "$CPUMinFreq MHz"
print_parser "CPU temp actual" "=>" "$CPUCoreTmpMax C | $CPUCoreTmpAvg C (core peak|avg)"
print_parser "CPU temp high" "=>" "$CPUCoreTempHigh C"
print_parser "CPU temp crit" "=>" "$CPUCoreTempCrit C"
# set print parser
PrintParser="print_CPU_data"
print_parser SeperatorLine
# get cpu status
CoreNumber="-1"
for i in /sys/devices/system/cpu/cpu[0-99]*; do
# calculate CPU/core count
CPUNumber=$(echo $i | awk -F "/cpu/cpu" '{printf $2}' | tr -d "/")
GovernorStatus=$(cat $i/cpufreq/scaling_governor 2>/dev/null)
CPUFreqActual="$(echo $(cat $i/cpufreq/scaling_cur_freq 2>/dev/null)/1000 | bc 2>/dev/null ) "
if [[ -z $CPUFreqActual ]] || [[ -n $CPUInfo ]]; then
CPUFreqActual="$(echo $(cat $i/cpufreq/cpuinfo_cur_freq 2>/dev/null)/1000 | bc 2>/dev/null ) "
fi
#CPUFreqActual=$(cat /proc/cpuinfo | grep -A10 "processor.*$CPUNumber" | grep "cpu MHz" | grep -o -P '(?<=: ).*(?=....)') # more accurate value
# substitute offline cpu vars
if [[ -z $( echo $CPUFreqActual | grep [[:digit:]] ) ]]; then
GovernorStatus="--------"
CPUFreqActual="---- "
fi
# get all CPU freqs for averrage freq calculation
CPUFreqSum=$(echo $CPUFreqSum $CPUFreqActual)
# check core and cpu count
if [[ $Hyperthreading == "notsupported" ]]; then
CoreNumber=$CPUNumber
else
CoreNumber=$(($CoreNumber+1))
if [[ $CoreNumber == $(($MaxCPUs/2)) ]]; then
CoreNumber=0
fi
fi
# check CPU online status
if [[ $CPUNumber == 0 ]]; then
CPUStatus=" online"
else
CPUStatus=$(cat $i/online)
fi
CPUStatus=${CPUStatus/1/ online}
CPUStatus=${CPUStatus/0/offline}
# print cpu details
print_parser "$CPUStatus" "CPU $CPUNumber" "Core $CoreNumber" "$GovernorStatus" "$CPUFreqActual MHz"
done
# calc print average freqency
CPUFreqAvg=$(($(echo "($CPUFreqSum)/$CPUCoreCountLogical" | tr " -" "+0" ) ))
print_parser SeperatorLine
PrintParser=print_CPU_data_info_line
print_parser " " " " " " " average" "$CPUFreqAvg MHz"
print_parser SeperatorLine
}
#------------------------------------------------------------------------------------------------------------
temp_check () {
# check for threshold input / if temp is not specified use CPU HighTemp as default var
if [[ -z $(echo $TempCheck | sed 's/\-tc//g') ]] ; then
printf " no threshold temperature specified, using CPU high temperature value ( $CPUCoreTempHigh°C )\n"
TempCheck=$CPUCoreTempHigh
else
OverrideCPUCoreTempHigh="(manually set)"
fi
# check threshold for email warning
if [[ $CPUCoreTmpAvg -gt $TempCheck ]] ; then
MailSubjectLine="WARNING! ($(hostname)): CPU core temperature high: $CPUCoreTmpAvg"°C" | $TempCheck"°C" (actual|threshold) "
MailContent="\n CPU core temperature threshold reached ($(hostname)) \n
actual: $CPUCoreTmpAvg"°C"
threshold: $TempCheck"°C" $OverrideCPUCoreTempHigh
cpu high: $CPUCoreTempHigh"°C"
cpu critical: $CPUCoreTempCrit"°C"
"
printf " $MailSubjectLine\n"
printf " Notification send via Mail ( $MailAddress )\n"
#TODO # send mail via $MailAddress
# printf \n CPU core temperature threshold reached (speenux) \n actual: 43°C threshold: 20°C (manually set) cpu high: 80°C cpu critical: 100°C | sed 's/^[ \t]*/ /' | mail -a Content-Type: text/plain -s WARNING! (speenux): CPU core temperature high: 43°C | 20°C (actual|threshold) root
printf "$MailContent" | sed 's/^[ \t]*/ /' | mail -a "Content-Type: text/plain" -s "$MailSubjectLine" $MailAddress
else
printf " Current CPU core temperature: ($CPUCoreTmpAvg"°C") | threshold ($TempCheck"°C") unreached. \n"
fi
}
#------------------------------------------------------------------------------------------------------------
get_CPU_configuration () {
# update cpu vars
get_cpu_vars
# print cpu status entire
echo " MaxCPUs=$MaxCPUs"
echo " Hyperthreading=$Hyperthreading"
# printf cpu status each processor
CoreNumber="-1"
for i in /sys/devices/system/cpu/cpu[0-99]*; do
# calculate CPU/core count / check for hyperthreadding support
CPUNumber=$(echo $i | awk -F "/cpu/cpu" '{printf $2}' | tr -d "/")
CPUFreq=$(cat /proc/cpuinfo | grep -A10 "processor.*$CPUNumber" | grep "cpu MHz" | grep -o -P '(?<=: ).*(?=....)')
GovernorStatus=$(cat $i/cpufreq/scaling_governor 2>/dev/null)
# get working core number
if [[ $Hyperthreading == "notsupported" ]]; then
CoreNumber=$CPUNumber
else
CoreNumber=$(($CoreNumber+1))
if [[ $CoreNumber == $(($MaxCPUs/2)) ]]; then
CoreNumber=0
fi
fi
# print configuration | write function output to var
printf " CPU=$CPUNumber Core=$CoreNumber"
if [[ $CPUNumber == 0 ]]; then
printf " OnlineStatus=1"
else
printf " OnlineStatus=$(cat $i/online)"
fi
printf " $GovernorStatus $CPUFreq"
printf "\n"
done
}
#------------------------------------------------------------------------------------------------------------
processing_core_options () { # usage: processing_core_options (set vars before function execution)
edit_configuration_var () { # usage: edit_configuration_var <e|d> <1|2-3|2-3,4|...>
# processing ProcessingCoreList
for CoreNumber in $2 ;do
# processing input var OnlineStatus
printf " Core $CoreNumber "
if [[ $1 == d ]]; then CoreStatus=0 && printf "disabled \n"
elif [[ $1 == e ]]; then CoreStatus=1 && printf "enabled \n"
fi
# edit systemSpecList
SystemSpecList=$(sed '/Core='$CoreNumber'/s/OnlineStatus=[0-9]/OnlineStatus='$CoreStatus'/' <<< $SystemSpecList )
done
}
# check for mode ( enable ) / calculate processing core numbers
for i in $EnableCore ; do
ProcessingCoreList=$( sed 's/,/ /g' <<< "$i" | tr " " "\n" | grep -v "-"
seq $(sed 's/,/ /g' <<< "$i" | tr " " "\n" | grep "-" | tr "-" " ") 2>/dev/null )
edit_configuration_var "e" "$ProcessingCoreList"
done
# check for mode ( disable ) / calculate processing core numbers
for i in $DisableCore ; do
ProcessingCoreList=$( sed 's/,/ /g' <<< "$i" | tr " " "\n" | grep -v "-"
seq $(sed 's/,/ /g' <<< "$i" | tr " " "\n" | grep "-" | tr "-" " ") 2>/dev/null )
edit_configuration_var "d" "$ProcessingCoreList"
done
}
#------------------------------------------------------------------------------------------------------------
processing_cpu_options () { # usage: processing_cpu_options (set vars before function execution)
edit_configuration_var () { # usage: edit_configuration_var <e|d> <1|2-3|2-3,4|...>
# processing ProcessingCPUList
for CPUNumber in $2 ;do
# auto enable hyperthreading for virtual CPUs
if [[ $1 == e ]] && [[ $CPUNumber -ge "$(($MaxCPUs/2))" ]] && [[ $( grep "Hyperthreading=" <<< "$SystemSpecList" | grep "off") ]] ;then
EnableHT=true && processing_hyperthreading_options
fi
# processing input var OnlineStatus
printf " cpu $CPUNumber "
if [[ $1 == d ]]; then CPUStatus=0 && printf "disabled \n"
elif [[ $1 == e ]]; then CPUStatus=1 && printf "enabled \n"
fi
# edit systemSpecList
SystemSpecList=$(sed '/CPU='$CPUNumber'/s/OnlineStatus=[0-9]/OnlineStatus='$CPUStatus'/' <<< $SystemSpecList )
done
}
# check for mode ( enable ) / calculate processing CPU numbers
for i in $EnableCPU ; do
ProcessingCPUList=$( sed 's/,/ /g' <<< "$i" | tr " " "\n" | grep -v "-"
seq $(sed 's/,/ /g' <<< "$i" | tr " " "\n" | grep "-" | tr "-" " ") 2>/dev/null )
edit_configuration_var "e" "$ProcessingCPUList"
done
# check for mode ( disable ) / calculate processing CPU numbers
for i in $DisableCPU ; do
ProcessingCPUList=$( sed 's/,/ /g' <<< "$i" | tr " " "\n" | grep -v "-"
seq $(sed 's/,/ /g' <<< "$i" | tr " " "\n" | grep "-" | tr "-" " ") 2>/dev/null )
edit_configuration_var "d" "$ProcessingCPUList"
done
}
#------------------------------------------------------------------------------------------------------------
processing_hyperthreading_options () {
# check for hyperthreading support
if [[ -n $(grep "notsupported" /sys/devices/system/cpu/smt/control) ]]; then
usage " hyperthreading not supported by $CPUModelName"
fi
# processing input var
printf " hyperthreading "
if [[ -n $DisableHT ]]; then HTStatus=off && printf "disabled \n"
elif [[ -n $EnableHT ]]; then HTStatus=on && printf "enabled \n"
fi
# edit systemSpecList
SystemSpecList=$(sed 's/Hyperthreading=.*/Hyperthreading='$HTStatus'/' <<< $SystemSpecList)
}
#------------------------------------------------------------------------------------------------------------
write_configuration () {
# write hyperthreading config
HyperthreadingConfig=$(awk -F "Hyperthreading=" '{printf $2}' <<< $SystemSpecList )
echo $HyperthreadingConfig > /sys/devices/system/cpu/smt/control 2> /dev/null
# write individual CPU config
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for i in $( grep "^ CPU" <<< $SystemSpecList) ; do
ProcessingCPUNumber=$(awk -F "CPU=" '{printf $2}' <<< $i | cut -d " " -f1)
OnlineStatus=$(awk -F "OnlineStatus=" '{printf $2}' <<< $i | cut -d " " -f1)
# skip CPU0
if [[ $ProcessingCPUNumber == 0 ]]; then continue ;fi
# write CPU status
echo $OnlineStatus > /sys/devices/system/cpu/cpu$ProcessingCPUNumber/online 2> /dev/null
done
IFS=$SAVEIFS
printf "\n"
print_colored_output "$(print_CPU_specs)"
}
#------------------------------------------------------------------------------------------------------------
############################################################################################################
############################################# start script #############################################
############################################################################################################
#------------------------------------------------------------------------------------------------------------
# check for cronjob execution and cronjob options
CronExecution=
if [ -z $(grep "/" <<< "$(tty)") ]; then
CronExecution=true
Monochrome=true
fi
#------------------------------------------------------------------------------------------------------------
# check for monochrome output
Reset='\033[0m'
if [[ -z $Monochrome ]]; then
load_color_codes
fi
#------------------------------------------------------------------------------------------------------------
# check help dialog
if [[ -n $HelpDialog ]] ; then usage "help dialog" ; fi
#------------------------------------------------------------------------------------------------------------
# check for script information
if [[ -n $ScriptInformation ]]; then script_information ; fi
#------------------------------------------------------------------------------------------------------------
# check for root permission
if [ "$(whoami)" = "root" ]; then echo "";else echo "Are You Root ?";exit 1;fi
#------------------------------------------------------------------------------------------------------------
# check for required package
if [[ -n $CheckForRequiredPackages ]]; then check_for_required_packages; fi
#------------------------------------------------------------------------------------------------------------
# check cpu temperatures and amil if threashold is reached
if [[ -n $TempCheck ]]; then temp_check && exit ; fi
#------------------------------------------------------------------------------------------------------------
# print_system_specs as loop output
if [[ $ShowSystemSpecs == "-ss" ]]; then
print_colored_output "$(print_CPU_specs)"
exit
elif [[ -n $ShowSystemSpecs ]] && [[ -z $(echo $ShowSystemSpecs | tr -d [[:digit:]] | tr -d ".") ]]; then
LoopDelay=$ShowSystemSpecs
clear
tput civis
while [[ -z $Quit ]] ; do
tput cup 0,0
print_colored_output "$(print_CPU_specs)"
printf " press any key to quit \n"
read -s -n 1 -t $LoopDelay Quit
done
tput cnorm
exit
fi
#------------------------------------------------------------------------------------------------------------
# get cpu configuration
SystemSpecList=$(get_CPU_configuration)
#------------------------------------------------------------------------------------------------------------
# enable / disable all
if [[ -n $EnableAll ]]; then
if [[ ! $Hyperthreading == notsupported ]] ;then EnableHT=true && processing_hyperthreading_options ; fi
EnableCPU=$(seq 0 1 $(($MaxCPUs-1)))
elif [[ -n $DisableAll ]]; then
if [[ ! $Hyperthreading == notsupported ]] ;then DisableHT=true && processing_hyperthreading_options ; fi
DisableCPU=$(seq 0 1 $(($MaxCPUs-1)))
fi
#------------------------------------------------------------------------------------------------------------
# configure core and cpu
if [[ -n $DisableHT || $EnableHT ]]; then processing_hyperthreading_options ; fi
if [[ -n $DisableCore || $EnableCore ]]; then processing_core_options ; fi
if [[ -n $DisableCPU || $EnableCPU ]]; then processing_cpu_options ; fi
#------------------------------------------------------------------------------------------------------------
# write cpu configuration when config changed
if [[ -n $( echo $DisableHT $EnableHT $DisableCore $EnableCore $DisableCPU $EnableCPU $EnableAll $DisableAll) ]]; then
write_configuration
fi
#------------------------------------------------------------------------------------------------------------
exit 0
#------------------------------------------------------------------------------------------------------------
############################################################################################################
############################################## changelog ###############################################
############################################################################################################
#------------------------------------------------------------------------------------------------------------
#changelog 2.6 => 2.7 : export get cpu specs to function => fast cpumam-cli script
#changelog 2.5 => 2.6 : code review
#changelog 2.4 => 2.5 : add printparser, code review
#changelog 2.3 => 2.4 : add cpu general specs output / code review
#changelog 2.2 => 2.3 : add cpu load and cpu MHZ to info output
#changelog 2.1 => 2.2 : add cpu_temp_check function / add cpu info MHz output / add loop output function /