This repository has been archived by the owner on Feb 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.sh
executable file
·211 lines (196 loc) · 5.07 KB
/
function.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# import readonly variables
source "${dir_src}/readonly.sh"
source "${dir_src}/wrap_tweet.sh"
function line () {
echo $1 | grep '^[0-9]*$' >& /dev/null
if [ $? -eq 0 ]; then
local line
local i=3
while [ $i -le $1 ]
do
line="${line}-"
i=`expr $i + 1`
done
if [ "$mute" != true ]; then
printf " $line \n"
fi
else
show "invaild argument" 1>&2
fi
}
function show () {
if [ "$mute" != true ]; then
echo "$@"
fi
}
function space () {
echo $2 | grep '^[0-9]*$' >& /dev/null
if [ $? -eq 0 ]; then
local string=$1
local length=$2
local string_length=${#string}
if [ $string_length -lt $length ]; then
show " ${string}"
else
show "invaild argument" 1>&2
fi
else
show "invaild argument" 1>&2
fi
}
function color() {
local red=31
local green=32
local yello=33
local blue=34
local color=$1
show -e "\033[${!color}m${2}\033[m" ${3}
}
function error() {
echo -e "\033[31m${1}\033[m" 1>&2
}
function footer () {
line $len_line
space "Thanks for using sigure..." $len_line
exit $1
}
function git_info () {
if [ -d "$1/.git" ]; then
git_ref=$(sed "s/.*: //g" "$1/.git/HEAD")
git_branch=${git_ref##*/}
git_commit=$(cat "$1/.git/${git_ref}")
fi
}
function git_update () {
if [ -d "$1/.git" ]; then
color green "* Welcome to sigure updator!"
git_info $1
local git_commit_older=${git_commit}
color green "* start updating..."
cd $1
git pull >& /dev/null
if [ $? -ne 0 ]; then
error "* E: git update failed."
cd $2
return 1
fi
git_info $1
if [ "${git_commit_older}" != "${git_commit}" ]; then
color green "* I: update ${git_commit_older} to ${git_commit}"
else
color green "* I: Already up-to-date."
fi
cd $2
return 0
else
error "* E: not git directory."
return 1
fi
}
function repo_init() {
local work=$1
local URL=$2
local target=$3
local raw
mkdir -p $target
cd $target
show -n "* please input init source name... > "
read raw
if [ "$raw" != "" ]; then
source=$raw
echo 'source="'"$source"'"' > "$target/config.sh"
if [ $? -ne 0 ]; then
error "* E: save failed."
else
show "* configuration saved."
fi
fi
repo init -u $URL
local result=$?
cd $work
if [ $result -eq 127 ]; then
error "* E: repo not installed."
elif [ $result -ne 0 ]; then
error "* E: repo init failed."
fi
return $result
}
function repo_sync() {
local work=$1
local pararell=$2
local target=$3
cd $target
repo sync --jobs $pararell --current-branch --force-broken --force-sync --no-clone-bundle
local result=$?
cd $work
if [ $result -eq 127 ]; then
error "* E: repo not installed."
elif [ $result -ne 0 ]; then
error "* E: repo sync failed."
fi
return $result
}
function make_clean() {
local work=$1
local pararell=$2
local target=$3
cd $target
make clean -j ${pararell}
local result=$?
cd $work
if [ $result -ne 0 ]; then
error "* E: make clean failed."
fi
return $result
}
function check_numeric() {
local check=$1
local except_numeric=`echo $check | sed 's/[0-9]//g'`
if [ "$except_numeric" = "" ]; then
return 0
fi
return 1
}
function tweet() {
if [ "$tweet" = true ]; then
local base_string=$1
local time=`date '+%m\/%d %H:%M:%S'`
local string=$(echo $base_string | sed -e "s/%time/$time/g" -e "s/%source/$source/g" -e "s/%model/$model/g" -e "s/%zip/$zip/g" -e "s/%hashtag/$hashtag/g" -e "s/%lastlog/$lastlog/g")
wrap_tweet "${string}"
if [ $? -ne 0 ]; then
error "E: tweet failed."
return 1
fi
return 0
fi
}
function load_config() {
local sigure=$1
local work=$2
local target=$3
if [ -f "${sigure}/config.sh" ]; then
source "${sigure}/config.sh"
fi
if [ -f "${work}/config.sh" ]; then
source "${work}/config.sh"
fi
if [ -f "${target}/config.sh" ]; then
source "${target}/config.sh"
fi
}
function usage () {
echo -e "* usage: $0 \033[32m[-d device] [-s dir]\033[m [-c] [-h] [-i URL] [-j number] [-m] [-r] [-t] [-u] [-x]" ${1}
echo -e "* -d: target device \033[32m(required)\033[m" ${1}
echo -e "* -s: target directory \033[32m(required)\033[m" ${1}
echo "* -c: make clean" ${1}
echo "* -h: show help" ${1}
echo "* -i: repo init" ${1}
echo " ex. $0"' -i "git://github.com/CyanogenMod/android.git -b cm-13.0"'
echo "* -j: job threads" ${1}
echo "* -m: mute mode" ${1}
echo "* -r: repo sync" ${1}
echo "* -t: tweet mode" ${1}
echo "* -u: sigure git updator" ${1}
echo "* -x: direct start-up" ${1}
echo " do not use screen" ${1}
}