1 | #!/bin/bash
|
---|
2 | # $Id: testbox-pxe-conf.sh 93115 2022-01-01 11:31:46Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # VirtualBox Validation Kit - testbox pxe config emitter.
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2006-2022 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 | #
|
---|
32 | MY_NFS_SERVER_IP="10.165.98.101"
|
---|
33 | MY_GATEWAY_IP="10.165.98.1"
|
---|
34 | MY_NETMASK="255.255.254.0"
|
---|
35 | MY_ETH_DEV="eth0"
|
---|
36 | MY_AUTO_CFG="none"
|
---|
37 |
|
---|
38 | # options
|
---|
39 | MY_PXELINUX_CFG_DIR="/mnt/testbox-tftp/pxelinux.cfg"
|
---|
40 | MY_ACTION=""
|
---|
41 | MY_IP=""
|
---|
42 | MY_IP_HEX=""
|
---|
43 |
|
---|
44 | #
|
---|
45 | # Parse arguments.
|
---|
46 | #
|
---|
47 | while 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
|
---|
110 | done
|
---|
111 |
|
---|
112 | if test -z "${MY_ACTION}"; then
|
---|
113 | echo "syntax error: Insufficient arguments" >&2;
|
---|
114 | exit 2;
|
---|
115 | fi
|
---|
116 | if 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;
|
---|
119 | fi
|
---|
120 | if 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;
|
---|
123 | fi
|
---|
124 |
|
---|
125 |
|
---|
126 | #
|
---|
127 | # Produce the file.
|
---|
128 | # Using echo here so we can split up the APPEND line more easily.
|
---|
129 | #
|
---|
130 | MY_CFG_FILE="${MY_PXELINUX_CFG_DIR}/${MY_IP_HEX}"
|
---|
131 | set +e
|
---|
132 | echo "PATH bios" > "${MY_CFG_FILE}";
|
---|
133 | echo "DEFAULT maintenance" >> "${MY_CFG_FILE}";
|
---|
134 | echo "LABEL maintenance" >> "${MY_CFG_FILE}";
|
---|
135 | echo " MENU LABEL Maintenance (NFS)" >> "${MY_CFG_FILE}";
|
---|
136 | echo " KERNEL maintenance-boot/vmlinuz-3.16.0-4-amd64" >> "${MY_CFG_FILE}";
|
---|
137 | echo -n " APPEND initrd=maintenance-boot/initrd.img-3.16.0-4-amd64 testbox-action-${MY_ACTION}" >> "${MY_CFG_FILE}";
|
---|
138 | echo -n " ro aufs=tmpfs boot=nfs root=/dev/nfs" >> "${MY_CFG_FILE}";
|
---|
139 | echo -n " nfsroot=${MY_NFS_SERVER_IP}:/export/testbox-nfsroot,ro,tcp" >> "${MY_CFG_FILE}";
|
---|
140 | echo -n " nfsvers=3 nfsrootdebug" >> "${MY_CFG_FILE}";
|
---|
141 | if 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}";
|
---|
144 | else
|
---|
145 | echo -n " ip=${MY_AUTO_CFG}" >> "${MY_CFG_FILE}";
|
---|
146 | fi
|
---|
147 | echo "" >> "${MY_CFG_FILE}";
|
---|
148 | echo "LABEL local-boot" >> "${MY_CFG_FILE}";
|
---|
149 | echo "LOCALBOOT" >> "${MY_CFG_FILE}";
|
---|
150 | echo "Successfully generated '${MY_CFG_FILE}'."
|
---|
151 | exit 0;
|
---|
152 |
|
---|