Skip to content

Commit

Permalink
PV doesn't show upgrading status in serial console. #710
Browse files Browse the repository at this point in the history
  • Loading branch information
jorikfon committed May 4, 2024
1 parent 5c0b291 commit ca704a2
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 95 deletions.
10 changes: 5 additions & 5 deletions src/Core/System/RootFS/sbin/check-update-pbx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
. /sbin/shell_functions.sh;

# Redirect standard input, output and error to /dev/console
if test -w /dev/ttyS0; then
exec </dev/console > >(/bin/busybox tee /dev/ttyS0 /dev/console) 2>&1
else
exec </dev/console >/dev/console 2>/dev/console;
fi
if test -w /dev/ttyS0; then
exec </dev/console > >(/bin/busybox tee /dev/ttyS0 /dev/console) 2>&1
else
exec </dev/console >/dev/console 2>/dev/console;
fi

systemDir='/system';
mkdir "$systemDir";
Expand Down
35 changes: 11 additions & 24 deletions src/Core/System/RootFS/sbin/firmware_upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ if [ -f "$ENV_FILE" ]; then
export $(cat "$ENV_FILE" | grep -v '^#' | xargs)
fi

if test -w /dev/ttyS0; then
exec </dev/console > >(/bin/busybox tee /dev/ttyS0 /dev/console) 2>&1
else
exec </dev/console >/dev/console 2>/dev/console;
fi

# mountDiskPart: Mounts a disk partition by UUID.
# Args:
# $1: UUID of the disk partition.
Expand All @@ -42,38 +48,19 @@ mountDiskPart()
uuid="$1";
mountpoint="$2";
if [ '1' = "$(/sbin/blkid | /bin/busybox grep "$uuid" > /dev/null)" ]; then
echoToTeletype " - Storage disk with UUID=${uuid} not found..."
echo " - Storage disk with UUID=${uuid} not found..."
exit 1;
fi

mkdir -p "$mountpoint";
mount -rw UUID="$uuid" "$mountpoint" 2> /dev/null;
MOUNT_RESULT=$?;
if [ ! "${MOUNT_RESULT}" = "0" ] ; then
echoToTeletype " - Fail mount storage with UUID=${uuid} to ${mountpoint} ..."
echo " - Fail mount storage with UUID=${uuid} to ${mountpoint} ..."
exit 1;
fi
}

# echoToTeletype: Prints a message to the console and the serial port if available.
# Args:
# $1: Message to be printed.
echoToTeletype()
{
echo "$1";
dev='/dev/ttyS0';
serialInfo="$(/bin/busybox setserial -g "$dev" 2> /dev/null)";
if [ "${serialInfo}x" = 'x' ]; then
return;
fi;
echo "$serialInfo" | /bin/grep unknown > /dev/null 2> /dev/null;
resultSetSerial="$?";
if [ ! "$resultSetSerial" = '0' ]; then
# Device ttys found
echo "$1" >> "$dev"
fi;
}

