Browse Source

Add Ubuntu 18.04 and 16.04

Also just use one preseed for all. Much cleaner.
master
Teran McKinney 2 years ago
parent
commit
1bbb526fab
  1. 58
      debian-10.go
  2. 58
      debian-9.go
  3. 57
      debian-preseed.go
  4. 6
      ipxeplease.go
  5. 9
      test.sh
  6. 66
      ubuntu-16-04.go
  7. 66
      ubuntu-18-04.go

58
debian-10.go

@ -19,62 +19,6 @@ kernel ${mirror}/linux console=ttyS0,115200n8 net.ifnames=0 netcfg/choose_interf
initrd ${mirror}/initrd.gz
boot`
const debian10_preseed = `d-i debian-installer/locale string en_US
d-i keyboard-configuration/xkb-keymap select us
d-i clock-setup/utc boolean true
d-i time/zone string Etc/UTC
d-i clock-setup/ntp boolean false
# https://superuser.com/a/920957
d-i partman-basicfilesystems/no_swap boolean false
d-i partman-auto/expert_recipe string myroot :: 1000 50 -1 ext4 \
$primary{ } $bootable{ } method{ format } \
format{ } use_filesystem{ } filesystem{ ext4 } \
options/noatime{ noatime } options/nodiratime{ nodiratime } \
mountpoint{ / } \
.
d-i partman-auto/choose_recipe select myroot
d-i partman-auto/method string regular
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto/choose_recipe select atomic
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i apt-setup/non-free boolean false
d-i apt-setup/contrib boolean false
d-i passwd/root-password password {{.PASSWORD}}
d-i passwd/root-password-again password {{.PASSWORD}}
d-i passwd/user-fullname string Debian User
d-i passwd/username string debian
d-i passwd/user-password password {{.PASSWORD}}
d-i passwd/user-password-again password {{.PASSWORD}}
d-i user-setup/allow-password-weak boolean true
d-i base-installer/install-recommends boolean false
tasksel tasksel/first multiselect standard
popularity-contest popularity-contest/participate boolean false
d-i debian-installer/add-kernel-opts string net.ifnames=0
d-i grub-installer/only_debian boolean false
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev string default
d-i finish-install/reboot_in_progress note
d-i preseed/late_command string apt-install openssh-server; in-target mkdir /root/.ssh; in-target sh -c "echo '{{.SSHKEY}}' > /root/.ssh/authorized_keys"; in-target systemctl enable serial-getty@ttyS0.service
`
func debian10(sshKey, burnpaste_endpoint string) (response IPXE, err error) {
// burnpaste_endpoint is a running burnpaste instance to store our preseed data.
var return_script bytes.Buffer
@ -84,7 +28,7 @@ func debian10(sshKey, burnpaste_endpoint string) (response IPXE, err error) {
return
}
tmpl, err := template.New("").Parse(debian10_preseed)
tmpl, err := template.New("").Parse(debian_preseed)
if err != nil {
return
}

58
debian-9.go

@ -19,62 +19,6 @@ kernel ${mirror}/linux console=ttyS0,115200n8 net.ifnames=0 netcfg/choose_interf
initrd ${mirror}/initrd.gz
boot`
const debian9_preseed = `d-i debian-installer/locale string en_US
d-i keyboard-configuration/xkb-keymap select us
d-i clock-setup/utc boolean true
d-i time/zone string Etc/UTC
d-i clock-setup/ntp boolean false
# https://superuser.com/a/920957
d-i partman-basicfilesystems/no_swap boolean false
d-i partman-auto/expert_recipe string myroot :: 1000 50 -1 ext4 \
$primary{ } $bootable{ } method{ format } \
format{ } use_filesystem{ } filesystem{ ext4 } \
options/noatime{ noatime } options/nodiratime{ nodiratime } \
mountpoint{ / } \
.
d-i partman-auto/choose_recipe select myroot
d-i partman-auto/method string regular
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto/choose_recipe select atomic
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i apt-setup/non-free boolean false
d-i apt-setup/contrib boolean false
d-i passwd/root-password password {{.PASSWORD}}
d-i passwd/root-password-again password {{.PASSWORD}}
d-i passwd/user-fullname string Debian User
d-i passwd/username string debian
d-i passwd/user-password password {{.PASSWORD}}
d-i passwd/user-password-again password {{.PASSWORD}}
d-i user-setup/allow-password-weak boolean true
d-i base-installer/install-recommends boolean false
tasksel tasksel/first multiselect standard
popularity-contest popularity-contest/participate boolean false
d-i debian-installer/add-kernel-opts string net.ifnames=0
d-i grub-installer/only_debian boolean false
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev string default
d-i finish-install/reboot_in_progress note
d-i preseed/late_command string apt-install openssh-server; in-target mkdir /root/.ssh; in-target sh -c "echo '{{.SSHKEY}}' > /root/.ssh/authorized_keys"; in-target systemctl enable serial-getty@ttyS0.service
`
func debian9(sshKey, burnpaste_endpoint string) (response IPXE, err error) {
// burnpaste_endpoint is a running burnpaste instance to store our preseed data.
var return_script bytes.Buffer
@ -84,7 +28,7 @@ func debian9(sshKey, burnpaste_endpoint string) (response IPXE, err error) {
return
}
tmpl, err := template.New("").Parse(debian9_preseed)
tmpl, err := template.New("").Parse(debian_preseed)
if err != nil {
return
}

57
debian-preseed.go

@ -0,0 +1,57 @@
package main
const debian_preseed = `d-i debian-installer/locale string en_US
d-i keyboard-configuration/xkb-keymap select us
d-i clock-setup/utc boolean true
d-i time/zone string Etc/UTC
d-i clock-setup/ntp boolean false
# https://superuser.com/a/920957
d-i partman-basicfilesystems/no_swap boolean false
d-i partman-auto/expert_recipe string myroot :: 1000 50 -1 ext4 \
$primary{ } $bootable{ } method{ format } \
format{ } use_filesystem{ } filesystem{ ext4 } \
options/noatime{ noatime } options/nodiratime{ nodiratime } \
mountpoint{ / } \
.
d-i partman-auto/choose_recipe select myroot
d-i partman-auto/method string regular
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto/choose_recipe select atomic
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i apt-setup/non-free boolean false
d-i apt-setup/contrib boolean false
d-i passwd/root-password password {{.PASSWORD}}
d-i passwd/root-password-again password {{.PASSWORD}}
d-i passwd/user-fullname string Debian User
d-i passwd/username string debian
d-i passwd/user-password password {{.PASSWORD}}
d-i passwd/user-password-again password {{.PASSWORD}}
d-i user-setup/allow-password-weak boolean true
d-i base-installer/install-recommends boolean false
tasksel tasksel/first multiselect standard
popularity-contest popularity-contest/participate boolean false
d-i debian-installer/add-kernel-opts string net.ifnames=0
d-i grub-installer/only_debian boolean false
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev string default
d-i finish-install/reboot_in_progress note
d-i preseed/late_command string apt-install openssh-server; in-target mkdir /root/.ssh; in-target sh -c "echo '{{.SSHKEY}}' > /root/.ssh/authorized_keys"; in-target systemctl enable serial-getty@ttyS0.service
`

6
ipxeplease.go

@ -22,6 +22,10 @@ func ipxe(operating_system, ssh_key, burnpaste_endpoint string) (IPXE, error) {
return debian9(ssh_key, burnpaste_endpoint)
case "debian-10":
return debian10(ssh_key, burnpaste_endpoint)
case "ubuntu-16-04":
return ubuntu1604(ssh_key, burnpaste_endpoint)
case "ubuntu-18-04":
return ubuntu1804(ssh_key, burnpaste_endpoint)
default:
return IPXE{}, errors.New(ErrorUnsupportedOS)
}
@ -29,7 +33,7 @@ func ipxe(operating_system, ssh_key, burnpaste_endpoint string) (IPXE, error) {
func list() ([]string, error) {
// This is ugly, needs to be improved. Too redundant.
our_list := []string{"coreos-stable", "debian-9", "debian-10"}
our_list := []string{"coreos-stable", "debian-9", "debian-10", "ubuntu-16-04", "ubuntu-18-04"}
var err error
return our_list, err
}

9
test.sh

@ -33,16 +33,23 @@ fail() {
curl -s --show-error --fail "http://localhost:5555"/list || fail "Should be able to list.."
curl -s --show-error --fail "http://localhost:5555"/list | grep 'debian-9' || fail "debian-9 should be in list"
curl -s --show-error --fail "http://localhost:5555"/list | grep 'debian-9' || fail "debian-9 should be in list"
curl -s --show-error --fail "http://localhost:5555"/list | grep 'debian-10' || fail "debian-10 should be in list"
curl -s --show-error --fail "http://localhost:5555"/list | grep 'ubuntu-16-04' || fail "ubuntu-16-04 should be in list"
curl -s --show-error --fail "http://localhost:5555"/list | grep 'ubuntu-18-04' || fail "ubuntu-18-04 should be in list"
echo '{"operating_system": "coreos-stable", "ssh_key": "ssh-rsa AAAA"}' | curl -d@- -s --show-error --fail "http://localhost:5555"/ipxe | grep -100 'http' || fail "coreos-stable ipxe failed."
# shellcheck disable=SC2028
echo '{"operating_system": "coreos-stable", "ssh_key": "ssh-rsa AAAA\n"}' | curl -d@- -s --show-error --fail "http://localhost:5555"/ipxe | grep -100 'AAAA\n' && fail "SSH key newline stripping failed."
# These require burnpaste to be running.
# burnpaste :2323
# shellcheck disable=SC2028
echo '{"operating_system": "debian-9", "ssh_key": "ssh-rsa AAAA\n"}' | curl -d@- -s --show-error --fail "http://localhost:5555"/ipxe | grep -q 'stretch' || fail "No stretch in debian-9"
# shellcheck disable=SC2028
echo '{"operating_system": "debian-10", "ssh_key": "ssh-rsa AAAA\n"}' | curl -d@- -s --show-error --fail "http://localhost:5555"/ipxe | grep -q 'buster' || fail "No buster in debian-9"
# shellcheck disable=SC2028
echo '{"operating_system": "ubuntu-18-04", "ssh_key": "ssh-rsa AAAA\n"}' | curl -d@- -s --show-error --fail "http://localhost:5555"/ipxe | grep -q 'bionic' || fail "No bionic in ubuntu-18-04"
# shellcheck disable=SC2028
echo '{"operating_system": "ubuntu-16-04", "ssh_key": "ssh-rsa AAAA\n"}' | curl -d@- -s --show-error --fail "http://localhost:5555"/ipxe | grep -q 'xenial' || fail "No xenial in ubuntu-16-04"
cleanup

66
ubuntu-16-04.go

@ -0,0 +1,66 @@
package main
import (
"bytes"
"crypto/md5"
"encoding/hex"
"text/template"
"github.com/teran-mckinney/burnpaste"
)
// Ubuntu Xenial
const ubuntu1604_ipxescript = `#!ipxe
dhcp
set mirror http://archive.ubuntu.com/ubuntu/dists/xenial-updates/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64
kernel ${mirror}/linux console=ttyS0,115200n8 net.ifnames=0 netcfg/choose_interface=eth0 initrd=initrd.gz auto=true priority=critical hostname=ubuntu-16-04 auto url={{.PRESEED}} preseed-md5={{.PRESEED_CHECKSUM}}
initrd ${mirror}/initrd.gz
boot`
func ubuntu1604(sshKey, burnpaste_endpoint string) (response IPXE, err error) {
// burnpaste_endpoint is a running burnpaste instance to store our preseed data.
var return_script bytes.Buffer
var rendered_preseed bytes.Buffer
if err = validateSSHKey(sshKey); err != nil {
return
}
tmpl, err := template.New("").Parse(debian_preseed)
if err != nil {
return
}
type preseed_args struct {
SSHKEY string
PASSWORD string
}
root_password, err := randomPassword()
if err != nil {
return
}
preseed_arguments := preseed_args{SSHKEY: sshKey, PASSWORD: root_password}
tmpl.Execute(&rendered_preseed, preseed_arguments)
hash := md5.Sum(rendered_preseed.Bytes())
hash_hex := hex.EncodeToString(hash[:])
url, err := burnpaste.Write(burnpaste_endpoint, rendered_preseed.Bytes())
if err != nil {
return
}
tmpl, err = template.New("").Parse(ubuntu1604_ipxescript)
if err != nil {
return
}
type args struct {
PRESEED string
PRESEED_CHECKSUM string
}
arguments := args{url, hash_hex}
tmpl.Execute(&return_script, arguments)
response = IPXE{Script: return_script.String(), RootPassword: &root_password}
return
}

66
ubuntu-18-04.go

@ -0,0 +1,66 @@
package main
import (
"bytes"
"crypto/md5"
"encoding/hex"
"text/template"
"github.com/teran-mckinney/burnpaste"
)
// Ubuntu Bionic
const ubuntu1804_ipxescript = `#!ipxe
dhcp
set mirror http://archive.ubuntu.com/ubuntu/dists/bionic-updates/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64
kernel ${mirror}/linux console=ttyS0,115200n8 net.ifnames=0 netcfg/choose_interface=eth0 initrd=initrd.gz auto=true priority=critical hostname=ubuntu-18-04 auto url={{.PRESEED}} preseed-md5={{.PRESEED_CHECKSUM}}
initrd ${mirror}/initrd.gz
boot`
func ubuntu1804(sshKey, burnpaste_endpoint string) (response IPXE, err error) {
// burnpaste_endpoint is a running burnpaste instance to store our preseed data.
var return_script bytes.Buffer
var rendered_preseed bytes.Buffer
if err = validateSSHKey(sshKey); err != nil {
return
}
tmpl, err := template.New("").Parse(debian_preseed)
if err != nil {
return
}
type preseed_args struct {
SSHKEY string
PASSWORD string
}
root_password, err := randomPassword()
if err != nil {
return
}
preseed_arguments := preseed_args{SSHKEY: sshKey, PASSWORD: root_password}
tmpl.Execute(&rendered_preseed, preseed_arguments)
hash := md5.Sum(rendered_preseed.Bytes())
hash_hex := hex.EncodeToString(hash[:])
url, err := burnpaste.Write(burnpaste_endpoint, rendered_preseed.Bytes())
if err != nil {
return
}
tmpl, err = template.New("").Parse(ubuntu1804_ipxescript)
if err != nil {
return
}
type args struct {
PRESEED string
PRESEED_CHECKSUM string
}
arguments := args{url, hash_hex}
tmpl.Execute(&return_script, arguments)
response = IPXE{Script: return_script.String(), RootPassword: &root_password}
return
}
Loading…
Cancel
Save