Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
guo-yong-zhi committed May 4, 2022
1 parent b13a085 commit 159b2a0
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 146 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Kindle越狱插件FileBrowser使用说明:

=======================================================

开始以下步骤前需确保你的Kindle已经成功越狱,并安装了KUAL插件。

1. 下载插件压缩包,解压得到filebrowser文件夹,将其拷贝到Kindle根目录下的extensions目录中。
2. 插件安装完成后,进入Kindle界面,打开KUAL,可以在菜单中找到【FileBrowser】,可进行如下操作:
* 【Start】可开启免登录的WEB服务
* 【Start(Auth)】可开启带登录验证的WEB服务(默认用户名密码均为:admin)
* 【Kill】强行中止后台的WEB服务(用于debug),勿用于正常退出。
* 【Reset】删除包含配置信息的数据文件filebrowser.db。谨慎点击。

3. 如果服务开启时设备WiFi处于关闭状态,WiFi会被自动打开并在服务关闭后恢复原来状态。
4. 开启WEB服务后,可以在Kindle界面的顶部看到IP地址,在同一局域网下即可通过浏览器访问此地址。
5. 服务开启后Kindle会保持屏幕常亮且不会休眠,使用完成后请按电源键关闭本服务以恢复到正常状态,此时再按电源键即可正常锁屏休眠。
6. 如果有IP显示残留则意味着服务未正常退出,这提醒用户此时设备可能依然处在屏幕常亮状态。正常情况下按一次电源键后IP会消失,否则请尝试点击【Kill】或重启设备。相反,IP显示消失则意味着服务已经完全关闭,保证了不会有后台任务耗电。
7. 如果IP及其它提示的显示位置不居中,可以自行在电脑上修改文件`filebrowser_wrapper.sh``kill.sh``show_status.sh`开头的`col=30`。例如改为`col=20`可以使显示更靠左。

=======================================================
* 可前往 https://github.com/filebrowser/filebrowser 下载linux-armv7版本的release,用以更新插件的二进制文件`extensions/filebrowser/filebrowser`
* 详细说明及问题反馈:https://bookfere.com/post/823.html
2 changes: 1 addition & 1 deletion filebrowser/config.xml → config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<extension>
<information>
<name>File Browser</name>
<version>1.3</version>
<version>1.4</version>
<author>Sparkle</author>
<author>guoyongzhi</author>
<id>filebrowser</id>
Expand Down
File renamed without changes.
20 changes: 0 additions & 20 deletions filebrowser/README.md

This file was deleted.

50 changes: 0 additions & 50 deletions filebrowser/filebrowser_start.sh

This file was deleted.

48 changes: 0 additions & 48 deletions filebrowser/filebrowser_start_auth.sh

This file was deleted.

13 changes: 13 additions & 0 deletions filebrowser_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
workdir=$1
if [ "$workdir" == "" ]; then workdir="/mnt/us"; fi
if [ ! -f ./filebrowser.db ]
then
./filebrowser --noauth -a 0.0.0.0 -p 80 -r "$workdir" > /dev/null
else
METHOD=$(./filebrowser config cat | grep 'Auth method' | awk '{print $3}')
if [ 'noauth' != "$METHOD" ];
then
./filebrowser config set --auth.method=noauth > /dev/null
fi
./filebrowser -a 0.0.0.0 -p 80 -r "$workdir" > /dev/null
fi
11 changes: 11 additions & 0 deletions filebrowser_start_auth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
workdir=$1
if [ "$workdir" == "" ]; then workdir="/mnt/us"; fi
if [ -f ./filebrowser.db ]
then
METHOD=$(./filebrowser config cat | grep 'Auth method' | awk '{print $3}')
if [ 'json' != "$METHOD" ]
then
./filebrowser config set --auth.method=json > /dev/null
fi
fi
./filebrowser -a 0.0.0.0 -p 80 -r "$workdir" > /dev/null
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
#!/bin/sh
col=30
iptables -I INPUT -p tcp --dport 80 -j ACCEPT

