2020-01-26 11:59:13 +01:00
|
|
|
build {
|
|
|
|
sources = [
|
|
|
|
"source.hcloud.main"
|
|
|
|
]
|
|
|
|
|
|
|
|
provisioner "file" {
|
|
|
|
direction = "upload"
|
2020-02-06 20:06:08 +01:00
|
|
|
source = "./rootfs"
|
|
|
|
destination = "/tmp"
|
2020-01-26 11:59:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "shell" {
|
|
|
|
environment_vars = [
|
2020-02-06 20:02:31 +01:00
|
|
|
"DPKG_FORCE=confold",
|
2020-01-26 11:59:13 +01:00
|
|
|
"DEBIAN_FRONTEND=noninteractive"
|
|
|
|
]
|
2020-02-06 20:02:31 +01:00
|
|
|
inline_shebang = "/bin/sh -eux"
|
2020-01-26 11:59:13 +01:00
|
|
|
inline = [
|
2020-02-06 20:02:31 +01:00
|
|
|
<<EOF
|
2020-02-06 20:06:08 +01:00
|
|
|
find /tmp/rootfs/ -type d -exec chmod 755 '{}' ';' -exec chown root:root '{}' ';'
|
|
|
|
find /tmp/rootfs/ -type f -exec chmod 644 '{}' ';' -exec chown root:root '{}' ';'
|
|
|
|
find /tmp/rootfs/ -type f -regex '.+/\(bin\|cron\..+\)/.+' -exec chmod 755 '{}' ';'
|
2020-02-06 20:58:18 +01:00
|
|
|
find /tmp/rootfs/ -type f -regex '.+/\(etc/wireguard\)/.+' -exec chmod 600 '{}' ';'
|
2020-02-07 22:28:11 +01:00
|
|
|
find /tmp/rootfs/ -mindepth 1 -maxdepth 1 -exec cp -fla '{}' / ';'
|
2020-02-06 20:06:08 +01:00
|
|
|
rm -rf /tmp/rootfs/
|
2020-02-06 20:02:31 +01:00
|
|
|
EOF
|
|
|
|
,
|
2020-02-06 20:22:40 +01:00
|
|
|
<<EOF
|
|
|
|
timedatectl set-timezone UTC
|
|
|
|
localectl set-locale LANG=en_US.UTF-8
|
|
|
|
EOF
|
|
|
|
,
|
2020-02-06 20:02:31 +01:00
|
|
|
<<EOF
|
|
|
|
apt-get update
|
2020-02-06 20:17:29 +01:00
|
|
|
apt-get dist-upgrade -yo DPkg::options::=--force-confold
|
|
|
|
EOF
|
|
|
|
,
|
|
|
|
<<EOF
|
|
|
|
apt-get install -yo DPkg::options::=--force-confold \
|
|
|
|
dns-root-data \
|
|
|
|
fail2ban \
|
|
|
|
htop \
|
|
|
|
iperf3 \
|
2020-03-02 22:17:18 +01:00
|
|
|
linux-generic \
|
2020-02-06 20:17:29 +01:00
|
|
|
nano \
|
|
|
|
openresolv \
|
|
|
|
qrencode \
|
|
|
|
ssh-import-id \
|
|
|
|
ufw \
|
|
|
|
unattended-upgrades \
|
|
|
|
unbound
|
|
|
|
EOF
|
|
|
|
,
|
|
|
|
<<EOF
|
2020-02-06 20:24:28 +01:00
|
|
|
printf "deb http://ppa.launchpad.net/wireguard/wireguard/ubuntu/ $(lsb_release -cs) main\n" > /etc/apt/sources.list.d/wireguard.list
|
2020-02-06 20:17:29 +01:00
|
|
|
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E1B39B6EF6DDB96564797591AE33835F504A1A25
|
|
|
|
apt-get update && apt-get install -yo DPkg::options::=--force-confold wireguard
|
2020-02-06 20:02:31 +01:00
|
|
|
EOF
|
|
|
|
,
|
|
|
|
<<EOF
|
|
|
|
systemctl disable --now systemd-resolved.service
|
|
|
|
unlink /etc/resolv.conf && printf 'nameserver 127.0.0.1\n' > /etc/resolv.conf
|
|
|
|
systemctl enable --now unbound.service unbound-resolvconf.service
|
|
|
|
EOF
|
|
|
|
,
|
|
|
|
<<EOF
|
|
|
|
systemctl enable --now fail2ban.service ufw.service unattended-upgrades.service
|
2020-03-02 22:21:36 +01:00
|
|
|
systemctl enable wg-quick@wg0.service
|
2020-02-06 20:02:31 +01:00
|
|
|
EOF
|
|
|
|
,
|
|
|
|
<<EOF
|
|
|
|
ufw --force enable
|
|
|
|
ufw default deny incoming
|
|
|
|
ufw default allow outgoing
|
|
|
|
ufw allow from any to any port 22 proto tcp
|
|
|
|
EOF
|
|
|
|
,
|
|
|
|
<<EOF
|
2020-02-06 20:17:29 +01:00
|
|
|
groupadd --system ssh-user
|
|
|
|
usermod --append --groups ssh-user root
|
2020-02-06 20:02:31 +01:00
|
|
|
passwd -d root
|
|
|
|
EOF
|
|
|
|
,
|
|
|
|
<<EOF
|
|
|
|
rm -f /etc/ssh/ssh_host_*key*
|
|
|
|
rm -f /etc/wireguard/*-*key
|
|
|
|
rm -f /etc/wireguard/*-iface
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
EOF
|
2020-01-26 11:59:13 +01:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|