install.sh 44 KB

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