blob: 24cb246bf990129895c866fc85a3dd3d19c2e6f6 (
plain)
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
|
#!/usr/bin/env janet
(use sh)
## Check we've got the tools we need, an excuse to test macros
(def missing-tools @[])
(defmacro checktool [tool-name]
~(try
($< ,tool-name | @"")
([err] (if
(string/has-prefix? "spawn failed" err)
(array/push missing-tools ,tool-name)))))
(checktool 'templ)
(checktool 'go)
(checktool 'rsync)
(if (any? missing-tools)
(do
(print (string "missing these tools: "
(string/join missing-tools " ")))
(os/exit 1)))
## Set up our variables
(def user "fnurk")
(def host "samuelw.dev")
(def appname "tinygram") # also user
(def binaryname "tinygram")
(def bin-dir (string "/opt/" appname "/"))
(def asset-dir (string "/srv/" appname "/"))
(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" (string "sudo -u " appname " rsync")])
(def rsync-path-sudo ["--rsync-path" "sudo rsync"])
(def rsync-bin-args [;rsync-path binaryname bin-target])
(def rsync-asset-args [;rsync-path "-r" "assets" asset-target])
(def rsync-service-args [;rsync-path-sudo "service/tinygram.service" service-target])
##Build and rsync the files!!
(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 "-- syncing service --")
($ rsync ;rsync-service-args)
(print "-- cleaning up binary --")
($ rm "tinygram")
(print "-- restarting service --")
($ ssh ,ssh-target "sudo systemctl daemon-reload")
($ ssh ,ssh-target "sudo systemctl restart tinygram.service")
(print "done!")
|