This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
select_daemon.sh
190 lines (158 loc) · 4.66 KB
/
select_daemon.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
# Raspberry Pi Internet Radio
# $Id: select_daemon.sh,v 1.27 2017/04/15 09:01:02 bob Exp $
#
# Author : Bob Rathbone
# Site : http://www.bobrathbone.com
#
# This program is used during installation to set up which
# radio daemon is to be used
#
# License: GNU V3, See https://www.gnu.org/copyleft/gpl.html
#
# Disclaimer: Software is provided as is and absolutly no warranties are implied or given.
# The authors shall not be liable for any loss or damage however caused.
#
# This program uses whiptail. Set putty terminal to use UTF-8 charachter set
# for best results
DAEMON=radiod.py
INIT=/etc/init.d/radiod
SERVICE=/lib/systemd/system/radiod.service
BINDIR="\/usr\/share\/radio\/"
DIR=/usr/share/radio
CONFIG=/etc/radiod.conf
PIRADIO_TYPE=/var/lib/radiod/piradio_type
# Display types
LCD=1 # LCD screen (direct)
I2C=2 # Requires I2C libraries
CAD=3 # PiFace Control and Display
NODISPLAY=4 # Retro radio with no display
BACKPACK=0 # Backpack selected 1=yes 0=no
ans=0
while [ $ans == 0 ]
do
ans=$(whiptail --title "Select wiring version" --menu "Choose your option" 15 75 9 \
"1" "26 pin version wiring" \
"2" "40 pin version wiring" \
"3" "Do not change configuration" 3>&1 1>&2 2>&3)
exitstatus=$?
if [[ $exitstatus != 0 ]]; then
exit 0
fi
if [[ ${ans} == '1' ]]; then
echo "26 pin version selected"
sudo cp -f ${DIR}/radiod.conf ${CONFIG}
elif [[ ${ans} == '2' ]]; then
echo "40 pin version selected"
sudo cp -f ${DIR}/radiod.conf.40_pin ${CONFIG}
else
echo "Wiring configuration in ${CONFIG} unchanged"
fi
done
# Select the actual radio daemon to run at boot time
selection=1
while [ $selection != 0 ]
do
ans=$(whiptail --title "Select radio daemon" --menu "Choose your option" 15 75 9 \
"1" "Two line LCD with push buttons (radiod.py)" \
"2" "Four line LCD with push buttons (radio4.py)" \
"3" "Two line LCD with rotary encoders (rradiod.py)" \
"4" "Four line LCD with rotary encoders (rradio4.py)" \
"5" "Two line Adafruit LCD with push buttons (ada_radio.py)" \
"6" "Two line LCD with I2C backpack and rotary encoders (rradiobp.py)" \
"7" "Four line LCD with I2C backpack and rotary encoders (rradiobp4.py)" \
"8" "PiFace Control and Display - CAD (radio_piface.py)" \
"9" "Retro radio with rotary encoders (retro_radio.py)" 3>&1 1>&2 2>&3)
exitstatus=$?
if [[ $exitstatus != 0 ]]; then
exit 0
fi
if [[ ${ans} == '1' ]]; then
DAEMON=radiod.py
TYPE=${LCD}
DESC="Two line LCD with buttons"
elif [[ ${ans} == '2' ]]; then
DAEMON=radio4.py
TYPE=${LCD}
DESC="Four line LCD with buttons"
elif [[ ${ans} == '3' ]]; then
DAEMON=rradiod.py
TYPE=${LCD}
DESC="Two line LCD with encoders"
elif [[ ${ans} == '4' ]]; then
DAEMON=rradio4.py
TYPE=${LCD}
DESC="Four line LCD with encoders"
elif [[ ${ans} == '5' ]]; then
DAEMON=ada_radio.py
TYPE=${I2C}
DESC="AdaFruit LCD"
elif [[ ${ans} == '6' ]]; then
DAEMON=rradiobp.py
TYPE=${I2C}
BACKPACK=1
DESC="Two line LCD with I2C backpack"
elif [[ ${ans} == '7' ]]; then
DAEMON=rradiobp4.py
TYPE=${I2C}
BACKPACK=1
DESC="Four line LCD with I2C backpack"
elif [[ ${ans} == '8' ]]; then
DAEMON=radio_piface.py
TYPE=${CAD}
DESC="Piface CAD"
elif [[ ${ans} == '9' ]]; then
DAEMON=retro_radio.py
TYPE=${NODISPLAY}
DESC="Retro radio no display, "
fi
whiptail --title "$DESC ($DAEMON)" --yesno "Is this correct?" 10 60
selection=$?
done
echo "Daemon ${DAEMON} selected"
# Update the System V init script
sudo sed -i "s/^NAME=.*/NAME=${DAEMON}/g" ${INIT}
# Update systemd script
sudo sed -i "s/^ExecStart=.*/ExecStart=${BINDIR}${DAEMON} nodaemon/g" ${SERVICE}
sudo sed -i "s/^ExecStop=.*/ExecStop=${BINDIR}${DAEMON} stop/g" ${SERVICE}
# Update system startup
if [[ -x /bin/systemctl ]]; then
sudo systemctl daemon-reload
sudo systemctl enable radiod.service
else
sudo update-rc.d radiod enable
fi
# Select the backpack type
if [[ ${BACKPACK} == 1 ]]; then
sleep 2
ans=0
BPTYPE=""
while [ $ans == 0 ]
do
ans=$(whiptail --title "Select backpack type" --menu "Choose I2C backpack" 15 75 9 \
"1" "ADAFRUIT I2C backpack" \
"2" "PCF8574 I2C backpack" \
"3" "Do not change configuration" 3>&1 1>&2 2>&3)
exitstatus=$?
if [[ $exitstatus != 0 ]]; then
exit 0
fi
if [[ ${ans} == '1' ]]; then
echo "ADAFRUIT I2C backpack selected"
BPTYPE="ADAFRUIT"
elif [[ ${ans} == '2' ]]; then
echo "PCF8574 I2C backpack selected"
BPTYPE="PCF8574"
else
echo "Backpack configuration in ${CONFIG} unchanged"
fi
if [[ ${BPTYPE} != "" ]]; then
sudo sed -i "s/^i2c_backpack=.*/i2c_backpack=${BPTYPE}/g" ${CONFIG}
fi
done
fi
echo
# Pass selected daemon type to post install script
echo ${TYPE} > ${PIRADIO_TYPE}
exit 0
# End of script