Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions install/debian-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ python3-pip
avahi-daemon
libopenblas-dev
libopenjp2-7
libjpeg-dev
chromium-headless-shell
libfreetype6-dev
fonts-noto-color-emoji
swig
liblgpio-dev
libheif-dev
pkg-config
jq
127 changes: 99 additions & 28 deletions install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,33 @@ enable_interfaces(){
}

show_loader() {
local pid=$!
local message="$1"
local pid="${2:-$!}"

if [[ -z "$pid" ]]; then
echo_success "$message"
return 0
fi

local delay=0.1
local spinstr='|/-\'
printf "$1 [${spinstr:0:1}] "
while ps a | awk '{print $1}' | grep -q "${pid}"; do
printf '%s [%s] ' "$message" "${spinstr:0:1}"
while kill -0 "$pid" 2>/dev/null; do
local temp=${spinstr#?}
printf "\r$1 [${temp:0:1}] "
printf '\r%s [%s] ' "$message" "${temp:0:1}"
spinstr=${temp}${spinstr%"${temp}"}
sleep ${delay}
done
if [[ $? -eq 0 ]]; then
printf "\r$1 [\e[32m\xE2\x9C\x94\e[0m]\n"

wait "$pid"
local status=$?
if [[ $status -eq 0 ]]; then
printf '\r%s [\e[32m\xE2\x9C\x94\e[0m]\n' "$message"
else
printf "\r$1 [\e[31m\xE2\x9C\x98\e[0m]\n"
printf '\r%s [\e[31m\xE2\x9C\x98\e[0m]\n' "$message"
fi

return "$status"
}

echo_success() {
Expand All @@ -181,11 +193,30 @@ echo_blue() {

install_debian_dependencies() {
if [ -f "$APT_REQUIREMENTS_FILE" ]; then
sudo apt-get update > /dev/null &
show_loader "Fetch available system dependencies updates. "
echo "Repairing interrupted package operations (if any)."
if ! sudo dpkg --configure -a; then
echo_error "ERROR: Failed to repair interrupted dpkg state. Please run 'sudo dpkg --configure -a' manually."
exit 1
fi

if ! sudo apt-get -f install -y > /dev/null; then
echo_error "ERROR: apt failed to repair broken dependencies."
exit 1
fi

xargs -a "$APT_REQUIREMENTS_FILE" sudo apt-get install -y > /dev/null &
show_loader "Installing system dependencies. "
echo "Fetching available system dependency updates."
if ! sudo apt-get update > /dev/null; then
echo_error "ERROR: Failed to fetch package updates via apt-get update."
exit 1
fi
echo_success "\tSystem package index updated"

echo "Installing system dependencies."
if ! xargs -a "$APT_REQUIREMENTS_FILE" sudo apt-get install -y > /dev/null; then
echo_error "ERROR: Failed to install one or more system dependencies from $APT_REQUIREMENTS_FILE"
exit 1
fi
echo_success "\tSystem dependencies installed"
else
echo "ERROR: System dependencies file $APT_REQUIREMENTS_FILE not found!"
exit 1
Expand All @@ -194,29 +225,53 @@ install_debian_dependencies() {

setup_zramswap_service() {
echo "Enabling and starting zramswap service."
sudo apt-get install -y zram-tools > /dev/null
if ! sudo apt-get install -y zram-tools > /dev/null; then
echo_error "ERROR: Failed to install zram-tools."
exit 1
fi
echo -e "ALGO=zstd\nPERCENT=60" | sudo tee /etc/default/zramswap > /dev/null
sudo systemctl enable --now zramswap
if ! sudo systemctl enable --now zramswap; then
echo_error "ERROR: Failed to enable/start zramswap service."
exit 1
fi
}

setup_earlyoom_service() {
echo "Enabling and starting earlyoom service."
sudo apt-get install -y earlyoom > /dev/null
sudo systemctl enable --now earlyoom
if ! sudo apt-get install -y earlyoom > /dev/null; then
echo_error "ERROR: Failed to install earlyoom package."
exit 1
fi

if ! sudo systemctl enable --now earlyoom; then
echo_error "ERROR: Failed to enable/start earlyoom service."
exit 1
fi
}

create_venv(){
echo "Creating python virtual environment. "
python3 -m venv "$VENV_PATH"
$VENV_PATH/bin/python -m pip install --upgrade pip setuptools wheel > /dev/null
$VENV_PATH/bin/python -m pip install -r $PIP_REQUIREMENTS_FILE -qq > /dev/null &
show_loader "\tInstalling python dependencies. "
if ! $VENV_PATH/bin/python -m pip install --upgrade pip setuptools wheel > /dev/null; then
echo_error "ERROR: Failed to upgrade pip tooling inside virtual environment."
exit 1
fi

echo "Installing python dependencies."
if ! $VENV_PATH/bin/python -m pip install -r "$PIP_REQUIREMENTS_FILE" -qq > /dev/null; then
echo_error "ERROR: Failed to install Python dependencies from $PIP_REQUIREMENTS_FILE"
exit 1
fi
echo_success "\tPython dependencies installed"

# do additional dependencies for Waveshare support.
if [[ -n "$WS_TYPE" ]]; then
echo "Adding additional dependencies for waveshare to the python virtual environment. "
$VENV_PATH/bin/python -m pip install -r $WS_REQUIREMENTS_FILE > ws_pip_install.log &
show_loader "\tInstalling additional Waveshare python dependencies. "
if ! $VENV_PATH/bin/python -m pip install -r "$WS_REQUIREMENTS_FILE" > ws_pip_install.log; then
echo_error "ERROR: Failed to install Waveshare Python dependencies from $WS_REQUIREMENTS_FILE"
exit 1
fi
echo_success "\tAdditional Waveshare python dependencies installed"
fi

}
Expand Down Expand Up @@ -244,10 +299,14 @@ install_config() {
CONFIG_DIR="$SRC_PATH/config"
echo "Copying config files to $CONFIG_DIR"

# Check and copy device.config if it doesn't exist
# Check and copy device.json if it doesn't exist
if [ ! -f "$CONFIG_DIR/device.json" ]; then
cp "$CONFIG_BASE_DIR/device.json" "$CONFIG_DIR/"
show_loader "\tCopying device.config to $CONFIG_DIR"
if cp "$CONFIG_BASE_DIR/device.json" "$CONFIG_DIR/"; then
echo_success "\tCopying device.json to $CONFIG_DIR"
else
echo_error "ERROR: Failed to copy device.json to $CONFIG_DIR"
exit 1
fi
else
echo_success "\tdevice.json already exists in $CONFIG_DIR"
fi
Expand Down Expand Up @@ -283,7 +342,11 @@ stop_service() {
if /usr/bin/systemctl is-active --quiet $SERVICE_FILE
then
/usr/bin/systemctl stop $SERVICE_FILE > /dev/null &
show_loader "Stopping $APPNAME service"
local stop_pid=$!
if ! show_loader "Stopping $APPNAME service" "$stop_pid"; then
echo_error "ERROR: Failed to stop $SERVICE_FILE"
exit 1
fi
else
echo_success "\t$SERVICE_FILE not running"
fi
Expand All @@ -298,14 +361,22 @@ install_src() {
# Check if an existing installation is present
echo "Installing $APPNAME to $INSTALL_PATH"
if [[ -d $INSTALL_PATH ]]; then
rm -rf "$INSTALL_PATH" > /dev/null
show_loader "\tRemoving existing installation found at $INSTALL_PATH"
if rm -rf "$INSTALL_PATH" > /dev/null; then
echo_success "\tRemoving existing installation found at $INSTALL_PATH"
else
echo_error "ERROR: Failed to remove existing installation at $INSTALL_PATH"
exit 1
fi
fi

mkdir -p "$INSTALL_PATH"

ln -sf "$SRC_PATH" "$INSTALL_PATH/src"
show_loader "\tCreating symlink from $SRC_PATH to $INSTALL_PATH/src"
if ln -sf "$SRC_PATH" "$INSTALL_PATH/src"; then
echo_success "\tCreating symlink from $SRC_PATH to $INSTALL_PATH/src"
else
echo_error "ERROR: Failed to create symlink from $SRC_PATH to $INSTALL_PATH/src"
exit 1
fi
}

install_cli() {
Expand Down