summaryrefslogtreecommitdiff
path: root/bin/tle
diff options
context:
space:
mode:
Diffstat (limited to 'bin/tle')
-rwxr-xr-xbin/tle61
1 files changed, 24 insertions, 37 deletions
diff --git a/bin/tle b/bin/tle
index a959f24..156551f 100755
--- a/bin/tle
+++ b/bin/tle
@@ -9,39 +9,35 @@ paddedsatnore="^[0| ]{1}[0-9| ]{3}[1-9]$" # Regex for padded satno
shortintdesre="^[0-9]{5}[A-Za-z]+$" # Regex for short int-des (98067A, 98067ABCD)
# Math functions
-function cuberoot
-{
+cuberoot() {
echo "e(l($1)/3)" | bc -l
}
# Main functions
-function settlefile
-{
+settlefile() {
#workingdir=$(pwd)
#tlefile=$workingdir/tle
tlefile=/usr/local/share/tle/tle
}
-function update
-{
- # Maybe use $1 and $2 for usn/password and have another function to set those?
- # That way the "autoupdate" function could just read usn/pwd from file instead
+update() {
+ # Maybe have a .csv file listing a saved account?
echo "Updating local spacetrack catalog."
- read -p "Enter space-track.org username: " username
- read -s -p "Enter space-track.org password: " password
+ case "$1" in
+ auto) username="" && password="" ;;
+ esac
+ [ -z "$1" ] && read -p "Enter space-track.org username: " username && read -s -p "Enter space-track.org password: " password
query="https://www.space-track.org/basicspacedata/query/class/tle_latest/ORDINAL/1/EPOCH/%3Enow-30/format/tle"
#query="https://www.space-track.org/basicspacedata/query/class/tle_latest/30/orderby/NORAD_CAT_ID/format/tle"
curl https://www.space-track.org/ajaxauth/login -c /usr/local/share/tle/cookies.txt -d "identity=$username&password=$password&query=$query" > /usr/local/share/tle/tle
exit 0
}
-function readplaces
-{
+readplaces() {
placefile=/usr/local/share/tle/places.csv
}
-function getplace
-{
+getplace() {
placeline=$(sed -n "/^$1/p" $placefile)
name=$(echo $placeline | cut -f1 -d",")
fullname=$(echo $placeline | cut -f2 -d",")
@@ -56,8 +52,7 @@ function getplace
rangemax=$(echo $placeline | cut -f11 -d",")
}
-function showplace
-{
+showplace() {
echo "Place: $fullname"
echo "Latitude (N): $lat"
echo "Longitude (W): $lon"
@@ -70,8 +65,7 @@ function showplace
echo "Maximum range (km): $rangemax"
}
-function padtime
-{
+padtime() {
read input
if [ ${#input} -eq 1 ]; then
echo 0$input
@@ -82,13 +76,11 @@ function padtime
fi
}
-function getseconds
-{
+getseconds() {
echo "(86400*$1)+(3600*$2)+(60*$3)+$4" | bc -l
}
-function getage
-{
+getage() {
days=$(echo "$1/86400" | bc -l)
dayfraction=0.$(echo $days | cut -f2 -d".")
hours=$(echo "(86400/3600)*$dayfraction" | bc -l)
@@ -104,8 +96,7 @@ function getage
echo "$days $hours $minutes $seconds"
}
-function epochtime
-{
+epochtime () {
# date +%Y-%j-%H-%M-%S
tle=$(getsatno $1 $2)
epochyear=${tle:18:2}
@@ -130,8 +121,7 @@ function epochtime
echo "$epochyear $jday $hours:$minutes:$seconds UTC"
}
-function age
-{
+age() {
read inputtime
epochyear=$(echo $inputtime | cut -f1 -d" ")
epochday=$(echo $inputtime | cut -f2 -d" ")
@@ -150,28 +140,24 @@ function age
echo $elsetage
}
-function gettle
-{
+gettle() {
sed -n "/^[12] $1/p" $2
}
-function getsatno
-{
+getsatno() {
[[ $1 =~ $satnore ]] && gettle $1 $2 && exit 0
[[ $1 =~ $paddedsatnore ]] && correctedsatno=$(echo "$1" | sed "s/^0/ /;: loop s/ 0/ /;t loop") && sed -n "/^[12] $correctedsatno/p" $2 && exit 0
[[ $1 =~ $shortintdesre ]] && line1=$(sed -n "/^1.\{8\}$1/p" $2) && gettle "${line1:2:5}" $2 && exit 0
}
-function printsatno
-{
+printsatno() {
[[ $1 =~ $satnore ]] && echo $1 && exit 0
[[ $1 =~ $shortintdesre ]] && line1=$(sed -n "/^1.\{8\}$1/p" $2)
echo ${line1:2:5}
}
-function decodetle
-{
+decodetle() {
read line1
read line2
# Line 1
@@ -295,8 +281,7 @@ case "$1" in
if [ -z "$2" ]; then echo "tle: not enough arguments."; exit 1; fi
getplace $2
showplace ;;
- update) update
- exit 0 ;;
+ update) [ -z "$2" ] && update || update auto ;;
*) cat << EOF
tle - NORAD two-line element set processor. Written 2020 by Ray Patrick.
@@ -329,8 +314,10 @@ Options:
Calculate look angles for a specific satellite.
(Coming soon)
- $ tle update
+ $ tle update [auto]
Updates the TLE file at /usr/local/share/tle/tle.
+ (Will prompt you for your space-track.org username
+ and password unless the "auto" option is given.)
NOTE: Typing "man tle" at the command line will bring up more
thorough instructions.