aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/home/.local/bin/cookiefire
blob: 7471f0507701d4ee6deb52342a6cdea6778626b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# -*- mode:sh -*-

die() {
    echo >&2 "$*"
    exit 1
}



cleanup() {
    rm -f "$tmpfile"
}
trap cleanup  EXIT INT QUIT TERM

# Run older ld (pseudo condition)

if [ "$#" == "0" ];  then
    profile=default-default
elif [ "$#" == "1"  ]; then
    profile=$1
else
    die "usage $0 [profile]"
fi;


extract_cookies() {

if [ "$#" -ge 1 ]; then
    sqlfile="$1"
else
    if tty -s; then
    sqlfile=$(ls -t ~/.librewolf/*/cookies.sqlite | head -1)

    sqlfile="-"     # Will use 'cat' below to read stdin
    fi
fi

if [ "$sqlfile" != "-" -a ! -r "$sqlfile" ]; then
    echo "Error. File $sqlfile is not readable." >&2
    exit 1
fi

# We have to copy cookies.sqlite, because FireFox has a lock on it
cat "$sqlfile" >> $tmpfile


# This is the format of the sqlite database:
# CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, name TEXT, value TEXT, host TEXT, path TEXT,expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER, isHttpOnly INTEGER);

echo "# Netscape HTTP Cookie File"
sqlite3 -separator $'\t' $tmpfile <<- EOF
.mode tabs
.header off
select host,
case substr(host,1,1)='.' when 0 then 'FALSE' else 'TRUE' end,
path,
case isSecure when 0 then 'FALSE' else 'TRUE' end,
expiry,
name,
value
from moz_cookies;
EOF

cleanup

}

tmpfile="$(mktemp /tmp/cookies.sqlite.XXXXXXXXXX)"
curlcookies="$(mktemp /tmp/curlcookies.XXXXXXXXXX)"
echo $HOME/.librewolf/*.$profile/cookies.sqlite | { read cookie_file ;
extract_cookies "$cookie_file" ;
}