aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--randopitons.sh81
1 files changed, 32 insertions, 49 deletions
diff --git a/randopitons.sh b/randopitons.sh
index 398b9f1..3cba118 100644
--- a/randopitons.sh
+++ b/randopitons.sh
@@ -1,6 +1,5 @@
#!/usr/bin/env bash
# Bash3 Boilerplate. Copyright (c) 2014, kvz.io
-clear
#set -o errexit
#set -o pipefail
@@ -14,6 +13,13 @@ __base="$(basename ${__file} .sh)"
__root="$(cd "$(dirname "${__dir}")" && pwd)" # <-- change this as it depends on your app
REGIONS=$(cat ${__dir}/regions.txt)
REGIONFILE="${__dir}/regions.txt"
+MAPTYPE="gpx"
+RDPUSER=
+RDPUSERPASS=
+LOGINOK=
+
+#Filechecks
+printf "Cirque de Cilaos\nCirque de Mafate\nCirque de Salazie\nEst\nNord\nOuest\nSud\nVolcan\nAilleurs\nAll" > $REGIONFILE
#https://stackoverflow.com/questions/4813092/how-to-read-entire-line-from-bash
#so we don't use a while loop
@@ -22,17 +28,16 @@ IFS=$'\n'
_download()
{
- while read linefromfile; do
- mkdir -p ${__dir}/randopfiles/"${linefromfile}"
- cd ${__dir}/randopfiles/"${linefromfile}"
- WEBREGION=$(echo ${linefromfile} | sed 's/ de /\-/g' | tr '[:upper:]' '[:lower:]')
- FILENBRS=$(wget -qO- https://randopitons.re/randonnees/region/${WEBREGION} | grep "<tr rid" | cut -d \" -f2)
- for nbr in $FILENBRS;do
- # you can change the delay for the -w option. I'm not held responsible for any DDoS complaints.
- wget -w 2 --content-disposition --load-cookies ${__dir}/cookiejar.txt "https://randopitons.re/randonnee/${nbr}/trace/${MAPTYPE}"
- done
- cd ..
- done <$1
+ while read linefromfile; do
+ mkdir -p ${__dir}/randopfiles/"${linefromfile}"
+ cd ${__dir}/randopfiles/"${linefromfile}"
+ WEBREGION=$(echo ${linefromfile} | sed 's/ de /\-/g' | tr '[:upper:]' '[:lower:]')
+ FILENBRS=$(wget -qO- https://randopitons.re/randonnees/region/${WEBREGION} | grep "<tr rid" | cut -d \" -f2)
+ for nbr in $FILENBRS; do
+ wget -w 3 --content-disposition --load-cookies ${__dir}/cookiejar.txt "https://randopitons.re/randonnee/${nbr}/trace/${MAPTYPE}"
+ done
+ cd ..
+ done <$1
}
_help()
@@ -45,8 +50,8 @@ _help()
_credentials()
{
- echo -e "\nYour username is $RDPUSER. (You can press CTRL+C to cancel the script if this info is incorrect)."
- echo -e "\nPassword (for randopitons.re): "
+ printf "\nYour username is $RDPUSER. (You can press CTRL+C to cancel the script if this info is incorrect)."
+ printf "\nPassword (for randopitons.re): "
read -s RDPUSERPASS
}
@@ -65,31 +70,6 @@ _logincheck()
fi
}
-_crearegfile()
-{
- echo "Region file doesn't exist or has been modified, we will (re)create it."
- echo -e "Cirque de Cilaos\nCirque de Mafate\nCirque de Salazie\nEst\nNord\nOuest\nSud\nVolcan\nAilleurs\nAll">$REGIONFILE
-}
-
-
-MAPTYPE="gpx"
-RDPUSER=
-RDPUSERPASS=
-LOGINOK=
-
-#Filechecks
-echo -e "Cirque de Cilaos\nCirque de Mafate\nCirque de Salazie\nEst\nNord\nOuest\nSud\nVolcan\nAilleurs\nAll">/tmp/regions.txt
-_ORIGREGIONMD5=$(md5sum /tmp/regions.txt)
-_CURRENTREGIONMD5=$(md5sum $REGIONFILE)
-echo $_ORIGREGIONMD5 > /tmp/regionshash.txt
-if [ -s $REGIONFILE ];then
- echo "Region file is already there. OK"
-elif [ "$_CURRENTREGIONMD5" != "$_ORIGREGIONMD5" ];then
- _crearegfile
-else
- _crearegfile
-fi
-
if [ "$1" = "" ];then
_help
@@ -110,45 +90,48 @@ while [ "$1" != "" ]; do
MAPTYPE="$1"
while [ $MAPTYPE != "gpx" -a $MAPTYPE != "trk" -a $MAPTYPE != "kml" ]
do
- echo -e "\nMaptype supplied is not correct"
- echo -e "Which map filetype you want to set : gpx(default),trk or kml ?"
+ printf "\nMaptype supplied is not correct"
+ printf "Which map filetype you want to set : gpx(default),trk or kml ?"
read -N 3 MAPTYPE
done
- echo -e "\nThe $MAPTYPE maptype is a valid choice !"
+ printf "\nThe $MAPTYPE maptype is a valid choice !"
;;
-lr | --list-regions)
- echo -e "Here's a list:\n"
+ printf "Here's a list:\n"
cat $REGIONFILE
;;
-lm | --list-maptypes)
- echo "These are the valid maptypes:gpx\nkml\ntrk"
+ printf "These are the valid maptypes:\ngpx\nkml\ntrk"
;;
-r | --region )
shift
MATCHEDFILE="${__dir}/matched.txt"
grep -iE "$1" $REGIONFILE > $MATCHEDFILE
- if [ -s ];then
+
+ if [ -s $MATCHEDFILE ];then
echo "Nothing matched or you entered an empty value."
_help
fi
- echo -e "Your region choice was '$1'\n See what matched :"
+ printf "Your region choice was '$1'\nMatches are:\n"
cat $MATCHEDFILE
_download $MATCHEDFILE
;;
-a | --all )
- echo -e "\nThis will download all the hitchiking routes from all regions.\nIf no maptype is specified (with -mp or --maptype), it will default to .gpx filetype.\nPausing for 5 seconds before launching it."
- _download $REGIONFILE
+ printf "\nThis will download all the hitchiking routes from all
+ regions.\nIf no extension is specified (with -mp or --maptype), it will
+ default to gpx.\nPausing for 5 seconds before downloading..."
sleep 5
+ _download $REGIONFILE
;;
-em | --elevator-music )
echo "Initiating elevator music"
- mpv --no-audio --really-quiet https://www.youtube.com/watch?v=KfNXGY9O5VY || echo -e "\nmpv is not installed."
+ mpv --no-audio --really-quiet https://www.youtube.com/watch?v=KfNXGY9O5VY || printf "\nmpv is not installed."
;;
-h | --help )