# enable wireless if it is currently off
WIFI_IS_OFF=0
if [ 0 -eq `lipc-get-prop com.lab126.cmd wirelessEnable` ]; then
eips 30 3 "WiFi is off, turning it on now"
eips $col 3 "WiFi is off, turning it on now"
lipc-set-prop com.lab126.cmd wirelessEnable 1
WIFI_IS_OFF=1
fi

# start filebrowser in the background
if [ "$(ps aux | grep '[f]ilebrowser')" ];then killall filebrowser;fi

if [ -f ./filebrowser.db ]
then
METHOD=$(./filebrowser config cat | grep 'Auth method' | awk '{print $3}')
if [ 'json' != "$METHOD" ]
then
./filebrowser config set --auth.method=json > /dev/null
fi
fi
./filebrowser -a 0.0.0.0 -p 80 -r / > /dev/null &
"$@" &

# refresh IP display in the background
while :; do
eips 30 1 "== `ifconfig wlan0 | grep 'inet addr' | awk -F '[ :]' '{print $13}'` =="
eips $col 1 "== `ifconfig wlan0 | grep 'inet addr' | awk -F '[ :]' '{print $13}'` =="
sleep 5
done > /dev/null &

Expand All @@ -33,16 +24,16 @@ lipc-set-prop -i com.lab126.powerd preventScreenSaver 1
lipc-wait-event com.lab126.hal powerButtonPressed | read event #it's blocking
lipc-set-prop -i com.lab126.powerd preventScreenSaver 0
kill $(jobs -p)
eips 30 3 "File Browser is turned off. "
eips $col 3 "File Browser is turned off. "

# Restore WiFi status
if [ 1 -eq $WIFI_IS_OFF ]; then
lipc-set-prop com.lab126.cmd wirelessEnable 0
sleep 0.5
eips 30 3 "Turning off WiFi "
eips $col 3 "Turning off WiFi "
fi

# Clear screen
sleep 1
eips 30 1 " "
eips 30 3 " "
eips $col 1 " "
eips $col 3 " "
6 changes: 4 additions & 2 deletions filebrowser/filebrowser_kill.sh → kill.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
col=30
eips $col 3 "killing... "
lipc-send-event com.lab126.hal powerButtonPressed
sleep 5
ps aux | grep [f]ilebrowser | awk '{print $2}' | xargs -i kill {} > /dev/null
lipc-set-prop -i com.lab126.powerd preventScreenSaver 0
eips 30 1 " "
eips 30 3 " "
eips $col 1 " "
eips $col 3 " "
14 changes: 8 additions & 6 deletions filebrowser/menu.json → menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
{
"name": "Start",
"priority": 1,
"action": "./filebrowser_start.sh",
"action": "./filebrowser_wrapper.sh sh ./filebrowser_start.sh",
"param": ""
},
{
"name": "Start (Auth)",
"priority": 2,
"action": "./filebrowser_start_auth.sh",
"action": "./filebrowser_wrapper.sh sh ./filebrowser_start_auth.sh",
"param": ""
},
{
"name": "Start (root path)",
"priority": 3,
"action": "./filebrowser_start_auth_root.sh",
"action": "./filebrowser_wrapper.sh sh ./filebrowser_start_auth.sh /",
"param": ""
},
{
Expand All @@ -32,14 +32,16 @@
{
"name": "Kill",
"priority": 5,
"action": "./filebrowser_kill.sh",
"param": ""
"action": "./kill.sh",
"param": "",
"exitmenu": false
},
{
"name": "Reset",
"priority": 6,
"action": "rm ./filebrowser.db",
"param": ""
"param": "",
"exitmenu": false
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions filebrowser/show_status.sh → show_status.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh

col=30
test_process=$(ps aux | grep "[f]ilebrowser")
if [ -n "$test_process" ]
then
result="File Browser is Running..... "
else
result="File Browser is not running "
fi
eips 30 3 "$result"
eips $col 3 "$result"

0 comments on commit 159b2a0

Please sign in to comment.