From fa048447a825998f0248eb9818cae059e8aca781 Mon Sep 17 00:00:00 2001 From: skipfire Date: Tue, 23 Oct 2018 18:25:29 -0500 Subject: [PATCH 1/6] Multiple WiFi Adding powershell script to run after main setup to add additional WiFi configs. --- .../setup-piForHeadlessConfigAddWifi.ps1 | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 windows_archive/setup-piForHeadlessConfigAddWifi.ps1 diff --git a/windows_archive/setup-piForHeadlessConfigAddWifi.ps1 b/windows_archive/setup-piForHeadlessConfigAddWifi.ps1 new file mode 100644 index 0000000..ef2d69f --- /dev/null +++ b/windows_archive/setup-piForHeadlessConfigAddWifi.ps1 @@ -0,0 +1,31 @@ +[CmdletBinding()] +Param +( + [Parameter(Mandatory=$True,Position=1)] + [string]$driveLetter, + + [Parameter(Mandatory=$True,Position=2)] + [string]$wifiSSID, + + [Parameter(Mandatory=$True,Position=3)] + [string]$wifiPSK +) + +$drivePath="${driveLetter}:" + +$wpaSupplicantConfPath="$drivePath\wpa_supplicant.conf" + +$wpaSupplicantConfContent=@" + + +network={ + ssid="$wifiSSID" + psk="$wifiPSK" +} +"@ + +$utf8 = New-Object System.Text.UTF8Encoding $false + +Add-Content -Value $utf8.GetBytes($wpaSupplicantConfContent) -Encoding Byte -Path "$wpaSupplicantConfPath" + +Write-Verbose "All done." From ef10b2ec67967dfaee527f215e260a5053dc7ac7 Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 20:44:14 -0700 Subject: [PATCH 2/6] Move setup-piForHeadlessConfigAddWifi.ps1 to windows_setup --- .../setup-piForHeadlessConfigAddWifi.ps1 | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {windows_archive => windows_setup}/setup-piForHeadlessConfigAddWifi.ps1 (100%) diff --git a/windows_archive/setup-piForHeadlessConfigAddWifi.ps1 b/windows_setup/setup-piForHeadlessConfigAddWifi.ps1 similarity index 100% rename from windows_archive/setup-piForHeadlessConfigAddWifi.ps1 rename to windows_setup/setup-piForHeadlessConfigAddWifi.ps1 From e875763e58188c2d383b3507a35ad9e462125f1f Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 20:55:29 -0700 Subject: [PATCH 3/6] Separate files into those used for setup and those used at runtime. Files used for both will go in the run tree. --- .../ConfigureNotificationsForArchive.md | 0 .../GetShellWithoutMonitorOnLinux.md | 0 .../GetShellWithoutMonitorOnWindows.md | 0 SetupRSync.md => doc/SetupRSync.md | 0 archive-teslacam-clips => run/archive-teslacam-clips | 0 archiveloop => run/archiveloop | 0 {cifs_archive => run/cifs_archive}/archive-clips.sh | 0 {cifs_archive => run/cifs_archive}/configure-archive.sh | 0 {cifs_archive => run/cifs_archive}/connect-archive.sh | 0 {cifs_archive => run/cifs_archive}/disconnect-archive.sh | 0 .../cifs_archive}/verify-archive-configuration.sh | 0 .../cifs_archive}/write-archive-credentials-to.sh | 0 .../get-archiveserver-ip-address.sh | 0 remountfs_rw => run/remountfs_rw | 0 {rsync_archive => run/rsync_archive}/archive-clips.sh | 0 {rsync_archive => run/rsync_archive}/configure-archive.sh | 0 {rsync_archive => run/rsync_archive}/connect-archive.sh | 0 {rsync_archive => run/rsync_archive}/disconnect-archive.sh | 0 .../rsync_archive}/verify-archive-configuration.sh | 0 send-pushover => run/send-pushover | 0 .../macos_linux/setup-piForHeadlessConfig.sh | 0 .../pi/create-backingfiles-partition.sh | 0 create-backingfiles.sh => setup/pi/create-backingfiles.sh | 0 make-root-fs-readonly.sh => setup/pi/make-root-fs-readonly.sh | 0 setup-teslausb => setup/pi/setup-teslausb | 0 .../windows/setup-piForHeadlessConfig.ps1 | 0 .../windows}/setup-piForHeadlessConfigAddWifi.ps1 | 0 27 files changed, 0 insertions(+), 0 deletions(-) rename ConfigureNotificationsForArchive.md => doc/ConfigureNotificationsForArchive.md (100%) rename GetShellWithoutMonitorOnLinux.md => doc/GetShellWithoutMonitorOnLinux.md (100%) rename GetShellWithoutMonitorOnWindows.md => doc/GetShellWithoutMonitorOnWindows.md (100%) rename SetupRSync.md => doc/SetupRSync.md (100%) rename archive-teslacam-clips => run/archive-teslacam-clips (100%) rename archiveloop => run/archiveloop (100%) rename {cifs_archive => run/cifs_archive}/archive-clips.sh (100%) rename {cifs_archive => run/cifs_archive}/configure-archive.sh (100%) rename {cifs_archive => run/cifs_archive}/connect-archive.sh (100%) rename {cifs_archive => run/cifs_archive}/disconnect-archive.sh (100%) rename {cifs_archive => run/cifs_archive}/verify-archive-configuration.sh (100%) rename {cifs_archive => run/cifs_archive}/write-archive-credentials-to.sh (100%) rename get-archiveserver-ip-address.sh => run/get-archiveserver-ip-address.sh (100%) rename remountfs_rw => run/remountfs_rw (100%) rename {rsync_archive => run/rsync_archive}/archive-clips.sh (100%) rename {rsync_archive => run/rsync_archive}/configure-archive.sh (100%) rename {rsync_archive => run/rsync_archive}/connect-archive.sh (100%) rename {rsync_archive => run/rsync_archive}/disconnect-archive.sh (100%) rename {rsync_archive => run/rsync_archive}/verify-archive-configuration.sh (100%) rename send-pushover => run/send-pushover (100%) rename setup-piForHeadlessConfig.sh => setup/macos_linux/setup-piForHeadlessConfig.sh (100%) rename create-backingfiles-partition.sh => setup/pi/create-backingfiles-partition.sh (100%) rename create-backingfiles.sh => setup/pi/create-backingfiles.sh (100%) rename make-root-fs-readonly.sh => setup/pi/make-root-fs-readonly.sh (100%) rename setup-teslausb => setup/pi/setup-teslausb (100%) rename setup-piForHeadlessConfig.ps1 => setup/windows/setup-piForHeadlessConfig.ps1 (100%) rename {windows_setup => setup/windows}/setup-piForHeadlessConfigAddWifi.ps1 (100%) diff --git a/ConfigureNotificationsForArchive.md b/doc/ConfigureNotificationsForArchive.md similarity index 100% rename from ConfigureNotificationsForArchive.md rename to doc/ConfigureNotificationsForArchive.md diff --git a/GetShellWithoutMonitorOnLinux.md b/doc/GetShellWithoutMonitorOnLinux.md similarity index 100% rename from GetShellWithoutMonitorOnLinux.md rename to doc/GetShellWithoutMonitorOnLinux.md diff --git a/GetShellWithoutMonitorOnWindows.md b/doc/GetShellWithoutMonitorOnWindows.md similarity index 100% rename from GetShellWithoutMonitorOnWindows.md rename to doc/GetShellWithoutMonitorOnWindows.md 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 100% rename from setup-teslausb rename to setup/pi/setup-teslausb diff --git a/setup-piForHeadlessConfig.ps1 b/setup/windows/setup-piForHeadlessConfig.ps1 similarity index 100% rename from setup-piForHeadlessConfig.ps1 rename to setup/windows/setup-piForHeadlessConfig.ps1 diff --git a/windows_setup/setup-piForHeadlessConfigAddWifi.ps1 b/setup/windows/setup-piForHeadlessConfigAddWifi.ps1 similarity index 100% rename from windows_setup/setup-piForHeadlessConfigAddWifi.ps1 rename to setup/windows/setup-piForHeadlessConfigAddWifi.ps1 From 5db24b3af04222ed92b24997d1a30f2fa9390760 Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 21:19:16 -0700 Subject: [PATCH 4/6] Fix references to file locations, and simplify llinux/macos instructions. --- README.md | 10 +++--- doc/GetShellWithoutMonitorOnLinux.md | 42 +++++++++++--------------- doc/GetShellWithoutMonitorOnWindows.md | 2 +- setup/pi/setup-teslausb | 38 +++++++++++------------ 4 files changed, 42 insertions(+), 50 deletions(-) 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/doc/GetShellWithoutMonitorOnLinux.md b/doc/GetShellWithoutMonitorOnLinux.md index 2013114..2439691 100644 --- a/doc/GetShellWithoutMonitorOnLinux.md +++ b/doc/GetShellWithoutMonitorOnLinux.md @@ -1,43 +1,35 @@ -# Setting up the Pi without a monitor using a Mac or Linux +# Getting a shell on 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). +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. - -**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**. +**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. +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/mac_linux_archive/setup-piForHeadlessConfig.sh + 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. Run the script: - `./setup-piForHeadlessConfig.sh` +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 --` + ``` + -- 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/doc/GetShellWithoutMonitorOnWindows.md b/doc/GetShellWithoutMonitorOnWindows.md index 205c0b2..83aa360 100644 --- a/doc/GetShellWithoutMonitorOnWindows.md +++ b/doc/GetShellWithoutMonitorOnWindows.md @@ -14,7 +14,7 @@ 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 ./setup-piForHeadlessConfig.ps1 -Verbose ``` 1. Enter the single letter of the "boot" drive and press Enter. diff --git a/setup/pi/setup-teslausb b/setup/pi/setup-teslausb index 8c0d6b1..abf884a 100644 --- a/setup/pi/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 From 27ed80059b1da48bb7af1fe4425ac76e44e3775d Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 21:20:35 -0700 Subject: [PATCH 5/6] Rename setup-piForHeadlessConfigAddWifi --- .../{setup-piForHeadlessConfigAddWifi.ps1 => add-wifi.ps1} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename setup/windows/{setup-piForHeadlessConfigAddWifi.ps1 => add-wifi.ps1} (100%) diff --git a/setup/windows/setup-piForHeadlessConfigAddWifi.ps1 b/setup/windows/add-wifi.ps1 similarity index 100% rename from setup/windows/setup-piForHeadlessConfigAddWifi.ps1 rename to setup/windows/add-wifi.ps1 From c607860052210dcfe24b0e326504f5666b685b0b Mon Sep 17 00:00:00 2001 From: cimryan Date: Wed, 24 Oct 2018 22:33:51 -0700 Subject: [PATCH 6/6] Extract common functionality to WpaSupplicantConf.psm1 --- doc/GetShellWithoutMonitorOnWindows.md | 1 + setup/windows/WpaSupplicantConf.psm1 | 91 +++++++++++++++++++++ setup/windows/add-wifi.ps1 | 17 +--- setup/windows/setup-piForHeadlessConfig.ps1 | 25 +----- 4 files changed, 98 insertions(+), 36 deletions(-) create mode 100644 setup/windows/WpaSupplicantConf.psm1 diff --git a/doc/GetShellWithoutMonitorOnWindows.md b/doc/GetShellWithoutMonitorOnWindows.md index 83aa360..0142aeb 100644 --- a/doc/GetShellWithoutMonitorOnWindows.md +++ b/doc/GetShellWithoutMonitorOnWindows.md @@ -15,6 +15,7 @@ ``` cd ~ 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/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 index ef2d69f..cd1b06e 100644 --- a/setup/windows/add-wifi.ps1 +++ b/setup/windows/add-wifi.ps1 @@ -11,21 +11,8 @@ Param [string]$wifiPSK ) -$drivePath="${driveLetter}:" +Import-Module -Name ".\WpaSupplicantConf.psm1" -Force -$wpaSupplicantConfPath="$drivePath\wpa_supplicant.conf" - -$wpaSupplicantConfContent=@" - - -network={ - ssid="$wifiSSID" - psk="$wifiPSK" -} -"@ - -$utf8 = New-Object System.Text.UTF8Encoding $false - -Add-Content -Value $utf8.GetBytes($wpaSupplicantConfContent) -Encoding Byte -Path "$wpaSupplicantConfPath" +Add-Network "$driveLetter" "$wifiSSID" "$wifiPSK" Write-Verbose "All done." diff --git a/setup/windows/setup-piForHeadlessConfig.ps1 b/setup/windows/setup-piForHeadlessConfig.ps1 index d2a1eea..a2a802c 100644 --- a/setup/windows/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