-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
run.sh
195 lines (111 loc) · 2.75 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
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
#!/usr/bin/env bash
set -e
_script="$0"
_script_home="$(dirname "$_script")"
_oldPWD="$PWD"
#everytime we cd to the script home
cd "$_script_home"
#find the release number
if [ -z "$VM_RELEASE" ]; then
if [ ! -e "conf/default.release.conf" ]; then
echo "The VM_RELEASE is empty, but the conf/default.release.conf is not found. something wrong."
exit 1
fi
. "conf/default.release.conf"
VM_RELEASE=$DEFAULT_RELEASE
fi
export VM_RELEASE
#load the release conf
if [ ! -e "conf/$VM_RELEASE.conf" ]; then
echo "Can not find release conf: conf/$VM_RELEASE.conf"
echo "The supported release conf: "
ls conf/*
exit 1
fi
. conf/$VM_RELEASE.conf
#load the vm conf
_conf_filename="$(echo "$CONF_LINK" | rev | cut -d / -f 1 | rev)"
echo "Config file: $_conf_filename"
if [ ! -e "$_conf_filename" ]; then
wget -q "$CONF_LINK"
fi
. $_conf_filename
##########################################################
export VM_OS_NAME
vmsh="$VM_VBOX"
if [ ! -e "$vmsh" ]; then
echo "Downloading vbox to: $PWD"
wget "$VM_VBOX_LINK"
fi
osname="$VM_OS_NAME"
ostype="$VM_OS_TYPE"
sshport=$VM_SSH_PORT
ovafile="$osname-$VM_RELEASE.ova"
importVM() {
_idfile='~/.ssh/mac.id_rsa'
bash $vmsh addSSHHost $osname $sshport "$_idfile"
bash $vmsh setup
if [ ! -e "$ovafile" ]; then
echo "Downloading $OVA_LINK"
wget -O "$ovafile" -q "$OVA_LINK"
fi
if [ ! -e "id_rsa.pub" ]; then
echo "Downloading $VM_PUBID_LINK"
wget -O "id_rsa.pub" -q "$VM_PUBID_LINK"
fi
if [ ! -e "mac.id_rsa" ]; then
echo "Downloading $VM_PUBID_LINK"
wget -O "mac.id_rsa" -q "$HOST_ID_LINK"
fi
ls -lah
bash $vmsh addSSHAuthorizedKeys id_rsa.pub
cat mac.id_rsa >$HOME/.ssh/mac.id_rsa
chmod 600 $HOME/.ssh/mac.id_rsa
bash $vmsh importVM "$ovafile"
if [ "$DEBUG" ]; then
bash $vmsh startWeb $osname
bash $vmsh startCF
fi
}
waitForLoginTag() {
bash $vmsh waitForText "$osname" "$VM_LOGIN_TAG"
}
#using the default ksh
execSSH() {
exec ssh "$osname"
}
#using the sh
execSSHSH() {
exec ssh "$osname" sh
}
addNAT() {
bash $vmsh addNAT "$osname" "$@"
}
setMemory() {
bash $vmsh setMemory "$osname" "$@"
}
setCPU() {
bash $vmsh setCPU "$osname" "$@"
}
startVM() {
bash $vmsh startVM "$osname"
}
rsyncToVM() {
_pwd="$PWD"
cd "$_oldPWD"
rsync -auvzrtopg --exclude _actions/vmactions/$osname-vm /Users/runner/work/ $osname:work
cd "$_pwd"
}
rsyncBackFromVM() {
_pwd="$PWD"
cd "$_oldPWD"
rsync -uvzrtopg $osname:work/ /Users/runner/work
cd "$_pwd"
}
installRsyncInVM() {
ssh "$osname" "$VM_INSTALL_CMD $VM_RSYNC_PKG"
}
runSSHFSInVM() {
ssh "$osname" "$VM_INSTALL_CMD $VM_SSHFS_PKG && sshfs -o allow_other,default_permissions runner@10.0.2.2:work /Users/runner/work"
}
"$@"