Skip to content

Instantly share code, notes, and snippets.

@L422Y
Last active August 29, 2015 14:12
Show Gist options
  • Save L422Y/2b0fda17b601bf004d80 to your computer and use it in GitHub Desktop.
Save L422Y/2b0fda17b601bf004d80 to your computer and use it in GitHub Desktop.
Javascript Map object: OSX Release IDs to OSX Versions
// use the major version from data.kern.osversion in sysctl output
var osxversions = {
"14": "Yosemite",
"13": "Mavericks",
"12": "Mountain Lion",
"11": "Lion",
"10": "Snow Leopard",
"9": "Leopard",
"8": "Tiger",
"7": "Panther",
"6": "Jaguar",
"5": "Puma"
}
// use data.kern.osrelease in sysctl output
var osxreleases = {
"11A511": "10.7.0",
"11A511s": "10.7.0",
"11A2061": "10.7.0",
"11A2063": "10.7.0",
"11B26": "10.7.1",
"11B2118": "10.7.1",
"11C74": "10.7.2",
"11D50": "10.7.3",
"11E53": "10.7.4",
"11G56": "10.7.5",
"11G63": "10.7.5",
"12A269": "10.8.0",
"12B19": "10.8.1",
"12C54": "10.8.2",
"12C60": "10.8.2",
"12C2034": "10.8.2",
"12C3104": "10.8.2",
"12D78": "10.8.3",
"12E55": "10.8.4",
"12E3067": "10.8.4",
"12E4022": "10.8.4",
"12F37": "10.8.5",
"12F45": "10.8.5",
"13A603": "10.9.0",
"13B42": "10.9.1",
"13C64": "10.9.2",
"13D65": "10.9.3",
"13E28": "10.9.4",
"13F34": "10.9.5",
}
<?php
require "db.php";
if (isset($_REQUEST['hostname']) && isset($_REQUEST['user'])):
$hostname = $_REQUEST['hostname'];
$user = $_REQUEST['user'];
$sysctl = $_REQUEST['sysctl'];
$sysctl = preg_replace('/vfs\.(.*)/', '', $sysctl);
$sysctl = preg_replace('/\r\n\s+\r\n/', '\r\n', $sysctl);
$sysctl = preg_replace('/ = /', ': ', $sysctl);
$sysctl = preg_replace('/([A-Za-z0-9\._-]*)\s{0,}?:\s([^\r\n]*)/', '"$1": "$2"', $sysctl);
$sysctl = explode("\n", $sysctl);
$sysctl = "{" . implode(", ", array_filter($sysctl)) . "}";
$sysctl = json_decode($sysctl, true);
$old_sysctl = $sysctl;
$sysctl = array();
foreach ($old_sysctl as $ik => $iv):
$sp = explode(".", $ik);
$curr = &$sysctl;
while ($nk = array_shift($sp)):
if (!isset($curr[$nk])):
$curr[$nk] = array();
endif;
$curr =& $curr[$nk];
endwhile;
$curr = $iv;
endforeach;
$data = array(
"hostname" => $hostname,
"username" => $user,
"createdAt" => new MongoDate(),
"data" => (object)$sysctl
);
$systems->update(array("hostname" => $hostname), $data, array("upsert" => true, "new" => true));
$results = $systems->find(array(), array('username' => 1, 'hostname' => 1));
foreach ($results as $system):
print $system['hostname'] . "\t" . $system['username'] . "\r\n";
endforeach;
echo "SUCCESS";
else:
echo "ERROR";
endif;
?>
#!/bin/bash
sysctl -a > /tmp/sysctl.data
CLEAN_MAC="$(ifconfig en0 | grep ether | awk '{print $2}' | sed 's/00:24//g' | sed 's/://g' )";
CLEAN_MODEL="$(sysctl hw.model | awk '{print tolower($2)}' | sed 's/[0-9\,]*$//g')";
NEW_HOSTNAME="${CLEAN_MODEL}-${CLEAN_MAC}";
echo "Enter this computer's primary user id:"
read NEW_USER
sudo scutil --set HostName ${CLEAN_MODEL}-${CLEAN_MAC}
sudo scutil --set ComputerName ${NEW_USER}-${CLEAN_MODEL}
curl "http://it.intranet/api/savesystem.php" --data "sysctl=`cat /tmp/sysctl.data`" --data "hostname=$NEW_HOSTNAME&user=$NEW_USER"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment