Skip to content

[Raspberry Pi OS] platform.js does not recognise later versions of Raspberry Pi OS #3220

@flatsiedatsie

Description

@flatsiedatsie

This code in platform.js does not work on Raspberry Pi OS versions above Buster:

// Check lsb_release for the name of a Linux distribution
  const proc = child_process.spawnSync('lsb_release', ['-i', '-s']);
  if (proc.status === 0) {
    const lsb_release = proc.stdout.toString().trim();
    switch (lsb_release) {
      case 'Arch':
        return 'linux-arch';
      case 'Debian':
        return 'linux-debian';
      case 'Raspbian':
        return 'linux-raspbian';
      case 'Ubuntu':
        return 'linux-ubuntu';
      default:
        return 'linux-unknown';
    }
  } else {
    return 'linux-unknown';
  }
}

as it results in, for example:

lsb_release -i -r
No LSB modules are available.
Distributor ID:	Debian
Release:	12

My hack to fix this has been to do an earlier check if raspi-config exists first:

const raspi = child_process.spawnSync('which', ['raspi-config']);
  if (raspi.status === 0) {
    const raspi_string = raspi.stdout.toString().trim();
    if(raspi_string.indexOf('raspi-config') != -1){
      return 'linux-raspbian';
    }
  }
  
  // Check lsb_release for the name of a Linux distribution
  const proc = child_process.spawnSync('lsb_release', ['-i', '-s']);
  if (proc.status === 0) {
    const lsb_release = proc.stdout.toString().trim();
    switch (lsb_release) {
      case 'Arch':
        return 'linux-arch';
      case 'Debian':
        return 'linux-debian';
      case 'Raspbian':
        return 'linux-raspbian';
      case 'Ubuntu':
        return 'linux-ubuntu';
      default:
        return 'linux-unknown';
    }
  } else {
    return 'linux-unknown';
  }
}

But there might be a more elegant solution. For example, this is one way to find the Raspberry Pi OS version:

cat /etc/os-release

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions