cookies2txt.sh 929 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. {
  4. # profile=$(awk -v RS="(^|\n)\\\[[a-zA-Z0-9]*\\\](\n|$)" '/\nDefault=1/' "$HOME/.mozilla/firefox/profiles.ini" | sed -n 's/^Path=\(.*\)$/\1/p')
  5. # if [ -z "$profile" ]; then
  6. # echo "couldn't find profile"
  7. # exit 1
  8. # fi
  9. # profile_dir="$HOME/.mozilla/firefox/$profile"
  10. # if [ ! -e "$profile_dir" ]; then
  11. # echo "Failed to locate profile"
  12. # exit 1
  13. # fi
  14. TMPDB=$(mktemp -u)
  15. # cp "$profile_dir/cookies.sqlite" "$TMPDB"
  16. cookies="$1"
  17. cp "$cookies" "$TMPDB"
  18. {
  19. echo "# Netscape HTTP Cookie File"
  20. sqlite3 -separator "$(printf '\t')" "$TMPDB" <<EOF
  21. .mode tabs
  22. .header off
  23. select host,
  24. case substr(host,1,1)='.' when 0 then 'FALSE' else 'TRUE' end,
  25. path,
  26. case isSecure when 0 then 'FALSE' else 'TRUE' end,
  27. expiry,
  28. name,
  29. value
  30. from moz_cookies;
  31. EOF
  32. }
  33. rm -f "$TMPDB"
  34. } >~/cookies.txt