commit 65138bcf6cf0022346206a4f0348d730810c8d24
parent 5f80089bb159e9517ad428abd06909032e32364b
Author: Daniel Moch <daniel@danielmoch.com>
Date: Sat, 3 Feb 2018 08:08:24 -0500
Use netrc for service passwords
The keyring API requires a running DBus, which I don't want to be
constrained to, especially for cron jobs. Python has a nice netrc API
already, so we just expose that to the command line and allow any
service with password eval capability to use it.
Diffstat:
6 files changed, 49 insertions(+), 15 deletions(-)
diff --git a/.local/bin/my-init b/.local/bin/my-init
@@ -73,8 +73,9 @@ then
log_dir="$HOME/.local/var/log"
cat > /tmp/crontab.$$ <<-EOF
# m h dom mon dow command
+
*/5 * * * * $cron_dir/weather.sh > $log_dir/weather 2>&1
-*/15 * * * * $cron_dir/vdirsyncer.sh > $log_dir/vdirsyncer 2>&1
+*/15 * * * * PATH="$HOME/.local/bin":$PATH $cron_dir/vdirsyncer.sh > $log_dir/vdirsyncer 2>&1
*/15 * * * * $cron_dir/photosync.sh > $log_dir/photosync 2>&1
EOF
diff --git a/.local/bin/my-netrc b/.local/bin/my-netrc
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+#
+# ~/.local/bin/my-netrc
+#
+# Parse .netrc for usernames and passwords. For clients with a password
+# eval feature, but no built-in netrc support.
+import netrc
+import sys
+
+def parse_netrc(host, token=None):
+ authenticators = netrc.netrc().authenticators(host)
+ if authenticators is None:
+ exit('my-netrc: ' + host + ' not found')
+ elif token == 'login':
+ if authenticators[0] is not None:
+ print(authenticators[0])
+ else:
+ exit(host + ' contains no login token')
+ elif token == 'account':
+ if authenticators[1] is not None:
+ print(authenticators[1])
+ else:
+ exit(host + ' contains no account token')
+ elif token == 'password':
+ if authenticators[2] is not None:
+ print(authenticators[2])
+ else:
+ exit(host + ' contains no password token')
+ else:
+ if authenticators[0] is not None:
+ print('login: ' + authenticators[0])
+ if authenticators[1] is not None:
+ print('account: ' + authenticators[1])
+ if authenticators[2] is not None:
+ print('password: ' + authenticators[2])
+
+if __name__ == "__main__":
+ if len(sys.argv) < 2:
+ exit('my-netrc: No request made. Exiting')
+ elif len(sys.argv) == 2:
+ parse_netrc(sys.argv[1])
+ else:
+ parse_netrc(sys.argv[1], sys.argv[2])
diff --git a/.local/lib/cron/vdirsyncer.sh b/.local/lib/cron/vdirsyncer.sh
@@ -1,14 +1,4 @@
#!/bin/sh
echo "Beginning sync on `date`"
-xsession_pid=`cat $HOME/.xsession.pid`
-
-if ps -U $LOGNAME -o pid= | grep $xsession_pid > /dev/null 2>&1 && type vdirsyncer > /dev/null 2>&1
-then
- export DISPLAY=`cat $HOME/.xdisplay`
- vdirsyncer sync
- unset DISPLAY
-else
- echo "No X session running. Aborting"
-fi
-
+vdirsyncer sync
echo "Completed sync on `date`"
diff --git a/.newsboat/bookmark-pinboard.sh b/.newsboat/bookmark-pinboard.sh
@@ -4,7 +4,7 @@
# documentation: https://pinboard.in/api
username="djmoch"
-password="`secret-tool lookup account djmoch service in.pinboard`"
+password="`my-netrc pinboard.in password`"
# You can enter up to 100 tags here, space delimited, or leave blank for no tag
tags="via:newsbeuter"
diff --git a/.newsboat/config b/.newsboat/config
@@ -4,7 +4,7 @@ macro o set browser "open %u" ; open-in-browser ; set browser "w3m %u"
feedhq-flag-share "s"
feedhq-flag-star "x"
feedhq-login "djmoch"
-feedhq-passwordeval "secret-tool lookup account djmoch service org.feedhq"
+feedhq-passwordeval "my-netrc feedhq.org password"
urls-source "feedhq"
bookmark-cmd "~/.newsboat/bookmark-pinboard.sh"
diff --git a/.snclirc b/.snclirc
@@ -1,6 +1,6 @@
[sncli]
cfg_sn_username=djmoch@gmail.com
-cfg_sn_password_eval=secret-tool lookup account djmoch@gmail.com service com.simplenote
+cfg_sn_password_eval=my-netrc simplenote.com password
clr_default_fg=default
clr_default_bg=default
clr_status_bar_fg=black