From Social Guinea Pig, 1 Week ago, written in Plain Text.
  1. #!/bin/bash
  2.  
  3. #PS4=$'+[$?]${FUNCNAME[0]}: '
  4. #exec 87>./basibak.xtrace
  5. #export BASH_XTRACEFD=87
  6. #set -x
  7. shopt -s huponexit
  8. trap "exit" INT
  9.  
  10. hthead(){
  11.   local _sdate _fname
  12.   _sdate="$1" _fname="$2"
  13.   cat <<<"<!DOCTYPE HTML>
  14. <html>
  15.   <head>
  16.     <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />
  17.     <title>Basilisk ${_fname} -- ${_sdate}</title>
  18.     <style type=\"text/css\">
  19.       html,body {color:#9AA2A3; background:#14191F}
  20.       a, ol, li {color:#9AA2A3; line-height: 2em; list-style:disc outside none}
  21.       li {margin-top: 1em; padding-left: 0.2em}
  22.       div {margin-left: 1em; line-height: 1.6em}
  23.       a:link {color:#2B78AD}
  24.       a:visited {color:#6771C4}
  25.       .date {display:table-header-group;}
  26.       .show {padding:0 1em 0 1em;margin:0;cursor:pointer;text-align:left;display:inline;}
  27.       #panel {display:none;margin:0 0 -2em 0;} // NOTE: This must be named 'panel' for some reason...
  28.     </style>
  29.   </head>
  30.   <h1>Basilisk ${_fname} -- ${_sdate}</h1>
  31.   <body>
  32.     <ol>
  33. "
  34. }
  35.  
  36. httail(){
  37.   cat <<<"
  38.     </ol>
  39.     <script>function showMeta(){
  40.         var cur = document.getElementById(id).childNodes[1].style.display
  41.         if(cur == \"table-row\") {
  42.             document.getElementById(id).childNodes[1].style.display = \"none\"
  43.         } else {
  44.             document.getElementById(id).childNodes[1].style.display = \"table-row\"
  45.         }
  46.     </script>
  47.   </body>
  48. </html>
  49. "
  50. }
  51.  
  52. sqldump(){
  53.   local db dat
  54.   dat="$1"; db="$2"
  55.   #sqlite3 "$db" .dump
  56.  
  57.   if [[ "$dat" == "-h" ]]; then
  58.     sqlite3 "$db" -separator $'\001' 'select moz_places.* from moz_places order by moz_places.id' \
  59.      return
  60.   else
  61.     if [[ "$dat" == "-b" ]]; then
  62.      sqlite3 "$db" -separator $'\001' 'select moz_places.*, moz_bookmarks.title
  63.          from moz_places, moz_bookmarks
  64.          where moz_bookmarks.fk = moz_places.id
  65.          and moz_bookmarks.type = 1
  66.          order by moz_bookmarks.dateAdded'
  67.     fi
  68.   fi
  69. }
  70.        
  71. htcreat(){
  72.   local _sdate _fname
  73.   _sdate="$1" _fname="$2"
  74.   # NOTE: The srand() is to get length($EPOCH). A second call to srand() returns the seed.
  75.   gawk -F "|" -v OFS="] [" -v head="$(hthead "$_sdate" "$_fname")" -v tail="$(httail)" '
  76.     BEGIN{srand(); e[12]=e[10]="</div>"; e[8]="</li><br>\n"; print head}
  77.     {pad="      "}
  78.     {printf("%s<li><div>%s</div>\n", pad, $3); pad=pad"  "}
  79.     {printf("%s<div><a href=\"%s\">%s</a></div>\n", pad, $2, $2); pad=pad"  "}
  80.     {printf("%s<div class=\"date\">visited: %s\n", pad, substr($10, 0, length(srand()))); pad=pad"  "}
  81.     {printf("%s<div id=\"%s\" class=\"show\" onclick=\"showMeta(this.id)\">...\n", pad, NR); pad=pad"  "}
  82.     {printf("%s<select id=\"panel\"><option>[%s]</option></select>\n", pad, $0)}
  83.     {printf("            </div>\n        </div>\n      </li><br>\n")}
  84.     END{ print tail}
  85.   ' <&0
  86.     # TODO: HAHAHA no feck orf awk. LOOOOOOOoop you bastarddddddddd!
  87.     #{for(pl=(length(pad)-2);pl<6;pl--) {pad=substr(pad, (length(pad)-2)); printf("%s%s\n", pad, e[$pl]); pl--}}
  88.     #{printf("%s</div>\n%s</div>\n</li><br>\n", substr(pad, 0, (length(pad-2))), substr(pad, 0, (length(pad-4))), substr(pad, 0, (length(pad-6))))}
  89.     #{printf("%s</div>\n        </div>\n      </li><br>\n", substr(pad, length(pad-2)))}
  90.     # wtffffff -2? -4? -27?????
  91.  
  92. }
  93.  
  94. pulldb(){
  95.   local p
  96.   # Extract profile name
  97.   p="$(gawk -F "=" '
  98.     {if($0~/Name=default/) {while($1!~/^Path/) next;}}
  99.     /.*\.default/{print $2;exit}' ~/.moonchild_productions/basilisk/profiles.ini)"
  100.  
  101.   command cat "$HOME/.moonchild_productions/basilisk/$p/places.sqlite"
  102. }
  103.  
  104.  
  105. declare -rgi sdate="$(command date +%s)"
  106. declare -rg  dir="$HOME/.moonchild_productions/places.bak"
  107. declare -rg  tmp="${dir}/places.sqlite.tmp"
  108. declare -rg  hfile="${dir}/history.$sdate.html"
  109. declare -rg  bfile="${dir}/bookmarks.$sdate.html"
  110.  
  111. basibak(){
  112.   local d
  113.   cd ~/.moonchild_productions/ || exit 1
  114.  
  115.   while sleep 18h; do
  116.   #for d in 13; do
  117.  
  118.       d="$(date +%d)"
  119.       # Only fire twice a month
  120.       if [[ "$d" =~ (13|28) ]]; then
  121.      
  122.         pulldb >"$tmp" && wait
  123.         htcreat "$sdate" "${hfile##*/}" < <(sqldump -h "$tmp") >"$hfile" && wait
  124.         htcreat "$sdate" "${bfile##*/}" < <(sqldump -b "$tmp") >"$bfile" && wait
  125.  
  126.         # Remove tmpfile
  127.         gawk -v tmp="$tmp" 'END{if(FNR!=0) system("rm " tmp)}' <"$hfile"
  128.       fi
  129.    
  130.   done
  131.  
  132. }
  133.  
  134. basibak
captcha