-
Notifications
You must be signed in to change notification settings - Fork 315
/
Copy pathstart-anyplace-tiler.sh
executable file
·120 lines (94 loc) · 2.93 KB
/
start-anyplace-tiler.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
#!/bin/bash
LOG_ENABLED=0
get_abs_path(){
[[ -z "$1" ]] && echo "get_abs_path:: 1 argument required" && exit 1
local PARENT_DIR=$(dirname "$1")
# navigate to the direcotry of the argument
cd "$PARENT_DIR"
local abs_path="$(pwd)"/"$(basename "$1")"
# return to the directory we execute
cd - >/dev/null
echo "$abs_path"
}
get_abs_path2(){
[[ -z "$1" ]] && echo "get_abs_path:: 1 argument required" && exit 1
local arg_path=$(readlink -f $1)
#local abs_parent_path=$(dirname "$arg_path")
#echo "$abs_parent_path"
echo "$arg_path"
}
get_scripts_dir(){
local abs_path=$(get_abs_path "$0")
echo $(dirname "$abs_path")
}
get_scripts_dir2(){
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
echo "$DIR"
}
usage(){
echo " ::: Usage ::: "
echo -e "./start-anyplace-tiler.sh <ImageFilePath> <ImageLatitude> <ImageLongitude> [-DISLOG/-ENLOG]"
echo
exit 1
}
check_for_errors(){
if [[ $? -ne 0 ]]; then
echo "There was a problem running the anyplace-tiler.py script!"
echo "Log: $LOG"
exit 1
fi
}
check_requirements(){
[[ -z "$(which python)" ]] && echo "python ::You do not have Python installed!" && exit 1
[[ -z "$(which convert)" ]] && echo "convert ::You do not have ImageMagick installed!" && exit 1
[[ -z "$(which identify)" ]] && echo "identify ::You do not have ImageMagick installed!" && exit 1
[[ -z "$(which advpng)" ]] && echo "advpng ::You do not have AdvanceCOMP installed!" && exit 1
}
##################### MAIN
[[ "$#" != "5" ]] && usage
[[ "$4" != "-ENLOG" && "$4" != "-DISLOG" ]] && usage
# TODO
# DO MORE ROBUST CHECK FOR THE ARGUMENTS
if [[ "$4" == "-ENLOG" ]]; then
LOG_ENABLED=1
else
LOG_ENABLED=0
fi
scriptsDir=$( get_scripts_dir )
imagePath=$( get_abs_path2 $1 )
imageDir=$( dirname "$imagePath" )
LOG="$imageDir/anyplace_tiler_$(date +"%Y_%m_%d_%s").log"
# save Input to 3 and output to 4 and redirect them to the LOG file
if [[ $LOG_ENABLED -eq 1 ]]; then
exec 3>&1 4>&2 1>$LOG 2>&1
fi
echo
echo ":: INITIATING TILING PROCESS ..."
echo "Checking requirements ..."
check_requirements
echo "Scripts Directory: $scriptsDir"
echo "Image: $imagePath"
ImageLatitude="$2"
ImageLongitude="$3"
ZoomOriginal=22
ZoomDestination=19
ImageFileName="$imagePath"
UploadZoom="$5"
echo
echo ":: Starting anyplace-tiler ..."
anyTiler="$scriptsDir/anyplace-tiler.py"
python "$anyTiler" "$scriptsDir" "$ImageLatitude" "$ImageLongitude" "$ZoomOriginal" "$ZoomDestination" "$ImageFileName" "$UploadZoom"
check_for_errors
echo
echo ":: Finished Tiling! ::"
# restore the input and output
if [[ $LOG_ENABLED -eq 1 ]]; then
exec 1>&3 2>&4
fi
echo "Log: $LOG"