xref: /haiku/3rdparty/cloud/sysprep-gce.sh (revision 9a6a20d4689307142a7ed26a1437ba47e244e73f)
1#!/bin/bash
2#
3# For "official" images on https://www.haiku-os.org/guides/virtualizing/google
4#
5# Making a new Google Compute Engine image
6#   * Create a raw disk 4GiB image dd if=/dev/zero of=disk.raw bs=1M count=4096
7#   * Boot VM (qemu-system-x86_64 -cdrom (haiku-release.iso) -hda disk.raw -boot d --enable-kvm -m 4G
8#     * Partition new disk
9#       * 32 MiB EFI System Data. FAT32 named "ESP"
10#       * Rest of disk, Haiku, BFS, named "Haiku"
11#     * Install Haiku to it new disk
12#     * Allow installer to Reboot, *boot again from CD*
13#     * Setup EFI bootloader
14#       * mount "haiku esp", mount "ESP"
15#       * Copy all contents of "haiku esp" to "ESP"
16#       * unmount "haiku esp", unmount "ESP"
17#     * Mount new Haiku install.  (should mount to /Haiku1)
18#     * Run this script (sysprep-gce.sh /Haiku1)
19#     * If r1beta4
20#       * Manually copy over latest r1beta4 haiku, haiku_devel, haiku_data_translations, haiku_loader
21#         * Needed on r1b4 due to / permissions fix needed by sshd
22#     * Shutdown VM.  DO NOT BOOT FROM NEW DISK!
23#       * Booting from new disk will cause SSH host keys to generate! (#18186)
24#   * Compress tar cvzf haiku-r1beta5-x64-v20241024.tar.gz disk.raw
25#   * Upload to google cloud storage bucket for the haiku-inc project (ex: haiku-images/r1beta4/xxx)
26#     ex: gcloud storage cp ./haiku-r1beta5-x64-v20241024.tar.gz  gs://haiku-images/master/haiku-r1beta5-x64-v20241024.tar.gz
27#   * Import image (be sure to update version information below)
28#     ex: gcloud compute images create haiku-r1beta5-x64-v20241024 \
29#       --project=haiku-inc \
30#       --description=Haiku\ R1/Beta5\ x86_64 \
31#       --family=haiku-r1beta5-x64 \
32#       --source-uri=https://storage.googleapis.com/haiku-images/r1beta5/haiku-r1beta5-x64-v20240924.tar.gz \
33#       --labels=os=haiku,release=r1beta5 \
34#       --storage-location=us \
35#       --architecture=X86_64
36#     * Add allAuthenticatedUsers principal to "Compute Image User" role on the new image
37#       permissions to make it public
38
39if [ $# -ne 1 ]; then
40		echo "usage: $0 <HAIKU ROOTFS>"
41		echo "  example: $0 /Haiku1"
42		exit 1;
43fi
44
45SMOL_RELEASE="0.1.1-1"
46TARGET_ROOTFS="$1"
47
48echo "Preparing $TARGET_ROOTFS for Google Compute Engine..."
49echo "WARNING: DO NOT DIRECTLY BOOT FROM THIS HAIKU INSTALL!"
50echo ""
51echo "Installing basic authentication stuff..."
52# Installs gce_metadata_ssh tool for sshd. This lets you control the keys
53# of the "user" user from GKE.  ONLY "user" WORKS! We have no PAM for gce's os-login stuff
54wget https://eu.hpkg.haiku-os.org/haikuports/current/$(uname -m)/current/packages/smolcloudtools-$SMOL_RELEASE-$(uname -m).hpkg \
55	-O $TARGET_ROOTFS/system/packages/smolcloudtools-$SMOL_RELEASE-$(uname -m).hpkg
56
57echo "Configuring ssh..."
58# Configure SSHD (reminder, sshd sees "user" as root since it is UID 0)
59echo "# For Google Compute Engine" >> $TARGET_ROOTFS/system/settings/ssh/sshd_config
60echo "AuthorizedKeysCommand /bin/gce_metadata_ssh" >> $TARGET_ROOTFS/system/settings/ssh/sshd_config
61echo "AuthorizedKeysCommandUser user" >> $TARGET_ROOTFS/system/settings/ssh/sshd_config
62echo "PasswordAuthentication no" >> $TARGET_ROOTFS/system/settings/ssh/sshd_config
63echo "PermitRootLogin without-password" >> $TARGET_ROOTFS/system/settings/ssh/sshd_config
64
65echo "Configuring kernel..."
66# GCP likes serial debug data on com0 (helps in troubleshooting)
67sed -i "s/^serial_debug_output .*$/serial_debug_output true/g" $TARGET_ROOTFS/home/config/settings/kernel/drivers/kernel
68sed -i "s/^serial_debug_port .*$/serial_debug_port 0/g" $TARGET_ROOTFS/home/config/settings/kernel/drivers/kernel
69
70unmount $TARGET_ROOTFS
71
72echo "Complete!  Please shutdown VM. DO NOT BOOT FROM NEW OS IMAGE!"
73