Skip to content

Instantly share code, notes, and snippets.

@andriilive
Last active May 26, 2024 04:50
Show Gist options
  • Save andriilive/33dfd99705a15b7219f9563b3067a79d to your computer and use it in GitHub Desktop.
Save andriilive/33dfd99705a15b7219f9563b3067a79d to your computer and use it in GitHub Desktop.
Raspberry Pi 4 🍓Homebridge | Docker | NVM

Raspberry Pi 4 🍓Homebridge | Docker | NVM

Clean installation on Raspberry Pi OS Lite (64-bit)

⚠️ Setup Example do not use on real projects

#!/bin/bash
# Install optional packages
sudo apt install tree jq micro bat
# Install Components:
# GitHub CLI
# https://github.com/cli/cli/blob/trunk/docs/install_linux.md
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
# MarkDown in terminal
# https://github.com/charmbracelet/glow
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
sudo apt update && sudo apt install glow
# Bun Package Manager
# https://bun.sh
curl -fsSL https://bun.sh/install | bash
# Ngrok tunneling
# https://ngrok.com/download
curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list && sudo apt update && sudo apt install ngrok
# RClone Cloud Storage Sync
# https://rclone.org
sudo -v ; curl https://rclone.org/install.sh | sudo bash
# Install global node packages via nvm
# Package managers
npm install -g yarn pnpm
touch ~/.bash_aliases
cat <<EOF >> ~/.bash_aliases
alias l='ls -lha'
alias nano='micro'
EOF
# Micro config
touch -p ~/.config/micro/settings.json
cat <<EOF > ~/.config/micro/settings.json
{"keymenu": true}
EOF
# BatCat config
mkdir -p ~/.config/bat
touch ~/.config/bat/config
cat <<EOF > ~/.config/bat/config
# See: https://github.com/sharkdp/bat#configuration-file
# Options: batcat -h
--style="header,grid,header-filesize,header-filename"
EOF
# continue with script/post-install.sh
#!/bin/bash
## Only required packages install
# Update and Upgrade
sudo apt update && sudo apt upgrade -y
# Install required packages
sudo apt install git
# Node.JS (via NVM)
# https://github.com/nvm-sh/nvm#install--update-script
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
source "$HOME/.bashrc"
nvm install --lts
# Homebridge (Rootless)
# https://github.com/homebridge/homebridge/wiki/Install-Homebridge-on-Raspbian#installing-homebridge
curl -sSfL https://repo.homebridge.io/KEY.gpg | sudo gpg --dearmor | sudo tee /usr/share/keyrings/homebridge.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/homebridge.gpg] https://repo.homebridge.io stable main" | sudo tee /etc/apt/sources.list.d/homebridge.list > /dev/null
sudo apt-get update
sudo apt-get install homebridge
# Docker Installation
# https://docs.docker.com/engine/install/debian
curl -sSL https://get.docker.com | sh
# Install newuidmap & newgidmap binaries
sudo sh -eux <<EOF
apt-get install -y uidmap
EOF
# Rootless Installation
dockerd-rootless-setuptool.sh install
# Verify docker installation
docker run hello-world
# dotenvx
# https://dotenvx.com/docs/install#npm-global
npm install @dotenvx/dotenvx --global
sudo reboot
# continue with script/install.optional.sh

Composer provides an installer script written in PHP. We’ll download it, verify that it’s not corrupted, and then use it to install Composer.

Make sure you’re in your home directory, then retrieve the installer using curl:

# COMPOSER
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
echo ''
echo 'export PATH="$HOME/.composer/vendor/bin/:$PATH"' >> ~/.bashrc

# WP-CLI 
# https://wp-cli.org/#installing
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

# Completion
mkdir .bash_completion
cd .bash_completion
curl -o wp.bash https://raw.githubusercontent.com/wp-cli/wp-cli/v2.10.0/utils/wp-completion.bash

cat <<EOF >> ~/.bashrc
# BASH COMPLETION
source "\$HOME/.bash_completion/wp.bash"

EOF
#!/bin/bash
# Github Copilot CLI (requires Oauth token)
BROWSER=false gh auth login -h github.com
# fix keys permissions
chmod 700 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
# test github connection
ssh -T git@github.com
# Post-Installation
# Homebridge Update Node (Optional, recommended)
sudo hb-service update-node
sudo reboot

Noble need assistance 🙋🏻‍♂️

Need assistance with noble configuration for my setup

I’m running custom Raspberry Pi OS Lite (64-bit) with:

Homebridge

installed via Install-Homebridge-on-Raspbian, no-root

sudo hb-shell log output:

# Note: This is a restricted shell, sudo cannot be used here.
# …
# Node.js Version: v20.9.0
# Node.js Path: /opt/homebridge/bin/node
# Plugin Path: /var/lib/homebridge/node_modules
# …
# homebridge@home:/var/lib/homebridge $

NVM

Used for personal projects management.
It’s not related to Homebridge, sharing it as it's node is in the pi user's path.

# pi@home ~
$ which node
# /home/pi/.nvm/versions/node/v20.9.0/bin/node

Qestions

Noble installation

https://github.com/noble/noble#ubuntudebianraspbian

sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev

1.1 Node in the path

Noble installation requires the node binary to be in the path, I assume that the above config can lead to issues and a mess. Any suggestions on how to configure it properly?

1.2 Running without a sudo

https://github.com/noble/noble#running-without-rootsudo

The original noble docs suggest to run the following command:

sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)

It should be executed in the homebridge shell, right?


⚠️ Setup Example do not use for real projects:
https://gist.github.com/andriilive/33dfd99705a15b7219f9563b3067a79d#file-install-sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment