-
Notifications
You must be signed in to change notification settings - Fork 6
/
ui_install.sh
51 lines (41 loc) · 1.77 KB
/
ui_install.sh
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
#!/bin/sh
source /usr/sbin/helper.sh
# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT=$(readlink -f "$0")
# Absolute path this script is in, thus /home/user/bin
SCRIPTPATH=$(dirname "$SCRIPT")
# load standard variables
source "$SCRIPTPATH/addon_vars"
if [ ! -f "/jffs/addons/$MY_ADDON_NAME/$MY_ADDON_PAGE" ]; then
echo "/jffs/addons/$MY_ADDON_NAME/$MY_ADDON_PAGE does not exist. Cannot enable UI without this file."
exit 5
fi
# Does the firmware support addons?
nvram get rc_support | grep -q am_addons
if [ $? != 0 ]
then
echo "This firmware does not support addons!"
logger "$MY_ADDON_NAME addon" "This firmware does not support addons!"
exit 5
fi
# Obtain the first available mount point in $am_webui_page
am_get_webui_page /jffs/addons/$MY_ADDON_NAME/$MY_ADDON_PAGE
if [ "$am_webui_page" = "none" ]
then
echo "Unable to install $MY_ADDON_PAGE"
logger "$MY_ADDON_NAME addon" "Unable to install $MY_ADDON_PAGE"
exit 5
fi
logger "$MY_ADDON_NAME addon" "Mounting $MY_ADDON_PAGE as $am_webui_page"
# Copy custom page
cp /jffs/addons/$MY_ADDON_NAME/$MY_ADDON_PAGE /www/user/$am_webui_page
# Copy menuTree (if no other script has done it yet) so we can modify it
if [ ! -f /tmp/menuTree.js ]
then
cp /www/require/modules/menuTree.js /tmp/
mount -o bind /tmp/menuTree.js /www/require/modules/menuTree.js
fi
# Insert link at the end of the Tools menu. Match partial string, since tabname can change between builds (if using an AS tag)
sed -i "/url: \"Tools_OtherSettings.asp\", tabName:/a {url: \"$am_webui_page\", tabName: \"$MY_ADDON_TAB\"}," /tmp/menuTree.js
# sed and binding mounts don't work well together, so remount modified file
umount /www/require/modules/menuTree.js && mount -o bind /tmp/menuTree.js /www/require/modules/menuTree.js