1 Star 0 Fork 1

DabinLiu/Shell Utility

forked from MJ PC Lab/Shell Utility 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
rsynciso 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
小小猫猫 提交于 2015-07-19 21:23 +08:00 . always delete non used files when using rsync
#!/bin/bash
#rsync files from ISO image into directory
#examples
#
#rsync all files/sub directories from iso into a directory
#cpiso dvd.iso /tmp/dvd/
#
#rsync all files/sub directories under a specified directory from iso into a directory
#cpiso dvd.iso:pareht/directory/ /tmp/dvd/
#
#rsync a single file from iso into a directory
#cpiso dvd.iso:path/to/file /tmp/dvd/
if [ $# -lt 2 ]; then
echo "Usage: $(basename $0) <ISO File>[:parent/directory] <Target Directory>" >&2;
exit 1;
fi
colonPos=$(expr index "$1" ':');
if [ $colonPos -eq 0 ]; then
colonPos=$(expr length "$1");
colonPos=$[colonPos+1];
fi;
isoPathLength=$[colonPos-1];
image=${1:0:isoPathLength};
if [ ! -f "$image" ]; then
echo "\"$image\" is no a file." >&2;
hasError=1;
fi;
rawSource=${1:colonPos}
if [ "${rawSource:0:1}" == '/' ]; then
rawSource=${rawSource##/};
fi;
if [ -z "$rawSource" ]; then
rawSource='.';
fi;
rawTarget="$2";
if [ ${rawTarget:0:1} != "/" ]; then
pwd=$(pwd);
if [ "$pwd" == "/" ]; then
target="$pwd""$rawTarget";
else
target="$pwd"/"$rawTarget";
fi;
else
target="$rawTarget";
fi;
if [ ! -d "$target" ]; then
echo "\"$rawTarget\" is no a directory." >&2;
hasError=1;
fi;
if [ $hasError ]; then
exit 2;
fi;
tempdir=$(mktemp -d);
mount -o loop,ro "$image" "$tempdir";
if [ $? -ne 0 ]; then
rmdir "$tempdir";
echo 'Mount image failed.' >&2;
exit 3;
fi;
pushd "$tempdir" &> /dev/null;
if [ ! -e "$rawSource" ]; then
popd &> /dev/null;
umount "$tempdir";
rmdir "$tempdir";
echo 'Source directory not exists.' >&2;
exit 4;
elif [ -d "$rawSource" ]; then
pushd "$rawSource" &> /dev/null;
rsync -a --delete ./ "$target";
popd &> /dev/null;
elif [ -f "$rawSource" ]; then
cp "$rawSource" "$target";
fi;
popd &> /dev/null;
umount "$tempdir";
rmdir "$tempdir";
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dabinvip/Shell-Utility.git
git@gitee.com:dabinvip/Shell-Utility.git
dabinvip
Shell-Utility
Shell Utility
master

搜索帮助