export_browser_history.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. OUTPUT_DIR="$(pwd)"
  3. if [[ "$1" == "--chrome" ]]; then
  4. # Google Chrome / Chromium
  5. if [[ -e "$2" ]]; then
  6. cp "$2" "$OUTPUT_DIR/chrome_history.db.tmp"
  7. else
  8. default=$(ls ~/Library/Application\ Support/Google/Chrome/Default/History)
  9. echo "Defaulting to history db: $default"
  10. echo "Optionally specify the path to a different sqlite history database as the 2nd argument."
  11. cp "$default" "$OUTPUT_DIR/chrome_history.db.tmp"
  12. fi
  13. sqlite3 "$OUTPUT_DIR/chrome_history.db.tmp" "SELECT \"[\" || group_concat(json_object('timestamp', last_visit_time, 'description', title, 'href', url)) || \"]\" FROM urls;" > "$OUTPUT_DIR/chrome_history.json"
  14. jq < "$(dirname "${2:-$default}")"/Bookmarks '.roots.other.children[] | {href: .url, description: .name, timestamp: .date_added}' > "$OUTPUT_DIR/chrome_bookmarks.json"
  15. rm "$DATA_DIR"/output/sources/chrome_history.db.*
  16. echo "Chrome history exported to:"
  17. echo " output/sources/chrome_history.json"
  18. fi
  19. if [[ "$1" == "--firefox" ]]; then
  20. # Firefox
  21. if [[ -e "$2" ]]; then
  22. cp "$2" "$OUTPUT_DIR/firefox_history.db.tmp"
  23. else
  24. default=$(ls ~/Library/Application\ Support/Firefox/Profiles/*.default/places.sqlite)
  25. echo "Defaulting to history db: $default"
  26. echo "Optionally specify the path to a different sqlite history database as the 2nd argument."
  27. cp "$default" "$OUTPUT_DIR/firefox_history.db.tmp"
  28. fi
  29. sqlite3 "$OUTPUT_DIR/firefox_history.db.tmp" "SELECT \"[\" || group_concat(json_object('timestamp', last_visit_date, 'description', title, 'href', url)) || \"]\" FROM moz_places;" > "$OUTPUT_DIR/firefox_history.json"
  30. sqlite3 "$OUTPUT_DIR/firefox_history.db.tmp" "SELECT \"[\" || group_concat(json_object('timestamp', b.dateAdded, 'description', b.title, 'href', f.url)) || \"]\" FROM moz_bookmarks AS b JOIN moz_places AS f ON f.id = b.fk" > "$OUTPUT_DIR/firefox_bookmarks.json"
  31. rm "$DATA_DIR"/output/sources/firefox_history.db.*
  32. echo "Firefox history exported to:"
  33. echo " output/sources/firefox_history.json"
  34. echo " output/sources/firefox_bookmarks.json"
  35. fi
  36. if [[ "$1" == "--safari" ]]; then
  37. # Safari
  38. if [[ -e "$2" ]]; then
  39. cp "$2" "$OUTPUT_DIR/safari_history.db.tmp"
  40. else
  41. default="~/Library/Safari/History.db"
  42. echo "Defaulting to history db: $default"
  43. echo "Optionally specify the path to a different sqlite history database as the 2nd argument."
  44. cp "$default" "$OUTPUT_DIR/safari_history.db.tmp"
  45. fi
  46. sqlite3 "$OUTPUT_DIR/safari_history.db.tmp" "select url from history_items" > "$OUTPUT_DIR/safari_history.json"
  47. rm "$DATA_DIR"/output/sources/safari_history.db.*
  48. echo "Safari history exported to:"
  49. echo " output/sources/safari_history.json"
  50. fi