@nexssp/os
02.04.2022 - Added github workflows and now works also with MacOS.
15.01.2022 Upgrade - Now works also with import
as module.
New version 2.x
NOTE: 1.x USERS: Also 1.x Users can still move to this version but they will need to change the way to load @nexssp/os plugin from require("@nexssp/os")
to require("@nexssp/os/legacy")
- NEW: FreeBSD and Gentoo supported.
- NEW: terminal functions eg.
nexssp-os env
nexssp-os get
nexssp-os install nodejs --dry
nexssp-os uninstall nodejs --json
nexssp-os search nodejs
nexssp-os update nodejs
- NEW: Functions
.where()
- finds program and return path. Option to find multiple files at once with --all option - NEW API:
Example
const nexssOS = require('@nexssp/os')
const nexssOS1 = nexssOS()
const result1 = nexssOS1.install(['nodejs'], { dry: true })
const result2 = nexssOS1.uninstall(['nodejs'], { json: true })
nexssOS1.search(['nodejs'])
nexssOS1.update(['nodejs'])
- NEW 1.0.30+ -
os.pathWinToLinux(path)
- converts windows path to linux -> handy with WSL automations (Windows Subsystem for Linux).
Note: This function is used in the Nexss Programmer to implement Crystal Language for Windows through WSL.
Installation
npm i @nexssp/os
Usage
const os = require('@nexssp/os/legacy')
console.log(os.name())
Detect Linux
distro name and version, check if user is root, and some other info. Also works for Windows showing name as Windows
and version like 10.0.19041
Recognize different distros and Windows versions by tags.
Example:
New Tags
console.log(nexssOS1.getTags('Ubuntu', '20.10'))
console.log(nexssOS1.getTags('Ubuntu', 20.1))
console.log(nexssOS1.getTags())
console.log(nexssOS1.getTags('Ubuntu', '20.10').first())
console.log(nexssOS1.getTags('Ubuntu', 20.1).second())
console.log(nexssOS1.getTags().third())
Legacy Tags
console.log('tags(prefix)', os.tags('prFX:'))
console.log('tags(prefix)', os.tags('prFX:'))
New
- Added Amazon Linux AMI distro and package manager setup.
- function
sudo()
which contain sudo where user is not admin and nothing if it is. It helps writing installers so automatically will add sudo if needed and for example docker containers will leave it blank. eg ${sudo()}apt-get install -y somepackage
- function
replacePMByDistro()
which replaces default (apt-get install -y) to the host distribution. For example ${os.replacePMByDistro('apt-get install -y nexss')}
, will on Fedora replace with dnf install, on Ubuntu will not replace it as it is default, on Alpine it will be apk, on Oracle Linux yum install or dns install depends on your linux distribution...
Distros list
module.exports.distros = {
ALPINE: 'Alpine Linux',
AMAZON: 'Amazon Linux',
AMAZON_AMI: 'Amazon Linux AMI',
ARCH: 'Arch Linux',
CENTOS: 'CentOS Linux',
DEBIAN: 'Debian GNU/Linux',
FREEBSD: 'FreeBSD',
FEDORA: 'Fedora',
GENTOO: 'Gentoo',
MINT: 'Linux Mint',
NIXOS: 'NixOS',
ORACLE: 'Oracle Linux Server',
RHEL: 'RHEL Linux',
SUSE_LEAP: 'openSUSE Leap',
SUSE_TUMBLEWEED: 'openSUSE Tumbleweed',
UBUNTU: 'Ubuntu',
WINDOWS: 'Windows',
MACOS: 'MacOS',
}
More Examples
const os = require('@nexssp/os/legacy')
console.log('distrosList', os.distros)
console.log('isRoot: ', os.isRoot())
console.log('name: ', os.name())
console.log('get("name"): ', os.get('NAME'))
console.log('v: ', os.v())
console.log('get("VERSION_ID"): ', os.get('VERSION_ID'))
console.log('get("VERSION_IDxxx"): ', os.get('VERSION_IDxxx'))
console.log('get()', os.get())
console.log('getShell() - your OS Shell', os.getShell())
console.log('getShell(ALPINE)', os.getShell(os.distros.ALPINE))
console.log('getShell(MACOS)', os.getShell(os.distros.MACOS))
console.log('getPM(install):', os.getPM())
console.log('getPM(update):', os.getPM('update'))
console.log('getPM(uninstall):', os.getPM('uninstall'))
console.log('getPM(search):', os.getPM('search'))
console.log('tags(prefix)', os.tags('prFX:'))
console.log(`${os.sudo()}apt-get install -y mypackage`)
console.log(
`Replaces apt install/update/uninstall to the right for distribution: ${os.replacePMByDistro(
'apt-get install -y mypackage'
)}`
)
console.log('getShell() - your OS Shell', os.getShell())
console.log(
`pathWinToLinux("C:\\Users\\mapoart\\testok"):`,
os.pathWinToLinux('C:\\Users\\mapoart\\testok')
)