-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·173 lines (143 loc) · 4.58 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
#!/bin/bash
#
# Installation framework for lightshowPi
#
# Support for each individual distribution is
INSTALL_DIR="$( cd $(dirname $0) ; pwd -P )"
BUILD_DIR=${INSTALL_DIR}/build_dir
# Globals populated below
BASE_DISTRO=
DISTRO=
# Globals populated by distro-specific scripts
INSTALL_COMMAND=
PYTHON_DEPS=
SYSTEM_DEPS=
# Set up file-based logging
exec 1> >(tee install.log)
# Root check
if [ "$EUID" -ne 0 ]; then
echo 'Install script requires root privileges!'
if [ -x /usr/bin/sudo ]; then
echo 'Switching now, enter the password for "'$USER'", if prompted.'
sudo su -c "$0 $*"
else
echo 'Switching now, enter the password for "root"!'
su root -c "$0 $*"
fi
exit $?
fi
#
# Wrapper for informational logging
# Args:
# All arguments are written to the terminal and log file
log() {
echo -ne "\e[1;34mlightshowpi \e[m" >&2
echo -e "[`date`] $@"
}
#
# Checks the return value of the last command to run
# Args:
# 1 - Message to display on failure
verify() {
if [ $? -ne 0 ]; then
echo "Encountered a fatal error: $@"
exit 1
fi
}
#
# Configure installation process based on Linux distribution
install_init() {
DISTRO=`awk -F= '$1~/^ID$/ {print $2}' /etc/os-release`
BASE_DISTRO=`awk -F= '$1=/ID_LIKE/ {print $2}' /etc/os-release`
all_supported="ls "
case $DISTRO in
archarm|raspbian)
log Configuring installation for detected distro="'$DISTRO'"
source $INSTALL_DIR/install-scripts/$DISTRO
verify "Error importing configuration from install-scripts/$DISTRO"
;;
*)
log Detected unknown distribution. Please verify that "'$DISTRO'" is supported and update this script.
log To add support for "'$DISTRO'" create a script with that name in "install-scripts"
exit 1
;;
esac
}
#
# Wrapper function to handle installation of system packages
# Args:
# 1 - Package name
pkginstall() {
log Installing $1...
$INSTALL_COMMAND $1
verify "Installation of package '$1' failed"
}
#
# Wrapper function to handle installation of Python packages
# Args:
# 1 - Package name
pipinstall() {
log Installing $1 via pip...
if [ $1 == "numpy" ]; then echo -e "\e[1;33mWARNING:\e[m numpy installation may take up to 30 minutes"; fi
/usr/bin/yes | pip3 install --upgrade $1
verify "Installation of Python package '$1' failed"
}
# Prepare the build environment
install_init
rm -rf $BUILD_DIR
mkdir -p $BUILD_DIR && cd $BUILD_DIR
# Install system dependencies
log Preparing to install ${#SYSTEM_DEPS[@]} packages on your system...
for _dep in ${SYSTEM_DEPS[@]}; do
pkginstall $_dep;
done
# Some symlinks that will make life a little easier
# Note that this may (intentionally) clobber Python 3 symlinks in newer OS's
mv /usr/bin/python /usr/bin/python2
mv /usr/bin/pip /usr/bin/pip2
ln -fs `which python3` /usr/bin/python
ln -fs `which pip3` /usr/bin/pip
# Install decoder
log Installing decoder...
pip3 install --upgrade git+https://[email protected]/broken2048/decoder-v3.py.git
verify "Installation of decoder-1.5XB-Unix failed"
# Install Python dependencies
log Preparing to install ${#PYTHON_DEPS[@]} python packages on your system...
for _dep in ${PYTHON_DEPS[@]}; do
pipinstall $_dep;
done
log Installing rpi-audio-levels...
pip3 install git+https://[email protected]/broken2048/rpi-audio-levels.git
verify "Installation of rpi-audio-levels failed"
# Install pygooglevoice
log Installing pygooglevoice...
pip3 install --upgrade git+https://github.com/pettazz/pygooglevoice.git
verify "Installation of pygooglevoice failed"
# Install wiringpipy
log Installing wiringpipy...
pip3 install --upgrade git+https://[email protected]/broken2048/wiringpipy.git
verify "Installation of wiringpipy failed"
# Optionally add a line to /etc/sudoers
if [ -f /etc/sudoers ]; then
KEEP_EN="Defaults env_keep="SYNCHRONIZED_LIGHTS_HOME""
grep -q "$KEEP_EN" /etc/sudoers
if [ $? -ne 0 ]; then
echo "$KEEP_EN" >> /etc/sudoers
fi
fi
# Set up environment variables
cat <<EOF >/etc/profile.d/lightshowpi.sh
# Lightshow Pi Home
export SYNCHRONIZED_LIGHTS_HOME=${INSTALL_DIR}
# Add Lightshow Pi bin directory to path
export PATH=\$PATH:${INSTALL_DIR}/bin
EOF
# Clean up after ourselves
cd ${INSTALL_DIR} && rm -rf ${BUILD_DIR}
# Print some instructions to the user
cat <<EOF
All done! Reboot your Raspberry Pi before running lightshowPi.
Run the following command to test your installation and hardware setup:
sudo python $INSTALL_DIR/py/hardware_controller.py --state=flash
EOF
exit 0