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
/
piradio.postinst
220 lines (185 loc) · 5.92 KB
/
piradio.postinst
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/bin/bash
set -e
# Radio daemon post install script
# $Id: piradio.postinst,v 1.57 2017/08/27 08:16:34 bob Exp $
# Support for Pulseaudio added
# File locations
DIR=/usr/share/radio
RADIOLIB=/var/lib/radiod
INITTAB=/etc/inittab
BOOTCMD=/boot/cmdline.txt
MODULES=/etc/modules
MPDCONF=/etc/mpd.conf
VOICEDIST=voice.dist
LANGUAGEFILE=language/language.en
RSSFILE=rss/rss
CONFIGFILE=/etc/radiod.conf
DEFAULTRCS=/etc/default/rcS
# The following is set up in the select_daemon.sh program
PIRADIO_TYPE=${RADIOLIB}/piradio_type
# Display types
LCD=1 # LCD screen (direct)
I2C=2 # Uses I2C libraries
CAD=3 # PiFace control and display
NODISPLAY=4 # Retro radio with no display
# Check if the script is being run as root
if [[ $EUID -ne 0 ]]
then
printf 'This script must be run using sudo.\nExiting..\n'
exit 1
fi
# Set up a default radio variant
sudo mkdir -p ${RADIOLIB}
sudo echo 1 > ${PIRADIO_TYPE}
# Set daemon startup defaults
update-rc.d radiod defaults
update-rc.d -f pifacercd defaults
update-rc.d -f shairport-sync defaults
# Ensure owner is pi
sudo chown -R pi:pi ${DIR}
sudo chmod +x ${DIR}/*.py
sudo chmod +x ${DIR}/*.sh
# Create configuration file in /etc
if [[ ! -f ${CONFIGFILE} ]]; then
sudo cp -f ${DIR}/radiod.conf ${CONFIGFILE}
fi
# Set up radio daemon
${DIR}/select_daemon.sh
if [[ $? != 0 ]]; then
echo "${DIR}/select_daemon.sh script failed"
exit 1
fi
TYPE=$(cat ${PIRADIO_TYPE})
rm -f ${PIRADIO_TYPE}
# Disable serial interface (reboot required)
if [[ ${TYPE} -eq ${LCD} || ${TYPE} -eq ${NODISPLAY} ]]; then
if [[ ! -f ${INITTAB}.orig && -f ${INITTAB} ]]; then
echo "Disabling serial interface in ${INITTAB}"
sudo cp -f ${INITTAB} ${INITTAB}.orig
OLDENTRY="T0\:23\:respawn\:\/sbin\/getty -L ttyAMA0"
NEWENTRY="\#T0\:23:respawn\:\/sbin\/getty -L ttyAMA0 115200 vt100"
sudo sed -i "s/^${OLDENTRY}.*/${NEWENTRY}/g" ${INITTAB}
echo "# Original file stored as ${INITTAB}.orig" >> ${INITTAB}
fi
echo "Disabling serial interface in ${BOOTCMD}"
if [[ ! -f ${BOOTCMD}.orig ]]; then
sudo cp -f ${BOOTCMD} ${BOOTCMD}.orig
echo "# Original file stored as ${BOOTCMD}.orig" >> ${BOOTCMD}
fi
OLDENTRY="console=ttyAMA0,115200 "
sudo sed -i "s/${OLDENTRY}//g" ${BOOTCMD}
OLDENTRY="kgdboc=ttyAMA0,115200 "
sudo sed -i "s/${OLDENTRY}//g" ${BOOTCMD}
REBOOT=1
elif [[ ${TYPE} -eq ${I2C} ]]; then
# Restore original moules file
if [[ -f ${MODULES}.orig ]]; then
sudo cp -fp ${MODULES}.orig ${MODULES}
else
sudo cp -fp ${MODULES} ${MODULES}.orig
fi
echo "i2c-bcm2708" >> ${MODULES}
echo "i2c-dev" >> ${MODULES}
echo "# Original file stored as ${MODULES}.orig" >> ${MODULES}
echo "Updated ${MODULES}"
else
echo "No radio daemon selected"
echo "Run ${DIR}/select_daemon.sh at the end of this installation"
fi
# Configure the MPD daemon
if [[ ! -f ${MPDCONF}.orig ]]; then
echo "Modifying ${MPDCONF}"
sudo cp -fp ${MPDCONF} ${MPDCONF}.orig
# Bind to any address
OLDENTRY="bind_to_address"
NEWENTRY="bind_to_address \"any\""
sudo sed -i "s/^${OLDENTRY}.*/${NEWENTRY}/g" ${MPDCONF}
# Disable zeroconf
OLDENTRY="\#zeroconf_enabled.*"
NEWENTRY="zeroconf_enabled \"no\""
# Add note to the end of file
sudo sed -i "s/^${OLDENTRY}.*/${NEWENTRY}/g" ${MPDCONF}
echo "# Original file stored as ${MPDCONF}.orig" >> ${MPDCONF}
fi
# Disable mpd on startup
sudo update-rc.d -f mpd disable
# Go to radio directory
cd ${DIR}
# Copy espeak command to the radio lib directory
if [[ ! -f "${RADIOLIB}/voice" ]]; then
echo "Copying ${VOICEDIST} to ${RADIOLIB}/voice"
mkdir -p ${RADIOLIB}
cp -f ${VOICEDIST} ${RADIOLIB}/voice
fi
# Copy language file
if [[ ! -f "${RADIOLIB}/language" ]]; then
echo "Copying ${LANGUAGEFILE} to ${RADIOLIB}/language"
mkdir -p ${RADIOLIB}
cp -f ${LANGUAGEFILE} ${RADIOLIB}/language
fi
# Copy RSS file
if [[ ! -f "${RADIOLIB}/rss" ]]; then
echo "Copying ${RSSFILE} to ${RADIOLIB}/rss"
mkdir -p ${RADIOLIB}
cp -f ${RSSFILE} ${RADIOLIB}/rss
fi
# Create playlists if no station list present
if [[ ! -f "${RADIOLIB}/stationlist" ]]; then
echo "Creating playlists:"
echo "This will take a few minutes"
${DIR}/create_m3u.py --no_delete 2>&1 > ${DIR}/playlists.log
echo "Done: See ${DIR}/playlists.log for information about playlists created"
echo
fi
echo
echo "PI Radio software successfully installed"
echo "See /usr/share/doc/radiod/README for release information"
echo
if [[ ${TYPE} -eq ${I2C} ]]; then
echo "Configured to use I2C libraries"
${DIR}/run_raspi-config.sh ${I2C}
# Check to see if the python-smbus is already installed
dpkg -l python-smbus > /dev/null 2>&1
if [[ $? > 0 ]]; then # Don't seperate from above
echo "It is necessary to install the I2C libraries"
echo "Carry out the following command:"
echo " sudo apt-get install python-smbus"
echo "and reboot the system"
REBOOT=0
else
REBOOT=1
fi
elif [[ ${TYPE} -eq ${CAD} ]]; then
# Check to see if the python-pifacecommon is already installed
echo "Configured to use PiFace CAD"
${DIR}/run_raspi-config.sh ${CAD}
dpkg -l python-pifacecommon > /dev/null 2>&1
if [[ $? > 0 ]]; then # Don't seperate from above
echo "It is necessary to install the SPI libraries for PiFace CAD"
echo "Carry out the following command:"
echo " sudo apt-get install python{,3}-pifacecad"
echo "and reboot the system"
REBOOT=0
else
REBOOT=1
fi
fi
# Force file checks on reboot
if [[ ! -f ${DEFAULTRCS}.orig && -f ${DEFAULTRCS}.orig ]]; then
sudo cp -f -p ${DEFAULTRCS} ${DEFAULTRCS}.orig
sudo sed -i -e 's/\#FSCKFIX=no/FSCKFIX=yes/' ${DEFAULTRCS}
fi
# Install shairport-sync and metadata reader
#sudo install bin/shairport-sync /usr/local/bin
#sudo install bin/shairport-sync-metadata-reader /usr/local/bin
# Move old radio directory
if [[ -d /home/pi/radio ]]; then
mv -f /home/pi/radio /home/pi/radio_old
fi
ln -fs /usr/share/radio /home/pi/radio
echo "Installation complete"
if [[ REBOOT -eq 1 ]]; then
echo "It is necessary to reboot the system to start the radio"
fi
exit 0
# End of post-installation script