-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-server.bash
110 lines (100 loc) · 2.67 KB
/
setup-server.bash
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
set -euo pipefail
echo "-- Beginning Traccar server setup script"
echo "--> Update and upgrade packages"
apt-get --quiet --yes remove snapd
apt-mark hold snapd
apt-get --quiet --yes --no-install-recommends update
apt-get --quiet --yes --no-install-recommends upgrade
echo "--> Install, configure and start tailscale"
curl \
--fail \
--silent \
--show-error \
--location \
https://tailscale.com/install.sh |
sh
cat <<EOF >/etc/sysctl.d/99-tailscale.conf
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1
EOF
sysctl --load=/etc/sysctl.d/99-tailscale.conf
# shellcheck disable=SC2154
tailscale \
up \
--authkey="${tailscale_authkey}" \
--hostname="${tailscale_hostname}" \
--ssh=true
tailscale serve --bg 8082
echo "--> Disable multipathd"
systemctl disable --now multipathd
echo "--> Mount storage volume"
# shellcheck disable=SC2154
storage_name=$(
lsblk \
--output name,size |
grep "${storage_volume_size}G" |
awk '{ print $1 }'
)
# shellcheck disable=SC2154
storage_uuid=$(
lsblk \
--output name,size,UUID |
grep "${storage_volume_size}G" |
awk '{ print $3 }'
)
if ! file \
--special-files \
--dereference \
"/dev/$storage_name" |
grep --silent ext4; then
mkfs.ext4 "/dev/$storage_name"
fi
mkdir /storage
echo "UUID=$storage_uuid /storage ext4 defaults,nofail 0 2" >>/etc/fstab
systemctl daemon-reload
mount "/dev/$storage_name" /storage
mount --all
chown ubuntu:ubuntu --recursive /storage
echo "--> Install and configure podman"
# https://github.com/containers/podman/issues/10556
mkdir --parents /etc/containers
curl \
--fail \
--silent \
--show-error \
--location \
https://github.com/containers/common/raw/main/pkg/seccomp/seccomp.json \
>/etc/containers/seccomp.json
mkdir --parents /home/ubuntu/.config/containers/
cat <<EOF >/home/ubuntu/.config/containers/storage.conf
[storage]
driver = "overlay"
runroot = "/run/user/1000/containers"
graphroot = "/storage"
EOF
chown ubuntu:ubuntu --recursive /home/ubuntu/.config
apt-get \
--quiet \
--yes \
--no-install-recommends \
install \
podman \
slirp4netns \
uidmap
loginctl enable-linger ubuntu
systemctl --machine=ubuntu@ --user --now enable podman.socket
echo "--> Install and start traccar systemd unit"
mkdir --parents /home/ubuntu/.config/containers/systemd
cat <<EOF >/home/ubuntu/.config/containers/systemd/traccar.kube
[Install]
WantedBy=default.target
[Unit]
Description=Traccar
[Kube]
Yaml=/storage/traccar.yaml
EOF
chown ubuntu:ubuntu --recursive /home/ubuntu/.config/containers/systemd
systemctl --machine=ubuntu@ --user daemon-reload
systemctl --machine=ubuntu@ --user start traccar || true
echo "-- Completed Traccar server setup script"