diff --git a/embedded/network/vmnet_arm64.tar.gz b/embedded/network/vmnet_arm64.tar.gz index 39e063bc3..f12b6b972 100644 Binary files a/embedded/network/vmnet_arm64.tar.gz and b/embedded/network/vmnet_arm64.tar.gz differ diff --git a/embedded/network/vmnet_x86_64.tar.gz b/embedded/network/vmnet_x86_64.tar.gz index 4f9d07c0b..5e82a0611 100644 Binary files a/embedded/network/vmnet_x86_64.tar.gz and b/embedded/network/vmnet_x86_64.tar.gz differ diff --git a/environment/vm/lima/network/installer.go b/environment/vm/lima/network/installer.go index 2e810e516..fb7ac956e 100644 --- a/environment/vm/lima/network/installer.go +++ b/environment/vm/lima/network/installer.go @@ -14,19 +14,23 @@ import ( type rootfulInstaller struct{ host environment.HostActions } func (r rootfulInstaller) Installed(file rootfulFile) bool { - stat, err := os.Stat(file.Path()) - if err != nil { - return false - } - if file.Executable() { - return stat.Mode()&0100 != 0 + for _, f := range file.Paths() { + stat, err := os.Stat(f) + if err != nil { + return false + } + if file.Executable() { + if stat.Mode()&0100 == 0 { + return false + } + } } return true } func (r rootfulInstaller) Install(file rootfulFile) error { return file.Install(r.host) } type rootfulFile interface { - Path() string + Paths() []string Executable() bool Install(host environment.HostActions) error } @@ -35,7 +39,7 @@ var _ rootfulFile = sudoerFile{} type sudoerFile struct{} -func (s sudoerFile) Path() string { return "/etc/sudoers.d/colima" } +func (s sudoerFile) Paths() []string { return []string{"/etc/sudoers.d/colima"} } func (s sudoerFile) Executable() bool { return false } func (s sudoerFile) Install(host environment.HostActions) error { // read embedded file contents @@ -44,11 +48,13 @@ func (s sudoerFile) Install(host environment.HostActions) error { return fmt.Errorf("error retrieving embedded sudo file: %w", err) } // ensure parent directory exists - if err := host.RunInteractive("sudo", "mkdir", "-p", filepath.Dir(s.Path())); err != nil { + path := s.Paths()[0] + dir := filepath.Dir(path) + if err := host.RunInteractive("sudo", "mkdir", "-p", dir); err != nil { return fmt.Errorf("error preparing sudoers directory: %w", err) } // persist file to desired location - if err := host.RunInteractive("sudo", "sh", "-c", fmt.Sprintf(`echo "%s" > %s`, txt, s.Path())); err != nil { + if err := host.RunInteractive("sudo", "sh", "-c", fmt.Sprintf(`echo "%s" > %s`, txt, path)); err != nil { return fmt.Errorf("error writing sudoers file: %w", err) } return nil @@ -57,10 +63,13 @@ func (s sudoerFile) Install(host environment.HostActions) error { var _ rootfulFile = vmnetFile{} const VmnetBinary = "/opt/colima/bin/vde_vmnet" +const vmnetLibrary = "/opt/colima/lib/libvdeplug.3.dylib" type vmnetFile struct{} -func (s vmnetFile) Path() string { return VmnetBinary } +func (s vmnetFile) Paths() []string { + return []string{VmnetBinary, vmnetLibrary} +} func (s vmnetFile) Executable() bool { return true } func (s vmnetFile) Install(host environment.HostActions) error { arch := "x86_64" @@ -85,7 +94,7 @@ func (s vmnetFile) Install(host environment.HostActions) error { _ = f.Close() // not a fatal error // extract tar to desired location - dir := filepath.Dir(s.Path()) + dir := "/opt/colima" if err := host.RunInteractive("sudo", "mkdir", "-p", dir); err != nil { return fmt.Errorf("error preparing colima privileged dir: %w", err) } @@ -99,14 +108,14 @@ var _ rootfulFile = colimaVmnetFile{} type colimaVmnetFile struct{} -func (s colimaVmnetFile) Path() string { return "/opt/colima/bin/colima-vmnet" } +func (s colimaVmnetFile) Paths() []string { return []string{"/opt/colima/bin/colima-vmnet"} } func (s colimaVmnetFile) Executable() bool { return true } func (s colimaVmnetFile) Install(host environment.HostActions) error { arg0, _ := exec.LookPath(os.Args[0]) if arg0 == "" { // should never happen arg0 = os.Args[0] } - if err := host.RunInteractive("sudo", "ln", "-sfn", arg0, s.Path()); err != nil { + if err := host.RunInteractive("sudo", "ln", "-sfn", arg0, s.Paths()[0]); err != nil { return fmt.Errorf("error creating colima-vmnet binary: %w", err) } return nil diff --git a/scripts/build_vmnet.sh b/scripts/build_vmnet.sh index a2dd224e3..a371c8ca8 100755 --- a/scripts/build_vmnet.sh +++ b/scripts/build_vmnet.sh @@ -18,8 +18,9 @@ clone https://github.com/lima-vm/vde_vmnet.git $DIR_VMNET clone https://github.com/virtualsquare/vde-2.git $DIR_VDE build_x86_64() ( - export PREFIX=$DIR_BUILD/dist/x86_64 - mkdir -p $PREFIX + export PREFIX=/opt/colima + sudo rm -rf $PREFIX + sudo mkdir -p $PREFIX # vde-2 ( @@ -31,7 +32,7 @@ build_x86_64() ( ./configure --prefix=$PREFIX make PREFIX=$PREFIX - make PREFIX=$PREFIX install + sudo make PREFIX=$PREFIX install # cleanup make distclean ) @@ -40,22 +41,23 @@ build_x86_64() ( ( cd $DIR_VMNET make PREFIX=$PREFIX - make PREFIX=$PREFIX install.bin + sudo make PREFIX=$PREFIX install.bin ) # copy to embed directory ( - mkdir -p $EMBED_DIR - VMNET_FILE=$PREFIX/bin/vde_vmnet - cp $VMNET_FILE $EMBED_DIR - cd "$(dirname ${VMNET_FILE})" && tar cvfz $EMBED_DIR/vmnet_x86_64.tar.gz "$(basename ${VMNET_FILE})" - rm $EMBED_DIR/vde_vmnet + mkdir -p $EMBED_DIR/vmnet/bin $EMBED_DIR/vmnet/lib + cp $PREFIX/bin/vde_vmnet $EMBED_DIR/vmnet/bin + cp $PREFIX/lib/libvdeplug.3.dylib $EMBED_DIR/vmnet/lib + cd $EMBED_DIR/vmnet && tar cvfz $EMBED_DIR/vmnet_x86_64.tar.gz bin/vde_vmnet lib/libvdeplug.3.dylib + rm -rf $EMBED_DIR/vmnet + sudo rm -rf /opt/colima ) ) build_arm64() ( - export PREFIX=$DIR_BUILD/dist/arm64 - mkdir -p $PREFIX + export PREFIX=/opt/colima + sudo mkdir -p $PREFIX export SDKROOT=$(xcrun --sdk macosx --show-sdk-path) export CC=$(xcrun --sdk macosx --find clang) @@ -73,7 +75,7 @@ build_arm64() ( ./configure --prefix=$PREFIX --host=arm-apple-darwin --target=arm-apple-darwin --build=x86_64-apple-darwin make PREFIX=$PREFIX - make PREFIX=$PREFIX install + sudo make PREFIX=$PREFIX install # cleanup make distclean ) @@ -82,16 +84,17 @@ build_arm64() ( ( cd $DIR_VMNET make PREFIX=$PREFIX - make PREFIX=$PREFIX install.bin + sudo make PREFIX=$PREFIX install.bin ) # copy to embed directory ( - mkdir -p $EMBED_DIR - VMNET_FILE=$PREFIX/bin/vde_vmnet - cp $VMNET_FILE $EMBED_DIR - cd "$(dirname ${VMNET_FILE})" && tar cvfz $EMBED_DIR/vmnet_arm64.tar.gz "$(basename ${VMNET_FILE})" - rm $EMBED_DIR/vde_vmnet + mkdir -p $EMBED_DIR/vmnet/bin $EMBED_DIR/vmnet/lib + cp $PREFIX/bin/vde_vmnet $EMBED_DIR/vmnet/bin + cp $PREFIX/lib/libvdeplug.3.dylib $EMBED_DIR/vmnet/lib + cd $EMBED_DIR/vmnet && tar cvfz $EMBED_DIR/vmnet_arm64.tar.gz bin/vde_vmnet lib/libvdeplug.3.dylib + rm -rf $EMBED_DIR/vmnet + sudo rm -rf /opt/colima ) )