dwm: updated to 5.1
[namenlos-ports.git] / cgit / copyrepos
blobf5ea19ef92504a769bed041fad52e66c1edfd5f1
1 #!/bin/bash
3 # author: richard pöttler, richard dot poettler at gmail dot com
4 # repocopy: clones/pushes repositories to a given destination
7 # prints the usage and exits if a parameter is given
8 function printusage() {
9 echo "usage: "
10 echo "$0 [-h] [-f <config file>] [filter [, filter]*]"
11 echo " -h prints this help message"
12 echo " -f specify another config file (default: /etc/copyreposrc)"
13 echo " filter: only lines containing a phrase of a filter will be processed"
14 echo ""
15 echo " format of the config file:"
16 echo " <from dir> <to dir> <clone option>"
17 if [ $# -ge 1 ]; then
18 exit $1
23 config=/etc/copyreposrc
24 oldpwd=`pwd`
26 # parsing the commandline options
27 args=`getopt f:h $*`
28 if [ $? -ne 0 ]; then
29 printusage 1
31 set -- $args
33 for a; do
34 case $a in
35 -f)
36 shift
37 config=$1
38 shift
40 -h)
41 printusage 0
43 esac
44 done;
45 shift
47 if [ ! -f $config ]; then
48 echo "Can't open the config file: $config"
49 exit 2
50 fi;
52 # cloning/pushing the repositories
53 if [ $# -eq 0 ]; then # doing all repositories
54 while read from to opts; do
55 if [ -d $to ]; then # already cloned -> push
56 cd $from
57 git-push $to
58 else # cloning
59 git-clone $opts $from $to
61 done < $config
62 else # doing a filtered list of repositories
63 # constructing the filter for the config file lines
64 argc=$#
65 for repo; do
66 filter+=$repo\\\|
67 done
68 if [ $argc -ge 1 ]; then
69 filter=${filter:0:$((${#filter} - 2))}
71 # iterating over the lines
72 grep $filter $config | while read from to opts; do
73 if [ -d $to ]; then # already cloned -> push
74 cd $from
75 git-push $to
76 else # cloning
77 git-clone $opts $from $to
79 done
82 cd $oldpwd