VirtualBox

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

Last change on this file since 103416 was 98103, checked in by vboxsync, 22 months ago

Copyright year updates by scm.

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