+ local repo_file='' repo_data_working='' repo_data_working2='' repo_line=''
+ local apt_file='/etc/apt/sources.list' yum_repo_dir='/etc/yum.repos.d/' yum_conf='/etc/yum.conf'
+ local pacman_conf='/etc/pacman.conf' pacman_repo_dir='/etc/pacman.d/' pisi_dir='/etc/pisi/'
+
+ # apt - debian, buntus
+ if [[ -f $apt_file || -d $apt_file.d ]];then
+ REPO_DATA="$( grep -Esv '(^[[:space:]]*$|^[[:space:]]*#)' $apt_file $apt_file.d/*.list )"
+ REPO_FILE_ID='apt sources'
+ # yum - fedora, redhat, centos, etc
+ elif [[ -d $yum_repo_dir || -f $yum_conf ]];then
+ # older redhats put their yum data in /etc/yum.conf
+ for repo_file in $( ls $yum_repo_dir*.repo $yum_conf 2>/dev/null )
+ do
+ repo_data_working="$( gawk -v repoFile=$repo_file '
+ # construct the string for the print function to work with, file name: data
+ function print_line( fileName, repoId, repoUrl ){
+ print fileName ":" repoId repoUrl
+ }
+ BEGIN {
+ FS="\n"
+ IGNORECASE=1
+ enabledStatus=""
+ repoTitle=""
+ urlData=""
+ }
+ # this is a hack, assuming that each item has these fields listed, we collect the 3
+ # items one by one, then when the url/enabled fields are set, we print it out and
+ # reset the data. Not elegant but it works. Note that if enabled was not present
+ # we assume it is enabled then, and print the line, reset the variables. This will
+ # miss the last item, so it is printed if found in END
+ /^\[.+\]/ {
+ if ( urlData != "" && repoTitle != "" ){
+ print_line( repoFile, repoTitle, urlData )
+ enabledStatus=""
+ urlData=""
+ repoTitle=""
+ }
+ gsub( /\[|\]/, "", $1 ) # strip out the brackets
+ repoTitle = $1 " ~ "
+ }
+ /^(mirrorlist|baseurl)/ {
+ sub( /(mirrorlist|baseurl)=/, "", $1 ) # strip out the field starter
+ urlData = $1
+ }
+ /^enabled=/ {
+ enabledStatus = $1
+ }
+ # print out the line if all 3 values are found, otherwise if a new
+ # repoTitle is hit above, it will print out the line there instead
+ {
+ if ( urlData != "" && enabledStatus != "" && repoTitle != "" ){
+ if ( enabledStatus !~ /enabled=0/ ){
+ print_line( repoFile, repoTitle, urlData )
+ }
+ enabledStatus=""
+ urlData=""
+ repoTitle=""
+ }
+ }
+ END {
+ # print the last one if there is data for it
+ if ( urlData != "" && repoTitle != "" ){
+ print_line( repoFile, repoTitle, urlData )
+ }
+ }
+ ' $repo_file )"
+
+ # then load the global for each file as it gets filled
+ if [[ -n $repo_data_working ]];then
+ if [[ -z $REPO_DATA ]];then
+ REPO_DATA="$repo_data_working"
+ else
+ REPO_DATA="$REPO_DATA
+$repo_data_working"
+ fi
+ repo_data_working=''
+ fi
+ done
+ REPO_FILE_ID='yum repos'
+ # pisi - pardus
+ elif [[ -d $pisi_dir && -n $( type -p pisi ) ]];then
+ REPO_DATA="$( pisi list-repo )"
+ # now we need to create the structure: repo info: repo path
+ # we do that by looping through the lines of the output and then
+ # putting it back into the <data>:<url> format print repos expects to see
+ while read repo_line
+ do
+ repo_line=$( gawk '
+ {
+ # need to dump leading/trailing spaces and clear out color codes for irc output
+ sub(/^[[:space:]]+|[[:space:]]+$/,"",$0)
+# gsub(/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]/,"",$0) # leaving this pattern in case need it
+ gsub(/\e\[([0-9];)?[0-9]+m/,"",$0)
+ print $0
+ }' <<< $repo_line )
+ if [[ -n $( grep '://' <<< $repo_line ) ]];then
+ repo_data_working="$repo_data_working:$repo_line\n"
+ else
+ repo_data_working="$repo_data_working$repo_line"
+ fi
+ done <<< "$REPO_DATA"
+ # echo and execute the line breaks inserted
+ REPO_DATA="$( echo -e $repo_data_working )"
+ REPO_FILE_ID='pisi repo'
+ # pacman - archlinux
+ elif [[ -f $pacman_conf ]];then
+ # get list of mirror include files, trim white space off ends
+ repo_data_working="$( gawk '
+ BEGIN {
+ FS="="
+ IGNORECASE=1
+ }
+ /^[[:space:]]*Include/ {
+ sub(/^[[:space:]]+|[[:space:]]+$/,"",$2)
+ print $2
+ }
+ ' $pacman_conf )"
+ # sort into unique paths only, to be used to search for server = data
+ repo_data_working=$( sort -bu <<< "$repo_data_working" | uniq )
+ repo_data_working="$repo_data_working $pacman_conf"
+ for repo_file in $repo_data_working
+ do
+ if [[ -f $repo_file ]];then
+ # inserting a new line after each found / processed match
+ repo_data_working2="$repo_data_working2$( gawk -v repoFile=$repo_file '
+ BEGIN {
+ FS="="
+ IGNORECASE=1
+ }
+ /^[[:space:]]*Server/ {
+ sub(/^[[:space:]]+|[[:space:]]+$/,"",$2)
+ print repoFile ":" $2 "\\n"
+ }
+ ' $repo_file )"
+ else
+ echo "Error: file listed in $pacman_conf does not exist - $repo_file"
+ fi
+ done
+ # execute line breaks
+ REPO_DATA="$( echo -e $repo_data_working2 )"
+ REPO_FILE_ID='arch repo servers'
+ fi
+ eval $LOGFE
+}
+
+get_runlevel_data()
+{
+ eval $LOGFS
+ local runlvl=''
+ local runlevel_path=$( type -p runlevel )
+ if [[ -n $runlevel_path ]];then
+ runlvl="$( $runlevel_path | gawk '{ print $2 }' )"
+ fi
+ echo $runlvl
+ eval $LOGFE
+}
+
+get_sensors_data()
+{
+ eval $LOGFS
+
+ local sensors_path=$( type -p sensors )
+
+ IFS=$'\n'
+ if [[ -n $sensors_path ]];then
+ # note: non-configured sensors gives error message, which we need to redirect to stdout
+ # also, -F ':' no space, since some cases have the data starting right after,like - :1287
+ A_SENSORS_DATA=( $(
+ $sensors_path | gawk -F ':' -v userCpuNo="$SENSORS_CPU_NO" '
+ BEGIN {
+ IGNORECASE=1
+ core0Temp="" # only if all else fails...
+ cpuTemp=""
+ cpuTempReal=""
+ fanWorking=""
+ indexCountaFanMain=0
+ indexCountaFanDefault=0
+ i=""
+ j=""
+ moboTemp=""
+ moboTempReal=""
+ psuTemp=""
+ separator=""
+ sysFanString=""
+ temp1=""
+ temp2=""
+ tempFanType="" # set to 1 or 2
+ tempUnit=""
+ tempWorking=""
+ tempWorkingUnit=""
+ }
+ # dumping the extra + signs after testing for them, nobody has negative temps.
+ # also, note gawk treats ° as a space, so we have to get the C/F data
+ # there are some guesses here, but with more sensors samples it will get closer.
+ # note: using arrays starting at 1 for all fan arrays to make it easier overall
+ # more validation because gensub if fails to get match returns full string, so
+ # we have to be sure we are working with the actual real string before assiging
+ # data to real variables and arrays. Extracting C/F degree unit as well to use
+ # when constructing temp items for array.
+ # note that because of charset issues, no tempUnit="°" tempWorkingUnit degree sign
+ # used, but it is required in testing regex to avoid error.
+ /^(M\/B|MB|SIO|SYS)(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
+ moboTemp=gensub( /[ \t]+\+([0-9\.]*)(.*)/, "\\1", 1, $2 )
+ tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
+ if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
+ tempUnit=tempWorkingUnit
+ }
+ }
+ /^CPU(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
+ cpuTemp=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 )
+ tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
+ if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
+ tempUnit=tempWorkingUnit
+ }
+ }
+ /^(P\/S|Power)(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
+ psuTemp=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 )
+ tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
+ if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
+ tempUnit=tempWorkingUnit
+ }
+ }
+ $1 ~ /^temp1$/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
+ tempWorking=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 )
+ if ( temp1 == "" || tempWorking > 0 ) {
+ temp1=tempWorking
+ }
+ tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
+ if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
+ tempUnit=tempWorkingUnit
+ }
+ }
+ $1 ~ /^temp2$/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
+ tempWorking=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 )
+ if ( temp2 == "" || tempWorking > 0 ) {
+ temp2=tempWorking
+ }
+ tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
+ if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
+ tempUnit=tempWorkingUnit
+ }
+ }
+
+ # final fallback if all else fails, funtoo user showed sensors putting
+ # temp on wrapped second line, not handled
+ /^(core0|core 0)(.*)\+([0-9]+)(.*)[ \t°](C|F)/ && $2 ~ /^[ \t]*\+([0-9]+)/ {
+ tempWorking=gensub( /[ \t]+\+([0-9\.]+)(.*)/, "\\1", 1, $2 )
+ if ( core0Temp == "" || tempWorking > 0 ) {
+ core0Temp=tempWorking
+ }
+ tempWorkingUnit=gensub( /[ \t]+\+([0-9\.]+)[ \t°]+([CF])(.*)/, "\\2", 1, $2 )
+ if ( tempWorkingUnit ~ /^C|F$/ && tempUnit == "" ){
+ tempUnit=tempWorkingUnit
+ }
+ }
+
+ # note: can be cpu fan:, cpu fan speed:, etc. Some cases have no space before
+ # $2 starts (like so :1234 RPM), so skip that space test in regex
+ /^CPU(.*)[ \t]*([0-9]+)[ \t]RPM/ {
+ aFanMain[1]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
+ }
+ /^(M\/B|MB|SYS)(.*)[ \t]*([0-9]+)[ \t]RPM/ {
+ aFanMain[2]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
+ }
+ /(Power|P\/S|POWER)(.*)[ \t]*([0-9]+)[ \t]RPM/ {
+ aFanMain[3]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
+ }
+ # note that the counters are dynamically set for fan numbers here
+ # otherwise you could overwrite eg aux fan2 with case fan2 in theory
+ # note: cpu/mobo/ps are 1/2/3
+ # NOTE: test: ! i in array does NOT work, this appears to be an awk/gawk bug
+ /^(AUX(1)? |CASE(1)? |CHASSIS(1)? )(.*)[ \t]*([0-9]+)[ \t]RPM/ {
+ for ( i = 4; i < 7; i++ ){
+ if ( i in aFanMain ){
+ ##
+ }
+ else {
+ aFanMain[i]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
+ break
+ }
+ }
+ }
+ /^(AUX([2-9]) |CASE([2-9]) |CHASSIS([2-9]) )(.*)[ \t]*([0-9]+)[ \t]RPM/ {
+ for ( i = 5; i < 30; i++ ){
+ if ( i in aFanMain ) {
+ ##
+ }
+ else {
+ sysFanNu = i
+ aFanMain[i]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
+ break
+ }
+ }
+ }
+ # in rare cases syntax is like: fan1: xxx RPM
+ /^(FAN(1)?[ \t:])(.*)[ \t]*([0-9]+)[ \t]RPM/ {
+ aFanDefault[1]=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
+ }
+ /^FAN([2-9]|1[0-9])(.*)[ \t]*([0-9]+)[ \t]RPM/ {
+ fanWorking=gensub( /[ \t]*([0-9]+)[ \t]+(.*)/, "\\1", 1, $2 )
+ sysFanNu=gensub( /fan([0-9]+)/, "\\1", 1, $1 )
+ if ( sysFanNu ~ /^([0-9]+)$/ ) {
+ # add to array if array index does not exist OR if number is > existing number
+ if ( sysFanNu in aFanDefault ) {
+ if ( fanWorking >= aFanDefault[sysFanNu] ) {
+ aFanDefault[sysFanNu]=fanWorking
+ }
+ }
+ else {
+ aFanDefault[sysFanNu]=fanWorking
+ }
+ }
+ }
+
+ END {
+ # first we need to handle the case where we have to determine which temp/fan to use for cpu and mobo:
+ # note, for rare cases of weird cool cpus, user can override in their prefs and force the assignment
+ if ( temp1 != "" && temp2 != "" ){
+ if ( userCpuNo != "" && userCpuNo ~ /(1|2)/ ) {
+ tempFanType=userCpuNo
+ }
+ else {
+ # first some fringe cases with cooler cpu than mobo: assume which is cpu temp based on fan speed
+ # but only if other fan speed is 0
+ if ( temp1 >= temp2 && 1 in aFanDefault && 2 in aFanDefault && aFanDefault[1] == 0 && aFanDefault[2] > 0 ) {
+ tempFanType=2
+ }
+ else if ( temp2 >= temp1 && 1 in aFanDefault && 2 in aFanDefault && aFanDefault[2] == 0 && aFanDefault[1] > 0 ) {
+ tempFanType=1
+ }
+ # then handle the standard case if these fringe cases are false
+ else if ( temp1 >= temp2 ) {
+ tempFanType=1
+ }
+ else {
+ tempFanType=2
+ }
+ }
+ }
+ # need a case for no temps at all reported, like with old intels
+ else if ( temp2 == "" && cpuTemp == "" ){
+ if ( temp1 == "" && moboTemp == "" ){
+ tempFanType=1
+ }
+ else if ( temp1 != "" && moboTemp == "" ){
+ tempFanType=1
+ }
+ else if ( temp1 != "" && moboTemp != "" ){
+ tempFanType=1
+ }
+ }
+
+ # then get the real cpu temp, best guess is hottest is real
+ if ( cpuTemp != "" ){
+ cpuTempReal=cpuTemp
+ }
+ else if ( tempFanType != "" ){
+ if ( tempFanType == 1 ){
+ cpuTempReal=temp1
+ }
+ else {
+ cpuTempReal=temp2
+ }
+ }
+ else {
+ cpuTempReal=temp1
+ }
+ # if all else fails, use core0 temp if it is present and cpu is null
+ if ( cpuTempReal == "" && core0Temp != "" ) {
+ cpuTempReal=core0Temp
+ }
+
+ # then the real mobo temp
+ if ( moboTemp != "" ){
+ moboTempReal=moboTemp
+ }
+ else if ( tempFanType != "" ){
+ if ( tempFanType == 1 ) {
+ moboTempReal=temp2
+ }
+ else {
+ moboTempReal=temp1
+ }
+ }
+ else {
+ moboTempReal=temp2
+ }
+ # then set the cpu fan speed
+ if ( aFanMain[1] == "" ) {
+ # note, you cannot test for aFanDefault[1] or [2] != ""
+ # because that creates an array item in gawk just by the test itself
+ if ( tempFanType == 1 && 1 in aFanDefault ) {
+ aFanMain[1]=aFanDefault[1]
+ aFanDefault[1]=""
+ }
+ else if ( tempFanType == 2 && 2 in aFanDefault ) {
+ aFanMain[1]=aFanDefault[2]
+ aFanDefault[2]=""
+ }
+ }
+
+ # then we need to get the actual numeric max array count for both fan arrays
+ for (i = 0; i <= 29; i++) {
+ if ( i in aFanMain && i > indexCountaFanMain ) {
+ indexCountaFanMain=i
+ }
+ }
+ for (i = 0; i <= 14; i++) {
+ if ( i in aFanDefault && i > indexCountaFanDefault ) {
+ indexCountaFanDefault=i
+ }
+ }
+
+ # clear out any duplicates. Primary fan real trumps fan working always if same speed
+ for (i = 1; i <= indexCountaFanMain; i++) {
+ if ( i in aFanMain && aFanMain[i] != "" && aFanMain[i] != 0 ) {
+ for (j = 1; j <= indexCountaFanDefault; j++) {
+ if ( j in aFanDefault && aFanMain[i] == aFanDefault[j] ) {
+ aFanDefault[j] = ""
+ }
+ }
+ }
+ }
+
+ # now see if you can find the fast little mobo fan, > 5000 rpm and put it as mobo
+ # note that gawk is returning true for some test cases when aFanDefault[j] < 5000
+ # which has to be a gawk bug, unless there is something really weird with arrays
+ # note: 500 > aFanDefault[j] < 1000 is the exact trigger, and if you manually
+ # assign that value below, the > 5000 test works again, and a print of the value
+ # shows the proper value, so the corruption might be internal in awk.
+ # Note: gensub is the culprit I think, assigning type string for range 501-1000 but
+ # type integer for all others, this triggers true for >
+ for (j = 1; j <= indexCountaFanDefault; j++) {
+ if ( j in aFanDefault && int( aFanDefault[j] ) > 5000 && aFanMain[2] == "" ) {
+ aFanMain[2] = aFanDefault[j]
+ aFanDefault[j] = ""
+ # then add one if required for output
+ if ( indexCountaFanMain < 2 ) {
+ indexCountaFanMain = 2
+ }
+ }
+ }
+
+ # then construct the sys_fan string for echo, note that iteration 1
+ # makes: fanDefaultString separator null, ie, no space or ,
+ for (j = 1; j <= indexCountaFanDefault; j++) {
+ fanDefaultString = fanDefaultString separator aFanDefault[j]
+ separator=","
+ }
+ separator="" # reset to null for next loop
+ # then construct the sys_fan string for echo
+ for (j = 1; j <= indexCountaFanMain; j++) {
+ fanMainString = fanMainString separator aFanMain[j]
+ separator=","
+ }
+
+ # and then build the temps:
+ if ( moboTempReal != "" ) {
+ moboTempReal = moboTempReal tempUnit
+ }
+ if ( cpuTempReal != "" ) {
+ cpuTempReal = cpuTempReal tempUnit
+ }
+
+ # if they are ALL null, print error message. psFan is not used in output currently
+ if ( cpuTempReal == "" && moboTempReal == "" && aFanMain[1] == "" && aFanMain[2] == "" && aFanMain[3] == "" && fanDefaultString == "" ) {
+ print "No active sensors found. Have you configured your sensors yet?"