#!/bin/bash
echo "Use at your own risk. There is no guarantee that this will work correctly."
read -p "Continue? y/n " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit 1
fi
echo "Updating packages..."
opkg update
echo "Installing necessary packages..."
opkg install block-mount kmod-usd-storage kmod-fs-ext4 e2fsprogs
echo "Checking for USB/SD card..."
DEVICE=$(ls /dev/sd* || ls /dev/mmcblk0*)
echo "Found device: $DEVICE"
echo "Formatting the USB/SD card..."
mkfs.ext4 $DEVICE << EOF
Y
EOF
echo "Mounting the USB/SD card..."
mount -t ext4 $DEVICE /mnt
echo "Creating a temporary root directory..."
mkdir /tmp/root
echo "Binding mount the root filesystem..."
mount -o bind / /tmp/root
echo "Copying the root filesystem to the USB/SD card..."
cp /tmp/root/* /mnt -a
echo "Unmounting the temporary root directory and the USB/SD card..."
umount /tmp/root
umount /mnt
echo "Setting up auto-mount..."
block detect > /etc/config/fstab
uci set fstab.@mount[0].target='/overlay'
uci set fstab.@mount[0].enabled='1'
uci commit fstab
echo "Rebooting the router..."
reboot
This script will automate this official instructions:
No error handling at all, which could lead to major issues - especially when formatting something.
I would add a big warning at the beginning of the script