Files
MIXBOX-ARCHIVE/apps/mixbox/bin/applist
2020-04-26 09:44:29 +08:00

100 lines
2.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
#copyright by monlor
# source /etc/mixbox/bin/base
export PATH=$PATH:/etc/mixbox/bin
mbroot="/etc/mixbox"
mbtmp="/tmp/mbtmp"
mburl=$(mbdb get mixbox.main.url)
model=$(mbdb get mixbox.main.model)
source ${mbroot}/scripts/helper.sh
fix_local_applist() {
rm -rf ${mbroot}/config/applist.txt
if [ ! -f ${mbtmp}/applist.txt ]; then
echo "未找到在线插件列表,无法修复!"
return 1
else
get_applist all -a | while read line
do
name="$(get_applist ${line} -n)"
checkuci $name && echo ${line} >> ${mbroot}/config/applist.txt
done
fi
if [ ! -f ${mbroot}/config/applist.txt ]; then
echo "修复失败!"
return 1
else
return 0
fi
}
get_applist() {
if [ "$1" = "installed" ]; then
[ ! -f ${mbroot}/config/applist.txt ] && fix_local_applist
applist_txt="${mbroot}/config/applist.txt"
else
applist_txt="${mbtmp}/applist.txt"
fi
appname="$1" # all: all app, installed, installed app
arg="$2" # -n:appname, -i:appinfo, -e:newinfo, -v:version, -s:service
[ "$appname" = "all" -o "$appname" = "installed" ] && appname=".*"
case "$arg" in
"-n")
cat $applist_txt 2> /dev/null | grep -v mixbox | grep "^${appname}|" | cut -d'|' -f1 | sort -u
;;
"-i")
cat $applist_txt 2> /dev/null | grep "^${appname}|" | cut -d'|' -f2
;;
"-e")
cat $applist_txt 2> /dev/null | grep "^${appname}|" | cut -d'|' -f3
;;
"-v")
cat $applist_txt 2> /dev/null | grep "^${appname}|" | cut -d'|' -f4
;;
"-s")
cat $applist_txt 2> /dev/null | grep "^${appname}|" | cut -d'|' -f5
;;
"-a")
cat $applist_txt 2> /dev/null | grep -v mixbox | grep "^${appname}|"
;;
*)
cat $applist_txt 2> /dev/null | sort -u
;;
esac
}
update_applist() {
wgetsh ${mbtmp}/applist_tmp.txt $mburl/applist.txt
# 判断applist的内容防止软件源异常
if [ $? -eq 0 ] && [ -n `cat ${mbtmp}/applist_tmp.txt | grep -E "^mixbox"` ]; then
rm -rf ${mbtmp}/applist.txt
cat ${mbtmp}/applist_tmp.txt | grep "${model}" | sort -u | while read line; do
local install_text=""
local update_text=""
local appname=""
local version=""
appname="$(echo -n "$line" | cut -d'|' -f1)"
version="$(echo -n "$line" | cut -d '|' -f4)"
if ls ${mbroot}/apps/${appname} &> /dev/null; then
[ "$(mbdb get ${appname}.main.version)" != "${version}" ] && update_text="有更新"
else
install_text="未安装"
fi
echo "${line}|${install_text}|${update_text}" >> ${mbtmp}/applist.txt
done
fi
rm -rf ${mbtmp}/applist_tmp.txt
}
# force udpate
[ "$1" = "update" ] && update_applist && exit
[ ! -f ${mbtmp}/applist.txt ] && update_applist
get_applist $@
exit 0