Merge pull request #10 from cimryan/u/cimryan/music

Support music files in addition to dashcam functionality
This commit is contained in:
cimryan
2018-10-13 20:52:18 -07:00
committed by GitHub
4 changed files with 45 additions and 21 deletions

View File

@@ -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"
}
```
@@ -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
export 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
```

View File

@@ -1 +0,0 @@
options g_mass_storage file=/piusb.bin removable=1 ro=0 stall=0 iSerialNumber=123456

View File

@@ -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."
}
@@ -124,4 +124,4 @@ move_clips_to_archive
unmount_cam_drive
connect_usb_to_host
connect_usb_drives_to_host

View File

@@ -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,12 +100,23 @@ 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
cp /etc/hostname ~
sed s/raspberrypi/teslausb/g ~/hostname > /etc/hostname
sed s/raspberrypi/teslausb/g ~/hostname > /etc/hostname