aboutsummaryrefslogtreecommitdiff
path: root/tw/system.scm
diff options
context:
space:
mode:
Diffstat (limited to 'tw/system.scm')
-rw-r--r--tw/system.scm40
1 files changed, 23 insertions, 17 deletions
diff --git a/tw/system.scm b/tw/system.scm
index 34f398a8..e62ad095 100644
--- a/tw/system.scm
+++ b/tw/system.scm
@@ -125,33 +125,39 @@
(with-extensions (list guile-json-4 guile-gnutls) ; guile-gnutls needed by (web client)
#~(begin
(use-modules ((srfi srfi-11) #:select (let-values))
+ ((ice-9 textual-ports) #:select (get-string-all))
+ (ice-9 format)
(json)
(web client)
(web response))
(define api-url "https://ipapi.co/json")
+ (define headers '((user-agent . "tw-dotfiles/0.0 (abuse@twilken.net)")))
;; According to the Arch Wiki, when checking for "up" as the second
;; argument, VPN connections could cause undesired timezone changes.
(when (and (string=? "connectivity-change" (caddr (command-line)))
(string=? "FULL" (getenv "CONNECTIVITY_STATE")))
- (let-values (((response text) (http-get api-url)))
+ (let-values (((response body-port) (http-get api-url #:headers headers #:streaming? #t)))
(unless (= 200 (response-code response))
- (error "Got error response to request:" response))
- (let* ((json (json-string->scm text))
- (timezone (assoc-ref json "timezone"))
- (zonefile (string-append #$tzdata "/share/zoneinfo/" timezone))
- (regdb-country (assoc-ref json "country_code"))
- (error-code
- (status:exit-val
- ;; Set WiFi regulatory domain to use the correct channels.
- (system* #$(file-append iw "/bin/iw") "reg" "set" regdb-country))))
- (format (current-error-port) "Updated WiFi regdomain to ~a: ~a~%"
- regdb-country (if (zero? error-code) "success"
- (format #f "error ~d" error-code)))
+ (error "Got error response to request:"
+ (response-code response) (get-string-all body-port)))
+ (let ((json (json->scm body-port)))
+ (when (assoc-ref json "error")
+ (error "Got error response to request:"
+ (assoc-ref json "reason") (assoc-ref json "message")))
+ ;; Set WiFi regulatory domain to use the correct channels.
+ (let* ((regdb-country (assoc-ref json "country_code"))
+ (error-code
+ (system* #$(file-append iw "/sbin/iw") "reg" "set" regdb-country)))
+ (format (current-error-port) "Updated WiFi regdomain to ~a: ~a~%"
+ regdb-country (if (status:exit-val error-code) "success"
+ (format #f "error ~d" error-code))))
;; Set local timezone.
- (delete-file "/etc/localtime")
- (symlink zonefile "/etc/localtime")
- (format (current-error-port)
- "Updated timezone to ~a: success~%" timezone)))))))
+ (let* ((timezone (assoc-ref json "timezone"))
+ (zonefile (string-append #$tzdata "/share/zoneinfo/" timezone)))
+ (delete-file "/etc/localtime")
+ (symlink zonefile "/etc/localtime")
+ (format (current-error-port)
+ "Updated timezone to ~a: success~%" timezone))))))))
;; This text is added verbatim to the Xorg config file.
(define touchpad-xorg-config "\