mirror of
https://github.com/cimryan/teslausb.git
synced 2026-02-28 20:20:32 +00:00
Merge branch 'u/rtgoodwin/headless-patch' into headless-patch
This commit is contained in:
@@ -1,16 +1,27 @@
|
||||
#!/bin/bash -eu
|
||||
|
||||
BACKINGFILES_MOUNTPOINT="$1"
|
||||
|
||||
PARTITION_TABLE=$(parted -m /dev/mmcblk0 unit s print)
|
||||
ROOT_PARTITION_LINE=$(echo "$PARTITION_TABLE" | grep -e "^2:")
|
||||
LAST_ROOT_PARTITION_SECTOR=$(echo "$ROOT_PARTITION_LINE" | sed 's/s//g' | cut -d ":" -f 3)
|
||||
MUTABLE_MOUNTPOINT="$2"
|
||||
|
||||
FIRST_BACKINGFILES_PARTITION_SECTOR=$(( $LAST_ROOT_PARTITION_SECTOR + 1 ))
|
||||
PARTITION_TABLE=$(parted -m /dev/mmcblk0 unit B print)
|
||||
DISK_LINE=$(echo "$PARTITION_TABLE" | grep -e "^/dev/mmcblk0:")
|
||||
DISK_SIZE=$(echo "$DISK_LINE" | cut -d ":" -f 2 | sed 's/B//' )
|
||||
|
||||
ROOT_PARTITION_LINE=$(echo "$PARTITION_TABLE" | grep -e "^2:")
|
||||
LAST_ROOT_PARTITION_BYTE=$(echo "$ROOT_PARTITION_LINE" | sed 's/B//g' | cut -d ":" -f 3)
|
||||
|
||||
FIRST_BACKINGFILES_PARTITION_BYTE="$(( $LAST_ROOT_PARTITION_BYTE + 1 ))"
|
||||
LAST_BACKINGFILES_PARTITION_DESIRED_BYTE="$(( $DISK_SIZE - (100 * (2 ** 20)) - 1))"
|
||||
|
||||
ORIGINAL_DISK_IDENTIFIER=$( fdisk -l /dev/mmcblk0 | grep -e "^Disk identifier" | sed "s/Disk identifier: 0x//" )
|
||||
|
||||
parted -m /dev/mmcblk0 u s mkpart primary ext4 "$FIRST_BACKINGFILES_PARTITION_SECTOR" 100%
|
||||
BACKINGFILES_PARTITION_END_SPEC="$(( $LAST_BACKINGFILES_PARTITION_DESIRED_BYTE / 1000000 ))M"
|
||||
parted -a optimal -m /dev/mmcblk0 unit B mkpart primary ext4 "$FIRST_BACKINGFILES_PARTITION_BYTE" "$BACKINGFILES_PARTITION_END_SPEC"
|
||||
|
||||
LAST_BACKINGFILES_PARTITION_BYTE=$(parted -m /dev/mmcblk0 unit B print | grep -e "^3:" | cut -d ":" -f 3 | sed 's/B//g' )
|
||||
|
||||
MUTABLE_PARTITION_START_SPEC="$(( $LAST_BACKINGFILES_PARTITION_BYTE / 1000000 ))M"
|
||||
parted -a optimal -m /dev/mmcblk0 unit B mkpart primary ext4 "$MUTABLE_PARTITION_START_SPEC" 100%
|
||||
|
||||
NEW_DISK_IDENTIFIER=$( fdisk -l /dev/mmcblk0 | grep -e "^Disk identifier" | sed "s/Disk identifier: 0x//" )
|
||||
|
||||
@@ -18,5 +29,7 @@ sed -i "s/${ORIGINAL_DISK_IDENTIFIER}/${NEW_DISK_IDENTIFIER}/g" /etc/fstab
|
||||
sed -i "s/${ORIGINAL_DISK_IDENTIFIER}/${NEW_DISK_IDENTIFIER}/" /boot/cmdline.txt
|
||||
|
||||
mkfs.ext4 -F /dev/mmcblk0p3
|
||||
mkfs.ext4 -F /dev/mmcblk0p4
|
||||
|
||||
echo "/dev/mmcblk0p3 $BACKINGFILES_MOUNTPOINT ext4 auto,rw,noatime 0 2" >> /etc/fstab
|
||||
echo "/dev/mmcblk0p4 $MUTABLE_MOUNTPOINT ext4 auto,rw 0 2" >> /etc/fstab
|
||||
|
||||
@@ -38,7 +38,7 @@ then
|
||||
MUSIC_DISK_SIZE="$(df --output=avail --block-size=1K $BACKINGFILES_MOUNTPOINT/ | tail -n 1)"
|
||||
MUSIC_DISK_FILE_NAME="$BACKINGFILES_MOUNTPOINT/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" > "$G_MASS_STORAGE_CONF_FILE_NAME"
|
||||
echo "options g_mass_storage file=$MUSIC_DISK_FILE_NAME,$CAM_DISK_FILE_NAME removable=1,1 ro=0,0 stall=0 iSerialNumber=123456" > "$G_MASS_STORAGE_CONF_FILE_NAME"
|
||||
else
|
||||
echo "options g_mass_storage file=$CAM_DISK_FILE_NAME removable=1 ro=0 stall=0 iSerialNumber=123456" > "$G_MASS_STORAGE_CONF_FILE_NAME"
|
||||
fi
|
||||
|
||||
@@ -10,7 +10,7 @@ function append_cmdline_txt_param() {
|
||||
echo "Updating package index files..."
|
||||
apt-get update
|
||||
echo "Removing unwanted packages..."
|
||||
apt-get remove -y --force-yes --purge triggerhappy logrotate dphys-swapfile fake-hwclock
|
||||
apt-get remove -y --force-yes --purge triggerhappy logrotate dphys-swapfile
|
||||
apt-get -y --force-yes autoremove --purge
|
||||
# Replace log management with busybox (use logread if needed)
|
||||
echo "Installing ntp and busybox-syslogd..."
|
||||
@@ -22,6 +22,37 @@ append_cmdline_txt_param fastboot
|
||||
append_cmdline_txt_param noswap
|
||||
append_cmdline_txt_param ro
|
||||
|
||||
# Move fake-hwclock.data to /mutable directory so it can be updated
|
||||
if ! findmnt --mountpoint /mutable
|
||||
then
|
||||
echo "Mounting the multable partition..."
|
||||
mount /mutable
|
||||
echo "Mounted."
|
||||
fi
|
||||
if [ ! -e "/mutable/etc" ]
|
||||
then
|
||||
mkdir -p /mutable/etc
|
||||
fi
|
||||
if [ -e "/etc/fake-hwclock.data" ]
|
||||
then
|
||||
echo "Moving fake-hwclock data"
|
||||
cp /etc/fake-hwclock.data /mutable/etc/fake-hwclock.data
|
||||
rm /etc/fake-hwclock.data
|
||||
ln -s /mutable/etc/fake-hwclock.data /etc/fake-hwclock.data
|
||||
fi
|
||||
|
||||
# Move rclone configs if it exists so we can write to it
|
||||
if [ ! -e "/mutable/configs" ]
|
||||
then
|
||||
mkdir -p /mutable/configs
|
||||
fi
|
||||
if [ -e "/root/.config/rclone/rclone.conf" ]
|
||||
then
|
||||
echo "Moving rclone configs"
|
||||
mv /root/.config/rclone /mutable/configs
|
||||
ln -s /mutable/configs/rclone /root/.config/rclone
|
||||
fi
|
||||
|
||||
# Move /var/spool to /tmp
|
||||
rm -rf /var/spool
|
||||
ln -s /tmp /var/spool
|
||||
|
||||
@@ -154,6 +154,7 @@ function fix_cmdline_txt_modules_load ()
|
||||
}
|
||||
|
||||
BACKINGFILES_MOUNTPOINT=/backingfiles
|
||||
MUTABLE_MOUNTPOINT=/mutable
|
||||
|
||||
function create_usb_drive_backing_files () {
|
||||
if [ ! -e "$BACKINGFILES_MOUNTPOINT" ]
|
||||
@@ -161,9 +162,14 @@ function create_usb_drive_backing_files () {
|
||||
mkdir "$BACKINGFILES_MOUNTPOINT"
|
||||
fi
|
||||
|
||||
if [ ! -e "$MUTABLE_MOUNTPOINT" ]
|
||||
then
|
||||
mkdir "$MUTABLE_MOUNTPOINT"
|
||||
fi
|
||||
|
||||
if [ ! -e /dev/mmcblk0p3 ]
|
||||
then
|
||||
/tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT"
|
||||
/tmp/create-backingfiles-partition.sh "$BACKINGFILES_MOUNTPOINT" "$MUTABLE_MOUNTPOINT"
|
||||
fi
|
||||
|
||||
if ! findmnt --mountpoint $BACKINGFILES_MOUNTPOINT
|
||||
@@ -190,6 +196,11 @@ function configure_archive_scripts () {
|
||||
get_script /root/bin archive-clips.sh run/rsync_archive
|
||||
get_script /root/bin connect-archive.sh run/rsync_archive
|
||||
get_script /root/bin disconnect-archive.sh run/rsync_archive
|
||||
elif [ $RCLONE_ENABLE = true ]
|
||||
then
|
||||
get_script /root/bin archive-clips.sh run/rclone_archive
|
||||
get_script /root/bin connect-archive.sh run/rclone_archive
|
||||
get_script /root/bin disconnect-archive.sh run/rclone_archive
|
||||
else
|
||||
get_script /root/bin archive-clips.sh run/cifs_archive
|
||||
get_script /root/bin connect-archive.sh run/cifs_archive
|
||||
@@ -264,6 +275,7 @@ headless_setup_progress_flash 1
|
||||
setup_progress "Verifying environment variables..."
|
||||
|
||||
RSYNC_ENABLE="${RSYNC_ENABLE:-false}"
|
||||
RCLONE_ENABLE="${RCLONE_ENABLE:-false}"
|
||||
|
||||
if [ "$RSYNC_ENABLE" = true ]
|
||||
then
|
||||
@@ -271,6 +283,12 @@ then
|
||||
check_variable "RSYNC_SERVER"
|
||||
export archiveserver="$RSYNC_SERVER"
|
||||
check_variable "RSYNC_PATH"
|
||||
elif [ "$RCLONE_ENABLE" = true ]
|
||||
then
|
||||
check_variable "RCLONE_DRIVE"
|
||||
check_variable "RCLONE_PATH"
|
||||
# since it's a cloud hosted drive we'll just set this to google dns
|
||||
export archiveserver="8.8.8.8"
|
||||
else # Else for now, TODO allow both for more redundancy?
|
||||
check_variable "sharename"
|
||||
check_variable "shareuser"
|
||||
@@ -298,6 +316,10 @@ if [ "$RSYNC_ENABLE" = true ]
|
||||
then
|
||||
get_script /root/bin verify-archive-configuration.sh run/rsync_archive
|
||||
get_script /root/bin configure-archive.sh run/rsync_archive
|
||||
elif [ "$RCLONE_ENABLE" = true ]
|
||||
then
|
||||
get_script /root/bin verify-archive-configuration.sh run/rclone_archive
|
||||
get_script /root/bin configure-archive.sh run/rclone_archive
|
||||
else
|
||||
get_script /root/bin verify-archive-configuration.sh run/cifs_archive
|
||||
get_script /root/bin configure-archive.sh run/cifs_archive
|
||||
|
||||
Reference in New Issue
Block a user