From 6eff099c73db8d293a9e0e433f66bcfddee7ee3f Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Tue, 7 Jun 2011 17:13:50 +0300 Subject: added asd2nb --- asd2nb/asdbless.sh | 36 ++++++++++++++++++++++++++++++++++++ asd2nb/server.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 asd2nb/asdbless.sh create mode 100644 asd2nb/server.php diff --git a/asd2nb/asdbless.sh b/asd2nb/asdbless.sh new file mode 100644 index 0000000..e18d170 --- /dev/null +++ b/asd2nb/asdbless.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# asdbless.sh +# Pick correct ASD image for this machine +# @author Filipp Lepalaan +# @package mtk + +SERVER_IP=192.168.1.10 # The IP of the NetBoot server +SERVER_URL="http://example.com/mtk/asd2nb/server.php" # URL of the server-side script +NBI_PATH=/data/nb # Path to the ASD image repository +ASD_ROOT=/asd # + +if [[ ! -d "${NBI_PATH}" ]]; then + echo "Path ${NBI_PATH} does not exist" 2>&1 + exit 1 +fi + +MODEL=$(/usr/sbin/sysctl -n hw.model) +MACHINE=$(/usr/sbin/sysctl -n hw.machine) +RESULT=$(/usr/bin/curl -s ${SERVER_URL} -d m=${MODEL}) + +if [[ -z ${RESULT} ]]; then + echo "${MODEL} not found on server, exiting" 2>&1 + exit 1; +fi + +ASD=$(echo $RESULT | awk 'BEGIN { FS = "/" } ; { print $1 }') +DMG=$(echo $RESULT | awk 'BEGIN { FS = "/" } ; { print $2 }') + +/usr/sbin/bless --netboot \ + --booter tftp://${SERVER_IP}${ASD_ROOT}/${ASD}/${MACHINE}/booter \ + --kernel tftp://${SERVER_IP}${ASD_ROOT}/${ASD}/${MACHINE}/mach.macosx \ + --options "rp=nfs:${SERVER_IP}:${NBI_PATH}:${ASD_ROOT}/${RESULT}" \ + --nextonly + +echo "Boot volume set to ${ASD}" +exit 0 diff --git a/asd2nb/server.php b/asd2nb/server.php new file mode 100644 index 0000000..26aaf1a --- /dev/null +++ b/asd2nb/server.php @@ -0,0 +1,33 @@ + + * @package mtk + */ + + header('Content-Type: text/plain'); + + if (!isset($_REQUEST['m'])) { + exit("Sorry, have to know who you are first..."); + } + + $imgdir = '/data/nb/asd'; // edit this + + $model = $_REQUEST['m']; + + require "plist.php"; + + foreach(glob("${imgdir}/*.nbi") as $nbi) + { + $p = new PropertyList("{$nbi}/NBImageInfo.plist"); + $a = $p->toArray(); + $ids = $a['EnabledSystemIdentifiers']; + if (in_array($model, $ids)) { + exit(basename($nbi).'/'.$a['RootPath']); + } + } + +?> -- cgit v1.2.3