<commit_before>#!/usr/bin/env ruby
require 'socket'

hostnames=[`hostname`.chop]

# block until the network comes up
`ipconfig waitall`
real_interfaces = `netstat -ni`.split("\n").select {|line| line.match(/en.*((\d+\.){3}\d+)/) }
host_ips = real_interfaces.collect {|line| line.match(/en.*?((\d+\.){3}\d+)/); Regexp.last_match(1) }
host_ips.each do |ip|
  hostnames << Socket.gethostbyaddr(ip.split(/\./).collect! {|i| i.to_i }.pack('CCCC'))[0]
end

print "hostnames: "
p hostnames
hostnames.each do |hostname|
  if hostname =~ /pivotallabs.com/ and hostname !~ /^dyn-/
    hostname = hostname.gsub(/\..*/,"")
    # The scutil commands need to run as root, unless
    # you're logged into the console, but we can't be sure of that.
    `sudo scutil --set ComputerName #{hostname}`
    `sudo scutil --set LocalHostName #{hostname}`
    `sudo scutil --set HostName #{hostname}`
    `sudo hostname #{hostname}`
    `diskutil rename / #{hostname}`
  end
end

# We now remove ourselves (we only want to run once)
# We move ourselves to .Trash instead of rm'ing in case the
# sysadmin wants to run this script again (e.g. ethernet wasn't
# plugged in when the machine is booted).
pivot_home="/Users/pivotal"
`mv #{pivot_home}/bin #{pivot_home}/.Trash`
`sudo mv /Library/LaunchAgents/com.pivotallabs.auto_set_hostname.plist #{pivot_home}/.Trash`
`sudo chown -R pivotal #{pivot_home}/.Trash`<commit_msg>if the hostname is 'bacon', it sets the hostname to 'NEWLY_IMAGED'<commit_after>#!/usr/bin/env ruby
require 'socket'

hostname=`hostname`.chop
hostname = hostname == "bacon" ? "NEWLY_IMAGED" : hostname
hostnames=[hostname]

# block until the network comes up
`ipconfig waitall`
real_interfaces = `netstat -ni`.split("\n").select {|line| line.match(/en.*((\d+\.){3}\d+)/) }
host_ips = real_interfaces.collect {|line| line.match(/en.*?((\d+\.){3}\d+)/); Regexp.last_match(1) }
host_ips.each do |ip|
  begin
    hostnames << Socket.gethostbyaddr(ip.split(/\./).collect! {|i| i.to_i }.pack('CCCC'))[0]
  rescue SocketError
    log "no reverse lookup for \"#{ip}\""
  end
end

print "hostnames: "
p hostnames
hostnames.each do |hostname|
  if hostname =~ /pivotallabs.com/ and hostname !~ /^dyn-/
    hostname = hostname.gsub(/\..*/,"")
    # The scutil commands need to run as root, unless
    # you're logged into the console, but we can't be sure of that.
    `sudo scutil --set ComputerName #{hostname}`
    `sudo scutil --set LocalHostName #{hostname}`
    `sudo scutil --set HostName #{hostname}`
    `sudo hostname #{hostname}`
    `diskutil rename / #{hostname}`
  end
end

# We now remove ourselves (we only want to run once)
# We move ourselves to .Trash instead of rm'ing in case the
# sysadmin wants to run this script again (e.g. ethernet wasn't
# plugged in when the machine is booted).
pivot_home="/Users/pivotal"
`mv #{pivot_home}/bin #{pivot_home}/.Trash`
`sudo mv /Library/LaunchAgents/com.pivotallabs.auto_set_hostname.plist #{pivot_home}/.Trash`
`sudo chown -R pivotal #{pivot_home}/.Trash`
{'fraction_non_alphanumeric': 0.16261246251249584, 'fraction_numerical': 0.0026657780739753416, 'mean_word_length': 4.011686143572621, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '1046552', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1089, 'n_words': 309}