-
Notifications
You must be signed in to change notification settings - Fork 83
/
update.sh
167 lines (145 loc) · 2.82 KB
/
update.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
# the script get the master brach of the github repo, clone it to local with git
# or delete the repo directly.
#
# for get pure url, first get the url list and print to tmp file, and will be delete
# at the end.
#
# require : the script need to run in git bash
# or system with git installed
#
# the script use awk, grep, cat to do work
#
# usage : sh update.sh
#
INFILE='README.md'
OUTFILE='.tmp'
DEBUG=''
# print usage
function usage
{
echo ""
echo " usage:"
echo ""
echo "sh update.sh <cmd>"
echo " where <cmd> is one of:"
echo " --install-or-update (does full installation or update.)"
echo " --remove (removes all installed)"
echo ""
echo "example:"
echo ' $ sh update.sh --install-or-update'
}
# for debug
function printvar
{
if [[ "$DEBUG" != "" ]]; then
echo $1
fi
:
}
# find the git is installed
function check
{
git --version >/dev/null
if [ $? -ne 0 ]
then
echo "no git command found ! please download and install"
exit
fi
:
}
# find and write the list to file
function pure_list
{
# clean list
>$2
# loop the line of the readme
for LINE in $(cat $1)
do
rs=$(echo $LINE | grep "github" )
if [[ "$rs" != "" ]]; then
# the projects list can not be installed
rt=$(echo $LINE | grep "HardwareBoard" )
if [[ "$rt" != "" ]]; then
continue
fi
rl=$(echo $LINE | awk -F '(' '{print $2}' | awk -F ')' '{print $1}' )
# write list
echo "$rl" >> $2
fi
:
done
}
# find the git dir
function is_git
{
isg=$(cat $1/.git/config)
if [[ "$isg" == "" ]]; then
return "0"
else
return "1"
fi
}
# git clone the repo , update if it is exist
function do_update
{
# loop the line of the readme
for LINE in $(cat $1)
do
instant=$(echo $LINE | awk -F '/' '{print $5}' )
printvar $instant
if [[ "$instant" == "" ]]; then
continue
printvar "noting"
fi
if [ -d "$instant" ]; then
# find the dir is git dir or not
ig=is_git "$instant"
if [[ "$ig" == "0" ]]; then
rm -rf $instant
git clone "$LINE" &
fi
git pull origin master ; printvar "$instant"
else
git clone "$LINE" &
fi
:
done
}
# delete the repo, through the list in the list file, so it need to get
# the list first
function do_del
{
for LINE in $(cat $1)
do
instant=$(echo $LINE | awk -F '/' '{print $5}' )
printvar $instant
if [[ "$instant" == "" ]]; then
continue
fi
printvar $instant
if [ -d "$instant" ]; then
rm -rf $instant
fi
:
done
}
# main
check
if [ $# -eq 1 -a "$1" == "--install-or-update" ]; then
if [ ! -f "$OUTFILE" ]; then
pure_list $INFILE $OUTFILE
fi
do_update $OUTFILE
rm -rf $OUTFILE
exit
fi
if [ $# -eq 1 -a "$1" == "--remove" ]; then
if [ ! -f "$OUTFILE" ]; then
pure_list $INFILE $OUTFILE
fi
do_del $OUTFILE
rm -rf $OUTFILE
exit
fi
usage