43 Star 33 Fork 172

openEuler/openeuler-jenkins
关闭

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
extract_file 1.91 KB
一键复制 编辑 原始数据 按行查看 历史
tracedeng 提交于 2020-09-08 17:33 +08:00 . initail
#!/bin/bash
# A simple script to checkout or update a svn or git repo as source service
# defaults
MYARCHIVE=""
MYFILES=""
OUTFILE="."
FILES=""
while test $# -gt 0; do
case $1 in
*-archive)
MYARCHIVE="${2##*/}"
shift
;;
*-file|*-files)
MYFILES="$MYFILES ${2}"
FILES=${2}
shift
;;
*-outfilename)
OUTFILE="${2}"
shift
;;
*-outdir)
MYOUTDIR="$2"
shift
;;
*)
echo Unknown parameter $1.
echo 'Usage: extract_file --archive $ARCHIVE --file $FILE --outdir $OUT'
exit 1
;;
esac
shift
done
if [ -z "$MYARCHIVE" ]; then
echo "ERROR: no archive specified!"
exit 1
fi
if [ -z "$MYFILES" ]; then
echo "ERROR: no checkout URL is given via --file parameter!"
exit 1
fi
if [ -z "$MYOUTDIR" ]; then
echo "ERROR: no output directory is given via --outdir parameter!"
exit 1
fi
set -x
if [ "${FILES}" == '*' ];then
MYFILES=" "
fi
existing_archive="$MYOUTDIR/$(echo $MYARCHIVE)"
cd "$MYOUTDIR"
existing_archive=`ls $existing_archive`
if [ -e "$existing_archive" ]; then
if [ "${existing_archive%.tar.gz}" != "$existing_archive" ]; then
tar xfz "$existing_archive" --wildcards $MYFILES || exit 1
elif [ "${existing_archive%.tar.bz2}" != "$existing_archive" ]; then
tar xfj "$existing_archive" --wildcards $MYFILES || exit 1
elif [ "${existing_archive%.tar.xz}" != "$existing_archive" ]; then
tar xfJ "$existing_archive" --wildcards $MYFILES || exit 1
elif [ "${existing_archive%.tar}" != "$existing_archive" ]; then
tar xf "$existing_archive" --wildcards $MYFILES || exit 1
elif [ "${existing_archive%.zip}" != "$existing_archive" ]; then
unzip "$existing_archive" $MYFILES || exit 1
else
echo "ERROR: unknown archive format $existing_archive"
exit 1
fi
for i in $MYFILES; do
mv "$i" "$OUTFILE"
done
else
echo "ERROR: archive not found: $existing_archive"
exit 1
fi
exit 0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openeuler/openeuler-jenkins.git
git@gitee.com:openeuler/openeuler-jenkins.git
openeuler
openeuler-jenkins
openeuler-jenkins
master

搜索帮助