mirror of
https://github.com/cimryan/teslausb.git
synced 2026-03-01 04:30:33 +00:00
Make calculations of backng file size in terms of free 1k blocks
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
#!/bin/bash -eu
|
#!/bin/bash -eu
|
||||||
|
|
||||||
SPACE_TO_USE="$1"
|
CAM_PERCENT="$1"
|
||||||
CAM_PERCENT="$2"
|
BACKINGFILES_MOUNTPOINT="$2"
|
||||||
BACKINGFILES_MOUNTPOINT="$3"
|
|
||||||
|
|
||||||
G_MASS_STORAGE_CONF_FILE_NAME=/etc/modprobe.d/g_mass_storage.conf
|
G_MASS_STORAGE_CONF_FILE_NAME=/etc/modprobe.d/g_mass_storage.conf
|
||||||
|
|
||||||
@@ -12,7 +11,7 @@ function add_drive () {
|
|||||||
local size="$3"
|
local size="$3"
|
||||||
|
|
||||||
local filename="$4"
|
local filename="$4"
|
||||||
fallocate -l "$size" "$filename"
|
fallocate -l "$size"K "$filename"
|
||||||
mkfs.vfat "$filename" -F 32 -n "$label"
|
mkfs.vfat "$filename" -F 32 -n "$label"
|
||||||
|
|
||||||
local mountpoint=/mnt/"$name"
|
local mountpoint=/mnt/"$name"
|
||||||
@@ -21,14 +20,15 @@ function add_drive () {
|
|||||||
echo "$filename $mountpoint vfat noauto,users,umask=000 0 0" >> /etc/fstab
|
echo "$filename $mountpoint vfat noauto,users,umask=000 0 0" >> /etc/fstab
|
||||||
}
|
}
|
||||||
|
|
||||||
CAM_DISK_SIZE="$(( $SPACE_TO_USE * $CAM_PERCENT / 100 ))"
|
FREE_1K_BLOCKS="$(df --output=avail --block-size=1K /backingfiles/ | tail -n 1)"
|
||||||
|
|
||||||
|
CAM_DISK_SIZE="$(( $FREE_1K_BLOCKS * $CAM_PERCENT / 100 ))"
|
||||||
CAM_DISK_FILE_NAME="$BACKINGFILES_MOUNTPOINT/cam_disk.bin"
|
CAM_DISK_FILE_NAME="$BACKINGFILES_MOUNTPOINT/cam_disk.bin"
|
||||||
add_drive "cam" "CAM" "$CAM_DISK_SIZE" "$CAM_DISK_FILE_NAME"
|
add_drive "cam" "CAM" "$CAM_DISK_SIZE" "$CAM_DISK_FILE_NAME"
|
||||||
|
|
||||||
if [ "$CAM_PERCENT" -lt 100 ]
|
if [ "$CAM_PERCENT" -lt 100 ]
|
||||||
then
|
then
|
||||||
MUSIC_PERCENT="$(( 100 - $CAM_PERCENT ))"
|
MUSIC_DISK_SIZE="$(df --output=avail --block-size=1K /backingfiles/ | tail -n 1)"
|
||||||
MUSIC_DISK_SIZE="$(( $SPACE_TO_USE * $MUSIC_PERCENT / 100 ))"
|
|
||||||
MUSIC_DISK_FILE_NAME="$BACKINGFILES_MOUNTPOINT/music_disk.bin"
|
MUSIC_DISK_FILE_NAME="$BACKINGFILES_MOUNTPOINT/music_disk.bin"
|
||||||
add_drive "music" "MUSIC" "$MUSIC_DISK_SIZE" "$MUSIC_DISK_FILE_NAME"
|
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" > G_MASS_STORAGE_CONF_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" > G_MASS_STORAGE_CONF_FILE_NAME
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ function check_archive_server_reachable () {
|
|||||||
|
|
||||||
function check_available_space () {
|
function check_available_space () {
|
||||||
echo "Verifying that there is sufficient space available on the MicroSD card..."
|
echo "Verifying that there is sufficient space available on the MicroSD card..."
|
||||||
local available_space="$1"
|
|
||||||
|
local available_space="$( parted -m /dev/mmcblk0 u b print free | tail -1 | cut -d ":" -f 4 | sed 's/B//g' )"
|
||||||
|
|
||||||
if [ "$available_space" -lt 4294967296 ]
|
if [ "$available_space" -lt 4294967296 ]
|
||||||
then
|
then
|
||||||
echo "STOP: The MicroSD card is too small."
|
echo "STOP: The MicroSD card is too small."
|
||||||
@@ -66,7 +68,7 @@ function create_usb_drive_backing_files () {
|
|||||||
|
|
||||||
wget https://raw.githubusercontent.com/cimryan/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh
|
wget https://raw.githubusercontent.com/cimryan/teslausb/"$BRANCH"/windows_archive/create-backingfiles.sh
|
||||||
chmod +x ./create-backingfiles.sh
|
chmod +x ./create-backingfiles.sh
|
||||||
./create-backingfiles.sh "$AVAILABLE_SPACE" "$campercent" "$BACKINGFILES_MOUNTPOINT"
|
./create-backingfiles.sh "$campercent" "$BACKINGFILES_MOUNTPOINT"
|
||||||
}
|
}
|
||||||
|
|
||||||
function configure_archive () {
|
function configure_archive () {
|
||||||
@@ -141,8 +143,7 @@ check_variable "campercent"
|
|||||||
|
|
||||||
check_archive_server_reachable
|
check_archive_server_reachable
|
||||||
|
|
||||||
AVAILABLE_SPACE="$( parted -m /dev/mmcblk0 u b print free | tail -1 | cut -d ":" -f 4 | sed 's/B//g' )"
|
check_available_space
|
||||||
check_available_space "$AVAILABLE_SPACE"
|
|
||||||
|
|
||||||
|
|
||||||
pushd ~
|
pushd ~
|
||||||
|
|||||||
Reference in New Issue
Block a user