diff --git a/GetShellWithoutMonitorOnLinux.md b/GetShellWithoutMonitorOnLinux.md deleted file mode 100644 index 2013114..0000000 --- a/GetShellWithoutMonitorOnLinux.md +++ /dev/null @@ -1,43 +0,0 @@ -# Setting up the Pi without a monitor using a Mac or Linux - -You can setup the Pi to connect to your Wifi network, and also provide the option to connect over USB networking (Rasberry Pi Zero W or other recent Pi's). - - -**What is USB networking?** -Basically what you're doing is using the Pi's capability to emulate a network connection over USB. So you need to get the Pi (the guest) set up to load the proper modules to do so, and then connect from your machine (the host) using a shell (like iTerm+SSH on macOS). It's an alternative to Wifi if needed. - -## Use the update script to setup Wifi and USB networking - -A [script](https://raw.githubusercontent.com/cimryan/teslausb/master/mac_linux_archive/setup-piForHeadlessConfig.sh is provided to automatically update your SD card so the first time you boot it on your Pi, USB networking and Wifi will automatically be configured. - -If you prefer not to run the script, it's also a useful reference for the steps you'll need to take. - -> It's important you do these steps **before you boot the Pi the first time with the SD card inserted**. - -1. Ensure you've flashed your Raspbian image to your SD card. -1. If the `boot` folder isn't showing on your computer, eject and re-insert the SD card into your computer, **not the Raspberry Pi**. -1. Change to the directory where the SD card's `boot` folder (containing `cmdline.txt`) is located. On a Mac, this will be `/Volumes/boot`. On Linux the location may vary. -1. Run the following commands: - ``` - wget https://raw.githubusercontent.com/cimryan/teslausb/master/mac_linux_archive/setup-piForHeadlessConfig.sh - chmod +x setup-piForHeadlessConfig.sh - ``` -1. Set your SSID (Wifi network name) and WIFIPASS environment variables. The script will insert them into the `wpa_supplicant.conf` when creating it: - - ``` - export SSID=your_ssid_here - export WIFIPASS=your_wifi_password_here - ``` -1. Run the script: - `./setup-piForHeadlessConfig.sh` -1. If all goes well, the script will report: - `-- Files updated and ready for Wifi and SSH over USB --` -1. Eject the SD card safely, insert into your Pi, and reboot. If the Pi is connected over USB to your host, and/or if the Wifi setup went correctly, you should be able to `ssh pi@raspberrypi.local`. The default password is `raspberry`. - - > Note: If you receive an error indicating that the host id has changed, edit your computer's `~/.ssh/known_hosts` file. Find the line with the IP address of your Pi, or labeled "raspberrypi.local" and delete the entire line. You're especially likely to encounter this error if you're following these instructions for a second time. - -## Manual/other resources - -* [Gist (text file) showing example steps to setup USB networking](https://gist.github.com/gbaman/975e2db164b3ca2b51ae11e45e8fd40a) - -If manually configuring the Pi vs using the update script, be sure to delete the `init=/usr/lib/raspi-config/init_resize.sh` parameter from cmdline.txt to prevent the os partition from being expanded to fill the drive. diff --git a/README.md b/README.md index 8f8c5fa..fa902c4 100644 --- a/README.md +++ b/README.md @@ -78,9 +78,9 @@ There are three phases to setting up the Pi: > Note: you don't need to uncompress the zip file you downloaded. ### Get a shell on the Pi -If you used a Windows computer to flash the OS onto the MicroSD card, follow these [Instructions](GetShellWithoutMonitorOnWindows.md). +If you used a Windows computer to flash the OS onto the MicroSD card, follow these [Instructions](doc/GetShellWithoutMonitorOnWindows.md). -If you used a Mac or a Linux computer, follow these [Instructions](GetShellWithoutMonitorOnLinux.md). +If you used a Mac or a Linux computer, follow these [Instructions](doc/GetShellWithoutMonitorOnLinux.md). ### Set up the USB storage functionality @@ -104,7 +104,7 @@ Now that you have Wifi up and running, it's time to set up the USB storage and s export campercent= ``` For example, using `export campercent=100` would allocate 100% of the space to recording footage from your car, and would not create a separate music partition. `export campercent=50` would be only allocate half of the space for a dashcam footage drive, and allocates the other half to be a music storage drive. -1. If you are trying to archive on an SFTP/rsync server, then follow these [instructions](SetupRSync.md) and skip step 7. Otherwise, skip this step. +1. If you are trying to archive on an SFTP/rsync server, then follow these [instructions](doc/SetupRSync.md) and skip step 7. Otherwise, skip this step. 1. If you are trying to archive on a shared drive, run these commands, subsituting your values for your shared drive: ``` export archiveserver=Nautilus @@ -112,10 +112,10 @@ Now that you have Wifi up and running, it's time to set up the USB storage and s export shareuser=sailfish export sharepassword=pa$$w0rd ``` -1. If you'd like to receive a text message when your Pi finishes archiving clips follow these [Instructions](ConfigureNotificationsForArchive.md). +1. If you'd like to receive a text message when your Pi finishes archiving clips follow these [Instructions](doc/ConfigureNotificationsForArchive.md). 1. Run these commands: ``` - wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup-teslausb + wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup/pi/setup-teslausb chmod +x setup-teslausb ./setup-teslausb ``` diff --git a/ConfigureNotificationsForArchive.md b/doc/ConfigureNotificationsForArchive.md similarity index 100% rename from ConfigureNotificationsForArchive.md rename to doc/ConfigureNotificationsForArchive.md diff --git a/doc/GetShellWithoutMonitorOnLinux.md b/doc/GetShellWithoutMonitorOnLinux.md new file mode 100644 index 0000000..2439691 --- /dev/null +++ b/doc/GetShellWithoutMonitorOnLinux.md @@ -0,0 +1,35 @@ +# Getting a shell on the Pi without a monitor using a Mac or Linux + +These instructions will configure a Raspberry Pi so that you can proceed with the next step of setting it up as a smart USB drive for your Tesla. Specifically, these intructions will configure your Pi to join your wireless network and also enable you to ssh to the Pi, either over your wireless network or through a USB connection. + +**Important:** Do these steps before you boot the Pi for the first time. + +1. Ensure you've flashed your Raspbian image to your SD card. +1. If the `boot` folder isn't showing on your computer, eject and re-insert the SD card into your computer, **not the Raspberry Pi**. +1. Change to the directory where the SD card's `boot` folder (containing `cmdline.txt`) is located. On a Mac, this will be `/Volumes/boot`. On Linux the location may vary; on recent Ubuntu installations it will be /media/$USER/boot +1. Run the following commands: + ``` + wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup/macos_linux/setup-piForHeadlessConfig.sh + chmod +x setup-piForHeadlessConfig.sh + ``` +1. Set your SSID (Wifi network name) and WIFIPASS environment variables. The script will insert them into the `wpa_supplicant.conf` when creating it: + ``` + export SSID=your_ssid_here + export WIFIPASS=your_wifi_password_here + ``` +1. If you're using a Mac, run this command + ``` + ./setup-piForHeadlessConfig.sh /Volumes/boot + ``` +1. If you're using Ubuntu, run this command: + ``` + ./setup-piForHeadlessConfig.sh /media/$USER/boot + ``` + > If you're using another Linux distribution figure out the path to where the boot partitio of the SD card is mounted and specify that path, instead. +1. If all goes well, the script will report: + ``` + -- Files updated and ready for Wifi and SSH over USB -- + ``` +1. Eject the SD card safely, insert into your Pi, and reboot. If the Pi is connected over USB to your host, and/or if the Wifi setup went correctly, you should be able to `ssh pi@raspberrypi.local`. The default password is `raspberry`. + + > Note: If you receive an error indicating that the host id has changed, edit your computer's `~/.ssh/known_hosts` file. Find the line with the IP address of your Pi, or labeled "raspberrypi.local" and delete the entire line. You're especially likely to encounter this error if you're following these instructions for a second time. diff --git a/GetShellWithoutMonitorOnWindows.md b/doc/GetShellWithoutMonitorOnWindows.md similarity index 92% rename from GetShellWithoutMonitorOnWindows.md rename to doc/GetShellWithoutMonitorOnWindows.md index 205c0b2..0142aeb 100644 --- a/GetShellWithoutMonitorOnWindows.md +++ b/doc/GetShellWithoutMonitorOnWindows.md @@ -14,7 +14,8 @@ 1. Run the following commands: ``` cd ~ - wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup-piForHeadlessConfig.ps1 -OutFile setup-piForHeadlessConfig.ps1 + wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup/windows/setup-piForHeadlessConfig.ps1 -OutFile setup-piForHeadlessConfig.ps1 + wget https://raw.githubusercontent.com/cimryan/teslausb/master/setup/windows/WpaSupplicantConf.psm1 -OutFile WpaSupplicantConf.psm1 ./setup-piForHeadlessConfig.ps1 -Verbose ``` 1. Enter the single letter of the "boot" drive and press Enter. diff --git a/SetupRSync.md b/doc/SetupRSync.md similarity index 100% rename from SetupRSync.md rename to doc/SetupRSync.md diff --git a/archive-teslacam-clips b/run/archive-teslacam-clips similarity index 100% rename from archive-teslacam-clips rename to run/archive-teslacam-clips diff --git a/archiveloop b/run/archiveloop similarity index 100% rename from archiveloop rename to run/archiveloop diff --git a/cifs_archive/archive-clips.sh b/run/cifs_archive/archive-clips.sh similarity index 100% rename from cifs_archive/archive-clips.sh rename to run/cifs_archive/archive-clips.sh diff --git a/cifs_archive/configure-archive.sh b/run/cifs_archive/configure-archive.sh similarity index 100% rename from cifs_archive/configure-archive.sh rename to run/cifs_archive/configure-archive.sh diff --git a/cifs_archive/connect-archive.sh b/run/cifs_archive/connect-archive.sh similarity index 100% rename from cifs_archive/connect-archive.sh rename to run/cifs_archive/connect-archive.sh diff --git a/cifs_archive/disconnect-archive.sh b/run/cifs_archive/disconnect-archive.sh similarity index 100% rename from cifs_archive/disconnect-archive.sh rename to run/cifs_archive/disconnect-archive.sh diff --git a/cifs_archive/verify-archive-configuration.sh b/run/cifs_archive/verify-archive-configuration.sh similarity index 100% rename from cifs_archive/verify-archive-configuration.sh rename to run/cifs_archive/verify-archive-configuration.sh diff --git a/cifs_archive/write-archive-credentials-to.sh b/run/cifs_archive/write-archive-credentials-to.sh similarity index 100% rename from cifs_archive/write-archive-credentials-to.sh rename to run/cifs_archive/write-archive-credentials-to.sh diff --git a/get-archiveserver-ip-address.sh b/run/get-archiveserver-ip-address.sh similarity index 100% rename from get-archiveserver-ip-address.sh rename to run/get-archiveserver-ip-address.sh diff --git a/remountfs_rw b/run/remountfs_rw similarity index 100% rename from remountfs_rw rename to run/remountfs_rw diff --git a/rsync_archive/archive-clips.sh b/run/rsync_archive/archive-clips.sh similarity index 100% rename from rsync_archive/archive-clips.sh rename to run/rsync_archive/archive-clips.sh diff --git a/rsync_archive/configure-archive.sh b/run/rsync_archive/configure-archive.sh similarity index 100% rename from rsync_archive/configure-archive.sh rename to run/rsync_archive/configure-archive.sh diff --git a/rsync_archive/connect-archive.sh b/run/rsync_archive/connect-archive.sh similarity index 100% rename from rsync_archive/connect-archive.sh rename to run/rsync_archive/connect-archive.sh diff --git a/rsync_archive/disconnect-archive.sh b/run/rsync_archive/disconnect-archive.sh similarity index 100% rename from rsync_archive/disconnect-archive.sh rename to run/rsync_archive/disconnect-archive.sh diff --git a/rsync_archive/verify-archive-configuration.sh b/run/rsync_archive/verify-archive-configuration.sh similarity index 100% rename from rsync_archive/verify-archive-configuration.sh rename to run/rsync_archive/verify-archive-configuration.sh diff --git a/send-pushover b/run/send-pushover similarity index 100% rename from send-pushover rename to run/send-pushover diff --git a/setup-piForHeadlessConfig.sh b/setup/macos_linux/setup-piForHeadlessConfig.sh similarity index 100% rename from setup-piForHeadlessConfig.sh rename to setup/macos_linux/setup-piForHeadlessConfig.sh diff --git a/create-backingfiles-partition.sh b/setup/pi/create-backingfiles-partition.sh similarity index 100% rename from create-backingfiles-partition.sh rename to setup/pi/create-backingfiles-partition.sh diff --git a/create-backingfiles.sh b/setup/pi/create-backingfiles.sh similarity index 100% rename from create-backingfiles.sh rename to setup/pi/create-backingfiles.sh diff --git a/make-root-fs-readonly.sh b/setup/pi/make-root-fs-readonly.sh similarity index 100% rename from make-root-fs-readonly.sh rename to setup/pi/make-root-fs-readonly.sh diff --git a/setup-teslausb b/setup/pi/setup-teslausb similarity index 82% rename from setup-teslausb rename to setup/pi/setup-teslausb index 8c0d6b1..abf884a 100644 --- a/setup-teslausb +++ b/setup/pi/setup-teslausb @@ -68,9 +68,9 @@ function get_script () { } function get_ancillary_setup_scripts () { - get_script /tmp create-backingfiles-partition.sh - get_script /tmp create-backingfiles.sh - get_script /tmp make-root-fs-readonly.sh + get_script /tmp create-backingfiles-partition.sh setup/pi + get_script /tmp create-backingfiles.sh setup/pi + get_script /tmp make-root-fs-readonly.sh setup/pi } function fix_cmdline_txt_modules_load () @@ -111,27 +111,27 @@ function create_usb_drive_backing_files () { function configure_archive_scripts () { echo "Configuring the archive scripts..." - get_script /root/bin archiveloop - get_script /root/bin archive-teslacam-clips + get_script /root/bin archiveloop run + get_script /root/bin archive-teslacam-clips run if [ $RSYNC_ENABLE = true ] then - get_script /root/bin archive-clips.sh rsync_archive - get_script /root/bin connect-archive.sh rsync_archive - get_script /root/bin disconnect-archive.sh rsync_archive + get_script /root/bin archive-clips.sh run/rsync_archive + get_script /root/bin connect-archive.sh run/rsync_archive + get_script /root/bin disconnect-archive.sh run/rsync_archive else - get_script /root/bin archive-clips.sh cifs_archive - get_script /root/bin connect-archive.sh cifs_archive - get_script /root/bin disconnect-archive.sh cifs_archive + get_script /root/bin archive-clips.sh run/cifs_archive + get_script /root/bin connect-archive.sh run/cifs_archive + get_script /root/bin disconnect-archive.sh run/cifs_archive fi - get_script /root/bin remountfs_rw + get_script /root/bin remountfs_rw run echo "Configured the archive scripts." } function configure_pushover_scripts() { - get_script /root/bin send-pushover + get_script /root/bin send-pushover run } function configure_rc_local () { @@ -208,15 +208,15 @@ fi if [ "$RSYNC_ENABLE" = true ] then - get_script /root/bin verify-archive-configuration.sh rsync_archive - get_script /root/bin configure-archive.sh rsync_archive + get_script /root/bin verify-archive-configuration.sh run/rsync_archive + get_script /root/bin configure-archive.sh run/rsync_archive else - get_script /root/bin verify-archive-configuration.sh cifs_archive - get_script /root/bin configure-archive.sh cifs_archive - get_script /root/bin write-archive-credentials-to.sh cifs_archive + get_script /root/bin verify-archive-configuration.sh run/cifs_archive + get_script /root/bin configure-archive.sh run/cifs_archive + get_script /root/bin write-archive-credentials-to.sh run/cifs_archive fi -get_script /root/bin get-archiveserver-ip-address.sh +get_script /root/bin get-archiveserver-ip-address.sh run /root/bin/verify-archive-configuration.sh diff --git a/setup/windows/WpaSupplicantConf.psm1 b/setup/windows/WpaSupplicantConf.psm1 new file mode 100644 index 0000000..93b9f7a --- /dev/null +++ b/setup/windows/WpaSupplicantConf.psm1 @@ -0,0 +1,91 @@ +function Write-Header { +param( + [string]$driveLetter + ) +$header=@" +ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev +update_config=1 +"@ + + Set-WpaSupplicantConfContent "$driveLetter" "$header" +} + +function Add-Network { +param( + [string]$driveLetter, + [string]$wifiSSID, + [string]$wifiPSK + ) + + $network=@" + + +network={ + ssid="$wifiSSID" + psk="$wifiPSK" +} +"@ + + Add-WpaSupplicantConfContent "$driveLetter" "$network" +} + +function Set-WpaSupplicantConfContent { +param( + [string]$driveLetter, + [string]$content + ) + + $wpaSupplicantConfPath = Get-WpaSupplicantConfPath $driveLetter + $encodedContent = Encode-Content $content + Set-Content -Value $encodedContent -Encoding Byte -Path "$wpaSupplicantConfPath" +} + +function Add-WpaSupplicantConfContent { +param( + [string]$driveLetter, + [string]$content + ) + + $wpaSupplicantConfPath = Get-WpaSupplicantConfPath $driveLetter + $encodedContent = Encode-Content $content + Add-Content -Value $encodedContent -Encoding Byte -Path "$wpaSupplicantConfPath" +} + +function Verify-WpaSupplicantConfPath { +param( + [string]$driveLetter + ) + + $drivePath="${driveLetter}:" + $configPath = "$drivePath\config.txt" + $cmdlinePath = "$drivePath\cmdline.txt" + $sshPath = "$drivePath\ssh" + + if ((![System.IO.File]::Exists($configPath) -or + (![System.IO.File]::Exists($cmdlinePath)))) { + Write-Error "Didn't find cmdline.txt and config.txt on drive $drivePath." + exit 1 + } +} + +function Encode-Content { +param( + [string]$content + ) + $utf8 = New-Object System.Text.UTF8Encoding $false + + return $utf8.GetBytes($content) +} + +function Get-WpaSupplicantConfPath { +param( + [string]$driveLetter + ) + + Verify-WpaSupplicantConfPath $driveLetter + + return "${driveLetter}:\wpa_supplicant.conf" +} + +Export-ModuleMember -Function Write-Header +Export-ModuleMember -Function Add-Network \ No newline at end of file diff --git a/setup/windows/add-wifi.ps1 b/setup/windows/add-wifi.ps1 new file mode 100644 index 0000000..cd1b06e --- /dev/null +++ b/setup/windows/add-wifi.ps1 @@ -0,0 +1,18 @@ +[CmdletBinding()] +Param +( + [Parameter(Mandatory=$True,Position=1)] + [string]$driveLetter, + + [Parameter(Mandatory=$True,Position=2)] + [string]$wifiSSID, + + [Parameter(Mandatory=$True,Position=3)] + [string]$wifiPSK +) + +Import-Module -Name ".\WpaSupplicantConf.psm1" -Force + +Add-Network "$driveLetter" "$wifiSSID" "$wifiPSK" + +Write-Verbose "All done." diff --git a/setup-piForHeadlessConfig.ps1 b/setup/windows/setup-piForHeadlessConfig.ps1 similarity index 68% rename from setup-piForHeadlessConfig.ps1 rename to setup/windows/setup-piForHeadlessConfig.ps1 index d2a1eea..a2a802c 100644 --- a/setup-piForHeadlessConfig.ps1 +++ b/setup/windows/setup-piForHeadlessConfig.ps1 @@ -11,6 +11,8 @@ Param [string]$wifiPSK ) +Import-Module -Name ".\WpaSupplicantConf.psm1" -Force + $drivePath="${driveLetter}:" $configPath = "$drivePath\config.txt" $cmdlinePath = "$drivePath\cmdline.txt" @@ -34,28 +36,9 @@ $cmdlinetxtContent.Replace("rootwait", "rootwait modules-load=dwc2,g_ether").Rep Write-Verbose "Enabling SSH ..." [System.IO.File]::CreateText($sshPath).Dispose() -# Sets up wifi credentials so wifi will be -# auto configured on first boot - -$wpaSupplicantConfPath="$drivePath\wpa_supplicant.conf" - Write-Verbose "(Re)creating WiFi configuration file $wpaSupplicantConfPath." -if ([System.IO.File]::Exists("$wpaSupplicantConfPath")) { - del "$wpaSupplicantConfPath" -} -$wpaSupplicantConfContent=@" -ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev -update_config=1 - -network={ - ssid="$wifiSSID" - psk="$wifiPSK" -} -"@ - -$utf8 = New-Object System.Text.UTF8Encoding $false - -Set-Content -Value $utf8.GetBytes($wpaSupplicantConfContent) -Encoding Byte -Path "$wpaSupplicantConfPath" +Write-Header "$driveLetter" +Add-Network "$driveLetter" "$wifiSSID" "$wifiPSK" Write-Verbose "All done." \ No newline at end of file