# Mounts storage and configuration partitions
mountPartitions() {
umount "/system" 2>/dev/null
Expand All @@ -90,7 +77,7 @@ executeFirmwareUpdate() {
echo "$systemDevice" > /var/etc/cfdevice
/bin/sh pbx_firmware "$UPDATE_IMG_FILE" "$systemDevice"
else
echoToTeletype ' - System disk not found...'
echo ' - System disk not found...'
return 1
fi
}
Expand All @@ -100,9 +87,9 @@ startUpgrade() {
local updateVersion="version"
if [ -f "$updateVersion" ]; then
local versionNumber=$(cat "$updateVersion")
echoToTeletype " - Start update script from the version: $versionNumber..."
echo " - Start update script from the version: $versionNumber..."
else
echoToTeletype " - Start update script"
echo " - Start update script"
fi

mountPartitions && executeFirmwareUpdate
Expand Down
102 changes: 48 additions & 54 deletions src/Core/System/RootFS/sbin/mountoffload
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ MD5_BUILD_INFO=$(/bin/busybox md5sum /etc/version.buildtime 2>/dev/null | /bin/b
PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH

if test -w /dev/ttyS0; then
exec </dev/console > >(/bin/busybox tee /dev/ttyS0 /dev/console) 2>&1
else
exec </dev/console >/dev/console 2>/dev/console;
fi

# Import shell functions
. /sbin/shell_functions.sh

Expand All @@ -49,7 +43,7 @@ checkOffloadDisk() {
# Check if the file exists
if [ ! -f "${pathToFile}" ]; then
# If it doesn't exist, set the result variable to 1 and print an error message
echo " - File ${pathToFile} not found"
echoToTeletype " - File ${pathToFile} not found"
CHECK_RESULT=1
else
# If it exists, calculate its MD5 hash and compare it with the stored MD5 hash
Expand All @@ -58,7 +52,7 @@ checkOffloadDisk() {
# If the hashes don't match, set the result variable to 2 and print an error message
if [ ! "${md5OffloadBI}" = "${MD5_BUILD_INFO}" ]; then
CHECK_RESULT=2
echo " - Hash file ${pathToFile} verification failed"
echoToTeletype " - Hash file ${pathToFile} verification failed"
fi
fi
}
Expand Down Expand Up @@ -104,7 +98,7 @@ mountoffload() {

# If the size of the disk is less than or equal to 600MB, it will perform a filesystem check
if [ "$size_bytes" -le 629145600 ]; then
echo " - Start check: $disk"
echoToTeletype " - Start check: $disk"
"/sbin/fsck.${type}" -f -p "$disk" >/dev/null 2>/dev/null
else
MOUNT_RESULT='Disk size exceeds 600MB, cannot offload partition'
Expand Down Expand Up @@ -149,7 +143,7 @@ mountConfRecover() {

# Disk variable which takes the first argument of the function
offloaddisk="$1"
echo " - Attempting to mount existing configuration..."
echoToTeletype " - Attempting to mount existing configuration..."

# Create a directory for mounting (old config)
rec_dir='/conf.recover/'
Expand All @@ -162,31 +156,31 @@ mountConfRecover() {

# Skip if the disk is already mounted
if [ "${diskr}" = "${offloaddisk}" ]; then
echo " - Skip ${diskr}, already mounted..."
echoToTeletype " - Skip ${diskr}, already mounted..."
continue
fi

# Skip if the disk does not have a third partition
if [ ! -b "/dev/${disk3}" ]; then
echo " - Skip ${diskr}, part 3 not found..."
echoToTeletype " - Skip ${diskr}, part 3 not found..."
continue
fi

# Get the type of the filesystem of the partition and run filesystem check if possible
type=$(/sbin/blkid -o full "/dev/${disk3}" | /bin/busybox sed -r 's/[[:alnum:]]+=/\n&/g' | /bin/busybox grep "^TYPE" | /bin/busybox cut -d '"' -f 2 | /bin/busybox head -n 1)
if [ -f "/sbin/fsck.${type}" ]; then
"/sbin/fsck.${type}" -f -p "/dev/${disk3}" >/dev/null 2>/dev/null
echo " - Trying fsck /dev/${disk3} ... returned: $?"
echoToTeletype " - Trying fsck /dev/${disk3} ... returned: $?"
fi

# Get the UUID of the partition and attempt to mount it read-only to the created directory
uuid=$(/sbin/blkid -o full "/dev/${disk3}" | /bin/busybox sed -r 's/[[:alnum:]]+=/\n&/g' | /bin/busybox grep "^UUID" | /bin/busybox cut -d '"' -f 2 | /bin/busybox head -n 1)
mount -t "${type}" -r UUID="${uuid}" "${rec_dir}"
echo " - Trying mount ${diskr} fs ${type} ... returned: $?"
echoToTeletype " - Trying mount ${diskr} fs ${type} ... returned: $?"

# If the directory has a "conf" subdirectory and no "livecd" file, exit
if [ -d "${rec_dir}conf" ] && [ ! -f "${rec_dir}livecd" ]; then
echo " - Found existing configuration on ${disk3}!"
echoToTeletype " - Found existing configuration on ${disk3}!"
exit 0
else
# If not, unmount the directory and remove it before moving on to the next disk
Expand All @@ -205,7 +199,7 @@ rm -rf /tmp/freeoffload
################################################################################

# Start of the block for LIVE CD-ROM
echo " - Waiting for device ready..."
echoToTeletype " - Waiting for device ready..."
busybox sleep 4

# Attempt to identify CD-ROM drives
Expand All @@ -220,7 +214,7 @@ blkResult="$?"
if [ "$blkResult" -eq 0 ]; then
length=${#cddev}
fi
echo " - Searching for RootFS on LiveCD..."
echoToTeletype " - Searching for RootFS on LiveCD..."

# If the length of the identifier is more than 2, it means we have identified a CD-ROM drive,
# and we should use this for subsequent operations. Otherwise, try to identify regular disks.
Expand All @@ -245,14 +239,14 @@ for disk in $disks; do
fi

# Attempt to mount the disk or partition as an offload disk
echo
echo " - Mounting $diskPath..."
echoToTeletype
echoToTeletype " - Mounting $diskPath..."
mountoffload "$diskPath"
echo " - Mount result: $MOUNT_RESULT"
echoToTeletype " - Mount result: $MOUNT_RESULT"

# Check for the presence of a "livecd" flag file in the root of the offload disk.
if [ -f /offload/livecd ]; then
echo " - Found LiveCD flag..."
echoToTeletype " - Found LiveCD flag..."

# Call function to create boot configuration files and recover configuration from the offload disk
createBootConfFiles
Expand All @@ -269,8 +263,8 @@ done
# Start of the block for RAID disks
################################################################################

echo
echo " - Searching for RootFS on RAID devices..."
echoToTeletype
echoToTeletype " - Searching for RootFS on RAID devices..."

# Identify RAID drives
disks=$(/bin/lsblk -b -r -o NAME,TYPE -n | /bin/busybox grep "raid" | /bin/busybox cut -d ' ' -f 1 | /bin/busybox sort -u)
Expand All @@ -286,28 +280,28 @@ for disk in $disks; do
fi

# Attempt to mount the partition as an offload disk
echo
echo " - Mounting $diskPath..."
echoToTeletype
echoToTeletype " - Mounting $diskPath..."
mountoffload "$diskPath"
echo " - Mount result: $MOUNT_RESULT"
echoToTeletype " - Mount result: $MOUNT_RESULT"

# Check for the presence of a "rootfs" directory in the root of the offload disk
if [ -d /offload/rootfs ]; then
echo " - RootFS founded on $diskPath!"
echoToTeletype " - RootFS founded on $diskPath!"
exit 0
fi

# If the "rootfs" directory was not found, unmount the offload disk and continue with the next one
umount -f /offload >/dev/null
echo " - Failed to find RootFS on $diskPath!"
echoToTeletype " - Failed to find RootFS on $diskPath!"
done

################################################################################
# Start of the block for Hard Disk Drives (HDDs)
################################################################################

echo
echo " - Searching for RootFS on block devices..."
echoToTeletype
echoToTeletype " - Searching for RootFS on block devices..."

# Identify HDDs
disks=$(/bin/lsblk -b -d -r -o NAME,TYPE -n | /bin/busybox grep "disk$" | /bin/busybox cut -d ' ' -f 1 | /bin/busybox uniq)
Expand All @@ -327,33 +321,33 @@ for disk in $disks; do
fi

# Attempt to mount the partition as an offload disk
echo
echo " - Mounting $diskPath..."
echoToTeletype
echoToTeletype " - Mounting $diskPath..."
mountoffload "$diskPath"
echo " - Mount result: $MOUNT_RESULT"
echoToTeletype " - Mount result: $MOUNT_RESULT"

# Check if a directory named "rootfs" exists in the root of the offload disk
if [ -d /offload/rootfs ]; then
echo " - RootFS founded on $diskPath!"
echoToTeletype " - RootFS founded on $diskPath!"
exit 0
fi

# If the "rootfs" directory was not found, unmount the offload disk and log failure to find "rootfs"
umount -f /offload >/dev/null
echo " - Failed to find RootFS on $diskPath!"
echoToTeletype " - Failed to find RootFS on $diskPath!"
done

################################################################################
# Start of the block for Universal Serial Bus (USB) devices
################################################################################

echo
echo " - Waiting for disks USB ready and trying again..."
echoToTeletype
echoToTeletype " - Waiting for disks USB ready and trying again..."

# Sleep for 10 seconds to give disks time to settle
/bin/busybox sleep 10

echo " - Searching for RootFS on USB devices..."
echoToTeletype " - Searching for RootFS on USB devices..."

# Identify USB devices
disks=$(/bin/lsblk -b -d -r -o NAME,TYPE -n | /bin/busybox grep "disk$" | /bin/busybox cut -d ' ' -f 1 | /bin/busybox uniq)
Expand All @@ -373,14 +367,14 @@ for disk in $disks; do
fi

# Attempt to mount the partition as an offload disk
echo
echo " - Mounting $diskPath..."
echoToTeletype
echoToTeletype " - Mounting $diskPath..."
mountoffload "$diskPath"
echo " - Mount result: $MOUNT_RESULT"
echoToTeletype " - Mount result: $MOUNT_RESULT"

# Check if a file named "livecd" exists in the root of the offload disk
if [ -f /offload/livecd ]; then
echo " - Found LiveUSB flag..."
echoToTeletype " - Found LiveUSB flag..."
mountConfRecover "$disk"
exit 0
fi
Expand All @@ -390,7 +384,7 @@ for disk in $disks; do
done

# Checking for a rootfs directory on the second partition of each USB device
echo
echoToTeletype
for disk in $disks; do

# Get the second partition of the USB device
Expand All @@ -405,26 +399,26 @@ for disk in $disks; do
fi

# Attempt to mount the partition as an offload disk
echo
echo " - Mounting $diskPath..."
echoToTeletype
echoToTeletype " - Mounting $diskPath..."
mountoffload "$diskPath"
echo " - Mount result: $MOUNT_RESULT"
echoToTeletype " - Mount result: $MOUNT_RESULT"

# Check if a directory named "rootfs" exists in the root of the offload disk
if [ -d /offload/rootfs ]; then
echo " - RootFS founded on $diskPath!"
echoToTeletype " - RootFS founded on $diskPath!"
exit 0
fi
echo " - Failed to find RootFS on $diskPath!"
echoToTeletype " - Failed to find RootFS on $diskPath!"
done


# Log message indicating failure to find the /offload partition
echo "The system was unable to find the /offload partition!"
echo
echo "Please send the output of 'ls /dev' and 'fdisk -l' to the"
echo "development team for assistance."
echo "Apologies for the inconvenience, and thank you for your patience as we resolve this issue."
echo
echoToTeletype "The system was unable to find the /offload partition!"
echoToTeletype
echoToTeletype "Please send the output of 'ls /dev' and 'fdisk -l' to the"
echoToTeletype "development team for assistance."
echoToTeletype "Apologies for the inconvenience, and thank you for your patience as we resolve this issue."
echoToTeletype

exit 1
Loading

0 comments on commit ca704a2

Please sign in to comment.