How marcone/teslausb works
Purpose and execution model
teslausb turns a Raspberry Pi or other USB-OTG SBC into a Tesla-visible USB storage device. It exposes dashcam and music storage to the car, then uses the SBC’s network access to repair, archive, manage, and serve that data. The system is primarily Bash running on Linux, with small Python notification/API integrations and a C++ web utility.
Primary operational entry points are device setup in setup/pi/setup-teslausb, runtime orchestration in run/archiveloop, and USB gadget state changes in run/enable_gadget.sh and run/disable_gadget.sh.
Image build and first-boot provisioning
A customized Pi image is built through pi-gen sources, injecting packages, system tweaks, configuration samples, and first-run behavior. pi-gen-sources/prepare.sh prepares the build inputs; pi-gen-sources/00-teslausb-tweaks/00-run.sh installs the project stage; pi-gen-sources/00-teslausb-tweaks/files/run_once supports one-time initialization.
On-device setup configures storage, networking, automounting, Samba, SSH, and the web service. The central Pi setup flow is setup/pi/configure.sh, with backing-file creation in setup/pi/create-backingfiles.sh and setup/pi/create-backingfiles-partition.sh.
USB gadget and mutable storage boundary
The SBC emulates a USB mass-storage device for the Tesla. Gadget enable/disable scripts control when the car can access backing storage: run/enable_gadget.sh, run/disable_gadget.sh, and run/auto.teslausb.
The key safety boundary is Tesla-owned USB access versus Linux-owned filesystem access. Runtime scripts disable or detach the gadget before local maintenance/archiving, then restore it afterward. Read-only-root support and writable backing files reduce SD-card wear and isolate Tesla filesystem corruption; relevant setup is setup/pi/make-root-fs-readonly.sh and run/remountfs_rw.
Runtime lifecycle and recording maintenance
run/archiveloop is the long-running control loop coordinating archive availability, clip transfer, cleanup, and retry behavior. Vehicle state controls transitions: run/awake_start, run/awake_stop, and run/waitforidle gate work around Tesla activity.
Storage protection is handled by run/manage_free_space.sh; snapshot-style protection/recovery uses run/make_snapshot.sh, run/release_snapshot.sh, and run/force_sync.sh. Mounting backing images and deriving mount options are separated into run/mountimage and run/mountoptsforimage.
Pluggable archive backends
Archiving is an adapter-style subsystem selected by archive type. Each backend supplies a common lifecycle—reachability check, connect, archive clips, disconnect, and archive configuration—under parallel directories:
• CIFS/SMB: run/cifs_archive/archive-clips.sh, run/cifs_archive/connect-archive.sh
• NFS: run/nfs_archive/archive-clips.sh, run/nfs_archive/connect-archive.sh
• rsync: run/rsync_archive/archive-clips.sh, run/rsync_archive/connect-archive.sh
• rclone/cloud remotes: run/rclone_archive/archive-clips.sh, run/rclone_archive/connect-archive.sh
• no external archive: run/none_archive/archive-clips.sh
CIFS and NFS also include music synchronization, enabling network-hosted music to be copied onto the Tesla-visible drive.
Administration and web interface
The embedded web UI is static HTML/JavaScript plus CGI shell endpoints, deployed/configured by setup/pi/configure-web.sh and Nginx configuration teslausb-www/teslausb.nginx. The interface provides file browsing, clip viewing/download, diagnostics, configuration, reboot, and sync triggers.
Important privileged CGI boundaries are teslausb-www/html/cgi-bin/trigger_sync.sh, teslausb-www/html/cgi-bin/status.sh, and teslausb-www/html/cgi-bin/config.sh. These bridge browser requests into local system and archive operations.
External integrations and observability
The system depends on Linux USB gadget support, Wi-Fi/WPA2, filesystem/mount tooling, and optional SMB/CIFS, NFS, rsync, or rclone archive services. Samba and SSH are optional management-facing services configured in setup/pi/configure-samba.sh and setup/pi/configure-ssh.sh.
Notifications support push, Matrix, and AWS SNS through run/send-push-message, run/send_matrix.py, and run/send_sns.py. Tesla-aware behavior can use run/tesla_api.py; device health monitoring is implemented by run/temperature_monitor.
Main entry points: archiveloop archive loop · mountimage mounted backing image · configure.sh Pi configuration · teslausb.nginx web UI
Components 22
Image & Provisioning
Builds and configures the Pi appliance.
- pi-gen input prep
pi-gen-sources/prepare.sh - teslausb pi-gen stage
pi-gen-sources/00-teslausb-tweaks/00-run.sh - first-run init
pi-gen-sources/00-teslausb-tweaks/files/run_once - Pi configuration · Configures storage, network, services, and web UI.
setup/pi/configure.sh - backing-file storage
setup/pi/create-backingfiles.sh - read-only root
setup/pi/make-root-fs-readonly.sh - device setup
setup/pi/setup-teslausb
Tesla Storage Runtime
Coordinates safe USB ownership and recording maintenance.
- archive loop · Long-running control loop for transfer, cleanup, and retries.
run/archiveloop - vehicle activity gate
run/waitforidle - enable USB gadget · Exposes backing storage to the Tesla.
run/enable_gadget.sh - disable USB gadget · Returns filesystem ownership to Linux.
run/disable_gadget.sh - mounted backing image · Tesla-visible recordings and music storage.
run/mountimage - snapshot & free-space control
run/manage_free_space.sh
Archive Adapters
Selectable common archive lifecycle implementations.
- archive lifecycle · Reachability, connect, transfer, and disconnect flow.
- CIFS/SMB archive · Also supports network music synchronization.
run/cifs_archive/archive-clips.sh - NFS archive · Also supports network music synchronization.
run/nfs_archive/archive-clips.sh - rsync archive
run/rsync_archive/archive-clips.sh - rclone archive
run/rclone_archive/archive-clips.sh
Administration
Browser and remote management surfaces.
- web UI · Browser administration and file access surface.
teslausb-www/teslausb.nginx - sync trigger CGI · Bridges browser sync requests into local operations.
teslausb-www/html/cgi-bin/trigger_sync.sh - status CGI
teslausb-www/html/cgi-bin/status.sh
Other components
- notifications · Push, Matrix, and AWS SNS delivery.
run/send-push-message
Connections 25
- pi-gen input prep → teslausb pi-gen stage: supplies build inputs
- teslausb pi-gen stage → first-run init: installs
- first-run init → Pi configuration: initializes
- device setup → Pi configuration: runs
- Pi configuration → backing-file storage: creates
- Pi configuration → read-only root: enables
- backing-file storage → mounted backing image: provides image
- archive loop → vehicle activity gate: waits for idle
- archive loop → disable USB gadget: detaches before maintenance
- disable USB gadget → mounted backing image: permits Linux access
- archive loop → snapshot & free-space control: maintains
- snapshot & free-space control → mounted backing image: protects
- archive loop → archive lifecycle: selects backend
- archive lifecycle → CIFS/SMB archive: implements
- archive lifecycle → NFS archive: implements
- archive lifecycle → rsync archive: implements
- archive lifecycle → rclone archive: implements
- archive lifecycle → mounted backing image: archives clips from
- archive loop → enable USB gadget: restores after work
- enable USB gadget → mounted backing image: exports to Tesla
- web UI → sync trigger CGI: invokes
- web UI → status CGI: invokes
- sync trigger CGI → archive loop: triggers sync
- status CGI → archive loop: reads runtime status
- archive loop → notifications: reports events