mirror of
https://github.com/kenzok8/openwrt-packages
synced 2025-01-07 07:06:45 +08:00
update 2023-08-19 02:01:07
This commit is contained in:
parent
04c53c98e5
commit
da38c64796
24
luci-app-partexp/Makefile
Normal file
24
luci-app-partexp/Makefile
Normal file
@ -0,0 +1,24 @@
|
||||
#
|
||||
# Copyright (C) 2020-2022 sirpdboy <herboy2008@gmail.com>
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v3.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-partexp
|
||||
PKG_VERSION:=0.1.9
|
||||
PKG_RELEASE:=20221201
|
||||
|
||||
PKG_LICENSE:=Apache-2.0
|
||||
PKG_MAINTAINER:=Sirpdboy <herboy2008@gmail.com>
|
||||
|
||||
LUCI_TITLE:=LuCI Support for Automatic Partition Mount
|
||||
LUCI_DEPENDS:=+fdisk +block-mount
|
||||
LUCI_PKGARCH:=all
|
||||
|
||||
|
||||
include $(TOPDIR)/feeds/luci/luci.mk
|
||||
|
||||
|
||||
# call BuildPackage - OpenWrt buildroot signature
|
116
luci-app-partexp/README.md
Normal file
116
luci-app-partexp/README.md
Normal file
@ -0,0 +1,116 @@
|
||||
### 访问数:[![](https://visitor-badge.glitch.me/badge?page_id=sirpdboy-visitor-badge)] [![](https://img.shields.io/badge/TG群-点击加入-FFFFFF.svg)](https://t.me/joinchat/AAAAAEpRF88NfOK5vBXGBQ)
|
||||
|
||||
![screenshots](https://raw.githubusercontent.com/sirpdboy/openwrt/master/doc/说明1.jpg)
|
||||
|
||||
=
|
||||
# luci-app-partexp
|
||||
|
||||
luci-app-partexp 一键自动格式化分区、扩容、自动挂载插件
|
||||
[![若部分图片无法正常显示,请挂上机场浏览或点这里到末尾看修复教程](https://visitor-badge.glitch.me/badge?page_id=sirpdboy-visitor-badge)](#解决-github-网页上图片显示失败的问题) [![](https://img.shields.io/badge/TG群-点击加入-FFFFFF.svg)](https://t.me/joinchat/AAAAAEpRF88NfOK5vBXGBQ)
|
||||
|
||||
[luci-app-partexp](https://github.com/sirpdboy/luci-app-partexp)
|
||||
======================
|
||||
|
||||
|
||||
请 **认真阅读完毕** 本页面,本页面包含注意事项和如何使用。
|
||||
|
||||
## 功能说明:
|
||||
|
||||
|
||||
#### 一键自动格式化分区、扩容、自动挂载插件,专为OPENWRT设计,简化OPENWRT在分区挂载上烦锁的操作。本插件是sirpdboy耗费大量精力制作测试,请勿删除制作者信息!!
|
||||
|
||||
<!-- TOC -->
|
||||
|
||||
- [partexp](#luci-app-partexp)
|
||||
- [特性](#特性)
|
||||
- [使用方法](#使用方法)
|
||||
- [说明](#说明)
|
||||
- [界面](#界面)
|
||||
- [捐助](#捐助)
|
||||
|
||||
<!-- /TOC -->
|
||||
|
||||
## 特性
|
||||
luci-app-partexp 自动获格式化分区扩容,自动挂载插件
|
||||
|
||||
## 使用方法
|
||||
|
||||
- 将luci-app-partexp添加至 LEDE/OpenWRT 源码的方法。
|
||||
|
||||
### 下载源码方法:
|
||||
|
||||
```Brach
|
||||
|
||||
# 下载源码
|
||||
|
||||
git clone https://github.com/sirpdboy/luci-app-partexp.git package/luci-app-partexp
|
||||
make menuconfig
|
||||
|
||||
```
|
||||
### 配置菜单
|
||||
|
||||
```Brach
|
||||
make menuconfig
|
||||
# 找到 LuCI -> Applications, 选择 luci-app-partexp, 保存后退出。
|
||||
```
|
||||
|
||||
### 编译
|
||||
|
||||
```Brach
|
||||
# 编译固件
|
||||
make package/luci-app-partexp/compile V=s
|
||||
```
|
||||
|
||||
## 说明
|
||||
|
||||
![screenshots](https://raw.githubusercontent.com/sirpdboy/openwrt/master/doc/说明2.jpg)
|
||||
|
||||
## 界面
|
||||
|
||||
![screenshots](https://raw.githubusercontent.com/sirpdboy/openwrt/master/doc/partexp.jpg)
|
||||
|
||||
|
||||
|
||||
|
||||
## 使用与授权相关说明
|
||||
|
||||
- 本人开源的所有源码,任何引用需注明本处出处,如需修改二次发布必告之本人,未经许可不得做于任何商用用途。
|
||||
|
||||
|
||||
# My other project
|
||||
|
||||
- 网络速度测试 :https://github.com/sirpdboy/NetSpeedTest
|
||||
|
||||
- 定时设置插件 : https://github.com/sirpdboy/luci-app-autotimeset
|
||||
|
||||
- 关机功能插件 : https://github.com/sirpdboy/luci-app-poweroffdevice
|
||||
|
||||
- opentopd主题 : https://github.com/sirpdboy/luci-theme-opentopd
|
||||
|
||||
- kucat 主题: https://github.com/sirpdboy/luci-theme-kucat
|
||||
|
||||
- 家长控制: https://github.com/sirpdboy/luci-theme-parentcontrol
|
||||
|
||||
- 系统高级设置 : https://github.com/sirpdboy/luci-app-advanced
|
||||
|
||||
- ddns-go动态域名: https://github.com/sirpdboy/luci-app-ddns-go
|
||||
|
||||
- 进阶设置(系统高级设置+主题设置kucat/agron/opentopd): https://github.com/sirpdboy/luci-app-advancedplus
|
||||
|
||||
- 设置向导: https://github.com/sirpdboy/luci-app-wizard
|
||||
|
||||
- 分区扩容: https://github.com/sirpdboy/luci-app-partexp
|
||||
|
||||
- lukcy大吉: https://github.com/sirpdboy/luci-app-lukcy
|
||||
|
||||
## 捐助
|
||||
|
||||
![screenshots](https://raw.githubusercontent.com/sirpdboy/openwrt/master/doc/说明3.jpg)
|
||||
|
||||
| <img src="https://img.shields.io/badge/-支付宝-F5F5F5.svg" href="#赞助支持本项目-" height="25" alt="图飞了😂"/> | <img src="https://img.shields.io/badge/-微信-F5F5F5.svg" height="25" alt="图飞了😂" href="#赞助支持本项目-"/> |
|
||||
| :-----------------: | :-------------: |
|
||||
|![xm1](https://raw.githubusercontent.com/sirpdboy/openwrt/master/doc/支付宝.png) | ![xm1](https://raw.githubusercontent.com/sirpdboy/openwrt/master/doc/微信.png) |
|
||||
|
||||
<a href="#readme">
|
||||
<img src="https://img.shields.io/badge/-返回顶部-orange.svg" alt="图飞了😂" title="返回顶部" align="right"/>
|
||||
</a>
|
80
luci-app-partexp/luasrc/controller/partexp.lua
Normal file
80
luci-app-partexp/luasrc/controller/partexp.lua
Normal file
@ -0,0 +1,80 @@
|
||||
--[[
|
||||
LuCI - Lua Configuration Partition Expansion
|
||||
Copyright (C) 2022 sirpdboy <herboy2008@gmail.com> https://github.com/sirpdboy/luci-app-partexp
|
||||
]]--
|
||||
require "luci.util"
|
||||
local name = 'partexp'
|
||||
|
||||
module("luci.controller.partexp", package.seeall)
|
||||
function index()
|
||||
entry({"admin","system","partexp"},alias("admin", "system", "partexp", "global"),_("Partition Expansion"), 54)
|
||||
-- entry({"admin", "system", "partexp", "global"}, form("partexp/global"), nil).leaf = true
|
||||
entry({"admin", "system", "partexp", "global"}, cbi('partexp/global', {hideapplybtn = true, hidesavebtn = true, hideresetbtn = true}), _('Partition Expansion'), 10).leaf = true
|
||||
entry({"admin", "system", "partexp","partexprun"}, call("partexprun")).leaf = true
|
||||
end
|
||||
|
||||
function get_log()
|
||||
local e = {}
|
||||
e.running = luci.sys.call("busybox ps -w | grep partexp | grep -v grep >/dev/null") == 0
|
||||
e.log = fs.readfile("/etc/partexp/partexp.log") or ""
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
||||
|
||||
function partexprun()
|
||||
local uci = luci.model.uci.cursor()
|
||||
local keep_config = luci.http.formvalue('keep_config')
|
||||
local auto_format = luci.http.formvalue('auto_format')
|
||||
local target_function = luci.http.formvalue('target_function')
|
||||
local target_disk = luci.http.formvalue('target_disk')
|
||||
--uci:delete(name, '@global[0]', global)
|
||||
uci:set(name, '@global[0]', 'target_disk', target_disk)
|
||||
uci:set(name, '@global[0]', 'target_function', target_function)
|
||||
uci:set(name, '@global[0]', 'auto_format', auto_format)
|
||||
uci:set(name, '@global[0]', 'keep_config', keep_config)
|
||||
uci:commit(name)
|
||||
-- e = nixio.exec("/bin/sh", "-c" ,"/etc/init.d/partexp autopart")
|
||||
e = luci.sys.exec('/etc/init.d/partexp autopart')
|
||||
|
||||
luci.http.prepare_content('application/json')
|
||||
luci.http.write_json(e)
|
||||
end
|
||||
|
||||
function outexec(cmd)
|
||||
luci.http.prepare_content("text/plain")
|
||||
local util = io.popen(cmd)
|
||||
if util then
|
||||
while true do
|
||||
local ln = util:read("*l")
|
||||
if not ln then break end
|
||||
luci.http.write(ln)
|
||||
luci.http.write("\n")
|
||||
end
|
||||
util:close()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function fork_exec(command)
|
||||
local pid = nixio.fork()
|
||||
if pid > 0 then
|
||||
return
|
||||
elseif pid == 0 then
|
||||
-- change to root dir
|
||||
nixio.chdir("/")
|
||||
|
||||
-- patch stdin, out, err to /dev/null
|
||||
local null = nixio.open("/dev/null", "w+")
|
||||
if null then
|
||||
nixio.dup(null, nixio.stderr)
|
||||
nixio.dup(null, nixio.stdout)
|
||||
nixio.dup(null, nixio.stdin)
|
||||
if null:fileno() > 2 then
|
||||
null:close()
|
||||
end
|
||||
end
|
||||
|
||||
-- replace with target command
|
||||
nixio.exec("/bin/sh", "-c", command)
|
||||
end
|
||||
end
|
83
luci-app-partexp/luasrc/model/cbi/partexp/global.lua
Normal file
83
luci-app-partexp/luasrc/model/cbi/partexp/global.lua
Normal file
@ -0,0 +1,83 @@
|
||||
--[[
|
||||
LuCI - Lua Configuration Interface
|
||||
Copyright (C) 2022 sirpdboy <herboy2008@gmail.com> https://github.com/sirpdboy/luci-app-partexp
|
||||
]]--
|
||||
local fs = require "nixio.fs"
|
||||
local util = require "nixio.util"
|
||||
local tp = require "luci.template.parser"
|
||||
local uci=luci.model.uci.cursor()
|
||||
-- get all device names (sdX and mmcblkX)
|
||||
local target_devnames = {}
|
||||
for dev in fs.dir("/dev") do
|
||||
if dev:match("^sd[a-z]$")
|
||||
or dev:match("^mmcblk%d+$")
|
||||
or dev:match("^sata[a-z]$")
|
||||
or dev:match("^nvme%d+n%d+$")
|
||||
then
|
||||
table.insert(target_devnames, dev)
|
||||
end
|
||||
end
|
||||
local devices = {}
|
||||
for i, bname in pairs(target_devnames) do
|
||||
local device_info = {}
|
||||
local device = "/dev/" .. bname
|
||||
device_info["name"] = bname
|
||||
device_info["dev"] = device
|
||||
|
||||
s = tonumber((fs.readfile("/sys/class/block/%s/size" % bname)))
|
||||
device_info["size"] = s and math.floor(s / 2048)
|
||||
|
||||
devices[#devices+1] = device_info
|
||||
end
|
||||
|
||||
local m,t,e
|
||||
m = Map("partexp", "<font color='green'>" .. translate("One click partition expansion mounting tool") .."</font>",
|
||||
translate( "Automatically format and mount the target device partition. If there are multiple partitions, it is recommended to manually delete all partitions before using this tool.<br/>For specific usage, see:") ..translate("<a href=\'https://github.com/sirpdboy/luci-app-partexp.git' target=\'_blank\'>GitHub @sirpdboy</a>") )
|
||||
|
||||
t=m:section(TypedSection,"global")
|
||||
t.anonymous=true
|
||||
|
||||
e=t:option(ListValue,"target_function", translate("Select function"),translate("Select the function to be performed"))
|
||||
e:value("/overlay", translate("Expand application space overlay (/overlay)"))
|
||||
-- e:value("/", translate("Use as root filesystem (/)"))
|
||||
e:value("/opt", translate("Used as Docker data disk (/opt)"))
|
||||
e:value("/dev", translate("Normal mount and use by device name(/dev/x1)"))
|
||||
|
||||
e=t:option(ListValue,"target_disk", translate("Destination hard disk"),translate("Select the hard disk device to operate"))
|
||||
for i, d in ipairs(devices) do
|
||||
if d.name and d.size then
|
||||
e:value(d.name, "%s (%s, %d MB)" %{ d.name, d.dev, d.size })
|
||||
elseif d.name then
|
||||
e:value(d.name, "%s (%s)" %{ d.name, d.dev })
|
||||
end
|
||||
end
|
||||
|
||||
o=t:option(Flag,"keep_config",translate("Keep configuration"))
|
||||
o:depends("target_function", "/overlay")
|
||||
o.default=0
|
||||
|
||||
o=t:option(Flag,'auto_format', translate('Format before use'))
|
||||
o:depends("target_function", "/opt")
|
||||
o:depends("target_function", "/dev")
|
||||
o.default=0
|
||||
|
||||
o=t:option(DummyValue, '', '')
|
||||
o.rawhtml = true
|
||||
o.template ='partexp'
|
||||
|
||||
|
||||
e=t:option(TextValue,"log")
|
||||
e.rows=15
|
||||
e.wrap="on"
|
||||
e.readonly=true
|
||||
e.cfgvalue=function(t,t)
|
||||
return fs.readfile("/etc/partexp/partexp.log")or""
|
||||
end
|
||||
e.write=function(e,e,e)
|
||||
end
|
||||
|
||||
-- e =t:option(DummyValue, '', '')
|
||||
-- e.rawhtml = true
|
||||
-- e.template = 'partexplog'
|
||||
|
||||
return m
|
40
luci-app-partexp/luasrc/model/diskmount.lua
Normal file
40
luci-app-partexp/luasrc/model/diskmount.lua
Normal file
@ -0,0 +1,40 @@
|
||||
--[[
|
||||
LuCI - Lua Configuration Interface
|
||||
Copyright (C) 2022 sirpdboy <herboy2008@gmail.com> https://github.com/sirpdboy/luci-app-partexp
|
||||
]]--
|
||||
|
||||
local fs = require "nixio.fs"
|
||||
local util = require "nixio.util"
|
||||
local tp = require "luci.template.parser"
|
||||
local uci=luci.model.uci.cursor()
|
||||
local ver = require "luci.version"
|
||||
|
||||
local d.list_disks = function()
|
||||
-- get all device names (sdX and mmcblkX)
|
||||
local target_devnames = {}
|
||||
for dev in fs.dir("/dev") do
|
||||
if dev:match("^sd[a-z]$")
|
||||
or dev:match("^mmcblk%d+$")
|
||||
or dev:match("^sata[a-z]$")
|
||||
or dev:match("^nvme%d+n%d+$")
|
||||
then
|
||||
table.insert(target_devnames, dev)
|
||||
end
|
||||
end
|
||||
local devices = {}
|
||||
for i, bname in pairs(target_devnames) do
|
||||
local device_info = {}
|
||||
local device = "/dev/" .. bname
|
||||
device_info["name"] = bname
|
||||
device_info["dev"] = device
|
||||
|
||||
s = tonumber((fs.readfile("/sys/class/block/%s/size" % bname)))
|
||||
device_info["size"] = s and math.floor(s / 2048)
|
||||
|
||||
devices[#devices+1] = device_info
|
||||
end
|
||||
return devices
|
||||
end
|
||||
|
||||
|
||||
return d
|
106
luci-app-partexp/luasrc/view/partexp.htm
Normal file
106
luci-app-partexp/luasrc/view/partexp.htm
Normal file
@ -0,0 +1,106 @@
|
||||
<%#
|
||||
Copyright (C) 2022 sirpdboy <herboy2008@gmail.com> https://github.com/sirpdboy/luci-app-partexp
|
||||
-%>
|
||||
<%
|
||||
local fs = require "nixio.fs"
|
||||
%>
|
||||
|
||||
<%+cbi/valueheader%>
|
||||
|
||||
<script src="/luci-static/vssr/jquery.min.js"></script>
|
||||
<label class="cbi-value-title"><%= translate("Select the function to be performed") %></label>
|
||||
<div class="cbi-value-field">
|
||||
<input class="cbi-button cbi-button-reload" id="go_partexprun" type="button" value="<%= translate("Perform operation") %>">
|
||||
|
||||
</div>
|
||||
<fieldset class="cbi-section" style="display:none">
|
||||
<legend id="partexprun-legend">
|
||||
<%:Collecting data...%>
|
||||
</legend>
|
||||
<span id="partexprun-output"></span>
|
||||
</fieldset>
|
||||
|
||||
<script type="text/javascript">
|
||||
const PARTEXP_RUN_URL = '<%=luci.dispatcher.build_url("admin", "system", "partexp","partexprun")%>';
|
||||
const PARTEXP_URL = '<%=luci.dispatcher.build_url("admin", "system", "partexp","global")%>';
|
||||
|
||||
var legend = document.getElementById('partexprun-legend');
|
||||
var output = document.getElementById('partexprun-output');
|
||||
|
||||
|
||||
$(document).ready(function(){
|
||||
// alert("hello");
|
||||
function go_run() {
|
||||
legend.style.display = 'none';
|
||||
output.innerHTML ='</p><%:After operation, restart the machine, please wait...%></p>';
|
||||
setTimeout(() => { window.location = PARTEXP_URL }, 6000);
|
||||
}
|
||||
|
||||
function go_err() {
|
||||
legend.style.display = 'none';
|
||||
output.innerHTML ='</p><%:Please delete the partition or share and try again%></p>';
|
||||
setTimeout(() => { window.location = PARTEXP_URL }, 6000);
|
||||
}
|
||||
$("#go_partexprun").click(function () {
|
||||
if (confirm('<%:Restart the device to take effect. Confirm whether to continue?%>'))
|
||||
{
|
||||
|
||||
prefix_array = $("#cbi-partexp .cbi-section-node").attr("id").split("-");
|
||||
prefix_array[0] = "cbid";
|
||||
prefix = prefix_array.join(".");
|
||||
output.innerHTML =
|
||||
'<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" /> ' +
|
||||
'<%:Operation in progress, please wait...%>'
|
||||
;
|
||||
legend.parentNode.style.display = 'block';
|
||||
legend.style.display = 'inline';
|
||||
var target_function = $("[name='" + prefix + ".target_function']").val();
|
||||
if ($("[name='" + prefix + ".keep_config']").is(":checked")) {
|
||||
var keep_config = "1";
|
||||
} else {
|
||||
var keep_config = "0";
|
||||
}
|
||||
var target_disk = $("[name='" + prefix + ".target_disk']").val();
|
||||
|
||||
if ($("[name='" + prefix + ".auto_format']").is(":checked")) {
|
||||
var auto_format = "1";
|
||||
} else {
|
||||
var auto_format = "0";
|
||||
}
|
||||
|
||||
|
||||
var data = {
|
||||
keep_config: keep_config,
|
||||
target_disk: target_disk,
|
||||
auto_format: auto_format,
|
||||
target_function: target_function
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
type: "post",
|
||||
url: PARTEXP_RUN_URL,
|
||||
dataType: "json",
|
||||
data: data,
|
||||
success: function (d) {
|
||||
if (d == 2) {
|
||||
legend.style.display = 'none';
|
||||
output.innerHTML ='</p><%:After operation, restart the machine, please wait...%></p>';
|
||||
|
||||
} else {
|
||||
legend.style.display = 'none';
|
||||
output.innerHTML ='</p> <%:Operation execution complete%></p>';
|
||||
}
|
||||
setTimeout(() => { window.location = PARTEXP_URL }, 5000);
|
||||
}
|
||||
|
||||
});
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<%+cbi/valuefooter%>
|
16
luci-app-partexp/luasrc/view/partexp/log.htm
Normal file
16
luci-app-partexp/luasrc/view/partexp/log.htm
Normal file
@ -0,0 +1,16 @@
|
||||
<%+cbi/valueheader%>
|
||||
<textarea id="logview.list" class="cbi-input-textarea" style="width: 100%" rows="20" readonly="readonly"></textarea>
|
||||
|
||||
<script type="text/javascript">
|
||||
const LOG_URL = '<%=luci.dispatcher.build_url("admin", "system", "partexp","realtime_log")%>';
|
||||
|
||||
XHR.poll(1, LOG_URL, null, (x, d) => {
|
||||
let logview = document.getElementById("logview.list");
|
||||
if (!d.running) {
|
||||
XHR.halt();
|
||||
}
|
||||
logview.value = d.log;
|
||||
logview.scrollTop = logview.scrollHeight;
|
||||
});
|
||||
</script>
|
||||
<%+cbi/valuefooter%>
|
70
luci-app-partexp/po/zh-cn/partexp.po
Normal file
70
luci-app-partexp/po/zh-cn/partexp.po
Normal file
@ -0,0 +1,70 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Copyright (C) 2022 sirpdboy herboy2008@gmail.com https://github.com/sirpdboy/luci-app-partexp"
|
||||
"This is free software, licensed under the GNU General Public License v3."
|
||||
|
||||
msgid "Partition Expansion"
|
||||
msgstr "分区扩容"
|
||||
|
||||
msgid "One click partition expansion mounting tool"
|
||||
msgstr "一键分区扩容挂载工具"
|
||||
|
||||
msgid "Automatically format and mount the target device partition. If there are multiple partitions, it is recommended to manually delete all partitions before using this tool.<br/>For specific usage, see:"
|
||||
msgstr "自动对目标设备分区格式化挂载,如果有多分区建议手动删除所有分区再使用本工具.<br/>使用说明见:"
|
||||
|
||||
msgid "Select the function to be performed"
|
||||
msgstr "选择需要执行的功能"
|
||||
|
||||
msgid "Expand application space overlay (/overlay)"
|
||||
msgstr "用于overlay软件空间 (/overlay)"
|
||||
|
||||
msgid "Use as root filesystem (/)"
|
||||
msgstr "用作根文件系统(/)"
|
||||
|
||||
msgid "Used as Docker data disk (/opt)"
|
||||
msgstr "用作Docker数据盘 (/opt)"
|
||||
|
||||
msgid "Normal mount and use by device name(/dev/x1)"
|
||||
msgstr "按设备名普通挂载使用(/dev/x1)"
|
||||
|
||||
msgid "Destination hard disk"
|
||||
msgstr "目标硬盘"
|
||||
|
||||
msgid "Keep configuration"
|
||||
msgstr "保留配置"
|
||||
|
||||
msgid "Format before use"
|
||||
msgstr "使用前格式化"
|
||||
|
||||
msgid "Select the hard disk device to operate"
|
||||
msgstr "选择需要操作的硬盘设备"
|
||||
|
||||
msgid "Select function"
|
||||
msgstr "选择功能"
|
||||
|
||||
msgid "Perform operation"
|
||||
msgstr "执行操作"
|
||||
|
||||
msgid "To make the operation effective, the device will restart. Are you sure to execute?"
|
||||
msgstr "警告:操作一旦确定无法取消,设备将会重启,是否确定执行?"
|
||||
|
||||
msgid "Operation in progress, please wait..."
|
||||
msgstr "操作执行中,请稍候..."
|
||||
|
||||
msgid "After operation, restart the machine, please wait..."
|
||||
msgstr "操作完毕,机器重启,请稍候..."
|
||||
|
||||
msgid "Please delete the partition or share and try again"
|
||||
msgstr "错误,请检查是否有足够空间或是共享使用中。"
|
||||
|
||||
msgid "Restart the device to take effect. Confirm whether to continue?"
|
||||
msgstr "重启设备操作才生效,确定是否继续执行?"
|
||||
|
||||
msgid "Operation execution complete"
|
||||
msgstr "操作执行完毕"
|
||||
|
||||
msgid "Ticking indicates formatting"
|
||||
msgstr "打勾选择表示格式化"
|
||||
|
||||
msgid "Tick means to retain the settings"
|
||||
msgstr "打勾选择表示保留设置"
|
1
luci-app-partexp/po/zh_Hans
Normal file
1
luci-app-partexp/po/zh_Hans
Normal file
@ -0,0 +1 @@
|
||||
zh-cn
|
5
luci-app-partexp/root/etc/config/partexp
Normal file
5
luci-app-partexp/root/etc/config/partexp
Normal file
@ -0,0 +1,5 @@
|
||||
config global
|
||||
option target_function '/overlay'
|
||||
option target_disk ''
|
||||
option keep_config '1'
|
||||
option auto_format '1'
|
298
luci-app-partexp/root/etc/init.d/partexp
Normal file
298
luci-app-partexp/root/etc/init.d/partexp
Normal file
@ -0,0 +1,298 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
#
|
||||
# Copyright (C) 2021-2022 sirpdboy <herboy2008@gmail.com> https://github.com/sirpdboy/luci-app-partexp
|
||||
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
|
||||
EXTRA_COMMANDS="autopart"
|
||||
|
||||
LOCK=/var/lock/partexp.lock
|
||||
LOGD=/etc/partexp
|
||||
LOG=/etc/partexp/partexp.log
|
||||
|
||||
limit_log() {
|
||||
local logf=$1
|
||||
[ ! -f "$logf" ] && return
|
||||
local sc=100
|
||||
[ -n "$2" ] && sc=$2
|
||||
local count=$(grep -c "" $logf)
|
||||
if [ $count -gt $sc ];then
|
||||
let count=count-$sc
|
||||
sed -i "1,$count d" $logf
|
||||
fi
|
||||
}
|
||||
|
||||
init_env() {
|
||||
[ -d "$LOGD" ] || mkdir -p $LOGD
|
||||
[ ! -f "$LOG" ] && echo "" > $LOG
|
||||
|
||||
}
|
||||
|
||||
|
||||
gen_log()(
|
||||
[ -s $LOG ] && echo " ---------------------------------------------------------------------- " >> $LOG
|
||||
log "自动分区扩展挂载开始执行..."
|
||||
)
|
||||
|
||||
log(){
|
||||
echo " $(date +'%Y-%m-%d %H:%M:%S') $*" >> $LOG
|
||||
}
|
||||
|
||||
|
||||
get_config() {
|
||||
config_get target_function $1 target_function 1
|
||||
config_get target_disk $1 target_disk 1
|
||||
config_get_bool keep_config $1 keep_config 1
|
||||
config_get_bool auto_format $1 auto_format 1
|
||||
}
|
||||
nfdisk(){
|
||||
#Start partition
|
||||
fdisk /dev/$a << EOF >/dev/null 2> /dev/null
|
||||
n
|
||||
p
|
||||
|
||||
|
||||
|
||||
wq
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
fdiskB(){
|
||||
a=$1
|
||||
b=$2
|
||||
log "检测$a是否分区..."
|
||||
isP=`fdisk -l /dev/$a |grep -v "bytes"|grep "/dev/$a$b" `
|
||||
sleep 2
|
||||
isfdisk=0
|
||||
if [ ! "$isP" ];then
|
||||
nfdisk
|
||||
sleep 2
|
||||
isfdisk=1
|
||||
|
||||
else
|
||||
isfdisk=2
|
||||
fi
|
||||
isP=`fdisk -l /dev/$a |grep -v "bytes" | grep "/dev/$a$b"`
|
||||
if [ "$isP" -a "$isfdisk" = 1 ] ;then
|
||||
log "分区$a$b建立成功!"
|
||||
elif [ "$isP" -a "$isfdisk" = 2 ] ;then
|
||||
log "检测目标分区$a$b已存在."
|
||||
else
|
||||
log "分区$a$b建立失败,没有足够的空间操作失败!"
|
||||
expquit 1
|
||||
fi
|
||||
isD=`df -T | grep /dev/$a$b `
|
||||
if [ "$isD" ];then
|
||||
eval $(block info "/dev/$a$b" | grep -o -e "MOUNT=\S*")
|
||||
log "检测$a$b是不是被共享..."
|
||||
sleep 1
|
||||
if [ "$MOUNT" ] ; then
|
||||
msum=$(grep -c "config sambashare" /etc/config/samba4)
|
||||
for i in $(seq 0 $((msum-1)))
|
||||
do
|
||||
dev=`uci -q get samba4.@sambashare[$i].device `
|
||||
[ $? -ne 0 ] && break
|
||||
[ "$dev" = "$a$b" ] && {
|
||||
uci delete samba4.@sambashare[$i]
|
||||
uci commit
|
||||
/etc/init.d/samba4 restart &
|
||||
sleep 5
|
||||
|
||||
}
|
||||
done
|
||||
block umount /dev/$a$b
|
||||
sleep 5
|
||||
eval $(block info "/dev/$a$b" | grep -o -e "MOUNT=\S*")
|
||||
if [ "$MOUNT" ] ;then
|
||||
log "分区$a$b被挂载$MOUNT共享使用,删除共享失败,请手动删除共享再重新操作!"
|
||||
expquit 1
|
||||
else
|
||||
log "分区$a$b被挂载$MOUNT共享使用,自动删除共享成功!"
|
||||
fi
|
||||
else
|
||||
log "检测目标硬盘$a$b未被共享..."
|
||||
fi
|
||||
fi
|
||||
isD=`df -T | grep /dev/$a$b | awk '{print $2}'`
|
||||
if [ "$target_function" = "/" -o "$target_function" = "/overlay" ] ; then
|
||||
mkfs.ext4 -L extroot /dev/$a$b >/dev/null 2> /dev/null
|
||||
log "硬盘/dev/$a$b格式化成功!"
|
||||
elif [ "$auto_format" = "1" -o "$isfdisk" = "1" - ! "$isD" ] ; then
|
||||
mkfs.ext4 -F /dev/$a$b >/dev/null 2> /dev/null
|
||||
log "硬盘/dev/$a$b格式化成功!"
|
||||
else
|
||||
log "硬盘/dev/$a$b无需格式化!"
|
||||
fi
|
||||
eval $(block info /dev/$a$b | grep -o -e "UUID=\S*")
|
||||
if [ "$UUID" = "" ] ; then
|
||||
log "获取/dev/$a$b分区信息失败!"
|
||||
expquit 1
|
||||
else
|
||||
log "成功获取/dev/$a$b分区信息!"
|
||||
fi
|
||||
[ -d "/mnt/$a$b" ] || mkdir -p /mnt/$a$b
|
||||
isM=`block info /dev/$a$b`
|
||||
isD=`df -T | grep /dev/$a$b | awk '{print $2}'`
|
||||
if [ "$isM" -a "$isD" ] ;then
|
||||
umount /mnt/$a$b
|
||||
eval $(block info "/dev/$a$b" | grep -o -e "MOUNT=\S*")
|
||||
if [ "$MOUNT" ] ; then
|
||||
log "检测设备/dev/$a$b挂载$MOUNT,请取消读写权限再重试!"
|
||||
expquit 1
|
||||
else
|
||||
[ "$isD" == "ntfs" ] && mount -t ntfs-3g /dev/$a$b /mnt/$a$b || mount -o rw,noatime,discard /dev/$a$b /mnt/$a$b
|
||||
fi
|
||||
fi
|
||||
log "检测设备/dev/$a$b分区是$isD格式!"
|
||||
|
||||
if [ "$target_function" = "/" ] ; then
|
||||
mkdir -p /tmp/introot
|
||||
mount --bind / /tmp/introot
|
||||
tar -C /tmp/introot -cvf - . | tar -C /mnt/$a$b -xf -
|
||||
umount /tmp/introot
|
||||
umount /mnt/$a$b
|
||||
block detect > /etc/config/fstab
|
||||
log "保留数据根目录扩展/dev/$a$b成功!"
|
||||
uci set fstab.@global[0].delay_root="15"
|
||||
uci -q set fstab.@mount[0].uuid="${UUID}"
|
||||
uci -q set fstab.@mount[0].target='/'
|
||||
uci -q set fstab.@mount[0].enabled='1'
|
||||
uci commit fstab
|
||||
|
||||
expquit 2
|
||||
|
||||
elif [ "$target_function" = "/overlay" ] ; then
|
||||
if [ "$keep_config" = "1" ] ; then
|
||||
|
||||
# cp -a -f /overlay/* /mnt/$a$b/ || cp -a -f /rom/overlay/* /mnt/$a$b/
|
||||
tar -C /overlay -cvf - . | tar -C /mnt/$a$b/ -xf - || tar -C /rom/overlay -cvf - . | tar -C /mnt/$a$b/ -xf -
|
||||
umount /mnt/$a$b
|
||||
block detect > /etc/config/fstab
|
||||
|
||||
msum=$(grep -c "'mount'" /etc/config/fstab)
|
||||
for i in $(seq 0 $((msum-1)))
|
||||
do
|
||||
zuuid=`uci -q get fstab.@mount[$i].uuid `
|
||||
[ $? -ne 0 ] && break
|
||||
if [ "$zuuid" = "$UUID" ] ; then
|
||||
uci -q set fstab.@mount[$i].target="/overlay"
|
||||
uci -q set fstab.@mount[$i].enabled='1'
|
||||
fi
|
||||
done
|
||||
uci set fstab.@global[0].delay_root="15"
|
||||
uci commit fstab
|
||||
log "保留数据overlay扩展/dev/$a$b成功!"
|
||||
log "设备重启才能生效,重启中..."
|
||||
expquit 2
|
||||
|
||||
else
|
||||
|
||||
umount /mnt/$a$b
|
||||
block detect > /etc/config/fstab
|
||||
|
||||
|
||||
msum=$(grep -c "'mount'" /etc/config/fstab)
|
||||
for i in $(seq 0 $((msum-1)))
|
||||
do
|
||||
zuuid=`uci -q get fstab.@mount[$i].uuid `
|
||||
[ $? -ne 0 ] && break
|
||||
if [ "$zuuid" = "$UUID" ] ; then
|
||||
uci -q set fstab.@mount[$i].target="/overlay"
|
||||
uci -q set fstab.@mount[$i].enabled='1'
|
||||
fi
|
||||
done
|
||||
uci set fstab.@global[0].delay_root="15"
|
||||
uci commit fstab
|
||||
log "不保留数据overlay扩展/dev/$a$b成功!"
|
||||
log "设备重启才能生效,重启中..."
|
||||
expquit 2
|
||||
|
||||
fi
|
||||
else
|
||||
block detect > /etc/config/fstab
|
||||
mkdir -p $target_function
|
||||
msum=$(grep -c "'mount'" /etc/config/fstab)
|
||||
for i in $(seq 0 $((msum-1)))
|
||||
do
|
||||
zuuid=`uci -q get fstab.@mount[$i].uuid `
|
||||
[ $? -ne 0 ] && break
|
||||
if [ "$zuuid" = "$UUID" ] ; then
|
||||
|
||||
[ "$target_function" = "/opt" ] && uci -q set fstab.@mount[$i].target="$target_function" || uci -q set fstab.@mount[$i].target="/mnt/$a$b"
|
||||
|
||||
uci -q set fstab.@mount[$i].enabled='1'
|
||||
fi
|
||||
done
|
||||
uci commit fstab
|
||||
[ "$target_function" = "/opt" ] && log "挂载/dev/$a$b到$target_function成功!" || log "挂载/dev/$a$b到/mnt/$a$b成功!"
|
||||
log "设备重启才能生效,重启中..."
|
||||
expquit 2
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
autopart() {
|
||||
# [ -f $LOCK ] && exit
|
||||
config_load partexp
|
||||
config_foreach get_config global
|
||||
init_env
|
||||
limit_log $LOG 500
|
||||
# touch $LOCK
|
||||
cat $LOG 2>/dev/null | sed -n '$p' | grep -q '自动分区扩展挂载开始执行...' || gen_log
|
||||
|
||||
isB=`df -P|grep '/boot' | head -n1 | awk -F ' ' '{print $1}'`
|
||||
isb=`fdisk -l | grep /dev/$target_disk | grep -v "bytes" | wc -l`
|
||||
if [ "$isb" = 0 -o "$isb" = "" -o "$isb" = 1 ] ;then
|
||||
isb=1
|
||||
elif [ "$isb" = 3 -o "$isb" = 4 ] ;then
|
||||
isb=3
|
||||
fi
|
||||
isP=`fdisk -l /dev/$target_disk |grep "Disk /dev/$target_disk"`
|
||||
if [ "$isP" = "" ];then
|
||||
log "没有检测到/dev/$target_disk目标硬盘!操作失败!"
|
||||
expquit 1
|
||||
else
|
||||
log "检测到操作目标硬盘:/dev/$target_disk$isb!"
|
||||
|
||||
case "$target_disk" in
|
||||
sd*)
|
||||
[ "$isB" = "/dev/${target_disk}1" -a "$target_function" = "/overlay" ] && fdiskB $target_disk 3 || fdiskB $target_disk $isb
|
||||
;;
|
||||
nvme*)
|
||||
[ "$isB" = "/dev/${target_disk}p1" -a "$target_function" = "/overlay" ] && fdiskB $target_disk p3 || fdiskB $target_disk p$isb
|
||||
;;
|
||||
mmc*)
|
||||
[ "$isB" = "/dev/${target_disk}p1" -a "$target_function" = "/overlay" ] && fdiskB $target_disk p3 || fdiskB $target_disk p$isb
|
||||
;;
|
||||
*)
|
||||
log "未能识别/dev/$target_disk目标硬盘!请联系作者sirpdboy!"
|
||||
expquit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
fi
|
||||
# rm -f $LOCK
|
||||
}
|
||||
|
||||
start() {
|
||||
init_env
|
||||
[ x$x = x1 ] && exit || autopart
|
||||
|
||||
}
|
||||
|
||||
boot() {
|
||||
x=1
|
||||
}
|
||||
|
||||
expquit() {
|
||||
rm -f $LOCK
|
||||
echo $1
|
||||
[ $1 == 2 ] &&reboot
|
||||
exit $1
|
||||
}
|
5
luci-app-partexp/root/etc/uci-defaults/40_luci-partexp
Normal file
5
luci-app-partexp/root/etc/uci-defaults/40_luci-partexp
Normal file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
chmod +x /etc/init.d/partexp >/dev/null 2>&1
|
||||
|
||||
rm -rf /tmp/luci-modulecache /tmp/luci-indexcache*
|
||||
exit 0
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-partexp": {
|
||||
"description": "Grant UCI access for luci-app-partexp",
|
||||
"read": {
|
||||
"uci": [ "partexp" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "partexp" ]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user