Merge branch 'rtgoodwin/updater-script' of github.com:cimryan/teslausb into rtgoodwin/updater-script

This commit is contained in:
cimryan
2018-10-18 08:57:55 -07:00
7 changed files with 199 additions and 28 deletions

View File

@@ -0,0 +1,43 @@
# 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/update-rpi-mac-linux.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/update-rpi-mac-linux.sh
chmod +x update-rpi-mac-linux.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:
`./update-rpi-mac-linux.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

@@ -1,10 +0,0 @@
# Seting up the Pi without a monitor using a Mac or Linux
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).
Here are a few ways to accomplish this
* [Gist (text file) showing example steps and discussion thread about issues, etc](https://gist.github.com/gbaman/975e2db164b3ca2b51ae11e45e8fd40a)
* [Script to setup the Pi for connecting over USB](https://github.com/BigNate1234/rpi-USBSSH)
* (I.e. First write the OS image to the SD card, then this script will make the changes to the card so you can boot it and access it over the USB cable.
* **Assumes the SD card for the Pi is mounted at /Volumes/boot , and that you can use `sh`/`bash`**. This _should_ be the default for a Mac; if using something else, modify the script accordingly.
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

@@ -1,7 +1,7 @@
# teslausb # teslaUSB
## Meta ## Meta
This repo contains steps and scripts originally from [this thread on Reddit]( https://www.reddit.com/r/teslamotors/comments/9m9gyk/build_a_smart_usb_drive_for_your_tesla_dash_cam/) This repo contains steps and scripts originally from [this thread on Reddit]( https://www.reddit.com/r/teslamotors/comments/9m9gyk/build_a_smart_USB_drive_for_your_tesla_dash_cam/)
Many people in that thread suggested that the scripts be hosted on Github but the author didn't seem interested in making that happen. I've hosted the scripts here with his/her permission. Many people in that thread suggested that the scripts be hosted on Github but the author didn't seem interested in making that happen. I've hosted the scripts here with his/her permission.
@@ -54,7 +54,7 @@ Download and install:
## Create your archive ## Create your archive
### Hosting on Windows ### Hosting on Windows
Set up a share on a Windows machine to host the archive. These instructions assume that you created a share named "SailfishCam" on the server "Nautilus". It is recommended that you create a new user. Grant the user you'll be using read/write access to the share. These instructions will assume that the user you've created is named "sailfish" and that the password for this user is "pa$$w0rd". Set up a share on a Windows (or macOS using Sharing, or Linux using Samba) machine to host the archive. These instructions assume that you created a share named "SailfishCam" on the server "Nautilus". It is recommended that you create a new user. Grant the user you'll be using read/write access to the share. These instructions will assume that the user you've created is named "sailfish" and that the password for this user is "pa$$w0rd".
Get the IP address of the archive machine. You'll need this later, so write it down, somewhere. You can do this by opening a command prompt on the archive machine and typing ipconfig. Get the IP address from the line labeled "IPv4 Address". These instructions will assume that the IP address of the archive server is 192.168.0.41. Get the IP address of the archive machine. You'll need this later, so write it down, somewhere. You can do this by opening a command prompt on the archive machine and typing ipconfig. Get the IP address from the line labeled "IPv4 Address". These instructions will assume that the IP address of the archive server is 192.168.0.41.
@@ -75,22 +75,31 @@ There are four 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
> Regardless of which way you use to access the Pi (Keyboard+HDMI or USB networking), **before you boot the Pi for for the first time with the MicroSD inserted**, edit the /boot/cmdline.txt file on the MicroSD to delete the parameter "init=/usr/lib/raspi-config/init_resize.sh". > Regardless of which way you use to access the Pi (Keyboard+HDMI or USB networking), **before you boot the Pi for for the first time with the MicroSD inserted**, verify that the /boot/cmdline.txt file on the MicroSD does not contain the parameter "init=/usr/lib/raspi-config/init_resize.sh". Delete that entire string if present.
If you have a monitor with an hdmi input, a mini hdmi to hdmi cable, a usb keyboard and a micro usb power cable you can hook up the devices to the Pi and configure it directly. #### Use a monitor/keyboard/mouse
If you have a monitor with an HDMI input, a Mini HDMI to HDMI cable, a USB keyboard and a Micro USB power cable you can hook up the devices to the Pi and configure it directly.
1. Insert the MicroSD card into the Pi. 1. Insert the MicroSD card into the Pi.
1. Connect the keyboard, and monitor to the Pi. 1. Connect the keyboard, and monitor to the Pi.
1. Connect the power supply to the Pi using the port labeld "PWR" on the circuitboard. 1. Connect the power supply to the Pi using the port labeld "PWR" on the circuitboard.
1. When you're prompted for the password for the user "pi" use "raspberry" without the quotes. 1. When you're prompted for the password for the user "pi" use "raspberry" without the quotes.
1. Now skip to section below titled "Get the scripts onto the Pi". 1. Now skip to section below titled "Get the scripts onto the Pi".
If you don't have a keyboard/HDMI setup to boot the Pi and edit/transfer files directly, you'll probably want to connect to the Pi over USB. #### Windows (Setup USB Networking)
* If you're using Windows, follow [these instructions](GetShellWithoutMonitorOnWindows.md), then skip down to the section titled "Get the scripts onto the Pi".
* If you're using Linux or a Mac, follow [these instructions](GetShellWitoutMonitorOnLinux.md), then proceed to the next section. If you don't have a keyboard/HDMI setup to boot the Pi and edit/transfer files directly, you'll probably want to connect to the Pi over Wifi or USB networking.
* Follow [these instructions](GetShellWithoutMonitorOnWindows.md), then skip down to the section titled **Set up Set up Wifi on the Pi (manually)y**.
#### macOS or Linux (Setup Wifi or USB Networking)
* Follow [these instructions](GetShellWithoutMonitorOnLinux.md), then proceed to the section **Set up the USB Storage Functionality**.
### Get the scripts onto the Pi ### Set up Wifi on the Pi (manually)
Now that you have a shell on the Pi you can turn the Pi into a smart USB drive.
If you don't yet have Wifi running from the previous section, use these instructions to get it set up. Otherwise, skip to **Set up the USB Storage Functionality**.
Now that you have an `ssh` shell on the Pi over USB networking, you can set up Wifi and continue with setup.
1. Enter the following commands: 1. Enter the following commands:
``` ```
sudo -i sudo -i
@@ -114,7 +123,13 @@ Now that you have a shell on the Pi you can turn the Pi into a smart USB drive.
ifconfig wlan0 ifconfig wlan0
``` ```
1. Verify that there's an IP address on your subnet assigned. If you don't see the IP address wait for a couple of seconds and re-run the command. 1. Verify that there's an IP address on your subnet assigned. If you don't see the IP address wait for a couple of seconds and re-run the command.
1. Try to ping your archive server from the Pi.
### Set up the USB Storage Functionality
Now that you have Wifi up and running, it's time to set up the USB Storage and scripts that will manage the dashcam and (optionally) music storage.
1. SSH to the Pi and run `sudo -i`
1. Try to ping your archive server from the Pi. In this example the server is named `nautilus`.
``` ```
ping -c 3 nautilus ping -c 3 nautilus
``` ```
@@ -122,7 +137,7 @@ Now that you have a shell on the Pi you can turn the Pi into a smart USB drive.
``` ```
ping 192.168.0.41 ping 192.168.0.41
``` ```
1. If you can't ping the archive server by IP address from the Pi you should go do whatever you need to on your network to fix that. If you can't reach the archive server by name from the Pi but you can by IP address then use its IP address, below, in place of its name. 1. If you can't ping the archive server by IP address from the Pi, you should go do whatever you need to on your network to fix that. If you can't reach the archive server by name, from the Pi but you can by IP address, then use its IP address, below, in place of its name.
1. Run these commands, subsituting your values. The last line is the percent of the drive you want to allocate for dashcam storage. The remaining percentage will be allocated for music. 1. Run these commands, subsituting your values. The last line is the percent of the drive you want to allocate for dashcam storage. The remaining percentage will be allocated for music.
``` ```
export archiveserver=Nautilus export archiveserver=Nautilus
@@ -145,16 +160,19 @@ Now that you have a shell on the Pi you can turn the Pi into a smart USB drive.
``` ```
1. Run these commands: 1. Run these commands:
``` ```
wget https://raw.githubusercontent.com/cimryan/teslausb/master/windows_archive/setup-teslausb wget https://raw.githubusercontent.com/cimryan/teslaUSB/master/windows_archive/setup-teslaUSB
chmod +x setup-teslausb chmod +x setup-teslaUSB
./setup-teslausb ./setup-teslaUSB
``` ```
1. Run this command: 1. Run this command:
``` ```
reboot reboot
``` ```
After reboot, the Pi hostname will become `teslaUSB`, so future `ssh` sessions will be `ssh pi@teslaUSB.local`.
### Get the Pi set up for your Tesla. ### Get the Pi set up for your Tesla.
If you set up the Pi with a keyboard and a monitor disconnect it and connect it to a PC. If you're using a cable be sure to use the port labeled "usb" on the circuitboard. If you set up the Pi with a keyboard and a monitor disconnect it and connect it to a PC. If you're using a cable be sure to use the port labeled "USB" on the circuitboard.
1. Wait for the Pi to show up on the PC as a USB drive. 1. Wait for the Pi to show up on the PC as a USB drive.
1. Create a directory named TeslaCam at the root of the drive labeled CAM. 1. Create a directory named TeslaCam at the root of the drive labeled CAM.
1. Copy any music you'd like to the drive labeled MUSIC. 1. Copy any music you'd like to the drive labeled MUSIC.
@@ -169,9 +187,11 @@ The setup process configures the Pi with read-only file systems for the operatin
To make changes to the system partitions: To make changes to the system partitions:
``` ```
ssh pi@teslausb. ssh pi@teslaUSB.
sudo -i sudo -i
mount / -o remount,rw mount / -o remount,rw
mount /boot -o remount,rw mount /boot -o remount,rw
``` ```
A script has been provided as `/root/remountfs_rw` to run the mount commands for you more easily.
Then make whatever changes you need to. The next time the system boots the partitions will once again be read-only. Then make whatever changes you need to. The next time the system boots the partitions will once again be read-only.

View File

@@ -0,0 +1,102 @@
#!/bin/bash
#|| @license
#|| | This program is free software; you can redistribute it and/or
#|| | modify it under the terms of the GNU Lesser General Public
#|| | License as published by the Free Software Foundation; version
#|| | 2.1 of the License.
#|| |
#|| | This program is distributed in the hope that it will be useful,
#|| | but WITHOUT ANY WARRANTY; without even the implied warranty of
#|| | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#|| | Lesser General Public License for more details.
#|| |
#|| | You should have received a copy of the GNU Lesser General Public
#|| | License along with this library; if not, write to the Free Software
#|| | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#|| #
# Script repurposed from https://github.com/BigNate1234/rpi-USBSSH
#
# This script will modify the cmdline.txt file on a freshly flashed Raspbian Stretch/Lite
# It readies it for SSH, USB OTG, USB networking, and Wifi
#
# Run it in a terminal in the "boot" directory of the flashed MicroSD card
# Ex:
# cd /Volumes/boot (or wherever the boot folder is mounted)
# chmod+x update-rpi-mac-linux.sh (if not executable already)
# ./update-rpi-mac-linux.sh
#
# Put the card in your Pi, and reboot!
# Creates the ssh file if needed, since Raspbian now disables
# ssh by default if the file isn't present
if [ ! -r "cmdline.txt" ]; then
echo 'STOP: Run this script in the "boot" directory where cmdline.txt is located.'
exit 1
fi
if [ ! -n "${SSID+x}" ] || [ ! -n "${WIFIPASS+x}" ]
then
echo 'STOP: You need to specify your wifi name and password first. Run: '
echo " "
echo ' export SSID=your_ssid'
echo ' export WIFIPASS=your_wifi_password'
echo " "
echo "Be sure to replace the values with your SSID (network name) and password."
exit 1
fi
if [ ! -f ssh ]; then
touch ssh
fi
# Append the dwc2 module if not set (USB OTG)
echo "Verifying dwc2 module is set in config.txt."
dt=$(cat config.txt | grep "dtoverlay=dwc2")
if [ "$dt" != "dtoverlay=dwc2" ]; then
echo "dtoverlay=dwc2" >> config.txt
fi
# Append the g_ether module if not set (USB networking)
echo "Verifying the g_ether module (USB networking) is set in cmdline.txt."
mod=$(cat cmdline.txt | grep -o "modules-load=dwc2,g_ether")
if [ "$mod" != "modules-load=dwc2,g_ether" ]; then
sed -i '' '$ s/$/ modules-load=dwc2,g_ether/' cmdline.txt
# Only appends to end of line, not newline
fi
# Remove the automatic filesystem expansion action
# This is specific to the teslausb project; normally the
# Raspbian image will automatically expand the filesystem to include the
# entire SD card.
echo "Removing the command to auto-expand the root filesystem."
mod=$(cat cmdline.txt | grep -o "init=/usr/lib/raspi-config/init_resize.sh")
if [ "$mod" = "init=/usr/lib/raspi-config/init_resize.sh" ]; then
sed -i'.bak' -e 's/ init=\/usr\/lib\/raspi-config\/init_resize.sh//g' cmdline.txt
fi
# Sets up wifi credentials so wifi will be
# auto configured on first boot
echo "Adding Wifi setup file (wpa_supplicant.conf)."
if [ -r "wpa_supplicant.conf" ]
then
rm wpa_supplicant.conf
fi
cat << EOF >> wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="$SSID"
psk="$WIFIPASS"
key_mgmt=WPA-PSK
}
EOF
echo ""
echo '-- Files updated and ready for Wifi and SSH over USB --'
echo ""

View File

@@ -81,7 +81,7 @@ function move_clips_to_archive () {
done done
log "Moved $move_count file(s)." log "Moved $move_count file(s)."
if [ -r "/root/.teslaCamPushoverCredentials" ] if [ -r "/root/.teslaCamPushoverCredentials" ] && [ $move_count > 0 ]
then then
log "Sending Pushover message for copied files." log "Sending Pushover message for copied files."
/root/bin/send-pushover $move_count /root/bin/send-pushover $move_count

View File

@@ -0,0 +1,9 @@
#!/bin/bash
echo "Remounting / as read/write"
mount / -o remount,rw
echo "Remounting /boot as read/write"
mount /boot -o remount,rw
echo "Done. Make any changes needed, and reboot the Pi when ready."
echo "Filesystems / and /boot will be mounted as read only after reboot."

View File

@@ -133,8 +133,15 @@ function configure_archive_scripts () {
chmod +x archive-teslacam-clips chmod +x archive-teslacam-clips
popd popd
echo "Configured the archive scripts." echo "Configured the archive scripts."
pushd /root
wget https://raw.githubusercontent.com/"$REPO"/teslausb/"$BRANCH"/windows_archive/remountfs_rw
chmod +x remountfs_rw
popd
echo "Downloaded script to remount filesystems read/write if needed (/root/remountfs_rw)."
} }
function configure_pushover_scripts() { function configure_pushover_scripts() {
if [ ${user_enabled_pushover} = "true" ] if [ ${user_enabled_pushover} = "true" ]
then then