From 8fb86d29d665da263a7dfefdcbe708c1be0c52c9 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 16 Nov 2020 22:45:17 +0100 Subject: Removed useless code, fix missing var - simplified the region file creation, no need for a gazillion line. - The -r switch was missing $MATCHEDFILE for its -s test - indenting --- randopitons.sh | 81 +++++++++++++++++++++++----------------------------------- 1 file 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 "$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 ) -- cgit v1.2.3-70-g09d2