-
Notifications
You must be signed in to change notification settings - Fork 482
/
kpr_tar_install.sh
executable file
·124 lines (117 loc) · 3.95 KB
/
kpr_tar_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/sh
# for lede x64 by fw867
export KSROOT=/koolshare
source $KSROOT/scripts/base.sh
alias echo_date='echo 【$(date +%Y年%m月%d日\ %X)】:'
eval `dbus export soft`
TARGET_DIR=/tmp/upload
clean(){
rm -rf /tmp/$name >/dev/null 2>&1
rm -rf /tmp/$MODULE_NAME >/dev/null 2>&1
rm -rf /tmp/$soft_name >/dev/null 2>&1
find /tmp -name "*.tar.gz"|xargs rm -rf >/dev/null 2>&1
}
install_tar(){
name=`echo "$soft_name"|sed 's/.tar.gz//g'|awk -F "_" '{print $1}'|awk -F "-" '{print $1}'`
INSTALL_SUFFIX=_install
VER_SUFFIX=_version
NAME_SUFFIX=_name
cd /tmp
echo_date ====================== step 1 ===========================
echo_date 即将开始在线更新!
sleep 1
if [ -f $TARGET_DIR/$soft_name ]; then
echo_date $TARGET_DIR目录下检测到在线更新包$soft_name
mv /tmp/upload/$soft_name /tmp
sleep 1
echo_date 尝试解压在线更新包
sleep 1
tar -zxvf $soft_name >/dev/null 2>&1
echo_date 解压完成!
sleep 1
cd /tmp
if [ -f /tmp/$name/install.sh ]; then
INSTALL_SCRIPT=/tmp/$name/install.sh
else
INSTALL_SCRIPT_NU=`find /tmp -name "install.sh"|wc -l` 2>/dev/null
[ "$INSTALL_SCRIPT_NU" == "1" ] && INSTALL_SCRIPT=`find /tmp -name "install.sh"` || INSTALL_SCRIPT=""
fi
if [ -n "$INSTALL_SCRIPT" -a -f "$INSTALL_SCRIPT" ]; then
SCRIPT_AB_DIR=`dirname $INSTALL_SCRIPT`
MODULE_NAME=${SCRIPT_AB_DIR##*/}
echo_date 准备安装$MODULE_NAME插件!
echo_date 找到安装脚本!
chmod +x $INSTALL_SCRIPT >/dev/null 2>&1
echo_date 运行安装脚本...
echo_date ====================== step 2 ===========================
sleep 1
start-stop-daemon -S -q -x $INSTALL_SCRIPT 2>&1
# sh /tmp/$name/install.sh 2>&1
if [[ "$?" != "0" ]]; then
echo_date 因为$MODULE_NAME安装失败!退出在线更新!
clean
dbus remove "softcenter_module_$MODULE_NAME$INSTALL_SUFFIX"
echo jobdown
exit
fi
echo_date ====================== step 3 ===========================
dbus set "softcenter_module_$MODULE_NAME$NAME_SUFFIX=$MODULE_NAME"
dbus set "softcenter_module_$MODULE_NAME$INSTALL_SUFFIX=1"
#dbus set "softcenter_module_$name$VER_SUFFIX=$soft_install_version"
if [ -n "$soft_install_version" ]; then
dbus set "softcenter_module_$MODULE_NAME$VER_SUFFIX=$soft_install_version"
echo_date "从插件文件名中获取到了版本号:$soft_install_version"
else
#已经在插件安装中设置了
if [ -z "`dbus get softcenter_module_$MODULE_NAME$VER_SUFFIX`" ]; then
dbus set "softcenter_module_$MODULE_NAME$VER_SUFFIX=0.1"
echo_date "插件安装脚本里没有找到版本号,设置默认版本号为0.1"
else
echo_date "插件安装脚本已经设置了插件版本号为:`dbus get softcenter_module_$MODULE_NAME$VER_SUFFIX`"
fi
fi
install_pid=`ps | grep -w install.sh | grep -v grep | awk '{print $1}'`
i=120
until [ -z "$install_pid" ]
do
install_pid=`ps | grep -w install.sh | grep -v grep | awk '{print $1}'`
i=$(($i-1))
if [[ "$i" -lt 1 ]]; then
echo_date "Could not load nat rules!"
echo_date 安装似乎出了点问题,请手动重启路由器后重新尝试...
echo_date 删除相关文件并退出...
sleep 1
clean
dbus remove "softcenter_module_$MODULE_NAME$INSTALL_SUFFIX"
echo jobdown
exit
fi
sleep 1
done
echo_date 离线包安装完成!
sleep 1
echo_date 一点点清理工作...
sleep 1
clean
echo_date 完成!在线更新插件成功,现在你可以退出本页面~
sleep 1
else
echo_date 没有找到安装脚本!
echo_date 删除相关文件并退出...
clean
fi
else
echo_date 没有找到在线更新包!
echo_date 删除相关文件并退出...
clean
fi
sleep 1
dbus remove soft_install_version
dbus remove soft_name
echo jobdown
clean
}
# 将 install_tar 的第一个参数 echo_date 传入log
install_tar "$1" > /tmp/upload/kpr_log.txt
# 顺带给 网页反馈下 第一个参数
http_response "$1"