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

     1  # Copyright 2015 The Go Authors. All rights reserved.
     2  # Use of this source code is governed by a BSD-style
     3  # license that can be found in the LICENSE file.
     4  
     5  set -e
     6  
     7  arch=$1
     8  platform=$2
     9  
    10  if [ ! $# -eq 2 ]; then
    11  	echo 'usage: make.bash [ 386 | amd64 ] [ qemu | gce ]' 2>&1
    12  	exit 1
    13  fi
    14  
    15  if [ "$arch" != 386 ] && [ "$arch" != amd64 ]; then
    16  	echo 'supported architectures are 386 and amd64' 2>&1
    17  	exit 1
    18  fi
    19  
    20  case "$platform" in
    21  	qemu)
    22  		disk=sd00
    23  		;;
    24  	gce)
    25  		disk=sd01
    26  		;;
    27  	*)
    28  		echo 'supported platforms are qemu and gce' 2>&1
    29  		exit 1
    30  		;;
    31  esac
    32  
    33  # Download Plan 9
    34  if ! sha1sum -c plan9-gce.iso.sha1; then
    35    curl --fail -O http://9legacy.org/download/go/2018-11-30/plan9-gce.iso.bz2
    36    bunzip2 plan9-gce.iso.bz2
    37    sha1sum -c plan9-gce.iso.sha1
    38  fi
    39  
    40  # Initialize disk image.
    41  rm -f disk.raw
    42  qemu-img create -f raw disk.raw 10G
    43  
    44  # Run the installer to create the disk image.
    45  expect <<EOF
    46  spawn qemu-system-i386 -machine accel=kvm -nographic -net user -net nic,model=virtio -m 1024 -vga none -drive if=none,id=hd,file=disk.raw -device virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd -cdrom plan9-gce.iso -boot d
    47  
    48  expect -exact "Selection:"
    49  send "1\n"
    50  
    51  expect -exact "Plan 9"
    52  sleep 5
    53  
    54  # Need to wait for the kernel to boot.
    55  expect -timeout 600 -exact "use DMA for ide drives\[yes\]:"
    56  send "\n"
    57  
    58  expect -exact "mouseport is (ps2, ps2intellimouse, 0, 1, 2)\[ps2\]:"
    59  send "ps2intellimouse\n"
    60  
    61  expect -exact "vgasize \[640x480x8\]:"
    62  send "1280x1024x32\n"
    63  
    64  expect -exact "monitor is \[xga\]:"
    65  send "vesa\n"
    66  
    67  expect -exact "% "
    68  send "inst/textonly\n"
    69  
    70  expect -exact "Task to do \[configfs\]:"
    71  send "\n"
    72  
    73  expect -exact "File system (fossil, fossil+venti)\[fossil\]:"
    74  send "\n"
    75  
    76  expect -exact "Task to do \[partdisk\]:"
    77  send "\n"
    78  
    79  expect -exact "Disk to partition (sd00, sdD0)\[no default\]:"
    80  send "sd00\n"
    81  
    82  expect -exact "Install mbr \(y, n\)\[no default\]:"
    83  send "y\n"
    84  
    85  expect -exact ">>> "
    86  send "w\n"
    87  
    88  expect -exact ">>> "
    89  send "q\n"
    90  
    91  expect -exact "Task to do \[prepdisk\]:"
    92  send "\n"
    93  
    94  expect -exact "Plan 9 partition to subdivide \(/dev/sd00/plan9\)\[/dev/sd00/plan9\]:"
    95  send "\n"
    96  
    97  expect -exact ">>> "
    98  send "w\n"
    99  
   100  expect -exact ">>> "
   101  send "q\n"
   102  
   103  expect -exact "Task to do \[fmtfossil\]:"
   104  send "\n"
   105  
   106  expect -exact "Fossil partition to format \(/dev/sd00/fossil\)\[/dev/sd00/fossil\]:"
   107  send "\n"
   108  
   109  expect -exact "Task to do \[mountfs\]:"
   110  send "\n"
   111  
   112  expect -exact "Fossil partition \(/dev/sd00/fossil\)\[/dev/sd00/fossil\]:"
   113  send "\n"
   114  
   115  expect -exact "Task to do \[configdist\]:"
   116  send "\n"
   117  
   118  expect -exact "Distribution is from \(local, net\)\[local\]:"
   119  send "\n"
   120  
   121  expect -exact "Task to do \[mountdist\]:"
   122  send "\n"
   123  
   124  expect -exact "Distribution disk \[no default\]:"
   125  send "/dev/sdD0/data\n"
   126  
   127  expect -exact "Location of archives \[browse\]:"
   128  send "/\n"
   129  
   130  expect -exact "Task to do \[copydist\]:"
   131  send "\n"
   132  
   133  # Need to wait for the copy to finish.
   134  expect -timeout 600 -exact "Task to do \[bootsetup\]:"
   135  send "\n"
   136  
   137  expect -exact "Enable boot method (floppy, plan9, win9x, winnt)\[no default\]:"
   138  send "plan9\n"
   139  
   140  expect -exact "Install the Plan 9 master boot record (y, n)\[no default\]:"
   141  send "y\n"
   142  
   143  expect -exact "Task to do \[finish\]:"
   144  send "\n"
   145  
   146  expect -exact "Feel free to turn off your computer."
   147  exit
   148  EOF
   149  
   150  # Configuration.
   151  expect <<EOF
   152  spawn qemu-system-i386 -machine accel=kvm -nographic -net user -net nic,model=virtio -m 1024 -vga none -drive if=none,id=hd,file=disk.raw -device virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd -cdrom plan9-gce.iso -boot c
   153  
   154  expect -exact "Plan 9"
   155  sleep 5
   156  
   157  # Need to wait for the kernel to boot.
   158  expect -timeout 600 -exact "term% "
   159  send "\n"
   160  
   161  expect -exact "term% "
   162  send "mkdir /cfg/helix\n"
   163  
   164  expect -exact "term% "
   165  send "dircp /cfg/example /cfg/helix\n"
   166  
   167  expect -exact "term% "
   168  send "echo ip/ipconfig -o mtu >>/cfg/helix/cpurc\n"
   169  
   170  expect -exact "term% "
   171  send "echo ndb/dns -r >>/cfg/helix/cpurc\n"
   172  
   173  expect -exact "term% "
   174  send "echo echo remove 10.0.0.0 /104 10.0.0.0 '>'/net/iproute >>/cfg/helix/cpurc\n"
   175  
   176  expect -exact "term% "
   177  send "echo ramfs -su >>/cfg/helix/cpustart\n"
   178  
   179  expect -exact "term% "
   180  send "echo mount -c /srv/ramfs /tmp >>/cfg/helix/cpustart\n"
   181  
   182  expect -exact "term% "
   183  send "echo aux/randfs -m /dev >>/cfg/helix/cpustart\n"
   184  
   185  expect -exact "term% "
   186  send "echo kill timesync '|' rc >>/cfg/helix/cpustart\n"
   187  
   188  expect -exact "term% "
   189  send "echo >>/cfg/helix/cpustart\n"
   190  
   191  expect -exact "term% "
   192  send "echo echo downloading git >>/cfg/helix/cpustart\n"
   193  
   194  expect -exact "term% "
   195  send "echo hget http://9legacy.org/9legacy/tools/git '>'/usr/glenda/bin/rc/git >>/cfg/helix/cpustart\n"
   196  
   197  expect -exact "term% "
   198  send "echo chmod +x /usr/glenda/bin/rc/git >>/cfg/helix/cpustart\n"
   199  
   200  expect -exact "term% "
   201  send "echo >>/cfg/helix/cpustart\n"
   202  
   203  expect -exact "term% "
   204  send "echo echo starting buildlet script >>/cfg/helix/cpustart\n"
   205  
   206  expect -exact "term% "
   207  send "echo 'hget \`{hget -r '''Metadata-Flavor: Google''' http://metadata.google.internal/computeMetadata/v1/instance/attributes/buildlet-binary-url} >/tmp/buildlet' >>/cfg/helix/cpustart\n"
   208  
   209  expect -exact "term% "
   210  send "echo chmod +x /tmp/buildlet >>/cfg/helix/cpustart\n"
   211  
   212  expect -exact "term% "
   213  send "echo exec /tmp/buildlet >>/cfg/helix/cpustart\n"
   214  
   215  expect -exact "term% "
   216  send "echo fshalt >>/cfg/helix/cpustart\n"
   217  
   218  expect -exact "term% "
   219  send "sed /exec/d \\\$home/lib/profile >\\\$home/lib/profile.new && mv \\\$home/lib/profile.new \\\$home/lib/profile\n"
   220  
   221  expect -exact "term% "
   222  send "auth/wrkey\n"
   223  
   224  expect -exact "authid: "
   225  send "glenda\n"
   226  
   227  expect -exact "authdom: "
   228  send "go\n"
   229  
   230  expect -exact "auth password: "
   231  send "glenda123\n"
   232  
   233  expect -exact "secstore password: "
   234  send "glenda123\n"
   235  
   236  expect -exact "term% "
   237  send "fshalt\n"
   238  
   239  expect -exact "done halting"
   240  exit
   241  EOF
   242  
   243  if [ "$arch" == "amd64" ]; then
   244  	expect <<EOF
   245  	spawn qemu-system-i386 -machine accel=kvm -nographic -net user -net nic,model=virtio -m 1024 -vga none -drive if=none,id=hd,file=disk.raw -device virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd -cdrom plan9-gce.iso -boot c
   246  
   247  	expect -exact "Plan 9"
   248  	sleep 5
   249  
   250  	# Need to wait for the kernel to boot.
   251  	expect -timeout 600 -exact "term% "
   252  	send "\n"
   253  
   254  	expect -exact "term% "
   255  	send "echo 'aux/listen1 tcp!*!17007 /bin/exportfs -a &' >>/cfg/helix/cpurc\n"
   256  
   257  	expect -exact "term% "
   258  	send "echo 'aux/listen1 tcp!*!17010 /bin/cpu -R &' >>/cfg/helix/cpurc\n"
   259  
   260  	expect -exact "term% "
   261  	send "mkdir /usr/glenda/bin/amd64\n"
   262  
   263  	expect -exact "term% "
   264  	send "9fat:\n"
   265  
   266  	expect -exact "term% "
   267  	send "cp /amd64/9k10cpuf /n/9fat\n"
   268  
   269  	expect -exact "term% "
   270  	send "sed s/9pcf/9k10cpuf/ /n/9fat/plan9.ini >/tmp/plan9.ini\n"
   271  
   272  	expect -exact "term% "
   273  	send "mv /tmp/plan9.ini /n/9fat/plan9.ini\n"
   274  
   275  	expect -exact "term% "
   276  	send "sed s/sd00/$disk/ /n/9fat/plan9.ini >/tmp/plan9.ini\n"
   277  
   278  	expect -exact "term% "
   279  	send "mv /tmp/plan9.ini /n/9fat/plan9.ini\n"
   280  
   281  	expect -exact "term% "
   282  	send "unmount /n/9fat\n"
   283  
   284  	expect -exact "term% "
   285  	send "fossil/conf /dev/sd00/fossil | sed s/sd00/$disk/ >/tmp/fossil.conf\n"
   286  
   287  	expect -exact "term% "
   288  	send "fossil/conf -w /dev/sd00/fossil /tmp/fossil.conf\n"
   289  
   290  	expect -exact "term% "
   291  	send "rm /tmp/fossil.conf\n"
   292  
   293  	expect -exact "term% "
   294  	send "fshalt\n"
   295  
   296  	expect -exact "done halting"
   297  EOF
   298  else
   299  	expect <<EOF
   300  	spawn qemu-system-i386 -machine accel=kvm -nographic -net user -net nic,model=virtio -m 1024 -vga none -drive if=none,id=hd,file=disk.raw -device virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd -cdrom plan9-gce.iso -boot c
   301  
   302  	expect -exact "Plan 9"
   303  	sleep 5
   304  
   305  	# Need to wait for the kernel to boot.
   306  	expect -timeout 600 -exact "term% "
   307  	send "\n"
   308  
   309  	expect -exact "term% "
   310  	send "9fat:\n"
   311  
   312  	expect -exact "term% "
   313  	send "cp /386/9pccpuf /n/9fat\n"
   314  
   315  	expect -exact "term% "
   316  	send "sed s/9pcf/9pccpuf/ /n/9fat/plan9.ini >/tmp/plan9.ini\n"
   317  
   318  	expect -exact "term% "
   319  	send "mv /tmp/plan9.ini /n/9fat/plan9.ini\n"
   320  
   321  	expect -exact "term% "
   322  	send "sed s/sd00/$disk/ /n/9fat/plan9.ini >/tmp/plan9.ini\n"
   323  
   324  	expect -exact "term% "
   325  	send "mv /tmp/plan9.ini /n/9fat/plan9.ini\n"
   326  
   327  	expect -exact "term% "
   328  	send "unmount /n/9fat\n"
   329  
   330  	expect -exact "term% "
   331  	send "fossil/conf /dev/sd00/fossil | sed s/sd00/$disk/ >/tmp/fossil.conf\n"
   332  
   333  	expect -exact "term% "
   334  	send "fossil/conf -w /dev/sd00/fossil /tmp/fossil.conf\n"
   335  
   336  	expect -exact "term% "
   337  	send "rm /tmp/fossil.conf\n"
   338  
   339  	expect -exact "term% "
   340  	send "fshalt\n"
   341  
   342  	expect -exact "done halting"
   343  EOF
   344  fi
   345  
   346  echo
   347  
   348  if [ "$platform" == qemu ]; then
   349  	echo "Done. QEMU image is disk.raw."
   350  	exit
   351  fi
   352  
   353  # Create Compute Engine disk image.
   354  echo "Archiving disk.raw... (this may take a while)"
   355  tar -Szcf plan9-$arch-gce.tar.gz disk.raw
   356  
   357  echo "Done. GCE image is plan9-$arch-gce.tar.gz."