From 94df55ddaccab80c5fdb75f8ba6a8775be8b0a68 Mon Sep 17 00:00:00 2001 From: wanghanwen <1564586847@qq.com> Date: Fri, 22 Apr 2022 18:36:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=8B=E8=BD=BD=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/common/download.sh | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 package/common/download.sh diff --git a/package/common/download.sh b/package/common/download.sh new file mode 100644 index 0000000..947b2ce --- /dev/null +++ b/package/common/download.sh @@ -0,0 +1,57 @@ +#!/bin/bash +download_path=$JARVIS_DOWNLOAD +type_=wget + +OPTIND=1 + +while getopts ":u:f:t:" opt; +do + case $opt in + #下载的链接 + u) url=$OPTARG;; + #使用的下载类型,默认wget + t) type_=$OPTARG;; + #下载后重命名,可不添加 + f) filename=$OPTARG;; + ?) echo -e "\033[0;31m[Error]\033[0m:Unknown parameter:"$opt + exit 0;; + esac + +done + +if [ ! "$url" ];then + echo "Error: No available download link found" + exit 0 +fi +#如果需要重命名,则修改exist +if [ "$filename" ];then + exist_path=$download_path/$filename +else + if [ "$type_" == "git" ];then + url=$(echo $url|sed 's/\.[^./]*$//') + fi + exist_path=$download_path/${url##*/} +fi + +#判断文件是否存在 +if [ ! -e $exist_path ];then + if [ "$type_" == "wget" ];then + echo -e "\033[0;32m[Info]\033[0m:Using commands: wget $url -O $exist_path --no-check-certificate" + wget $url -O $exist_path --no-check-certificate + elif [ "$type_" == "git" ];then + echo -e "\033[0;32m[Info]\033[0m:Using commands: git clone $url $exist_path" + git clone $url $exist_path + else + echo -e "\033[0;31m[Error]\033[0m:Unsupported download mode:"$type_ + exit 0 + fi + + #下载失败 + if [ $? != 0 ];then + rm -rf $exist_path + echo -e "\033[0;31m[Error]\033[0m:Download failed:"$url + exit 0 + fi +else + echo -e "\033[0;32m[Info]\033[0m:"$exist_path" already exist" +fi -- Gitee