1 Star 0 Fork 0

BulletYuan / shell-downloadTool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
shell.sh 3.08 KB
一键复制 编辑 原始数据 按行查看 历史
BulletYuan 提交于 2017-06-23 11:17 . commit downloadTool
#!/usr/bash
# BulletYuan****author****1.0****version
echo -e "\n...BulletYuan...\n...version 1.0 ...\n\n"
argnum="$#"
echo -e "args number is : $argnum\n"
# output help info
_HELP_Info(){
echo -e "looks like you need help:\n"
echo -e "-d src savepath: the mode is that just download.just two args"
echo -e "-dtar src savepath/tarpath: the mode is that download and zip the file.just two args; unzip file type just .tar/.tar.gz/.tar.bz2/.tar.Z/.zip"
}
# output wroung info,programmer defined wroung info text
_WROUNG_Info(){
echo -e "something is wroung!:\n"
echo -e "$1"
}
# output error info,programmer defined error info text
_ERROR_Info(){
echo -e "something is error!:\n"
echo -e "$1"
}
# download function
_DOWNLOAD_(){
wget --user-agent="Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16" -v -c --tries=5 --timeout=30 --no-cache --output-document="$2" "$1"
sleep 1s
}
# unzip function
_UNZIP_(){
file="$1"
read "the zipfile is in path:$file\nand if you wanna unzip to another directory,please keypress the abs-path\nand if you wanna unzip to this directory,just keypress ENTER skip:" unzippath
if [ -n $unzippath ]; then
if [ "${file##*.}"x = "gz"x ]||[ "${file##*.}"x = "bz2"x ]||[ "${file##*.}"x = "Z"x ]; then
read "is that show the zipfile's list? [y/n]" res
if [ -n $res]; then
$res="$res | tr '[:upper:]' '[:lower:]'"
else
$res="y"
fi
if [ $res -q "y"]; then
tar -tf "$file"
fi
echo -e "start unzip\n"
tar -xf --checkpoint=2 "$file" -C "$unzippath"
elif [ "${file##*.}"x = "zip"x ]; then
read "is that show the zipfile's list? [y/n]" res
if [ -n $res]; then
$res="$res | tr '[:upper:]' '[:lower:]'"
else
$res="y"
fi
if [ $res -q "y"]; then
unzip -l "$file"
fi
echo -e "start unzip\n"
tar -n "$file" -d "$unzippath"
fi
else
echo -e "the unzip path had wroung input!please retry!\n"
_UNZIP_ "$file"
fi
}
# download&unzip function
_DOWNLOAD_UNZIP_(){
wget --user-agent="Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16" -v -c --tries=5 --timeout=30 --no-cache --output-document="$2" "$1"
sleep 1s
_UNZIP_ "$2"
}
# main program enter
if [ "$argnum" -eq "0" ]; then
_HELP_Info
else
arg1="$1"
case $arg1 in
-d)
if [ -n "$2" ]; then
if [ -n "$3" ]; then
echo -e "just download;\nsrc: $2\ntarget: $3\n"
_DOWNLOAD_ "$2" "$3"
else
wtxt="arg:target can not be noneType or empty!"
_ERROR_Info "$wtxt"
fi
else
wtxt="arg:src can not be noneType or empty!"
_ERROR_Info "$wtxt"
fi
;;
-dtar)
if [ -n "$2" ]; then
if [ -n "$3" ]; then
echo -e "download and unzip;\nsrc $2\ntarget: $3\n"
_DOWNLOAD_UNZIP_ "$2" "$3"
else
wtxt="arg:target can not be noneType or empty!"
_ERROR_Info "$wtxt"
fi
else
wtxt="arg:src can not be noneType or empty!"
_ERROR_Info "$wtxt"
fi
;;
-h)
_HELP_Info
;;
-help)
_HELP_Info
;;
*)
_HELP_Info
;;
esac
fi
Shell
1
https://gitee.com/bulletyuan/shell-downloadTool.git
git@gitee.com:bulletyuan/shell-downloadTool.git
bulletyuan
shell-downloadTool
shell-downloadTool
master

搜索帮助