golang.org/x/build@v0.0.0-20240506185731-218518f32b70/env/openbsd-amd64/make.bash (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2014 The Go Authors. All rights reserved.
     3  # Use of this source code is governed by a BSD-style
     4  # license that can be found in the LICENSE file.
     5  
     6  set -e
     7  set -u
     8  
     9  # Update to the version listed on https://openbsd.org
    10  readonly VERSION="${VERSION:-7.2}"
    11  readonly RELNO="${VERSION/./}"
    12  readonly SNAPSHOT=false
    13  
    14  readonly ARCH="${ARCH:-amd64}"
    15  readonly MIRROR="${MIRROR:-cdn.openbsd.org}"
    16  
    17  readonly WORK="$(mktemp -d)"
    18  readonly SITE="${WORK}/site"
    19  
    20  if [[ "${ARCH}" != "amd64" && "${ARCH}" != "i386" ]]; then
    21    echo "ARCH must be amd64 or i386"
    22    exit 1
    23  fi
    24  
    25  readonly ISO="install${RELNO}-${ARCH}.iso"
    26  readonly ISO_PATCHED="install${RELNO}-${ARCH}-patched.iso"
    27  
    28  if [[ ! -f "${ISO}" ]]; then
    29    DIR="${VERSION}"
    30    if [[ "$SNAPSHOT" = true ]]; then
    31      DIR="snapshots"
    32    fi
    33    curl -o "${ISO}" "https://${MIRROR}/pub/OpenBSD/${DIR}/${ARCH}/install${RELNO}.iso"
    34  fi
    35  
    36  function cleanup() {
    37  	rm -rf "${WORK}"
    38  }
    39  
    40  trap cleanup EXIT INT
    41  
    42  # Create custom siteXX.tgz set.
    43  PKG_ADD_OPTIONS="-I"
    44  if [[ "$SNAPSHOT" = true ]]; then
    45    PKG_ADD_OPTIONS="-I -D snap"
    46  fi
    47  mkdir -p ${SITE}/etc
    48  cat >${SITE}/install.site <<EOF
    49  #!/bin/sh
    50  echo 'set tty com0' > boot.conf
    51  EOF
    52  
    53  cat >${SITE}/etc/installurl <<EOF
    54  https://${MIRROR}/pub/OpenBSD
    55  EOF
    56  cat >${SITE}/etc/rc.firsttime <<EOF
    57  set -x
    58  cat > /etc/login.conf.d/moreres <<'EOLOGIN'
    59  moreres:\
    60    :datasize-max=infinity: \
    61    :datasize-cur=infinity: \
    62    :vmemoryuse-max=infinity: \
    63    :vmemoryuse-cur=infinity: \
    64    :memoryuse-max=infinity: \
    65    :memoryuse-cur=infinity: \
    66    :maxproc-max=1024: \
    67    :maxproc-cur=1024: \
    68    :openfiles-max=4096: \
    69    :openfiles-cur=4096: \
    70    :tc=default:
    71  EOLOGIN
    72  usermod -L moreres swarming
    73  syspatch
    74  # Run syspatch twice in case syspatch itself needs patching (this is the case with OpenBSD
    75  # 7.1: https://www.openbsd.org/errata71.html )
    76  syspatch
    77  pkg_add -iv ${PKG_ADD_OPTIONS} bash curl git python3 sudo--gettext
    78  chown root:wheel /etc/sudoers
    79  halt -p
    80  EOF
    81  
    82  cat >${SITE}/etc/rc.local <<EOF
    83  (
    84    set -x
    85  
    86    echo "Remounting root with softdep,noatime..."
    87    mount -o softdep,noatime,update /
    88  
    89    echo "starting buildlet script"
    90    netstat -rn
    91    cat /etc/resolv.conf
    92    dig metadata.google.internal
    93    (
    94      set -e
    95      export PATH="\$PATH:/usr/local/bin"
    96      project=\$(curl -s -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/project/project-id)
    97      case "\$project" in
    98        *luci*)
    99          gcehost=\$(curl -s -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/hostname | cut -d . -f 1)
   100          swarming=\$(curl -s -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/attributes/swarming | cut -d . -f 1)
   101          su -l swarming -c "/usr/local/bin/bootstrapswarm --hostname \$gcehost --swarming \${swarming}.appspot.com"
   102        ;;
   103        *)
   104          /usr/local/bin/curl -o /buildlet \$(/usr/local/bin/curl --fail -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/attributes/buildlet-binary-url)
   105          chmod +x /buildlet
   106          exec /buildlet
   107        ;;
   108      esac
   109    )
   110    echo "giving up"
   111    (
   112      sleep 60
   113      halt -p
   114    )&
   115  )
   116  EOF
   117  cat >${SITE}/etc/sysctl.conf <<EOF
   118  hw.smt=1
   119  kern.timecounter.hardware=tsc
   120  EOF
   121  cat >${SITE}/etc/sudoers <<EOF
   122  root ALL=(ALL:ALL) ALL
   123  swarming ALL=NOPASSWD:/sbin/shutdown -r now
   124  EOF
   125  chmod +x ${SITE}/install.site
   126  mkdir -p ${SITE}/usr/local/bin
   127  CGO_ENABLED=0 GOOS=openbsd GOARCH=${ARCH/i386/386} go1.21.0 build -o ${SITE}/usr/local/bin/bootstrapswarm golang.org/x/build/cmd/bootstrapswarm
   128  tar --mode a=rx,u=rwx --owner root:0 --group wheel:0 -C ${SITE} -zcf ${WORK}/site${RELNO}.tgz .
   129  
   130  # Autoinstall script.
   131  cat >${WORK}/auto_install.conf <<EOF
   132  System hostname = openbsd-amd64
   133  Which network interface = vio0
   134  IPv4 address for vio0 = dhcp
   135  IPv6 address for vio0 = none
   136  Password for root account = root
   137  Do you expect to run the X Window System = no
   138  Change the default console to com0 = yes
   139  Which speed should com0 use = 115200
   140  Setup a user = swarming
   141  Full name for user swarming = Swarming Gopher Gopherson
   142  Password for user swarming = swarming
   143  Allow root ssh login = no
   144  What timezone = US/Pacific
   145  Which disk = sd0
   146  Use (W)hole disk or (E)dit the MBR = whole
   147  Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout = auto
   148  URL to autopartitioning template for disklabel = file://disklabel.template
   149  Location of sets = cd0
   150  Set name(s) = +* -x* -game* -man* done
   151  Directory does not contain SHA256.sig. Continue without verification = yes
   152  EOF
   153  
   154  # Disklabel template.
   155  cat >${WORK}/disklabel.template <<EOF
   156  /	5G-*	95%
   157  swap	1G
   158  EOF
   159  
   160  # Hack install CD a bit.
   161  echo 'set tty com0' > ${WORK}/boot.conf
   162  dd if=/dev/urandom of=${WORK}/random.seed bs=4096 count=1
   163  cp "${ISO}" "${ISO_PATCHED}"
   164  growisofs -M "${ISO_PATCHED}" -l -R -graft-points \
   165    /${VERSION}/${ARCH}/site${RELNO}.tgz=${WORK}/site${RELNO}.tgz \
   166    /auto_install.conf=${WORK}/auto_install.conf \
   167    /disklabel.template=${WORK}/disklabel.template \
   168    /etc/boot.conf=${WORK}/boot.conf \
   169    /etc/random.seed=${WORK}/random.seed
   170  
   171  # Initialize disk image.
   172  rm -f ${WORK}/disk.raw
   173  qemu-img create -f raw ${WORK}/disk.raw 30G
   174  
   175  # Run the installer to create the disk image.
   176  expect <<EOF
   177  set timeout 1800
   178  
   179  spawn qemu-system-x86_64 -nographic -smp 2 \
   180    -drive if=virtio,file=${WORK}/disk.raw,format=raw -cdrom "${ISO_PATCHED}" \
   181    -net nic,model=virtio -net user -boot once=d
   182  
   183  expect timeout { exit 1 } "boot>"
   184  send "\n"
   185  
   186  # Need to wait for the kernel to boot.
   187  expect timeout { exit 1 } "\(I\)nstall, \(U\)pgrade, \(A\)utoinstall or \(S\)hell\?"
   188  send "s\n"
   189  
   190  expect timeout { exit 1 } "# "
   191  send "mount /dev/cd0c /mnt\n"
   192  send "cp /mnt/auto_install.conf /mnt/disklabel.template /\n"
   193  send "chmod a+r /disklabel.template\n"
   194  send "umount /mnt\n"
   195  send "exit\n"
   196  
   197  expect timeout { exit 1 } "CONGRATULATIONS!"
   198  expect timeout { exit 1 } eof
   199  EOF
   200  
   201  # Create Compute Engine disk image.
   202  echo "Archiving disk.raw... (this may take a while)"
   203  tar -C ${WORK} -Szcf "openbsd-${VERSION}-${ARCH}-gce.tar.gz" disk.raw
   204  
   205  echo "Done. GCE image is openbsd-${VERSION}-${ARCH}-gce.tar.gz."