-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtualbox.plg
290 lines (273 loc) · 12.4 KB
/
virtualbox.plg
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?xml version='1.0' standalone='yes'?>
<!DOCTYPE PLUGIN [
<!ENTITY name "virtualbox">
<!ENTITY author "Dan Kessler">
<!ENTITY version "2017.05.19e">
<!ENTITY launch "Settings/&name;">
<!ENTITY pluginURL "https://raw.githubusercontent.com/theone11/virtualbox_plugin/master/&name;.plg">
<!ENTITY packageVER "&version;">
<!ENTITY packageMD5 "347e60b6905fd1ff659534ba66bbe68f">
<!ENTITY packagefile "&name;-package-&packageVER;.tar.gz">
<!ENTITY packageURL "https://github.com/theone11/virtualbox_plugin/raw/master/&packagefile;">
<!ENTITY pluginLOC "/boot/config/plugins/&name;">
<!ENTITY emhttpLOC "/usr/local/emhttp/plugins/&name;">
]>
<PLUGIN name="&name;"
author="&author;"
version="&version;"
launch="&launch;"
pluginURL="&pluginURL;"
>
<!--
# Release Version v2017.05.19e
-->
<CHANGES>
###2017.05.19e
- Fixed extension pack install failure due to license agreement acceptance prompt - finally got it working :)
###2017.05.19d
- Fixed extension pack install failure due to license agreement acceptance prompt using different approach (license number)
###2017.05.19c
- Fixed extension pack install failure due to license agreement acceptance prompt
###2015.09.18
- Fixed online package lookup
###2015.09.17
- Added unRAID 6.1 compatibility and keep backward compatibility
###2015.06.07
- Changed start and stop events to "started" and "stopping_svcs" instead of "disks_mounted" and "unmounting_disks"
- Moved plugin icon to "User Utilities" section (unRAID v6)
###2015.06.05
- Added launch option from plugin manager (unRAID v6)
- Changed package version to same as plugin version
- Fixed - Inadvertently Cleared vboxwebsrv settings - Returned onsubmit="validateForm();" to form submission
###2015.04.22-1
- Fixed unRAID v5 compatibility
###2015.04.22
- Added newline between each log line during install/remove scripts
- Added settings page icon
- Changed package so that it extracts directly to all needed folders (/etc/rc.d, /usr/local/emhttp/plugins/virtualbox)
- Add version to PAGE file automatically so it and package don't need to be modified on every change
###2015.04.21-1
- Fixed unRAID v5 compatibility
###2015.04.21
- Added support for unRAID v6 Plugin Manager and Architecture
- Added support for tgz and txz compiled packages
###0.5.7
- Reduced plugin load time by reducing network accessing when checking online versions
### 0.5.6
- Added MD5 checksum verification for all downloaded packages immediately after download - delete download if MD5 cannot be verified or fails verification
### 0.5.5
- Fixed kernel version number extraction from online package
### 0.5.4
- Changed unRAID compiled VirtualBox version availability and presentation in WEBUI (compatible and latest)
- Changed timeout to 10 seconds (instead of 60)
- Added plugin forum link to WEBUI
- Automatic support of 32/64bit packages depending on OS
### 0.5.3
- Added changelog history
- Enabled changing of Mount and Startup options also when virtualbox is running - They impact only during plugin start
- Only if VirtualBox installed give option to update from local or online versions if exist otherwise download options
- Changed "vboxmanage" to correct case "VBoxManage" and added full path "/opt/Virtualbox/VBoxManage"
- Added to log confirmation that installation of packages completed correctly.
- If "VirtualBox LOCAL version different than INSTALLED version" then function changed to "update" instead of "install"
- Duplicated all "logger" output also to regular output "echo"
- Added --timeout=10 on all wget commands
- Minor UI Change
### 0.5.2 - Added Latest Release version available from VirtualBox.org (not necessarily existing for unRAID yet)
- Local versions extraction
- Cosmetic changes
### 0.5.1 - Fixed bottom of page is sometimes not visible due to unRAID progressframe
### 0.5 - Added option to download GuestAdditions Package
- Added option to change /boot/custom/vbox to different location including moving of files - New parameter in configuration
- Changed configuration update code
- When upgrading from older version plugins the following line should be added to cfg file before upgading the plugin:
VBOX_SYMLINK_LOCATION="/boot/custom/vbox"
That way the plugin can move existing files once you decide to move the VirtualBox symbolic link from original location "/boot/custom/vbox" to your new desired location.
### 0.4.2
- Fixed: Icon file couldn't be saved because plugin folder doesn't exist on first run
### 0.4.1
- Fixed: Icon file deleted when upgrading plugin without restarting server
### 0.4
- Workaround for downloading non exiting icon file
### 0.3
- Fixed startup sequence - Virtualbox can only be started (specifically VMs) after array mounted
### 0.2.7
- Changed WEBUI layout, Corrected few functions
### 0.2.6
- Corrected access to previous session VM list (vms_session.cfg)
### 0.2.5
- Corrected boot and plugin update functions
### 0.2.4
- Fix install function during boot when online version doesn't exist or is not checked
### 0.2.3
- Fix install function
### 0.2.2
- Initial Release
</CHANGES>
<!--
############################################
# Plugin Install script
############################################
-->
<FILE Name="/tmp/&name;-install" Run="/bin/bash">
<INLINE>
<!--
#################
# L O G I T
#################
-->
logit()
{
<!--logger -trc.&name; -plocal7.info -is "$1"-->
echo ""
echo "$1"
}
DOWNLOAD_PKG="false"
INSTALL_PKG="false"
logit "Installing plugin..."
<!--
logit "Cleaning up older versions if exist in &emhttpLOC;"
[ -d "&emhttpLOC;" ] && rm -fR "&emhttpLOC;"
-->
<!--# Create plugin folder if needed -->
if [ ! -d "&pluginLOC;" ] ; then
logit "Creating plugin folder &pluginLOC;"
mkdir -p "&pluginLOC;"
else
logit "Plugin folder &pluginLOC; already exists"
fi
<!--# Check local package file -->
logit "Checking existing package &pluginLOC;/&packagefile;..."
if [ -f "&pluginLOC;/&packagefile;" ] ; then
VBOX_PKG_LOCAL_MD5=$(/usr/bin/md5sum &pluginLOC;/&packagefile; | cut -d' ' -f1)
if [ "$VBOX_PKG_LOCAL_MD5" == "&packageMD5;" ] ; then
logit "Latest package already exists &pluginLOC;/&packagefile;"
INSTALL_PKG="true"
else
logit "Local/Online package MD5 mismatch ($VBOX_PKG_LOCAL_MD5/&packageMD5;) on &pluginLOC;/&packagefile; - deleting local package"
DOWNLOAD_PKG="true"
fi
else
logit "Latest package does not exist &pluginLOC;/&packagefile;"
DOWNLOAD_PKG="true"
fi
<!--# Download plugin files -->
if [ "$DOWNLOAD_PKG" == "true" ]; then
<!--# Save existing packages until new package is downloaded OK -->
logit "Saving any previous packages from &pluginLOC;"
mkdir -p "/tmp/&name;-packages"
TEMP="&pluginLOC;/&name;-package-*"
mv -f $TEMP "/tmp/&name;-packages"
logit "Attempting to download plugin package &packageURL;..."
wget --quiet --spider --no-check-certificate --timeout=10 &packageURL;
if [ ! $? == "0" ] ; then
logit "Package server down &packageURL; - Plugin cannot install"
INSTALL_PKG="false"
else
wget --quiet --no-check-certificate --timeout=10 -O &pluginLOC;/&packagefile; &packageURL;
if [ ! -f "&pluginLOC;/&packagefile;" ] ; then
logit "Package download failed &packageURL; - Plugin cannot install"
INSTALL_PKG="false"
else
VBOX_PKG_LOCAL_MD5=$(/usr/bin/md5sum &pluginLOC;/&packagefile; | cut -d' ' -f1)
if [ "$VBOX_PKG_LOCAL_MD5" != "&packageMD5;" ] ; then
logit "Package MD5 mismatch ($VBOX_PKG_LOCAL_MD5/&packageMD5;) on &pluginLOC;/&packagefile; - Plugin cannot install"
INSTALL_PKG="false"
else
logit "Package &packagefile; downloaded to &pluginLOC; - MD5 match "$VBOX_PKG_LOCAL_MD5""
INSTALL_PKG="true"
fi
fi
fi
fi
if [ "$INSTALL_PKG" == "true" ] ; then
logit "Extracting plugin package..."
<!--# Remove current existing files -->
[ -f "/etc/rc.d/rc.&name;" ] && rm -f "/etc/rc.d/rc.&name;"
[ -d "&emhttpLOC;" ] && rm -fR "&emhttpLOC;"
<!--# Extract files -->
tar -xf "&pluginLOC;/&packagefile;" -C "/"
<!-- Make rc.&name executable -->
chmod 0770 "&emhttpLOC;/scripts/rc.&name;"
<!-- Create symlink to rc file -->
ln -s "&emhttpLOC;/scripts/rc.&name;" "/etc/rc.d/rc.&name;"
<!--# Edit PAGE file depending on unRAID OS type 32/64 bit, also add version number -->
<!--# Add plugin image to emhttp depending on unRAID OS type 32/64 bit -->
UNRAID_OS_BITS=$(getconf LONG_BIT)
echo "Version=\"&version;\"" >> "&emhttpLOC;/&name;.page"
if [ "$UNRAID_OS_BITS" == "64" ] ; then
echo "Menu=\"Utilities\"" >> "&emhttpLOC;/&name;.page"
echo "---" >> "&emhttpLOC;/&name;.page"
else
echo "Menu=\"OtherSettings\"" >> "&emhttpLOC;/&name;.page"
cp -f "&emhttpLOC;/images/&name;.png" "&emhttpLOC;"
cp -f "&emhttpLOC;/php/&name;_main.php" "&emhttpLOC;/&name;.php"
fi
echo "<?php include '&emhttpLOC;/php/&name;_main.php';?>" >> "&emhttpLOC;/&name;.page"
<!--# Create or fix configuration file -->
if [ ! -f "&pluginLOC;/&name;.cfg" ] ; then
logit "Configuration file not found. Creating configuration file..."
echo "# VirtualBox plugin configuration - Do not modify manually - Change via WEBUI" > "&pluginLOC;/&name;.cfg"
fi
logit "Checking all configuration file parameters exist"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep INSTALL_ON_BOOT` ] && echo "INSTALL_ON_BOOT=\"false\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep UPGRADE_ON_BOOT` ] && echo "UPGRADE_ON_BOOT=\"false\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep UPGRADE_PLG_ON_BOOT` ] && echo "UPGRADE_PLG_ON_BOOT=\"false\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep START_ON_ARRAY_MOUNT` ] && echo "START_ON_ARRAY_MOUNT=\"false\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep START_VMS_ON_START` ] && echo "START_VMS_ON_START=\"previous\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep VBOX_SYMLINK_LOCATION` ] && echo "VBOX_SYMLINK_LOCATION=\"/boot/custom/vbox\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep VBOXWEBSRV_HOST_IP` ] && echo "VBOXWEBSRV_HOST_IP=\"127.0.0.1\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep VBOXWEBSRV_HOST_PORT` ] && echo "VBOXWEBSRV_HOST_PORT=\"18083\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep VBOXWEBSRV_LOGFILE` ] && echo "VBOXWEBSRV_LOGFILE=\"/boot/config/plugins/virtualbox/vboxwebsrv.log\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep VBOXWEBSRV_VERBOSE` ] && echo "VBOXWEBSRV_VERBOSE=\"true\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep VBOXWEBSRV_LOGROTATE` ] && echo "VBOXWEBSRV_LOGROTATE=\"0\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep VBOXWEBSRV_LOGSIZE` ] && echo "VBOXWEBSRV_LOGSIZE=\"50000\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep VBOXWEBSRV_LOGINTERVAL` ] && echo "VBOXWEBSRV_LOGINTERVAL=\"604800\"" >> "&pluginLOC;/&name;.cfg"
rm -Rf "/tmp/&name;-packages"
rm -f "/tmp/&name;-install"
logit "Plugin and Package file &packagefile; extracted and installed successfully"
exit 0
else
<!-- Revert back to previous packages -->
if [ -f "&pluginLOC;/&packagefile;" ] ; then
<!-- Remove bad MD5 downloaded package if exists -->
rm -f "&pluginLOC;/&packagefile;"
fi
logit "Reverting back to previously saved packages..."
TEMP1="/tmp/&name;-packages"
TEMP2=$(ls $TEMP1)
if [ "$TEMP2" != "" ] ; then
TEMP="/tmp/&name;-packages/&name;-package-*"
mv -f $TEMP "&pluginLOC;"
logit "Previous packages restored"
else
logit "No previous packages to restored"
fi
rm -Rf "/tmp/&name;-packages"
rm -f "/tmp/&name;-install"
logit "Plugin install failed"
exit 1
fi
</INLINE>
</FILE>
<!--
############################################
# plugin Remove method
############################################
-->
<FILE Run="/bin/bash" Method="remove">
<INLINE>
logit()
{
<!--logger -trc.&name; -plocal7.info -is "$1"-->
echo "$1"
echo ""
}
logit "Removing plugin..."
[ -f "/tmp/&name;-install" ] && rm -f "/tmp/&name;-install"
[ -f "/etc/rc.d/rc.&name;" ] && "/etc/rc.d/rc.&name;" stop
[ -f "/etc/rc.d/rc.&name;" ] && rm -f "/etc/rc.d/rc.&name;"
[ -d "&emhttpLOC;" ] && rm -fR "&emhttpLOC;"
logit "Plugin stopped and removed - no files removed from &pluginLOC;"
</INLINE>
</FILE>
</PLUGIN>