This repository has been archived by the owner on Oct 28, 2021. It is now read-only.
/
pxe
executable file
·184 lines (152 loc) · 6.12 KB
/
pxe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/sh
#
# Copyright (C) 2014-2017 OpenMediaVault Plugin Developers
#
# This file is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
set -e
. /etc/default/openmediavault
. /usr/share/openmediavault/scripts/helper-functions
SERVICE_XPATH="/config/services/pxe"
SERVICE_XPATH_ENTRY="${SERVICE_XPATH}/entries/entry"
PXE_SHARED_FOLDER_REF=$(omv_config_get "${SERVICE_XPATH}/sharedfolderref")
PXE_PATH=$(omv_get_sharedfolder_path "${PXE_SHARED_FOLDER_REF}")
PXE_CONFIG_PATH="${PXE_PATH}/pxelinux.cfg"
PXE_CONFIG="${PXE_CONFIG_PATH}/default"
package=$1
echo $package >> /tmp/pxe_package
update()
{
mkdir -p "${PXE_CONFIG_PATH}"
enablewinpath=$(omv_config_get "${SERVICE_XPATH}/enableWinPath")
if [ "${enablewinpath}" = "1" ]; then
cat <<EOF > /etc/tftp_remap.conf
re ^pxeboot\.n12 Boot/pxeboot.n12
re ^pxeboot\.com Boot/pxeboot.com
re ^pxeboot\.0 Boot/pxeboot.n12
re ^bootmgr\.exe Boot/bootmgr.exe
rg \\ /
EOF
elif [ -e "/etc/tftp_remap.conf" ]; then
rm /etc/tftp_remap.conf
fi
systemctl restart tftpd-hpa.service
if [ -f "/usr/lib/syslinux/modules/bios/vesamenu.c32" ]; then
cp -f /usr/lib/syslinux/modules/bios/vesamenu.c32 "${PXE_PATH}"
fi
if [ -f "/usr/lib/PXELINUX/pxelinux.0" ]; then
cp -f /usr/lib/PXELINUX/pxelinux.0 "${PXE_PATH}"
fi
if [ -f "/usr/lib/PXELINUX/lpxelinux.0" ]; then
cp -f /usr/lib/PXELINUX/lpxelinux.0 "${PXE_PATH}"
fi
if [ -f "/usr/lib/syslinux/modules/bios/ldlinux.c32" ]; then
cp -f /usr/lib/syslinux/modules/bios/ldlinux.c32 "${PXE_PATH}"
fi
if [ -f "/usr/lib/syslinux/modules/bios/libcom32.c32" ]; then
cp -f /usr/lib/syslinux/modules/bios/libcom32.c32 "${PXE_PATH}"
fi
if [ -f "/usr/lib/syslinux/modules/bios/libutil.c32" ]; then
cp -f /usr/lib/syslinux/modules/bios/libutil.c32 "${PXE_PATH}"
fi
if [ -f "/usr/lib/syslinux/modules/bios/chain.c32" ]; then
cp -f /usr/lib/syslinux/modules/bios/chain.c32 "${PXE_PATH}"
fi
if [ -f "/usr/lib/syslinux/memdisk" ]; then
cp -f /usr/lib/syslinux/memdisk "${PXE_PATH}"
fi
rm -f ${PXE_CONFIG}.*
timeout="$(omv_config_get "${SERVICE_XPATH}/timeout")"
cat <<EOF > "${PXE_CONFIG}"
DEFAULT vesamenu.c32
TIMEOUT 100
# TIMEOUT ${timeout}
PROMPT 0
MENU TITLE PXE Boot System
LABEL Local HDD
LOCALBOOT 0
EOF
#Loop through entries and output them into the config file
count=$(omv_config_get_count "${SERVICE_XPATH_ENTRY}");
index=1;
while [ ${index} -le ${count} ]; do
enable="$(omv_config_get "${SERVICE_XPATH_ENTRY}[position()=${index}]/enable")"
group="$(omv_config_get "${SERVICE_XPATH_ENTRY}[position()=${index}]/grp")"
label="$(omv_config_get "${SERVICE_XPATH_ENTRY}[position()=${index}]/label")"
menu="$(omv_config_get "${SERVICE_XPATH_ENTRY}[position()=${index}]/menu")"
kernel="$(omv_config_get "${SERVICE_XPATH_ENTRY}[position()=${index}]/kernel")"
initrd="$(omv_config_get "${SERVICE_XPATH_ENTRY}[position()=${index}]/initrd")"
append="$(omv_config_get "${SERVICE_XPATH_ENTRY}[position()=${index}]/append")"
if [ "${enable}" != "0" ]; then
if [ "${group}" != "Default" ]; then
echo "" >> "$PXE_CONFIG"
echo "LABEL ${group}" >> "$PXE_CONFIG"
echo " KERNEL vesamenu.c32" >> "$PXE_CONFIG"
echo " APPEND pxelinux.cfg/default.${group}" >> "$PXE_CONFIG"
if [ ! -e "${PXE_CONFIG}.${group}" ]; then
echo "MENU TITLE PXE Boot System" > "${PXE_CONFIG}.${group}"
echo " LABEL Main Menu" >> "${PXE_CONFIG}.${group}"
echo " KERNEL vesamenu.c32" >> "${PXE_CONFIG}.${group}"
echo " APPEND pxelinux.cfg/default" >> "${PXE_CONFIG}.${group}"
fi
echo "" >> "${PXE_CONFIG}.${group}"
echo "LABEL ${label}" >> "${PXE_CONFIG}.${group}"
[ -n "${menu}" ] && echo " MENU ${menu}" >> "${PXE_CONFIG}.${group}"
[ -n "${kernel}" ] && echo " KERNEL ${kernel}" >> "${PXE_CONFIG}.${group}"
[ -n "${initrd}" ] && echo " INITRD ${initrd}" >> "${PXE_CONFIG}.${group}"
[ -n "${append}" ] && echo " APPEND ${append}" >> "${PXE_CONFIG}.${group}"
else
echo "" >> "${PXE_CONFIG}"
echo "LABEL ${label}" >> "${PXE_CONFIG}"
[ -n "${menu}" ] && echo " MENU ${menu}" >> "${PXE_CONFIG}"
[ -n "${kernel}" ] && echo " KERNEL ${kernel}" >> "${PXE_CONFIG}"
[ -n "${initrd}" ] && echo " INITRD ${initrd}" >> "${PXE_CONFIG}"
[ -n "${append}" ] && echo " APPEND ${append}" >> "${PXE_CONFIG}"
fi
fi
index=$(( ${index} + 1 ))
done;
}
package()
{
export LANG=C
templocation="/tmp/pxeinstall/"
# make temp directory
mkdir -p "${templocation}"
# remove existing config.txt (if any)
rm -f "${PXE_PATH}"/config.txt
# download package
wget http://pxe.omv-extras.org/${package} -P "${PXE_PATH}"
# Check to see if downloaded package exists
if [ ! -f "${PXE_PATH}/${package}" ]; then
echo "${package} was not downloaded."
exit 1
fi
# unzip package
tar xvzf "${PXE_PATH}/${package}" -C "${PXE_PATH}"
# put config.txt in temp directory
mv -f "${PXE_PATH}"/config.txt "${templocation}"
# remove downloaded package file
rm -f "${PXE_PATH}/${package}"
}
case ${package} in
"" | update)
echo "Updating ..."
update
;;
*)
echo "Installing $package ..."
package
;;
esac
exit 0