forked from xingfuqiu/PokemonGoMove
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-web
executable file
·57 lines (51 loc) · 1.71 KB
/
start-web
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
echo
echo "Initializing..."
echo
echo "Did you know you can now specify the GPS coordinates at the startup?"
echo "$ ./start-web -l 1.0 -o 2.0 #startup lat=1.0 and long=2.0 "
echo "$ ./start-web #startup with current location base on ip"
echo
latitude= longtitude=
while getopts l:o: opt; do
case $opt in
l)
latitude=$OPTARG
;;
o)
longtitude=$OPTARG
;;
esac
done
shift $((OPTIND - 1))
if [ -z "$latitude" ] || [ -z "$longtitude" ]; then
echo "Getting user's current GPS coordinates..."
location=$(curl -s http://whatismycountry.com/ | sed -n 's/.*Coordinates \(.*\)<.*/\1/p')
if [ -z "$location" ]; then
echo "Cannot get GPS coordinates"
else
location_array=($location)
latitude=${location_array[0]}
longtitude=${location_array[1]}
echo "Got "$location
fi
fi
if [ ! -z "$latitude" ] && [ ! -z "$longtitude" ]; then
if (( ${latitude%.*} >= -90 )) && (( ${latitude%.*} <= 90 )) && (( ${longtitude%.*} >= -180 )) && (( ${longtitude%.*} <= 180 )); then
echo "Setting latitude to: "$latitude", longtitude to: "$longtitude
else
echo "Error: Invalid latitude (must be >=-90 && =<90) and longtitude (must be >=-180 && <=180)"
exit
fi
else
# Cannot get a valid pair of GPS coordinates
echo "Using default GPS coordinates: latitude=37.808341; longtitude=-122.409664"
latitude=37.808341 #default latitude
longtitude=-122.409664 #default longtitude
fi
# Replace the value of latitude and longtitude
index_file=controller/views/index.erb
sed -i "" "s/var START_LATITUDE.*$/var START_LATITUDE = \"$latitude\"\;/g" $index_file
sed -i "" "s/var START_LONGTITUDE.*$/var START_LONGTITUDE = \"$longtitude\"\;/g" $index_file
echo
echo
ruby controller/app.rb