howFar.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #!/bin/bash
  2. # Copyright © 2023-2024 Jeffrey Cliff
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or (at
  7. # your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. TEMP=`mktemp`
  17. TEMP1=`mktemp`
  18. BASEDIR=/home/themusicgod1
  19. RED="\x1343"
  20. MAXLEVEL=`grep -i "maximum" $BASEDIR/tools/grabLaundry.sh | awk -F' ' '{print $8}' | awk -F')' '{print $1}'`".0"
  21. # MAXLEVEL="156.0"
  22. echo "maxlevel" $MAXLEVEL
  23. # MAXLEVEL="134.0"
  24. WHAT=$1
  25. echo $WHAT
  26. WHAT=`echo $WHAT | sed -e "s/www.threads.net/threads.net/"`
  27. echo $WHAT
  28. if [ -z $WHAT ] ; then
  29. echo "you need to give this script some input"
  30. exit;
  31. fi
  32. DB=/home/themusicgod1/TDL/urls.db
  33. FEDIDB=/home/themusicgod1/TDL/fedi.db
  34. LEVEL=`sqlite3 $DB -line "select level from news where url like \""$WHAT"\"" | grep -i 'level' | awk -F' ' '{print $3}'`
  35. if [[ -z $LEVEL ]]; then
  36. echo "zero - we have a new user"
  37. NEWID=`sqlite3 $DB -line "select max(id) from news" | grep -i 'id' | awk -F' ' '{print $3}'`
  38. # echo $NEWID
  39. NEWID2=`echo $NEWID "+ 1" | bc`
  40. # echo $NEWID2
  41. DOMAIN=`echo $WHAT | awk -F'@' '{print $3}'`;
  42. # NEWLEVEL=`grep -i $DOMAIN $BASEDIR/FediSus.html | head -n 1 | awk -F' ' '{print $2}'`
  43. # echo $NEWLEVEL
  44. # echo "we need to check if it's threads here";
  45. if [[ -z $DOMAIN ]]; then
  46. echo "something went wrong here : " $DOMAIN "should be a domain"
  47. echo "what is " $WHAT
  48. echo "this should give results:"
  49. echo $WHAT | grep -i '@.*@.*'
  50. if [[ $? -eq "1" ]]; then
  51. echo "you probably are missing a @ in your fedi id"
  52. fi
  53. exit
  54. fi
  55. if [ $DOMAIN = "www.threads.net" ]; then
  56. echo "its threads";
  57. DOMAIN="threads.net"
  58. echo "NEWID2" $WHAT
  59. WHAT=`echo $WHAT | sed -e "s/www.threads.net/threads.net/"`
  60. echo "NEWID2" $WHAT
  61. else
  62. echo "its' not threads";
  63. fi
  64. NEWLEVEL=`sqlite3 $FEDIDB -line "select level from instances where name like '"$DOMAIN"';" | grep -i 'level' | awk -F' ' '{print $3}'`
  65. HOWMANY=`how_many_arguments.sh $NEWLEVEL`
  66. if [[ $HOWMANY -gt 1 ]]; then
  67. setterm --foreground red
  68. echo "looks like we have too many levels: " $WHAT
  69. setterm --foreground default
  70. exit 1
  71. fi
  72. if [[ -z $NEWLEVEL ]]; then
  73. echo "insert into news values ("$NEWID2",\""$WHAT"\",0,'','','');"
  74. else
  75. echo "insert into news values ("$NEWID2",\""$WHAT"\","$NEWLEVEL",'','','');"
  76. fi
  77. exit
  78. fi
  79. ID=`sqlite3 $DB -line "select id from news where url like \""$WHAT"\"" | grep -i 'id' | awk -F' ' '{print $3}'`
  80. DOMAIN=`echo $1 | awk -F'@' '{print $3}'`
  81. if [ $DOMAIN = "www.threads.net" ]; then
  82. echo "its threads";
  83. DOMAIN="threads.net"
  84. else
  85. echo "its' not threads";
  86. fi
  87. echo "domain is " $DOMAIN
  88. # deal with the great cloudwall
  89. ISCLOUDWALL=`sqlite3 $FEDIDB -line "select iscf from instances where name = \"$DOMAIN\"" | sed -e "s/ iscf = //" `
  90. #echo sqlite3 $FEDIDB -line "select iscf from instances where name = \"$DOMAIN\""
  91. #echo "db" $FEDIDB
  92. #echo "cloudwall" $ISCLOUDWALL
  93. # thanks https://dev.to/dak425/how-to-check-if-a-string-is-empty-in-bash-264l
  94. ICWA=`how_many_arguments.sh $ISCLOUDWALL`
  95. if [[ $ICWA -gt 1 ]]; then
  96. setterm --foreground red
  97. echo "something up with " $DOMAIN
  98. setterm --foreground default
  99. fi
  100. echo "is cloudwall" $ISCLOUDWALL
  101. if [[ -z $ISCLOUDWALL ]] ; then
  102. setterm --foreground red
  103. echo "we are probably missing " $DOMAIN " in our database"
  104. echo "blocks:" `how_many_blocks_estimate.sh $DOMAIN`
  105. echo "cloudflare?" `is_cloudflare $DOMAIN`
  106. echo $DOMAIN >> /tmp/totallymissingdomains
  107. setterm --foreground default
  108. exit;
  109. fi
  110. if [ $ISCLOUDWALL -eq 2 ] ; then
  111. echo $DOMAIN " was in the database but cf status not known"
  112. setterm --foreground yellow
  113. echo "CLOUDFLARE - STATUS UNKNOWN"
  114. echo "cloudflare?" `is_cloudflare $DOMAIN`
  115. echo $DOMAIN >> /tmp/missingdomains
  116. setterm --foreground default
  117. fi
  118. if [ $ISCLOUDWALL -eq 1 ] ; then
  119. echo $DOMAIN
  120. setterm --foreground red
  121. echo "CLOUDFLARED"
  122. setterm --foreground default
  123. fi
  124. # cat FediSus.html | grep -i $DOMAIN | head -n 1 | awk -F' ' '{print $2}'
  125. #FEDILEVEL=`cat /home/themusicgod1/FediSus.html | grep -i $DOMAIN | head -n 1 | awk -F' ' '{print $2}'`
  126. #echo "domain:" $DOMAIN
  127. #echo sqlite3 $FEDIDB -line "select level from instances where name = '"$DOMAIN"';"
  128. FEDILEVEL=`sqlite3 $FEDIDB -line "select level from instances where name = '"$DOMAIN"';" | grep -i 'level' | awk -F' ' '{print $3}'`
  129. echo "instance level is" $FEDILEVEL
  130. echo "max LEVEL is " $MAXLEVEL
  131. echo "user LEVEL is " $LEVEL
  132. #echo "why:"
  133. echo "what:" $WHAT
  134. # this is the line where things can go wrong if there's 2 results
  135. # we don't want to incur another database hit.
  136. WHYLINE=`sqlite3 $DB -line "select why from news where url = \""$WHAT"\"" | grep -i 'why'`
  137. sqlite3 $DB -line "select why from news where url = \""$WHAT"\"" | grep -i 'why' > /tmp/whylines
  138. WHYLINELINES=`wc -l /tmp/whylines | awk -F' ' '{print $1}'`
  139. #WHYLINELINES=`echo $WHYLINE`
  140. echo "WHYWLINELINES " $WHYLINELINES
  141. if [[ $WHYLINELINES -gt 1 ]]; then
  142. echo "we have more than one line!!!!"
  143. setterm --foreground red
  144. echo "problem at $WHAT "
  145. setterm --foreground default
  146. exit
  147. fi
  148. echo $WHYLINE
  149. echo "we are over by:"
  150. echo "("$FEDILEVEL" - "$LEVEL")/"$MAXLEVEL
  151. echo "("$FEDILEVEL" - "$LEVEL")/"$MAXLEVEL | bc;
  152. LEVEL2=`echo $LEVEL + "("$FEDILEVEL" - "$LEVEL")/"$MAXLEVEL | bc`
  153. LEVEL3=`echo "("$FEDILEVEL" - "$LEVEL")/"$MAXLEVEL | bc`
  154. echo "level3" $LEVEL3
  155. if [[ -z $LEVEL3 ]]; then
  156. echo "this was crashing. its zero??"
  157. echo "fedi level again:" $FEDILEVEL
  158. echo "level again:" $LEVEL
  159. echo "maxlevel again:" $MAXLEVEL
  160. elif [[ $LEVEL3 -eq "0" ]] ; then
  161. echo "its zero"
  162. else
  163. echo "id" $ID
  164. echo "update news set level = " $LEVEL2 " where id = "$ID";"
  165. echo "WHAT Is " $WHAT
  166. fi
  167. whoisthis $WHAT
  168. grabSnowflake.sh $WHAT