small-package/luci-app-gpsysupgrade/root/etc/init.d/packages

102 lines
3.5 KiB
Plaintext
Raw Normal View History

2021-09-24 23:37:27 +08:00
#!/bin/sh
2021-10-16 09:07:40 +08:00
START=99
2021-09-24 23:37:27 +08:00
LOCK=/var/lock/opkgupgrade.lock
BKOPKG="/etc/backup"
# 防止重复启动
[ -f $LOCK ] && exit 1
touch $LOCK
2021-10-16 09:07:40 +08:00
if [ ! -f "$BKOPKG/user_installed.opkg" ]; then
touch /etc/inited
fi
function opkgupgrade() {
2021-09-24 23:37:27 +08:00
mkdir -p $BKOPKG
if [ ! -f /etc/inited ]; then
[ "$(uci -q get dhcp.@dnsmasq[0].noresolv)" ] && {
uci -q del dhcp.@dnsmasq[0].noresolv
uci commit dhcp
2021-10-12 19:29:23 +08:00
/etc/init.d/dnsmasq reload
2021-09-24 23:37:27 +08:00
}
# sh -c "cat '/usr/share/patch/adblock.patch' | patch -d '/' -p1 --forward" >/dev/null 2>&1
fi
c1=0
c2=0
c3=0
2021-11-16 09:36:38 +08:00
c4=0
2021-09-24 23:37:27 +08:00
while ! curl --retry 3 -m 5 https://op.supes.top >/dev/null 2>&1;do
echo "无法连接仓库服务器,请检查网络. $c1" | sed -e "s/^/$(date +%Y-%m-%d" "%H:%M:%S) /" >>/tmp/opkgupdate.log
2021-11-16 09:36:38 +08:00
[ $c1 eq 120 ] && return || let c1++
2021-09-24 23:37:27 +08:00
sleep 5
done
while :; do
opkg update | sed -e "s/^/$(date +%Y-%m-%d" "%H:%M:%S) /" >>/tmp/opkgupdate.log 2>&1
if [ "$?" == "0" ]; then
2021-10-31 09:03:02 +08:00
def="$(opkg list-upgradable | cut -f 1 -d ' ' | grep -vE 'opkg|luci-lib-fs|firewall|base-files|luci-base|busybox|^?nginx($|-)|dnsmasq-full|coremark|miniupnpd|luci-mod-network|luci-mod-status|luci-mod-system')"
2021-09-24 23:37:27 +08:00
if [ ! -f /etc/inited ]; then
insed="$(cat $BKOPKG/user_installed.opkg)"
fi
upopkg="$insed $def"
if [ "$upopkg" != " " ]; then
for ipk in $upopkg; do
2021-11-16 20:31:07 +08:00
while [ ! "$(opkg list-installed | cut -f 1 -d ' ' | grep -w $ipk)" ]; do
2021-10-31 09:03:02 +08:00
opkg install --force-overwrite --force-checksum --force-depends $ipk 2>&1 | sed -e "s/^/$(date +%Y-%m-%d" "%H:%M:%S) /" >>/tmp/opkgupdate.log 2>&1 || true
2021-11-16 09:36:38 +08:00
[ $c2 eq 3 ] && {
2021-09-24 23:37:27 +08:00
echo $ipk >> $BKOPKG/failed.txt
2021-11-16 20:31:07 +08:00
sed -i "/^$ipk$/d" $BKOPKG/user_installed.opkg
2021-09-24 23:37:27 +08:00
break
} || let c2++
sleep 1
rm -f /var/lock/opkg.lock
done
2021-11-16 20:31:07 +08:00
if [[ $ipk == luci-app-* ]]; then
opkg install --force-overwrite --force-checksum luci-i18n-"$(echo $ipk | cut -d - -f 3-4)"-zh-cn 2>&1 | sed -e "s/^/$(date +%Y-%m-%d" "%H:%M:%S) /" >>/tmp/opkgupdate.log 2>&1 || true
fi
2021-09-24 23:37:27 +08:00
done
rm -f /etc/config/*-opkg
fi
2021-11-16 09:36:38 +08:00
while [[ -f $BKOPKG/failed.txt && -f /etc/inited && $c4 -le 5 ]]; do
2021-09-24 23:37:27 +08:00
for ipk in $(cat $BKOPKG/failed.txt); do
2021-10-31 09:03:02 +08:00
opkg install --force-overwrite --force-checksum --force-depends $ipk 2>&1 | sed -e "s/^/$(date +%Y-%m-%d" "%H:%M:%S) /" >>/tmp/opkgupdate.log 2>&1 || true
2021-11-16 20:31:07 +08:00
[[ "$(opkg list-installed | cut -f 1 -d ' ' | grep -w $ipk)" ]] && {
sed -i "/^$ipk$/d" $BKOPKG/failed.txt
2021-11-16 09:36:38 +08:00
[ -n "$(cat $BKOPKG/failed.txt)" ] || rm -f $BKOPKG/failed.txt
2021-09-24 23:37:27 +08:00
}
done
2021-11-16 09:36:38 +08:00
let c4++
sleep 1
rm -f /var/lock/opkg.lock
done
2021-11-16 20:31:07 +08:00
if [[ $ipk == luci-app-* ]]; then
opkg install --force-overwrite --force-checksum luci-i18n-"$(echo $ipk | cut -d - -f 3-4)"-zh-cn 2>&1 | sed -e "s/^/$(date +%Y-%m-%d" "%H:%M:%S) /" >>/tmp/opkgupdate.log 2>&1 || true
fi
2021-11-16 09:36:38 +08:00
mv $BKOPKG/failed.txt $BKOPKG/failed_.txt >/dev/null 2>&1
2021-09-24 23:37:27 +08:00
touch /etc/inited
rm -f /var/lock/opkg.lock
break
fi
2021-11-16 09:36:38 +08:00
[ $c3 eq 10 ] && break || let c3++
2021-09-24 23:37:27 +08:00
done
rm -f /var/lock/opkg.lock
}
(
if [[ ! -f /etc/inited || -f $BKOPKG/failed.txt ]]; then
opkgupgrade || true
elif [[ -f /etc/inited && `uci -q get system.@system[0].autoupgrade_pkg || echo "1"` != '0' ]]; then
opkgupgrade || true
fi
rm -f /var/lock/opkg.lock
[[ -f "/bin/coremark" && ! -f "/etc/bench.log" ]] && {
sleep 5
/bin/coremark >/tmp/coremark.log
cat /tmp/coremark.log | grep "CoreMark 1.0" | cut -d "/" -f 1 >/etc/bench.log
sed -i 's/CoreMark 1.0/(CpuMark/g' /etc/bench.log
echo " Scores)" >>/etc/bench.log
}
rm -f $LOCK
) &