-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathinstall.sh
executable file
·110 lines (98 loc) · 3.19 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
#!/bin/bash
#
# Can be run for updates too.
for i in "$@"; do
case $i in
-d|--docker)
DOCKER=yes
shift
;;
-h|--help)
echo "usage: $0 [-d|--docker]"
echo " -d|--docker Bootstrap Raspberry Pi before using Docker image."
exit 0
esac
done
err_report() {
echo "[ERROR] on line $1"
exit 1
}
trap 'err_report $LINENO' ERR
DIR="$(pwd)"
check_python_version() {
# Check Python version
[[ "$DOCKER" ]] && return
echo "[INFO] Checking Python version..."
PYTHON_VERSION=$(python --version | awk '{ print $NF }')
REQUIRED_VERSION="3.8.5"
if [[ $PYTHON_VERSION != $REQUIRED_VERSION ]]; then
min=$(echo $PYTHON_VERSION $REQUIRED_VERSION| awk '{if ($1 < $2) print $1; else print $2}')
if [[ "$min" == "$PYTHON_VERSION" ]]; then
echo "[ERROR] Please install Python 3.8.5 or higher."
exit 1
fi
fi
}
git_pull() {
# Get latest code
[[ "$DOCKER" ]] && return
echo "[INFO] Retrieve app updates"
git pull | sed -e 's/^/[INFO] /g'
}
apt_get() {
[[ "$DOCKER" ]] && return
echo "[INFO] Installing apt-get packages..."
sudo apt-get -y -qq install python-usb mpg123
}
pip_install() {
[[ "$DOCKER" ]] && return
echo "[INFO] Installing Python packages..."
pip install -q -r requirements.txt
}
setup_usb() {
if [ ! -f /etc/udev/rules.d/99-lego.rules ]; then
echo "[INFO] Install USB device rules..."
[[ "$DOCKER" ]] && curl -s -O https://raw.githubusercontent.com/meltaxa/musicfig/master/99-lego.rules
sudo cp ${DIR}/99-lego.rules /etc/udev/rules.d
sudo udevadm control --reload-rules && sudo udevadm trigger
fi
}
setup_files() {
if [[ "$DOCKER" ]]; then
curl -s -O https://raw.githubusercontent.com/meltaxa/musicfig/master/config.py-sample
curl -s -O https://raw.githubusercontent.com/meltaxa/musicfig/master/tags.yml-sample
fi
if [ ! -f ${DIR}/tags.yml ]; then
echo "[INFO] Initial example ${DIR}/tags.yml created. Edit this file as tag UIDs are discovered."
cp ${DIR}/tags.yml-sample ${DIR}/tags.yml
fi
if [ ! -f ${DIR}/config.py ]; then
echo "[OPTIONAL] Edit the ${DIR}/config.py with your Spotify API app credentials before starting."
cp ${DIR}/config.py-sample ${DIR}/config.py
fi
}
install_startup() {
[[ "$DOCKER" ]] && return
# Install startup service
PYTHON_PATH=$(which python)
MUSICFIG_DIR=$(pwd)
cp musicfig.service musicfig.service-temp
sed -i "s!%MUSICFIG_DIR%!${MUSICFIG_DIR}!ig" musicfig.service-temp
sed -i "s!%PYTHON_PATH%!${PYTHON_PATH}!ig" musicfig.service-temp
sudo cp musicfig.service-temp /etc/systemd/system/musicfig.service
rm -f musicfig.service-temp
sudo chown root:root /etc/systemd/system/musicfig.service
sudo chmod 644 /etc/systemd/system/musicfig.service
sudo systemctl daemon-reload
sudo systemctl enable musicfig.service
echo "[INFO] Starting Musicfig server"
sudo systemctl restart musicfig.service
echo "[INFO] See the musicfig.log file for application logs."
}
check_python_version
git_pull
apt_get
pip_install
setup_usb
setup_files
install_startup