-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_simulator.sh
executable file
·187 lines (170 loc) · 6 KB
/
update_simulator.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
#!/usr/bin/bash
VALID_ARGS=$(getopt -o c:f:do:h --long config:,folder:,download,only:,help -- "$@")
if [[ $? -ne 0 ]]; then
exit 1;
fi
config="false"
folderloc="false"
download="false"
only="all"
help="false"
eval set -- "$VALID_ARGS"
while true; do
case "$1" in
-c | --config)
config="$2"
shift 2
;;
-f | --folder)
folderloc="$2"
shift 2
;;
-d | --download)
download="true"
shift 1
;;
-o | --only)
only=$2
shift 2
;;
-h | --help)
help="true"
break
;;
--) shift;
break
;;
esac
done
if [[ $help == "true" ]]
then
cat <<EOF
This script expects you to make a config file that will be used everytime you update.
Details on its format are at the bottom. It also expects that you are in your batsim_environment
Usage:
update_simulator.sh -i <path_to_config> [-f <path_to_folders>|-d] [-o (code|simulator)]
-c <path>, --config <path> path to config
-f <path>, --folder <path> path to simulator,batsim4,batsched4
-d, --download download latest
-o ,--only (code|simulator) only update 'code' or 'simulator', otherwise update all
config file:
paths should be absolute expanded paths. input field will not be used with -f or -d options
input=/path/to/tarfile.tar.gz include the filename in path
This tarball should include batsim4, batsched4, and simulator folders
output=/path/to/simulator include the simulator folder in path but not a trailing slash '/'
compileCommand="compile.sh -f <format> -p <path> -m <modules>"
example: update_simulator.sh -i /users/<name>/update.config [-o (simulator|code)]
Script will:
untar your tarball into temp folder || copy to temp folder || download latest into temp folder
remove .../simulator/Downloads/[batsim4 and batsched4]
move the new batsim4 and batsched4 to .../simulator/Downloads/
move .../simulator/basefiles/batsim_environment.sh to .../simulator/batsim_environment.sh
remove .../simulator/basefiles
move the new simulator/basefiles to .../simulator/
move .../simulator/batsim_environment.sh to .../simulator/basefiles/
remove the new simulator folder
remove the new tarfile
run compileCommand
EOF
fi
batsim4compile=false
batsched4compile=false
if [[ $only != "simulator" ]] && [[ $only != "code" ]];then
echo "Error, -o option only takes 'simulator' or 'code'"
exit
fi
if [[ $config != "false" ]]
then
#source config file
. $config
#source batsim_environment
. "${output}/basefiles/batsim_environment.sh"
#get the name of the tarball
file="$(basename $input)"
#get the folder that the tarball is in and will untar to
folder="$(dirname $input)"
#go to this folder
cd "$folder"
mkdir -p tmp_update
if [[ $folderloc != "false" ]]; then
if [[ $only == "simulator" ]] || [[ $only == "all" ]];then
cp -R ${folderloc}/simulator ./tmp_update/
fi
if [[ $only == "code" ]] || [[ $only == "all" ]];then
cp -R ${folderloc}/batsim4 ./tmp_update/
cp -R ${folderloc}/batsched4 ./tmp_update/
fi
cd ./tmp_update
elif [[ $download != "false" ]]; then
cd ./tmp_update
if [[ $only == "simulator" ]] || [[ $only == "all" ]];then
git clone https://github.com/hpc/simulator.git
fi
if [[ $only == "code" ]] || [[ $only == "all" ]];then
git clone https://github.com/hpc/batsim4.git
git clone https://github.com/hpc/batsched4.git
fi
else
mv $file ./tmp_update
cd ./tmp_update
#untar the tarball
echo "untaring ..."
tar -xzf $file
fi
batsim4compile=false;batsched4compile=false;
if [[ $only == "code" ]] || [[ $only == "all" ]];then
#remove the batsim4 and batsched4 folders
if [ -d batsim4 ];then
echo "removing old batsim4 code ..."
rm -rf "${output}/Downloads/batsim4"
echo "moving new batsim4 code ..."
mv ./batsim4 "${output}/Downloads/"
batsim4compile=true
fi
if [ -d batsched4 ];then
echo "removing old batsched4 code ..."
rm -rf "${output}/Downloads/batsched4"
echo "moving new batsched4 code ..."
mv ./batsched4 "${output}/Downloads/"
batsched4compile=true
fi
fi
if [[ $only == "simulator" ]] || [[ $only == "all" ]];then
#move the original batsim_environment.sh
if [ -d simulator ];then
mv "${output}/basefiles/batsim_environment.sh" "${output}/"
#remove basefiles and moving new basefiles
echo "removing old basefiles ..."
rm -rf "${output}/basefiles" && not_finish=false
echo "move new basefiles ..."
mv ./simulator/basefiles "${output}/basefiles"
#remove the new batsim_environment.sh
rm -rf "${output}/basefiles/batsim_environment.sh"
#move the original batsim_environment.sh into basefiles
mv "${output}/batsim_environment.sh" "${output}/basefiles/"
#remove new simulator folder
rm -rf ./simulator
#remove the tar file
fi
fi
rm $file
if [[ $only == "code" ]] || [[ $only == "all" ]];then
#compile both batsim4 and batsched4
sleep 5
if [ $batsim4compile = true ];then
echo "compiling new batsim code ..."
$compileCommand -o batsim
fi
sleep 5
if [ $batsched4compile = true ];then
echo "compiling new batsched code ..."
$compileCommand -o batsched
fi
fi
#print out success message
echo "***********************************"
echo ""
echo " Successfully updated !!!"
echo ""
echo "***********************************"
fi