diff --git a/.gitignore b/.gitignore
index 130847d..06053d2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
.my*
*~
-tmp/*
\ No newline at end of file
+tmp/*
+.idea
+.DS_Store
diff --git a/42MapGenerator.sh b/42MapGenerator.sh
index b7cb8a2..35d3494 100644
--- a/42MapGenerator.sh
+++ b/42MapGenerator.sh
@@ -1,11 +1,37 @@
#!/bin/bash
-####################################################################
-# jgigault @ student.42.fr 06 51 15 98 82 #
-####################################################################
+#####################################################
+# _ _ ____ __ __ ____ #
+# | || ||___ \| \/ | __ _ _ __ / ___| ___ _ __ #
+# | || |_ __) | |\/| |/ _` | '_ \| | _ / _ \ '_ \ #
+# |__ _/ __/| | | | (_| | |_) | |_| | __/ | | | #
+# |_||_____|_| |_|\__,_| .__/ \____|\___|_| |_| #
+# jgigault @ student.42.fr |_| 06 51 15 98 82 #
+#####################################################
+
+
+function mapgen_install_dir
+{
+ local SOURCE="${BASH_SOURCE[0]}"
+ local DIR
+ while [ -h "${SOURCE}" ]
+ do
+ DIR="$(cd -P "$(dirname "${SOURCE}")" && pwd)"
+ SOURCE="$(readlink "${SOURCE}")"
+ [[ "${SOURCE}" != /* ]] && SOURCE="${DIR}/${SOURCE}"
+ done
+ printf "%s" "$(cd -P "$(dirname "${SOURCE}")" && pwd)"
+}
+
+GLOBAL_ENTRYPATH=$(pwd)
+GLOBAL_INSTALLDIR=$(mapgen_install_dir)
+cd "${GLOBAL_INSTALLDIR}"
MAPGENERATOR_SH=1
RETURNPATH=$(pwd | sed 's/ /\ /g')
+CVERSION=$(git log --oneline 2>/dev/null | wc -l | sed 's/ //g')
+if [ "$CVERSION" == "" ]; then CVERSION="???"; fi
+
OPT_NO_UPDATE=0
OPT_NO_COLOR=0
OPT_NO_TIMEOUT=0
@@ -13,77 +39,73 @@ OPT_NO_TIMEOUT=0
i=1
while (( i <= $# ))
do
- if [ "${!i}" == "--no-update" ]
- then
- OPT_NO_UPDATE=1
- fi
- if [ "${!i}" == "--no-color" ]
- then
- OPT_NO_COLOR=1
- fi
- if [ "${!i}" == "--no-timeout" ]
- then
- OPT_NO_TIMEOUT=1
- fi
- (( i += 1 ))
+ case "${!i}" in
+ "--no-update") OPT_NO_UPDATE=1 ;;
+ "--no-color") OPT_NO_COLOR=1 ;;
+ "--no-timeout") OPT_NO_TIMEOUT=1 ;;
+ esac
+ (( i += 1 ))
done
+source includes/maps.sh
+source includes/data_providers.sh
source includes/utils.sh
-source includes/map.sh
-source includes/update.sh
-source includes/credits.sh
+source includes/display_menu.sh
+source includes/display_header.sh
+source includes/display_center.sh
+source includes/display_section.sh
+source includes/display_error.sh
+source includes/display_success.sh
+source includes/display_right.sh
+source includes/display_spinner.sh
+source includes/generate_map.sh
+source includes/download_map.sh
+source includes/google_api.sh
+source includes/ign.sh
+source includes/noaa.sh
+source includes/mgds.sh
source includes/config.sh
-source includes/custom.sh
+source includes/credits.sh
+source includes/update.sh
+
function main
{
- tput civis
- display_header
- display_menu\
- ""\
- gen_custom "find your own country with the Google Geocoding API"\
- main_ign "preset regions: IGN's data (France and Overseas)"\
- main_noaa "preset regions: NOAA's data (World)"\
- display_credits "CREDITS"\
- "open https://github.com/jgigault/42MapGenerator/issues/new" "REPORT A BUG"\
- exit_generator "EXIT"
+ local RETURNFUNCTION="main" DATA_PROVIDER_ID="" MAPS_ID="" MAPS_FORMAT="" MY_EXPORT_PATH=$(utils_get_config "export_path")
+ if [ "${MY_EXPORT_PATH}" == "" ]
+ then
+ config_path
+ else
+ display_header
+ display_section
+ display_menu\
+ "" "Select a data provider:"\
+ main_ign "${DATA_PROVIDERS[$(utils_data_provider_id "IGN")]}"\
+ main_noaa "${DATA_PROVIDERS[$(utils_data_provider_id "NOAA")]}"\
+ main_mgds "${DATA_PROVIDERS[$(utils_data_provider_id "MGDS")]}"\
+ "_"\
+ "config_path" "Change export directory"\
+ "_"\
+ "utils_option_set OPT_NO_TIMEOUT" "$(if [ "$OPT_NO_TIMEOUT" == 0 ]; then echo "Disable timeout (--no-timeout)"; else echo "Enable timeout"; fi)"\
+ "utils_option_set OPT_NO_COLOR" "$(if [ "$OPT_NO_COLOR" == 0 ]; then echo "Disable color (--no-color)"; else echo "Enable color"; fi)"\
+ "_"\
+ display_credits "CREDITS"\
+ "open https://github.com/jgigault/42MapGenerator/issues/new" "REPORT A BUG"\
+ utils_exit "EXIT"
+ fi
}
-function main_ign
-{
- display_header
- display_menu\
- ""\
- "gen_map 0" "France Métropolitaine"\
- "gen_map 1" "DOM TOM: Guadeloupe"\
- "gen_map 2" "DOM TOM: Martinique"\
- "gen_map 3" "DOM TOM: Réunion"\
- "gen_map 4" "DOM TOM: Guyane"\
- "gen_map 5" "DOM TOM: Saint Martin - Saint Barthélémy"\
- main "BACK TO MAIN MENU"
-}
+utils_set_env
+utils_set_colors
-function main_noaa
-{
- display_header
- display_menu\
- ""\
- "gen_map 8" "Amazonia"\
- "gen_map 14" "Australia"\
- "gen_map 13" "Cordillera de los Andes"\
- "gen_map 16" "Ethiopia"\
- "gen_map 6" "Europe"\
- "gen_map 12" "Great Britain & Ireland"\
- "gen_map 15" "Great Lakes (North America)"\
- "gen_map 9" "India & Himalaya"\
- "gen_map 11" "Italy"\
- "gen_map 10" "New Zealand"\
- "gen_map 7" "West Coast (North America)"\
- main "BACK TO MAIN MENU"
-}
+#if [ "$OPT_NO_UPDATE" == "0" ]
+#then
+ #update
+#fi
-if [ "$OPT_NO_UPDATE" == "0" ]
-then
- update
-fi
-main
\ No newline at end of file
+tput civis
+tput smcup
+utils_update
+tput rmcup
+tput cnorm
+cd "${GLOBAL_ENTRYPATH}"
\ No newline at end of file
diff --git a/README.md b/README.md
index 9284dbe..e29911c 100644
--- a/README.md
+++ b/README.md
@@ -1,40 +1,99 @@
-# 42MapGenerator
+# 42MapGenerator (v2)
-
42 Map Generator is a tiny bash script developed at 42 school for generating maps for FdF project whose data are extracted from IGN's and NOAA's servers.
+
42 Map Generator is a tiny bash script developed at 42 school for downloading and generating maps of the real world for the pedagogical project FdF.
-Choose a region and an export directory and let the script generate 5 maps of different accuracies (XXL is original data, XL, L, M and S).
+A map for the project FdF is a simple file based on the *ASCII Grid Format* whose headers were removed. The *ASCII Grid Format* is a good means of distributing raster image data files. It is widely supported and easy to import and export from most GIS softwares (Geographic Information System).
-Horizontal accuracy of the maps according to the data source:
-* IGN's data: up to 250 meters
-* NOAA's data: up to 1852 meters (1 arc-minute)
+The script 42 Map Generator allows you to find by name the coordinates of any country thanks to the *Google Geocoding API* and to reduce the exported file size by providing 5 different formats (XXL, XL, L, M, S).
+
+It extracts data from 3 different providers:
+* **IGN** (National Institute of Geographic and Forest Information / France), providing horizontal accuracy up to 250 meters of France and Overseas but excluding marine topography
+* **NOAA** (National Oceanic and Atmospheric Administration / USA), providing horizontal accuracy up to 1852 meters (1 arc-meter) of any region of the world but with a limited capacity of exported file size
+* **MGDS** (Marine Geoscience Data System / USA), providing an exceptional horizontal accuracy up to 100 meters of any region of the world, including marine topography but excluding some continental regions like Europe.
+
+At first, you're asked to select an export directory in which to save the computed FdF maps. Then select a data provider and an available region of the world. Finally, choose a mode of export of the marine's coordinates between flatten and keep data.
## install & launch
- git clone https://github.com/jgigault/42MapGenerator ~/42MapGenerator
- cd ~/42MapGenerator && sh ./42MapGenerator.sh
-## features
-* Choose a preset region
-* Find your own country with the Google Geocoding API
-* Generate random maps (in progress)
+```bash
+git clone https://github.com/jgigault/42MapGenerator ~/42MapGenerator
+cd ~/42MapGenerator && sh ./42MapGenerator.sh
+```
-## preset regions
-* France and Overseas
-* Europe, Italy, Great Britain & Ireland
-* Great Lakes, West Coast (North America)
-* Amazonia, Cordillera de los Andes
-* Himalaya & India
-* Ethiopia
-* Australia, New Zealand
+You may also want to set an alias to run it from everywhere, even in your project path. Add this line of code at the end of your shell initialization file (e.g.: ~/.zshrc):
+
+```bash
+alias 42MapGenerator='sh ~/42MapGenerator/42MapGenerator.sh'
+```
## options
- --no-update // Do not check for updates at launch
- --no-color // Do not display color tags
- --no-timeout // Disable time-out child process
-## preview
+```
+--no-update // Do not check for updates at launch
+--no-color // Do not display color tags
+--no-timeout // Disable time-out for child processes
+```
+
+Add your options as arguments at launch:
+
+```bash
+sh ./42MapGenerator --no-update --no-timeout
+```
+
+## preset regions
+
+
+##### IGN
+
+* France Métropolitaine
+* DOM-TOM: Guadeloupe
+* DOM-TOM: Martinique
+* DOM-TOM: Réunion
+* DOM-TOM: Guyane
+* DOM-TOM: Saint Martin - Saint Barthélémy
+
+##### NOAA / MGDS
+
+* Whole world *(MGDS only)*
+* Antarctic *(MGDS only)*
+* Arctic *(MGDS only)*
+* Europe *(NOAA only)*
+* Alaska-Aleutians
+* Cascade Range (West Coast USA)
+* Central America
+* East African Rift System
+* Eastern North American Margin
+* Gulf of California
+* Amazonia
+* Cordillera de los Andes
+* Izu-Bonin-Marinia
+* Nankai
+* New Zealand
+* Papua New Guinea
+* Red Sea
+* Himalaya
+* Mid-Ocean Ridges: EPR 8-11 N
+* Mid-Ocean Ridges: JdF Endeavour
+* Mid-Ocean Ridges: Lau Basin
+
+## previews
+



## credits
-* BD ALTI® - IGN (http://professionnels.ign.fr/bdalti)
-* ETOPO1 - NGDC Grid Extraction Tool - NOAA (http://maps.ngdc.noaa.gov/viewers/wcs-client/)
-* Google Geocoding API (https://developers.google.com/maps/documentation/geocoding/)
\ No newline at end of file
+
+* **MNT BD Alti®**
+ IGN National Institute of Geographic and Forest Information / France
+ http://professionnels.ign.fr/bdalti
+
+* **NGDC Grid Extraction Tool**
+ NOAA National Oceanic and Atmospheric Administration / USA
+ http://maps.ngdc.noaa.gov/viewers/wcs-client
+
+* **GMRT Map Tool**
+ MGDS Marine Geoscience Data System / USA
+ Ryan, W.B.F., S.M. Carbotte, J.O. Coplan, S. O'Hara, A. Melkonian, R. Arko, R.A. Weissel, V. Ferrini, A. Goodwillie, F. Nitsche, J. Bonczkowski, and R. Zemsky (2009), Global Multi-Resolution Topography synthesis, Geochem. Geophys. Geosyst., 10, Q03014, doi: 10.1029/2008GC002332
+ http://www.marine-geo.org/tools/GMRTMapTool/
+
+* **Google Geocoding API**
+ https://developers.google.com/maps/documentation/geocoding/le
\ No newline at end of file
diff --git a/includes/config.sh b/includes/config.sh
index 773eba7..504ef19 100644
--- a/includes/config.sh
+++ b/includes/config.sh
@@ -3,42 +3,100 @@
if [ "$MAPGENERATOR_SH" == "1" ]
then
- function config_path
- {
- local AB0 AB2 MYPATH
- MYPATH=$(get_config "export_path")
- display_header
- if [ "$MYPATH" != "" -a -d "$MYPATH" ]
- then
- printf $C_WHITE" Current export directory:\n"$C_CLEAR
- printf " "$MYPATH"\n\n"
- fi
- echo " Please type a directory to which to export the maps:"$C_WHITE
- cd "$HOME/"
- tput cnorm
- read -p " $HOME/" -e AB0
- tput civis
- AB0=`echo "$AB0" | sed 's/\/$//'`
- AB2="$HOME/$AB0"
- while [ "$AB0" == "" -o ! -d "$AB2" ]
- do
- display_header
- echo " Please type a directory to which to export the maps:"$C_WHITE
- if [ "$AB0" != "" ]
- then
- echo $C_RED" $AB2: No such file or directory"$C_CLEAR$C_WHITE
- else
- printf $C_WHITE
- fi
- tput cnorm
- read -p " $HOME/" -e AB0
- tput civis
- AB0=`echo "$AB0" | sed 's/\/$//'`
- AB2="$HOME/$AB0"
- done
- cd "$RETURNPATH"
- save_config "export_path" "$AB2"
- printf $C_CLEAR""
- }
+ function config_path
+ {
+ local STARTDIR
+ display_header
+ display_section
+ if [ "${MY_EXPORT_PATH}" == "" ]
+ then
+ display_error "Welcome! You must specify an export directory at first"
+ printf "\n"
+ fi
+ display_menu\
+ "" "Select a location where to find an export directory:"\
+ "config_path_select HOME" "Home directory: ~/"\
+ "config_path_select TMP" "Temporary directory: /tmp"\
+ "config_path_select ROOT" "Root folder: /"\
+ "_"\
+ "config_path_select" "CANCEL"
+ display_header
+ display_section
+ if [ "${STARTDIR}" != "*" ]
+ then
+ check_configure_read
+ eval "${RETURNFUNCTION}"
+ else
+ eval "${RETURNFUNCTION}"
+ fi
+ }
+
+ function config_path_select
+ {
+ case "$1" in
+ 'TMP')
+ STARTDIR="/tmp"
+ ;;
+ 'HOME')
+ STARTDIR="${HOME}"
+ ;;
+ 'ROOT')
+ STARTDIR=""
+ ;;
+ *)
+ STARTDIR="*"
+ ;;
+ esac
+ }
+
+ function check_configure_read
+ {
+ local AB0 AB2
+ printf " Find an export directory by using the shell prompt and then press ENTER:\n -> Use TAB to see what's inside the directories\n -> Keep empty and press ENTER to cancel\n\n${C_INVERTGREY}"
+ cd "${STARTDIR}/"
+ printf "${C_WHITE}"
+ tput cnorm
+ read -p " $(echo "${STARTDIR}" | sed "s/^$(echo "${HOME}" | sed 's/\//\\\//g')/~/")/" -e AB0
+ tput civis
+ if [ "${AB0}" == "" ]
+ then
+ cd "${RETURNPATH}"
+ STARTDIR="*"
+ return
+ else
+ AB0=`echo "${AB0}" | sed 's/\/$//'`
+ AB2="${STARTDIR}/${AB0}"
+ while [ "${AB0}" == "" -o ! -d "${AB2}" ]
+ do
+ display_header
+ display_section
+ printf " Find an export directory by using the shell prompt and then press ENTER:\n -> Use TAB to see what's inside the directories\n -> Keep empty and press ENTER to cancel\n\n"$C_INVERTGREY
+ printf "${C_WHITE}"
+ if [ "$AB0" != "" ]
+ then
+ display_error "${AB2}: No such file or directory"
+ else
+ printf "${C_WHITE}"
+ fi
+ tput cnorm
+ read -p " $(echo "${STARTDIR}" | sed "s/^$(echo "${HOME}" | sed 's/\//\\\//g')/~/")" -e AB0
+ tput civis
+ if [ "$AB0" == "" ]
+ then
+ cd "${RETURNPATH}"
+ STARTDIR="*"
+ return
+ fi
+ AB0=`echo "${AB0}" | sed 's/\/$//'`
+ AB2="${STARTDIR}/${AB0}"
+ done
+ cd "${RETURNPATH}"
+ utils_save_config "export_path" "${AB2}"
+ printf "${C_CLEAR}"
+ return
+ fi
+
+ }
+
fi;
\ No newline at end of file
diff --git a/includes/credits.sh b/includes/credits.sh
index e44076f..c78cc52 100644
--- a/includes/credits.sh
+++ b/includes/credits.sh
@@ -1,25 +1,35 @@
#!/bin/bash
-if [ "$MAPGENERATOR_SH" == "1" ]
+if [ "${MAPGENERATOR_SH}" == "1" ]
then
- function display_credits
- {
- local SEL
- clear
- display_header
- display_righttitle ""
- printf " 42MapGenerator is a tiny bash script developped at 42 school for downloading and generating maps for FdF project.\n\n"
- printf " The script has the following dependencies:\n\n"
- printf " -> "$C_WHITE"MNT BD Alti® - IGN\n"$C_CLEAR
- printf " http://professionnels.ign.fr/bdalti\n\n"
- printf " -> "$C_WHITE"ETOPO1 - NGDC Grid Extraction Tool - NOAA\n"$C_CLEAR
- printf " http://maps.ngdc.noaa.gov/viewers/wcs-client\n\n"
- printf " -> "$C_WHITE"Google Geocoding API\n"$C_CLEAR
- printf " https://developers.google.com/maps/documentation/geocoding/\n\n"
- printf "\n Press ENTER to continue..."
- read -s SEL
- main
- }
+ function display_credits
+ {
+ local SEL
+ clear
+ display_header
+ display_righttitle ""
+ printf " 42MapGenerator is a tiny bash script developped at 42 school for downloading and generating maps of the real world for the pedagogic project FdF.\n\n"
+ printf " It contains the following credits:\n\n"
+ printf " -> ${C_WHITE}MNT BD Alti®\n"
+ printf " IGN National Institute of Geographic and Forest Information / France\n${C_CLEAR}"
+ printf " http://professionnels.ign.fr/bdalti\n\n"
+ printf " -> ${C_WHITE}NGDC Grid Extraction Tool\n"
+ printf " NOAA National Oceanic and Atmospheric Administration / USA\n${C_CLEAR}"
+ printf " http://maps.ngdc.noaa.gov/viewers/wcs-client\n\n"
+ printf " -> ${C_WHITE}GMRT Map Tool\n"
+ printf " MGDS Marine Geoscience Data System / USA\n${C_CLEAR}"
+ printf " Ryan, W.B.F., S.M. Carbotte, J.O. Coplan, S. O'Hara,\n"
+ printf " A. Melkonian, R. Arko, R.A. Weissel, V. Ferrini, A. Goodwillie,\n"
+ printf " F. Nitsche, J. Bonczkowski, and R. Zemsky (2009),\n"
+ printf " Global Multi-Resolution Topography synthesis, Geochem. Geophys. Geosyst.,\n"
+ printf " 10, Q03014, doi: 10.1029/2008GC002332\n"
+ printf " http://www.marine-geo.org/tools/GMRTMapTool/\n\n"
+ printf " -> ${C_WHITE}Google Geocoding API\n${C_CLEAR}"
+ printf " https://developers.google.com/maps/documentation/geocoding/\n\n"
+ printf "\n Press ENTER to continue..."
+ read -s SEL
+ main
+ }
-fi;
\ No newline at end of file
+fi
diff --git a/includes/custom.sh b/includes/custom.sh
deleted file mode 100644
index dbf2135..0000000
--- a/includes/custom.sh
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/bin/bash
-if [ "$MAPGENERATOR_SH" == "1" ]
-then
-
- declare API_KEY="AIzaSyAO_R8YeQL6Zgl1d-E_H3Y9h3ZF_yZ9meI"
- declare STATUS=$(cat ".mycustomSTATUS")
-
- function gen_custom
- {
- local LAT0 LNG0 LAT1 LNG1 TITLE RET0 JSON0 MSG
- LAT0=$(cat ".mycustomLAT0")
- LAT1=$(cat ".mycustomLAT1")
- LNG0=$(cat ".mycustomLNG0")
- LNG1=$(cat ".mycustomLNG1")
- TITLE=$(cat ".mycustomTITLE")
- display_header
- gen_custom_header
- if [ "$STATUS" == "OK" ]
- then
- gen_custom_header_config
- display_menu\
- ""\
- gen_map_custom "generate map"\
- gen_custom_config "find other coordinates by country name"\
- main "BACK TO MAIN MENU"
- else
- if [ "$STATUS" != "" ]
- then
- case "$STATUS" in
- "ZERO_RESULTS")
- MSG="Your query returned no results"
- ;;
- "OVER_QUERY_LIMIT")
- MSG="The daily quota of 2500 queries was reached"
- ;;
- "REQUEST_DENIED")
- MSG="Request denied"
- ;;
- "INVALID_REQUEST")
- MSG="Your request is invalid"
- ;;
- "UNKNOWN_ERROR")
- MSG="An error occured (unknown error)"
- ;;
- esac
- printf $C_RED" $MSG\n\n"$C_CLEAR
- fi
- display_menu\
- ""\
- gen_custom_config "find coordinates by country name"\
- main "BACK TO MAIN MENU"
- fi
- }
-
- function gen_custom_config
- {
- local RET0 JSON0 JSON1 TITLE2 SHORTTITLE
- STATUS=""
- TITLE=""
- save_config customTITLE ""
- save_config customSTATUS ""
- while [ "$TITLE" == "" ]
- do
- display_header
- gen_custom_header
- tput cnorm
- printf $C_WHITE""
- read -p " Type a country name (e.g. Spain): " -e TITLE
- printf $C_CLEAR""
- tput civis
- if [ "$TITLE" != "" ]
- then
- TITLE2=`echo "$TITLE" | sed 's/ /+/g'`
- display_header
- gen_custom_header
- printf $C_BLUE" Looking for coordinates...\n"
- sleep 0.3
- (curl -s "https://maps.googleapis.com/maps/api/geocode/json?components=country:$TITLE2&key=$API_KEY" > .myret 2>&1) &
- display_spinner $!
- JSON0=`cat .myret | sed 's/[" ,]//g'`
- STATUS=`echo "$JSON0" | grep "status" | cut -d: -f2 | sed 's/[ \t]*//g'`
- if [ "$STATUS" == "OK" ]
- then
- TITLE=`cat .myret | sed 's/[",]//g' | grep "formatted_address" | cut -d":" -f2 | sed 's/^[ ]*//g' | sed 's/[ ]*$//g'`
- JSON1=`echo "$JSON0" | awk 'BEGIN {OFS=""; VIEWPORT=0; NORTHEAST=0; SOUTHWEST=0 } $0 ~ /viewport/ {VIEWPORT=1} $0 ~ /northeast/ {if (VIEWPORT==1 && NORTHEAST==0) { NORTHEAST=1 }} $0 ~ /lat/ {if (NORTHEAST>0) {printf "NE" $0 "\n"; NORTHEAST+=1}} $0 ~ /lng/ {if (NORTHEAST>0) {printf "NE" $0 "\n"; NORTHEAST+=1}} $0 ~ /southwest/ {if (VIEWPORT==1 && SOUTHWEST==0) { SOUTHWEST=1 }} $0 ~ /lat/ {if (SOUTHWEST>0) {printf "SW" $0 "\n"; SOUTHWEST+=1}} $0 ~ /lng/ {if (SOUTHWEST>0) {printf "SW" $0 "\n"; SOUTHWEST+=1}} {if (NORTHEAST==3) {NORTHEAST=-1} if(SOUTHWEST==3) {SOUTHWEST=-1}}'`
- echo "$JSON1" | grep "SWlng" | cut -d":" -f2 > .mycustomLNG0
- echo "$JSON1" | grep "NElng" | cut -d":" -f2 > .mycustomLNG1
- echo "$JSON1" | grep "SWlat" | cut -d":" -f2 > .mycustomLAT0
- echo "$JSON1" | grep "NElat" | cut -d":" -f2 > .mycustomLAT1
- echo "$TITLE" > .mycustomTITLE
- fi
- printf $C_CLEAR""
- fi
- done
- save_config customSTATUS "$STATUS"
- gen_custom
- }
-
- function gen_map_custom
- {
- local FNAME
- FNAME=`echo "$TITLE" | sed 's/[^0-9a-zA-Z]/_/g'`
- gen_map_cp "CUSTOM_$FNAME" "http://mapserver.ngdc.noaa.gov/cgi-bin/public/wcs/etopo1.asc?filename=CUSTOM_$FNAME.asc&request=getcoverage&version=1.0.0&service=wcs&coverage=etopo1&CRS=EPSG:4326&format=aaigrid&resx=0.016666666666666667&resy=0.016666666666666667&bbox=$LNG0,$LAT0,$LNG1,$LAT1" "CUSTOM_$FNAME" "noaa" "$TITLE"
-
- }
-
- function gen_custom_header
- {
- printf $C_GREY""
- display_center "Customized coordinates"
- printf "\n"$C_CLEAR
- }
-
- function gen_custom_header_config
- {
- printf $C_WHITE" Current configuration:\n\n"$C_CLEAR
- printf " NorthWest:\tlat: $C_WHITE$LAT0$C_CLEAR\n"
- printf " \tlng: $C_WHITE$LNG0$C_CLEAR\n\n"
- printf " SouthEast:\tlat: $C_WHITE$LAT1$C_CLEAR\n"
- printf " \tlng: $C_WHITE$LNG1$C_CLEAR\n\n"
- printf " Title: \t$C_WHITE$TITLE$C_CLEAR\n"
- printf "\n"
-
- }
-
-fi;
\ No newline at end of file
diff --git a/includes/data_providers.sh b/includes/data_providers.sh
new file mode 100644
index 0000000..d6f01eb
--- /dev/null
+++ b/includes/data_providers.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ declare -a DATA_PROVIDERS
+ declare -i DATA_PROVIDERS_SHIFT=5
+
+ DATA_PROVIDERS[${#DATA_PROVIDERS[*]}]="IGN (National Institute of Geographic and Forest Information / France)"
+ DATA_PROVIDERS[${#DATA_PROVIDERS[*]}]="Horizontal accuracy up to 250 meters"
+ DATA_PROVIDERS[${#DATA_PROVIDERS[*]}]="http://professionnels.ign.fr/sites/default/files/"
+ DATA_PROVIDERS[${#DATA_PROVIDERS[*]}]="ocean_topography_unavailable"
+ DATA_PROVIDERS[${#DATA_PROVIDERS[*]}]="IGN"
+
+ DATA_PROVIDERS[${#DATA_PROVIDERS[*]}]="NOAA (National Oceanic and Atmospheric Administration / USA)"
+ DATA_PROVIDERS[${#DATA_PROVIDERS[*]}]="Horizontal accuracy up to 1852 meters"
+ DATA_PROVIDERS[${#DATA_PROVIDERS[*]}]="http://mapserver.ngdc.noaa.gov/cgi-bin/public/wcs/etopo1.asc?request=getcoverage&version=1.0.0&service=wcs&coverage=etopo1&CRS=EPSG:4326&format=aaigrid&resx=0.016666666666666667&resy=0.016666666666666667&bbox=MAPGEN_MAPBOX&filename=tmp.asc"
+ DATA_PROVIDERS[${#DATA_PROVIDERS[*]}]="ocean_topography_available"
+ DATA_PROVIDERS[${#DATA_PROVIDERS[*]}]="NOAA"
+
+ DATA_PROVIDERS[${#DATA_PROVIDERS[*]}]="MGDS (Marine Geoscience Data System / USA)"
+ DATA_PROVIDERS[${#DATA_PROVIDERS[*]}]="Horizontal accuracy up to 100 meters"
+ DATA_PROVIDERS[${#DATA_PROVIDERS[*]}]="http://www.marine-geo.org/services/GridServer?minlongitude=MAPGEN_WEST&maxlongitude=MAPGEN_EAST&minlatitude=MAPGEN_SOUTH&maxlatitude=MAPGEN_NORTH&format=esriascii&layer=topo&resolution=high"
+ DATA_PROVIDERS[${#DATA_PROVIDERS[*]}]="ocean_topography_available"
+ DATA_PROVIDERS[${#DATA_PROVIDERS[*]}]="MGDS"
+
+ function utils_data_provider_id
+ {
+ case $1 in
+ "IGN") printf "0" ;;
+ "NOAA") printf "$((1 * ${DATA_PROVIDERS_SHIFT}))" ;;
+ "MGDS") printf "$((2 * ${DATA_PROVIDERS_SHIFT}))" ;;
+ esac
+ }
+
+ function utils_data_provider_get_url
+ {
+ printf "%s" "${DATA_PROVIDERS[$(($1 + 2))]}"
+ }
+
+ function utils_data_provider_get_abbr
+ {
+ printf "%s" "${DATA_PROVIDERS[$(($1 + 4))]}"
+ }
+
+fi
diff --git a/includes/display_center.sh b/includes/display_center.sh
new file mode 100644
index 0000000..e90b11f
--- /dev/null
+++ b/includes/display_center.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ function display_center
+ {
+ local LEN MARGIN
+ if [ "$1" != "" ]
+ then
+ LEN=${#1}
+ (( MARGIN= (${COLUMNS} - ${LEN}) / 2 ))
+ printf "%"${MARGIN}"s" " "
+ printf "$1"
+ (( MARGIN= ${MARGIN} + (${COLUMNS} - ${LEN} - ${MARGIN} * 2) ))
+ printf "%"${MARGIN}"s" " "
+ else
+ printf "\n"
+ fi
+ }
+
+fi
diff --git a/includes/display_error.sh b/includes/display_error.sh
new file mode 100644
index 0000000..0a519db
--- /dev/null
+++ b/includes/display_error.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ function display_error
+ {
+ printf "${C_RED} %s${C_CLEAR}\n" "$1"
+ }
+
+fi
diff --git a/includes/display_header.sh b/includes/display_header.sh
new file mode 100644
index 0000000..f432e97
--- /dev/null
+++ b/includes/display_header.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ function display_header
+ {
+ local MARGIN
+ utils_clear
+ utils_set_env
+ if [ "$1" != "" ]
+ then
+ printf "$1"
+ else
+ printf ${C_INVERT}""
+ fi
+ display_righttitle "PRESS ESCAPE TO EXIT - V2.r${CVERSION}"
+ display_center " _ _ ____ __ __ ____ "
+ display_center " | || ||___ \| \/ | __ _ _ __ / ___| ___ _ __ "
+ display_center " | || |_ __) | |\/| |/ _\ | '_ \| | _ / _ \ '_ \ "
+ display_center " |__ _/ __/| | | | (_| | |_) | |_| | __/ | | | "
+ display_center " |_||_____|_| |_|\__,_| .__/ \____|\___|_| |_| "
+ display_center " jgigault @ student.42.fr |_| 06 51 15 98 82 "
+ display_center " "
+ printf "${C_CLEAR}\n\n"
+ }
+
+fi
diff --git a/includes/display_menu.sh b/includes/display_menu.sh
new file mode 100644
index 0000000..c29db18
--- /dev/null
+++ b/includes/display_menu.sh
@@ -0,0 +1,167 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ function display_menu
+ {
+ local -a MENU FUNCS
+ local TOTAL SEL LEN SELN TITLE i MAPSA
+ SEL=""
+ if [ "$1" != "" ]
+ then
+ printf $1
+ else
+ printf "${C_INVERT}"
+ fi
+ shift 1
+ TITLE="$1"
+ if [ "${TITLE}" != "" ]
+ then
+ printf "%${COLUMNS}s" " "
+ printf "\n"
+ (( LEN=${COLUMNS} - ${#TITLE} - 3 ))
+ printf " ${TITLE} "
+ printf "%"$LEN"s\n" " "
+ fi
+ printf "%${COLUMNS}s\n" " "
+ shift 1
+ while (( $# > 0 ))
+ do
+ if [ "$1" == "_" ]
+ then
+ printf "%${COLUMNS}s" " "
+ printf "\n"
+ shift 1
+ else
+ if [ "$1" == "MAPS" ]
+ then
+ i=0
+ MAPSA="$2[${i}]"
+ while [ ! -z "${!MAPSA}" ]
+ do
+ (( TOTAL += 1 ))
+ FUNCS[$TOTAL]="$3 $((${MAPSA} * ${MAPS_SHIFT}))"
+ MENU[$TOTAL]="${!MAPSA}"
+ TITLE=`echo "${MAPS[$((${MAPSA} * ${MAPS_SHIFT}))]}" | sed 's/%/%%/g'`
+ if (( $TOTAL < 10 ))
+ then
+ SELN=${TOTAL}
+ else
+ (( SELN=65 + ${TOTAL} - 10 ))
+ SELN=`echo "${SELN}" | awk '{printf("%c", $0)}'`
+ fi
+ (( LEN=${COLUMNS} - ${#TITLE} - 9 ))
+ printf " ${SELN}) ${TITLE} "
+ printf "%${LEN}s" " "
+ printf "\n"
+ (( i++ ))
+ MAPSA="$2[${i}]"
+ done
+ shift 3
+ else
+ (( TOTAL += 1 ))
+ FUNCS[$TOTAL]="$1"
+ MENU[$TOTAL]="$2"
+ TITLE=`echo "$2" | sed 's/%/%%/g'`
+ if (( $TOTAL < 10 ))
+ then
+ SELN=$TOTAL
+ else
+ (( SELN=65 + $TOTAL - 10 ))
+ SELN=`echo "$SELN" | awk '{printf("%c", $0)}'`
+ fi
+ (( LEN=$COLUMNS - ${#TITLE} - 9 ))
+ printf " "$SELN") $TITLE "
+ printf "%"$LEN"s" " "
+ printf "\n"
+ shift 2
+ fi
+ fi
+ done
+
+ printf "%"$COLUMNS"s" " "
+ printf ${C_CLEAR}""
+ read -r -s -n 1 SEL
+ SEL=$(display_menu_get_key $SEL)
+ if [ "$SEL" == "ESC" ]
+ then
+ utils_exit
+ fi
+ SEL=`display_menu_atoi "$SEL"`
+ while [ -z "${MENU[$SEL]}" -o "$(echo "${FUNCS[$SEL]}" | grep '^open ')" != "" ]
+ do
+ printf "\a"
+ if [ "$(echo "${FUNCS[$SEL]}" | grep '^open ')" != "" ]
+ then
+ if [ -f "$(echo "${FUNCS[$SEL]}" | sed 's/^open //')" -o -d "$(echo "${FUNCS[$SEL]}" | sed 's/^open //')" -o "$(echo "${FUNCS[$SEL]}" | grep http)" != "" ]
+ then
+ eval ${FUNCS[$SEL]}
+ fi
+ fi
+ SEL=""
+ read -s -n 1 SEL
+ SEL=$(display_menu_get_key $SEL)
+ if [ "$SEL" == "ESC" ]
+ then
+ utils_exit
+ fi
+ SEL=`display_menu_atoi "$SEL"`
+ done
+ printf "\n"
+ if [ "${FUNCS[$SEL]}" != "" ]
+ then
+ eval ${FUNCS[$SEL]}
+ fi
+ }
+
+ function display_menu_get_key
+ {
+ local ord_value old_tty_settings key
+ ord_value=$(printf '%d' "'$1")
+ if [[ ${ord_value} -eq 27 ]]; then
+ old_tty_settings=`stty -g`
+ stty -icanon min 0 time 0
+ read -s key
+ if [[ ${#key} -eq 0 ]]
+ then
+ printf "ESC"
+ else
+ printf "NULL"
+ fi
+ stty "${old_tty_settings}"
+ else
+ printf "%s" "$1"
+ fi
+ }
+
+ function display_menu_atoi
+ {
+ local SELN
+ if [ "$1" == "NULL" ]
+ then
+ printf "0"
+ else
+ if [ "$1" != "1" -a "$1" != "2" -a "$1" != "3" -a "$1" != "4" -a "$1" != "5" -a "$1" != "6" -a "$1" != "7" -a "$1" != "8" -a "$1" != "9" ]
+ then
+ SELN=`LC_CTYPE=C printf '%d' "'$1"`
+ if (( $SELN >= 65 )) && (( $SELN <= 90 ))
+ then
+ (( SELN=$SELN - 65 + 10 ))
+ printf "$SELN"
+ else
+ if (( $SELN >= 97 )) && (( $SELN <= 122 ))
+ then
+ (( SELN=$SELN - 97 + 10 ))
+ printf "$SELN"
+ else
+ printf "0"
+ fi
+ fi
+ else
+ printf "$1"
+ fi
+ fi
+ }
+
+fi
diff --git a/includes/display_right.sh b/includes/display_right.sh
new file mode 100644
index 0000000..750f19e
--- /dev/null
+++ b/includes/display_right.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ function display_righttitle
+ {
+ local LEN MARGIN
+ if [ "$1" != "" ]
+ then
+ LEN=${#1}
+ (( MARGIN= $COLUMNS - $LEN))
+ printf "%"$MARGIN"s" " "
+ printf "$1\n"
+ else
+ printf "\n"
+ fi
+ }
+
+fi
diff --git a/includes/display_section.sh b/includes/display_section.sh
new file mode 100644
index 0000000..e4ecb0c
--- /dev/null
+++ b/includes/display_section.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ function display_section
+ {
+ if [ "${MY_EXPORT_PATH}" != "" ]
+ then
+ printf "${C_GREY} Export directory: ${C_WHITE}$(echo "${MY_EXPORT_PATH}" | sed "s/^$(echo "${HOME}" | sed 's/\//\\\//g')/~/")\n"
+ if [ "${DATA_PROVIDER_ID}" != "" ]
+ then
+ printf "${C_GREY} Data provider: ${C_WHITE}${DATA_PROVIDERS[${DATA_PROVIDER_ID}]}\n"
+ if [ "${MAPS_ID}" != "" -a "$(utils_maps_get_name "${MAPS_ID}")" != "" ]
+ then
+ printf "${C_GREY} Region to export: ${C_WHITE}$(utils_maps_get_name "${MAPS_ID}")\n"
+ if [ "$(utils_maps_get_coor "NORTH" "${MAPS_ID}")" != "" ]
+ then
+ printf "${C_GREY} Coordinates: ${C_WHITE}North:$(utils_maps_get_coor "NORTH" "${MAPS_ID}") East:$(utils_maps_get_coor "EAST" "${MAPS_ID}") South:$(utils_maps_get_coor "SOUTH" "${MAPS_ID}") West:$(utils_maps_get_coor "WEST" "${MAPS_ID}")\n"
+ fi
+ if [ "${MAPS_FORMAT}" != "" ]
+ then
+ printf "${C_GREY} Format: ${C_WHITE}${MAPS_FORMAT}\n"
+ if [ "${OCEAN_TOPOGRAPHY}" != "" ]
+ then
+ case "${OCEAN_TOPOGRAPHY}" in
+ "unavailable")
+ printf "${C_GREY} Ocean topography: ${C_WHITE}Unavailable\n"; ;;
+ "yes")
+ printf "${C_GREY} Ocean topography: ${C_WHITE}Keep data\n"; ;;
+ "no")
+ printf "${C_GREY} Ocean topography: ${C_WHITE}Flatten ocean\n"; ;;
+ esac
+ if [ "${MY_EXPORT_PATH_FILENAME}" != "" ]
+ then
+ printf "${C_GREY} Export file: ${C_WHITE}${MY_EXPORT_PATH_FILENAME}\n"
+ fi
+ fi
+ fi
+ fi
+ fi
+ printf "${C_CLEAR}"
+ printf "\n"
+ fi
+ }
+
+fi
diff --git a/includes/display_spinner.sh b/includes/display_spinner.sh
new file mode 100644
index 0000000..4448256
--- /dev/null
+++ b/includes/display_spinner.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ function display_spinner
+ {
+ local pid=$1
+ local total_delay=0
+ local total_delay2=240
+ local delay=0.2
+ local spinstr='|/-\'
+ printf $C_BLUE""
+ while [ "$(ps a | awk '{print $1}' | grep $pid)" ];
+ do
+ if (( $total_delay2 < 1 ))
+ then
+ kill $pid
+ wait $! 2>/dev/null
+ (( total_delay2 = $total_delay / 5 ))
+ printf $C_RED" Time out ($total_delay2 sec)"$C_CLEAR > $RETURNPATH/.myret
+ fi
+ if [ "$OPT_NO_TIMEOUT" == "0" ]
+ then
+ (( total_delay += 1 ))
+ fi
+ local temp=${spinstr#?}
+ printf " [%c] " "$spinstr"
+ local spinstr=$temp${spinstr%"$temp"}
+ if (( $total_delay >= 5 ))
+ then
+ (( total_delay2 = ( 209 - $total_delay ) / 5 ))
+ printf "[time out: %02d]" "$total_delay2"
+ fi
+ sleep $delay
+ printf "\b\b\b\b\b\b"
+ if (( $total_delay >= 5 ))
+ then
+ printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
+ fi
+ done
+ printf " \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
+ printf $C_CLEAR""
+ }
+
+fi
diff --git a/includes/display_success.sh b/includes/display_success.sh
new file mode 100644
index 0000000..c455db8
--- /dev/null
+++ b/includes/display_success.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ function display_success
+ {
+ printf "${C_GREEN} %s\n" "$1"
+ }
+
+fi
diff --git a/includes/download_map.sh b/includes/download_map.sh
new file mode 100644
index 0000000..928f66d
--- /dev/null
+++ b/includes/download_map.sh
@@ -0,0 +1,150 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ function download_map_and_extract_zip
+ {
+ local TMPFILENAME="$(utils_data_provider_get_abbr "${DATA_PROVIDER_ID}")_${FILENAME}.txt"
+ if [ ! -f "${MAPS_TMPDIR}${TMPFILENAME}" ]
+ then
+ download_map "${TMPFILENAME}.zip" "$(utils_data_provider_get_url "${DATA_PROVIDER_ID}")${FILENAME}.zip" && extract_map "${TMPFILENAME}.zip" "${TMPFILENAME}" && check_headers "${TMPFILENAME}"
+ return "$?"
+ else
+ return 0
+ fi
+ }
+
+ function download_map_with_mapbox
+ {
+ local TMPFILENAME="$(utils_data_provider_get_abbr "${DATA_PROVIDER_ID}")_${FILENAME}.txt" URL_REQUEST="$(utils_data_provider_get_url "${DATA_PROVIDER_ID}")" NORTH=$(utils_maps_get_coor "NORTH" "${MAPS_ID}") EAST=$(utils_maps_get_coor "EAST" "${MAPS_ID}") SOUTH=$(utils_maps_get_coor "SOUTH" "${MAPS_ID}") WEST=$(utils_maps_get_coor "WEST" "${MAPS_ID}")
+ URL_REQUEST=${URL_REQUEST/MAPGEN_MAPBOX/"${WEST},${SOUTH},${EAST},${NORTH}"}
+ URL_REQUEST=${URL_REQUEST/MAPGEN_NORTH/${NORTH}}
+ URL_REQUEST=${URL_REQUEST/MAPGEN_EAST/${EAST}}
+ URL_REQUEST=${URL_REQUEST/MAPGEN_SOUTH/${SOUTH}}
+ URL_REQUEST=${URL_REQUEST/MAPGEN_WEST/${WEST}}
+ if [ ! -f "${MAPS_TMPDIR}${TMPFILENAME}" ]
+ then
+ download_map "${TMPFILENAME}" "${URL_REQUEST}" && check_headers "${TMPFILENAME}"
+ return "$?"
+ else
+ return 0
+ fi
+ }
+
+ function download_map
+ {
+ create_tmp_dir
+ display_header
+ display_section
+ printf "${C_BLUE} %s\n\n" "Downloading $1 from remote server..."
+ sleep 0.5
+ curl --show-error --output "${MAPS_TMPDIR}$1" "$2"
+ printf $C_CLEAR""
+ if [ ! -f "${MAPS_TMPDIR}$1" -o "$?" != "0" ]
+ then
+ display_header
+ display_section
+ display_error "An error occured while downloading file:"
+ display_error "$2"
+ printf "\n"
+ display_menu\
+ "" ""\
+ "${RETURNFUNCTION}" "OK"\
+ "_"\
+ "open https://github.com/jgigault/42MapGenerator/issues/new" "REPORT A BUG"\
+ "utils_exit" "EXIT"
+ return 1
+ else
+ printf "\n${C_BLUE} Completed!\n\n"
+ sleep 1
+ fi
+ return 0
+ }
+
+ function extract_map
+ {
+ local EXTRACTED_FILE EXTRACT_DIRECTORY="${MAPS_TMPDIR}extract/"
+ create_tmp_dir "extract/"
+ display_header
+ display_section
+ printf "${C_BLUE} %s\n\n" "Extracting map from archive..."
+ sleep 0.5
+ rm -rf "${EXTRACT_DIRECTORY}"
+ unzip -o -j -d "${EXTRACT_DIRECTORY}" "${MAPS_TMPDIR}$1" \*.[Aa][Ss][Cc]
+ if [ "$?" != "0" ]
+ then
+ display_header
+ display_section
+ display_error "An error occured while extracting file:"
+ display_error "${MAPS_TMPDIR}$1"
+ printf "\n"
+ display_menu\
+ "" ""\
+ "${RETURNFUNCTION}" "OK"\
+ "_"\
+ "open https://github.com/jgigault/42MapGenerator/issues/new" "REPORT A BUG"\
+ "utils_exit" "EXIT"
+ return 1
+ else
+ EXTRACTED_FILE=`find "${EXTRACT_DIRECTORY}/" -name \*.[Aa][Ss][Cc] | awk '{if(NR==1) {print}}'`
+ if [ "${EXTRACTED_FILE}" == "" ]
+ then
+ display_header
+ display_section
+ display_error "An error occured while extracting file:"
+ display_error "${MAPS_TMPDIR}$1"
+ printf "\n"
+ display_menu\
+ "" ""\
+ "${RETURNFUNCTION}" "OK"\
+ "_"\
+ "open https://github.com/jgigault/42MapGenerator/issues/new" "REPORT A BUG"\
+ "utils_exit" "EXIT"
+ return 1
+ else
+ mv "${EXTRACTED_FILE}" "${MAPS_TMPDIR}$2"
+ rm -rf "${MAPS_TMPDIR}extract/"
+ rm -f "${MAPS_TMPDIR}$1"
+ printf "\n${C_BLUE} Completed!\n\n"
+ sleep 1
+ fi
+ fi
+ return 0
+ }
+
+ function check_headers
+ {
+ local HEADER_NCOLS HEADER_NROWS
+ display_header
+ display_section
+ printf "${C_BLUE} %s\n\n" "Checking headers..."
+ sleep .3
+ HEADER_NCOLS="$(awk 'BEGIN{OFS=""; ORS=""} $1 == "ncols" {print $2/1; exit}' "${MAPS_TMPDIR}$1")"
+ HEADER_NROWS="$(awk 'BEGIN{OFS=""; ORS=""} $1 == "nrows" {print $2/1; exit}' "${MAPS_TMPDIR}$1")"
+ if [ "${HEADER_NCOLS}" == "" ]; then HEADER_NCOLS=0; fi
+ if [ "${HEADER_NROWS}" == "" ]; then HEADER_NROWS=0; fi
+ if [[ "${HEADER_NCOLS}" -le "0" || "${HEADER_NROWS}" -le "0" ]]
+ then
+ rm -f "${MAPS_TMPDIR}$1"
+ display_header
+ display_section
+ display_error "The file downloaded from the remote server is corrupted"
+ display_error "Maybe the requested region is too large or is not supported"
+ printf "\n"
+ display_menu\
+ "" ""\
+ "${RETURNFUNCTION}" "OK"\
+ "_"\
+ "open https://github.com/jgigault/42MapGenerator/issues/new" "REPORT A BUG"\
+ "utils_exit" "EXIT"
+ return 1
+ else
+ awk '{if(NF > 3) {print $0}}' "${MAPS_TMPDIR}$1" > "${MAPS_TMPDIR}$1.tmp"
+ rm -f "${MAPS_TMPDIR}$1"
+ mv "${MAPS_TMPDIR}$1.tmp" "${MAPS_TMPDIR}$1"
+ fi
+ return 0
+ }
+
+fi
diff --git a/includes/formats.sh b/includes/formats.sh
new file mode 100644
index 0000000..e69de29
diff --git a/includes/generate_map.sh b/includes/generate_map.sh
new file mode 100644
index 0000000..af4eb2a
--- /dev/null
+++ b/includes/generate_map.sh
@@ -0,0 +1,177 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ function display_menu_format
+ {
+ local FILENAME="$(utils_maps_get_filename "${MAPS_ID}")" PREVIEWLINK
+ if [ "$(utils_maps_get_coor "NORTH" "${MAPS_ID}")" != "" ]
+ then
+ PREVIEWLINK="http://www.marine-geo.org/tools/gmrt_image_1.php?maptool=1\&north=$(utils_maps_get_coor "NORTH" "${MAPS_ID}")\&west=$(utils_maps_get_coor "WEST" "${MAPS_ID}")\&east=$(utils_maps_get_coor "EAST" "${MAPS_ID}")\&south=$(utils_maps_get_coor "SOUTH" "${MAPS_ID}")\&mask=0"
+ display_menu\
+ "" "Select a format:"\
+ "select_map_format XXL" "XXL (original data)"\
+ "select_map_format XL" "XL (reduce factor: 2)"\
+ "select_map_format L" "L (reduce factor: 4)"\
+ "select_map_format M" "M (reduce factor: 8)"\
+ "select_map_format S" "S (reduce factor: 16)"\
+ "_"\
+ "open ${PREVIEWLINK}" "Get a preview image on MGDS portal"\
+ "_"\
+ "${RETURNFUNCTION}" "CANCEL"
+ else
+ display_menu\
+ "" "Select a format:"\
+ "select_map_format XXL" "XXL (original data)"\
+ "select_map_format XL" "XL (reduce factor: 2)"\
+ "select_map_format L" "L (reduce factor: 4)"\
+ "select_map_format M" "M (reduce factor: 8)"\
+ "select_map_format S" "S (reduce factor: 16)"\
+ "_"\
+ "${RETURNFUNCTION}" "CANCEL"
+ fi
+ }
+
+ function select_map_format
+ {
+ local DOWNLOAD_STATUS=0 OCEAN_TOPOGRAPHY=""
+ MAPS_FORMAT=$1
+ if [ "${DATA_PROVIDERS[$((${DATA_PROVIDER_ID} + 3))]}" == "ocean_topography_unavailable" ]
+ then
+ set_ocean_topography "unavailable"
+ else
+ display_header
+ display_section
+ display_menu\
+ "" "Configure ocean topography:"\
+ "set_ocean_topography yes" "Keep data"\
+ "set_ocean_topography no" "Flatten ocean"\
+ "_"\
+ "${RETURNFUNCTION}" "CANCEL"
+ fi
+ }
+
+ function set_ocean_topography
+ {
+ local MY_EXPORT_PATH_FILENAME
+ OCEAN_TOPOGRAPHY="$1"
+ case "${MAPS[$((${MAPS_ID} + 2))]}" in
+ "download_and_extract_zip")
+ download_map_and_extract_zip
+ DOWNLOAD_STATUS=$?
+ ;;
+ "download_with_mapbox")
+ download_map_with_mapbox
+ DOWNLOAD_STATUS=$?
+ ;;
+ esac
+ if [ "${DOWNLOAD_STATUS}" == "0" ]
+ then
+ MY_EXPORT_PATH_FILENAME="$(utils_data_provider_get_abbr "${DATA_PROVIDER_ID}")_${MAPS[$((${MAPS_ID} + 1))]}_$(if [ "${OCEAN_TOPOGRAPHY}" == "yes" ]; then printf "OCEAN1"; else printf "OCEAN0"; fi)_${MAPS_FORMAT}.fdf"
+ if [ ! -f "${MY_EXPORT_PATH}/${MY_EXPORT_PATH_FILENAME}" ]
+ then
+ generate_map
+ else
+ display_header
+ display_section
+ display_menu\
+ "" "Export file already exists:"\
+ "generate_map" "ERASE"\
+ "${RETURNFUNCTION}" "CANCEL"
+ fi
+ fi
+ }
+
+ function generate_map
+ {
+ local REDUCE_XY_FACTOR=1
+ local REDUCE_Z_FACTOR=1
+ local OCEAN_Z=-10
+ local UNKNOWN_Z=-10
+ case "${MAPS_FORMAT}" in
+ "XL")
+ REDUCE_XY_FACTOR=2
+ REDUCE_Z_FACTOR=2
+ OCEAN_Z=-5
+ UNKNOWN_Z=-5
+ ;;
+ "L")
+ REDUCE_XY_FACTOR=4
+ REDUCE_Z_FACTOR=4
+ OCEAN_Z=-3
+ UNKNOWN_Z=-3
+ ;;
+ "M")
+ REDUCE_XY_FACTOR=8
+ REDUCE_Z_FACTOR=8
+ OCEAN_Z=-2
+ UNKNOWN_Z=-2
+ ;;
+ "S")
+ REDUCE_XY_FACTOR=16
+ REDUCE_Z_FACTOR=16
+ OCEAN_Z=-1
+ UNKNOWN_Z=-1
+ ;;
+ esac
+ display_header
+ display_section
+ printf "${C_BLUE} %s\n\n" "Computing data..."
+ (awk\
+ -v REDUCE_XY_FACTOR="${REDUCE_XY_FACTOR}"\
+ -v REDUCE_Z_FACTOR="${REDUCE_Z_FACTOR}"\
+ -v UNKNOWN_Z="${UNKNOWN_Z}"\
+ -v OCEAN_Z="${OCEAN_Z}"\
+ -v OCEAN_TOPOGRAPHY="${OCEAN_TOPOGRAPHY}"\
+ 'BEGIN {odd=0}\
+ {\
+ odd+=1;\
+ if(odd==1)\
+ {\
+ for(i=1;i<=NF;i++)\
+ {\
+ if(OCEAN_TOPOGRAPHY=="unavailable" && $i==-9999)\
+ {\
+ printf UNKNOWN_Z\
+ }\
+ else\
+ {\
+ if(OCEAN_TOPOGRAPHY!="yes" && $i<0)\
+ {\
+ printf OCEAN_Z\
+ }\
+ else\
+ {\
+ printf("%d", $i/REDUCE_Z_FACTOR)\
+ }\
+ }\
+ i+=REDUCE_XY_FACTOR;\
+ if(i>=NF)\
+ {\
+ printf "\n"\
+ }\
+ else\
+ {\
+ printf " "\
+ }\
+ }\
+ }\
+ if(odd==REDUCE_XY_FACTOR)\
+ {\
+ odd=0\
+ }\
+ }'\
+ "${MAPS_TMPDIR}$(utils_data_provider_get_abbr "${DATA_PROVIDER_ID}")_${FILENAME}.txt" > "${MY_EXPORT_PATH}/${MY_EXPORT_PATH_FILENAME}"\
+ ) &
+ display_spinner $!
+ display_header
+ display_section
+ display_success "Export was successful!"
+ printf "\n"
+ display_menu\
+ "" ""\
+ "${RETURNFUNCTION}" "OK"
+ }
+
+fi
diff --git a/includes/google_api.sh b/includes/google_api.sh
new file mode 100644
index 0000000..69a56b4
--- /dev/null
+++ b/includes/google_api.sh
@@ -0,0 +1,120 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ declare GOOGLE_API_KEY="AIzaSyAO_R8YeQL6Zgl1d-E_H3Y9h3ZF_yZ9meI"
+
+ function main_google_api
+ {
+ MAPS_ID=0
+ MAPS_FORMAT=""
+ MAPS[0]=$(utils_get_config "customTITLE")
+ if [ "${MAPS[0]}" != "" ]
+ then
+ MAPS[1]="CUSTOM_$(echo "${MAPS[0]}" | awk '{gsub(/ /, "_"); print toupper($0)}')"
+ MAPS[4]=$(utils_get_config "customNORTH")
+ MAPS[5]=$(utils_get_config "customEAST")
+ MAPS[6]=$(utils_get_config "customSOUTH")
+ MAPS[7]=$(utils_get_config "customWEST")
+ display_header
+ display_section
+ display_menu\
+ "" ""\
+ "google_api_generate" "Generate map"\
+ "google_api_search" "Change country"\
+ "_"\
+ "${RETURNFUNCTION}" "CANCEL"
+ else
+ google_api_search
+ if [ "$?" == "0" ]
+ then
+ echo "0"
+ seep 10
+ utils_exit
+ else
+ echo "error"
+ seep 10
+ utils_exit
+ fi
+ fi
+ }
+
+ function google_api_generate
+ {
+ MAPS_FORMAT=""
+ display_header
+ display_section
+ display_menu_format
+ }
+
+ function google_api_search
+ {
+ local TITLE="" TITLEURL MSG JSON0 JSON1 STATUS=""
+ MAPS[0]=""
+ utils_save_config "customTITLE" ""
+ while [ "${MAPS[0]}" == "" ]
+ do
+ display_header
+ display_section
+ printf " %s\n\n" "Note: Keep empty and press ENTER to cancel"
+ if [ "${STATUS}" != "" ]
+ then
+ case "${STATUS}" in
+ "ZERO_RESULTS")
+ MSG="Your query returned no results"
+ ;;
+ "OVER_QUERY_LIMIT")
+ MSG="The daily quota of 2500 queries was reached"
+ ;;
+ "REQUEST_DENIED")
+ MSG="Request denied"
+ ;;
+ "INVALID_REQUEST")
+ MSG="Your request is invalid"
+ ;;
+ "UNKNOWN_ERROR")
+ MSG="An error occured (unknown error)"
+ ;;
+ *)
+ MSG="Unknown error (Status code: ${STATUS})"
+ ;;
+ esac
+ display_error "${MSG}"
+ printf "\n"
+ fi
+ printf "${C_WHITE}"
+ tput cnorm
+ read -p " Type a country name (e.g. Spain): " -e TITLE
+ tput civis
+ printf "${C_CLEAR}"
+ if [ "${TITLE}" == "" ]
+ then
+ eval "${RETURNFUNCTION}"
+ else
+ TITLEURL=`echo "${TITLE}" | sed 's/ /+/g'`
+ display_header
+ display_section
+ printf "${C_BLUE} %s\n\n" "Looking for coordinates..."
+ sleep 0.3
+ (curl -s "https://maps.googleapis.com/maps/api/geocode/json?components=country:${TITLEURL}&key=${GOOGLE_API_KEY}" > .myret 2>&1) &
+ display_spinner $!
+ JSON0=`cat .myret | sed 's/[" ,]//g'`
+ STATUS=`echo "${JSON0}" | grep "status" | cut -d: -f2 | sed 's/[ \t]*//g'`
+ if [ "${STATUS}" == "OK" ]
+ then
+ TITLE=`cat .myret | sed 's/[",]//g' | grep "formatted_address" | cut -d":" -f2 | sed 's/^[ ]*//g' | sed 's/[ ]*$//g'`
+ JSON1=`echo "${JSON0}" | awk 'BEGIN {OFS=""; VIEWPORT=0; NORTHEAST=0; SOUTHWEST=0 } $0 ~ /viewport/ {VIEWPORT=1} $0 ~ /northeast/ {if (VIEWPORT==1 && NORTHEAST==0) { NORTHEAST=1 }} $0 ~ /lat/ {if (NORTHEAST>0) {printf "NE" $0 "\n"; NORTHEAST+=1}} $0 ~ /lng/ {if (NORTHEAST>0) {printf "NE" $0 "\n"; NORTHEAST+=1}} $0 ~ /southwest/ {if (VIEWPORT==1 && SOUTHWEST==0) { SOUTHWEST=1 }} $0 ~ /lat/ {if (SOUTHWEST>0) {printf "SW" $0 "\n"; SOUTHWEST+=1}} $0 ~ /lng/ {if (SOUTHWEST>0) {printf "SW" $0 "\n"; SOUTHWEST+=1}} {if (NORTHEAST==3) {NORTHEAST=-1} if(SOUTHWEST==3) {SOUTHWEST=-1}}'`
+ utils_save_config "customWEST" "$(printf "%.4f" "$(printf "%s" "${JSON1}" | grep "SWlng" | cut -d":" -f2)")"
+ utils_save_config "customEAST" "$(printf "%.4f" "$(printf "%s" "${JSON1}" | grep "NElng" | cut -d":" -f2)")"
+ utils_save_config "customSOUTH" "$(printf "%.4f" "$(printf "%s" "${JSON1}" | grep "SWlat" | cut -d":" -f2)")"
+ utils_save_config "customNORTH" "$(printf "%.4f" "$(printf "%s" "${JSON1}" | grep "NElat" | cut -d":" -f2)")"
+ utils_save_config "customTITLE" "${TITLE}"
+ MAPS[0]="${TITLE}"
+ fi
+ fi
+ done
+ main_google_api
+ }
+
+fi
diff --git a/includes/ign.sh b/includes/ign.sh
new file mode 100644
index 0000000..c6fed2e
--- /dev/null
+++ b/includes/ign.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ function main_ign
+ {
+ RETURNFUNCTION="main_ign"
+ DATA_PROVIDER_ID=$(utils_data_provider_id "IGN")
+ MAPS_ID=""
+ display_header
+ display_section
+ display_menu\
+ "" "Select a preset region:"\
+ "MAPS" "MAPS_IGN" "main_ign_preset"\
+ "_"\
+ "open https://github.com/jgigault/42MapGenerator/issues/new" "REPORT A BUG"\
+ main "BACK TO MAIN MENU"
+ }
+
+ function main_ign_preset
+ {
+ RETURNFUNCTION="main_ign $1"
+ MAPS_ID=$1
+ MAPS_FORMAT=""
+ display_header
+ display_section
+ display_menu_format
+ }
+
+fi
diff --git a/includes/map.sh b/includes/map.sh
deleted file mode 100644
index eae7114..0000000
--- a/includes/map.sh
+++ /dev/null
@@ -1,353 +0,0 @@
-#!/bin/bash
-if [ "$MAPGENERATOR_SH" == "1" ]
-then
-
- declare -a MAPS
-
- MAPS[${#MAPS[*]}]=""
- MAPS[${#MAPS[*]}]="France_250_ASC_L93"
- MAPS[${#MAPS[*]}]="ign"
- MAPS[${#MAPS[*]}]="France Métropolitaine"
-
- MAPS[${#MAPS[*]}]=""
- MAPS[${#MAPS[*]}]="Guadeloupe_MNT250_ASC"
- MAPS[${#MAPS[*]}]="ign"
- MAPS[${#MAPS[*]}]="Guadeloupe"
-
- MAPS[${#MAPS[*]}]=""
- MAPS[${#MAPS[*]}]="Martinique_MNT250_ASC"
- MAPS[${#MAPS[*]}]="ign"
- MAPS[${#MAPS[*]}]="Martinique"
-
- MAPS[${#MAPS[*]}]=""
- MAPS[${#MAPS[*]}]="Reunion_MNT250_ASC"
- MAPS[${#MAPS[*]}]="ign"
- MAPS[${#MAPS[*]}]="Réunion"
-
- MAPS[${#MAPS[*]}]=""
- MAPS[${#MAPS[*]}]="Guyane_MNT250_ASC"
- MAPS[${#MAPS[*]}]="ign"
- MAPS[${#MAPS[*]}]="Guyane"
-
- MAPS[${#MAPS[*]}]=""
- MAPS[${#MAPS[*]}]="ST_MART_ST_BART_MNT250_ASC"
- MAPS[${#MAPS[*]}]="ign"
- MAPS[${#MAPS[*]}]="Saint Martin - Saint Barthélémy"
-
- MAPS[${#MAPS[*]}]="-13.0916666666666669285,35.5916666666666673785,31.6583333333333339665,59.0250000000000011805"
- MAPS[${#MAPS[*]}]="NOAA_ETOPO_EUROPE"
- MAPS[${#MAPS[*]}]="noaa"
- MAPS[${#MAPS[*]}]="Europe"
-
- MAPS[${#MAPS[*]}]="-127.3250000000000025465,14.0083333333333336135,-94.4416666666666685555,46.3250000000000009265"
- MAPS[${#MAPS[*]}]="NOAA_ETOPO_WEST_COAST"
- MAPS[${#MAPS[*]}]="noaa"
- MAPS[${#MAPS[*]}]="West Coast (North America)"
-
- MAPS[${#MAPS[*]}]="-82.8583333333333349905,-17.9916666666666670265,-33.3583333333333340005,13.2416666666666669315"
- MAPS[${#MAPS[*]}]="NOAA_ETOPO_AMAZONIA"
- MAPS[${#MAPS[*]}]="noaa"
- MAPS[${#MAPS[*]}]="Amazonia (South America)"
-
- MAPS[${#MAPS[*]}]="62.2583333333333345785,4.4750000000000000895,107.0916666666666688085,40.9250000000000008185"
- MAPS[${#MAPS[*]}]="NOAA_ETOPO_HIMALAYA"
- MAPS[${#MAPS[*]}]="noaa"
- MAPS[${#MAPS[*]}]="India & Himalaya"
-
- MAPS[${#MAPS[*]}]="165.4083333333333366415,-47.8250000000000009565,179.6083333333333369255,-33.8916666666666673445"
- MAPS[${#MAPS[*]}]="NOAA_ETOPO_NEWZEALAND"
- MAPS[${#MAPS[*]}]="noaa"
- MAPS[${#MAPS[*]}]="New Zealand"
-
- MAPS[${#MAPS[*]}]="6.6750000000000001335,36.4916666666666673965,18.7916666666666670425,46.0083333333333342535"
- MAPS[${#MAPS[*]}]="NOAA_ETOPO_ITALY"
- MAPS[${#MAPS[*]}]="noaa"
- MAPS[${#MAPS[*]}]="Italy"
-
- MAPS[${#MAPS[*]}]="-11.3083333333333335595,49.7250000000000009945,2.4916666666666667165,59.5916666666666678585"
- MAPS[${#MAPS[*]}]="NOAA_ETOPO_GB"
- MAPS[${#MAPS[*]}]="noaa"
- MAPS[${#MAPS[*]}]="Great Britain & Ireland"
-
- MAPS[${#MAPS[*]}]="-82.4416666666666683155,-57.1750000000000011435,-61.8583333333333345705,13.0416666666666669275"
- MAPS[${#MAPS[*]}]="NOAA_ETOPO_ANDES"
- MAPS[${#MAPS[*]}]="noaa"
- MAPS[${#MAPS[*]}]="Cordillera de los Andes"
-
- MAPS[${#MAPS[*]}]="111.3583333333333355605,-45.0083333333333342335,155.0583333333333364345,-9.7416666666666668615"
- MAPS[${#MAPS[*]}]="NOAA_ETOPO_AUSTRALIA"
- MAPS[${#MAPS[*]}]="noaa"
- MAPS[${#MAPS[*]}]="Australia"
-
- MAPS[${#MAPS[*]}]="-93.7750000000000018755,40.7750000000000008155,-59.4750000000000011895,50.3583333333333343405"
- MAPS[${#MAPS[*]}]="NOAA_ETOPO_GREAT_LAKES"
- MAPS[${#MAPS[*]}]="noaa"
- MAPS[${#MAPS[*]}]="Great Lakes (North America)"
-
-
- MAPS[${#MAPS[*]}]="24.4416666666666671555,-4.6250000000000000925,52.5416666666666677175,18.1916666666666670305"
- MAPS[${#MAPS[*]}]="NOAA_ETOPO_ETHIOPIA"
- MAPS[${#MAPS[*]}]="noaa"
- MAPS[${#MAPS[*]}]="Ethiopia"
-
- function gen_header
- {
- printf $C_GREY""
- display_center "$MAPNAME"
- printf "\n"$C_CLEAR
- }
-
- function gen_map
- {
- local index MAPURL MAPBOX MAPFILENAME MAPTYPE MAPNAME
- (( index=$1 * 4 ))
- MAPBOX=${MAPS[index]}
- (( index=$index + 1 ))
- MAPFILENAME=${MAPS[index]}
- (( index=$index + 1 ))
- MAPTYPE=${MAPS[index]}
- (( index=$index + 1 ))
- MAPNAME=${MAPS[index]}
- case "$MAPTYPE" in
- "noaa")
- MAPURL="http://mapserver.ngdc.noaa.gov/cgi-bin/public/wcs/etopo1.asc?filename="$MAPFILENAME".asc&request=getcoverage&version=1.0.0&service=wcs&coverage=etopo1&CRS=EPSG:4326&format=aaigrid&resx=0.016666666666666667&resy=0.016666666666666667&bbox="$MAPBOX
- ;;
- "ign")
- MAPURL="http://professionnels.ign.fr/sites/default/files/"
- ;;
- esac
- gen_map_cp "$1" "$MAPURL" "$MAPFILENAME" "$MAPTYPE" "$MAPNAME"
- }
-
- function gen_map_cp
- {
- local MYCONF index MAPNAME MAPURL LHOME LPATH MAPTYPE WIDTH0 MYWATER
- local ERASE=0
- local ERASE_ALL=0
- MAPURL=$2
- MAPFILENAME=$3
- MAPTYPE=$4
- MAPNAME=$5
- LHOME=`echo "$HOME" | sed 's/\//\\\\\\//g'`
- MYCONF=$(get_config "$1")
- local LIST=""
-
- if [ ! -f "$RETURNPATH/tmp/$MAPFILENAME.txt" ]
- then
- if [ "$MAPTYPE" == "ign" ]
- then
- download_map "$MAPURL$MAPFILENAME.zip" "$RETURNPATH/tmp/$MAPFILENAME.zip"
- extract_map "$RETURNPATH/tmp" "$MAPFILENAME.zip"
- else
- download_map "$MAPURL" "$RETURNPATH/tmp/$MAPFILENAME.asc"
- mv "$RETURNPATH/tmp/$MAPFILENAME.asc" "$RETURNPATH/tmp/$MAPFILENAME.txt"
- fi
- fi
- display_header
- gen_header
- printf $C_BLUE" Initialization...\n"$C_CLEAR
-
- (cat "$RETURNPATH/tmp/$MAPFILENAME.txt" | awk '{if(NR==10) {print NF} if(NR>10) {exit 1}}' > .myret) &
- display_spinner $!
- WIDTH0=`cat .myret`
- MYPATH=$(get_config "export_path")
- if [ ! -d "$MYPATH" -o "$MYPATH" == "" ]
- then
- config_path
- MYPATH=$(get_config "export_path")
- else
- display_header
- gen_header
- LPATH="$MYPATH"
- LPATH="echo \"$LPATH\" | sed 's/$LHOME/~/'"
- LPATH=`eval $LPATH`
- printf $C_WHITE" Current export directory:\n"$C_CLEAR
- printf " "$MYPATH"\n\n"
- display_menu\
- ""\
- "" "use current configuration"\
- config_path "change directory"
- MYPATH=$(get_config "export_path")
- fi
- MYWATER=`cat .mywater`
- if [ "$MYWATER" == "" ]
- then
- MYWATER=1
- fi
- if [ "$MAPTYPE" == "noaa" ]
- then
- display_header
- gen_header
- printf $C_WHITE" Configure the ocean topography:\n"$C_CLEAR
- printf " Select option (2) if you want the script to create a virtual ocean level (around -20).\n\n"
- display_menu\
- ""\
- "echo 1 > .mywater" "keep the original topography of the ocean"\
- "echo 0 > .mywater" "set up the oceans as flat"
- MYWATER=`cat .mywater`
- else
- MYWATER=0
- fi
-
- parse_map XXL "$MYPATH/$MAPFILENAME.OCEAN$MYWATER.XXL.fdf"
- parse_map XL "$MYPATH/$MAPFILENAME.OCEAN$MYWATER.XL.fdf"
- parse_map L "$MYPATH/$MAPFILENAME.OCEAN$MYWATER.L.fdf"
- parse_map M "$MYPATH/$MAPFILENAME.OCEAN$MYWATER.M.fdf"
- parse_map S "$MYPATH/$MAPFILENAME.OCEAN$MYWATER.S.fdf"
-
- display_header
- gen_header
- LPATH="$MYPATH"
- LPATH="echo \"$LPATH\" | sed 's/$LHOME/~/'"
- LPATH=`eval $LPATH`
- printf $C_WHITE" Current export directory:\n"$C_CLEAR
- printf " "$MYPATH"\n\n"
- if [ "$LIST" == "" ]
- then
- printf $C_BLUE" Nothing to do.\n$LIST\n"$C_CLEAR
- else
- printf $C_BLUE" Done.\n$LIST\n"$C_CLEAR
- fi
- sleep 0.3
- display_menu\
- ""\
- "main" "BACK TO MAIN MENU"\
- "exit_generator" "EXIT"
- }
-
-
- function config_parse
- {
- display_header
- #todo
- }
-
- function parse_map
- {
- local step=1
- local zfactor=2
- local unknown=-130
- local water=-130
- case "$1" in
- "XL")
- step=2
- #zfactor=5
- water=-60
- unknown=-60
- ;;
- "L")
- step=4
- #zfactor=10
- water=-30
- unknown=-30
- ;;
- "M")
- step=8
- #zfactor=20
- water=-15
- unknown=-15
- ;;
- "S")
- step=16
- #zfactor=40
- water=-10
- unknown=-10
- ;;
- esac
- ERASE=0
- display_header
- gen_header
- printf $C_WHITE" Current export directory:\n"$C_CLEAR
- printf " "$MYPATH"\n\n"
- printf $C_BLUE" Generating $1 map...\n"
- (( XFACTOR=$WIDTH0 / $step ))
- (( XFACTOR=$XFACTOR * 100 ))
- (( XFACTOR=$XFACTOR / $WIDTH0 ))
- (( zfactor=$zfactor * $XFACTOR ))
- (( zfactor=$zfactor / 100 + 1))
-
- zfactor=16
-
- if [ "$MYWATER" == "0" ]
- then
- (( water=10 - 10 * 100 / $WIDTH0 ))
- (( water=$water * 2 ))
- if (( $water <= 5 ))
- then
- water=5
- fi
- (( water= $water * -1 ))
- unknown=$water
- else
- unknown=-9999999
- water=-9999999
- fi
-
- if [ -f "$2" -a "$ERASE_ALL" == "0" ]
- then
- printf $C_RED" !!! This map already exists. !!!\n\n"
- display_menu\
- ""\
- "erase_map \"$1\" \"$2\"" "erase map"\
- "erase_map_all \"$1\" \"$2\"" "erase all maps"\
- "" "skip warning"
- else
-
- (cat "$RETURNPATH/tmp/$MAPFILENAME.txt" | awk -v step=$step -v zfactor=$zfactor -v unknown=$unknown -v water=$water 'BEGIN {odd=-1} {if(NR > 6) {odd+=1; if(odd==0) {for(i=1;i<=NF;i++) {if(unknown!=-9999999 && $i==-9999) {printf unknown} else {if(water!=-9999999 && $i<=0) {printf water} else {printf("%d", $i/zfactor+1)}} i+=step; if(i>=NF) {printf "\n"} else {printf " "}}} else {if (odd>=step) {odd=-1}}}}' > "$2") &
- display_spinner $!
- LIST=$LIST" -> $MAPFILENAME.OCEAN$MYWATER.$1.fdf\n"
- fi
- }
-
- function erase_map_all
- {
- ERASE_ALL=1
- erase_map "$1" "$2"
- }
-
- function erase_map
- {
- rm -f "$2"
- printf ""$C_CLEAR
- parse_map "$1" "$2"
- }
-
- function download_map
- {
- create_tmp_dir
- display_header
- gen_header
- printf $C_BLUE" Downloading map from remote server...\n"
- sleep 0.5
- rm -f "$2"
- curl --output "$2" "$1"
- printf $C_CLEAR""
- if [ ! -f "$2" ]
- then
- display_error "An error occured while downloading file"
- exit_generator
- fi
- }
-
- function extract_map
- {
- local RET0
- display_header
- gen_header
- printf $C_BLUE" Extracting map from archive...\n "
- sleep 0.5
- rm -f "$1/"*.ASC
- unzip -d "$1" "$1/$2" *.[Aa][Ss][Cc]
- printf $C_CLEAR""
- RET0=`find "$1" -name *.[Aa][Ss][Cc] | awk '{if(NR==1) {print}}'`
- if [ "$RET0" == "" ]
- then
- display_error "An error occured while extracting file"
- exit_generator
- fi
- echo $RET0
- mv "$RET0" "$1/$MAPFILENAME.txt"
- rm -f "$1/$2"
- }
-
-fi;
\ No newline at end of file
diff --git a/includes/maps.sh b/includes/maps.sh
new file mode 100644
index 0000000..44a1e4b
--- /dev/null
+++ b/includes/maps.sh
@@ -0,0 +1,293 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ declare -a MAPS
+ declare -i MAPS_SHIFT=8
+ declare -a MAPS_IGN='(1 2 3 4 5 6)'
+ declare -a MAPS_NOAA='(7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27)'
+ declare -a MAPS_MGDS='(7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27)'
+
+ # RESERVED FOR CUSTOM COORDINATES
+
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+
+ # IGN
+
+ MAPS[${#MAPS[*]}]="France Métropolitaine"
+ MAPS[${#MAPS[*]}]="France_250_ASC_L93"
+ MAPS[${#MAPS[*]}]="download_and_extract_zip"
+ MAPS[${#MAPS[*]}]="12.7M"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+
+ MAPS[${#MAPS[*]}]="DOM-TOM: Guadeloupe"
+ MAPS[${#MAPS[*]}]="Guadeloupe_MNT250_ASC"
+ MAPS[${#MAPS[*]}]="download_and_extract_zip"
+ MAPS[${#MAPS[*]}]="25K"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+
+ MAPS[${#MAPS[*]}]="DOM-TOM: Martinique"
+ MAPS[${#MAPS[*]}]="Martinique_MNT250_ASC"
+ MAPS[${#MAPS[*]}]="download_and_extract_zip"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+
+ MAPS[${#MAPS[*]}]="DOM-TOM: Réunion"
+ MAPS[${#MAPS[*]}]="Reunion_MNT250_ASC"
+ MAPS[${#MAPS[*]}]="download_and_extract_zip"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+
+ MAPS[${#MAPS[*]}]="DOM-TOM: Guyane"
+ MAPS[${#MAPS[*]}]="Guyane_MNT250_ASC"
+ MAPS[${#MAPS[*]}]="download_and_extract_zip"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+
+ MAPS[${#MAPS[*]}]="DOM-TOM: Saint Martin - Saint Barthélémy"
+ MAPS[${#MAPS[*]}]="ST_MART_ST_BART_MNT250_ASC"
+ MAPS[${#MAPS[*]}]="download_and_extract_zip"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]=""
+
+ # NOAA/MGDS
+
+ MAPS[${#MAPS[*]}]="Whole World"
+ MAPS[${#MAPS[*]}]="WHOLE_WORLD"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="81"
+ MAPS[${#MAPS[*]}]="180"
+ MAPS[${#MAPS[*]}]="-78"
+ MAPS[${#MAPS[*]}]="-180"
+
+ MAPS[${#MAPS[*]}]="Antarctic"
+ MAPS[${#MAPS[*]}]="ANTARCTIC"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="-60"
+ MAPS[${#MAPS[*]}]="180"
+ MAPS[${#MAPS[*]}]="-78"
+ MAPS[${#MAPS[*]}]="-180"
+
+ MAPS[${#MAPS[*]}]="Arctic"
+ MAPS[${#MAPS[*]}]="ARCTIC"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="81"
+ MAPS[${#MAPS[*]}]="180"
+ MAPS[${#MAPS[*]}]="72"
+ MAPS[${#MAPS[*]}]="-180"
+
+ MAPS[${#MAPS[*]}]="Europe"
+ MAPS[${#MAPS[*]}]="EUROPE"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="59.0250"
+ MAPS[${#MAPS[*]}]="31.6583"
+ MAPS[${#MAPS[*]}]="35.5916"
+ MAPS[${#MAPS[*]}]="-13.0916"
+
+ MAPS[${#MAPS[*]}]="Alaska-Aleutians"
+ MAPS[${#MAPS[*]}]="ALASKA_ALEUTIANS"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="63"
+ MAPS[${#MAPS[*]}]="-135"
+ MAPS[${#MAPS[*]}]="48"
+ MAPS[${#MAPS[*]}]="162"
+
+ MAPS[${#MAPS[*]}]="Cascade Range (West Coast USA)"
+ MAPS[${#MAPS[*]}]="CASCADIA_RANGE_WEST_COAST_USA"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="52"
+ MAPS[${#MAPS[*]}]="-118"
+ MAPS[${#MAPS[*]}]="39"
+ MAPS[${#MAPS[*]}]="-132"
+
+ MAPS[${#MAPS[*]}]="Central America"
+ MAPS[${#MAPS[*]}]="CENTRAL_AMERICA"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="17"
+ MAPS[${#MAPS[*]}]="-80"
+ MAPS[${#MAPS[*]}]="5"
+ MAPS[${#MAPS[*]}]="-95"
+
+ MAPS[${#MAPS[*]}]="East African Rift System"
+ MAPS[${#MAPS[*]}]="EAST_AFRICAN_RIFT_SYSTEM"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="17"
+ MAPS[${#MAPS[*]}]="45"
+ MAPS[${#MAPS[*]}]="-20"
+ MAPS[${#MAPS[*]}]="24"
+
+ MAPS[${#MAPS[*]}]="Eastern North American Margin"
+ MAPS[${#MAPS[*]}]="EASTERN_NORTH_AMERICAN_MARGIN"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="53"
+ MAPS[${#MAPS[*]}]="-42"
+ MAPS[${#MAPS[*]}]="28"
+ MAPS[${#MAPS[*]}]="-85"
+
+ MAPS[${#MAPS[*]}]="Gulf of California"
+ MAPS[${#MAPS[*]}]="GULF_OF_CALIFORNIA"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="32"
+ MAPS[${#MAPS[*]}]="-108"
+ MAPS[${#MAPS[*]}]="22"
+ MAPS[${#MAPS[*]}]="-117"
+
+ MAPS[${#MAPS[*]}]="Amazonia"
+ MAPS[${#MAPS[*]}]="AMAZONIA"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="13.2416"
+ MAPS[${#MAPS[*]}]="-33.3583"
+ MAPS[${#MAPS[*]}]="-17.9916"
+ MAPS[${#MAPS[*]}]="-82.8583"
+
+ MAPS[${#MAPS[*]}]="Cordillera de los Andes"
+ MAPS[${#MAPS[*]}]="CORDILLERA_DE_LOS_ANDES"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="13.0416"
+ MAPS[${#MAPS[*]}]="-61.8583"
+ MAPS[${#MAPS[*]}]="-57.1750"
+ MAPS[${#MAPS[*]}]="-82.4416"
+
+ MAPS[${#MAPS[*]}]="Izu-Bonin-Marinia"
+ MAPS[${#MAPS[*]}]="IZU_BONIN_MARIANIA"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="36"
+ MAPS[${#MAPS[*]}]="150"
+ MAPS[${#MAPS[*]}]="10"
+ MAPS[${#MAPS[*]}]="138"
+
+ MAPS[${#MAPS[*]}]="Nankai"
+ MAPS[${#MAPS[*]}]="NANKAI"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="35"
+ MAPS[${#MAPS[*]}]="138"
+ MAPS[${#MAPS[*]}]="30"
+ MAPS[${#MAPS[*]}]="130"
+
+ MAPS[${#MAPS[*]}]="New Zealand"
+ MAPS[${#MAPS[*]}]="NEW_ZEALAND"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="-27"
+ MAPS[${#MAPS[*]}]="-172"
+ MAPS[${#MAPS[*]}]="-57"
+ MAPS[${#MAPS[*]}]="155"
+
+ MAPS[${#MAPS[*]}]="Papua New Guinea"
+ MAPS[${#MAPS[*]}]="PAPUA_NEW_GUINEA"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="0"
+ MAPS[${#MAPS[*]}]="153"
+ MAPS[${#MAPS[*]}]="-12"
+ MAPS[${#MAPS[*]}]="134"
+
+ MAPS[${#MAPS[*]}]="Red Sea"
+ MAPS[${#MAPS[*]}]="RED_SEA"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="33.5"
+ MAPS[${#MAPS[*]}]="51"
+ MAPS[${#MAPS[*]}]="9"
+ MAPS[${#MAPS[*]}]="30"
+
+ MAPS[${#MAPS[*]}]="Himalaya"
+ MAPS[${#MAPS[*]}]="HIMALAYA"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="40.9250"
+ MAPS[${#MAPS[*]}]="107.0916"
+ MAPS[${#MAPS[*]}]="4.4750"
+ MAPS[${#MAPS[*]}]="62.2583"
+
+ MAPS[${#MAPS[*]}]="Mid-Ocean Ridges: EPR 8-11 N"
+ MAPS[${#MAPS[*]}]="MID_OCEAN_RIDGES_EPR_8_11_N"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="11"
+ MAPS[${#MAPS[*]}]="-102"
+ MAPS[${#MAPS[*]}]="8"
+ MAPS[${#MAPS[*]}]="-106"
+
+ MAPS[${#MAPS[*]}]="Mid-Ocean Ridges: JdF Endeavour"
+ MAPS[${#MAPS[*]}]="MID_OCEAN_RIDGES_JDF_ENDEAVOUR"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="48.5"
+ MAPS[${#MAPS[*]}]="-128.5"
+ MAPS[${#MAPS[*]}]="47.5"
+ MAPS[${#MAPS[*]}]="-129.5"
+
+ MAPS[${#MAPS[*]}]="Mid-Ocean Ridges: Lau Basin"
+ MAPS[${#MAPS[*]}]="MID_OCEAN_RIDGES_LAU_BASIN"
+ MAPS[${#MAPS[*]}]="download_with_mapbox"
+ MAPS[${#MAPS[*]}]=""
+ MAPS[${#MAPS[*]}]="-19"
+ MAPS[${#MAPS[*]}]="-173.5"
+ MAPS[${#MAPS[*]}]="-23"
+ MAPS[${#MAPS[*]}]="-178"
+
+ function utils_maps_get_name
+ {
+ printf "%s" "${MAPS[$1]}"
+ }
+
+ function utils_maps_get_filename
+ {
+ printf "%s" "${MAPS[$(($1 + 1))]}"
+ }
+
+ function utils_maps_get_coor
+ {
+ case "$1" in
+ "NORTH")
+ printf "%s" "${MAPS[$(($2 + 4))]}"; ;;
+ "EAST")
+ printf "%s" "${MAPS[$(($2 + 5))]}"; ;;
+ "SOUTH")
+ printf "%s" "${MAPS[$(($2 + 6))]}"; ;;
+ "WEST")
+ printf "%s" "${MAPS[$(($2 + 7))]}"; ;;
+ esac
+ }
+fi
\ No newline at end of file
diff --git a/includes/mgds.sh b/includes/mgds.sh
new file mode 100644
index 0000000..f4b443a
--- /dev/null
+++ b/includes/mgds.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ function main_mgds
+ {
+ RETURNFUNCTION="main_mgds"
+ DATA_PROVIDER_ID=$(utils_data_provider_id "MGDS")
+ MAPS_ID=""
+ display_header
+ display_section
+ display_menu\
+ "" "Find a country or select a preset region:"\
+ "main_google_api" "Find a country"\
+ "_"\
+ "MAPS" "MAPS_MGDS" "main_mgds_preset"\
+ "_"\
+ "open https://github.com/jgigault/42MapGenerator/issues/new" "REPORT A BUG"\
+ main "BACK TO MAIN MENU"
+ }
+
+ function main_mgds_preset
+ {
+ RETURNFUNCTION="main_mgds $1"
+ MAPS_ID=$1
+ MAPS_FORMAT=""
+ display_header
+ display_section
+ display_menu_format
+ }
+
+fi
diff --git a/includes/noaa.sh b/includes/noaa.sh
new file mode 100644
index 0000000..941523c
--- /dev/null
+++ b/includes/noaa.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+if [ "${MAPGENERATOR_SH}" == "1" ]
+then
+
+ function main_noaa
+ {
+ RETURNFUNCTION="main_noaa"
+ DATA_PROVIDER_ID=$(utils_data_provider_id "NOAA")
+ MAPS_ID=""
+ display_header
+ display_section
+ display_menu\
+ "" "Find a country or select a preset region:"\
+ "main_google_api" "Find a country"\
+ "_"\
+ "MAPS" "MAPS_NOAA" "main_noaa_preset"\
+ "_"\
+ "open https://github.com/jgigault/42MapGenerator/issues/new" "REPORT A BUG"\
+ main "BACK TO MAIN MENU"
+ }
+
+ function main_noaa_preset
+ {
+ RETURNFUNCTION="main_noaa $1"
+ MAPS_ID=$1
+ MAPS_FORMAT=""
+ display_header
+ display_section
+ display_menu_format
+ }
+
+fi
diff --git a/includes/update.sh b/includes/update.sh
index 0a6b4e5..fbd3c6e 100644
--- a/includes/update.sh
+++ b/includes/update.sh
@@ -1,86 +1,126 @@
#!/bin/bash
-if [ "$MAPGENERATOR_SH" == "1" ]
+if [ "${MAPGENERATOR_SH}" == "1" ]
then
- function update
- {
- local UPTODATE
- tput civis
- display_header
- display_righttitle ""
- printf " Checking for updates...\n"
- (check_for_update > .myret) &
- display_spinner $!
- UPTODATE=`cat .myret`
- if [ "$UPTODATE" != "1" ]
- then
- if [ "$UPTODATE" == "2" ]
- then
- display_error "An error occured."
- printf $C_RED"$(cat .myret2 | awk 'BEGIN {OFS=""} {print " ",$0}')"$C_CLEAR
- exit_generator
- printf "UPTODATE2" > .myret
- else
- printf $C_RED" Your version of '42MapGenerator' is out-of-date.\n Choose UPDATE 42MAPGENERATOR (1) for getting the last version or use '--no-update' to skip this message.\n\n"$C_CLEAR
- display_menu\
- ""\
- install_update "UPDATE 42MAPGENERATOR"\
- "" "SKIP UPDATE"\
- exit_generator "EXIT"
- fi
- fi
- }
+ function utils_update
+ {
+ tput civis
+ rm -f ".myret"
+ utils_update_check
+ case "$(cat ".myret")" in
+ "exit")
+ utils_exit
+ return ;;
+ "nothing")
+ tput cnorm
+ return ;;
+ esac
+ main
+ }
- function check_for_update
- {
- local DIFF0
- DIFF0=`git fetch origin 2>&1 | tee .myret2 | grep fatal`
- if [ "$DIFF0" != "" ]
- then
- printf "2"
- else
- DIFF0=`git diff origin/master 2>&1 | sed 's/\"//'`
- if [ "$DIFF0" != "" ]
- then
- printf "0"
- else
- printf "1"
- fi
- fi
- }
+ function utils_update_check
+ { if [ "${OPT_NO_UPDATE}" == "0" ]; then
+ local UPTODATE VERSION RET0 RET1 LOCALHASH REMOTEHASH LOCALBRANCH
+ display_header
+ printf "${C_BLUE} %s\n" "Checking for updates..."
+ (utils_update_check_diff > .myret) &
+ display_spinner $!
+ UPTODATE=`cat .myret`
+ case "${UPTODATE}" in
+ "1")
+ printf "continue" > .myret
+ ;;
+ "3")
+ display_header "${C_INVERTRED}"
+ display_error "Cannot check for updates: Your Internet connection is probably down..."
+ printf "\n"
+ display_menu\
+ "${C_INVERTRED}" ""\
+ "printf 'continue' > .myret" "SKIP UPDATE"\
+ "printf 'exit' > .myret" "EXIT"
+ ;;
+ "0")
+ LOCALBRANCH=$(git branch | grep '^\*' | cut -d" " -f2)
+ LOCALHASH=`git show-ref | grep "refs/heads/${LOCALBRANCH}" | cut -d" " -f1 | awk '{print; exit}'`
+ REMOTEHASH=`git ls-remote 2>/dev/null | grep refs/heads/${LOCALBRANCH} | cut -f1 | awk '{print; exit}'`
+ CVERSION=$(git log --oneline "refs/heads/${LOCALBRANCH}" | wc -l | sed 's/ //g')
+ VERSION=$(git log --oneline "refs/remotes/origin/${LOCALBRANCH}" | wc -l | sed 's/ //g')
+ display_header "${C_INVERTRED}"
+ printf "${C_RED}"
+ if [ "${REMOTEHASH}" != "${LOCALHASH}" -a "${REMOTEHASH}" != "" -a "${CVERSION}" -lt "${VERSION}" ]
+ then
+ display_center "Your version of '42MapGenerator' is out-of-date."
+ display_center "REMOTE: r$VERSION LOCAL: r$CVERSION"
+ RET1=`git log --pretty=oneline "refs/remotes/origin/${LOCALBRANCH}" 2>/dev/null | awk -v lhash="${LOCALHASH}" '{if ($1 == lhash) {exit} print}' | cut -d" " -f2- | awk 'BEGIN {LIMIT=0} {print " -> "$0; LIMIT+=1; if(LIMIT==10) {print " -> (limited to 10 last commits...)"; exit}}'`
+ if [ "$RET1" != "" ]
+ then
+ printf "\n\n Most recent commits:\n%s\n\n" "$RET1"
+ fi
+ else
+ display_center "Your copy of '42MapGenerator' has been modified locally."
+ display_center "Skip update if you don't want to erase your changes."
+ printf "\n\n"
+ fi
+ display_error "Choose UPDATE 42MAPGENERATOR (1) for installing the latest version or skip this warning by choosing SKIP UPDATE (2) or by using '--no-update' at launch."
+ printf "\n"
+ display_menu\
+ "${C_INVERTRED}" ""\
+ utils_update_install "UPDATE 42MAPGENERATOR"\
+ "printf 'continue' > .myret" "SKIP UPDATE"\
+ "printf 'exit' > .myret" "EXIT"
+ ;;
+ esac
+ fi
+ }
- function install_update
- {
- local RES0
- display_header
- display_righttitle ""
- printf " Updating 42MapGenerator\n"
- (git merge origin/master 2>&1 > .myret) &
- display_spinner $!
- RES0=`cat .myret`
- sleep 0.5
- if [ "$RES0" == "" ]
- then
- printf $C_BLUE" Done.\n"$C_CLEAR
- sleep 0.2
- tput cnorm
- sh ./42MapGenerator.sh
- else
- RES0=`git reset --hard origin/master 2>&1`
- RES0=`git merge origin/master 2>&1`
- if [ "$RES0" == "" ]
- then
- display_error "An error occured."
- printf $C_RED"\n You should better discard your repository and clone again.\n"$C_CLEAR
- tput cnorm
- else
- printf $C_BLUE" Done.\n"$C_CLEAR
- sleep 0.2
- tput cnorm
- sh ./42MapGenerator.sh
- fi
- fi
- }
+ function utils_update_check_diff
+ {
+ local DIFF0
+ local LOCALBRANCH=$(git branch | grep '^\*' | cut -d" " -f2)
+ DIFF0=`git fetch --all 2>&1 | tee .myret2 | grep fatal`
+ if [ "${DIFF0}" != "" ]
+ then
+ printf "3"
+ else
+ DIFF0=`git diff "refs/remotes/origin/${LOCALBRANCH}" 2>&1 | grep -E '^\+|^\-' | sed 's/\"//'`
+ if [ "$DIFF0" != "" ]
+ then
+ printf "0"
+ else
+ printf "1"
+ fi
+ fi
+ }
+
+ function utils_update_install
+ {
+ local RES0 LOCALBRANCH=$(git branch | grep '^\*' | cut -d" " -f2)
+ local LOGFILENAME=".myret"
+ display_header
+ printf "\n\n"
+ printf "${C_BLUE} %s\n" "Updating 42MapGenerator..."
+ rm -f ${LOGFILENAME}
+ (git fetch --all >/dev/null 2>&1) &
+ display_spinner $!
+ (git reset --hard "origin/${LOCALBRANCH}" 2>&1 | grep -v 'HEAD is now at' >${LOGFILENAME}) &
+ display_spinner $!
+ RES0=`cat ${LOGFILENAME}`
+ sleep 0.5
+ if [ "${RES0}" == "" ]
+ then
+ printf "${C_BLUE} %s\n${C_CLEAR}" "Done!"
+ (git shortlog -s | awk 'BEGIN {rev=0} {rev+=$1} END {printf rev"\n"}' >.myrev 2>/dev/null) &
+ display_spinner $!
+ sleep 0.5
+ sh ./42MapGenerator.sh
+ else
+ display_error "An error occured"
+ display_error "If the error persists, try to discard this directory and clone again"
+ printf "\n"
+ tput cnorm
+ fi
+ printf "nothing" >.myret
+ }
fi
\ No newline at end of file
diff --git a/includes/utils.sh b/includes/utils.sh
index 8fae881..3d046fc 100644
--- a/includes/utils.sh
+++ b/includes/utils.sh
@@ -1,312 +1,135 @@
#!/bin/bash
-if [ "$MAPGENERATOR_SH" == "1" ]
+if [ "${MAPGENERATOR_SH}" == "1" ]
then
- COLUMNS=`tput cols`
- if [ "$COLUMNS" == "" ]
- then
- $COLUMNS=80;
- fi;
-
- if [ "$OPT_NO_COLOR" == "0" ]
- then
- C_CLEAR="\033[0m"
- C_YELLOW="\033[33;1m"
- C_RED="\033[31m"
- C_GREEN="\033[32m"
- C_CYAN="\033[36;1m"
- C_WHITE="\033[37;1m"
- C_BLUE="\033[34;1m"
- C_GREY="\033[1;30m"
- C_BLACK="\033[30;1m"
- C_INVERT="\033[44;1m"$C_WHITE
- fi
-
- function display_error
- {
- echo $C_RED" !!! $1 !!!"$C_CLEAR
- }
-
- function display_hr
- {
- local MARGIN
- (( MARGIN= $COLUMNS ))
- if [ "$1" == "" ]
- then
- printf $C_GREY""
- else
- printf "$1"
- fi
- printf "%"$MARGIN"s" "" | sed s/' '/"${c:=_}"/g | cut -c1-$MARGIN
- printf "$C_CLEAR"
- }
-
- function display_hr2
- {
- local MARGIN
- (( MARGIN= $COLUMNS ))
- printf $C_GREY""
- printf "%"$MARGIN"s" "" | sed s/' '/"${c:=¯ }"/g | cut -c1-$MARGIN
- printf $C_CLEAR""
- if [ "$1" != "" ]
- then
- echo "$1";
- fi
- }
-
- function display_righttitle
- {
- local LEN MARGIN
- if [ "$1" != "" ]
- then
- LEN=${#1}
- (( MARGIN= $COLUMNS - $LEN))
- printf "%"$MARGIN"s" " "
- printf "$1\n"
- else
- printf "\n"
- fi
- }
-
- function display_center
- {
- local LEN MARGIN
- if [ "$1" != "" ]
- then
- LEN=${#1}
- (( MARGIN= ($COLUMNS - $LEN) / 2 ))
- printf "%"$MARGIN"s" " "
- printf "$1"
- printf "%"$MARGIN"s" " "
- printf "\n"
- else
- printf "\n"
- fi
- }
-
- function display_header
- {
- local MARGIN
- echo "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
- echo "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n "
- clear
- printf $C_GREY""
- display_center " "
- display_center " _ _ ____ __ __ ____ "
- display_center " | || ||___ \| \/ | __ _ _ __ / ___| ___ _ __ "
- display_center " | || |_ __) | |\/| |/ _\` | '_ \| | _ / _ \ '_ \ "
- display_center " |__ _/ __/| | | | (_| | |_) | |_| | __/ | | | "
- display_center " |_||_____|_| |_|\__,_| .__/ \____|\___|_| |_| "
- display_center " jgigault @ student.42.fr |_| 06 51 15 98 82 "
- display_center " "
- display_center " "
- printf $C_CLEAR""
- }
-
- function display_footer
- {
- echo $C_WHITE""
- printf "%"$COLUMNS"s" "" | sed s/' '/"${c:=#}"/g | cut -c1-$COLUMNS
- echo $C_CLEAR""
- }
-
- function ft_atoi
- {
- local SELN
- if [ "$1" != "1" -a "$1" != "2" -a "$1" != "3" -a "$1" != "4" -a "$1" != "5" -a "$1" != "6" -a "$1" != "7" -a "$1" != "8" -a "$1" != "9" ]
- then
- SELN=`LC_CTYPE=C printf '%d' "'$1"`
- if (( $SELN >= 65 )) && (( $SELN <= 90 ))
- then
- (( SELN=$SELN - 65 + 10 ))
- printf "$SELN"
- else
- if (( $SELN >= 97 )) && (( $SELN <= 122 ))
- then
- (( SELN=$SELN - 97 + 10 ))
- printf "$SELN"
- else
- printf "0"
- fi
- fi
- else
- printf "$1"
- fi
- }
-
- function display_menu
- {
- local -a MENU FUNCS
- local PARAMS0 TOTAL SEL LEN SELN
- PARAMS0="\"$1\" "
- SEL=""
- shift 1
- while (( $# > 0 ))
- do
- PARAMS0=$PARAMS0" $1 \"$2\""
- (( TOTAL += 1 ))
- FUNCS[$TOTAL]="$1"
- MENU[$TOTAL]="$2"
- if (( $TOTAL < 10 ))
- then
- SELN=$TOTAL
- else
- (( SELN=65 + $TOTAL - 10 ))
- SELN=`echo "$SELN" | awk '{printf("%c", $0)}'`
- fi
- (( LEN=$COLUMNS - ${#2} - 9 ))
- printf $C_INVERT" "$SELN") $2 "
- printf "%"$LEN"s" " "
- printf $C_CLEAR"\n"
- shift 2
- done
- printf "\n "$C_WHITE"Type a number between 1 and "$SELN": "
- tput cnorm
- read -s -n 1 SEL
- tput civis
- SEL=`ft_atoi "$SEL"`
- while [ -z "${MENU[$SEL]}" -o "$(echo "${FUNCS[$SEL]}" | grep open)" != "" ]
- do
- printf "\a"
- if [ "$(echo "${FUNCS[$SEL]}" | grep open)" != "" ]
- then
- eval ${FUNCS[$SEL]}
- fi
- SEL=""
- tput cnorm
- read -s -n 1 SEL
- tput civis
- SEL=`ft_atoi "$SEL"`
- done
- printf "\n"
- if [ "${FUNCS[$SEL]}" != "" ]
- then
- eval ${FUNCS[$SEL]}
- fi
- }
-
- function get_config
- {
- local MYFILE MYPATH RET0
- MYFILE=`printf "$RETURNPATH/.my$1" | sed 's/ /\\ /g'`
- if [ ! -f "$MYFILE" ]
- then
- touch "$MYFILE"
- fi
- MYPATH=`cat "$MYFILE"`
- if [ ! -d "$MYPATH" ]
- then
- printf "" > "$MYFILE"
- MYPATH=""
- fi
- printf "$MYPATH"
- }
-
- function save_config
- {
- local MYFILE RET0
- MYFILE=".my$1"
- RET0=`printf "$RETURNPATH/$MYFILE" | sed 's/ /\\ /g'`
- RET0=`echo "printf \"$2\" > \"$RET0\""`
- eval $RET0
- }
-
- function exit_generator
- {
- printf "\n"
- display_hr
- printf "\n\n\n\n"
- tput cnorm
-# clear
- exit
- }
-
- function display_spinner
- {
- local pid=$1
- local total_delay=0
- local total_delay2=240
- local delay=0.2
- local spinstr='|/-\'
- printf $C_BLUE""
- while [ "$(ps a | awk '{print $1}' | grep $pid)" ];
- do
- if (( $total_delay2 < 1 ))
- then
- kill $pid
- wait $! 2>/dev/null
- (( total_delay2 = $total_delay / 5 ))
- printf $C_RED" Time out ($total_delay2 sec)"$C_CLEAR > $RETURNPATH/.myret
- fi
- if [ "$OPT_NO_TIMEOUT" == "0" ]
- then
- (( total_delay += 1 ))
- fi
- local temp=${spinstr#?}
- printf " [%c] " "$spinstr"
- local spinstr=$temp${spinstr%"$temp"}
- if (( $total_delay >= 5 ))
- then
- (( total_delay2 = ( 209 - $total_delay ) / 5 ))
- printf "[time out: %02d]" "$total_delay2"
- fi
- sleep $delay
- printf "\b\b\b\b\b\b"
- if (( $total_delay >= 5 ))
- then
- printf "\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
- fi
- done
- printf " \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
- printf $C_CLEAR""
- }
-
- function check_fileexists
- {
- local i TOTAL RET0 VALPARAM
- if [ "$1" != "" ]
- then
- i=0
- VALPARAM=`eval echo \$1[\$i]`
- while [ "${!VALPARAM}" != "" ]
- do
- if [ ! -f "$MYPATH/${!VALPARAM}" ]
- then
- (( TOTAL += 1 ))
- RET0=$RET0"Not Found: ${!VALPARAM}\n"
- fi
- (( i += 1 ))
- VALPARAM=`eval echo \$1[\$i]`
- done
- printf "$RET0" > "$RETURNPATH"/.my$1
- if [ "$RET0" == "" ]
- then
- printf $C_GREEN" All files were found"$C_CLEAR
- else
- if (( $TOTAL == 1 ))
- then
- printf $C_RED" 1 file is missing"$C_CLEAR
- else
- printf $C_RED" $TOTAL files are missing"$C_CLEAR
- fi
- fi
- else
- printf $C_RED" An error occured (Files list missing)"$C_CLEAR
- fi
- }
-
- function create_tmp_dir
- {
- if [ ! -d "$RETURNPATH"/tmp ]
- then
- mkdir "$RETURNPATH"/tmp
- fi
- if [ ! -d "$RETURNPATH"/tmp ]
- then
- display_error "An error occured while creating temporary folder"
- exit_generator
- fi
- }
+ declare MAPS_TMPDIR="./tmp/"
+
+ function utils_set_env
+ {
+ COLUMNS=`tput cols`
+ if [ "${COLUMNS}" == "" ]
+ then
+ COLUMNS=80
+ fi
+ }
+
+ function utils_set_colors
+ {
+ if [ "${OPT_NO_COLOR}" == "0" ]
+ then
+ C_BLACKBG="\033[48;5;233m""\033[38;5;249m"
+ C_CLEAR="\033[0m"$C_BLACKBG
+ C_YELLOW=$C_BLACKBG"\033[33;1m"
+ C_RED=$C_BLACKBG"\033[31m\033[38;5;208m"
+ C_GREEN=$C_BLACKBG"\033[32m\033[38;5;77m"
+ C_CYAN=$C_BLACKBG"\033[36;1m"
+ C_WHITE=$C_BLACKBG"\033[37;1m"
+ C_BLUE=$C_BLACKBG"\033[38;5;12m"
+ C_GREY=$C_BLACKBG"\033[38;5;239m"
+ C_BLACK="\033[30;1m"
+ C_INVERT="\033[48;5;234m""\033[38;5;248m"
+ C_INVERT2="\033[48;5;233m""\033[38;5;242m"
+ C_INVERTGREY="\033[48;5;248m""\033[38;5;235m"
+ C_INVERTRED="\033[48;5;52m""\033[38;5;107m"
+ else
+ C_BLACKBG=
+ C_CLEAR="\033[0m"
+ C_YELLOW=
+ C_RED=
+ C_GREEN=
+ C_CYAN=
+ C_WHITE=
+ C_BLUE=
+ C_GREY=
+ C_GREY=
+ C_BLACK=
+ C_INVERT=
+ C_INVERT2=
+ C_INVERTGREY=
+ C_INVERTRED=
+ fi
+ }
+
+ function utils_exit
+ {
+ printf "\n\n\n\n\033[0m"
+ tput cnorm
+ tput rmcup
+ cd "${GLOBAL_ENTRYPATH}"
+ exit
+ }
+
+ function utils_clear
+ {
+ printf ${C_CLEAR}""
+ tput cup 0 0
+ tput cd
+ }
+
+ function utils_option_set
+ {
+ case "$1" in
+ "OPT_NO_TIMEOUT")
+ if [ "$OPT_NO_TIMEOUT" == 1 ]; then OPT_NO_TIMEOUT=0; else OPT_NO_TIMEOUT=1; fi
+ ;;
+ "OPT_NO_COLOR")
+ if [ "$OPT_NO_COLOR" == 1 ]; then OPT_NO_COLOR=0; else OPT_NO_COLOR=1; fi
+ utils_set_colors
+ ;;
+ esac
+ main
+ }
+
+ function create_tmp_dir
+ {
+ if [ ! -d "${MAPS_TMPDIR}" ]
+ then
+ mkdir "${MAPS_TMPDIR}"
+ fi
+ if [ ! -d "${MAPS_TMPDIR}" ]
+ then
+ display_header
+ display_section
+ display_error "An error occured while creating temporary folder"
+ display_menu\
+ "" ""\
+ "${RETURNFUNCTION}" "OK"\
+ "_"\
+ "open https://github.com/jgigault/42MapGenerator/issues/new" "REPORT A BUG"\
+ "utils_exit" "EXIT"
+ else
+ if [ "$1" != "" -a ! -d "${MAPS_TMPDIR}${1}" ]
+ then
+ mkdir "${MAPS_TMPDIR}${1}"
+ if [ ! -d "${MAPS_TMPDIR}${1}" ]
+ then
+ display_header
+ display_section
+ display_error "An error occured while creating temporary folder"
+ display_menu\
+ "" ""\
+ "${RETURNFUNCTION}" "OK"\
+ "_"\
+ "open https://github.com/jgigault/42MapGenerator/issues/new" "REPORT A BUG"\
+ "utils_exit" "EXIT"
+ fi
+ fi
+ fi
+ }
+
+ function utils_get_config
+ {
+ if [ ! -f ".my$1" ]
+ then
+ touch ".my$1"
+ fi
+ printf "%s" "$(cat ".my$1")"
+ }
+
+ function utils_save_config
+ {
+ printf "%s" "$2" > ".my$1"
+ }
fi
\ No newline at end of file