From f07030eb1d95e4ddc34370fed3c9996e91d4b7dc Mon Sep 17 00:00:00 2001 From: jrwimmer <67992074+jrwimmer@users.noreply.github.com> Date: Sun, 5 Dec 2021 08:13:09 -0800 Subject: [PATCH 1/9] Initial module commit --- modules/extroot | 27 +++++++++++++++++++++++++++ modules/module_list | 1 + 2 files changed, 28 insertions(+) create mode 100644 modules/extroot diff --git a/modules/extroot b/modules/extroot new file mode 100644 index 0000000..94dba58 --- /dev/null +++ b/modules/extroot @@ -0,0 +1,27 @@ +#!/bin/bash /usr/lib/turtle/turtle_module +# Title: LANTurtle OpenWRT Extroot configuration +# Description: Simplified SD card storage +# Author: jrwimmer +# Props: ImNatho, mike111b, madbuda +# Version: 1.0 +# Category: General +# Target: N/A +# Attackmodes: N/A + +VERSION="1.0" +DESCRIPTION="Simplified SD card storage" +CONF=/tmp/extroot.form + +# All "dialog" functionality is related to the Turtle shell +: ${DIALOG_OK=0} +: ${DIALOG_CANCEL=1} +: ${DIALOG_HELP=2} +: ${DIALOG_EXTRA=3} +: ${DIALOG_ITEM_HELP=4} +: ${DIALOG_ESC=255} + +function configure { +} + +function start { +} \ No newline at end of file diff --git a/modules/module_list b/modules/module_list index dc5d36b..5c39768 100644 --- a/modules/module_list +++ b/modules/module_list @@ -2,6 +2,7 @@ autossh Maintain persistent secure shells cron Schedule tasks dns-spoof Forges replies to arbitrary DNS address dnsmasq-spoof DNSSpoof using DNSMasq +extroot Simplified SD card storage follow-file Follow log printing data as file grows keymanager SSH Key Manager meterpreter Metasploit payload to maintain shells From 26053d83de3b4f79647f933f93a9a22a7fa14956 Mon Sep 17 00:00:00 2001 From: jrwimmer <67992074+jrwimmer@users.noreply.github.com> Date: Sun, 5 Dec 2021 08:56:22 -0800 Subject: [PATCH 2/9] First flesh-out --- modules/extroot | 121 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/modules/extroot b/modules/extroot index 94dba58..2c4cfb7 100644 --- a/modules/extroot +++ b/modules/extroot @@ -8,8 +8,10 @@ # Target: N/A # Attackmodes: N/A +# Constants VERSION="1.0" DESCRIPTION="Simplified SD card storage" +REQUIRED_PACKAGES="block-mount kmod-fs-ext4 e2fsprogs fdisk" CONF=/tmp/extroot.form # All "dialog" functionality is related to the Turtle shell @@ -23,5 +25,124 @@ CONF=/tmp/extroot.form function configure { } +function check_network { + # Check for Internet connection by attempting to contact an opkg repository server + + # First, extract a server URL from distfeeds.conf + opkg_baseurl=$(sed -E -n "s/^[^#]*(http:\/\/[^\/]*)\/.*/\1/p;q" /etc/opkg/distfeeds.conf) &> /dev/null + if [[ $? -ne 0 ]]; then + /usr/bin/dialog --title "Extroot" --msgbox "\nCould not extract an opkg repo from distfeeds.conf\n\nIf this is unexpected, you may need to upgrade or restore the firmware." 9 72 + exit 1 + fi + + # ...then, use wget to determine if the server can be reached + wget -q --spider "$opkg_baseurl" &> /dev/null + if [[ $? -ne 0 ]]; then + /usr/bin/dialog --title "Extroot" --msgbox "\nThe LAN Turtle could not connect to $output\nPlease connect the LAN Turtle to the Internet and try again." 9 72 + exit 1 + fi +} + +function install_dependencies { + /bin/opkg update | /usr/bin/dialog --progressbox "Updating opkg" 14 72 + + /bin/opkg install $REQUIRED_PACKAGES | /usr/bin/dialog --progressbox "Checking/installing dependencies" 14 72 +} + +function remount_rootfsdata { + #TODO: Add sanity check for the overlay having already been migrated + + # Identify flash memory device containing current overlay + rootfsdata_dev="$(sed -n -e "/\s\/overlay\s.*$/s///p" /etc/mtab)" + + # Create remount entry + uci -q delete fstab.rwm + uci set fstab.rwm="mount" + uci set fstab.rwm.device="${rootfsdata_dev}" + uci set fstab.rwm.target="/rwm" + uci commit fstab +} + +function format_sdcard { + # Identify our storage device + sdcard_device=$(ls /dev/sd* 2> /dev/null | head -n1) + + # Check SD card presence + [[ "$(ls /dev/sd* 2> /dev/null | wc -l)" == "0" ]] && { + echo "No SD card inserted or device not supported" + exit 1 + } + + # Unmount storage as applicable + block umount &> /dev/null + + # Partition SD card for storage and swap + echo -e "o\nn\np\n2\n\n+1024M\nn\np\n1\n\np\n\nw\n" | fdisk $sdcard_device + echo y | mkfs.ext4 ${sdcard_device}1 + mkswap ${sdcard_device}2 + + # Restart the storage bus + echo "1-0:1.0" > /sys/bus/usb/drivers/hub/unbind + echo "1-0:1.0" > /sys/bus/usb/drivers/hub/bind + sleep 3 + + # Commit/activate swap and remove existing SD card mounts + block detect > /etc/config/fstab + uci -q delete fstab.@mount[0] + uci commit fstab + block mount &> /dev/null +} + +function make_extroot { + # Identify our storage partition + sdcard_device=$(ls /dev/sd* 2> /dev/null | head -n1)1 + + # Identify the partition's UUID + eval $(block info ${sdcard_device} | grep -o -e "UUID=\S*") + + # Delete and recreate the overlay fstab entry + uci -q delete fstab.overlay + uci set fstab.overlay="mount" + uci set fstab.overlay.uuid="${UUID}" + uci set fstab.overlay.target="/overlay" + uci commit fstab +} + +function migrate_overlay { + # Identify our storage partition + sdcard_device=$(ls /dev/sd* 2> /dev/null | head -n1)1 + + # Create a temporary mount point directory + mkdir -p /tmp/cproot + + # Bind the current overlay to the mount point + mount --bind /overlay /tmp/cproot + + # Mount the new overlay storage + mount ${sdcard_device} /mount + + # Copy over the data + tar -C /tmp/cproot -cvf - . | tar -C /mnt -xf - + + # Unmount the new overlay and temporary mount point + umount /tmp/cproot /mnt +} + +function perform_migration { + check_network + + install_dependencies + + remount_rootfsdata + + format_sdcard + + make_extroot + + migrate_overlay + + reboot +} + function start { } \ No newline at end of file From 29582b77806a76b646e087baa65ad1216043be3e Mon Sep 17 00:00:00 2001 From: jrwimmer <67992074+jrwimmer@users.noreply.github.com> Date: Mon, 20 Dec 2021 19:30:41 -0800 Subject: [PATCH 3/9] Modify initialization * Moved entrypoint to CONFIGURE since the module framework already uses "dialog" in START --- modules/extroot | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/extroot b/modules/extroot index 2c4cfb7..c085e86 100644 --- a/modules/extroot +++ b/modules/extroot @@ -23,6 +23,19 @@ CONF=/tmp/extroot.form : ${DIALOG_ESC=255} function configure { + /usr/bin/dialog --title "Extroot: Info" --msgbox "::: NOTICE :::\n\nThis module is intended for use on freshly-imaged devices. Any customizations already made are not guaranteed to persist through extroot configuration." 14 72 + + /usr/bin/dialog --title "Extroot: WARNING" --defaultno --yesno "::: WARNING :::\n\n\nThis Operation WILL ERASE THE ATTACHED SD CARD \n\nAre you sure you wish to continue?" 14 72 + + return=$? + case $return in + $DIALOG_OK) + perform_migration;; + $DIALOG_CANCEL) + /usr/bin/dialog --title "Extroot" --msgbox "Operation cancelled" 14 72;; + $DIALOG_ESC) + /usr/bin/dialog --title "Extroot" --msgbox "Operation cancelled" 14 72;; + esac } function check_network { @@ -145,4 +158,5 @@ function perform_migration { } function start { + echo "This module is used via the 'Configure' option" } \ No newline at end of file From d02f467a0cbdc0633a3930f1f840d6e6f527cea2 Mon Sep 17 00:00:00 2001 From: jrwimmer <67992074+jrwimmer@users.noreply.github.com> Date: Mon, 20 Dec 2021 19:34:20 -0800 Subject: [PATCH 4/9] Correct props from template copy --- modules/extroot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/extroot b/modules/extroot index c085e86..f3c2ea0 100644 --- a/modules/extroot +++ b/modules/extroot @@ -2,7 +2,7 @@ # Title: LANTurtle OpenWRT Extroot configuration # Description: Simplified SD card storage # Author: jrwimmer -# Props: ImNatho, mike111b, madbuda +# Props: The OpenWrt community # Version: 1.0 # Category: General # Target: N/A From 3e108f1cbace09ba81c2c7ba9a1fd0ececa34b72 Mon Sep 17 00:00:00 2001 From: jrwimmer <67992074+jrwimmer@users.noreply.github.com> Date: Mon, 20 Dec 2021 19:42:19 -0800 Subject: [PATCH 5/9] Process refinement * Migration stages are now piped through to a dialog progressbox for monitoring * Migration stages are now proxied through a separate function to monitor for breaking errors * Each migration stage now ends with a 3-second sleep to provide time to review the last lines written to the progressbox * Limited the wget spider retry amount to prevent an indefinite wait during a bad connectivity check * Nulled stderr on select calls during formatting and data-copy to hide non-critical extraneous errors * Added a finalization step to inform the user of an impending reboot --- modules/extroot | 122 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 82 insertions(+), 40 deletions(-) diff --git a/modules/extroot b/modules/extroot index f3c2ea0..cfa427a 100644 --- a/modules/extroot +++ b/modules/extroot @@ -44,22 +44,27 @@ function check_network { # First, extract a server URL from distfeeds.conf opkg_baseurl=$(sed -E -n "s/^[^#]*(http:\/\/[^\/]*)\/.*/\1/p;q" /etc/opkg/distfeeds.conf) &> /dev/null if [[ $? -ne 0 ]]; then - /usr/bin/dialog --title "Extroot" --msgbox "\nCould not extract an opkg repo from distfeeds.conf\n\nIf this is unexpected, you may need to upgrade or restore the firmware." 9 72 - exit 1 + echo "\nCould not extract an opkg repo from distfeeds.conf\n\nIf this is unexpected, you may need to upgrade or restore the firmware." > $1 + return 1 fi # ...then, use wget to determine if the server can be reached - wget -q --spider "$opkg_baseurl" &> /dev/null - if [[ $? -ne 0 ]]; then - /usr/bin/dialog --title "Extroot" --msgbox "\nThe LAN Turtle could not connect to $output\nPlease connect the LAN Turtle to the Internet and try again." 9 72 - exit 1 + wget -q --tries 3 --spider "$opkg_baseurl" &> /dev/null + wget_returncode=$? + if [[ $wget_returncode -ne 0 ]]; then + echo "\nLAN Turtle could not connect to $opkg_baseurl\nVerify the device's internet connection and try again (wget error $wget_returncode)" > $1 + return 1 fi } function install_dependencies { - /bin/opkg update | /usr/bin/dialog --progressbox "Updating opkg" 14 72 + echo "Updating opkg" + /bin/opkg update - /bin/opkg install $REQUIRED_PACKAGES | /usr/bin/dialog --progressbox "Checking/installing dependencies" 14 72 + echo "Checking/installing dependencies" + /bin/opkg install $REQUIRED_PACKAGES + + sleep 3 } function remount_rootfsdata { @@ -74,87 +79,124 @@ function remount_rootfsdata { uci set fstab.rwm.device="${rootfsdata_dev}" uci set fstab.rwm.target="/rwm" uci commit fstab + + sleep 3 } function format_sdcard { - # Identify our storage device - sdcard_device=$(ls /dev/sd* 2> /dev/null | head -n1) - - # Check SD card presence + echo "Checking SD card presence" [[ "$(ls /dev/sd* 2> /dev/null | wc -l)" == "0" ]] && { - echo "No SD card inserted or device not supported" - exit 1 + echo "\nError: No SD card is inserted or the card is not supported\n\nAdditional Details:\nCould not find a device with prefix 'sd'" > $1 + return 1 } - # Unmount storage as applicable + sdcard_device=$(ls /dev/sd* 2> /dev/null | head -n1) + echo "New overlay device identified as: $sdcard_device" + + echo "Unmounting any active external storage" block umount &> /dev/null - # Partition SD card for storage and swap - echo -e "o\nn\np\n2\n\n+1024M\nn\np\n1\n\np\n\nw\n" | fdisk $sdcard_device - echo y | mkfs.ext4 ${sdcard_device}1 + echo "Partitioning SD card" + echo -e "o\nn\np\n2\n\n+1024M\nn\np\n1\n\np\n\nw\n" | fdisk $sdcard_device 2>/dev/null + mkfs.ext4 -F ${sdcard_device}1 mkswap ${sdcard_device}2 - # Restart the storage bus - echo "1-0:1.0" > /sys/bus/usb/drivers/hub/unbind - echo "1-0:1.0" > /sys/bus/usb/drivers/hub/bind + echo "Restarting the storage bus" + echo "1-0:1.0" > /sys/bus/usb/drivers/hub/unbind 2>/dev/null + echo "1-0:1.0" > /sys/bus/usb/drivers/hub/bind 2>/dev/null sleep 3 - # Commit/activate swap and remove existing SD card mounts + echo "Commit/activate swap and remove existing SD card mounts" block detect > /etc/config/fstab uci -q delete fstab.@mount[0] uci commit fstab block mount &> /dev/null + + sleep 3 } function make_extroot { - # Identify our storage partition sdcard_device=$(ls /dev/sd* 2> /dev/null | head -n1)1 + echo "New overlay partition identified as: $sdcard_device" - # Identify the partition's UUID eval $(block info ${sdcard_device} | grep -o -e "UUID=\S*") + echo "New overlay partition has a UUID of: $UUID" - # Delete and recreate the overlay fstab entry + echo "Recreating overlay fstab entry" uci -q delete fstab.overlay uci set fstab.overlay="mount" uci set fstab.overlay.uuid="${UUID}" uci set fstab.overlay.target="/overlay" uci commit fstab + + sleep 3 } function migrate_overlay { - # Identify our storage partition sdcard_device=$(ls /dev/sd* 2> /dev/null | head -n1)1 + echo "New overlay partition identified as: $sdcard_device" - # Create a temporary mount point directory + echo "Creating temporary mount point directory at: /tmp/cproot" mkdir -p /tmp/cproot - # Bind the current overlay to the mount point + echo "Binding active overlay to: /tmp/cproot" mount --bind /overlay /tmp/cproot - # Mount the new overlay storage - mount ${sdcard_device} /mount + echo "Mounting new overlay parition at: /mnt" + mount ${sdcard_device} /mnt - # Copy over the data - tar -C /tmp/cproot -cvf - . | tar -C /mnt -xf - + echo "Copying data; please wait..." + tar -C /tmp/cproot -cvf - . 2>/dev/null | tar -C /mnt -xf - 2>/dev/null + echo "Copy process complete" - # Unmount the new overlay and temporary mount point + echo "Unmounting new overlay and removing bind" umount /tmp/cproot /mnt + + sleep 3 +} + +function finalize { + /usr/bin/dialog --title "Extroot: Info" --msgbox "::: NOTICE :::\n\nOperation complete. To finalize changes, the system will now reboot." 14 72 + reboot +} + +function perform_step { + # Create a tmpfile in which we can store error data + active_tmpfile=$(mktemp) + # Default error data to 0 + echo 0 > $active_tmpfile + + # Perform the requested step + eval $1 | /usr/bin/dialog --progressbox "$2" 14 72 + + # Retrieve the last error written to the tmpfile + last_return_code=$(cat $active_tmpfile) + # Delete the tmpfile + rm $active_tmpfile + + # Determine if an error occurred + if [[ "$last_return_code" != 0 ]]; then + # Notify the user of the problem + /usr/bin/dialog --title "Extroot: Error" --msgbox "$last_return_code" 9 72 + exit 1 + fi } function perform_migration { - check_network - install_dependencies + perform_step "check_network" "Checking network connectivity" - remount_rootfsdata + perform_step "install_dependencies" "Installing requried dependencies" - format_sdcard + perform_step "remount_rootfsdata" "Creating backup mount for current overlay" - make_extroot + perform_step "format_sdcard" "Formatting SD card" - migrate_overlay + perform_step "make_extroot" "Configuring new overlay" - reboot + perform_step "migrate_overlay" "Migrating overlay data" + + finalize } function start { From 1a780657644166f50de853441f898aac5c9e68d3 Mon Sep 17 00:00:00 2001 From: jrwimmer <67992074+jrwimmer@users.noreply.github.com> Date: Mon, 20 Dec 2021 19:49:41 -0800 Subject: [PATCH 6/9] Remove inconsistent use of path prefixing --- modules/extroot | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/extroot b/modules/extroot index cfa427a..c782f96 100644 --- a/modules/extroot +++ b/modules/extroot @@ -23,18 +23,18 @@ CONF=/tmp/extroot.form : ${DIALOG_ESC=255} function configure { - /usr/bin/dialog --title "Extroot: Info" --msgbox "::: NOTICE :::\n\nThis module is intended for use on freshly-imaged devices. Any customizations already made are not guaranteed to persist through extroot configuration." 14 72 + dialog --title "Extroot: Info" --msgbox "::: NOTICE :::\n\nThis module is intended for use on freshly-imaged devices. Any customizations already made are not guaranteed to persist through extroot configuration." 14 72 - /usr/bin/dialog --title "Extroot: WARNING" --defaultno --yesno "::: WARNING :::\n\n\nThis Operation WILL ERASE THE ATTACHED SD CARD \n\nAre you sure you wish to continue?" 14 72 + dialog --title "Extroot: WARNING" --defaultno --yesno "::: WARNING :::\n\n\nThis Operation WILL ERASE THE ATTACHED SD CARD \n\nAre you sure you wish to continue?" 14 72 return=$? case $return in $DIALOG_OK) perform_migration;; $DIALOG_CANCEL) - /usr/bin/dialog --title "Extroot" --msgbox "Operation cancelled" 14 72;; + dialog --title "Extroot" --msgbox "Operation cancelled" 14 72;; $DIALOG_ESC) - /usr/bin/dialog --title "Extroot" --msgbox "Operation cancelled" 14 72;; + dialog --title "Extroot" --msgbox "Operation cancelled" 14 72;; esac } @@ -59,10 +59,10 @@ function check_network { function install_dependencies { echo "Updating opkg" - /bin/opkg update + opkg update echo "Checking/installing dependencies" - /bin/opkg install $REQUIRED_PACKAGES + opkg install $REQUIRED_PACKAGES sleep 3 } @@ -156,7 +156,7 @@ function migrate_overlay { } function finalize { - /usr/bin/dialog --title "Extroot: Info" --msgbox "::: NOTICE :::\n\nOperation complete. To finalize changes, the system will now reboot." 14 72 + dialog --title "Extroot: Info" --msgbox "::: NOTICE :::\n\nOperation complete. To finalize changes, the system will now reboot." 14 72 reboot } @@ -167,7 +167,7 @@ function perform_step { echo 0 > $active_tmpfile # Perform the requested step - eval $1 | /usr/bin/dialog --progressbox "$2" 14 72 + eval $1 | dialog --progressbox "$2" 14 72 # Retrieve the last error written to the tmpfile last_return_code=$(cat $active_tmpfile) @@ -177,7 +177,7 @@ function perform_step { # Determine if an error occurred if [[ "$last_return_code" != 0 ]]; then # Notify the user of the problem - /usr/bin/dialog --title "Extroot: Error" --msgbox "$last_return_code" 9 72 + dialog --title "Extroot: Error" --msgbox "$last_return_code" 9 72 exit 1 fi } From 0ed9bc94fb83089b144c7dc584d33b1afd789235 Mon Sep 17 00:00:00 2001 From: jrwimmer <67992074+jrwimmer@users.noreply.github.com> Date: Mon, 20 Dec 2021 20:32:06 -0800 Subject: [PATCH 7/9] Added rootfs-size sanity check * Module will now check the total size of the active root filesystem * - This is done to catch and prevent instances of double-extroot migration --- modules/extroot | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/modules/extroot b/modules/extroot index c782f96..cc18080 100644 --- a/modules/extroot +++ b/modules/extroot @@ -32,12 +32,37 @@ function configure { $DIALOG_OK) perform_migration;; $DIALOG_CANCEL) - dialog --title "Extroot" --msgbox "Operation cancelled" 14 72;; + dialog --title "Extroot" --msgbox "Operation cancelled" 14 72 + exit 0;; $DIALOG_ESC) - dialog --title "Extroot" --msgbox "Operation cancelled" 14 72;; + dialog --title "Extroot" --msgbox "Operation cancelled" 14 72 + exit 0;; esac } +function check_space { + # Get block size for the root partition + rootfs_blocksize=$(df -P / | awk '{print $2}' | tail -n+2) + rootfs_humansize=$(df -h / | awk '{print $2}' | tail -n+2) + + # Check if the root partition is larger than 256 MB + if (( $rootfs_blocksize > 256000 )); then + dialog --title "Extroot: WARNING" --defaultno --yesno "::: WARNING :::\n\n\nThe root partition appears to be larger than 256MB in size (Seen: $rootfs_humansize)\n\nThis may indicate that the overlay configuration process has already been performed on this installation.\n\nAre you sure you wish to continue?" 14 72 + + return=$? + case $return in + $DIALOG_OK) + return 0;; + $DIALOG_CANCEL) + dialog --title "Extroot" --msgbox "Operation cancelled" 14 72 + exit 0;; + $DIALOG_ESC) + dialog --title "Extroot" --msgbox "Operation cancelled" 14 72 + exit 0;; + esac + fi +} + function check_network { # Check for Internet connection by attempting to contact an opkg repository server @@ -68,8 +93,6 @@ function install_dependencies { } function remount_rootfsdata { - #TODO: Add sanity check for the overlay having already been migrated - # Identify flash memory device containing current overlay rootfsdata_dev="$(sed -n -e "/\s\/overlay\s.*$/s///p" /etc/mtab)" @@ -183,6 +206,7 @@ function perform_step { } function perform_migration { + check_space perform_step "check_network" "Checking network connectivity" From a5d084610fa62cc1b19de989ed96799804fba9a4 Mon Sep 17 00:00:00 2001 From: jrwimmer <67992074+jrwimmer@users.noreply.github.com> Date: Mon, 20 Dec 2021 21:02:23 -0800 Subject: [PATCH 8/9] Bash variable linting * Added double quotes where possible to prevent globbing/word-splitting --- modules/extroot | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/extroot b/modules/extroot index cc18080..b6aa372 100644 --- a/modules/extroot +++ b/modules/extroot @@ -29,12 +29,12 @@ function configure { return=$? case $return in - $DIALOG_OK) + "$DIALOG_OK") perform_migration;; - $DIALOG_CANCEL) + "$DIALOG_CANCEL") dialog --title "Extroot" --msgbox "Operation cancelled" 14 72 exit 0;; - $DIALOG_ESC) + "$DIALOG_ESC") dialog --title "Extroot" --msgbox "Operation cancelled" 14 72 exit 0;; esac @@ -51,12 +51,12 @@ function check_space { return=$? case $return in - $DIALOG_OK) + "$DIALOG_OK") return 0;; - $DIALOG_CANCEL) + "$DIALOG_CANCEL") dialog --title "Extroot" --msgbox "Operation cancelled" 14 72 exit 0;; - $DIALOG_ESC) + "$DIALOG_ESC") dialog --title "Extroot" --msgbox "Operation cancelled" 14 72 exit 0;; esac @@ -120,9 +120,9 @@ function format_sdcard { block umount &> /dev/null echo "Partitioning SD card" - echo -e "o\nn\np\n2\n\n+1024M\nn\np\n1\n\np\n\nw\n" | fdisk $sdcard_device 2>/dev/null - mkfs.ext4 -F ${sdcard_device}1 - mkswap ${sdcard_device}2 + echo -e "o\nn\np\n2\n\n+1024M\nn\np\n1\n\np\n\nw\n" | fdisk "$sdcard_device" 2>/dev/null + mkfs.ext4 -F "${sdcard_device}1" + mkswap "${sdcard_device}2" echo "Restarting the storage bus" echo "1-0:1.0" > /sys/bus/usb/drivers/hub/unbind 2>/dev/null @@ -142,7 +142,7 @@ function make_extroot { sdcard_device=$(ls /dev/sd* 2> /dev/null | head -n1)1 echo "New overlay partition identified as: $sdcard_device" - eval $(block info ${sdcard_device} | grep -o -e "UUID=\S*") + eval $(block info "${sdcard_device}" | grep -o -e "UUID=\S*") echo "New overlay partition has a UUID of: $UUID" echo "Recreating overlay fstab entry" @@ -166,7 +166,7 @@ function migrate_overlay { mount --bind /overlay /tmp/cproot echo "Mounting new overlay parition at: /mnt" - mount ${sdcard_device} /mnt + mount "${sdcard_device}" /mnt echo "Copying data; please wait..." tar -C /tmp/cproot -cvf - . 2>/dev/null | tar -C /mnt -xf - 2>/dev/null @@ -187,15 +187,15 @@ function perform_step { # Create a tmpfile in which we can store error data active_tmpfile=$(mktemp) # Default error data to 0 - echo 0 > $active_tmpfile + echo 0 > "$active_tmpfile" # Perform the requested step - eval $1 | dialog --progressbox "$2" 14 72 + eval "$1" | dialog --progressbox "$2" 14 72 # Retrieve the last error written to the tmpfile - last_return_code=$(cat $active_tmpfile) + last_return_code=$(cat "$active_tmpfile") # Delete the tmpfile - rm $active_tmpfile + rm "$active_tmpfile" # Determine if an error occurred if [[ "$last_return_code" != 0 ]]; then From b0c8927aed6692233260d3ec518a0cceaf6a1d9f Mon Sep 17 00:00:00 2001 From: jrwimmer <67992074+jrwimmer@users.noreply.github.com> Date: Mon, 20 Dec 2021 21:55:21 -0800 Subject: [PATCH 9/9] Restored missing parameter * perform_step was not passing the tmpfile used for error processing --- modules/extroot | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/extroot b/modules/extroot index b6aa372..27d2594 100644 --- a/modules/extroot +++ b/modules/extroot @@ -80,6 +80,8 @@ function check_network { echo "\nLAN Turtle could not connect to $opkg_baseurl\nVerify the device's internet connection and try again (wget error $wget_returncode)" > $1 return 1 fi + + sleep 3 } function install_dependencies { @@ -190,7 +192,7 @@ function perform_step { echo 0 > "$active_tmpfile" # Perform the requested step - eval "$1" | dialog --progressbox "$2" 14 72 + eval "$1" "$active_tmpfile" | dialog --progressbox "$2" 14 72 # Retrieve the last error written to the tmpfile last_return_code=$(cat "$active_tmpfile")