From d3ad26c500337cfa002eeda5c8877e11da4c6e6a Mon Sep 17 00:00:00 2001 From: Boaz Sender Date: Sun, 6 Apr 2025 17:08:27 -0700 Subject: [PATCH] improve setup script --- package.json | 2 +- setup/listener/install.sh | 85 ++++++++++++++++++++++++++------------- setup/listener/readme.md | 14 ++++++- 3 files changed, 69 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 9b21f96..4c86785 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "tsc", "deploy": "npm run build && rsync -av --exclude-from='exclude.txt' ./ grace@listener.local:portal", "setup:broadcaster": "rsync -av --exclude-from='exclude.txt' ./ grace@broadcaster.local:portal", - "setup:listener": "rsync -av --exclude-from='exclude.txt' ./ grace@listener.local:portal && ssh grace@listener.local -t 'cd portal/setup/listener && chmod +x install.sh && sudo ./install.sh; bash -l'" + "setup:listener": "rsync -av --exclude-from='exclude.txt' ./ grace@listener.local:portal && ssh grace@listener.local -t 'cd portal/setup/listener && chmod +x install.sh && ./install.sh;'" }, "repository": { "type": "git", diff --git a/setup/listener/install.sh b/setup/listener/install.sh index 6602311..830c011 100644 --- a/setup/listener/install.sh +++ b/setup/listener/install.sh @@ -1,45 +1,72 @@ -#!/bin/bash - -if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root. Try again with \n sudo ./install.sh" 1>&2 - exit 1 -fi - is_Raspberry=$(cat /proc/device-tree/model | awk '{print $1}') if [ "x${is_Raspberry}" != "xRaspberry" ] ; then echo "This script contains drivers for the Raspberry pi and will not work on the current platform." exit 1 fi -apt update -apt -y install git vim zsh mplayer +# sudo apt update +# sudo apt -y install git vim zsh mplayer +update_system() { + echo "Updating system" + sudo apt update + sudo apt dist-upgrade + sudo apt upgrade +} -curl https://get.volta.sh | bash -volta install node -cd portal -npm install -npx prisma generate && npx prisma db push && npx prisma db seed -cp ./screen.service /lib/systemd/system/ +install_volta() { + echo "Installing node@latest via volta" + sh -c "wget -qO- https://get.volta.sh | bash" + exec $SHELL + volta install node@latest +} -cp ./player.service /lib/systemd/system/ +install_screen() { + echo "Installing screen program" + cd portal + npm install + npx prisma generate && npx prisma db push && npx prisma db seed +} -git clone https://github.com/waveshare/WM8960-Audio-HAT -cd WM8960-Audio-HAT -sudo ./install.sh +install_sound_card_drivers() { + echo "Installing sound card drivers" + git clone https://github.com/waveshare/WM8960-Audio-HAT + cd WM8960-Audio-HAT + sudo ./install.sh +} -systemctl daemon-reload -systemctl enable player -systemctl enable screen -systemctl enable wm8960-soundcard.service -systemctl start player -systemctl start screen -systemctl start wm8960-soundcard +setup_daemons() { + echo "Setting up daemons" + sudo cp ./screen.service /lib/systemd/system/ + sudo cp ./player.service /lib/systemd/system/ + systemctl daemon-reload + systemctl enable player + systemctl enable screen + systemctl enable wm8960-soundcard.service + systemctl start player + systemctl start screen + systemctl start wm8960-soundcard +} + +install_ohmyzsh() { + echo "Installing oh my zsh" + sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" + echo TERM=xterm > ~/.zshrc +} -sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" +install_all() { + update_system + install_volta + install_screen + # install_sound_card_drivers + # setup_daemons + # install_ohmyzsh + # sudo reboot +} +install_all echo "------------------------------------------------------" -echo "The Black Portal listening device has been provisioned." -echo "Reboot this raspberry pi now in order for things to work" +echo "The Black Portal listening device has been setup." +echo "This raspberry pi now rebooting in order to apply changes" echo "------------------------------------------------------" \ No newline at end of file diff --git a/setup/listener/readme.md b/setup/listener/readme.md index 6f04d73..a00a1ad 100644 --- a/setup/listener/readme.md +++ b/setup/listener/readme.md @@ -10,6 +10,7 @@ Running mplayer, soundcard library, lcd graphics library, and custom python code ## Bill of Materials - Raspberry pi zero 2 wh - https://www.waveshare.com/product/raspberry-pi/boards-kits/raspberry-pi-zero-2-w-cat/raspberry-pi-zero-2-w.htm?sku=21038 +- 32GB Micro SD card - https://www.waveshare.com/raspberry-pi-sd-card.htm. - Waveshare UPS with 1000mah battery - https://www.waveshare.com/ups-hat-c.htm - Waveshare sound card hat with speakers- https://www.waveshare.com/wm8960-audio-hat.htm - 1602 LCD screen - https://www.waveshare.com/lcd1602-i2c-module-blue.htm?sku=30496 @@ -30,11 +31,18 @@ Running mplayer, soundcard library, lcd graphics library, and custom python code ## Pre work -1. Install raspian lite 64 for raspi zero. Make sure to configure user and wifi and turn on ssh services when you install. -2. Boot the pi. +You will need a micro SD card reader and computer to complete the next step. + +1. Download the raspberry pi imager from [raspberrypi.com/software](https://www.raspberrypi.com/software). +2. Install raspian lite 64 bit for raspi zero 2. + A. Make sure to configure user and wifi and turn on ssh services when you install. + B. If you don't already have an ssh key, make one with `ssh-keygen -t ed25519 -C "your_email@example.com"` and then copy it with `cat ~/.ssh/id_ed25519.pub` and paste it into the ssh service in the services section of the imager. +3. Boot the pi. ## Setup instructions +Running the setup script from the command line + ### Using node and npm If you have node and npm installed, you can run this command from inside this repository: @@ -43,6 +51,8 @@ If you have node and npm installed, you can run this command from inside this re npm run setup:listener ``` +Type "yes" when prompted to continue connecting and the press enter. + If you'd like to install node and npm try installing https://volta.sh and then running volta install node@latest. ### Using the terminal