-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathinstall.sh
executable file
·216 lines (184 loc) · 5.76 KB
/
install.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
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
#!/bin/bash
DATESTAMP=`date "+%Y-%m-%d-%H-%M-%S"`
MOPIDY_CONFIG="/etc/mopidy/mopidy.conf"
MOPIDY_SUDOERS="/etc/sudoers.d/010_mopidy-nopasswd"
EXISTING_CONFIG=false
PYTHON_MAJOR_VERSION=3
PIP_BIN=pip3
function add_to_config_text {
CONFIG_LINE="$1"
CONFIG="$2"
sed -i "s/^#$CONFIG_LINE/$CONFIG_LINE/" $CONFIG
if ! grep -q "$CONFIG_LINE" $CONFIG; then
printf "$CONFIG_LINE\n" >> $CONFIG
fi
}
success() {
echo -e "$(tput setaf 2)$1$(tput sgr0)"
}
inform() {
echo -e "$(tput setaf 6)$1$(tput sgr0)"
}
warning() {
echo -e "$(tput setaf 1)$1$(tput sgr0)"
}
# Update apt and install dependencies
inform "Updating apt and installing dependencies"
apt update
apt install -y python3-rpi.gpio python3-spidev python3-pip python3-pil python3-numpy libopenjp2-7
echo
# Verify python version via pip
inform "Verifying python $PYTHON_MAJOR_VERSION.x version"
PIP_CHECK="$PIP_BIN --version"
VERSION=`$PIP_CHECK | sed s/^.*\(python[\ ]*// | sed s/.$//`
RESULT=$?
if [ "$RESULT" == "0" ]; then
MAJOR_VERSION=`echo $VERSION | awk -F. {'print $1'}`
if [ "$MAJOR_VERSION" -eq "$PYTHON_MAJOR_VERSION" ]; then
success "Found Python $VERSION"
else
warning "error: installation requires pip for Python $PYTHON_MAJOR_VERSION.x, Python $VERSION found."
echo
exit 1
fi
else
warning "error: \`$PIP_CHECK\` failed to execute successfully"
echo
exit 1
fi
echo
# Stop mopidy if running
systemctl status mopidy > /dev/null 2>&1
RESULT=$?
if [ "$RESULT" == "0" ]; then
inform "Stopping Mopidy service..."
systemctl stop mopidy
echo
fi
# Enable SPI
raspi-config nonint do_spi 0
# Add necessary lines to config.txt (if they don't exist)
add_to_config_text "gpio=25=op,dh" /boot/config.txt
add_to_config_text "dtoverlay=hifiberry-dac" /boot/config.txt
if [ -f "$MOPIDY_CONFIG" ]; then
inform "Backing up mopidy config to: $MOPIDY_CONFIG.backup-$DATESTAMP"
cp "$MOPIDY_CONFIG" "$MOPIDY_CONFIG.backup-$DATESTAMP"
EXISTING_CONFIG=true
echo
fi
# Install apt list for Mopidy, see: https://docs.mopidy.com/en/latest/installation/debian/.
if [ ! -f "/etc/apt/sources.list.d/mopidy.list" ]; then
inform "Adding Mopidy apt source"
mkdir -p /etc/apt/keyrings
wget -q -O /etc/apt/keyrings/mopidy-archive-keyring.gpg \
https://apt.mopidy.com/mopidy.gpg
wget -q -O /etc/apt/sources.list.d/mopidy.list https://apt.mopidy.com/bullseye.list
apt update
echo
fi
# Install Mopidy and core plugins for Spotify
inform "Installing mopidy packages"
apt-mark unhold mopidy
apt install -y mopidy
echo
# Install Mopidy Iris web UI
inform "Installing Iris web UI for Mopidy"
$PIP_BIN install --upgrade mopidy-iris
echo
# Allow Iris to run its system.sh script for https://github.com/pimoroni/pirate-audio/issues/3
# This script backs Iris UI buttons for local scan and server restart.
# Get location of Iris's system.sh
MOPIDY_SYSTEM_SH=`python$PYTHON_MAJOR_VERSION - <<EOF
import pkg_resources
distribution = pkg_resources.get_distribution('mopidy_iris')
print(f"{distribution.location}/mopidy_iris/system.sh")
EOF`
# Add it to sudoers
if [ "$MOPIDY_SYSTEM_SH" == "" ]; then
warning "Could not find system.sh path for mopidy_iris using python$PYTHON_MAJOR_VERSION"
warning "Refusing to edit $MOPIDY_SUDOERS with empty system.sh path!"
else
inform "Adding $MOPIDY_SYSTEM_SH to $MOPIDY_SUDOERS"
echo "mopidy ALL=NOPASSWD: $MOPIDY_SYSTEM_SH" > $MOPIDY_SUDOERS
echo
fi
# Install support plugins for Pirate Audio
inform "Installing Pirate Audio plugins..."
$PIP_BIN install --upgrade Mopidy-PiDi Mopidy-Local pidi-display-pil pidi-display-st7789 mopidy-raspberry-gpio
echo
# Reset mopidy.conf to its default state
if [ $EXISTING_CONFIG ]; then
warning "Resetting $MOPIDY_CONFIG to package defaults."
inform "Any custom settings have been backed up to $MOPIDY_CONFIG.backup-$DATESTAMP"
apt install --reinstall -o Dpkg::Options::="--force-confask,confnew,confmiss" mopidy=$MOPIDY_VERSION > /dev/null 2>&1
echo
fi
# Append Pirate Audio specific defaults to mopidy.conf
# Updated to only change necessary values, as per: https://github.com/pimoroni/pirate-audio/issues/1
# Updated to *append* config values to mopidy.conf, as per: https://github.com/pimoroni/pirate-audio/issues/1#issuecomment-557556802
inform "Configuring Mopidy"
cat <<EOF >> $MOPIDY_CONFIG
[raspberry-gpio]
enabled = true
bcm5 = play_pause,active_low,250
bcm6 = volume_down,active_low,250
bcm16 = next,active_low,250
bcm20 = volume_up,active_low,250
bcm24 = volume_up,active_low,250
[file]
enabled = true
media_dirs = /home/pi/Music
show_dotfiles = false
excluded_file_extensions =
.directory
.html
.jpeg
.jpg
.log
.nfo
.pdf
.png
.txt
.zip
follow_symlinks = false
metadata_timeout = 1000
[pidi]
enabled = true
display = st7789
rotation = 90
[mpd]
hostname = 0.0.0.0
[http]
hostname = 0.0.0.0
[audio]
mixer_volume = 40
output = alsasink device=hw:sndrpihifiberry
[spotify]
enabled = false
username =
password =
client_id =
client_secret =
EOF
echo
# MAYBE?: Remove the sources.list to avoid any future issues with apt.mopidy.com failing
# rm -f /etc/apt/sources.list.d/mopidy.list
usermod -a -G spi,i2c,gpio,video mopidy
inform "Enabling and starting Mopidy"
sudo systemctl enable mopidy
sudo systemctl restart mopidy
echo
success "All done!"
if [ $EXISTING_CONFIG ]; then
diff $MOPIDY_CONFIG $MOPIDY_CONFIG.backup-$DATESTAMP > /dev/null 2>&1
RESULT=$?
if [ ! $RESULT == "0" ]; then
warning "Mopidy configuration has changed, see summary below and make sure to update $MOPIDY_CONFIG!"
inform "Your previous configuration was backed up to $MOPIDY_CONFIG.backup-$DATESTAMP"
diff $MOPIDY_CONFIG $MOPIDY_CONFIG.backup-$DATESTAMP
else
echo "Don't forget to edit $MOPIDY_CONFIG with your preferences and/or Spotify config."
fi
else
echo "Don't forget to edit $MOPIDY_CONFIG with you preferences and/or Spotify config."
fi