diff --git a/pi-gen-sources/00-teslausb-tweaks/files/teslausb_setup_variables.conf.sample b/pi-gen-sources/00-teslausb-tweaks/files/teslausb_setup_variables.conf.sample index 768a2d96..a9c584ec 100644 --- a/pi-gen-sources/00-teslausb-tweaks/files/teslausb_setup_variables.conf.sample +++ b/pi-gen-sources/00-teslausb-tweaks/files/teslausb_setup_variables.conf.sample @@ -73,21 +73,12 @@ export SHARE_PASSWORD='password' # Notes on sd card and image sizes: # * A 128 GB or larger sd card (or USB drive, when using Pi4) is recommended. # The minimum supported size is 64 GB. -# * When specifying sizes for the recordings and music drives, you can use -# specific sizes (e.g. 24G) or use sizes relative to the available space -# (e.g. 10%). It is recommended to use specific sizes. -# * The setup script will reserve a fixed 6 GB of space regardless of sd card -# size. -# * CAM_SIZE should generally be somewhat small, around 16G to 32G, unless you +# * The setup script will keep a fixed 6 GB of space in reserve regardless of +# sd card size. +# * CAM_SIZE should generally be somewhat small, 30G is recommended, unless you # plan on accumulating a lot of footage between archive operations, in which # case you should increase the value (an hour of recordings, or 6 Sentry # events, is about 7-9 GB of data). -# * As of Tesla software version 2020.48.10, the car will warn when the -# recording drive is smaller than 32 GB, but smaller values will still work. -# Tesla appears to use power-of-ten based sizes, presumably because most -# storage manufacturers do too. -# Because teslausb uses power-of-two sizes, you can specify "30G" for the -# size and not get the warning. # * MUSIC_SIZE should be large enough to hold your music library, obviously. # * If no music size is specified, no music drive will be created. # * If no lightshow size is specified, no lightshow drive will be created. diff --git a/setup/pi/create-backingfiles.sh b/setup/pi/create-backingfiles.sh index 71a08203..54d5c5a1 100755 --- a/setup/pi/create-backingfiles.sh +++ b/setup/pi/create-backingfiles.sh @@ -55,7 +55,7 @@ available_space () { } function calc_size () { - local requestedsize="$1" + local requestedsize="${!1}" local availablesize availablesize="$(available_space)" if [ "$availablesize" -lt 0 ] @@ -65,11 +65,27 @@ function calc_size () { fi if is_percent "$requestedsize" then - local percent=${requestedsize//%/} - requestedsize="$(( availablesize * percent / 100 ))" - else - requestedsize="$(( $(dehumanize $requestedsize) / 1024 ))" + case ${1} in + CAM_SIZE) + requestedsize=30G + ;; + MUSIC_SIZE) + requestedsize=4G + ;; + BOOMBOX_SIZE) + requestedsize=100M + ;; + LIGHTSHOW_SIZE) + requestedsize=1G + ;; + *) + log_progress "Percentage-based size no longer supported, use fixed size instead." > /dev/stderr + exit 1 + ;; + esac + log_progress "Percentage-based size no longer supported, using default size of $requestedsize for $1" > /dev/stderr fi + requestedsize="$(( $(dehumanize $requestedsize) / 1024 ))" if [ "$requestedsize" -gt "$availablesize" ] then requestedsize="$availablesize" @@ -136,7 +152,7 @@ LIGHTSHOW_DISK_FILE_NAME="$BACKINGFILES_MOUNTPOINT/lightshow_disk.bin" BOOMBOX_DISK_FILE_NAME="$BACKINGFILES_MOUNTPOINT/boombox_disk.bin" # delete existing files, because fallocate doesn't shrink files, and -# because they interfere with the percentage-of-free-space calculation +# because they interfere with the free-space calculation if [ -e "$CAM_DISK_FILE_NAME" ] || [ -e "$MUSIC_DISK_FILE_NAME" ] || [ -e "$LIGHTSHOW_DISK_FILE_NAME" ] || [ -e "$BOOMBOX_DISK_FILE_NAME" ] || [ -e "$BACKINGFILES_MOUNTPOINT/snapshots" ] then if [ -t 0 ] @@ -196,20 +212,24 @@ then apt-get -y --force-yes install dosfstools fi -CAM_DISK_SIZE="$(calc_size "$CAM_SIZE")" -MUSIC_DISK_SIZE="$(calc_size "$MUSIC_SIZE")" -LIGHTSHOW_DISK_SIZE="$(calc_size "$LIGHTSHOW_SIZE")" -BOOMBOX_DISK_SIZE="$(calc_size "$BOOMBOX_SIZE")" +CAM_DISK_SIZE="$(calc_size CAM_SIZE)" +MUSIC_DISK_SIZE="$(calc_size MUSIC_SIZE)" +LIGHTSHOW_DISK_SIZE="$(calc_size LIGHTSHOW_SIZE)" +BOOMBOX_DISK_SIZE="$(calc_size BOOMBOX_SIZE)" + +if [ "$((CAM_DISK_SIZE+MUSIC_DISK_SIZE+LIGHTSHOW_DISK_SIZE+BOOMBOX_DISK_SIZE))" -gt "$(available_space)" ] +then + echo "Total requested size exceeds available space" + # TODO: reduce sizes to fit + exit 1 +fi add_drive "cam" "CAM" "$CAM_DISK_SIZE" "$CAM_DISK_FILE_NAME" "$USE_EXFAT" log_progress "created camera backing file" REMAINING_SPACE="$(available_space)" -if [ "$CAM_SIZE" = "100%" ] -then - MUSIC_DISK_SIZE=0 -elif [ "$MUSIC_DISK_SIZE" -gt "$REMAINING_SPACE" ] +if [ "$MUSIC_DISK_SIZE" -gt "$REMAINING_SPACE" ] then MUSIC_DISK_SIZE="$REMAINING_SPACE" fi