forked from tiny-pilot/tinypilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquick-install
executable file
·163 lines (144 loc) · 4.79 KB
/
quick-install
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
#!/usr/bin/env bash
# Echo commands to stdout.
set -x
if [ -z "$TINYPILOT_INSTALL_VARS" ]
then
TINYPILOT_INSTALL_VARS=""
echo "Using default install vars"
else
echo "User-specified install vars: $TINYPILOT_INSTALL_VARS"
fi
# TODO(mtlynch): Move the TINYPILOT_INSTALL_VARS logic into
# TINYPILOT_SETTINGS_FILE vars.
# Check if this system uses the TC358743 HDMI to CSI capture bridge.
USE_TC358743_DEFAULTS=''
if [[ "$TINYPILOT_INSTALL_VARS" =~ 'ustreamer_capture_device=' ]]; then
if [[ "$TINYPILOT_INSTALL_VARS" =~ 'ustreamer_capture_device=tc358743' ]]; then
USE_TC358743_DEFAULTS='y'
fi
# Only check the existing config file if user has not set
# ustreamer_capture_device install variable.
elif [ -f /home/ustreamer/config.yml ] && grep --silent 'capture_device: "tc358743"' /home/ustreamer/config.yml; then
USE_TC358743_DEFAULTS='y'
fi
# If this system does not use a TC358743 capture chip, set defaults for any
# unset install variables.
if [ -z "$USE_TC358743_DEFAULTS" ]; then
if [[ ! "$TINYPILOT_INSTALL_VARS" =~ 'ustreamer_encoder=' ]]; then
TINYPILOT_INSTALL_VARS+=" ustreamer_encoder=hw"
fi
if [[ ! "$TINYPILOT_INSTALL_VARS" =~ 'ustreamer_format=' ]]; then
TINYPILOT_INSTALL_VARS+=" ustreamer_format=jpeg"
fi
if [[ ! "$TINYPILOT_INSTALL_VARS" =~ 'ustreamer_resolution=' ]]; then
TINYPILOT_INSTALL_VARS+=" ustreamer_resolution=1920x1080"
fi
if [[ ! "$TINYPILOT_INSTALL_VARS" =~ 'ustreamer_persistent=' ]]; then
TINYPILOT_INSTALL_VARS+=" ustreamer_persistent=true"
fi
if [[ ! "$TINYPILOT_INSTALL_VARS" =~ 'ustreamer_desired_fps=' ]]; then
TINYPILOT_INSTALL_VARS+=" ustreamer_desired_fps=30"
fi
fi
# Treat undefined environment variables as errors.
set -u
# Exit on first error.
set -e
echo "Final install vars: $TINYPILOT_INSTALL_VARS"
# Check if there's a settings file with extra installation settings.
readonly TINYPILOT_SETTINGS_FILE="/home/tinypilot/settings.yml"
EXTRA_VARS_PATH=""
if [ -f "${TINYPILOT_SETTINGS_FILE}" ]; then
echo "Using settings file at: ${TINYPILOT_SETTINGS_FILE}"
EXTRA_VARS_PATH="@${TINYPILOT_SETTINGS_FILE}"
else
echo "No pre-existing settings file found at: ${TINYPILOT_SETTINGS_FILE}"
EXTRA_VARS_PATH=""
fi
readonly EXTRA_VARS_PATH
# Check if the user is accidentally downgrading from TinyPilot Pro.
HAS_PRO_INSTALLED=0
SCRIPT_DIR="$(dirname $0)"
# If they're piping this script in from stdin, guess that TinyPilot is
# in the default location.
if [ "$SCRIPT_DIR" = "." ]; then
SCRIPT_DIR="/opt/tinypilot"
fi
# Detect TinyPilot Pro if the README file has a TinyPilot Pro header.
TINYPILOT_README="${SCRIPT_DIR}/README.md"
if [ -f "$TINYPILOT_README" ]; then
if [ "$(head -n 1 $TINYPILOT_README)" = "# TinyPilot Pro" ]; then
HAS_PRO_INSTALLED=1
fi
fi
if [ "$HAS_PRO_INSTALLED" = 1 ]; then
set +u # Don't exit if FORCE_DOWNGRADE is unset.
if [ "$FORCE_DOWNGRADE" = 1 ]; then
echo "Downgrading from TinyPilot Pro to TinyPilot Community Edition"
set -u
else
set +x
printf "You are trying to downgrade from TinyPilot Pro to TinyPilot "
printf "Community Edition.\n\n"
printf "You probably want to update to the latest version of TinyPilot "
printf "Pro instead:\n\n"
printf " /opt/tinypilot/scripts/upgrade && sudo reboot\n"
printf "\n"
printf "If you *really* want to downgrade to TinyPilot Community Edition, "
printf "type the following:\n\n"
printf " export FORCE_DOWNGRADE=1\n\n"
printf "And then run your previous command again.\n"
exit -1
fi
fi
sudo apt-get update
sudo apt-get install -y \
git \
libffi-dev \
libssl-dev \
python3-dev \
python3-venv
INSTALLER_DIR="/opt/tinypilot-updater"
sudo mkdir -p "$INSTALLER_DIR"
sudo chown "$(whoami):$(whoami)" --recursive "$INSTALLER_DIR"
pushd "$INSTALLER_DIR"
python3 -m venv venv
. venv/bin/activate
# For some reason, wheel has to be installed before anything else.
pip install wheel==0.34.2
echo 'ansible==2.9.10
cffi==1.14.4
cryptography==3.3.1
Jinja2==2.11.2
MarkupSafe==1.1.1
pkg-resources==0.0.0
pycparser==2.20
pyOpenSSL==20.0.1
PyYAML==5.3.1
six==1.15.0' > requirements.txt
pip install -r requirements.txt
echo "[defaults]
roles_path = $PWD
interpreter_python = /usr/bin/python3
" > ansible.cfg
TINYPILOT_ROLE_NAME="mtlynch.tinypilot"
if [ -d "$TINYPILOT_ROLE_NAME" ]; then
pushd "$TINYPILOT_ROLE_NAME"
git pull origin master
popd
else
TINYPILOT_ROLE_REPO="https://github.com/mtlynch/ansible-role-tinypilot.git"
git clone "$TINYPILOT_ROLE_REPO" "$TINYPILOT_ROLE_NAME"
fi
ansible-galaxy install \
--force \
--role-file "${TINYPILOT_ROLE_NAME}/requirements.yml"
echo "- hosts: localhost
connection: local
become: true
become_method: sudo
roles:
- role: $TINYPILOT_ROLE_NAME" > install.yml
ansible-playbook -i localhost, install.yml \
--extra-vars "${EXTRA_VARS_PATH}" \
--extra-vars "${TINYPILOT_INSTALL_VARS}"