-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·124 lines (104 loc) · 4.97 KB
/
install.sh
File metadata and controls
executable file
·124 lines (104 loc) · 4.97 KB
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
#!/usr/bin/env bash
set -e
if [ ! "$BASH_VERSION" ] ; then
echo "You must use bash to run this script. If running this script from curl, make sure the final word is 'bash'" 1>&2
exit 1
fi
# Check if this is a Debian-based system
if ! command -v apt-get &> /dev/null; then
echo "Error: This script is designed for Debian-based systems (Debian, Ubuntu, Raspbian, etc.)"
echo "The 'apt-get' package manager was not found on your system."
echo "Please use a Debian-based distribution to install Companion."
exit 1
fi
echo "This will attempt to install Companion as a system service on this device."
echo "It is designed to be run on headless servers, but can be used on desktop machines if you are happy to not have the tray icon."
echo "A user called 'companion' will be created to run the service, and various scripts will be installed to manage the service"
CURRENT_ARCH=$(dpkg --print-architecture)
if [[ "$CURRENT_ARCH" != "x64" && "$CURRENT_ARCH" != "amd64" && "$CURRENT_ARCH" != "arm64" ]]; then
echo "$CURRENT_ARCH is not a supported cpu architecture for running Companion."
echo "If you are running on an arm device (such as a Raspberry Pi), make sure to use an arm64 image."
exit 1
fi
# Check if system is compatible (Debian 11+ or Ubuntu 20.04+ or equivalent)
if [ -f /etc/os-release ]; then
. /etc/os-release
if [ "$ID" = "debian" ]; then
if [ "${VERSION_ID%%.*}" -lt 11 ] 2>/dev/null; then
echo "Error: This system is running Debian $VERSION_ID."
echo "Companion requires Debian 11 (Bullseye) or later."
echo "Please upgrade your system before installing Companion."
exit 1
fi
elif [ "$ID" = "ubuntu" ]; then
VERSION_NUM=$(echo "$VERSION_ID" | tr -d '.')
if [ "$VERSION_NUM" -lt 2004 ] 2>/dev/null; then
echo "Error: This system is running Ubuntu $VERSION_ID."
echo "Companion requires Ubuntu 20.04 LTS or later."
echo "Please upgrade your system before installing Companion."
exit 1
fi
else
# For other Debian derivatives, check glibc version without mentioning it
GLIBC_VERSION=$(ldd --version 2>/dev/null | head -n1 | grep -oP '\d+\.\d+$' || echo "0.0")
GLIBC_MAJOR=$(echo $GLIBC_VERSION | cut -d. -f1)
GLIBC_MINOR=$(echo $GLIBC_VERSION | cut -d. -f2)
if [ "$GLIBC_MAJOR" -lt 2 ] || ([ "$GLIBC_MAJOR" -eq 2 ] && [ "$GLIBC_MINOR" -lt 31 ]); then
echo "Error: Your system version appears to be too old to run Companion."
echo "Please ensure you are running:"
echo " - Debian 11 (Bullseye) or later"
echo " - Ubuntu 20.04 LTS or later"
echo " - Or an equivalent recent version of your distribution"
exit 1
fi
fi
fi
if [ $(/usr/bin/id -u) -ne 0 ]; then
echo "Must be run as root"
exit 1
fi
# Install a specific stable build. It is advised to not use this, as attempting to install a build that doesn't
# exist can leave your system in a broken state that needs fixing manually
COMPANION_BUILD="${COMPANION_BUILD:-beta}"
# Development only: Allow building using a testing branch of this updater
COMPANIONPI_BRANCH="${COMPANIONPI_BRANCH:-main}"
# install some dependencies
apt-get update
apt-get install -yq git zip unzip curl libusb-1.0-0-dev libudev-dev adduser wget
apt-get clean
# add a system user, if the user doesn't already exist
id -u companion &>/dev/null || adduser --disabled-password companion --gecos ""
# install fnm to manage node version
# we do this to /opt/fnm, so that the companion user can use the same installation
export FNM_DIR=/opt/fnm
echo "export FNM_DIR=/opt/fnm" >> /root/.bashrc
curl -fsSL https://fnm.vercel.app/install | bash -s -- --install-dir /opt/fnm &>/dev/null
export PATH=/opt/fnm:$PATH
eval "`fnm env --shell bash`"
# clone the companionpi repository
rm -R /usr/local/src/companionpi &>/dev/null || true
git clone https://github.com/bitfocus/companion-pi.git -b $COMPANIONPI_BRANCH /usr/local/src/companionpi
cd /usr/local/src/companionpi
# configure git for future updates
git config --global pull.rebase false
# run the update script
if [ "$COMPANION_BUILD" == "beta" ] || [ "$COMPANION_BUILD" == "experimental" ]; then
./update.sh beta
else
./update.sh stable "$COMPANION_BUILD"
fi
# install update script dependencies, as they were ignored
yarn --cwd "/usr/local/src/companionpi/update-prompt" install
# enable start on boot
systemctl enable companion
# add the fnm node to this users path
# TODO - verify permissions
echo "export PATH=/opt/fnm/aliases/default/bin:\$PATH" >> /home/companion/.bashrc
# check that a build of companion was installed
if [ ! -d "/opt/companion" ]
then
echo "No Companion build was installed!\nIt should be possible to recover from this with \"sudo companion-update\""
exit 9999 # die with error code 9999
fi
echo "Companion is installed!"
echo "You can start it with \"sudo systemctl start companion\" or \"sudo companion-update\""