Shell 脚本小试牛刀(2) -- git仓库的选取以及迁移

前文我展示了一个关于Debian系统配置的脚本,而新装电脑除了配置之外还有一个问题就是……资源的迁移!(对于一般的资源可以使用scp拷贝,当然在局域网内scp的速度相当可观,但是对于git仓库这样的特殊资源,直接使用scp可能会影响git仓库的使用哦!)

我个人的习惯时将所有的git仓库都放在一个叫做repository的目录下。如果通过一个个检查该目录下dirs/.git/config下的地址,然后一条条git clone 来在另一台机器上重建仓库目录显得有点太不专业了,所以我写了个非常简单的脚本(my_repository.sh)读取仓库中的地址,并把所有地址都追加到一个文件中,然后使用另外一个脚本(clone.sh)对这个文件中所有的地址进行git clone ,很简单。

首先,看一下搜集git仓库地址的shell脚本:

#!/bin/bash
# (C) 2014 Yunlong Zhou <reaper888@yeah.net>
# Under licence  GPL
# File :   my_repository.sh 
# Introduction:
#       This script is using for collect all the git address to a file -- repository_file
# Useage :
#		1. cd repository	-- cd to the dir that you store all the git repository
#		2. chmox +x my_repository.sh	-- give the script a execute permission
#		3. ./my_repository.sh


# for delete old temp file ,if there is !
if [ -f all_dir -a -f repository_file ]; then
	echo "Now delete old temp file"	
	rm all_dir repository_file 2> /dev/null
fi

# read all the items under this dir to the file all_dir
ls -l | awk '{print $9}' > all_dir
# deal with every git repository dir and collect the url then store to file repository_file
while read FILE_NAME
do
	if [ $FILE_NAME != " " -a -d $FILE_NAME -a -s $FILE_NAME ];then
		echo "Now dealing the "$FILE_NAME 
		if [ -d $FILE_NAME/.git ]; then
			grep -e "url"	$FILE_NAME/.git/config | cut -d "=" -f2 | cut -d " " -f2 >>repository_file
		fi
	fi

done < all_dir
# remove temp file and give a Hint !
rm all_dir
if [ $? == 0 ]; then
	echo "Ok,all the url of your repository have been send to file -- repository_file"
fi

现在,所有仓库目录下的git仓库地址已经被添加到 repository_file 文件中,如:

long@zhouyl:~/repository$ cat repository_file
git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
git://gitorious.org/tinylab/pleac-shell.git
git://git.kernel.org/pub/scm/linux/kernel/git/clrkwllms/rt-tests.git
...
这里省略了十几个个人仓库


现在我们可以使用scp将repository_file文件以及对下面的这个脚本拷贝到新安装的电脑上(scp repository_file clone.sh long@192.168.2.110:/tmp/),然后直接运行clone.sh(./clone.sh)即可!

#!/bin/bash
# (C) 2014 Yunlong Zhou <reaper888@yeah.net>
# Under licence  GPL
# File :   clone.sh 
# Introduction:
#       This script is using for git clone every item in repository_file
# Useage :
#       1. ./clone.sh   

if [ ! -f repository_file ]; then
	echo "There is no repository_file ,we will exit"
	exit
fi

while read READLINE
do
	echo "Now we will clone $READLINE"
	git clone $READLINE
done < repository_file

rm repository_file




转载请注明:“ 转自 :http://blog.csdn.net/longerzone/article/details/20877841



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值