Ver Fonte

fix: Samba for user-mode networking (#1132)

Kroese há 3 meses atrás
pai
commit
a3a2b3fb09
3 ficheiros alterados com 18 adições e 0 exclusões
  1. 6 0
      src/define.sh
  2. 2 0
      src/install.sh
  3. 10 0
      src/samba.sh

+ 6 - 0
src/define.sh

@@ -1491,6 +1491,12 @@ prepareInstall() {
           echo ""
           echo "Call Domain.MoveHere(LocalAdminADsPath, \"$username\")"
           echo ""
+          echo "Set oFSO = CreateObject(\"Scripting.FileSystemObject\")"
+          echo "Set oHosts = oFSO.GetFile(\"C:\Windows\System32\drivers\etc\hosts\")"
+          echo "Set fileAPPEND = oFSO.OpenTextFile(\"C:\Windows\System32\drivers\etc\hosts\", 8, true)"
+          echo "fileAPPEND.Write(\"${VM_NET_IP%.*}.1      host.lan\")"
+          echo "fileAPPEND.Close()"
+          echo ""
   } | unix2dos > "$dir/\$OEM\$/admin.vbs"
 
   {       echo "[COMMANDS]"

+ 2 - 0
src/install.sh

@@ -628,6 +628,8 @@ updateXML() {
   local language="$2"
   local culture region user admin pass keyboard
 
+  sed -i "s/ 20.20.20.1 / ${VM_NET_IP%.*}.1 /g" "$asset"
+
   [ -z "$HEIGHT" ] && HEIGHT="720"
   [ -z "$WIDTH" ] && WIDTH="1280"
 

+ 10 - 0
src/samba.sh

@@ -14,6 +14,10 @@ if [[ "$DHCP" == [Yy1]* ]]; then
   interface="$VM_NET_DEV"
 fi
 
+if [[ "${NETWORK,,}" == "user"* ]]; then
+  interface="127.0.0.1"
+fi
+
 addShare() {
   local dir="$1"
   local name="$2"
@@ -107,8 +111,14 @@ done
 if ! smbd; then
   error "Samba daemon failed to start!"
   smbd -i --debug-stdout || true
+else
+  if [[ "${NETWORK,,}" == "user"* ]]; then
+    NET_OPTS="${NET_OPTS/,hostfwd/,guestfwd=tcp:${VM_NET_IP%.*}.1:445-tcp:127.0.0.1:445,hostfwd}"
+  fi
 fi
 
+[[ "${NETWORK,,}" == "user"* ]] && return 0
+
 if [[ "${BOOT_MODE:-}" == "windows_legacy" ]]; then
   # Enable NetBIOS on Windows 7 and lower
   if ! nmbd; then