-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_config.sh
executable file
·81 lines (66 loc) · 2.25 KB
/
generate_config.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
#!/usr/bin/bash
PINS=("SS_PIN" "RST_PIN" "BUZZ" "LED_WiR" "LED_WiG" "LED_OK" "LED_NOK")
DEFAULT_PINS=(5 22 14 32 33 26 25)
NET=("ESSID" "PASSWD" "IP_ADDRESS")
set_passwd()
{
unset password
while IFS= read -p "$prompt" -r -s -n 1 char
do
if [[ $char == $'\0' ]] ; then
break
elif [[ $char == $'\177' ]] && [[ ${#password} > 0 ]] ; then
prompt=$'\b \b'
password="${password%?}"
elif [[ $char == $'\177' ]] && [[ ${#password} == 0 ]] ; then
prompt=$''
else
prompt='*'
password+="$char"
fi
done
}
if [ -f config.h ]
then
read -p ":: $(tput bold)Remove existing config file [y/N] $(tput sgr0)" yn
case $yn in
[Yy]* ) rm config.h;;
* ) exit 1;;
esac
fi
read -p ":: $(tput bold)Use the default pinout [Y/n] $(tput sgr0)" yn
case $yn in
[Nn]* ) for i in {0..6}
do
read -p ":: $(tput bold)Enter ${PINS[$i]}: $(tput sgr0)" p
echo -e "#ifndef ${PINS[$i]}\n#define ${PINS[$i]} $p\n#endif\n" >> config.h
done;;
* ) for i in {0..6}
do
echo -e "#ifndef ${PINS[$i]}\n#define ${PINS[$i]} ${DEFAULT_PINS[$i]}\n#endif\n" >> config.h
done;;
esac
read -p ":: $(tput bold)LEDs are common anode or cathode [A/c] $(tput sgr0)" yn
case $yn in
[Cc]* ) echo -e "#ifndef MODE\n#define MODE \"CATHODE\"\n#endif\n" >> config.h;;
* ) echo -e "#ifndef MODE\n#define MODE \"ANODE\"\n#endif\n" >> config.h;;
esac
for i in {0..2}
do
if [[ $i -eq 1 ]]
then
echo -ne ":: $(tput bold)Enter password: $(tput sgr0)"
set_passwd
echo -e "#ifndef ${NET[$i]}\n#define ${NET[$i]} \"$password\"\n#endif\n" >> config.h
echo
else
read -p ":: $(tput bold)Enter ${NET[$i]}: $(tput sgr0)" n
echo -e "#ifndef ${NET[$i]}\n#define ${NET[$i]} \"$n\"\n#endif\n" >> config.h
fi
done
read -p ":: $(tput bold)Use the default UUID [Y/n] $(tput sgr0)" yn
case $yn in
[Nn]* ) read -p ":: $(tput bold)Enter new UUID: $(tput sgr0)" u
echo -e "#ifndef UUID\n#define UUID \"$u\"\n#endif\n" >> config.h;;
* ) echo -e "#ifndef UUID\n#define UUID \"2c56d4c7-5c46-4191-bd65-5dd820b41c30\"\n#endif\n" >> config.h;;
esac