<commit_before># -*- powershell -*-

# Constants
$TMCCBIN    = "C:\Cygwin\usr\local\etc\emulab\tmcc.bin"
$TMCCARGS   = "-s","boss.emulab.net","-t","30"
$CYGBINPATH = "C:\Cygwin\bin"
$LOGFILE    = "C:\Temp\setnodename.log"

# Log to $LOGFILE
Function log($msg) {
   $time = Get-Date -format g
   ($time + ": " + $msg) | Out-File -append $LOGFILE
}

# Update the path to include Cygwin's /bin directory (including Cygwin1.dll)
$env:path += ";$CYGBINPATH"

$NameObj = Get-WmiObject Win32_ComputerSystem
$CurName = $NameObj.Item("name")

$NodeID = & $TMCCBIN $TMCCARGS nodeid
if (!$? -or $NodeID -eq "UNKNOWN" -or !$NodeID) {
   log("tmcc nodeid failed!")
   exit(1)
}

if ($NodeID -ne $CurName) {
   log("Computer name change required: $CurName -> $NodeID")
   if (!$NameObj.rename($NodeID)) {
      log("Name change failed: " + $Error)
      exit(1)
   } else {
      log("Node rename succeeded - reboot required")
   }
} else {
  log("Current node name is correct - no changes made")
}

exit(0)
<commit_msg>Changes to the setnodename.ps1 script to that allow it to work properly under Windows 7's mini-setup environment.  Specifically, switch from using WMI to change the hostname (unsupported under mini-setup) to poking directly at the registry.<commit_after># -*- powershell -*-

# Constants
$TMCCBIN    = "C:\Cygwin\usr\local\etc\emulab\tmcc.bin"
$TMCCARGS   = "-s","boss.emulab.net","-t","30"
$CYGBINPATH = "C:\Cygwin\bin"
$LOGFILE    = "C:\Temp\setnodename.log"
$CNPATH     = "HKLM:\System\CurrentControlSet\Control\ComputerName\ComputerName"
$HNPATH     = "HKLM:\System\CurrentControlSet\Services\Tcpip\Parameters"

# Log to $LOGFILE
Function log($msg) {
   $time = Get-Date -format g
   ($time + ": " + $msg) | Out-File -append $LOGFILE
}

# Update the path to include Cygwin's /bin directory (including Cygwin1.dll)
$env:path += ";$CYGBINPATH"

# XXX: This doesn't work under mini-setup
#$NameObj = Get-WmiObject Win32_ComputerSystem
#$CurName = $NameObj.Item("name")
$CurName = $env:computername

$NodeID = & $TMCCBIN $TMCCARGS nodeid
if (!$? -or $NodeID -eq "UNKNOWN" -or !$NodeID) {
   log("tmcc nodeid failed!")
   exit(1)
}

# Change the node's name to nodeid from Emulab Central, if required
if ($NodeID -ne $CurName) {
   log("Computer name change required: $CurName -> $NodeID")
# XXX: Doesn't work under mini-setup
#   if (!$NameObj.rename($NodeID)) {
#      log("Name change failed: " + $Error)
#      exit(1)
#   } else {
#      log("Node rename succeeded - reboot required")
#   }

   # Change the name via the registry
   New-ItemProperty -Path $CNPATH -Name ComputerName -PropertyType String`
                    -Value $nodeid.ToUpper() -Force
   New-ItemProperty -Path $HNPATH -Name "NV Hostname" -PropertyType String`
                    -Value $nodeid -Force

} else {
  log("Current node name is correct - no changes made")
}



exit(0)

{'fraction_non_alphanumeric': 0.15363128491620112, 'fraction_numerical': 0.006284916201117319, 'mean_word_length': 3.5118110236220472, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2483133', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1022, 'n_words': 269}