VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/docs/testbox-pxe-conf.sh@ 67954

Last change on this file since 67954 was 66550, checked in by vboxsync, 7 years ago

testbox-pxe-conf.sh: use different NFS server

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1#!/bin/bash
2# $Id: testbox-pxe-conf.sh 66550 2017-04-13 08:55:12Z vboxsync $
3## @file
4# VirtualBox Validation Kit - testbox pxe config emitter.
5#
6
7#
8# Copyright (C) 2006-2017 Oracle Corporation
9#
10# This file is part of VirtualBox Open Source Edition (OSE), as
11# available from http://www.virtualbox.org. This file is free software;
12# you can redistribute it and/or modify it under the terms of the GNU
13# General Public License (GPL) as published by the Free Software
14# Foundation, in version 2 as it comes in the "COPYING" file of the
15# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17#
18# The contents of this file may alternatively be used under the terms
19# of the Common Development and Distribution License Version 1.0
20# (CDDL) only, as it comes in the "COPYING.CDDL" file of the
21# VirtualBox OSE distribution, in which case the provisions of the
22# CDDL are applicable instead of those of the GPL.
23#
24# You may elect to license modified versions of this file under the
25# terms and conditions of either the GPL or the CDDL or both.
26#
27
28
29#
30# Global Variables (config first).
31#
32MY_NFS_SERVER_IP="10.165.98.101"
33MY_GATEWAY_IP="10.165.98.1"
34MY_NETMASK="255.255.254.0"
35MY_ETH_DEV="eth0"
36MY_AUTO_CFG="none"
37
38# options
39MY_PXELINUX_CFG_DIR="/mnt/testbox-tftp/pxelinux.cfg"
40MY_ACTION=""
41MY_IP=""
42MY_IP_HEX=""
43
44#
45# Parse arguments.
46#
47while test "$#" -ge 1; do
48 MY_ARG=$1
49 shift
50 case "${MY_ARG}" in
51 -c|--cfg-dir)
52 MY_PXELINUX_CFG_DIR="$1";
53 shift;
54 if test -z "${MY_PXELINUX_CFG_DIR}"; then
55 echo "syntax error: Empty pxeclient.cfg path." >&2;
56 exit 2;
57 fi
58 ;;
59
60 -h|--help)
61 echo "usage: testbox-pxe-conf.sh: [-c /mnt/testbox-tftp/pxelinux.cfg] <ip> <action>";
62 echo "Actions: backup, backup-again, restore, refresh-info, rescue";
63 exit 0;
64 ;;
65 -*)
66 echo "syntax error: Invalid option: ${MY_ARG}" >&2;
67 exit 2;
68 ;;
69
70 *) if test -z "$MY_ARG"; then
71 echo "syntax error: Empty argument" >&2;
72 exit 2;
73 fi
74 if test -z "${MY_IP}"; then
75 # Split up the IP if possible, if not do gethostbyname on the argument.
76 MY_TMP=`echo "${MY_ARG}" | sed -e 's/\./ /g'`
77 if test `echo "${MY_TMP}" | wc -w` -ne 4 \
78 || ! printf "%02X%02X%02X%02X" ${MY_TMP} > /dev/null 2>&1; then
79 MY_TMP2=`getent hosts "${MY_ARG}" | head -1 | cut -d' ' -f1`;
80 MY_TMP=`echo "${MY_TMP2}" | sed -e 's/\./ /g'`
81 if test `echo "${MY_TMP}" | wc -w` -eq 4 \
82 && printf "%02X%02X%02X%02X" ${MY_TMP} > /dev/null 2>&1; then
83 echo "info: resolved '${MY_ARG}' as '${MY_TMP2}'";
84 MY_ARG="${MY_TMP2}";
85 else
86 echo "syntax error: Invalid IP: ${MY_ARG}" >&2;
87 exit 2;
88 fi
89 fi
90 MY_IP_HEX=`printf "%02X%02X%02X%02X" ${MY_TMP}`;
91 MY_IP="${MY_ARG}";
92 else
93 if test -z "${MY_ACTION}"; then
94 case "${MY_ARG}" in
95 backup|backup-again|restore|refresh-info|rescue)
96 MY_ACTION="${MY_ARG}";
97 ;;
98 *)
99 echo "syntax error: Invalid action: ${MY_ARG}" >&2;
100 exit 2;
101 ;;
102 esac
103 else
104 echo "syntax error: Too many arguments" >&2;
105 exit 2;
106 fi
107 fi
108 ;;
109 esac
110done
111
112if test -z "${MY_ACTION}"; then
113 echo "syntax error: Insufficient arguments" >&2;
114 exit 2;
115fi
116if test ! -d "${MY_PXELINUX_CFG_DIR}"; then
117 echo "error: pxeclient.cfg path does not point to a directory: ${MY_PXELINUX_CFG_DIR}" >&2;
118 exit 1;
119fi
120if test ! -f "${MY_PXELINUX_CFG_DIR}/default"; then
121 echo "error: pxeclient.cfg path does contain a 'default' file: ${MY_PXELINUX_CFG_DIR}" >&2;
122 exit 1;
123fi
124
125
126#
127# Produce the file.
128# Using echo here so we can split up the APPEND line more easily.
129#
130MY_CFG_FILE="${MY_PXELINUX_CFG_DIR}/${MY_IP_HEX}"
131set +e
132echo "PATH bios" > "${MY_CFG_FILE}";
133echo "DEFAULT maintenance" >> "${MY_CFG_FILE}";
134echo "LABEL maintenance" >> "${MY_CFG_FILE}";
135echo " MENU LABEL Maintenance (NFS)" >> "${MY_CFG_FILE}";
136echo " KERNEL maintenance-boot/vmlinuz-3.16.0-4-amd64" >> "${MY_CFG_FILE}";
137echo -n " APPEND initrd=maintenance-boot/initrd.img-3.16.0-4-amd64 testbox-action-${MY_ACTION}" >> "${MY_CFG_FILE}";
138echo -n " ro aufs=tmpfs boot=nfs root=/dev/nfs" >> "${MY_CFG_FILE}";
139echo -n " nfsroot=${MY_NFS_SERVER_IP}:/export/testbox-nfsroot,ro,tcp" >> "${MY_CFG_FILE}";
140echo -n " nfsvers=3 nfsrootdebug" >> "${MY_CFG_FILE}";
141if test "${MY_AUTO_CFG}" = "none"; then
142 # Note! Only 6 arguments to ip! Userland ipconfig utility barfs if autoconf and dns options are given.
143 echo -n " ip=${MY_IP}:${MY_NFS_SERVER_IP}:${MY_GATEWAY_IP}:${MY_NETMASK}:maintenance:${MY_ETH_DEV}" >> "${MY_CFG_FILE}";
144else
145 echo -n " ip=${MY_AUTO_CFG}" >> "${MY_CFG_FILE}";
146fi
147echo "" >> "${MY_CFG_FILE}";
148echo "LABEL local-boot" >> "${MY_CFG_FILE}";
149echo "LOCALBOOT" >> "${MY_CFG_FILE}";
150echo "Successfully generated '${MY_CFG_FILE}'."
151exit 0;
152
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette