diff options
author | 2025-01-31 17:30:15 +0000 | |
---|---|---|
committer | 2025-01-31 17:56:05 +0000 | |
commit | e57389b5746c5f95aad8b81953a640983dcee871 (patch) | |
tree | 507bfe80b50d3ed3d5ad2603b46e9ee52f8c211f | |
parent | 35d9231411baa43ae214dcf1245f3b570d366e3e (diff) | |
download | dotfiles-e57389b5746c5f95aad8b81953a640983dcee871.tar.gz dotfiles-e57389b5746c5f95aad8b81953a640983dcee871.tar.bz2 dotfiles-e57389b5746c5f95aad8b81953a640983dcee871.zip |
Add curlfire script
-rwxr-xr-x | home/.local/bin/cookiefire | 73 | ||||
-rwxr-xr-x | home/.local/bin/curlfire | 29 |
2 files changed, 102 insertions, 0 deletions
diff --git a/home/.local/bin/cookiefire b/home/.local/bin/cookiefire new file mode 100755 index 0000000..7471f05 --- /dev/null +++ b/home/.local/bin/cookiefire @@ -0,0 +1,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" ; +} diff --git a/home/.local/bin/curlfire b/home/.local/bin/curlfire new file mode 100755 index 0000000..33e1590 --- /dev/null +++ b/home/.local/bin/curlfire @@ -0,0 +1,29 @@ +#!/bin/bash + +set -o errexit +set -o nounset +set -o pipefail + +profile=default-default +skip= +args=() +for var in "$@"; do + # Ignore known bad arguments + case "$var" in + -P) + skip=yes + ;; + *) + if [ -z "$skip" ]; then + args+=("$var") + else + profile=$var + fi; + skip= + esac; +done + + +curlcookies="$(mktemp /tmp/curlcookies.XXXXXXXXXX)" +cookiefire "$profile" > "$curlcookies" +curl -b "$curlcookies" "${args[@]}" ; |