-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdatePrefs.sh
executable file
·121 lines (116 loc) · 3.96 KB
/
UpdatePrefs.sh
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
114
115
116
117
118
119
120
121
#!/bin/sh
# Import preferences from prefs.cfg #
source $(pwd)/Prefs.cfg
clear
# Get old preferences #
newApiKey=$apiKey
newUnits=$units
newClearTerminal=$clearTerminal
newTimeFormat=$timeFormat
newSingleEvent=$singleEvent
newRefreshTime=$refreshTime
newInstallLocation=$installLocation
newDisplayWeatherImage=$displayWeatherImage
# Setup for new prefecences #
choice=00
while [ "$choice" != "0" ]
do
echo "---UPDATING OPEN WEATHER CLI APP PREFERENCES---"
echo "---Use numbers to navigate through the menus---"
echo "1) Modify API key"
echo "2) Modify units of measurements"
echo "3) Choose wether to clear terminal or not"
echo "4) Modify time format"
echo "5) Choose wether to refresh or not data"
echo "6) Modify the refresh timer"
echo "7) Update install path"
echo "8) Choose wether to show weather images or not"
echo "0) Exit"
read choice
echo -e '\e[1A\e[K'
case $choice in
1)
echo "Enter your Open Weather API key:"
read newApiKey
;;
2)
echo "Which units of measurements would you like to use (metric/imperial)?"
read newUnits
newUnits=$( echo $newUnits | tr [:upper:] [:lower:])
while [ "$newUnits" != "metric" ] && [ "$newUnits" != "imperial" ]
do
echo "Only 'metric' and 'imperial' are valid options"
echo "Which units of measurements would you like to use (metric/imperial)?"
read newUnits
newUnits=$( echo $newUnits | tr [:upper:] [:lower:])
done
;;
3)
echo "Would you like this app to clear the window before opening the app (y/n)?"
read newClearTerminal
newClearTerminal=$( echo $newClearTerminal | tr [:upper:] [:lower:])
while [ "$newClearTerminal" != "y" ] && [ "$newClearTerminal" != "n" ]
do
echo "Only 'y' and 'n' are valid options"
echo "Would you like this app to clear the window before opening the app (y/n)?"
read newClearTerminal
newClearTerminal=$( echo $newClearTerminal | tr [:upper:] [:lower:])
done
;;
4)
echo "Which time convention do you want to use: 12 hours of 24 hours (12/24)?"
read newTimeFormat
while [ "$newTimeFormat" != "12" ] && [ "$newTimeFormat" != "24" ]
do
echo "Only '12' and '24' are valid options"
echo "Which time convention do you want to use: 12 hours or 24 hours (12/24)?"
read newTimeFormat
done
;;
5)
echo "Do you want the data to be static (y/n)?"
read newSingleEvent
newSingleEvent=$( echo $newSingleEvent | tr [:upper:] [:lower:])
while [ "$newSingleEvent" != "y" ] && [ "$newSingleEvent" != "n" ]
do
echo "Only 'y' and 'n' are valid options"
echo "Do you want the data to be static (y/n)?"
read newSingleEvent
newSingleEvent=$( echo $newSingleEvent | tr [:upper:] [:lower:])
done
;;
6)
echo "Write here how often do you want the data to be refreshed, in seconds (min 3)"
read newRefreshTime
while [ "$newRefreshTime" < "3" ]
do
echo "Minimun amount of time must be 3 seconds or more"
echo "Write here how often do you want the data to be refreshed, in seconds (min 3)"
read newRefreshTime
done
;;
7)
newInstallLocation=$(pwd)
echo "Install path updated"
sleep 0.5
;;
8)
echo "Do you want the weather image to be shown (y/n)?"
read newDisplayWeatherImage
newDisplayWeatherImage=$( echo $newDisplayWeatherImage | tr [:upper:] [:lower:])
while [ "$newDisplayWeatherImage" != "y" ] && [ "$newDisplayWeatherImage" != "n" ]
do
echo "Only 'y' and 'n' are valid options"
echo "Do you want the weather image to be shown (y/n)?"
read newDisplayWeatherImage
newDisplayWeatherImage=$( echo $newDisplayWeatherImage | tr [:upper:] [:lower:])
done
;;
0)
;;
esac
clear
done
# Remove old Prefs.cfg and create a new updated one #
rm $(pwd)/Prefs.cfg
echo 'apiKey="'$newApiKey'"\nunits="'$newUnits'"\nclearTerminal="'$newClearTerminal'"\ntimeFormat="'$newTimeFormat'"\nsingleEvent="'$newSingleEvent'"\nrefreshTime="'$newRefreshTime'"\ninstallLocation="'$newInstallLocation'"\ndisplayWeatherImage="'$newDisplayWeatherImage'"' >> $(pwd)/Prefs.cfg