install.sh 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  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. spoolbuddy ALL=(root) NOPASSWD: /usr/bin/find /home -maxdepth 5 *
  325. SUDOERS
  326. chmod 440 /etc/sudoers.d/spoolbuddy
  327. success "Sudoers entries created for service and kiosk restart"
  328. }
  329. download_spoolbuddy() {
  330. if [[ -d "$INSTALL_PATH/.git" ]]; then
  331. info "Existing installation found, updating..."
  332. git config --global --add safe.directory "$INSTALL_PATH" 2>/dev/null || true
  333. cd "$INSTALL_PATH"
  334. run_with_progress "Fetching updates" git fetch origin
  335. git reset --hard origin/main > /dev/null 2>&1
  336. else
  337. mkdir -p "$INSTALL_PATH"
  338. run_with_progress "Cloning repository" git clone "$GITHUB_REPO" "$INSTALL_PATH"
  339. fi
  340. chown -R "$SPOOLBUDDY_SERVICE_USER:$SPOOLBUDDY_SERVICE_USER" "$INSTALL_PATH"
  341. }
  342. setup_spoolbuddy_venv() {
  343. cd "$INSTALL_PATH/spoolbuddy"
  344. run_with_progress "Creating SpoolBuddy venv" $PYTHON_CMD -m venv --system-site-packages venv
  345. run_with_progress "Upgrading pip" "$INSTALL_PATH/spoolbuddy/venv/bin/pip" install --upgrade pip
  346. run_with_progress "Installing SpoolBuddy packages" "$INSTALL_PATH/spoolbuddy/venv/bin/pip" install $SPOOLBUDDY_PIP_PACKAGES
  347. chown -R "$SPOOLBUDDY_SERVICE_USER:$SPOOLBUDDY_SERVICE_USER" "$INSTALL_PATH/spoolbuddy/venv"
  348. }
  349. create_spoolbuddy_env() {
  350. info "Creating SpoolBuddy configuration..."
  351. local env_file="$INSTALL_PATH/spoolbuddy/.env"
  352. cat > "$env_file" << EOF
  353. # SpoolBuddy Configuration
  354. # Generated by install.sh on $(date)
  355. # Bambuddy backend URL
  356. SPOOLBUDDY_BACKEND_URL=$BAMBUDDY_URL
  357. # API key (create one in Bambuddy Settings -> API Keys)
  358. SPOOLBUDDY_API_KEY=$API_KEY
  359. EOF
  360. chown "$SPOOLBUDDY_SERVICE_USER:$SPOOLBUDDY_SERVICE_USER" "$env_file"
  361. chmod 600 "$env_file"
  362. success "Configuration saved to $env_file"
  363. }
  364. setup_ssh_key() {
  365. info "Setting up SSH access for Bambuddy remote updates..."
  366. local ssh_dir="$INSTALL_PATH/.ssh"
  367. local auth_keys="$ssh_dir/authorized_keys"
  368. mkdir -p "$ssh_dir"
  369. chmod 700 "$ssh_dir"
  370. if [[ -n "$SSH_PUBKEY" ]]; then
  371. # Manual key provided via --ssh-pubkey flag
  372. if [[ -f "$auth_keys" ]] && grep -qF "$SSH_PUBKEY" "$auth_keys" 2>/dev/null; then
  373. info "SSH key already present in authorized_keys"
  374. else
  375. echo "$SSH_PUBKEY" >> "$auth_keys"
  376. success "SSH public key added"
  377. fi
  378. else
  379. # No manual key — the daemon will auto-deploy it on first registration
  380. info "SSH key will be deployed automatically when the daemon connects to Bambuddy"
  381. touch "$auth_keys"
  382. fi
  383. chmod 600 "$auth_keys"
  384. chown -R "$SPOOLBUDDY_SERVICE_USER:$SPOOLBUDDY_SERVICE_USER" "$ssh_dir"
  385. }
  386. create_spoolbuddy_service() {
  387. info "Creating SpoolBuddy systemd service..."
  388. local after_line="After=network-online.target"
  389. if [[ "$INSTALL_MODE" == "full" ]]; then
  390. after_line="After=network-online.target bambuddy.service"
  391. fi
  392. cat > /etc/systemd/system/spoolbuddy.service << EOF
  393. [Unit]
  394. Description=SpoolBuddy - NFC Spool Management Daemon
  395. Documentation=https://github.com/maziggy/bambuddy
  396. $after_line
  397. Wants=network-online.target
  398. [Service]
  399. Type=simple
  400. User=$SPOOLBUDDY_SERVICE_USER
  401. WorkingDirectory=$INSTALL_PATH/spoolbuddy
  402. EnvironmentFile=$INSTALL_PATH/spoolbuddy/.env
  403. ExecStart=$INSTALL_PATH/spoolbuddy/venv/bin/python -m daemon.main
  404. Restart=always
  405. RestartSec=5
  406. StandardOutput=journal
  407. StandardError=journal
  408. [Install]
  409. WantedBy=multi-user.target
  410. EOF
  411. systemctl daemon-reload
  412. systemctl enable spoolbuddy.service
  413. success "SpoolBuddy service created and enabled"
  414. }
  415. # ─────────────────────────────────────────────────────────────────────────────
  416. # Bambuddy Installation (full mode only)
  417. # ─────────────────────────────────────────────────────────────────────────────
  418. create_bambuddy_user() {
  419. if id "$BAMBUDDY_SERVICE_USER" &>/dev/null; then
  420. info "User '$BAMBUDDY_SERVICE_USER' already exists"
  421. return
  422. fi
  423. info "Creating service user '$BAMBUDDY_SERVICE_USER'..."
  424. useradd --system --shell /usr/sbin/nologin --home-dir "$INSTALL_PATH" "$BAMBUDDY_SERVICE_USER"
  425. success "Service user created"
  426. }
  427. setup_bambuddy_venv() {
  428. cd "$INSTALL_PATH"
  429. run_with_progress "Creating Bambuddy venv" $PYTHON_CMD -m venv venv
  430. run_with_progress "Upgrading pip" "$INSTALL_PATH/venv/bin/pip" install --upgrade pip
  431. run_with_progress "Installing Bambuddy dependencies" "$INSTALL_PATH/venv/bin/pip" install -r requirements.txt
  432. chown -R "$BAMBUDDY_SERVICE_USER:$BAMBUDDY_SERVICE_USER" "$INSTALL_PATH/venv"
  433. }
  434. install_nodejs() {
  435. if command -v node &>/dev/null; then
  436. local version
  437. version=$(node --version 2>/dev/null | sed 's/^v//')
  438. local major
  439. major=$(echo "$version" | cut -d'.' -f1)
  440. if [[ "$major" -ge 20 ]]; then
  441. success "Found Node.js v$version"
  442. return
  443. fi
  444. fi
  445. apt-get remove -y nodejs npm > /dev/null 2>&1 || true
  446. run_with_progress "Setting up Node.js repository" bash -c "curl -fsSL https://deb.nodesource.com/setup_22.x | bash -"
  447. run_with_progress "Installing Node.js" apt-get install -y nodejs
  448. hash -r 2>/dev/null || true
  449. success "Node.js installed: $(node --version)"
  450. }
  451. build_frontend() {
  452. cd "$INSTALL_PATH/frontend"
  453. run_with_progress "Installing frontend dependencies" npm ci
  454. run_with_progress "Building frontend" npm run build
  455. }
  456. create_bambuddy_env() {
  457. info "Creating Bambuddy configuration..."
  458. local env_file="$INSTALL_PATH/.env"
  459. cat > "$env_file" << EOF
  460. # Bambuddy Configuration
  461. # Generated by install.sh on $(date)
  462. DEBUG=false
  463. LOG_LEVEL=INFO
  464. LOG_TO_FILE=true
  465. EOF
  466. chown "$BAMBUDDY_SERVICE_USER:$BAMBUDDY_SERVICE_USER" "$env_file"
  467. chmod 600 "$env_file"
  468. success "Configuration saved to $env_file"
  469. }
  470. create_bambuddy_directories() {
  471. mkdir -p "$INSTALL_PATH/data" "$INSTALL_PATH/logs"
  472. chown -R "$BAMBUDDY_SERVICE_USER:$BAMBUDDY_SERVICE_USER" "$INSTALL_PATH/data" "$INSTALL_PATH/logs"
  473. success "Data directories created"
  474. }
  475. create_bambuddy_service() {
  476. info "Creating Bambuddy systemd service..."
  477. cat > /etc/systemd/system/bambuddy.service << EOF
  478. [Unit]
  479. Description=Bambuddy - Bambu Lab Print Management
  480. Documentation=https://github.com/maziggy/bambuddy
  481. After=network.target
  482. [Service]
  483. Type=simple
  484. User=$BAMBUDDY_SERVICE_USER
  485. Group=$BAMBUDDY_SERVICE_USER
  486. WorkingDirectory=$INSTALL_PATH
  487. EnvironmentFile=$INSTALL_PATH/.env
  488. Environment="DATA_DIR=$INSTALL_PATH/data"
  489. Environment="LOG_DIR=$INSTALL_PATH/logs"
  490. ExecStart=$INSTALL_PATH/venv/bin/uvicorn backend.app.main:app --host 0.0.0.0 --port $BAMBUDDY_PORT
  491. Restart=on-failure
  492. RestartSec=5
  493. StandardOutput=journal
  494. StandardError=journal
  495. NoNewPrivileges=true
  496. PrivateTmp=true
  497. ProtectSystem=strict
  498. ProtectHome=true
  499. ReadWritePaths=$INSTALL_PATH/data $INSTALL_PATH/logs $INSTALL_PATH
  500. [Install]
  501. WantedBy=multi-user.target
  502. EOF
  503. systemctl daemon-reload
  504. systemctl enable bambuddy.service
  505. success "Bambuddy service created and enabled"
  506. }
  507. # ─────────────────────────────────────────────────────────────────────────────
  508. # System Strip-Down (dedicated appliance — remove unnecessary services/packages)
  509. # ─────────────────────────────────────────────────────────────────────────────
  510. strip_services() {
  511. info "Disabling unnecessary services..."
  512. local services=(
  513. bluetooth.service
  514. lightdm.service
  515. cloud-init-local.service
  516. cloud-init.service
  517. cloud-init-network.service
  518. cloud-config.service
  519. cloud-final.service
  520. cloud-init-hotplugd.socket
  521. avahi-daemon.service
  522. avahi-daemon.socket
  523. ModemManager.service
  524. udisks2.service
  525. apparmor.service
  526. man-db.timer
  527. e2scrub_all.timer
  528. e2scrub_reap.service
  529. )
  530. local disabled=0
  531. for svc in "${services[@]}"; do
  532. if systemctl is-enabled "$svc" &>/dev/null; then
  533. systemctl disable "$svc" 2>/dev/null || true
  534. (( ++disabled ))
  535. fi
  536. done
  537. if (( disabled > 0 )); then
  538. success "Disabled $disabled unnecessary services"
  539. else
  540. success "No unnecessary services to disable"
  541. fi
  542. }
  543. strip_packages() {
  544. info "Removing unnecessary packages..."
  545. local packages=(
  546. mkvtoolnix
  547. firmware-atheros
  548. firmware-mediatek
  549. cloud-init
  550. rpi-cloud-init-mods
  551. rpi-connect-lite
  552. avahi-daemon
  553. modemmanager
  554. udisks2
  555. )
  556. local to_remove=()
  557. for pkg in "${packages[@]}"; do
  558. if dpkg -l "$pkg" &>/dev/null 2>&1; then
  559. to_remove+=("$pkg")
  560. fi
  561. done
  562. if (( ${#to_remove[@]} > 0 )); then
  563. run_with_progress "Removing ${#to_remove[@]} packages" apt-get remove --purge -y "${to_remove[@]}"
  564. run_with_progress "Cleaning up dependencies" apt-get autoremove --purge -y
  565. else
  566. success "No unnecessary packages to remove"
  567. fi
  568. }
  569. # ─────────────────────────────────────────────────────────────────────────────
  570. # Kiosk Setup (labwc + Chromium + Plymouth splash)
  571. # ─────────────────────────────────────────────────────────────────────────────
  572. setup_kiosk() {
  573. info "Setting up touchscreen kiosk..."
  574. # Detect kiosk user (the human user who ran sudo)
  575. KIOSK_USER="${SUDO_USER:-$(logname 2>/dev/null || echo pi)}"
  576. KIOSK_URL="${BAMBUDDY_URL}/spoolbuddy?token=${API_KEY}"
  577. local KIOSK_HOME
  578. KIOSK_HOME=$(eval echo "~$KIOSK_USER")
  579. info "Kiosk user: $KIOSK_USER (home: $KIOSK_HOME)"
  580. info "Kiosk URL: $KIOSK_URL"
  581. # ── Install kiosk packages ────────────────────────────────────────────
  582. run_with_progress "Installing kiosk packages" apt-get install -y labwc chromium plymouth wlr-randr
  583. # ── config.txt tweaks ─────────────────────────────────────────────────
  584. local boot_config="/boot/firmware/config.txt"
  585. if [[ ! -f "$boot_config" ]]; then
  586. boot_config="/boot/config.txt"
  587. fi
  588. if [[ -f "$boot_config" ]]; then
  589. info "Configuring $boot_config for kiosk..."
  590. # Disable audio (change existing on→off)
  591. sed -i 's/^dtparam=audio=on/dtparam=audio=off/' "$boot_config"
  592. # Disable camera auto-detect (change existing 1→0)
  593. sed -i 's/^camera_auto_detect=1/camera_auto_detect=0/' "$boot_config"
  594. # Append if missing: gpu_mem=32
  595. if ! grep -q "^gpu_mem=" "$boot_config"; then
  596. echo "" >> "$boot_config"
  597. echo "# Kiosk: Minimal GPU firmware memory (KMS uses CMA from system RAM)" >> "$boot_config"
  598. echo "gpu_mem=32" >> "$boot_config"
  599. fi
  600. # Append if missing: dtoverlay=disable-bt
  601. if ! grep -q "^dtoverlay=disable-bt" "$boot_config"; then
  602. echo "" >> "$boot_config"
  603. echo "# Kiosk: Disable Bluetooth hardware" >> "$boot_config"
  604. echo "dtoverlay=disable-bt" >> "$boot_config"
  605. fi
  606. # Append if missing: disable_splash=1
  607. if ! grep -q "^disable_splash=" "$boot_config"; then
  608. echo "" >> "$boot_config"
  609. echo "# Kiosk: Disable Raspberry Pi firmware splash, use custom splash.png" >> "$boot_config"
  610. echo "disable_splash=1" >> "$boot_config"
  611. fi
  612. success "Boot config updated"
  613. fi
  614. # ── cmdline.txt tweaks ────────────────────────────────────────────────
  615. local cmdline="/boot/firmware/cmdline.txt"
  616. if [[ ! -f "$cmdline" ]]; then
  617. cmdline="/boot/cmdline.txt"
  618. fi
  619. if [[ -f "$cmdline" ]]; then
  620. info "Configuring $cmdline for kiosk..."
  621. # Remove serial console (Plymouth needs tty-only console)
  622. sed -i 's/console=serial0,[0-9]* //' "$cmdline"
  623. # Add splash quiet loglevel=3 logo.nologo if missing
  624. grep -q "splash" "$cmdline" || sed -i 's/$/ splash quiet loglevel=3 logo.nologo/' "$cmdline"
  625. # Add video mode if missing
  626. grep -q "video=HDMI-A-1" "$cmdline" || sed -i 's/$/ video=HDMI-A-1:1024x600@60/' "$cmdline"
  627. success "Kernel cmdline updated"
  628. fi
  629. # ── Plymouth splash theme ─────────────────────────────────────────────
  630. info "Installing Plymouth boot splash..."
  631. local theme_dir="/usr/share/plymouth/themes/spoolbuddy"
  632. mkdir -p "$theme_dir"
  633. # Copy bundled splash image from the install directory
  634. local script_dir
  635. script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  636. if [[ -f "$script_dir/splash.png" ]]; then
  637. cp "$script_dir/splash.png" "$theme_dir/splash.png"
  638. elif [[ -f "$INSTALL_PATH/spoolbuddy/install/splash.png" ]]; then
  639. cp "$INSTALL_PATH/spoolbuddy/install/splash.png" "$theme_dir/splash.png"
  640. else
  641. warn "splash.png not found — Plymouth splash will not display an image"
  642. fi
  643. # Write .plymouth theme file
  644. cat > "$theme_dir/spoolbuddy.plymouth" << 'EOF'
  645. [Plymouth Theme]
  646. Name=SpoolBuddy
  647. Description=SpoolBuddy boot splash
  648. ModuleName=script
  649. [script]
  650. ImageDir=/usr/share/plymouth/themes/spoolbuddy
  651. ScriptFile=/usr/share/plymouth/themes/spoolbuddy/spoolbuddy.script
  652. EOF
  653. # Write .script theme file
  654. cat > "$theme_dir/spoolbuddy.script" << 'EOF'
  655. wallpaper_image = Image("splash.png");
  656. screen_width = Window.GetWidth();
  657. screen_height = Window.GetHeight();
  658. resized_wallpaper_image = wallpaper_image.Scale(screen_width, screen_height);
  659. wallpaper_sprite = Sprite(resized_wallpaper_image);
  660. wallpaper_sprite.SetZ(-100);
  661. EOF
  662. plymouth-set-default-theme spoolbuddy
  663. run_with_progress "Updating initramfs" update-initramfs -u
  664. success "Plymouth splash installed"
  665. # ── Auto-login on tty1 ────────────────────────────────────────────────
  666. info "Configuring auto-login for $KIOSK_USER..."
  667. mkdir -p /etc/systemd/system/getty@tty1.service.d
  668. cat > /etc/systemd/system/getty@tty1.service.d/autologin.conf << EOF
  669. [Unit]
  670. After=network-online.target
  671. Wants=network-online.target
  672. [Service]
  673. ExecStart=
  674. ExecStart=-/sbin/agetty --autologin $KIOSK_USER --noclear %I \$TERM
  675. EOF
  676. success "Auto-login configured"
  677. # ── labwc rc.xml (no decorations, no keybinds) ────────────────────────
  678. info "Configuring labwc window manager..."
  679. local labwc_dir="$KIOSK_HOME/.config/labwc"
  680. mkdir -p "$labwc_dir"
  681. cat > "$labwc_dir/rc.xml" << 'EOF'
  682. <?xml version="1.0"?>
  683. <labwc_config>
  684. <theme>
  685. <name></name>
  686. <cornerRadius>0</cornerRadius>
  687. </theme>
  688. <!-- Disable all keybindings - kiosk lockdown -->
  689. <keyboard>
  690. </keyboard>
  691. <!-- Disable right-click menu -->
  692. <mouse>
  693. <default />
  694. </mouse>
  695. <!-- Remove window decorations, maximize Chromium, prevent unfullscreen -->
  696. <windowRules>
  697. <windowRule identifier="*">
  698. <serverDecoration>no</serverDecoration>
  699. </windowRule>
  700. <windowRule identifier="chromium">
  701. <skipTaskbar>yes</skipTaskbar>
  702. <fixedPosition>yes</fixedPosition>
  703. </windowRule>
  704. </windowRules>
  705. </labwc_config>
  706. EOF
  707. # ── labwc autostart ───────────────────────────────────────────────────
  708. cat > "$labwc_dir/autostart" << EOF
  709. # Force 1024x600 (panel doesn't advertise this natively)
  710. wlr-randr --output HDMI-A-1 --custom-mode 1024x600@60 &
  711. # Launch Chromium in kiosk mode (virtual keyboard is embedded in the web app)
  712. chromium --kiosk --no-first-run --disable-infobars \\
  713. --disable-session-crashed-bubble --disable-features=TranslateUI \\
  714. --noerrdialogs --disable-component-update \\
  715. --disk-cache-size=0 \\
  716. --overscroll-history-navigation=0 \\
  717. --ozone-platform=wayland \\
  718. $KIOSK_URL &
  719. EOF
  720. chown -R "$KIOSK_USER:$KIOSK_USER" "$labwc_dir"
  721. # ── .bash_profile (source .bashrc, exec labwc on tty1) ────────────────
  722. cat > "$KIOSK_HOME/.bash_profile" << 'EOF'
  723. # Source .bashrc if it exists
  724. if [ -f ~/.bashrc ]; then
  725. . ~/.bashrc
  726. fi
  727. # Auto-start kiosk on tty1
  728. if [ "$(tty)" = "/dev/tty1" ]; then
  729. exec labwc
  730. fi
  731. EOF
  732. chown "$KIOSK_USER:$KIOSK_USER" "$KIOSK_HOME/.bash_profile"
  733. REBOOT_NEEDED="true"
  734. success "Kiosk setup complete"
  735. }
  736. # ─────────────────────────────────────────────────────────────────────────────
  737. # User Prompts
  738. # ─────────────────────────────────────────────────────────────────────────────
  739. parse_args() {
  740. while [[ $# -gt 0 ]]; do
  741. case "$1" in
  742. --mode)
  743. INSTALL_MODE="$2"
  744. shift 2
  745. ;;
  746. --bambuddy-url)
  747. BAMBUDDY_URL="$2"
  748. shift 2
  749. ;;
  750. --api-key)
  751. API_KEY="$2"
  752. shift 2
  753. ;;
  754. --path)
  755. INSTALL_PATH="$2"
  756. shift 2
  757. ;;
  758. --port)
  759. BAMBUDDY_PORT="$2"
  760. shift 2
  761. ;;
  762. --ssh-pubkey)
  763. SSH_PUBKEY="$2"
  764. shift 2
  765. ;;
  766. --yes|-y)
  767. NON_INTERACTIVE="true"
  768. shift
  769. ;;
  770. --help|-h)
  771. show_help
  772. ;;
  773. *)
  774. error "Unknown option: $1 (use --help for usage)"
  775. ;;
  776. esac
  777. done
  778. }
  779. ask_install_mode() {
  780. if [[ -n "$INSTALL_MODE" ]]; then
  781. return
  782. fi
  783. echo ""
  784. echo -e "${BOLD}How would you like to set up SpoolBuddy?${NC}"
  785. echo ""
  786. echo -e " ${CYAN}1)${NC} SpoolBuddy only"
  787. echo " NFC reader + scale on this RPi, Bambuddy runs on another device"
  788. echo ""
  789. echo -e " ${CYAN}2)${NC} SpoolBuddy + Bambuddy"
  790. echo " Both running natively on this Raspberry Pi"
  791. echo ""
  792. while true; do
  793. echo -en "${BOLD}Choose${NC} [${CYAN}1${NC}/${CYAN}2${NC}]: "
  794. read -r choice
  795. case "$choice" in
  796. 1) INSTALL_MODE="spoolbuddy"; return;;
  797. 2) INSTALL_MODE="full"; return;;
  798. *) echo "Please enter 1 or 2.";;
  799. esac
  800. done
  801. }
  802. gather_config() {
  803. echo ""
  804. echo -e "${BOLD}Configuration${NC}"
  805. echo -e "${CYAN}─────────────────────────────────────────${NC}"
  806. echo ""
  807. # Set default install path based on mode
  808. if [[ -z "$INSTALL_PATH" ]]; then
  809. if [[ "$INSTALL_MODE" == "full" ]]; then
  810. INSTALL_PATH="/opt/bambuddy"
  811. else
  812. INSTALL_PATH="/opt/bambuddy"
  813. fi
  814. fi
  815. prompt "Installation directory" "$INSTALL_PATH" INSTALL_PATH
  816. if [[ "$INSTALL_MODE" == "spoolbuddy" ]]; then
  817. # Need remote Bambuddy URL and API key
  818. echo ""
  819. info "SpoolBuddy needs to connect to your Bambuddy server."
  820. info "You can find/create an API key in Bambuddy under Settings -> API Keys."
  821. echo ""
  822. while [[ -z "$BAMBUDDY_URL" ]]; do
  823. prompt "Bambuddy server URL (e.g. http://192.168.1.100:8000)" "" BAMBUDDY_URL
  824. if [[ -z "$BAMBUDDY_URL" ]]; then
  825. warn "Bambuddy URL is required"
  826. fi
  827. done
  828. while [[ -z "$API_KEY" ]]; do
  829. prompt "Bambuddy API key" "" API_KEY
  830. if [[ -z "$API_KEY" ]]; then
  831. warn "API key is required"
  832. fi
  833. done
  834. else
  835. # Full mode — Bambuddy runs locally
  836. prompt "Bambuddy port" "$BAMBUDDY_PORT" BAMBUDDY_PORT
  837. BAMBUDDY_URL="http://localhost:$BAMBUDDY_PORT"
  838. echo ""
  839. info "After installation, create an API key in Bambuddy (Settings -> API Keys)"
  840. info "and update it in: $INSTALL_PATH/spoolbuddy/.env"
  841. API_KEY="CHANGE_ME_AFTER_SETUP"
  842. fi
  843. # Summary
  844. echo ""
  845. echo -e "${BOLD}Installation Summary${NC}"
  846. echo -e "${CYAN}─────────────────────────────────────────${NC}"
  847. echo -e " Mode: ${GREEN}$([ "$INSTALL_MODE" == "full" ] && echo "Bambuddy + SpoolBuddy" || echo "SpoolBuddy only")${NC}"
  848. echo -e " Install path: ${GREEN}$INSTALL_PATH${NC}"
  849. if [[ "$INSTALL_MODE" == "full" ]]; then
  850. echo -e " Bambuddy port: ${GREEN}$BAMBUDDY_PORT${NC}"
  851. echo -e " Bambuddy URL: ${GREEN}$BAMBUDDY_URL${NC}"
  852. else
  853. echo -e " Bambuddy URL: ${GREEN}$BAMBUDDY_URL${NC}"
  854. fi
  855. echo ""
  856. if ! prompt_yes_no "Proceed with installation?" "y"; then
  857. echo "Installation cancelled."
  858. exit 0
  859. fi
  860. }
  861. # ─────────────────────────────────────────────────────────────────────────────
  862. # Main
  863. # ─────────────────────────────────────────────────────────────────────────────
  864. main() {
  865. parse_args "$@"
  866. echo ""
  867. echo -e "${CYAN}╔══════════════════════════════════════════════════════════╗${NC}"
  868. echo -e "${CYAN}║ ║${NC}"
  869. echo -e "${CYAN}║ ____ _ ____ _ _ ║${NC}"
  870. echo -e "${CYAN}║ / ___| _ __ ___ ___ | | __ ) _ _ __| | __| |_ _ ║${NC}"
  871. echo -e "${CYAN}║ \\___ \\| '_ \\ / _ \\ / _ \\| | _ \\| | | |/ _\` |/ _\` | | | |║${NC}"
  872. echo -e "${CYAN}║ ___) | |_) | (_) | (_) | | |_) | |_| | (_| | (_| | |_| |║${NC}"
  873. echo -e "${CYAN}║ |____/| .__/ \\___/ \\___/|_|____/ \\__,_|\\__,_|\\__,_|\\__, |║${NC}"
  874. echo -e "${CYAN}║ |_| |___/ ║${NC}"
  875. echo -e "${CYAN}║ ║${NC}"
  876. echo -e "${CYAN}║ NFC Spool Management for Bambuddy ║${NC}"
  877. echo -e "${CYAN}║ ║${NC}"
  878. echo -e "${CYAN}╚══════════════════════════════════════════════════════════╝${NC}"
  879. echo ""
  880. # Check if running via pipe without -y
  881. if [[ ! -t 0 ]] && [[ "$NON_INTERACTIVE" != "true" ]]; then
  882. error "Interactive mode requires a terminal. Use -y for unattended install, or download and run directly."
  883. fi
  884. # Pre-flight checks
  885. check_root
  886. check_raspberry_pi
  887. check_raspberry_pi_os
  888. if ! detect_python; then
  889. info "Python 3.10+ not found, will install..."
  890. fi
  891. # Gather user preferences
  892. ask_install_mode
  893. gather_config
  894. # Validate mode
  895. if [[ "$INSTALL_MODE" != "spoolbuddy" && "$INSTALL_MODE" != "full" ]]; then
  896. error "Invalid mode: $INSTALL_MODE (must be 'spoolbuddy' or 'full')"
  897. fi
  898. echo ""
  899. echo -e "${BOLD}Starting Installation${NC}"
  900. echo -e "${CYAN}─────────────────────────────────────────${NC}"
  901. echo ""
  902. # ── Step 1: Raspberry Pi hardware config ──────────────────────────────
  903. info "Configuring Raspberry Pi hardware..."
  904. enable_spi
  905. enable_i2c
  906. configure_boot_config
  907. echo ""
  908. # ── Step 2: System packages ───────────────────────────────────────────
  909. install_system_packages
  910. detect_python || error "Failed to install Python 3.10+"
  911. echo ""
  912. # ── Step 2b: Strip unnecessary services & packages ────────────────────
  913. strip_services
  914. strip_packages
  915. echo ""
  916. # ── Step 3: Download source code ──────────────────────────────────────
  917. create_spoolbuddy_user
  918. download_spoolbuddy
  919. echo ""
  920. # ── Step 3b: Kiosk setup (labwc + Chromium + squeekboard + Plymouth) ──
  921. setup_kiosk
  922. echo ""
  923. # ── Step 4: SpoolBuddy setup ──────────────────────────────────────────
  924. info "Setting up SpoolBuddy..."
  925. setup_spoolbuddy_venv
  926. create_spoolbuddy_env
  927. setup_ssh_key
  928. create_spoolbuddy_service
  929. echo ""
  930. # ── Step 5: Bambuddy setup (full mode only) ───────────────────────────
  931. if [[ "$INSTALL_MODE" == "full" ]]; then
  932. info "Setting up Bambuddy..."
  933. create_bambuddy_user
  934. setup_bambuddy_venv
  935. install_nodejs
  936. build_frontend
  937. create_bambuddy_directories
  938. create_bambuddy_env
  939. create_bambuddy_service
  940. echo ""
  941. fi
  942. # ── Done ──────────────────────────────────────────────────────────────
  943. echo ""
  944. echo -e "${GREEN}╔══════════════════════════════════════════════════════════╗${NC}"
  945. echo -e "${GREEN}║ ║${NC}"
  946. echo -e "${GREEN}║ Installation Complete! ║${NC}"
  947. echo -e "${GREEN}║ ║${NC}"
  948. echo -e "${GREEN}╚══════════════════════════════════════════════════════════╝${NC}"
  949. echo ""
  950. local ip_addr
  951. ip_addr=$(hostname -I 2>/dev/null | awk '{print $1}') || ip_addr="<your-ip>"
  952. if [[ "$INSTALL_MODE" == "full" ]]; then
  953. echo -e " ${BOLD}Bambuddy:${NC} ${CYAN}http://$ip_addr:$BAMBUDDY_PORT${NC}"
  954. else
  955. echo -e " ${BOLD}SpoolBuddy:${NC} Connecting to ${CYAN}$BAMBUDDY_URL${NC}"
  956. fi
  957. echo -e " ${BOLD}Kiosk URL:${NC} ${CYAN}$KIOSK_URL${NC}"
  958. echo -e " ${BOLD}Kiosk user:${NC} ${CYAN}$KIOSK_USER${NC}"
  959. echo ""
  960. if [[ "$INSTALL_MODE" == "full" ]]; then
  961. echo -e " ${BOLD}Next steps:${NC}"
  962. echo -e " 1. Reboot (required for kiosk, Plymouth splash, and hardware changes)"
  963. echo -e " 2. The touchscreen kiosk will start automatically after reboot"
  964. echo -e " 3. On another device, open ${CYAN}http://$ip_addr:$BAMBUDDY_PORT${NC}"
  965. echo -e " 4. Go to Settings -> API Keys and create an API key"
  966. echo -e " 5. Update the API key in: ${CYAN}$INSTALL_PATH/spoolbuddy/.env${NC}"
  967. echo -e " 6. Restart SpoolBuddy: ${CYAN}sudo systemctl restart spoolbuddy${NC}"
  968. fi
  969. echo ""
  970. echo -e " ${BOLD}Manage services:${NC}"
  971. echo -e " SpoolBuddy status: ${CYAN}sudo systemctl status spoolbuddy${NC}"
  972. echo -e " SpoolBuddy logs: ${CYAN}sudo journalctl -u spoolbuddy -f${NC}"
  973. if [[ "$INSTALL_MODE" == "full" ]]; then
  974. echo -e " Bambuddy status: ${CYAN}sudo systemctl status bambuddy${NC}"
  975. echo -e " Bambuddy logs: ${CYAN}sudo journalctl -u bambuddy -f${NC}"
  976. fi
  977. echo ""
  978. echo -e " ${BOLD}Configuration:${NC} ${CYAN}$INSTALL_PATH/spoolbuddy/.env${NC}"
  979. echo -e " ${BOLD}Hardware wiring:${NC} ${CYAN}$INSTALL_PATH/spoolbuddy/README.md${NC}"
  980. echo -e " ${BOLD}Diagnostics:${NC} ${CYAN}sudo $INSTALL_PATH/spoolbuddy/venv/bin/python $INSTALL_PATH/spoolbuddy/pn5180_diag.py${NC}"
  981. echo ""
  982. echo -e " ${YELLOW}A reboot is required to apply all changes (kiosk, Plymouth splash, hardware).${NC}"
  983. echo ""
  984. if prompt_yes_no "Reboot now?" "y"; then
  985. reboot
  986. else
  987. echo -e " Run ${CYAN}sudo reboot${NC} when ready."
  988. fi
  989. echo ""
  990. }
  991. main "$@"