-
Notifications
You must be signed in to change notification settings - Fork 3
/
swapfile.plg
240 lines (223 loc) · 8.75 KB
/
swapfile.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
<?xml version='1.0' standalone='yes'?>
<!DOCTYPE PLUGIN [
<!ENTITY name "swapfile">
<!ENTITY author "Dan Kessler">
<!ENTITY version "2015.09.21">
<!ENTITY launch "Settings/&name;">
<!ENTITY pluginURL "https://raw.githubusercontent.com/theone11/&name;_plugin/master/&name;.plg">
<!ENTITY packageVER "&version;">
<!ENTITY packageMD5 "38cedf80a708dee7def1fa940525fcbe">
<!ENTITY packagefile "&name;-package-&packageVER;.tar.gz">
<!ENTITY packageURL "https://github.com/theone11/&name;_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 v2015.09.21
-->
<CHANGES>
###2015.09.21
- Changed start and stop events to "started" and "stopping_svcs" instead of "disks_mounted" and "unmounting_disks" to allow all array and non-array disks to be mounted before creating/using swap file
###2015.09.17
- Add unRAID 6.1 compatibility and keep backward compatibility
###2015.06.07
- 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
###2015.04.22
- Added support for unRAID v6 Plugin Manager and Architecture
- Changed timeout to 10 seconds for all network connections (was 60 seconds)
###0.5.3
- Added 60 second timeout to all network accesses
- Added comment regarding swap file location in WEBUI
###0.5.2
- Fixed bottom of page is sometimes not visible due to unRAID progressframe
###0.5.1
- Fixed division by zero in usage percentage calculation for usage bar
###0.5
- Added existance check before deleting swap file
- Cleaned up temporary file.
###0.4.4
- Fixed: Icon file couldn't be saved because plugin folder doesn't exist on first run
###0.4.3
- Fixed: Icon file deleted when upgrading plugin without restarting server
###0.4.1
- Fixed: local plugin version not shown
###0.4
- Workaround for downloading non exiting icon file
###0.3
- Fixed startup sequence - Swap file must be activated only after array mounted
###0.2.1
- Changed SWAP_ENABLE_ON_BOOT default value to "false"
###0.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"
echo "<?php include '&emhttpLOC;/php/&name;_main.php';?>" >> "&emhttpLOC;/&name;.page"
else
echo "Menu=\"OtherSettings\"" >> "&emhttpLOC;/&name;.page"
mv -f "&emhttpLOC;/images/&name;.png" "&emhttpLOC;"
mv -f "&emhttpLOC;/php/&name;_main.php" "&emhttpLOC;/&name;.php"
fi
<!--# Create or fix configuration file -->
if [ ! -f "&pluginLOC;/&name;.cfg" ] ; then
logit "Configuration file not found. Creating configuration file..."
echo "# SwapFile 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 UPGRADE_PLG_ON_BOOT` ] && echo "UPGRADE_PLG_ON_BOOT=\"false\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep SWAP_ENABLE_ON_BOOT` ] && echo "SWAP_ENABLE_ON_BOOT=\"false\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep SWAP_DELETE` ] && echo "SWAP_DELETE=\"false\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep SWAP_LOCATION` ] && echo "SWAP_LOCATION=\"/mnt/cache\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep SWAP_FILENAME` ] && echo "SWAP_FILENAME=\"swapfile\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep SWAP_NAME` ] && echo "SWAP_NAME=\"UNRAID-SWAP\"" >> "&pluginLOC;/&name;.cfg"
[ ! `cat "&pluginLOC;/&name;.cfg" | grep SWAP_SIZE_MB` ] && echo "SWAP_SIZE_MB=\"2048\"" >> "&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>