mirror of
https://github.com/cimryan/teslausb.git
synced 2026-03-01 04:30:33 +00:00
Merge branch 'master' into u/cimryan/verify_archive_mountable
This commit is contained in:
@@ -20,7 +20,7 @@ If you prefer not to run the script, it's also a useful reference for the steps
|
|||||||
1. Run the following commands:
|
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/mac_linux_archive/setup-piForHeadlessConfig.sh
|
||||||
chmod +x update-rpi-mac-linux.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:
|
1. Set your SSID (Wifi network name) and WIFIPASS environment variables. The script will insert them into the `wpa_supplicant.conf` when creating it:
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ If you prefer not to run the script, it's also a useful reference for the steps
|
|||||||
export WIFIPASS=your_wifi_password_here
|
export WIFIPASS=your_wifi_password_here
|
||||||
```
|
```
|
||||||
1. Run the script:
|
1. Run the script:
|
||||||
`./update-rpi-mac-linux.sh`
|
`./setup-piForHeadlessConfig.sh`
|
||||||
1. If all goes well, the script will report:
|
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`.
|
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`.
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#!/bin/bash -eu
|
#!/bin/bash -eu
|
||||||
|
|
||||||
LOG_FILE=/tmp/archive-teslacam-clips.log
|
LOG_FILE=/tmp/archive-teslacam-clips.log
|
||||||
CAM_MOUNT=/mnt/cam
|
|
||||||
ARCHIVE_MOUNT=/mnt/archive
|
ARCHIVE_MOUNT=/mnt/archive
|
||||||
|
|
||||||
function log () {
|
function log () {
|
||||||
@@ -9,66 +8,6 @@ function log () {
|
|||||||
echo "$1" >> "$LOG_FILE"
|
echo "$1" >> "$LOG_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
function retry () {
|
|
||||||
local attempts=0
|
|
||||||
while [ true ]
|
|
||||||
do
|
|
||||||
if eval "$@"
|
|
||||||
then
|
|
||||||
true
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
if [ "$attempts" -ge 10 ]
|
|
||||||
then
|
|
||||||
log "Attempts exhausted."
|
|
||||||
false
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
log "Sleeping before retry..."
|
|
||||||
/bin/sleep 1
|
|
||||||
attempts=$((attempts + 1))
|
|
||||||
log "Retrying..."
|
|
||||||
done
|
|
||||||
false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
function mount_mountpoint () {
|
|
||||||
local mount_point="$1"
|
|
||||||
log "Mounting $mount_point..."
|
|
||||||
|
|
||||||
local mounted=true
|
|
||||||
mount "$mount_point" >> "$LOG_FILE" 2>&1 || mounted=false
|
|
||||||
if [ "$mounted" = true ]
|
|
||||||
then
|
|
||||||
log "Mounted $mount_point."
|
|
||||||
true
|
|
||||||
return
|
|
||||||
else
|
|
||||||
log "Failed to mount $mount_point."
|
|
||||||
false
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function ensure_mountpoint_is_mounted () {
|
|
||||||
local mount_point="$1"
|
|
||||||
local mount_exists=true
|
|
||||||
|
|
||||||
findmnt --mountpoint "$mount_point" > /dev/null || mount_exists=false
|
|
||||||
|
|
||||||
if [ "$mount_exists" = true ]
|
|
||||||
then
|
|
||||||
log "$mount_point is already mounted."
|
|
||||||
else
|
|
||||||
mount_mountpoint "$mount_point"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function ensure_mountpoint_is_mounted_with_retry () {
|
|
||||||
retry ensure_mountpoint_is_mounted "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
function move_clips_to_archive () {
|
function move_clips_to_archive () {
|
||||||
log "Moving clips to archive..."
|
log "Moving clips to archive..."
|
||||||
local move_count=0
|
local move_count=0
|
||||||
@@ -95,42 +34,24 @@ function disconnect_usb_drives_from_host () {
|
|||||||
log "Disconnected usb from host."
|
log "Disconnected usb from host."
|
||||||
}
|
}
|
||||||
|
|
||||||
function fix_errors_on_cam_drive () {
|
|
||||||
log "Running fsck..."
|
|
||||||
/sbin/fsck "$CAM_MOUNT" -- -a >> "$LOG_FILE" 2>&1 || echo ""
|
|
||||||
log "Finished running fsck."
|
|
||||||
}
|
|
||||||
|
|
||||||
function ensure_archive_is_mounted () {
|
function ensure_archive_is_mounted () {
|
||||||
log "Ensuring cam archive is mounted..."
|
log "Ensuring cam archive is mounted..."
|
||||||
ensure_mountpoint_is_mounted_with_retry "$ARCHIVE_MOUNT"
|
ensure_mountpoint_is_mounted_with_retry "$ARCHIVE_MOUNT"
|
||||||
log "Ensured cam archive is mounted."
|
log "Ensured cam archive is mounted."
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensure_cam_drive_is_mounted () {
|
|
||||||
log "Ensuring cam drive is mounted..."
|
|
||||||
ensure_mountpoint_is_mounted_with_retry "$CAM_MOUNT"
|
|
||||||
log "Ensured cam drive is mounted."
|
|
||||||
}
|
|
||||||
|
|
||||||
function unmount_cam_drive () {
|
|
||||||
log "Unmounting cam drive..."
|
|
||||||
umount "$CAM_MOUNT"
|
|
||||||
log "Unmounted cam drive."
|
|
||||||
}
|
|
||||||
|
|
||||||
log "Starting..."
|
log "Starting..."
|
||||||
|
|
||||||
ensure_archive_is_mounted
|
ensure_archive_is_mounted
|
||||||
|
|
||||||
disconnect_usb_drives_from_host
|
disconnect_usb_drives_from_host
|
||||||
|
|
||||||
fix_errors_on_cam_drive
|
ensure_cam_file_is_mounted
|
||||||
|
|
||||||
ensure_cam_drive_is_mounted
|
fix_errors_in_cam_file
|
||||||
|
|
||||||
move_clips_to_archive
|
move_clips_to_archive
|
||||||
|
|
||||||
unmount_cam_drive
|
unmount_cam_file
|
||||||
|
|
||||||
connect_usb_drives_to_host
|
connect_usb_drives_to_host
|
||||||
@@ -2,11 +2,27 @@
|
|||||||
|
|
||||||
# Change the value on the right side of the equal sign to the name of the server hosting the archive.
|
# Change the value on the right side of the equal sign to the name of the server hosting the archive.
|
||||||
ARCHIVE_HOST_NAME=archiveserver
|
ARCHIVE_HOST_NAME=archiveserver
|
||||||
LOGFILE=/tmp/archiveloop.log
|
|
||||||
|
LOG_FILE=/tmp/archiveloop.log
|
||||||
|
|
||||||
|
export CAM_MOUNT=/mnt/cam
|
||||||
|
export MUSIC_MOUNT=/mnt/music
|
||||||
|
|
||||||
function log () {
|
function log () {
|
||||||
echo "$( date )" >> "$LOGFILE"
|
echo "$( date )" >> "$LOG_FILE"
|
||||||
echo "$1" >> "$LOGFILE"
|
echo "$1" >> "$LOG_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
function fix_errors_in_mount_point () {
|
||||||
|
local mount_point="$1"
|
||||||
|
log "Running fsck on $mount_point..."
|
||||||
|
/sbin/fsck "$mount_point" -- -a >> "$LOG_FILE" 2>&1 || echo ""
|
||||||
|
log "Finished fsck on $mount_point."
|
||||||
|
}
|
||||||
|
|
||||||
|
function fix_errors_in_mounted_files () {
|
||||||
|
fix_errors_in_mount_point "$CAM_MOUNT"
|
||||||
|
fix_errors_in_mount_point "$MUSIC_MOUNT"
|
||||||
}
|
}
|
||||||
|
|
||||||
function archive_is_reachable () {
|
function archive_is_reachable () {
|
||||||
@@ -35,10 +51,111 @@ function wait_for_archive_to_be_reachable () {
|
|||||||
log "Archive is reachable."
|
log "Archive is reachable."
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
if [ -e /tmp/archive_is_reachable ]
|
||||||
|
then
|
||||||
|
log "Simulating archive is reachable"
|
||||||
|
rm /tmp/archive_is_reachable
|
||||||
|
break
|
||||||
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function retry () {
|
||||||
|
local attempts=0
|
||||||
|
while [ true ]
|
||||||
|
do
|
||||||
|
if eval "$@"
|
||||||
|
then
|
||||||
|
true
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
if [ "$attempts" -ge 10 ]
|
||||||
|
then
|
||||||
|
log "Attempts exhausted."
|
||||||
|
false
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
log "Sleeping before retry..."
|
||||||
|
/bin/sleep 1
|
||||||
|
attempts=$((attempts + 1))
|
||||||
|
log "Retrying..."
|
||||||
|
done
|
||||||
|
false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
function mount_mountpoint () {
|
||||||
|
local mount_point="$1"
|
||||||
|
log "Mounting $mount_point..."
|
||||||
|
|
||||||
|
local mounted=true
|
||||||
|
mount "$mount_point" >> "$LOG_FILE" 2>&1 || mounted=false
|
||||||
|
if [ "$mounted" = true ]
|
||||||
|
then
|
||||||
|
log "Mounted $mount_point."
|
||||||
|
true
|
||||||
|
return
|
||||||
|
else
|
||||||
|
log "Failed to mount $mount_point."
|
||||||
|
false
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensure_mountpoint_is_mounted () {
|
||||||
|
local mount_point="$1"
|
||||||
|
local mount_exists=true
|
||||||
|
|
||||||
|
findmnt --mountpoint "$mount_point" > /dev/null || mount_exists=false
|
||||||
|
|
||||||
|
if [ "$mount_exists" = true ]
|
||||||
|
then
|
||||||
|
log "$mount_point is already mounted."
|
||||||
|
else
|
||||||
|
mount_mountpoint "$mount_point"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensure_mountpoint_is_mounted_with_retry () {
|
||||||
|
retry ensure_mountpoint_is_mounted "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
function fix_errors_in_cam_file () {
|
||||||
|
fix_errors_in_mount_point "$CAM_MOUNT"
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensure_cam_file_is_mounted () {
|
||||||
|
log "Ensuring cam file is mounted..."
|
||||||
|
ensure_mountpoint_is_mounted_with_retry "$CAM_MOUNT"
|
||||||
|
log "Ensured cam file is mounted."
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensure_music_file_is_mounted () {
|
||||||
|
log "Ensuring music backing file is mounted..."
|
||||||
|
ensure_mountpoint_is_mounted_with_retry "$MUSIC_MOUNT"
|
||||||
|
log "Ensured cam drive is mounted."
|
||||||
|
}
|
||||||
|
|
||||||
|
function unmount_mount_point () {
|
||||||
|
local mount_point="$1"
|
||||||
|
log "Unmounting $mount_point..."
|
||||||
|
umount "$mount_point" >> "$LOG_FILE" 2>&1
|
||||||
|
log "Unmounted $mount_point."
|
||||||
|
}
|
||||||
|
|
||||||
|
function unmount_cam_file () {
|
||||||
|
unmount_mount_point "$CAM_MOUNT"
|
||||||
|
}
|
||||||
|
|
||||||
|
function unmount_music_file () {
|
||||||
|
unmount_mount_point "$MUSIC_MOUNT"
|
||||||
|
}
|
||||||
|
|
||||||
|
function fix_errors_in_music_file () {
|
||||||
|
fix_errors_in_mount_point "$MUSIC_MOUNT"
|
||||||
|
}
|
||||||
|
|
||||||
function archive_clips () {
|
function archive_clips () {
|
||||||
log "Archiving..."
|
log "Archiving..."
|
||||||
/root/bin/archive-teslacam-clips
|
/root/bin/archive-teslacam-clips
|
||||||
@@ -54,20 +171,58 @@ function wait_for_archive_to_be_unreachable () {
|
|||||||
log "Archive is unreachable."
|
log "Archive is unreachable."
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
if [ -e /tmp/archive_is_unreachable ]
|
||||||
|
then
|
||||||
|
log "Simulating archive being unreachable."
|
||||||
|
rm /tmp/archive_is_unreachable
|
||||||
|
break
|
||||||
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mount_and_fix_errors_in_cam_file () {
|
||||||
|
ensure_cam_file_is_mounted
|
||||||
|
fix_errors_in_cam_file
|
||||||
|
unmount_cam_file
|
||||||
|
}
|
||||||
|
|
||||||
|
function mount_and_fix_errors_in_music_file () {
|
||||||
|
ensure_music_file_is_mounted
|
||||||
|
fix_errors_in_music_file
|
||||||
|
unmount_music_file
|
||||||
|
}
|
||||||
|
|
||||||
|
function mount_and_fix_errors_in_files () {
|
||||||
|
mount_and_fix_errors_in_cam_file
|
||||||
|
mount_and_fix_errors_in_music_file
|
||||||
|
}
|
||||||
|
|
||||||
|
export -f fix_errors_in_mount_point
|
||||||
|
export -f fix_errors_in_cam_file
|
||||||
|
export -f retry
|
||||||
|
export -f mount_mountpoint
|
||||||
|
export -f ensure_mountpoint_is_mounted
|
||||||
|
export -f ensure_mountpoint_is_mounted_with_retry
|
||||||
|
export -f ensure_cam_file_is_mounted
|
||||||
|
export -f fix_errors_in_cam_file
|
||||||
|
export -f unmount_mount_point
|
||||||
|
export -f unmount_cam_file
|
||||||
export -f connect_usb_drives_to_host
|
export -f connect_usb_drives_to_host
|
||||||
|
|
||||||
log "Starting..."
|
log "Starting..."
|
||||||
|
|
||||||
if archive_is_reachable
|
if archive_is_reachable
|
||||||
then
|
then
|
||||||
|
# archive_clips will fix errors in the cam file
|
||||||
|
mount_and_fix_errors_in_music_file
|
||||||
|
|
||||||
archive_clips
|
archive_clips
|
||||||
|
|
||||||
wait_for_archive_to_be_unreachable
|
wait_for_archive_to_be_unreachable
|
||||||
else
|
else
|
||||||
|
mount_and_fix_errors_in_files
|
||||||
|
|
||||||
connect_usb_drives_to_host
|
connect_usb_drives_to_host
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -44,14 +44,18 @@ if ([System.IO.File]::Exists("$wpaSupplicantConfPath")) {
|
|||||||
del "$wpaSupplicantConfPath"
|
del "$wpaSupplicantConfPath"
|
||||||
}
|
}
|
||||||
|
|
||||||
"ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev`
|
$wpaSupplicantConfContent=@"
|
||||||
update_config=1`
|
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
|
||||||
`
|
update_config=1
|
||||||
network={`
|
|
||||||
ssid=`"$wifiSSID`"`
|
network={
|
||||||
psk=`"$wifiPSK`"`
|
ssid="$wifiSSID"
|
||||||
key_mgmt=WPA-PSK`
|
psk="$wifiPSK"
|
||||||
}`
|
}
|
||||||
" | Out-File -FilePath "$wpaSupplicantConfPath" -Encoding utf8
|
"@
|
||||||
|
|
||||||
|
$utf8 = New-Object System.Text.UTF8Encoding $false
|
||||||
|
|
||||||
|
Set-Content -Value $utf8.GetBytes($wpaSupplicantConfContent) -Encoding Byte -Path "$wpaSupplicantConfPath"
|
||||||
|
|
||||||
Write-Verbose "All done."
|
Write-Verbose "All done."
|
||||||
Reference in New Issue
Block a user