aboutsummaryrefslogtreecommitdiff
path: root/randopitons.sh
blob: 2373fbd6befba1110c828e8114a556762a08e0e0 (plain) (blame)
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
#!/bin/bash
# ANSI color codes
RS="\e[0m"    # reset
HC="\e[1m"    # hicolor
UL="\e[4m"    # underline
BLNK='\e[5m'  #Blink (wtf)
INV="\e[7m"   # inverse background and foreground
FBLK="\e[30m" # foreground black
FRED="\e[31m" # foreground red
FGRN="\e[32m" # foreground green
FYEL="\e[33m" # foreground yellow
FBLE="\e[34m" # foreground blue
FMAG="\e[35m" # foreground magenta
FCYN="\e[36m" # foreground cyan
FWHT="\e[37m" # foreground white
BBLK="\e[40m" # background black
BRED="\e[41m" # background red
BGRN="\e[42m" # background green
BYEL="\e[43m" # background yellow
BBLE="\e[44m" # background blue
BMAG="\e[45m" # background magenta
BCYN="\e[46m" # background cyan
BWHT="\e[47m" # background white
BLD="\e[1m" # BOLD text
# ANSI color codes

#https://stackoverflow.com/questions/4813092/how-to-read-entire-line-from-bash
#so we don't use a while loop
IFS=$'\n'

tellusage()
{
echo -e "${BLD}PURPOSE:${RS} With this script, you will be able to download gpx,trk and kml traces for hitchiking on the Reunion Isle.\n
${BLD}USAGE$RS: randopitons.sh -u \"username@mymail.com\" -mp maptype. You can supply the -a flag to the previous example to download all regions \n
${BLD}MAPTYPE FORMAT:$RS gpx, trk or kml"

}

credentials()
{
RDPUSER=$1
echo -e "\nYour username is $RDPUSER. (You can press CTRL+C if this info is incorrect."
echo -e "\nPassword (for randopitons.re): "
read -s RDPUSERPASS
}

if [ -s "./regions.txt" ];then
	echo "Region file is already there. OK"
else
	echo "Region file doesn't exist, we will create it."
	echo -e "Cirque de Cilaos\nCirque de Mafate\nCirque de Salazie\nEst\nNord\nOuest\nSud\nVolcan\nAilleurs\nAll">regions.txt
fi

if [ -s "./webregions.txt" ];then
	echo "Webegion file is already there. OK"
else
	echo "Webregion file doesn't exist, we will create it."
	echo -e "cirque-cilaos\ncirque-mafate\ncirque-salazie\nest\nnord\nouest\nsud\nvolcan\nailleurs">webregions.txt
fi

MAPTYPE="gpx"
RDPHOME=$HOME"/Randopitons"
RDPUSER=
RDPUSERPASS=

if [ "$1" = "" ];then
	tellusage
fi

while [ "$1" != "" ]; do

    case $1 in
        -u | --username )  
		shift
                credentials
                ;;

        -mp | --maptype )	
		shift
		MAPTYPE=$1cl
		while [ $MAPTYPE != "gpx" -a $MAPTYPE != "trk" -a $MAPTYPE != "kml" ]
		do	
			echo -e $BLNK$HC$BRED"${FYEL}\nMaptype supplied is not correct$RS"
			echo -e "Which map filetype you want to set : ${BLD}gpx(default),trk or kml ?$RS$RS$RS"
			read -N 3 MAPTYPE
		done
		echo -e $HC$FGRN"\nThe $MAPTYPE maptype is a valid choice !"$RS
		;;
	-r | --region )
		shift
		matching=`grep -iE "$1" regions.txt`
		webmatching=`grep -iE "$1" webregions.txt`
		if [ "$1" != "" ];then
			echo -e "Your region choice was '$1'\n See what matched :"
		else
			echo -e $HC$FCYN"$matching"$RS
		fi
		;;
	-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.\n${BLD}Pausing for 5 seconds before launching it.$RS"
		;;

#	-h | --help )           tellusage
#                               exit
#                               ;;
        * )                     tellusage
                                exit 1
    esac
    shift
done


# echo -e "\n purz"