-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
executable file
·50 lines (41 loc) · 1.14 KB
/
script.sh
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
#!/bin/bash
set -eu
build() {
local pkg='github.com/movsb/on-ip-changed/utils/version'
local builtOn="$USER@${HOSTNAME:-$(hostname)}"
local builtAt="${DATE:-$(date +'%F %T %z')}"
local goVersion=$(go version | sed 's/go version //')
local gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
local gitCommit=$(git rev-parse --short HEAD)
local ldflags="\
-X '$pkg.BuiltOn=$builtOn' \
-X '$pkg.BuiltAt=$builtAt' \
-X '$pkg.GoVersion=$goVersion' \
-X '$pkg.GitAuthor=$gitAuthor' \
-X '$pkg.GitCommit=$gitCommit' \
"
go build -ldflags "$ldflags" -v
}
systemd() {
[[ $EUID -ne 0 ]] && echo Please run this command as root. 2>&1 && exit 1
local serviceName=on-ip-changed
local serviceFullName="$serviceName".service
local binPath="$(pwd)/$serviceName"
local binDir=$(dirname "$binPath")
cat <<-EOF > /etc/systemd/system/"$serviceFullName"
[Unit]
Description=On IP Changed
After=network.target
After=network-online.target
[Service]
ExecStart="$binPath" daemon
WorkingDirectory=$binDir
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target
EOF
systemctl enable "$serviceFullName"
systemctl restart "$serviceFullName"
}
"$@"