From a03c322c01684bbb44a2c851248ffa0bd6134853 Mon Sep 17 00:00:00 2001 From: cimryan Date: Sat, 13 Oct 2018 18:18:00 -0700 Subject: [PATCH 1/4] Support for music in addition to dashcam clip storage. --- README.md | 5 +-- g_mass_storage.conf | 1 - windows_archive/archive-teslacam-clips | 2 +- windows_archive/setup-teslausb | 46 ++++++++++++++++++++------ 4 files changed, 39 insertions(+), 15 deletions(-) delete mode 100644 g_mass_storage.conf diff --git a/README.md b/README.md index c07c5af..1d749f5 100644 --- a/README.md +++ b/README.md @@ -126,16 +126,17 @@ Now that you have a shell on the Pi you can turn the Pi into a smart USB drive. 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. Run these commands, subsituting your values: +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 sharename=SailfishCam export shareuser=sailfish export sharepassword=pa$$w0rd + epxort campercent=100 ``` 1. Run these commands: ``` - wget https://raw.githubusercontent.com/cimryan/teslausb/master/windows_archive/setup-teslausb + wget https://raw.githubusercontent.com/cimryan/teslausb/u/cimryan/music/windows_archive/setup-teslausb chmod +x setup-teslausb ./setup-teslausb ``` diff --git a/g_mass_storage.conf b/g_mass_storage.conf deleted file mode 100644 index 6ed888e..0000000 --- a/g_mass_storage.conf +++ /dev/null @@ -1 +0,0 @@ -options g_mass_storage file=/piusb.bin removable=1 ro=0 stall=0 iSerialNumber=123456 diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index eadfb38..1df2f9c 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -124,4 +124,4 @@ move_clips_to_archive unmount_cam_drive -connect_usb_to_host \ No newline at end of file +connect_usb_drives_to_host \ No newline at end of file diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 648fa88..80ce1eb 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -19,6 +19,7 @@ check_variable "archiveserver" check_variable "sharename" check_variable "shareuser" check_variable "sharepassword" +check_variable "campercent" serverunreachable=false ping -c 1 -w 1 "$archiveserver" 1>/dev/null 2>&1 || serverunreachable=true @@ -31,26 +32,38 @@ fi archiveserverip="$(getent hosts $archiveserver | cut -d' ' -f1)" -size="$(($(df --output=avail / | tail -1) - 1000000))" -if [ "$size" -lt 0 ] +available_space="$(($(df --output=avail / | tail -1) - 1000000))" + +if [ "$available_space" -lt 0 ] then echo "STOP: The MicroSD card is too small." exit 1 fi +function add_drive () { + local name="$1" + local label="$2" + local size="$3" + + local filename="$4" + fallocate -l "$size"K "$filename" + mkfs.vfat "$filename" -F 32 -n "$label" + + local mountpoint=/mnt/"$name" + + mkdir "$mountpoint" + echo "$filename $mountpoint vfat noauto,users,umask=000 0 0" >> /etc/fstab +} + pushd ~ cp /boot/cmdline.txt ~ cat ~/cmdline.txt | sed 's/[[:space:]]\+modules-load=[^ [:space:]]\+//' | sed 's/rootwait/rootwait modules-load=dwc2/' > /boot/cmdline.txt rm ~/cmdline.txt -fallocate -l "$size"K /piusb.bin -mkfs.vfat /piusb.bin -F 32 -n CAM -mkdir /mnt/cam mkdir /mnt/archive echo "" >> /etc/fstab -echo "/piusb.bin /mnt/cam vfat noauto,users,umask=000,debug 0 0" >> /etc/fstab echo "//$archiveserverip/$sharename /mnt/archive cifs vers=3,credentials=/root/.teslaCamArchiveCredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0" >> /etc/fstab echo "username=$shareuser" > /root/.teslaCamArchiveCredentials @@ -58,13 +71,13 @@ echo "password=$sharepassword" >> /root/.teslaCamArchiveCredentials mkdir /root/bin -wget https://raw.githubusercontent.com/cimryan/teslausb/master/windows_archive/archiveloop +wget https://raw.githubusercontent.com/cimryan/teslausb/u/cimryan/music/windows_archive/archiveloop sed s/ARCHIVE_HOST_NAME=archiveserver/ARCHIVE_HOST_NAME=$archiveserver/ ~/archiveloop > /root/bin/archiveloop rm ~/archiveloop chmod +x /root/bin/archiveloop pushd /root/bin -wget https://raw.githubusercontent.com/cimryan/teslausb/master/windows_archive/archive-teslacam-clips +wget https://raw.githubusercontent.com/cimryan/teslausb/u/cimryan/music/windows_archive/archive-teslacam-clips chmod +x archive-teslacam-clips popd @@ -87,9 +100,20 @@ EOF cat ~/rc.local > /etc/rc.local rm ~/rc.local -pushd /etc/modprobe.d -wget https://raw.githubusercontent.com/cimryan/teslausb/master/g_mass_storage.conf -popd +cam_disk_size="$(( $available_space * $campercent / 100 ))" +cam_disk_file_name="/cam_disk.bin" +add_drive "cam" "CAM" "$cam_disk_size" "$cam_disk_file_name" + +if [ "$campercent" -lt 100 ] +then + musicpercent=$$(( 100 - $campercent )) + music_disk_size="$(( $available_space * $musicpercent / 100 ))" + music_disk_file_name="/music_disk.bin" + add_drive "music" "MUSIC" "$music_disk_size" "$music_disk_file_name" + echo "options g_mass_storage file=$cam_disk_file_name,$music_disk_file_name removable=1,1 ro=0,0 stall=0 iSerialNumber=123456" > /etc/modprobe.d/g_mass_storage.conf +else + echo "options g_mass_storage file=$cam_disk_file_name removable=1 ro=0 stall=0 iSerialNumber=123456" > /etc/modprobe.d/g_mass_storage.conf +fi cp /etc/hosts ~ sed s/raspberrypi/teslausb/g ~/hosts > /etc/hosts From d0a1212ca6219a4312cc8a82cbf8ef3e515192db Mon Sep 17 00:00:00 2001 From: cimryan Date: Sat, 13 Oct 2018 19:04:09 -0700 Subject: [PATCH 2/4] Fix syntax error in the calculation of musicpercent. --- windows_archive/setup-teslausb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/windows_archive/setup-teslausb b/windows_archive/setup-teslausb index 80ce1eb..bd7c93e 100644 --- a/windows_archive/setup-teslausb +++ b/windows_archive/setup-teslausb @@ -44,13 +44,13 @@ function add_drive () { local name="$1" local label="$2" local size="$3" - + local filename="$4" fallocate -l "$size"K "$filename" mkfs.vfat "$filename" -F 32 -n "$label" local mountpoint=/mnt/"$name" - + mkdir "$mountpoint" echo "$filename $mountpoint vfat noauto,users,umask=000 0 0" >> /etc/fstab } @@ -106,7 +106,7 @@ add_drive "cam" "CAM" "$cam_disk_size" "$cam_disk_file_name" if [ "$campercent" -lt 100 ] then - musicpercent=$$(( 100 - $campercent )) + musicpercent="$(( 100 - $campercent ))" music_disk_size="$(( $available_space * $musicpercent / 100 ))" music_disk_file_name="/music_disk.bin" add_drive "music" "MUSIC" "$music_disk_size" "$music_disk_file_name" @@ -119,4 +119,4 @@ cp /etc/hosts ~ sed s/raspberrypi/teslausb/g ~/hosts > /etc/hosts cp /etc/hostname ~ -sed s/raspberrypi/teslausb/g ~/hostname > /etc/hostname +sed s/raspberrypi/teslausb/g ~/hostname > /etc/hostname \ No newline at end of file From 10dfaa439ebd80512571c6841d23ed810a41cf17 Mon Sep 17 00:00:00 2001 From: cimryan Date: Sat, 13 Oct 2018 19:04:50 -0700 Subject: [PATCH 3/4] Fix typo for campercent and add note about case-sensitivity in SSID. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1d749f5..5707d25 100644 --- a/README.md +++ b/README.md @@ -94,15 +94,15 @@ If you don't have a keyboard/HDMI setup to boot the Pi and edit/transfer files d ### Get the scripts onto the Pi Now that you have a shell on the Pi you can turn the Pi into a smart USB drive. -1. Enter the following command. +1. Enter the following commands: ``` sudo -i nano /etc/wpa_supplicant/wpa_supplicant.conf ``` -1. Add this block to the bottom of the file specifying the actual SSID of your network and your actual PSK, keeping the quotes around both values. +1. Add this block to the bottom of the file specifying the actual SSID of your network and your actual PSK, keeping the quotes around both values. Note that the SSID may be case-sensitive on your network. ``` network={ - ssid="NETWORK" + ssid="SSID" psk="PASSWORD" } ``` @@ -132,7 +132,7 @@ Now that you have a shell on the Pi you can turn the Pi into a smart USB drive. export sharename=SailfishCam export shareuser=sailfish export sharepassword=pa$$w0rd - epxort campercent=100 + export campercent=100 ``` 1. Run these commands: ``` From d39d08a738a16911184735b38a82b1c3d47d98a2 Mon Sep 17 00:00:00 2001 From: cimryan Date: Sat, 13 Oct 2018 20:50:34 -0700 Subject: [PATCH 4/4] Mount the archive and move the files into it. --- windows_archive/archive-teslacam-clips | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/windows_archive/archive-teslacam-clips b/windows_archive/archive-teslacam-clips index 1df2f9c..063c7d0 100644 --- a/windows_archive/archive-teslacam-clips +++ b/windows_archive/archive-teslacam-clips @@ -74,7 +74,7 @@ function move_clips_to_archive () { for file_name in "$CAM_MOUNT"/TeslaCam/saved*; do [ -e "$file_name" ] || continue log "Moving $file_name ..." - mv -- "$file_name" "$CAM_MOUNT" >> "$LOG_FILE" 2>&1 || echo "" + mv -- "$file_name" "$ARCHIVE_MOUNT" >> "$LOG_FILE" 2>&1 || echo "" log "Moved $file_name." done log "Finished moving clips to archive." @@ -94,7 +94,7 @@ function fix_errors_on_cam_drive () { function ensure_archive_is_mounted () { log "Ensuring cam archive is mounted..." - ensure_mountpoint_is_mounted_with_retry "$CAM_MOUNT" + ensure_mountpoint_is_mounted_with_retry "$ARCHIVE_MOUNT" log "Ensured cam archive is mounted." }