-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathgrid-calc
More file actions
130 lines (105 loc) · 3.88 KB
/
grid-calc
File metadata and controls
130 lines (105 loc) · 3.88 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
#!/bin/bash
#GUI interface for wwl command line application
#wwl was written by VA3DB
#17FEB2021 KM4ACK
##################################################################
# #
# # # # # # # ##### # # #
# # # # # # # ## # # # # # #
# # # # # # # # # # # # # #
# ## # # ##### ####### # ## #
# # # # # # # # # # # #
# # # # # # # # # # # #
# # # # # # # # ##### # # #
# #
##################################################################
VERSION=1
LOGO=/usr/share/icons/PiXflat/48x48/apps/gnome-calculator.png
###########################
# 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 yad 2>/dev/null; then
INSTALL
fi
if ! hash bc 2>/dev/null; then
INSTALL
fi
if ! hash wwl 2>/dev/null; then
INSTALL
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" \
--field="Other Grid" \
--button="Continue":2 \
--button="Exit":1)
BUT=$?
if [ $BUT = 252 ] || [ $BUT = 1 ]; then
exit
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