install.sh 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  1. #!/usr/bin/env bash
  2. #
  3. # SpoolBuddy Installation Script for Raspberry Pi
  4. #
  5. # Supports two scenarios:
  6. # 1) SpoolBuddy only — NFC/scale companion connecting to a remote Bambuddy instance
  7. # 2) SpoolBuddy + Bambuddy — both running natively on this Raspberry Pi
  8. #
  9. # Usage:
  10. # Interactive: curl -fsSL https://raw.githubusercontent.com/maziggy/bambuddy/main/spoolbuddy/install.sh -o install.sh && chmod +x install.sh && sudo ./install.sh
  11. # Unattended: sudo ./install.sh --mode spoolbuddy --bambuddy-url http://192.168.1.100:8000 --api-key bb_xxx --yes
  12. #
  13. # Options:
  14. # --mode MODE Installation mode: "spoolbuddy" (companion only) or "full" (both)
  15. # --bambuddy-url URL Bambuddy server URL (required for spoolbuddy mode)
  16. # --api-key KEY Bambuddy API key (required for spoolbuddy mode)
  17. # --path PATH Installation directory (default: /opt/spoolbuddy or /opt/bambuddy)
  18. # --port PORT Bambuddy port (full mode only, default: 8000)
  19. # --ssh-pubkey KEY Bambuddy SSH public key for remote updates
  20. # --yes, -y Non-interactive mode, accept defaults
  21. # --help, -h Show this help message
  22. #
  23. set -e
  24. # ─────────────────────────────────────────────────────────────────────────────
  25. # Constants
  26. # ─────────────────────────────────────────────────────────────────────────────
  27. RED='\033[0;31m'
  28. GREEN='\033[0;32m'
  29. YELLOW='\033[1;33m'
  30. CYAN='\033[0;36m'
  31. BOLD='\033[1m'
  32. NC='\033[0m'
  33. GITHUB_REPO="https://github.com/maziggy/bambuddy.git"
  34. SPOOLBUDDY_SERVICE_USER="spoolbuddy"
  35. BAMBUDDY_SERVICE_USER="bambuddy"
  36. # Packages needed for SpoolBuddy hardware (NFC reader + scale)
  37. SYSTEM_PACKAGES="python3 python3-pip python3-venv python3-dev python3-spidev python3-libgpiod gpiod libgpiod-dev i2c-tools git"
  38. # Python packages for SpoolBuddy daemon
  39. SPOOLBUDDY_PIP_PACKAGES="spidev gpiod smbus2 httpx"
  40. # ─────────────────────────────────────────────────────────────────────────────
  41. # Variables (set by args or prompts)
  42. # ─────────────────────────────────────────────────────────────────────────────
  43. INSTALL_MODE="" # "spoolbuddy" or "full"
  44. INSTALL_PATH=""
  45. BAMBUDDY_URL=""
  46. API_KEY=""
  47. BAMBUDDY_PORT="8000"
  48. NON_INTERACTIVE="false"
  49. REBOOT_NEEDED="false"
  50. KIOSK_USER="" # auto-detected from $SUDO_USER
  51. KIOSK_URL="" # derived from $BAMBUDDY_URL/spoolbuddy?token=$API_KEY
  52. SSH_PUBKEY="" # Bambuddy's SSH public key for remote updates
  53. # ─────────────────────────────────────────────────────────────────────────────
  54. # Helpers
  55. # ─────────────────────────────────────────────────────────────────────────────
  56. info() { echo -e "${CYAN}[INFO]${NC} $1"; }
  57. success() { echo -e "${GREEN}[OK]${NC} $1"; }
  58. warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
  59. error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; }
  60. # Run a long-running command with a spinner + live progress output.
  61. # Usage: run_with_progress "description" command [args...]
  62. run_with_progress() {
  63. local desc="$1"
  64. shift
  65. local log_file
  66. log_file=$(mktemp /tmp/spoolbuddy-install.XXXXXX)
  67. local start_time=$SECONDS
  68. # Run command in background, capture stdout+stderr
  69. "$@" > "$log_file" 2>&1 &
  70. local pid=$!
  71. # Spinner frames (braille pattern)
  72. local -a spin=("⠋" "⠙" "⠹" "⠸" "⠼" "⠴" "⠦" "⠧" "⠇" "⠏")
  73. local i=0
  74. while kill -0 "$pid" 2>/dev/null; do
  75. local elapsed=$(( SECONDS - start_time ))
  76. local time_str
  77. if (( elapsed >= 60 )); then
  78. time_str="$(( elapsed / 60 ))m$(printf '%02d' $(( elapsed % 60 )))s"
  79. else
  80. time_str="${elapsed}s"
  81. fi
  82. # Last chunk of output (handles \r progress lines and regular \n lines)
  83. local last_line=""
  84. last_line=$(tail -c 4096 "$log_file" 2>/dev/null | tr '\r' '\n' | sed 's/\x1b\[[0-9;]*[mGKHJ]//g' | sed '/^[[:space:]]*$/d' | tail -1 | sed 's/^[[:space:]]*//' | cut -c1-50) || true
  85. printf "\r ${spin[$((i % 10))]} %-36s ${CYAN}%6s${NC} %s\033[K" "$desc" "$time_str" "$last_line"
  86. i=$(( i + 1 ))
  87. sleep 0.15
  88. done
  89. local exit_code=0
  90. wait "$pid" || exit_code=$?
  91. # Clear spinner line
  92. printf "\r\033[K"
  93. # Format elapsed time for summary
  94. local elapsed=$(( SECONDS - start_time ))
  95. local time_suffix=""
  96. if (( elapsed >= 60 )); then
  97. time_suffix=" ($(( elapsed / 60 ))m $(( elapsed % 60 ))s)"
  98. elif (( elapsed >= 5 )); then
  99. time_suffix=" (${elapsed}s)"
  100. fi
  101. if [[ $exit_code -eq 0 ]]; then
  102. success "${desc}${time_suffix}"
  103. rm -f "$log_file"
  104. else
  105. echo -e "${RED}[FAIL]${NC} ${desc}${time_suffix}"
  106. echo ""
  107. echo -e " ${YELLOW}Last 20 lines:${NC}"
  108. tail -20 "$log_file" 2>/dev/null | sed 's/^/ /'
  109. echo ""
  110. echo -e " Full log: ${CYAN}$log_file${NC}"
  111. exit 1
  112. fi
  113. }
  114. prompt() {
  115. local prompt_text="$1"
  116. local default_value="$2"
  117. local var_name="$3"
  118. if [[ "$NON_INTERACTIVE" == "true" ]]; then
  119. eval "$var_name=\"$default_value\""
  120. return
  121. fi
  122. if [[ -n "$default_value" ]]; then
  123. echo -en "${BOLD}$prompt_text${NC} [${CYAN}$default_value${NC}]: "
  124. else
  125. echo -en "${BOLD}$prompt_text${NC}: "
  126. fi
  127. read -r input
  128. if [[ -z "$input" ]]; then
  129. eval "$var_name=\"$default_value\""
  130. else
  131. eval "$var_name=\"$input\""
  132. fi
  133. }
  134. prompt_yes_no() {
  135. local prompt_text="$1"
  136. local default="$2"
  137. if [[ "$NON_INTERACTIVE" == "true" ]]; then
  138. [[ "$default" == "y" ]] && return 0 || return 1
  139. fi
  140. local yn_hint="[y/n]"
  141. [[ "$default" == "y" ]] && yn_hint="[Y/n]"
  142. [[ "$default" == "n" ]] && yn_hint="[y/N]"
  143. while true; do
  144. echo -en "${BOLD}$prompt_text${NC} $yn_hint: "
  145. read -r yn
  146. [[ -z "$yn" ]] && yn="$default"
  147. case "$yn" in
  148. [Yy]* ) return 0;;
  149. [Nn]* ) return 1;;
  150. * ) echo "Please answer yes or no.";;
  151. esac
  152. done
  153. }
  154. show_help() {
  155. echo "SpoolBuddy Installation Script for Raspberry Pi"
  156. echo ""
  157. echo "Usage: sudo $0 [OPTIONS]"
  158. echo ""
  159. echo "Options:"
  160. echo " --mode MODE \"spoolbuddy\" (companion only) or \"full\" (Bambuddy + SpoolBuddy)"
  161. echo " --bambuddy-url URL Bambuddy server URL (required for spoolbuddy mode)"
  162. echo " --api-key KEY Bambuddy API key (required for spoolbuddy mode)"
  163. echo " --path PATH Installation directory (default: /opt/spoolbuddy or /opt/bambuddy)"
  164. echo " --port PORT Bambuddy port (full mode only, default: 8000)"
  165. echo " --ssh-pubkey KEY Bambuddy SSH public key for remote updates"
  166. echo " --yes, -y Non-interactive mode, accept defaults"
  167. echo " --help, -h Show this help message"
  168. echo ""
  169. echo "Examples:"
  170. echo " Interactive:"
  171. echo " sudo ./install.sh"
  172. echo ""
  173. echo " SpoolBuddy companion (unattended):"
  174. echo " sudo ./install.sh --mode spoolbuddy --bambuddy-url http://192.168.1.100:8000 --api-key bb_xxx -y"
  175. echo ""
  176. echo " Full install (unattended):"
  177. echo " sudo ./install.sh --mode full --port 8000 -y"
  178. exit 0
  179. }
  180. # ─────────────────────────────────────────────────────────────────────────────
  181. # Pre-flight Checks
  182. # ─────────────────────────────────────────────────────────────────────────────
  183. check_root() {
  184. if [[ $EUID -ne 0 ]]; then
  185. error "This script must be run as root (use sudo)"
  186. fi
  187. }
  188. check_raspberry_pi() {
  189. if ! grep -q "Raspberry Pi\|BCM2" /proc/cpuinfo 2>/dev/null; then
  190. error "This script is designed for Raspberry Pi only"
  191. fi
  192. # Detect Pi model for hardware recommendations
  193. local model
  194. model=$(tr -d '\0' < /proc/device-tree/model 2>/dev/null) || model="Unknown"
  195. success "Detected: $model"
  196. }
  197. check_raspberry_pi_os() {
  198. if [[ ! -f /etc/os-release ]]; then
  199. error "Cannot detect operating system"
  200. fi
  201. . /etc/os-release
  202. if [[ "$ID" != "raspbian" && "$ID" != "debian" ]]; then
  203. warn "Expected Raspberry Pi OS (Debian-based), found: $ID"
  204. if ! prompt_yes_no "Continue anyway?" "n"; then
  205. exit 0
  206. fi
  207. fi
  208. success "OS: $PRETTY_NAME"
  209. }
  210. detect_python() {
  211. local cmd=""
  212. if command -v python3 &>/dev/null; then
  213. cmd="python3"
  214. elif command -v python &>/dev/null; then
  215. local ver
  216. ver=$(python --version 2>&1 | cut -d' ' -f2 | cut -d'.' -f1)
  217. if [[ "$ver" -ge 3 ]]; then
  218. cmd="python"
  219. fi
  220. fi
  221. if [[ -z "$cmd" ]]; then
  222. return 1
  223. fi
  224. local version
  225. version=$($cmd -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
  226. local major minor
  227. major=$(echo "$version" | cut -d'.' -f1)
  228. minor=$(echo "$version" | cut -d'.' -f2)
  229. if [[ "$major" -lt 3 ]] || { [[ "$major" -eq 3 ]] && [[ "$minor" -lt 10 ]]; }; then
  230. warn "Python $version found, but 3.10+ is required"
  231. return 1
  232. fi
  233. PYTHON_CMD="$cmd"
  234. success "Found Python $version"
  235. return 0
  236. }
  237. # ─────────────────────────────────────────────────────────────────────────────
  238. # Raspberry Pi Hardware Configuration
  239. # ─────────────────────────────────────────────────────────────────────────────
  240. enable_spi() {
  241. if raspi-config nonint get_spi 2>/dev/null | grep -q "1"; then
  242. info "Enabling SPI..."
  243. raspi-config nonint do_spi 0
  244. REBOOT_NEEDED="true"
  245. success "SPI enabled"
  246. else
  247. success "SPI already enabled"
  248. fi
  249. }
  250. enable_i2c() {
  251. if raspi-config nonint get_i2c 2>/dev/null | grep -q "1"; then
  252. info "Enabling I2C..."
  253. raspi-config nonint do_i2c 0
  254. REBOOT_NEEDED="true"
  255. success "I2C enabled"
  256. else
  257. success "I2C already enabled"
  258. fi
  259. }
  260. configure_boot_config() {
  261. # Find the boot config file (Bookworm+ uses /boot/firmware/config.txt)
  262. local boot_config="/boot/firmware/config.txt"
  263. if [[ ! -f "$boot_config" ]]; then
  264. boot_config="/boot/config.txt"
  265. fi
  266. if [[ ! -f "$boot_config" ]]; then
  267. warn "Boot config not found at /boot/firmware/config.txt or /boot/config.txt"
  268. warn "You may need to manually add: dtparam=i2c_vc=on and dtoverlay=spi0-0cs"
  269. return
  270. fi
  271. info "Configuring $boot_config..."
  272. # Enable I2C bus 0 (GPIO0/GPIO1) for NAU7802 scale
  273. if ! grep -q "^dtparam=i2c_vc=on" "$boot_config"; then
  274. echo "" >> "$boot_config"
  275. echo "# SpoolBuddy: I2C bus 0 for NAU7802 scale (GPIO0/GPIO1)" >> "$boot_config"
  276. echo "dtparam=i2c_vc=on" >> "$boot_config"
  277. REBOOT_NEEDED="true"
  278. success "Added dtparam=i2c_vc=on"
  279. else
  280. success "dtparam=i2c_vc=on already set"
  281. fi
  282. # Disable SPI auto chip-select (manual CS on GPIO23 for PN5180)
  283. if ! grep -q "^dtoverlay=spi0-0cs" "$boot_config"; then
  284. echo "" >> "$boot_config"
  285. echo "# SpoolBuddy: Disable SPI auto CS (manual CS on GPIO23 for PN5180)" >> "$boot_config"
  286. echo "dtoverlay=spi0-0cs" >> "$boot_config"
  287. REBOOT_NEEDED="true"
  288. success "Added dtoverlay=spi0-0cs"
  289. else
  290. success "dtoverlay=spi0-0cs already set"
  291. fi
  292. }
  293. # ─────────────────────────────────────────────────────────────────────────────
  294. # Package Installation
  295. # ─────────────────────────────────────────────────────────────────────────────
  296. install_system_packages() {
  297. run_with_progress "Updating package lists" apt-get update
  298. run_with_progress "Installing system packages" apt-get install -y $SYSTEM_PACKAGES
  299. }
  300. # ─────────────────────────────────────────────────────────────────────────────
  301. # SpoolBuddy Installation
  302. # ─────────────────────────────────────────────────────────────────────────────
  303. create_spoolbuddy_user() {
  304. if id "$SPOOLBUDDY_SERVICE_USER" &>/dev/null; then
  305. info "User '$SPOOLBUDDY_SERVICE_USER' already exists"
  306. # Ensure existing installs get a real shell for SSH access
  307. usermod --shell /bin/bash "$SPOOLBUDDY_SERVICE_USER" 2>/dev/null || true
  308. else
  309. info "Creating service user '$SPOOLBUDDY_SERVICE_USER'..."
  310. useradd --system --shell /bin/bash --home-dir "$INSTALL_PATH" "$SPOOLBUDDY_SERVICE_USER"
  311. success "Service user created"
  312. fi
  313. # Add to hardware access groups (gpio, spi, i2c, video for backlight)
  314. for group in gpio spi i2c video; do
  315. if getent group "$group" &>/dev/null; then
  316. usermod -aG "$group" "$SPOOLBUDDY_SERVICE_USER" 2>/dev/null || true
  317. fi
  318. done
  319. success "User added to gpio, spi, i2c, video groups"
  320. # Allow passwordless restart of daemon + kiosk (needed for SSH-based updates from Bambuddy)
  321. cat > /etc/sudoers.d/spoolbuddy << 'SUDOERS'
  322. spoolbuddy ALL=(root) NOPASSWD: /usr/bin/systemctl restart spoolbuddy.service
  323. spoolbuddy ALL=(root) NOPASSWD: /usr/bin/systemctl restart getty@tty1.service
  324. SUDOERS
  325. chmod 440 /etc/sudoers.d/spoolbuddy
  326. success "Sudoers entries created for service and kiosk restart"
  327. }
  328. download_spoolbuddy() {
  329. if [[ -d "$INSTALL_PATH/.git" ]]; then
  330. info "Existing installation found, updating..."
  331. git config --global --add safe.directory "$INSTALL_PATH" 2>/dev/null || true
  332. cd "$INSTALL_PATH"
  333. run_with_progress "Fetching updates" git fetch origin
  334. git reset --hard origin/main > /dev/null 2>&1
  335. else
  336. mkdir -p "$INSTALL_PATH"
  337. run_with_progress "Cloning repository" git clone "$GITHUB_REPO" "$INSTALL_PATH"
  338. fi
  339. chown -R "$SPOOLBUDDY_SERVICE_USER:$SPOOLBUDDY_SERVICE_USER" "$INSTALL_PATH"
  340. }
  341. setup_spoolbuddy_venv() {
  342. cd "$INSTALL_PATH/spoolbuddy"
  343. run_with_progress "Creating SpoolBuddy venv" $PYTHON_CMD -m venv --system-site-packages venv
  344. run_with_progress "Upgrading pip" "$INSTALL_PATH/spoolbuddy/venv/bin/pip" install --upgrade pip
  345. run_with_progress "Installing SpoolBuddy packages" "$INSTALL_PATH/spoolbuddy/venv/bin/pip" install $SPOOLBUDDY_PIP_PACKAGES
  346. chown -R "$SPOOLBUDDY_SERVICE_USER:$SPOOLBUDDY_SERVICE_USER" "$INSTALL_PATH/spoolbuddy/venv"
  347. }
  348. create_spoolbuddy_env() {
  349. info "Creating SpoolBuddy configuration..."
  350. local env_file="$INSTALL_PATH/spoolbuddy/.env"
  351. cat > "$env_file" << EOF
  352. # SpoolBuddy Configuration
  353. # Generated by install.sh on $(date)
  354. # Bambuddy backend URL
  355. SPOOLBUDDY_BACKEND_URL=$BAMBUDDY_URL
  356. # API key (create one in Bambuddy Settings -> API Keys)
  357. SPOOLBUDDY_API_KEY=$API_KEY
  358. EOF
  359. chown "$SPOOLBUDDY_SERVICE_USER:$SPOOLBUDDY_SERVICE_USER" "$env_file"
  360. chmod 600 "$env_file"
  361. success "Configuration saved to $env_file"
  362. }
  363. setup_ssh_key() {
  364. info "Setting up SSH access for Bambuddy remote updates..."
  365. local ssh_dir="$INSTALL_PATH/.ssh"
  366. local auth_keys="$ssh_dir/authorized_keys"
  367. mkdir -p "$ssh_dir"
  368. chmod 700 "$ssh_dir"
  369. if [[ -n "$SSH_PUBKEY" ]]; then
  370. # Manual key provided via --ssh-pubkey flag
  371. if [[ -f "$auth_keys" ]] && grep -qF "$SSH_PUBKEY" "$auth_keys" 2>/dev/null; then
  372. info "SSH key already present in authorized_keys"
  373. else
  374. echo "$SSH_PUBKEY" >> "$auth_keys"
  375. success "SSH public key added"
  376. fi
  377. else
  378. # No manual key — the daemon will auto-deploy it on first registration
  379. info "SSH key will be deployed automatically when the daemon connects to Bambuddy"
  380. touch "$auth_keys"
  381. fi
  382. chmod 600 "$auth_keys"
  383. chown -R "$SPOOLBUDDY_SERVICE_USER:$SPOOLBUDDY_SERVICE_USER" "$ssh_dir"
  384. }
  385. create_spoolbuddy_service() {
  386. info "Creating SpoolBuddy systemd service..."
  387. local after_line="After=network-online.target"
  388. if [[ "$INSTALL_MODE" == "full" ]]; then
  389. after_line="After=network-online.target bambuddy.service"
  390. fi
  391. cat > /etc/systemd/system/spoolbuddy.service << EOF
  392. [Unit]
  393. Description=SpoolBuddy - NFC Spool Management Daemon
  394. Documentation=https://github.com/maziggy/bambuddy
  395. $after_line
  396. Wants=network-online.target
  397. [Service]
  398. Type=simple
  399. User=$SPOOLBUDDY_SERVICE_USER
  400. WorkingDirectory=$INSTALL_PATH/spoolbuddy
  401. EnvironmentFile=$INSTALL_PATH/spoolbuddy/.env
  402. ExecStart=$INSTALL_PATH/spoolbuddy/venv/bin/python -m daemon.main
  403. Restart=always
  404. RestartSec=5
  405. StandardOutput=journal
  406. StandardError=journal
  407. [Install]
  408. WantedBy=multi-user.target
  409. EOF
  410. systemctl daemon-reload
  411. systemctl enable spoolbuddy.service
  412. success "SpoolBuddy service created and enabled"
  413. }
  414. # ─────────────────────────────────────────────────────────────────────────────
  415. # Bambuddy Installation (full mode only)
  416. # ─────────────────────────────────────────────────────────────────────────────
  417. create_bambuddy_user() {
  418. if id "$BAMBUDDY_SERVICE_USER" &>/dev/null; then
  419. info "User '$BAMBUDDY_SERVICE_USER' already exists"
  420. return
  421. fi
  422. info "Creating service user '$BAMBUDDY_SERVICE_USER'..."
  423. useradd --system --shell /usr/sbin/nologin --home-dir "$INSTALL_PATH" "$BAMBUDDY_SERVICE_USER"
  424. success "Service user created"
  425. }
  426. setup_bambuddy_venv() {
  427. cd "$INSTALL_PATH"
  428. run_with_progress "Creating Bambuddy venv" $PYTHON_CMD -m venv venv
  429. run_with_progress "Upgrading pip" "$INSTALL_PATH/venv/bin/pip" install --upgrade pip
  430. run_with_progress "Installing Bambuddy dependencies" "$INSTALL_PATH/venv/bin/pip" install -r requirements.txt
  431. chown -R "$BAMBUDDY_SERVICE_USER:$BAMBUDDY_SERVICE_USER" "$INSTALL_PATH/venv"
  432. }
  433. install_nodejs() {
  434. if command -v node &>/dev/null; then
  435. local version
  436. version=$(node --version 2>/dev/null | sed 's/^v//')
  437. local major
  438. major=$(echo "$version" | cut -d'.' -f1)
  439. if [[ "$major" -ge 20 ]]; then
  440. success "Found Node.js v$version"
  441. return
  442. fi
  443. fi
  444. apt-get remove -y nodejs npm > /dev/null 2>&1 || true
  445. run_with_progress "Setting up Node.js repository" bash -c "curl -fsSL https://deb.nodesource.com/setup_22.x | bash -"
  446. run_with_progress "Installing Node.js" apt-get install -y nodejs
  447. hash -r 2>/dev/null || true
  448. success "Node.js installed: $(node --version)"
  449. }
  450. build_frontend() {
  451. cd "$INSTALL_PATH/frontend"
  452. run_with_progress "Installing frontend dependencies" npm ci
  453. run_with_progress "Building frontend" npm run build
  454. }
  455. create_bambuddy_env() {
  456. info "Creating Bambuddy configuration..."
  457. local env_file="$INSTALL_PATH/.env"
  458. cat > "$env_file" << EOF
  459. # Bambuddy Configuration
  460. # Generated by install.sh on $(date)
  461. DEBUG=false
  462. LOG_LEVEL=INFO
  463. LOG_TO_FILE=true
  464. EOF
  465. chown "$BAMBUDDY_SERVICE_USER:$BAMBUDDY_SERVICE_USER" "$env_file"
  466. chmod 600 "$env_file"
  467. success "Configuration saved to $env_file"
  468. }
  469. create_bambuddy_directories() {
  470. mkdir -p "$INSTALL_PATH/data" "$INSTALL_PATH/logs"
  471. chown -R "$BAMBUDDY_SERVICE_USER:$BAMBUDDY_SERVICE_USER" "$INSTALL_PATH/data" "$INSTALL_PATH/logs"
  472. success "Data directories created"
  473. }
  474. create_bambuddy_service() {
  475. info "Creating Bambuddy systemd service..."
  476. cat > /etc/systemd/system/bambuddy.service << EOF
  477. [Unit]
  478. Description=Bambuddy - Bambu Lab Print Management
  479. Documentation=https://github.com/maziggy/bambuddy
  480. After=network.target
  481. [Service]
  482. Type=simple
  483. User=$BAMBUDDY_SERVICE_USER
  484. Group=$BAMBUDDY_SERVICE_USER
  485. WorkingDirectory=$INSTALL_PATH
  486. EnvironmentFile=$INSTALL_PATH/.env
  487. Environment="DATA_DIR=$INSTALL_PATH/data"
  488. Environment="LOG_DIR=$INSTALL_PATH/logs"
  489. ExecStart=$INSTALL_PATH/venv/bin/uvicorn backend.app.main:app --host 0.0.0.0 --port $BAMBUDDY_PORT
  490. Restart=on-failure
  491. RestartSec=5
  492. StandardOutput=journal
  493. StandardError=journal
  494. NoNewPrivileges=true
  495. PrivateTmp=true
  496. ProtectSystem=strict
  497. ProtectHome=true
  498. ReadWritePaths=$INSTALL_PATH/data $INSTALL_PATH/logs $INSTALL_PATH
  499. [Install]
  500. WantedBy=multi-user.target
  501. EOF
  502. systemctl daemon-reload
  503. systemctl enable bambuddy.service
  504. success "Bambuddy service created and enabled"
  505. }
  506. # ─────────────────────────────────────────────────────────────────────────────
  507. # System Strip-Down (dedicated appliance — remove unnecessary services/packages)
  508. # ─────────────────────────────────────────────────────────────────────────────
  509. strip_services() {
  510. info "Disabling unnecessary services..."
  511. local services=(
  512. bluetooth.service
  513. lightdm.service
  514. cloud-init-local.service
  515. cloud-init.service
  516. cloud-init-network.service
  517. cloud-config.service
  518. cloud-final.service
  519. cloud-init-hotplugd.socket
  520. avahi-daemon.service
  521. avahi-daemon.socket
  522. ModemManager.service
  523. udisks2.service
  524. apparmor.service
  525. man-db.timer
  526. e2scrub_all.timer
  527. e2scrub_reap.service
  528. )
  529. local disabled=0
  530. for svc in "${services[@]}"; do
  531. if systemctl is-enabled "$svc" &>/dev/null; then
  532. systemctl disable "$svc" 2>/dev/null || true
  533. (( ++disabled ))
  534. fi
  535. done
  536. if (( disabled > 0 )); then
  537. success "Disabled $disabled unnecessary services"
  538. else
  539. success "No unnecessary services to disable"
  540. fi
  541. }
  542. strip_packages() {
  543. info "Removing unnecessary packages..."
  544. local packages=(
  545. mkvtoolnix
  546. firmware-atheros
  547. firmware-mediatek
  548. cloud-init
  549. rpi-cloud-init-mods
  550. rpi-connect-lite
  551. avahi-daemon
  552. modemmanager
  553. udisks2
  554. )
  555. local to_remove=()
  556. for pkg in "${packages[@]}"; do
  557. if dpkg -l "$pkg" &>/dev/null 2>&1; then
  558. to_remove+=("$pkg")
  559. fi
  560. done
  561. if (( ${#to_remove[@]} > 0 )); then
  562. run_with_progress "Removing ${#to_remove[@]} packages" apt-get remove --purge -y "${to_remove[@]}"
  563. run_with_progress "Cleaning up dependencies" apt-get autoremove --purge -y
  564. else
  565. success "No unnecessary packages to remove"
  566. fi
  567. }
  568. # ─────────────────────────────────────────────────────────────────────────────
  569. # Kiosk Setup (labwc + Chromium + Plymouth splash)
  570. # ─────────────────────────────────────────────────────────────────────────────
  571. setup_kiosk() {
  572. info "Setting up touchscreen kiosk..."
  573. # Detect kiosk user (the human user who ran sudo)
  574. KIOSK_USER="${SUDO_USER:-$(logname 2>/dev/null || echo pi)}"
  575. KIOSK_URL="${BAMBUDDY_URL}/spoolbuddy?token=${API_KEY}"
  576. local KIOSK_HOME
  577. KIOSK_HOME=$(eval echo "~$KIOSK_USER")
  578. info "Kiosk user: $KIOSK_USER (home: $KIOSK_HOME)"
  579. info "Kiosk URL: $KIOSK_URL"
  580. # ── Install kiosk packages ────────────────────────────────────────────
  581. run_with_progress "Installing kiosk packages" apt-get install -y labwc chromium plymouth wlr-randr
  582. # ── config.txt tweaks ─────────────────────────────────────────────────
  583. local boot_config="/boot/firmware/config.txt"
  584. if [[ ! -f "$boot_config" ]]; then
  585. boot_config="/boot/config.txt"
  586. fi
  587. if [[ -f "$boot_config" ]]; then
  588. info "Configuring $boot_config for kiosk..."
  589. # Disable audio (change existing on→off)
  590. sed -i 's/^dtparam=audio=on/dtparam=audio=off/' "$boot_config"
  591. # Disable camera auto-detect (change existing 1→0)
  592. sed -i 's/^camera_auto_detect=1/camera_auto_detect=0/' "$boot_config"
  593. # Append if missing: gpu_mem=32
  594. if ! grep -q "^gpu_mem=" "$boot_config"; then
  595. echo "" >> "$boot_config"
  596. echo "# Kiosk: Minimal GPU firmware memory (KMS uses CMA from system RAM)" >> "$boot_config"
  597. echo "gpu_mem=32" >> "$boot_config"
  598. fi
  599. # Append if missing: dtoverlay=disable-bt
  600. if ! grep -q "^dtoverlay=disable-bt" "$boot_config"; then
  601. echo "" >> "$boot_config"
  602. echo "# Kiosk: Disable Bluetooth hardware" >> "$boot_config"
  603. echo "dtoverlay=disable-bt" >> "$boot_config"
  604. fi
  605. # Append if missing: disable_splash=1
  606. if ! grep -q "^disable_splash=" "$boot_config"; then
  607. echo "" >> "$boot_config"
  608. echo "# Kiosk: Disable Raspberry Pi firmware splash, use custom splash.png" >> "$boot_config"
  609. echo "disable_splash=1" >> "$boot_config"
  610. fi
  611. success "Boot config updated"
  612. fi
  613. # ── cmdline.txt tweaks ────────────────────────────────────────────────
  614. local cmdline="/boot/firmware/cmdline.txt"
  615. if [[ ! -f "$cmdline" ]]; then
  616. cmdline="/boot/cmdline.txt"
  617. fi
  618. if [[ -f "$cmdline" ]]; then
  619. info "Configuring $cmdline for kiosk..."
  620. # Remove serial console (Plymouth needs tty-only console)
  621. sed -i 's/console=serial0,[0-9]* //' "$cmdline"
  622. # Add splash quiet loglevel=3 logo.nologo if missing
  623. grep -q "splash" "$cmdline" || sed -i 's/$/ splash quiet loglevel=3 logo.nologo/' "$cmdline"
  624. # Add video mode if missing
  625. grep -q "video=HDMI-A-1" "$cmdline" || sed -i 's/$/ video=HDMI-A-1:1024x600@60/' "$cmdline"
  626. success "Kernel cmdline updated"
  627. fi
  628. # ── Plymouth splash theme ─────────────────────────────────────────────
  629. info "Installing Plymouth boot splash..."
  630. local theme_dir="/usr/share/plymouth/themes/spoolbuddy"
  631. mkdir -p "$theme_dir"
  632. # Copy bundled splash image from the install directory
  633. local script_dir
  634. script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  635. if [[ -f "$script_dir/splash.png" ]]; then
  636. cp "$script_dir/splash.png" "$theme_dir/splash.png"
  637. elif [[ -f "$INSTALL_PATH/spoolbuddy/install/splash.png" ]]; then
  638. cp "$INSTALL_PATH/spoolbuddy/install/splash.png" "$theme_dir/splash.png"
  639. else
  640. warn "splash.png not found — Plymouth splash will not display an image"
  641. fi
  642. # Write .plymouth theme file
  643. cat > "$theme_dir/spoolbuddy.plymouth" << 'EOF'
  644. [Plymouth Theme]
  645. Name=SpoolBuddy
  646. Description=SpoolBuddy boot splash
  647. ModuleName=script
  648. [script]
  649. ImageDir=/usr/share/plymouth/themes/spoolbuddy
  650. ScriptFile=/usr/share/plymouth/themes/spoolbuddy/spoolbuddy.script
  651. EOF
  652. # Write .script theme file
  653. cat > "$theme_dir/spoolbuddy.script" << 'EOF'
  654. wallpaper_image = Image("splash.png");
  655. screen_width = Window.GetWidth();
  656. screen_height = Window.GetHeight();
  657. resized_wallpaper_image = wallpaper_image.Scale(screen_width, screen_height);
  658. wallpaper_sprite = Sprite(resized_wallpaper_image);
  659. wallpaper_sprite.SetZ(-100);
  660. EOF
  661. plymouth-set-default-theme spoolbuddy
  662. run_with_progress "Updating initramfs" update-initramfs -u
  663. success "Plymouth splash installed"
  664. # ── Auto-login on tty1 ────────────────────────────────────────────────
  665. info "Configuring auto-login for $KIOSK_USER..."
  666. mkdir -p /etc/systemd/system/getty@tty1.service.d
  667. cat > /etc/systemd/system/getty@tty1.service.d/autologin.conf << EOF
  668. [Service]
  669. ExecStart=
  670. ExecStart=-/sbin/agetty --autologin $KIOSK_USER --noclear %I \$TERM
  671. EOF
  672. success "Auto-login configured"
  673. # ── labwc rc.xml (no decorations, no keybinds) ────────────────────────
  674. info "Configuring labwc window manager..."
  675. local labwc_dir="$KIOSK_HOME/.config/labwc"
  676. mkdir -p "$labwc_dir"
  677. cat > "$labwc_dir/rc.xml" << 'EOF'
  678. <?xml version="1.0"?>
  679. <labwc_config>
  680. <theme>
  681. <name></name>
  682. <cornerRadius>0</cornerRadius>
  683. </theme>
  684. <!-- Disable all keybindings - kiosk lockdown -->
  685. <keyboard>
  686. </keyboard>
  687. <!-- Disable right-click menu -->
  688. <mouse>
  689. <default />
  690. </mouse>
  691. <!-- Remove window decorations, maximize Chromium, prevent unfullscreen -->
  692. <windowRules>
  693. <windowRule identifier="*">
  694. <serverDecoration>no</serverDecoration>
  695. </windowRule>
  696. <windowRule identifier="chromium">
  697. <skipTaskbar>yes</skipTaskbar>
  698. <fixedPosition>yes</fixedPosition>
  699. </windowRule>
  700. </windowRules>
  701. </labwc_config>
  702. EOF
  703. # ── labwc autostart ───────────────────────────────────────────────────
  704. cat > "$labwc_dir/autostart" << EOF
  705. # Force 1024x600 (panel doesn't advertise this natively)
  706. wlr-randr --output HDMI-A-1 --custom-mode 1024x600@60 &
  707. # Launch Chromium in kiosk mode (virtual keyboard is embedded in the web app)
  708. chromium --kiosk --no-first-run --disable-infobars \\
  709. --disable-session-crashed-bubble --disable-features=TranslateUI \\
  710. --noerrdialogs --disable-component-update \\
  711. --overscroll-history-navigation=0 \\
  712. --ozone-platform=wayland \\
  713. $KIOSK_URL &
  714. EOF
  715. chown -R "$KIOSK_USER:$KIOSK_USER" "$labwc_dir"
  716. # ── .bash_profile (source .bashrc, exec labwc on tty1) ────────────────
  717. cat > "$KIOSK_HOME/.bash_profile" << 'EOF'
  718. # Source .bashrc if it exists
  719. if [ -f ~/.bashrc ]; then
  720. . ~/.bashrc
  721. fi
  722. # Auto-start kiosk on tty1
  723. if [ "$(tty)" = "/dev/tty1" ]; then
  724. exec labwc
  725. fi
  726. EOF
  727. chown "$KIOSK_USER:$KIOSK_USER" "$KIOSK_HOME/.bash_profile"
  728. REBOOT_NEEDED="true"
  729. success "Kiosk setup complete"
  730. }
  731. # ─────────────────────────────────────────────────────────────────────────────
  732. # User Prompts
  733. # ─────────────────────────────────────────────────────────────────────────────
  734. parse_args() {
  735. while [[ $# -gt 0 ]]; do
  736. case "$1" in
  737. --mode)
  738. INSTALL_MODE="$2"
  739. shift 2
  740. ;;
  741. --bambuddy-url)
  742. BAMBUDDY_URL="$2"
  743. shift 2
  744. ;;
  745. --api-key)
  746. API_KEY="$2"
  747. shift 2
  748. ;;
  749. --path)
  750. INSTALL_PATH="$2"
  751. shift 2
  752. ;;
  753. --port)
  754. BAMBUDDY_PORT="$2"
  755. shift 2
  756. ;;
  757. --ssh-pubkey)
  758. SSH_PUBKEY="$2"
  759. shift 2
  760. ;;
  761. --yes|-y)
  762. NON_INTERACTIVE="true"
  763. shift
  764. ;;
  765. --help|-h)
  766. show_help
  767. ;;
  768. *)
  769. error "Unknown option: $1 (use --help for usage)"
  770. ;;
  771. esac
  772. done
  773. }
  774. ask_install_mode() {
  775. if [[ -n "$INSTALL_MODE" ]]; then
  776. return
  777. fi
  778. echo ""
  779. echo -e "${BOLD}How would you like to set up SpoolBuddy?${NC}"
  780. echo ""
  781. echo -e " ${CYAN}1)${NC} SpoolBuddy only"
  782. echo " NFC reader + scale on this RPi, Bambuddy runs on another device"
  783. echo ""
  784. echo -e " ${CYAN}2)${NC} SpoolBuddy + Bambuddy"
  785. echo " Both running natively on this Raspberry Pi"
  786. echo ""
  787. while true; do
  788. echo -en "${BOLD}Choose${NC} [${CYAN}1${NC}/${CYAN}2${NC}]: "
  789. read -r choice
  790. case "$choice" in
  791. 1) INSTALL_MODE="spoolbuddy"; return;;
  792. 2) INSTALL_MODE="full"; return;;
  793. *) echo "Please enter 1 or 2.";;
  794. esac
  795. done
  796. }
  797. gather_config() {
  798. echo ""
  799. echo -e "${BOLD}Configuration${NC}"
  800. echo -e "${CYAN}─────────────────────────────────────────${NC}"
  801. echo ""
  802. # Set default install path based on mode
  803. if [[ -z "$INSTALL_PATH" ]]; then
  804. if [[ "$INSTALL_MODE" == "full" ]]; then
  805. INSTALL_PATH="/opt/bambuddy"
  806. else
  807. INSTALL_PATH="/opt/bambuddy"
  808. fi
  809. fi
  810. prompt "Installation directory" "$INSTALL_PATH" INSTALL_PATH
  811. if [[ "$INSTALL_MODE" == "spoolbuddy" ]]; then
  812. # Need remote Bambuddy URL and API key
  813. echo ""
  814. info "SpoolBuddy needs to connect to your Bambuddy server."
  815. info "You can find/create an API key in Bambuddy under Settings -> API Keys."
  816. echo ""
  817. while [[ -z "$BAMBUDDY_URL" ]]; do
  818. prompt "Bambuddy server URL (e.g. http://192.168.1.100:8000)" "" BAMBUDDY_URL
  819. if [[ -z "$BAMBUDDY_URL" ]]; then
  820. warn "Bambuddy URL is required"
  821. fi
  822. done
  823. while [[ -z "$API_KEY" ]]; do
  824. prompt "Bambuddy API key" "" API_KEY
  825. if [[ -z "$API_KEY" ]]; then
  826. warn "API key is required"
  827. fi
  828. done
  829. else
  830. # Full mode — Bambuddy runs locally
  831. prompt "Bambuddy port" "$BAMBUDDY_PORT" BAMBUDDY_PORT
  832. BAMBUDDY_URL="http://localhost:$BAMBUDDY_PORT"
  833. echo ""
  834. info "After installation, create an API key in Bambuddy (Settings -> API Keys)"
  835. info "and update it in: $INSTALL_PATH/spoolbuddy/.env"
  836. API_KEY="CHANGE_ME_AFTER_SETUP"
  837. fi
  838. # Summary
  839. echo ""
  840. echo -e "${BOLD}Installation Summary${NC}"
  841. echo -e "${CYAN}─────────────────────────────────────────${NC}"
  842. echo -e " Mode: ${GREEN}$([ "$INSTALL_MODE" == "full" ] && echo "Bambuddy + SpoolBuddy" || echo "SpoolBuddy only")${NC}"
  843. echo -e " Install path: ${GREEN}$INSTALL_PATH${NC}"
  844. if [[ "$INSTALL_MODE" == "full" ]]; then
  845. echo -e " Bambuddy port: ${GREEN}$BAMBUDDY_PORT${NC}"
  846. echo -e " Bambuddy URL: ${GREEN}$BAMBUDDY_URL${NC}"
  847. else
  848. echo -e " Bambuddy URL: ${GREEN}$BAMBUDDY_URL${NC}"
  849. fi
  850. echo ""
  851. if ! prompt_yes_no "Proceed with installation?" "y"; then
  852. echo "Installation cancelled."
  853. exit 0
  854. fi
  855. }
  856. # ─────────────────────────────────────────────────────────────────────────────
  857. # Main
  858. # ─────────────────────────────────────────────────────────────────────────────
  859. main() {
  860. parse_args "$@"
  861. echo ""
  862. echo -e "${CYAN}╔══════════════════════════════════════════════════════════╗${NC}"
  863. echo -e "${CYAN}║ ║${NC}"
  864. echo -e "${CYAN}║ ____ _ ____ _ _ ║${NC}"
  865. echo -e "${CYAN}║ / ___| _ __ ___ ___ | | __ ) _ _ __| | __| |_ _ ║${NC}"
  866. echo -e "${CYAN}║ \\___ \\| '_ \\ / _ \\ / _ \\| | _ \\| | | |/ _\` |/ _\` | | | |║${NC}"
  867. echo -e "${CYAN}║ ___) | |_) | (_) | (_) | | |_) | |_| | (_| | (_| | |_| |║${NC}"
  868. echo -e "${CYAN}║ |____/| .__/ \\___/ \\___/|_|____/ \\__,_|\\__,_|\\__,_|\\__, |║${NC}"
  869. echo -e "${CYAN}║ |_| |___/ ║${NC}"
  870. echo -e "${CYAN}║ ║${NC}"
  871. echo -e "${CYAN}║ NFC Spool Management for Bambuddy ║${NC}"
  872. echo -e "${CYAN}║ ║${NC}"
  873. echo -e "${CYAN}╚══════════════════════════════════════════════════════════╝${NC}"
  874. echo ""
  875. # Check if running via pipe without -y
  876. if [[ ! -t 0 ]] && [[ "$NON_INTERACTIVE" != "true" ]]; then
  877. error "Interactive mode requires a terminal. Use -y for unattended install, or download and run directly."
  878. fi
  879. # Pre-flight checks
  880. check_root
  881. check_raspberry_pi
  882. check_raspberry_pi_os
  883. if ! detect_python; then
  884. info "Python 3.10+ not found, will install..."
  885. fi
  886. # Gather user preferences
  887. ask_install_mode
  888. gather_config
  889. # Validate mode
  890. if [[ "$INSTALL_MODE" != "spoolbuddy" && "$INSTALL_MODE" != "full" ]]; then
  891. error "Invalid mode: $INSTALL_MODE (must be 'spoolbuddy' or 'full')"
  892. fi
  893. echo ""
  894. echo -e "${BOLD}Starting Installation${NC}"
  895. echo -e "${CYAN}─────────────────────────────────────────${NC}"
  896. echo ""
  897. # ── Step 1: Raspberry Pi hardware config ──────────────────────────────
  898. info "Configuring Raspberry Pi hardware..."
  899. enable_spi
  900. enable_i2c
  901. configure_boot_config
  902. echo ""
  903. # ── Step 2: System packages ───────────────────────────────────────────
  904. install_system_packages
  905. detect_python || error "Failed to install Python 3.10+"
  906. echo ""
  907. # ── Step 2b: Strip unnecessary services & packages ────────────────────
  908. strip_services
  909. strip_packages
  910. echo ""
  911. # ── Step 3: Download source code ──────────────────────────────────────
  912. create_spoolbuddy_user
  913. download_spoolbuddy
  914. echo ""
  915. # ── Step 3b: Kiosk setup (labwc + Chromium + squeekboard + Plymouth) ──
  916. setup_kiosk
  917. echo ""
  918. # ── Step 4: SpoolBuddy setup ──────────────────────────────────────────
  919. info "Setting up SpoolBuddy..."
  920. setup_spoolbuddy_venv
  921. create_spoolbuddy_env
  922. setup_ssh_key
  923. create_spoolbuddy_service
  924. echo ""
  925. # ── Step 5: Bambuddy setup (full mode only) ───────────────────────────
  926. if [[ "$INSTALL_MODE" == "full" ]]; then
  927. info "Setting up Bambuddy..."
  928. create_bambuddy_user
  929. setup_bambuddy_venv
  930. install_nodejs
  931. build_frontend
  932. create_bambuddy_directories
  933. create_bambuddy_env
  934. create_bambuddy_service
  935. echo ""
  936. fi
  937. # ── Done ──────────────────────────────────────────────────────────────
  938. echo ""
  939. echo -e "${GREEN}╔══════════════════════════════════════════════════════════╗${NC}"
  940. echo -e "${GREEN}║ ║${NC}"
  941. echo -e "${GREEN}║ Installation Complete! ║${NC}"
  942. echo -e "${GREEN}║ ║${NC}"
  943. echo -e "${GREEN}╚══════════════════════════════════════════════════════════╝${NC}"
  944. echo ""
  945. local ip_addr
  946. ip_addr=$(hostname -I 2>/dev/null | awk '{print $1}') || ip_addr="<your-ip>"
  947. if [[ "$INSTALL_MODE" == "full" ]]; then
  948. echo -e " ${BOLD}Bambuddy:${NC} ${CYAN}http://$ip_addr:$BAMBUDDY_PORT${NC}"
  949. else
  950. echo -e " ${BOLD}SpoolBuddy:${NC} Connecting to ${CYAN}$BAMBUDDY_URL${NC}"
  951. fi
  952. echo -e " ${BOLD}Kiosk URL:${NC} ${CYAN}$KIOSK_URL${NC}"
  953. echo -e " ${BOLD}Kiosk user:${NC} ${CYAN}$KIOSK_USER${NC}"
  954. echo ""
  955. if [[ "$INSTALL_MODE" == "full" ]]; then
  956. echo -e " ${BOLD}Next steps:${NC}"
  957. echo -e " 1. Reboot (required for kiosk, Plymouth splash, and hardware changes)"
  958. echo -e " 2. The touchscreen kiosk will start automatically after reboot"
  959. echo -e " 3. On another device, open ${CYAN}http://$ip_addr:$BAMBUDDY_PORT${NC}"
  960. echo -e " 4. Go to Settings -> API Keys and create an API key"
  961. echo -e " 5. Update the API key in: ${CYAN}$INSTALL_PATH/spoolbuddy/.env${NC}"
  962. echo -e " 6. Restart SpoolBuddy: ${CYAN}sudo systemctl restart spoolbuddy${NC}"
  963. fi
  964. echo ""
  965. echo -e " ${BOLD}Manage services:${NC}"
  966. echo -e " SpoolBuddy status: ${CYAN}sudo systemctl status spoolbuddy${NC}"
  967. echo -e " SpoolBuddy logs: ${CYAN}sudo journalctl -u spoolbuddy -f${NC}"
  968. if [[ "$INSTALL_MODE" == "full" ]]; then
  969. echo -e " Bambuddy status: ${CYAN}sudo systemctl status bambuddy${NC}"
  970. echo -e " Bambuddy logs: ${CYAN}sudo journalctl -u bambuddy -f${NC}"
  971. fi
  972. echo ""
  973. echo -e " ${BOLD}Configuration:${NC} ${CYAN}$INSTALL_PATH/spoolbuddy/.env${NC}"
  974. echo -e " ${BOLD}Hardware wiring:${NC} ${CYAN}$INSTALL_PATH/spoolbuddy/README.md${NC}"
  975. echo -e " ${BOLD}Diagnostics:${NC} ${CYAN}sudo $INSTALL_PATH/spoolbuddy/venv/bin/python $INSTALL_PATH/spoolbuddy/pn5180_diag.py${NC}"
  976. echo ""
  977. echo -e " ${YELLOW}A reboot is required to apply all changes (kiosk, Plymouth splash, hardware).${NC}"
  978. echo ""
  979. if prompt_yes_no "Reboot now?" "y"; then
  980. reboot
  981. else
  982. echo -e " Run ${CYAN}sudo reboot${NC} when ready."
  983. fi
  984. echo ""
  985. }
  986. main "$@"