Merge pull request #58 from cimryan/u/skipfire/add_wifi

U/skipfire/add wifi
This commit is contained in:
cimryan
2018-10-24 22:58:36 -07:00
committed by GitHub
30 changed files with 174 additions and 89 deletions

View File

@@ -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.

View File

@@ -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. > Note: you don't need to uncompress the zip file you downloaded.
### Get a shell on the Pi ### 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 ### 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=<number> export campercent=<number>
``` ```
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. 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: 1. If you are trying to archive on a shared drive, run these commands, subsituting your values for your shared drive:
``` ```
export archiveserver=Nautilus 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 shareuser=sailfish
export sharepassword=pa$$w0rd 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: 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 chmod +x setup-teslausb
./setup-teslausb ./setup-teslausb
``` ```

View File

@@ -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.

View File

@@ -14,7 +14,8 @@
1. Run the following commands: 1. Run the following commands:
``` ```
cd ~ 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 ./setup-piForHeadlessConfig.ps1 -Verbose
``` ```
1. Enter the single letter of the "boot" drive and press Enter. 1. Enter the single letter of the "boot" drive and press Enter.

View File

@@ -68,9 +68,9 @@ function get_script () {
} }
function get_ancillary_setup_scripts () { function get_ancillary_setup_scripts () {
get_script /tmp create-backingfiles-partition.sh get_script /tmp create-backingfiles-partition.sh setup/pi
get_script /tmp create-backingfiles.sh get_script /tmp create-backingfiles.sh setup/pi
get_script /tmp make-root-fs-readonly.sh get_script /tmp make-root-fs-readonly.sh setup/pi
} }
function fix_cmdline_txt_modules_load () function fix_cmdline_txt_modules_load ()
@@ -111,27 +111,27 @@ function create_usb_drive_backing_files () {
function configure_archive_scripts () { function configure_archive_scripts () {
echo "Configuring the archive scripts..." echo "Configuring the archive scripts..."
get_script /root/bin archiveloop get_script /root/bin archiveloop run
get_script /root/bin archive-teslacam-clips get_script /root/bin archive-teslacam-clips run
if [ $RSYNC_ENABLE = true ] if [ $RSYNC_ENABLE = true ]
then then
get_script /root/bin archive-clips.sh rsync_archive get_script /root/bin archive-clips.sh run/rsync_archive
get_script /root/bin connect-archive.sh rsync_archive get_script /root/bin connect-archive.sh run/rsync_archive
get_script /root/bin disconnect-archive.sh rsync_archive get_script /root/bin disconnect-archive.sh run/rsync_archive
else else
get_script /root/bin archive-clips.sh cifs_archive get_script /root/bin archive-clips.sh run/cifs_archive
get_script /root/bin connect-archive.sh cifs_archive get_script /root/bin connect-archive.sh run/cifs_archive
get_script /root/bin disconnect-archive.sh cifs_archive get_script /root/bin disconnect-archive.sh run/cifs_archive
fi fi
get_script /root/bin remountfs_rw get_script /root/bin remountfs_rw run
echo "Configured the archive scripts." echo "Configured the archive scripts."
} }
function configure_pushover_scripts() { function configure_pushover_scripts() {
get_script /root/bin send-pushover get_script /root/bin send-pushover run
} }
function configure_rc_local () { function configure_rc_local () {
@@ -208,15 +208,15 @@ fi
if [ "$RSYNC_ENABLE" = true ] if [ "$RSYNC_ENABLE" = true ]
then then
get_script /root/bin verify-archive-configuration.sh rsync_archive get_script /root/bin verify-archive-configuration.sh run/rsync_archive
get_script /root/bin configure-archive.sh rsync_archive get_script /root/bin configure-archive.sh run/rsync_archive
else else
get_script /root/bin verify-archive-configuration.sh cifs_archive get_script /root/bin verify-archive-configuration.sh run/cifs_archive
get_script /root/bin configure-archive.sh cifs_archive get_script /root/bin configure-archive.sh run/cifs_archive
get_script /root/bin write-archive-credentials-to.sh cifs_archive get_script /root/bin write-archive-credentials-to.sh run/cifs_archive
fi 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 /root/bin/verify-archive-configuration.sh

View File

@@ -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

View File

@@ -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."

View File

@@ -11,6 +11,8 @@ Param
[string]$wifiPSK [string]$wifiPSK
) )
Import-Module -Name ".\WpaSupplicantConf.psm1" -Force
$drivePath="${driveLetter}:" $drivePath="${driveLetter}:"
$configPath = "$drivePath\config.txt" $configPath = "$drivePath\config.txt"
$cmdlinePath = "$drivePath\cmdline.txt" $cmdlinePath = "$drivePath\cmdline.txt"
@@ -34,28 +36,9 @@ $cmdlinetxtContent.Replace("rootwait", "rootwait modules-load=dwc2,g_ether").Rep
Write-Verbose "Enabling SSH ..." Write-Verbose "Enabling SSH ..."
[System.IO.File]::CreateText($sshPath).Dispose() [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." Write-Verbose "(Re)creating WiFi configuration file $wpaSupplicantConfPath."
if ([System.IO.File]::Exists("$wpaSupplicantConfPath")) {
del "$wpaSupplicantConfPath"
}
$wpaSupplicantConfContent=@" Write-Header "$driveLetter"
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev Add-Network "$driveLetter" "$wifiSSID" "$wifiPSK"
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-Verbose "All done." Write-Verbose "All done."