github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/dashboard/config/openbsd/recreate.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright 2021 syzkaller project authors. All rights reserved.
     4  # Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     5  
     6  # Rebuilds ci-openbsd in syzkaller project. Helpfully munges the
     7  # .ssh/known_hosts file since the new image has a fresh key.
     8  #
     9  # DROPS files in the current directory, so best used from a subdir of /tmp.
    10  #
    11  # The user is expected to have the private key matching
    12  # the public keys baked into create-openbsd* scripts and a
    13  # section in their .ssh/config similar to this:
    14  #  Host ci-openbsd
    15  #  Hostname ci-openbsd # if running on a project VM or the external IP
    16  #  User syzkaller
    17  #  IdentityFile ~/.ssh/id_syzkaller
    18  
    19  # Before running first time do:
    20  # sudo apt-get install genisoimage growisofs qemu qemu-kvm qemu-system-x86-64 expect
    21  
    22  # The script does not require any arguments/env vars, run just as:
    23  # $GOPATH/src/github.com/google/syzkaller/dashboard/config/openbsd/recreate.sh
    24  
    25  set -eux
    26  
    27  TODAY=$(date -u +%Y-%m-%d)
    28  
    29  SYZ_DIR="$(cd "$(dirname "${0}")"/../../..; pwd -P)"
    30  [[ -d "${SYZ_DIR}/tools" ]] || { echo "Requires syzkaller dir $SYZ_DIR" ; exit 1; }
    31  
    32  ZONE=us-central1-b
    33  INSTANCE=ci-openbsd
    34  HOST="${HOST:-${INSTANCE}}"
    35  IP=$(gcloud compute instances describe "${INSTANCE}" --zone="${ZONE}" --project=syzkaller '--format=text(networkInterfaces[].accessConfigs[].natIP)' | cut -f2 -d' ')
    36  SERVICE_ACCOUNT=$(gcloud compute instances describe "${INSTANCE}" --zone="${ZONE}" --project=syzkaller  '--format=text(serviceAccounts[].email)' | cut -d' ' -f2)
    37  IMAGE="${INSTANCE}"-"${TODAY}"-root
    38  
    39  "${SYZ_DIR}"/tools/create-openbsd-gce-ci.sh
    40  
    41  gsutil -u syzkaller cp -a public-read openbsd-amd64-snapshot-gce.tar.gz gs://syzkaller/openbsd-amd64-"${TODAY}"-gce.tar.gz
    42  
    43  ssh root@"${HOST}" halt -p || true
    44  
    45  yes | gcloud compute --project=syzkaller images delete "${IMAGE}" || true
    46  gcloud compute --project=syzkaller images create "${IMAGE}" --source-uri gs://syzkaller/"openbsd-amd64-${TODAY}-gce.tar.gz"
    47  
    48  yes | gcloud compute --project=syzkaller instances delete "${INSTANCE}" \
    49    --zone="${ZONE}"
    50  gcloud compute --project=syzkaller \
    51    instances create "${INSTANCE}" \
    52    --address="${IP}" \
    53    --private-network-ip "${INSTANCE}"-internal \
    54    --boot-disk-device-name="${INSTANCE}" \
    55    --boot-disk-size=10GB \
    56    --boot-disk-type=pd-ssd \
    57    --disk=name="${INSTANCE}"-syzkaller,device-name="${INSTANCE}"-syzkaller,mode=rw,boot=no \
    58    --image-project=syzkaller \
    59    --image="${IMAGE}" \
    60    --machine-type=custom-12-65536 \
    61    --maintenance-policy=MIGRATE \
    62    --metadata=serial-port-enable=1 \
    63    --network-tier=PREMIUM \
    64    --scopes=https://www.googleapis.com/auth/cloud-platform \
    65    --service-account="${SERVICE_ACCOUNT}" \
    66    --subnet=default \
    67    --zone="${ZONE}"
    68  
    69  (grep -v "^$IP" ~/.ssh/known_hosts && echo "${IP}" "$(grep ssh-ed25519 install_log)") > ~/.ssh/known_hosts.new
    70  mv  ~/.ssh/known_hosts{.new,}
    71  
    72  "${SYZ_DIR}"/tools/create-openbsd-vmm-worker.sh
    73  
    74  ssh syzkaller@"${HOST}" mkdir -p /syzkaller/userspace
    75  ssh syzkaller@"${HOST}" ln -sf /syzkaller/{gopath/src/github.com/google/syzkaller/dashboard/,}config
    76  scp worker_key syzkaller@"${HOST}":/syzkaller/userspace/key
    77  scp -C worker_disk.raw syzkaller@"${HOST}":/syzkaller/userspace/image
    78  ssh syzkaller@"${HOST}" 'D=/syzkaller/userspace-multicore && mkdir -p $D && ln -sf ../userspace/{image,key} $D && ln -sf ../config/openbsd/overlays/ci-openbsd-multicore $D/overlay'
    79  ssh root@"${HOST}" reboot