install.sh 44 KB

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