| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | set -eu -o pipefail |
| 7 | |
| 8 | scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 9 | |
| 10 | source "${scriptdir}/common.inc.sh" |
| 11 | cd "${scriptdir}/.." |
| 12 | |
| 13 | if [ "$#" -ne 2 ]; then |
| 14 | ERROR "Usage: $0 OLDVER NEWVER" |
| 15 | exit 1 |
| 16 | fi |
| 17 | |
| 18 | OLDVER="$1" |
| 19 | NEWVER="$2" |
| 20 | |
| 21 | PREFIX="/usr/local" |
| 22 | function install_lima() { |
| 23 | ver="$1" |
| 24 | git checkout "${ver}" |
| 25 | make clean |
| 26 | make |
| 27 | if [ -w "${PREFIX}/bin" ] && [ -w "${PREFIX}/share" ] && [ -w "${PREFIX}/libexec" ]; then |
| 28 | make install |
| 29 | else |
| 30 | sudo make install |
| 31 | fi |
| 32 | } |
| 33 | |
| 34 | function install_lima_binary() { |
| 35 | ver="$1" |
| 36 | tar="tar" |
| 37 | if [ ! -w "${PREFIX}/bin" ] || [ ! -w "${PREFIX}/share" ] || [ ! -w "${PREFIX}/libexec" ]; then |
| 38 | tar="sudo ${tar}" |
| 39 | fi |
| 40 | curl -fsSL "https://github.com/lima-vm/lima/releases/download/${ver}/lima-${ver:1}-$(uname -s)-$(uname -m).tar.gz" | ${tar} Cxzvm "${PREFIX}" |
| 41 | } |
| 42 | |
| 43 | function uninstall_lima() { |
| 44 | files="${PREFIX}/bin/lima ${PREFIX}/bin/limactl ${PREFIX}/share/lima ${PREFIX}/share/doc/lima ${PREFIX}/libexec/lima" |
| 45 | if [ -w "${PREFIX}/bin" ] && [ -w "${PREFIX}/share" ] && [ -w "${PREFIX}/libexec" ]; then |
| 46 | |
| 47 | rm -rf $files |
| 48 | else |
| 49 | |
| 50 | sudo rm -rf $files |
| 51 | fi |
| 52 | } |
| 53 | |
| 54 | function show_lima_log() { |
| 55 | tail -n 100 ~/.lima/"${LIMA_INSTANCE}"/*.log || true |
| 56 | mkdir -p failure-logs |
| 57 | cp -pf ~/.lima/"${LIMA_INSTANCE}"/*.log failure-logs/ || true |
| 58 | limactl shell "${LIMA_INSTANCE}" sudo cat /var/log/cloud-init-output.log | tee failure-logs/cloud-init-output.log || true |
| 59 | } |
| 60 | |
| 61 | INFO "Uninstalling lima" |
| 62 | uninstall_lima |
| 63 | |
| 64 | INFO "Installing the old Lima ${OLDVER}" |
| 65 | install_lima_binary "${OLDVER}" || install_lima "${OLDVER}" |
| 66 | |
| 67 | export LIMA_INSTANCE="test-upgrade" |
| 68 | |
| 69 | INFO "Creating an instance \"${LIMA_INSTANCE}\" with the old Lima" |
| 70 | defer "show_lima_log;limactl delete -f \"${LIMA_INSTANCE}\"" |
| 71 | limactl start --tty=false --name="${LIMA_INSTANCE}" template://ubuntu-lts || ( |
| 72 | show_lima_log |
| 73 | exit 1 |
| 74 | ) |
| 75 | lima nerdctl info |
| 76 | |
| 77 | image_name="lima-test-upgrade-containerd-${RANDOM}" |
| 78 | image_context="${HOME}/${image_name}" |
| 79 | INFO "Building containerd image \"${image_name}\" from \"${image_context}\"" |
| 80 | defer "rm -rf \"${image_context}\"" |
| 81 | mkdir -p "${image_context}" |
| 82 | cat <<EOF >"${image_context}"/Dockerfile |
| 83 | # Use GHCR to avoid hitting Docker Hub rate limit |
| 84 | FROM ghcr.io/containerd/alpine:3.14.0 |
| 85 | CMD ["echo", "Built with Lima ${OLDVER}"] |
| 86 | EOF |
| 87 | lima nerdctl build -t "${image_name}" "${image_context}" |
| 88 | lima nerdctl run --rm "${image_name}" |
| 89 | |
| 90 | INFO "Stopping the instance" |
| 91 | limactl stop "${LIMA_INSTANCE}" |
| 92 | |
| 93 | INFO "==============================================================================" |
| 94 | |
| 95 | INFO "Installing the new Lima ${NEWVER}" |
| 96 | install_lima "${NEWVER}" |
| 97 | |
| 98 | INFO "Editing the instance to specify vm-type as qemu explicitly" |
| 99 | limactl edit --vm-type=qemu "${LIMA_INSTANCE}" |
| 100 | |
| 101 | INFO "Restarting the instance" |
| 102 | limactl start --tty=false --vm-type=qemu "${LIMA_INSTANCE}" || show_lima_log |
| 103 | lima nerdctl info |
| 104 | |
| 105 | INFO "Confirming that the host filesystem is still mounted" |
| 106 | "${scriptdir}"/test-mount-home.sh "${LIMA_INSTANCE}" |
| 107 | |
| 108 | INFO "Confirming that the image \"${image_name}\" still exists" |
| 109 | lima nerdctl run --rm "${image_name}" |