提交 7ab12ae2 编写于 作者: S songchenwen

add luci-app-r2sflasher

上级 9b5cf067
......@@ -181,6 +181,7 @@ jobs:
mv friendlywrt-rk3328/out/*img* ./artifact/
cp friendlywrt-rk3328/friendlywrt/.config ./artifact/full.config
cp friendlywrt-rk3328/friendlywrt/bin/packages/*/scw/luci-app-passwall*.ipk ./artifact/
cp friendlywrt-rk3328/friendlywrt/bin/packages/*/*/luci-app-r2sflasher*.ipk ./artifact/
zip -r artifact.zip -j artifact artifact/*
release_tag=${{ steps.changelog.outputs.buildtag }}
echo "##[set-output name=release_tag;]$release_tag"
......
......@@ -187,6 +187,7 @@ jobs:
mv friendlywrt-rk3328/out/*img* ./artifact/
cp friendlywrt-rk3328/friendlywrt/.config ./artifact/full.config
cp friendlywrt-rk3328/friendlywrt/bin/packages/*/scw/luci-app-passwall*.ipk ./artifact/
cp friendlywrt-rk3328/friendlywrt/bin/packages/*/*/luci-app-r2sflasher*.ipk ./artifact/
zip -r artifact.zip -j artifact artifact/*
release_tag=${{ steps.changelog.outputs.buildtag }}
echo "##[set-output name=release_tag;]$release_tag"
......
......@@ -132,6 +132,7 @@ jobs:
mv friendlywrt-rk3328/out/*img* ./artifact/
cp friendlywrt-rk3328/friendlywrt/.config ./artifact/full.config
cp friendlywrt-rk3328/friendlywrt/bin/packages/*/scw/luci-app-passwall*.ipk ./artifact/
cp friendlywrt-rk3328/friendlywrt/bin/packages/*/*/luci-app-r2sflasher*.ipk ./artifact/
zip -r artifact.zip -j artifact artifact/*
release_tag=${{ steps.changelog.outputs.buildtag }}
echo "##[set-output name=release_tag;]$release_tag"
......
......@@ -134,6 +134,7 @@ jobs:
mv friendlywrt-rk3328/out/*img* ./artifact/
cp friendlywrt-rk3328/friendlywrt/.config ./artifact/full.config
cp friendlywrt-rk3328/friendlywrt/bin/packages/*/scw/luci-app-passwall*.ipk ./artifact/
cp friendlywrt-rk3328/friendlywrt/bin/packages/*/*/luci-app-r2sflasher*.ipk ./artifact/
zip -r artifact.zip -j artifact artifact/*
release_tag=${{ steps.changelog.outputs.buildtag }}
echo "##[set-output name=release_tag;]$release_tag"
......
......@@ -11,7 +11,7 @@
默认 LAN 口 IP `192.168.2.1` 默认密码 `password`
无需拔 SD 卡的升级方法, 4月11日以后的固件,ssh 进路由器, 并执行 `fw_update` 后面跟上新 ROM 的 zip 文件下载 URL, 比如 `fw_update "https://github.com/songchenwen/nanopi-r2s/releases/download/FriendlyWRT-2020-04-11-bf4fc77/FriendlyWRT-2020-04-11-bf4fc77-ROM.zip"`。这种刷机方式会保留配置文件, 如果新旧 ROM 的配置文件不兼容会引发各种问题,请自行判断配置文件的兼容性
4月14日之后的版本加入了 luci-app-r2sflasher, 可以图形化刷机了
Fork 自 [klever1988](https://github.com/klever1988/nanopi-openwrt)[soffchen](https://github.com/soffchen/NanoPi-R2S)
......
......@@ -26,3 +26,5 @@ echo "src-git scw https://github.com/songchenwen/openwrt-package" >> feeds.conf.
echo ""
echo "feeds.conf.default"
cat feeds.conf.default
cp -r ../../luci-app-r2sflasher package/
......@@ -116,6 +116,7 @@ CONFIG_PACKAGE_luci-app-wol=y
CONFIG_PACKAGE_luci-app-wrtbwmon=y
CONFIG_PACKAGE_luci-app-serverchan=y
CONFIG_PACKAGE_luci-app-filebrowser=y
CONFIG_PACKAGE_luci-app-r2sflasher=y
CONFIG_PACKAGE_luci-app-passwall=y
CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Brook=y
CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Shadowsocks=y
......
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-r2sflasher
PKG_VERSION:=1
PKG_RELEASE:=1
PKG_DATE:=20200413
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
CATEGORY:=LuCI
SUBMENU:=3. Applications
TITLE:=LuCI Application to Flash NanoPi R2S ROM
PKGARCH:=all
DEPENDS:=+bash +unzip +gzip +pv +losetup +tar +zstd
endef
define Build/Prepare
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/bin
cp ./root/usr/bin/rom_flash $(1)/usr/bin/rom_flash
$(INSTALL_DIR) $(1)/usr/lib/lua/luci
cp -pR ./luasrc/* $(1)/usr/lib/lua/luci/
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n
po2lmo ./po/zh-cn/r2sflasher.po $(1)/usr/lib/lua/luci/i18n/r2sflasher.zh-cn.lmo
endef
define Package/$(PKG_NAME)/postinst
#!/bin/sh
chmod a+x $${IPKG_INSTROOT}/usr/bin/rom_flash >/dev/null 2>&1
exit 0
endef
$(eval $(call BuildPackage,$(PKG_NAME)))
\ No newline at end of file
-- Copyright 2020 scw <me@songchenwen.com>
module("luci.controller.r2sflasher", package.seeall)
function index()
entry({"admin", "system", "r2sflasher"}, form("r2sflasher/flash"), _("R2S Flasher"), 79)
entry({"admin", "system", "r2sflasher", "log"}, form("r2sflasher/log"))
entry({"admin", "system", "r2sflasher", "get_log"}, call("get_log")).leaf = true
end
function get_log()
luci.http.write(luci.sys.exec(
"[ -f '/tmp/r2sflasher.log' ] && cat /tmp/r2sflasher.log"))
end
local fs = require "luci.fs"
local http = luci.http
local dsp = require 'luci.dispatcher'
romform = SimpleForm("romflash", translate("Flash ROM"), nil)
romform.reset = false
romform.submit = false
section = romform:section(SimpleSection, "", translate("Choose Your NanoPi R2S ROM zip File to Flash"))
fu = section:option(FileUpload, "")
fu.template = "r2sflasher/rom"
um = section:option(DummyValue, "", nil)
local dir, fd
dir = "/tmp/r2sflasher/"
nixio.fs.mkdir(dir)
http.setfilehandler(
function(meta, chunk, eof)
if not fd then
if not meta then return end
if meta and chunk then fd = nixio.open(dir .. meta.file, "w") end
if not fd then
um.value = translate("Create upload file error.")
return
end
end
if chunk and fd then
fd:write(chunk)
end
if eof and fd then
fd:close()
fd = nil
local keep_config = luci.http.formvalue("keep_config")
cmd = "/usr/bin/rom_flash " .. dir .. meta.file
if keep_config == nil then
cmd = cmd .. " nobackup"
end
luci.sys.call(cmd .. " &> /tmp/r2sflasher.log &")
http.redirect(dsp.build_url("/admin/system/r2sflasher/log"))
end
end
)
if luci.http.formvalue("flash") then
local f = luci.http.formvalue("romfile")
if #f <= 0 then
um.value = translate("No Specify ROM File.")
end
end
if luci.sys.call("pidof rom_flash > /dev/null") == 0 then
http.redirect(dsp.build_url("/admin/system/r2sflasher/log"))
return
else
return romform
end
log = SimpleForm("log")
log.reset = false
log.submit = false
log:append(Template("r2sflasher/log"))
return log
\ No newline at end of file
<%
local dsp = require "luci.dispatcher"
-%>
<script type="text/javascript">
//<![CDATA[
XHR.poll(1, '<%=dsp.build_url("admin/system/r2sflasher/get_log")%>', null,
function(x, data) {
if(x && x.status == 200) {
var log_textarea = document.getElementById('log_textarea');
log_textarea.innerHTML = x.responseText;
log_textarea.scrollTop = log_textarea.scrollHeight;
}
}
);
//]]>
</script>
<fieldset class="cbi-section" id="_log_fieldset">
<textarea id="log_textarea" class="cbi-input-textarea" style="width: 100%;margin-top: 10px;" data-update="change" rows="30" wrap="off" readonly="readonly"></textarea>
</fieldset>
<%+cbi/valueheader%>
<label class="cbi-value" style="display:inline-block; width: 130px" for="keep_config"><%:Keep Configs%></label>
<input class="cbi-input-file" style="width: 40px" type="checkbox" id="keep_config" name="keep_config" checked />
<div class="cbi-value-description"><span class="cbi-value-helpicon"><img src="/luci-static/resources/cbi/help.gif"/></span> <%:compatibility needs to be checked%></div>
<%+cbi/valuefooter%>
<%+cbi/valueheader%>
<label class="cbi-value" style="display:inline-block; width: 130px" for="romfile"><%:Choose File%></label>
<input class="cbi-input-file" style="width: 400px" type="file" id="romfile" name="romfile" />
<input type="submit" class="cbi-button cbi-input-apply" name="flash" value="<%:Flash%>" />
<%+cbi/valuefooter%>
<%+cbi/valueheader%>
<div class="cbi-value-description" style="margin-left:20px"><span class="cbi-value-helpicon"><img src="/luci-static/resources/cbi/help.gif"/></span> by <a href="https://songchenwen.com" target="_blank">scw</a> <a href="https://songchenwen.com/nanopi-r2s-roms-redir" target="_blank">roms</a></div>
<%+cbi/valuefooter%>
\ No newline at end of file
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8"
msgid "R2S Flasher"
msgstr "R2S 刷机"
msgid "Flash ROM"
msgstr "刷写 ROM"
msgid "Choose Your NanoPi R2S ROM zip File to Flash"
msgstr "选择 NanoPi R2S ROM zip 压缩文件"
msgid "No Specify ROM File."
msgstr "找不到 ROM 文件"
msgid "Keep Configs"
msgstr "保留设置"
msgid "compatibility needs to be checked"
msgstr "需自行确认配置文件兼容性"
msgid "Choose File"
msgstr "选择 ROM 文件"
msgid "Flash"
msgstr "刷写"
#!/bin/bash
sScriptName="$(basename $0)"
if [ $(pidof ${sScriptName}| wc -w) -gt 2 ]; then
pids=$(pidof ${sScriptName})
echo "其他任务正在执行刷机 ${pids}"
exit 1
fi
needed_binaries=(unzip gunzip pv losetup tar zstdmt zstdcat)
need_warn=""
for i in "${needed_binaries[@]}"; do
w_b=$(which $i)
if [ "$w_b" == "" ]; then
need_warn="${need_warn} $i"
fi
done
if ! [ "$need_warn" == "" ]; then
echo "无法刷机, 需要这些可执行文件 $need_warn"
exit 1
fi
workingdir=/root/r2sflasher/
rm -rf $workingdir
mkdir -p $workingdir
cd $workingdir
inputfile=$1
nobackup=$2
imgfile=rom.img
lomntpoint=/mnt/img
backupfile=/tmp/backup.tar.gz
if [ "$inputfile" == "" ];then
echo "需要传入 ROM zip 文件"
exit 1
fi
if [ -f "$inputfile" ]; then
echo "固件上传成功"
else
echo "固件上传失败"
cd /root
rm -rf $workingdir
exit 1
fi
inputfileext=${inputfile##*.}
gzfile=""
if [ "$inputfileext" == "gz" ]; then
gzfile="$inputfile"
fi
if [ "$inputfileext" == "zip" ]; then
gzfile=$(unzip -Z -1 "$inputfile" | grep "sd.img.gz$")
if [ "$gzfile" == "" ]; then
echo "没发现 sd.img.gz 结尾的固件包"
cd /root
rm -rf $workingdir
exit 1
fi
unzip "$inputfile" "$gzfile"
rm $inputfile
if [ -f "$gzfile" ]; then
echo "zip 固件已解压至 $gzfile"
else
echo "zip 固件解压失败"
cd /root
rm -rf $workingdir
exit 1
fi
fi
if [ "$gzfile" == "" ]; then
echo "不是有效的 ROM 文件"
cd /root
rm $inputfile
rm -rf $workingdir
exit 1
fi
echo "开始解压 gz 文件......"
pv "$gzfile" | gunzip -dc > "$imgfile"
if [ -f "$imgfile" ]; then
echo "gz 固件已解压至 $imgfile"
rm $gzfile
else
echo "gz 固件解压失败"
rm $gzfile
cd /root
rm -rf $workingdir
exit 1
fi
lodev=$(losetup -f)
echo "使用设备 $lodev 测试 ROM 文件"
mkdir -p "$lomntpoint"
losetup -o 100663296 $lodev "$imgfile"
mount $lodev "$lomntpoint"
if [ $? -ne 0 ]; then
echo "img 文件挂载失败"
losetup -d $lodev
cd /root
rm -rf $workingdir
exit 1
fi
cd "$lomntpoint"
imgbindir=$(ls | grep "bin")
if [ imgbindir == "" ]; then
echo "img 文件错误"
cd /root
umount "$lomntpoint"
losetup -d $lodev
rm -rf $workingdir
exit 1
fi
if [ "$2" == "nobackup" ]; then
echo "不备份设置"
else
echo "开始备份设置"
rm -f "$backupfile"
sysupgrade -b "$backupfile"
if ! [ -f "$backupfile" ]; then
echo "生成备份文件失败"
cd /root
umount "$lomntpoint"
losetup -d $lodev
rm -rf $workingdir
exit 1
fi
echo "开始写入备份到镜像文件"
tar zxf "$backupfile"
echo "备份文件已写入, 移除挂载"
rm "$backupfile"
fi
cd /tmp
umount "$lomntpoint"
losetup -d $lodev
zstfile="/tmp/$imgfile.zst"
echo "开始压缩镜像至 $zstfile"
rm -f $zstfile
zstdmt "${workingdir}${imgfile}" -o "$zstfile"
rm -rf $workingdir
if [ -f "$zstfile" ]; then
echo 1 > /proc/sys/kernel/sysrq
echo "卸载 SD 卡"
echo u > /proc/sysrq-trigger || umount /
rotestfile="/rotest.txt"
touch "$rotestfile"
if [ $? -eq 0 ]; then
rm "$rotestfile"
echo "卸载 SD 卡失败, 请重启后再继续使用"
exit 1
fi
echo "开始刷机, 请不要断电或关机, 如果刷机失败请取出 SD 卡用电脑重新写入 ROM"
pv "$zstfile" | zstdcat | dd of=/dev/mmcblk0 conv=fsync
echo "刷机完毕, 正在重启..."
echo o > /proc/sysrq-trigger
else
echo "压缩出错"
exit 1
fi
......@@ -116,6 +116,7 @@ CONFIG_PACKAGE_luci-app-wol=y
CONFIG_PACKAGE_luci-app-wrtbwmon=y
CONFIG_PACKAGE_luci-app-serverchan=y
CONFIG_PACKAGE_luci-app-filebrowser=y
CONFIG_PACKAGE_luci-app-r2sflasher=y
CONFIG_PACKAGE_luci-app-passwall=y
CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Brook=y
CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Shadowsocks=y
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册