Last active
September 12, 2020 21:15
-
-
Save thiago-rezende/8fa0440f58f86e1a7f18e2444ad4ead0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| ########################### | |
| # Time Zone Selection # | |
| # Dependencies: # | |
| # - dialog # | |
| # Folder Structure: # | |
| # ├── TZ # | |
| # │ ├── America # | |
| # │ ├── Europe # | |
| # │ └── . . . # | |
| # └── tz_selection.sh # | |
| # TZ File Example: # | |
| # America: # | |
| # America/Sao_Paulo # | |
| # ... # | |
| ########################### | |
| # Directory to timezones | |
| TZ_DIR="TZ" | |
| # Check the TZ directory | |
| if [ ! -d $TZ_DIR ]; then | |
| echo "ERROR: TZ directory not found" | |
| exit 1 | |
| fi | |
| # Check for continents list | |
| if [ ! "$(ls -A $TZ_DIR)" ]; then | |
| echo "ERROR: No continents found" | |
| exit 1 | |
| fi | |
| # Getting the avaliable continents | |
| TZ_CONTINENTS=`ls $TZ_DIR` | |
| # Prepare continent list | |
| TZ_CONTINENTS_LIST="" | |
| TZ_CONTINENTS_COUNT=0 | |
| while read tz; do | |
| TZ_CONTINENTS_LIST="$TZ_CONTINENTS_LIST $tz + off" | |
| let TZ_CONTINENTS_COUNT=TZ_CONTINENTS_COUNT+1 | |
| done <<EOF | |
| `echo $TZ_CONTINENTS | sed -e 's/\s/\\n/g'` | |
| EOF | |
| # Show continent selection dialog | |
| SELECTED_CONTINENT=$(dialog --stdout --backtitle "Select Time Zone" \ | |
| --radiolist "Continent" 0 0 $TZ_CONTINENTS_COUNT \ | |
| $TZ_CONTINENTS_LIST) | |
| # Prepare timezones list | |
| TZ_LIST="" | |
| TZ_COUNT=0 | |
| while read tz; do | |
| TZ_LIST="$TZ_LIST $tz + off" | |
| let TZ_COUNT=TZ_COUNT+1 | |
| done < $TZ_DIR/$SELECTED_CONTINENT | |
| SELECTED_TZ=$(dialog --stdout --backtitle "Select Time Zone" \ | |
| --radiolist "Time Zone" 0 0 $TZ_COUNT \ | |
| $TZ_LIST) | |
| dialog --backtitle "Select Time Zone" --title "Info[!]" --msgbox "\nSelected TZ: $SELECTED_TZ\n " 0 0 | |
| clear | |
| echo "Selected TZ: $SELECTED_TZ" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment