0.前言
本文基于本人之前写的文章:
Pavadan固件在不外挂硬盘的情况下使用opkg“曲线”安装插件,并在断电重启后恢复
本文内容较为简单,仅做记录备日后之用。
1.问题
之前为能够从Gitee上下载自己之前经upx压缩处理后小体积的VirtualHere以方便自己使用,本人在padavan上采用挖内存空间以创造opkg环境,后利用opkg环境安装git的方式成功实现了从Gitee git clone自己仓库的文件。但在使用过程中发现,可能由于路由器的性能问题,在安装git-http环境时速度很慢,这导致应用程序的整体启动时间变得很长。
2.改进
基于上述问题,联想到自己目前在使用的Zotero+坚果云方式同步外文文献,本人想到可以利用坚果云作为文件存储位置,使用cURL命令来下载文件,这样就省掉了安装git环境的步骤,能够大大提升程序的启动效率。
2.1 脚本内容
废话少说,直接放上脚本:
# 定义重试函数:捕获命令输出,并在失败时打印出具体命令及输出
retry() {
n=0
max_retries=5
delay=10
command="$1"
output=""
while [ $n -lt $max_retries ]; do
echo "正在执行命令: $command"
output=$(eval "$command" 2>&1)
status=$?
if [ $status -eq 0 ]; then
return 0
fi
n=$((n+1))
logger -t "【VH脚本】" "命令 \"$command\" 执行失败,正在第 $n 次尝试..."
echo "失败命令的输出:"
echo "$output"
sleep $delay
done
logger -t "【VH脚本】" "命令 \"$command\" 执行失败,已尝试 $max_retries 次,退出"
echo "最后失败命令的输出:"
echo "$output"
return 1
}
# 开始执行脚本
# 扩充 /opt 为 tmpfs,大小为 50M
retry "mount -t tmpfs -o size=50M tmpfs /opt/"
# 创建所需目录
retry "mkdir -p /opt/bin/"
retry "mkdir -p /opt/bin/VH/"
retry "mkdir -p /opt/etc/"
retry "mkdir -p /opt/var/lock/"
retry "mkdir -p /opt/tmp/"
logger -t "【VH脚本】" "创建 opt 目录完成"
logger -t "【VH脚本】" "从坚果云下载virtualhere..."
retry "curl -k -u 'username:passward' 'https://dav.jianguoyun.com/dav/virtualhere' -o '/opt/bin/VH/virtualhere'"
retry "chmod 755 /opt/bin/VH/virtualhere"
logger -t "【VH脚本】" "virtualhere 下载完成"
logger -t "【VH脚本】" "从坚果云下载replace.sh..."
retry "curl -k -u 'username:passward' 'https://dav.jianguoyun.com/dav/replace.sh' -o '/opt/bin/VH/replace.sh'"
retry "chmod 755 /opt/bin/VH/replace.sh"
logger -t "【VH脚本】" "下载replace.sh完成"
logger -t "【VH脚本】" "从坚果云下载config.ini..."
retry "curl -k -u 'username:passward' 'https://dav.jianguoyun.com/dav/config.ini' -o '/opt/bin/VH/config.ini'"
retry "chmod 755 /opt/bin/VH/config.ini"
logger -t "【VH脚本】" "下载config.ini完成"
# 修改 replace.sh 权限并执行
chmod 777 /opt/bin/VH/replace.sh
logger -t "【VH脚本】" "开始运行 VH"
retry "/opt/bin/VH/replace.sh"
retry "virtualhere start"
6459

被折叠的 条评论
为什么被折叠?



