Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 6f64ae9

Browse files
authored
Setup script refactor (#82), fixes #60, fixes #79
* modularized and generalized, cleanup * config: renamed ProductID to Device_Type_ID * support for Arch Linux (instructions by @maso27) * support for currently supported boards in AlexaPI (GPIO libs install, etc) * added unit overrides for various things * set up GPIO permissions (udev) * use pip instead of system packaging where possible * disabled pip cache due to pypa/pip#2984 * change default device_platform to dummy * set device-specific config on install
1 parent 852a572 commit 6f64ae9

15 files changed

+309
-113
lines changed

src/auth_web.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Start(object):
2020
def index(self):
2121
sd = json.dumps({
2222
"alexa:all": {
23-
"productID": config['alexa']['ProductID'],
23+
"productID": config['alexa']['Device_Type_ID'],
2424
"productInstanceAttributes": {
2525
"deviceSerialNumber": "001"
2626
}

src/config.template.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ sound:
1818
alexa:
1919
Client_ID:
2020
Client_Secret:
21-
ProductID:
21+
Device_Type_ID:
2222
Security_Profile_Description:
2323
Security_Profile_ID:
2424
refresh_token:
@@ -28,7 +28,7 @@ sphinx:
2828

2929
platform:
3030
# Name of your platform, e.g. raspberrypi, orangepi, desktop
31-
device: "raspberrypi"
31+
device: "dummy"
3232

3333
platforms:
3434
# common config for all platforms (if they support the options)

src/dev-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
fakeRPiGPIO
2-
git+https://github.com/oaubert/python-vlc.git
32
-e git+https://github.com/xtacocorex/CHIP_IO.git#egg=CHIP_IO
43
pylint

src/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ python-memcached>=1.50
33
requests>=2.4.3
44
wsgiref>=0.1.2
55
CherryPy>=4.0.0
6-
python-vlc>=1.1.2
6+
git+https://github.com/oaubert/python-vlc.git#egg=python-vlc
77
pyalsaaudio>=0.8.2
88
py-getch>=1.0.1
9-
pocketsphinx>=0.1.3
109
webrtcvad>=2.0.7
1110
pyyaml
11+
pocketsphinx>=0.1.3

src/scripts/inc/archlinux.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
function install_os {
4+
pacman -Sy
5+
pacman -S git python2 python2-pip swig alsa-lib alsa-utils libpulse vlc memcached gcc --noconfirm --needed
6+
7+
install -Dm644 ./unit-overrides/force-python2.conf /etc/systemd/system/AlexaPi.service.d/force-python2.conf
8+
systemctl daemon-reload
9+
systemctl enable memcached
10+
}
11+
12+
function install_shairport-sync {
13+
pacman -S shairport-sync --noconfirm --needed
14+
}

src/scripts/inc/chip.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
function install_device {
4+
run_pip install git+https://github.com/xtacocorex/CHIP_IO.git
5+
}
6+
7+
function install_device_config {
8+
config_set 'output_device' 'plughw:1'
9+
10+
handle_root_platform 'chip'
11+
}

src/scripts/inc/common.sh

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/bin/bash
2+
3+
TMP_DIR="/tmp"
4+
RUN_USER="alexapi"
5+
HOME_DIR="/var/lib/AlexaPi"
6+
7+
function run_python {
8+
$(which python2) $@
9+
}
10+
11+
function run_pip {
12+
$(which pip2) $@
13+
}
14+
15+
function init_classic {
16+
local monitorAlexa=${1}
17+
18+
install -Dm744 initd_alexa.sh /etc/init.d/AlexaPi
19+
20+
mkdir -p /etc/opt/AlexaPi
21+
touch /etc/opt/AlexaPi/.keep
22+
if [ "$monitorAlexa" == true ]; then
23+
touch /etc/opt/AlexaPi/monitor_enable
24+
fi
25+
26+
touch /var/log/AlexaPi.log
27+
28+
update-rc.d AlexaPi defaults
29+
}
30+
31+
function init_systemd {
32+
local monitorAlexa=${1}
33+
34+
install -Dm644 ./AlexaPi.service /usr/lib/systemd/system/AlexaPi.service
35+
mkdir -p /etc/systemd/system/AlexaPi.service.d/
36+
37+
if [ "$monitorAlexa" == true ]; then
38+
install -Dm644 ./unit-overrides/restart.conf /etc/systemd/system/AlexaPi.service.d/restart.conf
39+
fi
40+
41+
systemctl daemon-reload
42+
systemctl enable AlexaPi.service
43+
}
44+
45+
function create_user {
46+
47+
echo -n "Creating a user to run AlexaPi under ... "
48+
UID_TEST=`id -u ${RUN_USER} >/dev/null 2>&1`
49+
UID_TEST="$?"
50+
51+
if [ ${UID_TEST} -eq 0 ]; then
52+
echo "user already exists. That's cool - using that."
53+
else
54+
useradd --system --user-group ${RUN_USER} 2>/dev/null
55+
56+
if [ "$?" -eq "0" ]; then
57+
echo "done."
58+
else
59+
echo "unknown error. useradd returned code $?."
60+
fi
61+
62+
mkdir -p ${HOME_DIR}
63+
chown ${RUN_USER}:${RUN_USER} ${HOME_DIR}
64+
usermod --home ${HOME_DIR} ${RUN_USER}
65+
fi
66+
67+
getent group gpio || groupadd gpio
68+
getent group audio || groupadd audio
69+
70+
gpasswd -a ${RUN_USER} gpio > /dev/null
71+
gpasswd -a ${RUN_USER} audio > /dev/null
72+
73+
}
74+
75+
function gpio_permissions {
76+
77+
local rulesFile="/etc/udev/rules.d/99-gpio.rules"
78+
79+
if [ ! -f ${rulesFile} ]; then
80+
cat >${rulesFile} <<EOL
81+
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c '\
82+
chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;\
83+
chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio;\
84+
chown -R root:gpio /sys$devpath && chmod -R 770 /sys$devpath\
85+
'"
86+
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"
87+
EOL
88+
fi
89+
90+
}
91+
92+
function install_shairport-sync_from_source {
93+
94+
cd ${TMP_DIR}
95+
96+
git clone https://github.com/mikebrady/shairport-sync.git
97+
cd shairport-sync
98+
autoreconf -i -f
99+
./configure --with-alsa --with-avahi --with-ssl=openssl --with-soxr --with-metadata --with-pipe --with-systemd
100+
make
101+
getent group shairport-sync &>/dev/null || sudo groupadd -r shairport-sync >/dev/null
102+
getent passwd shairport-sync &> /dev/null || sudo useradd -r -M -g shairport-sync -s /usr/bin/nologin -G audio shairport-sync >/dev/null
103+
make install
104+
105+
rm -rf ${TMP_DIR}/shairport-sync
106+
107+
}
108+
109+
# global variable $CONFIG_FILE
110+
function config_get {
111+
grep -o -P "(?<=${1}:).*" ${CONFIG_FILE} | sed 's/^ *//;s/ *$//;s/"//g'
112+
}
113+
114+
# $1 field name
115+
# $2 user input
116+
# global array config_defaults
117+
# global variable $CONFIG_FILE
118+
function config_set {
119+
local name=${1}
120+
local value=${2}
121+
122+
if [ "${value}" == "" ]; then
123+
value="${config_defaults[${name}]}"
124+
fi
125+
sed -i -e 's/'"${name}"'.*/'"${name}"': "'"${value}"'"/g' ${CONFIG_FILE}
126+
}
127+
128+
function handle_root_platform {
129+
echo "Unfortunately, to use LEDs or trigger button on this platform (${1}) you have to"
130+
echo "a) run AlexaPi as root"
131+
echo "b) and switch the device platform in the configuration file."
132+
echo "If you wish to do that, please see the section in our wiki for instructions: https://github.com/alexa-pi/AlexaPi/wiki/Devices"
133+
}

src/scripts/inc/debian.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
function install_os {
4+
apt-get update
5+
apt-get install git python-dev python-setuptools python-pip swig libasound2-dev libpulse-dev vlc-nox memcached -y
6+
}
7+
8+
function install_shairport-sync {
9+
10+
apt-get install autoconf libdaemon-dev libasound2-dev libpopt-dev libconfig-dev avahi-daemon libavahi-client-dev libssl-dev libsoxr-dev -y
11+
12+
install_shairport-sync_from_source
13+
}

src/scripts/inc/orangepi.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
function install_device {
4+
run_pip install git+https://github.com/duxingkei33/orangepi_PC_gpio_pyH3.git
5+
}
6+
7+
function install_device_config {
8+
config_set 'input_device' 'default'
9+
10+
handle_root_platform 'orangepi'
11+
}

src/scripts/inc/raspberrypi.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
function install_device {
4+
run_pip install RPi.GPIO
5+
6+
local rulesFile="/etc/udev/rules.d/99-gpio.rules"
7+
8+
grep "bcm2835-gpiomem" ${rulesFile} || cat >>${rulesFile} <<EOL
9+
SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
10+
EOL
11+
}
12+
13+
function install_device_config {
14+
config_set 'device' 'raspberrypi'
15+
}

src/scripts/monitorAlexa.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)