mirror of
https://github.com/cimryan/teslausb.git
synced 2026-03-01 04:30:33 +00:00
Move create-backingfiles-partition.sh, create-backingfiles.sh, make-root-fs-readonly.sh to top level.
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
#!/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)
|
||||
|
||||
FIRST_BACKINGFILES_PARTITION_SECTOR=$(( $LAST_ROOT_PARTITION_SECTOR + 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%
|
||||
|
||||
NEW_DISK_IDENTIFIER=$( fdisk -l /dev/mmcblk0 | grep -e "^Disk identifier" | sed "s/Disk identifier: 0x//" )
|
||||
|
||||
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
|
||||
|
||||
echo "/dev/mmcblk0p3 $BACKINGFILES_MOUNTPOINT ext4 auto,rw,noatime 0 2" >> /etc/fstab
|
||||
@@ -1,46 +0,0 @@
|
||||
#!/bin/bash -eu
|
||||
|
||||
CAM_PERCENT="$1"
|
||||
BACKINGFILES_MOUNTPOINT="$2"
|
||||
|
||||
G_MASS_STORAGE_CONF_FILE_NAME=/etc/modprobe.d/g_mass_storage.conf
|
||||
|
||||
function add_drive () {
|
||||
local name="$1"
|
||||
local label="$2"
|
||||
local size="$3"
|
||||
|
||||
local filename="$4"
|
||||
echo "Allocating ${size}K for $filename..."
|
||||
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
|
||||
}
|
||||
|
||||
function create_teslacam_directory () {
|
||||
mount /mnt/cam
|
||||
mkdir /mnt/cam/TeslaCam
|
||||
umount /mnt/cam
|
||||
}
|
||||
|
||||
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"
|
||||
add_drive "cam" "CAM" "$CAM_DISK_SIZE" "$CAM_DISK_FILE_NAME"
|
||||
|
||||
if [ "$CAM_PERCENT" -lt 100 ]
|
||||
then
|
||||
MUSIC_DISK_SIZE="$(df --output=avail --block-size=1K /backingfiles/ | 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"
|
||||
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
|
||||
|
||||
create_teslacam_directory
|
||||
@@ -1,49 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Adapted from https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/master/read-only-fs.sh
|
||||
|
||||
function append_cmdline_txt_param() {
|
||||
local toAppend="$1"
|
||||
sed -i "s/\'/ ${toAppend}/g" /boot/cmdline.txt >/dev/null
|
||||
}
|
||||
|
||||
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 -y --force-yes autoremove --purge
|
||||
# Replace log management with busybox (use logread if needed)
|
||||
echo "Installing ntp and busybox-syslogd..."
|
||||
apt-get -y --force-yes install ntp busybox-syslogd; dpkg --purge rsyslog
|
||||
echo "Configuring system..."
|
||||
|
||||
# Add fastboot, noswap and/or ro to end of /boot/cmdline.txt
|
||||
append_cmdline_txt_param fastboot
|
||||
append_cmdline_txt_param noswap
|
||||
append_cmdline_txt_param ro
|
||||
|
||||
# Move /var/spool to /tmp
|
||||
rm -rf /var/spool
|
||||
ln -s /tmp /var/spool
|
||||
|
||||
# Change spool permissions in var.conf (rondie/Margaret fix)
|
||||
sed -i "s/spool\s*0755/spool 1777/g" /usr/lib/tmpfiles.d/var.conf >/dev/null
|
||||
|
||||
# Move dhcpd.resolv.conf to tmpfs
|
||||
touch /tmp/dhcpcd.resolv.conf
|
||||
rm /etc/resolv.conf
|
||||
ln -s /tmp/dhcpcd.resolv.conf /etc/resolv.conf
|
||||
|
||||
# Update /etc/fstab
|
||||
# make /boot read-only
|
||||
# make / read-only
|
||||
# tmpfs /var/log tmpfs nodev,nosuid 0 0
|
||||
# tmpfs /var/tmp tmpfs nodev,nosuid 0 0
|
||||
# tmpfs /tmp tmpfs nodev,nosuid 0 0
|
||||
sed -i -r "s@(/boot\s+vfat\s+\S+)@\1,ro@" /etc/fstab
|
||||
sed -i -r "s@(/\s+ext4\s+\S+)@\1,ro@" /etc/fstab
|
||||
echo "" >> /etc/fstab
|
||||
echo "tmpfs /var/log tmpfs nodev,nosuid 0 0" >> /etc/fstab
|
||||
echo "tmpfs /var/tmp tmpfs nodev,nosuid 0 0" >> /etc/fstab
|
||||
echo "tmpfs /tmp tmpfs nodev,nosuid 0 0" >> /etc/fstab
|
||||
|
||||
Reference in New Issue
Block a user