package:add nfs mount luci (#4171)

This commit is contained in:
Aes64X 2020-04-05 18:34:14 +08:00 committed by GitHub
parent 08637d8262
commit 5e9e8d8536
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 222 additions and 0 deletions

View File

@ -0,0 +1,17 @@
# Copyright (C) 2016 Openwrt.org
#
# This is free software, licensed under the Apache License, Version 2.0 .
#
include $(TOPDIR)/rules.mk
LUCI_TITLE:=LuCI support for nfs
LUCI_DEPENDS:=+nfs-utils +nfs-kernel-server +nfs-kernel-server-utils +mount-utils
LUCI_PKGARCH:=all
PKG_VERSION:=1.1
PKG_RELEASE:=1
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View File

@ -0,0 +1,8 @@
module("luci.controller.nfs", package.seeall)
function index()
if not nixio.fs.access("/etc/config/nfs") then
return
end
entry({"admin", "nas", "nfs"}, cbi("nfs"), _("NFS Manage"), 5).dependent = true
end

View File

@ -0,0 +1,70 @@
local fs = require "nixio.fs"
m = Map("nfs", translate("NFS Manage"))
-- NFS Share --
s = m:section(TypedSection, "share", translate("Shared Directories"))
s.anonymous = true
s.addremove = true
s.template = "cbi/tblsection"
en = s:option(Flag, "enabled", translate("Enable"))
en.rmempty = false
en.default = "1"
ph1 = s:option(Value, "path", translate("Path"))
ph1.placeholder = "/mnt"
ph1.rmempty = false
ph1.optional = false
ct = s:option(Value, "clients", translate("Clients"))
ct.placeholder = "192.168.1.0/24"
ct.rmempty = false
ct.optional = false
op = s:option(Value, "options", translate("options"))
op.placeholder = "rw,sync,root_squash,all_squash,insecure,no_subtree_check"
op.rmempty = false
op.optional = false
-- NFS Mount --
c = m:section(TypedSection, "mount", translate("Mounted Points"))
c.anonymous = true
c.addremove = true
c.template = "cbi/tblsection"
en = c:option(Flag, "enabled", translate("Enable"))
en.default = "1"
en.rmempty = false
sr = c:option(Value, "source", translate("source"))
sr.placeholder = "192.168.1.1:/mnt/*"
sr.rmempty = false
sr.optional = false
ph2 = c:option(Value, "target", translate("target"))
ph2.placeholder = "/mnt/nfs/*"
ph2.rmempty = false
ph2.optional = false
op = c:option(Value, "options", translate("options"))
op.placeholder = "rw,nolock"
op.rmempty = false
op.optional = false
de = c:option(Value, "delay", translate("delay"))
de.placeholder = "5"
de.rmempty = false
de.optional = false
if nixio.fs.access("/etc/config/fstab") then
ph1.titleref = luci.dispatcher.build_url("admin", "system", "mounts")
ph2.titleref = luci.dispatcher.build_url("admin", "system", "mounts")
end
local apply = luci.http.formvalue("cbi.apply")
if apply then
io.popen("/etc/init.d/nfs reload")
end
return m

View File

@ -0,0 +1,32 @@
msgid ""
msgstr ""
msgid "NFS Manage"
msgstr "NFS 管理"
msgid "Shared Directories"
msgstr "共享目录"
msgid "Enable"
msgstr "启用"
msgid "Path"
msgstr "路径"
msgid "Clients"
msgstr "允许的客户端"
msgid "Mounted Points"
msgstr "已挂载的目录"
msgid "source"
msgstr "源目录"
msgid "target"
msgstr "挂载到"
msgid "options"
msgstr "选项"
msgid "delay"
msgstr "延迟时间"

View File

@ -0,0 +1,6 @@
config share
option enabled '0'
option path '/mnt'
option clients '*'
option options 'rw,sync,root_squash,all_squash,insecure,no_subtree_check'

View File

@ -0,0 +1,75 @@
#!/bin/sh /etc/rc.common
START=45
STOP=99
NAME="nfs"
nfs_share() {
local enabled path clients options
config_get_bool enabled "$1" enabled 0
for opt in path clients options
do
config_get "$opt" "$1" "$opt"
done
if [ "$enabled" = 1 ]; then
grep -qs $path /etc/exports
if [ $? -ne 0 ]; then
echo -e "$path\t$clients($options)" >>/etc/exports
exportfs -r
fi
elif [ "$enabled" = 0 ]; then
exportfs -u | grep -qs $path
if [ $? -eq 0 ]; then
exportfs -u $clients:$path
fi
fi
exportfs -r
}
nfs_share_stop() {
exportfs -au &>/dev/null
}
nfs_mount() {
local enabled target source options delay
config_get_bool enabled "$1" enabled 0
for opt in target source options delay
do
config_get "$opt" "$1" "$opt"
done
if [ "$enabled" = 1 ]; then
if [ "$delay" -a $delay -gt 0 ]; then
logger "NetMount: Sleep $delay seconds before mount"
sleep $delay
fi
grep -qs $target /proc/mounts
if [ $? -ne 0 ]; then
mkdir -p $target
logger "NetMount: Mounting $source in $target"
mount -t nfs -o $options $source $target
fi
elif [ "$enabled" = 0 ]; then
if grep -qs $target /proc/mounts; then
umount -fr $target
sleep $delay
fi
fi
}
start() {
config_load "$NAME"
config_foreach nfs_share share
config_foreach nfs_mount mount
}
stop() {
nfs_share_stop
}
restart() {
echo > /etc/exports
start
}

View File

@ -0,0 +1,14 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@nfs[-1]
add ucitrack nfs
set ucitrack.@nfs[-1].init=nfs
commit ucitrack
EOF
/etc/init.d/nfs enable && /etc/init.d/nfs restart
rm -f /tmp/luci-indexcache
exit 0