-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_repos.sh
executable file
·130 lines (115 loc) · 2.08 KB
/
update_repos.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
#
# Script for updating repositories defined in text file.
#
# Format:
# name TAB type TAB local dir
#
# Supported types:
# - git
# sudo apt-get install git
# - svn
# sudo apt-get install subversion
# - gdrive
# https://github.com/odeke-em/drive
# the usage of this script
function usage()
{
echo
echo "${0##*/} [-r <name>] [-h]"
echo
echo "Updates projects as defined in $LIST."
echo
echo " -h this help"
echo " -l list all projects"
echo " -r <name>"
echo " resume update with this project name"
echo
}
# changes into DIR and calls git pull
function update_git {
cd $DIR
git pull
RC=$?
}
# changes into DIR and calls svn update
function update_svn {
cd $DIR
svn update
RC=$?
}
# changes into DIR and calls gdrive pull
function update_gdrive {
cd $DIR
drive pull -no-prompt -quiet -ignore-name-clashes -ignore-conflict
RC=$?
}
ROOT=`expr "$0" : '\(.*\)/'`
LIST=$ROOT/update.list
COMMENT="#"
RESUME=""
LIST_ONLY="no"
# interprete parameters
while getopts ":hlr:" flag
do
case $flag in
r) RESUME=$OPTARG
;;
l) LIST_ONLY="yes"
;;
h) usage
exit 0
;;
*) usage
exit 1
;;
esac
done
while read LINE
do
# comment or empty line?
if [[ "$LINE" =~ ^$COMMENT ]] || [ -z "$LINE" ]
then
continue
fi
read -a PARTS <<< "${LINE}"
NAME="${PARTS[0]}"
TYPE="${PARTS[1]}"
DIR="${PARTS[2]}"
# find project to resume
if [ ! "$RESUME" = "" ]
then
if [ ! "$RESUME" = "$NAME" ]
then
continue
else
RESUME=""
fi
fi
echo "$NAME - $DIR"
if [ ! "$LIST_ONLY" = "yes" ]
then
case $TYPE in
svn)
update_svn
;;
git)
update_git
;;
gdrive)
update_gdrive
;;
*)
echo "Unknown repository type $TYPE, skipping!"
esac
# failed?
if [ $RC != 0 ]
then
echo
echo "Update of '$NAME' failed with exit code: $RC"
echo "You can resume updates with: ${0##*/} -r $NAME"
echo
exit $RC
fi
fi
done < "$LIST"