-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathgrid-calc
More file actions
236 lines (195 loc) · 6.58 KB
/
grid-calc
File metadata and controls
236 lines (195 loc) · 6.58 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
#GUI interface for wwl command line application
#wwl was written by VA3DB
#17FEB2021 KM4ACK
##################################################################
# #
# # # # # # # ##### # # #
# # # # # # # ## # # # # # #
# # # # # # # # # # # # # #
# ## # # ##### ####### # ## #
# # # # # # # # # # # #
# # # # # # # # # # # #
# # # # # # # # ##### # # #
# #
##################################################################
VERSION=2
LOGO=/usr/share/icons/PiXflat/48x48/apps/gnome-calculator.png
#get gps grid if available
if [ -f /run/user/$UID/gridinfo.txt ]; then
GPSGRID=$(cat /run/user/$UID/gridinfo.txt)
fi
#verify yad is installed on this machine
if ! hash yad 2>/dev/null; then
echo "installing yad"
sudo apt update
sudo apt-get install -y yad
fi
###########################
# Changelog
###########################
CHANGELOG(){
version 2
add gps if available
add lat/long lookup
add changelog
build app from source
bump version number
}
###########################
# Menu Shortcut
###########################
MENUITEM(){
cat > /run/user/$UID/grid-calc.desktop <<EOF
[Desktop Entry]
Name=Grid Calc
GenericName=Check distance and bearing between 2 grids
Comment=Check distance and bearing between 2 grids
Exec=$HOME/bin/grid-calc
Icon=/usr/share/icons/gnome/32x32/apps/kcalc.png
Terminal=false
Type=Application
Categories=Utility;HamRadio
EOF
sudo mv /run/user/$UID/grid-calc.desktop /usr/share/applications/
}
if [ ! -f /usr/share/applications/grid-calc.desktop ]; then
MENUITEM
echo "Menu shortcut created for grid-calc"
echo "Start grid-calc from the pi menu"
exit 0
fi
###########################
# Install Depends
###########################
INSTALL(){
yad --form --width=420 --text-align=center --center --title="Grid Calc" \
--image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \
--text="<b>Grid Calc v $VERSION</b>\rDependencies missising!\rInstall now?" \
--button="Install Dependencies":2 \
--button="Exit":1
BUT=$?
if [ $BUT = 1 ] || [ $BUT = 252 ]; then
exit
elif [ $BUT = 2 ]; then
sudo apt update | yad --center --progress --pulsate --auto-close --no-buttons --text-align=center --title="Grid Calc" \
--text="Updateing Repository....This may take a few minutes\r<b>DO NOT CLOSE THIS WINDOW</b>\rDoing so will abort the process.\rThis window will auto close when the process completes"
sudo apt install -y wwl bc | yad --center --progress --pulsate --auto-close --no-buttons --text-align=center --title="Grid Calc" \
--text="Getting Depends....This may take a few minutes\r<b>DO NOT CLOSE THIS WINDOW</b>\rDoing so will abort the download.\rThis window will auto close when the process completes"
fi
}
if ! hash bc 2>/dev/null; then
INSTALL
fi
if ! hash wwl 2>/dev/null; then
if [ -f /usr/local/man/man1/locator.1.gz ]; then
sudo rm /usr/local/man/man1/locator.1.gz
fi
cd $HOME/Downloads
echo "checking for latest wwl package"
LATEST=$(curl -s http://www.db.net/downloads/ | grep wwl | awk '{print $2}' | sed 's/href="//;s/">//')
DIR=$(echo $LATEST | sed 's/.tgz//')
echo $DIR
echo "downloading latest wwl package"
wget http://www.db.net/downloads/$LATEST
tar -xvf $LATEST
cd $HOME/Downloads/$DIR
echo "building wwl"
make && sudo make install
echo "build done...cleaning up"
rm -rf $HOME/Downloads/$DIR
rm $HOME/Downloads/$LATEST
fi
if [ ! -f /usr/local/bin/locator ]; then
if [ -f /usr/local/man/man1/locator.1.gz ]; then
sudo rm /usr/local/man/man1/locator.1.gz
fi
cd $HOME/Downloads
echo "checking for latest wwl package"
LATEST=$(curl -s http://www.db.net/downloads/ | grep wwl | awk '{print $2}' | sed 's/href="//;s/">//')
DIR=$(echo $LATEST | sed 's/.tgz//')
echo $DIR
echo "downloading latest wwl package"
wget http://www.db.net/downloads/$LATEST
tar -xvf $LATEST
cd $HOME/Downloads/$DIR
echo "building wwl"
make && sudo make install
echo "build done...cleaning up"
rm -rf $HOME/Downloads/$DIR
rm $HOME/Downloads/$LATEST
fi
###########################
# Locator
###########################
LOCATOR(){
LOCATOR=$(yad --form --width=420 --text-align=center --center --title="Grid Calc" \
--image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \
--text="<b>Grid Calc v $VERSION</b>\rGet Lat-Long\rfrom a grid square" \
--field="Grid" \
--button="Continue":2 \
--button="Exit":1)
BUT=$?
GRID=$(echo $LOCATOR | awk -F "|" '{print $1}')
if [ $BUT = 252 ] || [ $BUT = 1 ]; then
exit
elif [ $BUT = 2 ]; then
CORD=$(locator $GRID)
fi
LONG=$(echo $CORD | awk '{print $7}')
LONG1=$(echo $CORD | awk '{print $6}' | sed 's/(//;s/)//')
LONG2="$LONG $LONG1"
LAT=$(echo $CORD | awk '{print $11}')
LAT1=$(echo $CORD | awk '{print $10}' | sed 's/(//;s/)//')
LAT2="$LAT $LAT1"
yad --form --width=420 --text-align=center --center --title="Grid Calc" \
--image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \
--text="<b>Grid Calc v $VERSION</b>\r\rLatitude is $LAT2\rLongitude is $LONG2" \
--button="Main Menu":2 \
--button="Exit":1
BUT=$?
if [ $BUT = 252 ] || [ $BUT = 1 ]; then
exit
fi
}
###########################
# Main Application
###########################
CALC(){
GRIDS=$(yad --form --width=420 --text-align=center --center --title="Grid Calc" \
--image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \
--text="<b>Grid Calc v $VERSION</b>\rEnter the two grids\rto be calculated" \
--field="Your Grid" "$GPSGRID" \
--field="Other Grid" \
--button="Grid to Lat-Long":3 \
--button="Calculate":2 \
--button="Exit":1)
BUT=$?
if [ $BUT = 252 ] || [ $BUT = 1 ]; then
exit
elif [ $BUT = 3 ]; then
LOCATOR
CALC
fi
MYGRID=$(echo $GRIDS | awk -F "|" '{print $1}')
GRID2=$(echo $GRIDS | awk -F "|" '{print $2}')
RESULTS=$(wwl $MYGRID $GRID2)
DISTANCE=$(echo $RESULTS | awk '{print $2}')
DEGREES=$(echo $RESULTS | awk '{print $5}')
#MILES=$(bc -l <<< "$DISTANCE*.6213712" | cut -c 1-5)
MILES=$(bc -l <<< "$DISTANCE*.6213712" | xargs printf "%.2f\n")
yad --form --width=420 --text-align=center --center --title="Grid Calc" \
--image $LOGO --window-icon=$LOGO --image-on-top --separator="|" --item-separator="|" \
--text="<b>Grid Calc v $VERSION</b>\rRESULTS" \
--field="Distance is $DISTANCE Kilometers or $MILES Miles":LBL \
--field="Bearing is $DEGREES Degrees":LBL \
--button="Calulate Another":2 \
--button="Exit":1
BUT=$?
if [ $BUT = 1 ] || [ $BUT = 252 ]; then
exit
elif [ $BUT = 2 ]; then
CALC
fi
}
CALC