reddit-image-wall-getter/reddit_imgs/get_firefox_cookies.sh

42 lines
1.1 KiB
Bash
Raw Normal View History

2020-07-20 01:54:26 +00:00
#!/bin/bash
export FIREFOX_VARIANT="default-release"
list_firefox_cookies(){
for COOKIEJAR in $HOME/.mozilla/firefox/*.$FIREFOX_VARIANT/cookies.sqlite;
do echo $COOKIEJAR;
done ;
}
one_firefox_cookie(){
list_firefox_cookies | head -1 ;
}
echoerr() { echo "$@" 1>&2; }
export FIREFOX_COOKIE_LOCATION=$(list_firefox_cookies)
export_firefox_cookies(){
export TMPDB=$(uuidgen -r | sed -e 's/-//g')
cp $FIREFOX_COOKIE_LOCATION /tmp/$TMPDB.db
echo "# Netscape HTTP Cookie File" > "$1~"
echo "# http://curl.haxx.se/rfc/cookie_spec.html" >> "$1~"
echo "# This is a generated file! Do not edit." >> "$1~"
echo -ne "\n" >> "$1~"
echo -e ".mode tabs\nselect host, case when host glob '.*' then 'TRUE' else 'FALSE' end, path, case when isSecure then 'TRUE' else 'FALSE' end, expiry, name, value from moz_cookies order by host;" | sqlite3 "/tmp/$TMPDB.db" >> "$1~"
rm /tmp/$TMPDB.db
mv "$1~" "$1"
}
if [ -z "$FIREFOX_COOKIE_LOCATION" ]; then
echoerr "Firefox cookie database was not found."
exit 1
else
if [ -z "$1" ]; then
echoerr "Cookie destination file unspecified."
exit 1
else
export_firefox_cookies "$@"
fi;
fi;