2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2021-07-13 17:45:09 +00:00
|
|
|
|
|
|
|
package vms
|
|
|
|
|
2021-07-16 19:25:16 +00:00
|
|
|
import (
|
|
|
|
_ "embed"
|
2022-05-06 21:16:10 +00:00
|
|
|
"encoding/json"
|
2021-07-16 19:25:16 +00:00
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/tailscale/hujson"
|
|
|
|
)
|
|
|
|
|
2021-07-13 17:45:09 +00:00
|
|
|
type Distro struct {
|
2021-07-16 19:25:16 +00:00
|
|
|
Name string // amazon-linux
|
|
|
|
URL string // URL to a qcow2 image
|
|
|
|
SHA256Sum string // hex-encoded sha256 sum of contents of URL
|
|
|
|
MemoryMegs int // VM memory in megabytes
|
|
|
|
PackageManager string // yum/apt/dnf/zypper
|
|
|
|
InitSystem string // systemd/openrc
|
2022-04-11 18:58:06 +00:00
|
|
|
HostGenerated bool // generated image rather than downloaded
|
2021-07-13 17:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Distro) InstallPre() string {
|
2021-07-16 19:25:16 +00:00
|
|
|
switch d.PackageManager {
|
2021-07-13 17:45:09 +00:00
|
|
|
case "yum":
|
|
|
|
return ` - [ yum, update, gnupg2 ]
|
2021-07-22 19:24:52 +00:00
|
|
|
- [ yum, "-y", install, iptables ]
|
|
|
|
- [ sh, "-c", "printf '\n\nUseDNS no\n\n' | tee -a /etc/ssh/sshd_config" ]
|
|
|
|
- [ systemctl, restart, "sshd.service" ]`
|
2021-07-13 17:45:09 +00:00
|
|
|
case "zypper":
|
|
|
|
return ` - [ zypper, in, "-y", iptables ]`
|
|
|
|
|
|
|
|
case "dnf":
|
|
|
|
return ` - [ dnf, install, "-y", iptables ]`
|
|
|
|
|
|
|
|
case "apt":
|
|
|
|
return ` - [ apt-get, update ]
|
|
|
|
- [ apt-get, "-y", install, curl, "apt-transport-https", gnupg2 ]`
|
|
|
|
|
|
|
|
case "apk":
|
|
|
|
return ` - [ apk, "-U", add, curl, "ca-certificates", iptables, ip6tables ]
|
|
|
|
- [ modprobe, tun ]`
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2021-07-16 19:25:16 +00:00
|
|
|
//go:embed distros.hujson
|
|
|
|
var distroData string
|
2021-07-13 17:45:09 +00:00
|
|
|
|
2021-07-16 19:25:16 +00:00
|
|
|
var Distros []Distro = func() []Distro {
|
|
|
|
var result []Distro
|
2022-05-06 21:16:10 +00:00
|
|
|
b, err := hujson.Standardize([]byte(distroData))
|
2021-07-16 19:25:16 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("error decoding distros: %v", err)
|
|
|
|
}
|
2022-05-06 21:16:10 +00:00
|
|
|
if err := json.Unmarshal(b, &result); err != nil {
|
|
|
|
log.Fatalf("error decoding distros: %v", err)
|
|
|
|
}
|
2021-07-16 19:25:16 +00:00
|
|
|
return result
|
|
|
|
}()
|