diff --git a/.github/workflows/vm.yml b/.github/workflows/vm.yml index 98bfee006..a62cf5fb2 100644 --- a/.github/workflows/vm.yml +++ b/.github/workflows/vm.yml @@ -100,13 +100,13 @@ jobs: sudo apt update case ${{ matrix.arch }} in aarch64) - sudo apt install -y --no-install-recommends netcat-traditional qemu-system-aarch64 qemu-efi-aarch64 ipxe-qemu + sudo apt install -y --no-install-recommends ncat qemu-system-aarch64 qemu-efi-aarch64 ipxe-qemu ;; x86 | amd64) - sudo apt install -y --no-install-recommends netcat-traditional qemu-system-x86 + sudo apt install -y --no-install-recommends ncat qemu-system-x86 ;; armv6) - sudo apt install -y --no-install-recommends netcat-traditional qemu-system-arm + sudo apt install -y --no-install-recommends ncat qemu-system-arm ;; *) echo "Don't know what to install" @@ -138,7 +138,7 @@ jobs: if [ "${{ matrix.os }}-${{ matrix.arch }}" == "raspios-armv6" ]; then # qemu doesn't really support armv6 shutting down (if that's a thing anyway???) # Instead linux kernel panics because init is exiting. Let's wait for that. - vm/wait_for_string.sh 'not syncing: Attempted to kill init' nc.traditional localhost 2222 + vm/wait_for_string.sh 'not syncing: Attempted to kill init' ncat --no-shutdown localhost 2222 kill -INT $(cat vm/${{ matrix.os }}-${{ matrix.arch }}/pid.txt) else echo "Waiting for VM to shut down..." diff --git a/vm/README.md b/vm/README.md index 7061a91c4..a4595659f 100644 --- a/vm/README.md +++ b/vm/README.md @@ -60,10 +60,12 @@ Here are some guidelines for working on the scripts: - Use `set -e -o pipefail`. If this gets in your way, use `|| true` only in the places that need it. This way failures are not silenced except where you expect to get failures. -- Use `nc.traditional` instead of `nc`. There are several different versions of - netcat, and they are similar but incompatible in subtle ways. For example, - `echo | nc ...` doesn't work as expected with `ncat`, because `ncat` closes - the connection when it gets EOF on stdin. +- Use `ncat` instead of `nc`. The `nc` command can be any of several different + netcat implementations: it may be same as `ncat`, or something else. The + different implementations are similar but incompatible in subtle ways. For + example, when `nc` gets EOF on stdin, some `nc` implementations (like `ncat`) + close the connection while others keep it open. I chose to use `ncat` because + it is available with the same name in most linux distros. - Use the [`wait_for_string.sh`](./wait_for_string.sh) script instead of the `expect` program, for two reasons: - Jou developers already need to know at least 4 programming languages, and @@ -71,7 +73,7 @@ Here are some guidelines for working on the scripts: - `expect` would be an unnecessary dependency. Dependencies (in addition to what you need for Jou anyway): -- All architectures and operating systems: `sudo apt install wget openssh-client netcat-traditional` +- All architectures and operating systems: `sudo apt install wget openssh-client ncat` - x86: `sudo apt install qemu-system-x86` - aarch64: `sudo apt install qemu-system-aarch64 qemu-efi-aarch64 ipxe-qemu` - armv6: `sudo apt install qemu-system-arm` diff --git a/vm/alpine.sh b/vm/alpine.sh index ab4b3b89a..3b23b90d8 100755 --- a/vm/alpine.sh +++ b/vm/alpine.sh @@ -65,13 +65,13 @@ if ! [ -f disk.img ]; then qemu_pid=$! echo "Waiting for temporary VM to boot so we can install alpine..." - until echo | ../wait_for_string.sh 'localhost login:' nc.traditional localhost 4444; do + until echo | ../wait_for_string.sh 'localhost login:' ncat --no-shutdown localhost 4444; do sleep 1 kill -0 $qemu_pid # Stop if qemu dies done echo "Logging in to temporary VM..." - echo root | ../wait_for_string.sh 'localhost:~#' nc.traditional localhost 4444 + echo root | ../wait_for_string.sh 'localhost:~#' ncat --no-shutdown localhost 4444 echo "Installing alpine..." echo " @@ -82,7 +82,7 @@ setup-alpine -f answerfile -e y sync poweroff -" | nc.traditional localhost 4444 +" | ncat --no-shutdown localhost 4444 wait # Make sure qemu has died before we proceed further trap - EXIT # Don't delete disk.img when we exit fi diff --git a/vm/netbsd.sh b/vm/netbsd.sh index 21c673d15..ff5254a71 100755 --- a/vm/netbsd.sh +++ b/vm/netbsd.sh @@ -92,7 +92,7 @@ if ! timeout 5 ../ssh.sh echo hello; then # We consider the VM started when it shows login prompt on serial port. # At that point it has also started ssh. echo "Waiting for VM to boot..." - until echo | ../wait_for_string.sh 'login:' nc.traditional localhost 4444; do + until echo | ../wait_for_string.sh 'login:' ncat --no-shutdown localhost 4444; do sleep 1 kill -0 $qemu_pid # Stop if qemu dies done @@ -105,7 +105,7 @@ mkdir .ssh chmod 700 .ssh echo '$(../keygen.sh)' > .ssh/authorized_keys echo ALL'DONE'NOW -exit" | ../wait_for_string.sh 'ALLDONENOW' nc.traditional localhost 4444 +exit" | ../wait_for_string.sh 'ALLDONENOW' ncat --no-shutdown localhost 4444 echo "Now ssh setup is done, let's check one last time..." ../ssh.sh echo hello # Check that it works fi diff --git a/vm/raspios.sh b/vm/raspios.sh index 720fe0d41..b881550f4 100755 --- a/vm/raspios.sh +++ b/vm/raspios.sh @@ -181,7 +181,7 @@ else disown echo "Waiting for VM to boot..." - until echo | ../wait_for_string.sh 'raspberrypi login:' nc.traditional localhost 4444; do + until echo | ../wait_for_string.sh 'raspberrypi login:' ncat --no-shutdown localhost 4444; do sleep 1 kill -0 $qemu_pid # Stop if qemu dies done diff --git a/vm/wait_for_string.sh b/vm/wait_for_string.sh index feba4b1c0..5efdfd101 100755 --- a/vm/wait_for_string.sh +++ b/vm/wait_for_string.sh @@ -9,7 +9,7 @@ # For example, this logs in as root to serial console on localhost:4444, and # waits until the shell prompt appears: # -# $ echo root | ./wait_for_string.sh "root@localhost:~#" nc.traditional localhost 4444 +# $ echo root | ./wait_for_string.sh "root@localhost:~#" ncat --no-shutdown localhost 4444 # # Here is another example, which is more useful for developing this script. It # tells Python to print "blah" and "foobar", with 1 second delays before and