pub mod config; pub mod install; pub mod wifi; pub use config::TollGateConfig; pub use install::install_tollgate; pub use wifi::provision_ssid; use anyhow::Result; use tracing::info; use crate::{opkg::PkgManager, Router}; /// Full TollGate provisioning sequence: /// 1. Install tollgate-module-basic-go /// 2. Write TollGate UCI config (pricing, mint URL) /// 3. Create the pay-as-you-go WiFi SSID /// 4. Restart affected services pub async fn provision(router: &Router, config: &TollGateConfig) -> Result<()> { info!("[{}] Starting TollGate provisioning", router.host); let pkg_mgr = router.opkg_check()?; match pkg_mgr { PkgManager::Opkg => { router.opkg_update()?; install_tollgate(router)?; } PkgManager::ApkNative => { install::install_tollgate_apk_native(router)?; } } config::apply(router, config)?; wifi::provision_ssid(router, config)?; restart_services(router, config.enabled)?; info!("[{}] TollGate provisioning complete", router.host); Ok(()) } /// Applies `enabled` to the actual running service, not just the UCI value — /// the tollgate-wrt init script doesn't consult `tollgate.main.enabled` /// itself, so toggling it requires an explicit enable/start or disable/stop. /// /// The service's init script is `/etc/init.d/tollgate-wrt` (its actual /// on-disk name — "tollgate" alone does not exist). fn restart_services(router: &Router, enabled: bool) -> Result<()> { if enabled { router.run_ok("/etc/init.d/tollgate-wrt enable")?; router.run_ok( "/etc/init.d/tollgate-wrt restart || /etc/init.d/tollgate-wrt start" )?; } else { router.run_ok("/etc/init.d/tollgate-wrt stop || true")?; router.run_ok("/etc/init.d/tollgate-wrt disable || true")?; } router.run_ok("/etc/init.d/network restart")?; // Reload wireless so wireless.tollgate.disabled takes effect on the radio — // `network restart` alone doesn't reliably reconfigure wifi interfaces. router.run_ok("wifi down 2>&1; wifi up 2>&1")?; Ok(()) }