-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
80 lines (67 loc) · 1.58 KB
/
run.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
#!/usr/bin/sh
function clone()
{
local repository=$1
local username=$2
local password=$3
echo "Start getting ${repository}"
expect <<EOF
set timeout 30
spawn git clone --bare ${repository}
expect {
"Username for *" {
send "${username}\n"
expect "Password for *"
send "${password}\n"
}
"Password for *" { send "${password}\n" }
}
expect eof
EOF
}
function push()
{
local repository=$1
local username=$2
local password=$3
echo "Start sending git information to ${repository}"
expect <<EOF
set timeout 300
spawn git push --mirror ${repository}
expect {
"Username for *" {
send "${username}\n"
expect "Password for *"
send "${password}\n"
}
"Password for *" { send "${password}\n" }
}
expect eof
EOF
echo "${repository} done."
}
function sync()
{
local formRepository=https://github.com/old.git
local toRepository=https://github.com/new.git
echo "Start synchronizing ..."
mkdir /tmp/app
cd /tmp/app
clone ${formRepository} username password
local gitPath=$(echo ${formRepository} | grep -E '\w*\.git$' -o)
if [[ -d $gitPath ]];then
cd $gitPath
# Send to remote git
push ${toRepository} username password
# Clear
rm -rf /tmp/app/${gitPath}
else
echo "Synchronization failure: Cloning didn't work."
fi
echo "fulfilled synchronously."
}
while true
do
sync
sleep 10
done