Skip to content

Commit

Permalink
#745 Расширил вывод информации в консоль для отладки (3).
Browse files Browse the repository at this point in the history
  • Loading branch information
boffart committed Jun 18, 2024
1 parent 04c1d8b commit 5fa6bac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
9 changes: 8 additions & 1 deletion src/Core/System/PBXInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,14 @@ private function copyConfiguration():void
Util::mwMkdir('/mnttmp');

echo "Target disk: $this->target_disk ...".PHP_EOL;
$confPartitionName = Storage::getDevPartName($this->target_disk, '3');
// Touch the disk to update disk tables
$partProbePath = Util::which('partprobe');
shell_exec($partProbePath." '/dev/$this->target_disk'");
$confPartitionName = Storage::getDevPartName($this->target_disk, '3', true);
if(empty($confPartitionName)){
echo "Target partition not found: $this->target_disk (part 3) ...".PHP_EOL;
return;
}
// Mount the disk with settings.
$mount = Util::which('mount');
$umount = Util::which('umount');
Expand Down
33 changes: 21 additions & 12 deletions src/Core/System/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,21 +383,21 @@ public function formatEntireDisk(string $device, bool $bg = false): bool

// First, remove existing partitions and then create a new msdos partition table and ext4 partition
// This command deletes all existing partitions and creates a new primary partition using the full disk
$command = "{$parted} --script --align optimal '{$device}' 'mklabel msdos'";
$command = "$parted --script --align optimal '$device' 'mklabel msdos'";
Processes::mwExec($command); // Apply the command to clear the partition table

// Now create a new partition that spans the entire disk
$createPartCommand = "{$parted} --script --align optimal '{$device}' 'mkpart primary ext4 0% 100%'";
$createPartCommand = "$parted --script --align optimal '$device' 'mkpart primary ext4 0% 100%'";
$retVal = Processes::mwExec($createPartCommand);

// Log the result of the create partition command
SystemMessages::sysLogMsg(__CLASS__, "{$createPartCommand} returned {$retVal}", LOG_INFO);
SystemMessages::sysLogMsg(__CLASS__, "$createPartCommand returned $retVal", LOG_INFO);

sleep(2); // Wait for the system to recognize changes to the partition table

// Touch the disk to update disk tables
$partprobe = Util::which('partprobe');
Processes::mwExec("{$partprobe} '{$device}'");
$partProbePath = Util::which('partprobe');
Processes::mwExec("$partProbePath '$device'");

// Get the newly created partition name, assuming it's always the first partition after a fresh format
$partition = self::getDevPartName($device, '1');
Expand Down Expand Up @@ -645,19 +645,28 @@ public static function selectAndConfigureStorageDisk(bool $automatic=false, bool
*
* @param string $dev The device name
* @param string $part The partition number
* @param bool $verbose print verbose messages
* @return string The partition name
*/
public static function getDevPartName(string $dev, string $part): string
public static function getDevPartName(string $dev, string $part, bool $verbose = false): string
{
$lsBlkPath = Util::which('lsblk');
$cutPath = Util::which('cut');
$grepPath = Util::which('grep');
$sortPath = Util::which('sort');
$cutPath = Util::which('cut');
$grepPath = Util::which('grep');
$sortPath = Util::which('sort');

// Touch the disk to update disk tables
$command = "$lsBlkPath -r -p | $grepPath ' part' | $sortPath -u | $cutPath -d ' ' -f 1 | $grepPath '" . basename($dev) . "' | $grepPath \"$part\$\"";
Processes::mwExec($command, $out);
$devName = trim(implode('', $out));
return trim($devName);
$devName = trim(shell_exec($command));
if(empty($devName) && $verbose ){
$verboseMsg = trim(shell_exec("$lsBlkPath -r -p"));
echo "--- filtered command ---".PHP_EOL;
echo $command.PHP_EOL;
echo "--- result 'lsblk -r -p' ---".PHP_EOL;
echo $verboseMsg.PHP_EOL;
echo "--- --- ---".PHP_EOL;
}
return $devName;
}

/**
Expand Down

0 comments on commit 5fa6bac

Please sign in to comment.