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