|
|
@ -85,6 +85,25 @@ unmount_partition () { |
|
|
|
umount "${MOUNT_POINT}" |
|
|
|
} |
|
|
|
|
|
|
|
# Formats and sets up a new device |
|
|
|
setup_new_device () { |
|
|
|
block_device="${1}" |
|
|
|
partition_path="${2}" |
|
|
|
|
|
|
|
echo "Formatting device..." |
|
|
|
format_block_device $block_device |
|
|
|
|
|
|
|
echo "Mounting partition..." |
|
|
|
mount_partition "${partition_path}" |
|
|
|
|
|
|
|
echo "Copying Umbrel install to external storage..." |
|
|
|
mkdir -p "${EXTERNAL_UMBREL_ROOT}" |
|
|
|
cp --recursive \ |
|
|
|
--archive \ |
|
|
|
--no-target-directory \ |
|
|
|
"${UMBREL_ROOT}" "${EXTERNAL_UMBREL_ROOT}" |
|
|
|
} |
|
|
|
|
|
|
|
main () { |
|
|
|
echo "Running external storage mount script..." |
|
|
|
check_root |
|
|
@ -111,39 +130,34 @@ main () { |
|
|
|
block_device_model=$(get_block_device_model $block_device) |
|
|
|
echo "Found device \"${block_device_model}\"" |
|
|
|
|
|
|
|
echo "Checking if device contains an Umbrel install..." |
|
|
|
|
|
|
|
mount_partition "${partition_path}" |
|
|
|
|
|
|
|
echo "Checking if the device is ext4..." |
|
|
|
|
|
|
|
if is_partition_ext4 "${partition_path}" && [[ -f "${EXTERNAL_UMBREL_ROOT}"/.umbrel ]]; then |
|
|
|
echo "Yes, it does" |
|
|
|
else |
|
|
|
echo "No, it doesn't" |
|
|
|
|
|
|
|
echo "Unmounting partition..." |
|
|
|
unmount_partition |
|
|
|
|
|
|
|
echo "Formatting device..." |
|
|
|
format_block_device $block_device |
|
|
|
|
|
|
|
echo "Mounting partition..." |
|
|
|
if is_partition_ext4 "${partition_path}" ; then |
|
|
|
echo "Yes, it is ext4" |
|
|
|
mount_partition "${partition_path}" |
|
|
|
|
|
|
|
echo "Copying Umbrel install to external storage..." |
|
|
|
mkdir -p "${EXTERNAL_UMBREL_ROOT}" |
|
|
|
cp --recursive \ |
|
|
|
--archive \ |
|
|
|
--no-target-directory \ |
|
|
|
"${UMBREL_ROOT}" "${EXTERNAL_UMBREL_ROOT}" |
|
|
|
echo "Checking if device contains an Umbrel install..." |
|
|
|
|
|
|
|
echo "Creating /sd-root to bind-mount SD card root..." |
|
|
|
mkdir -p "/sd-root" |
|
|
|
if [[ -f "${EXTERNAL_UMBREL_ROOT}"/.umbrel ]]; then |
|
|
|
echo "Yes, it contains an Umbrel install" |
|
|
|
else |
|
|
|
echo "No, it doesn't contain an Umbrel install" |
|
|
|
echo "Unmounting partition..." |
|
|
|
unmount_partition |
|
|
|
setup_new_device $block_device $partition_path |
|
|
|
fi |
|
|
|
|
|
|
|
else |
|
|
|
echo "No, it's not ext4" |
|
|
|
setup_new_device $block_device $partition_path |
|
|
|
fi |
|
|
|
|
|
|
|
echo "Bind mounting external storage over local Umbrel installation..." |
|
|
|
mount --bind "${EXTERNAL_UMBREL_ROOT}" "${UMBREL_ROOT}" |
|
|
|
|
|
|
|
echo "Bind mounting SD card root at /sd-card" |
|
|
|
echo "Bind mounting SD card root at /sd-card..." |
|
|
|
[[ ! -d "/sd-root" ]] && mkdir -p "/sd-root" |
|
|
|
mount --bind "/" "/sd-root" |
|
|
|
|
|
|
|
echo "Checking Umbrel root is now on external storage..." |
|
|
|