#!/usr/bin/env janet (use sh) (def user "fnurk") (def host "samuelw.dev") (def bin-dir "/opt/tinygram/") (def asset-dir "/srv/tinygram/") (def service-dir "/etc/systemd/system/") (def ssh-target (string user "@" host)) (def bin-target (string ssh-target ":" bin-dir)) (def asset-target (string ssh-target ":" asset-dir)) (def service-target (string ssh-target ":" service-dir)) (def rsync-path ["--rsync-path" "sudo -u tinygram rsync"]) (def rsync-path-sudo ["--rsync-path" "sudo rsync"]) (def rsync-bin-args [;rsync-path "tinygram" bin-target]) (def rsync-asset-args [;rsync-path "-r" "assets" asset-target]) (def rsync-service-args [;rsync-path-sudo "service/tinygram.service" service-target]) (def rsync-service [;rsync-path "-r" "assets" asset-target]) (print "-- building templ --") ($ templ generate) (print "-- building go --") ($ go build ".") (print "-- syncing binary --") ($ rsync ;rsync-bin-args) (print "-- syncing assets --") ($ rsync ;rsync-asset-args) (print "-- creating service locally--") (def template (slurp "service/tinygram.service.template")) (print "-- decrypting env --") ($ agebox decrypt --all) (def envfile (slurp "prod.env")) ($ agebox encrypt --all) (print "-- encrypting env --") (def env-statements (filter (fn [s] (not (empty? s))) (string/split "\n" envfile))) (def env-block (string ;(map (fn [env] (string "Environment=\"" env "\"\n")) env-statements))) (spit "service/tinygram.service" (peg/replace "<1>\n" env-block template)) (print "-- syncing service --") ($ rsync ;rsync-service-args) (print "-- cleaning up service locally --") ($ rm "service/tinygram.service") (print "-- restarting service --") ($ ssh ,ssh-target "sudo systemctl daemon-reload") ($ ssh ,ssh-target "sudo systemctl restart tinygram.service") (print "done!")