forked from dresdner353/mpd2chromecast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·72 lines (56 loc) · 1.68 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
#!/bin/bash
# Exit on errors
set -e
# install
function install_mpd2chromecast {
cd # go to home
echo "Installing mpd2chromecast user:${USER} pwd:${HOME}"
# GIT repo
echo "Downloading mpd2chromecast..."
rm -rf mpd2chromecast
git clone https://github.com/dresdner353/mpd2chromecast.git
# Crontab
echo "Adding cron job..."
# extract any existing crontab entries, deleting refs to mpd2chromecast
crontab -l | sed -e '/mpd2chromecast/d' >/tmp/${USER}.cron
# Add in mpd2chromecast entry
echo "# mpd2chromecast keepalive, run every minute" >> /tmp/${USER}.cron
echo "* * * * * ${HOME}/mpd2chromecast/mpd2chromecast.sh keepalive > /dev/null" >> /tmp/${USER}.cron
# Overwrite crontab
crontab /tmp/${USER}.cron
# kill any remnants of the existing scripts
pkill -f mpd2chromecast.py
pkill -f mpd2chromecast.sh
}
# export function for su call
export -f install_mpd2chromecast
# main()
if [[ "`whoami`" != "root" ]]
then
echo "This script must be run as root (or with sudo)"
exit 1
fi
# Determine the variant and then non-root user
# only supports Volumio and moOde at present
VOLUMIO_CHECK=/usr/local/bin/volumio
MOODE_CHECK=/usr/local/bin/moodeutl
if [[ -f ${VOLUMIO_CHECK} ]]
then
HOME_USER=volumio
elif [[ -f ${MOODE_CHECK} ]]
then
HOME_USER=pi
else
echo "Cannot determine variant (volumio or moOde)"
exit 1
fi
echo "Detected home user:${HOME_USER}"
# install packages
apt-get update
apt-get install python3-pip
apt-get install cron
pip3 install pychromecast cherrypy python-mpd2 mutagen
# Enable cron
update-rc.d cron enable 2 3 4 5
/etc/init.d/cron restart
su ${HOME_USER} -c "bash -c install_mpd2chromecast"