ChibraxOS 2

Changes:
- kernel 6.0.2
- Broken init scripts
- Switch to bun for better peroformance an easier ffi
- Removed grup
- Efi support without graphics (at least graphics werent tested)
- Suppression de toutes les dépendance non libc
- new splash
- broken audio
- typescript support
- ls rewritten to be more reliable
This commit is contained in:
Marc
2022-10-22 13:47:33 +02:00
parent db49f8d205
commit 721c919c7b
76 changed files with 2485 additions and 2665 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
const fs = require('fs');
import * as fs from 'fs'
if(process.argv.length >= 3){
try{
@@ -15,4 +15,4 @@ if(process.argv.length >= 3){
}
}
}
}
+3 -4
View File
@@ -1,7 +1,6 @@
//@ts-check
const graphics = require('../../core/graphics')
const shapes = require('../lib/shapes')
const path = require('path')
import * as graphics from '../../core/graphics'
import * as shapes from '../lib/shapes'
graphics.clear()
drawChibrax()
@@ -141,4 +140,4 @@ function drawChibrax() {
}
}
}
}
@@ -1,5 +1,5 @@
//@ts-check
const ip = require('../../core/ip')
const ip = require('../../core/ip.js.bak')
const fs = require('fs')
const { exit } = require('process')
@@ -70,4 +70,4 @@ if(flags & ip.flags.IFF_SLAVE) {
if(flags & ip.flags.IFF_UP) {
flagsStr += 'IFF_SLAVE\n'
}
console.log(flagsStr)
console.log(flagsStr)
@@ -1,5 +1,5 @@
//@ts-check
const ip = require('../../core/ip')
const ip = require('../../core/ip.js.bak')
const fs = require('fs')
const { exit } = require('process')
-129
View File
@@ -1,129 +0,0 @@
const fs = require('fs')
let paths = []
let options = []
for(arg of process.argv.slice(3)){
if(arg.startsWith('--')){
options.push(arg)
}
else if(arg.startsWith('-')){
for(let option of arg.slice(1)){
options.push('-' + option);
}
}
else{
paths.push(arg)
}
}
if(paths.length == 0){
paths = ['.'];
}
try{
listFiles(paths[0], options)
}
catch(e){
switch(e.code){
case "ENOENT":
console.error(`path "${paths[0]}" does not exist`);
break;
default:
console.error(`ls: ${e.code}`)
}
}
function listFiles(path, options){
const files = ['.', '..'].concat(fs.readdirSync(paths[0]))
const nonHiddenFiles = files.filter(file => file[0] != '.')
colorList = JSON.parse(process.env.ls_color)
if(options.includes('-l')){
console.log(`total ${options.includes('-a') ? files.length : nonHiddenFiles.length}`)
for(let file of options.includes('-a') ? files : nonHiddenFiles){
stats = fs.lstatSync(`${path}/${file}`);
mode = stats.mode
result = ""
let color = []
let defaultColor = "\x1b[0m"
let fileType = "-"
if(stats.isFile()){
fileType = "-";
if(stats.mode & 00100){ //owner can execute
color = colorList.ex ? `\x1b[${colorList.ex[0]}m\x1b[${colorList.ex[1]}m` : "\x1b[0m"
}
}
else if (stats.isDirectory()) {
fileType = "d";
color = colorList.di ? `\x1b[${colorList.di[0]}m\x1b[${colorList.di[1]}m` : "\x1b[0m"
}
else if (stats.isSymbolicLink()){
fileType = "l"
color = colorList.ln ? `\x1b[${colorList.ln[0]}m\x1b[${colorList.ln[1]}m` : "\x1b[0m"
}
result += fileType;
permissions = "xwr"
for(let i=8;i>=0;i--){
result += parseInt(Math.pow(2,i).toString(2)) & mode ? permissions[i%3] : '-'
}
if(01000 & mode){ // check sticky bit
color = "\x1b[40m\x1b[92m\x1b[7m"
}
let date = new Date(stats.mtimeMs*1000).toDateString().split(' ');
result += ` ${usernameFromUID(stats.uid)}\t${groupnameFromGID(stats.gid)}\t${stats.size}\t${date[2]} ${date[1]}. ${options.includes('--color') ? color : ""}${file}${defaultColor}`
console.log(result)
}
}
else{
result = ""
const defaultColor = "\x1b[0m";
if(options.includes('--color')){
for(let file of options.includes('-a') ? files : nonHiddenFiles){
stats = fs.lstatSync(`${path}/${file}`);
let color = defaultColor
if(stats.isDirectory()){
color = colorList.di ? `\x1b[${colorList.di[1]}m\x1b[${colorList.di[0]}m` : defaultColor
}
else if (stats.isSymbolicLink()){
color = colorList.ln ? `\x1b[${colorList.ln[1]}m\x1b[${colorList.ln[0]}m` : defaultColor
}
if(01000 & stats.mode){ // check sticky bit
color = "\x1b[40m\x1b[92m\x1b[7m"
}
result += color + file + defaultColor + " ";
}
console.log(result)
}else{
console.log(options.includes('-a') ? files.join(' ') : nonHiddenFiles.join(' '))
}
}
}
function usernameFromUID(uid){
const passwd = fs.readFileSync("/etc/passwd", {encoding: 'utf-8'}).split('\n');
for(let line of passwd){
let lineSplited = line.split(':')
if(lineSplited[2] == uid){
return lineSplited[0];
}
}
return uid
}
function groupnameFromGID(uid){
const passwd = fs.readFileSync("/etc/passwd", {encoding: 'utf-8'}).split('\n');
for(let line of passwd){
let lineSplited = line.split(':')
if(lineSplited[3] == uid){
return lineSplited[0];
}
}
return uid
}
+144
View File
@@ -0,0 +1,144 @@
'strict'
import { file } from 'bun'
import * as fs from 'fs'
import * as path from 'path'
let paths: string[] = []
let options = []
const defaultColors = {
di: [1, 34],
ln: [1, 36],
ex: [1, 32]
}
for(const arg of process.argv.slice(3)){
if(arg.startsWith('--')){
options.push(arg)
}
else if(arg.startsWith('-')){
for(let option of arg.slice(1)){
options.push('-' + option);
}
}
else{
paths.push(arg)
}
}
if(paths.length == 0){
paths = [ process.cwd() ];
}
try{
listFiles(paths[0], options)
}
catch(e){
switch(e.code){
case 'ENOENT':
console.error(`path '${paths[0]}' does not exist`);
break;
default:
console.error(`ls: ${e}`)
}
}
function listFiles(directory: string, options: string[]){
if(!fs.existsSync(directory)) {
console.error('Path not found')
return;
}
let files = ['.', '..', ...fs.readdirSync(paths[0])]
if(!options.includes('-a')) {
files = files.filter(file => !file.startsWith('.') || file === '.' || file === '..')
}
let colorList: typeof defaultColors
if(process.env.ls_color) {
colorList = { ...defaultColors, ...JSON.parse(process.env.ls_color)}
} else {
colorList = defaultColors
}
if(options.includes('-l')){
console.log(`total ${file.length}`)
for(let file of files){
let result = ''
const stats = fs.lstatSync(path.join(directory, file));
let color = ''
let defaultColor = '\x1b[0m'
let fileType = '?'
if(stats.isFile()){
fileType = '-';
if(stats.mode & 0o100){ //owner can execute
color = colorList.ex ? `\x1b[${colorList.ex[0]}m\x1b[${colorList.ex[1]}m` : '\x1b[0m'
}
}
else if (stats.isDirectory()) {
fileType = 'd';
color = colorList.di ? `\x1b[${colorList.di[0]}m\x1b[${colorList.di[1]}m` : '\x1b[0m'
}
else if (stats.isSymbolicLink()){
fileType = 'l'
color = colorList.ln ? `\x1b[${colorList.ln[0]}m\x1b[${colorList.ln[1]}m` : '\x1b[0m'
}
result += fileType;
const permissions = 'xwr'
for(let i=8;i>=0;i--){
result += parseInt(Math.pow(2,i).toString(2)) & stats.mode ? permissions[i%3] : '-'
}
if(0o1000 & stats.mode){ // check sticky bit
color = '\x1b[40m\x1b[92m\x1b[7m'
}
const date = stats.mtime.toDateString().split(' ');
result += ` ${usernameFromUID(stats.uid)}\t${groupnameFromGID(stats.gid)}\t${stats.size}\t${date[2]} ${date[1]}. ${options.includes('--color') ? color : ''}${file}${defaultColor}`
console.log(result)
}
}
else{
const defaultColor = '\x1b[0m';
if(options.includes('--color')){
let result = ''
for(let file of files){
const stats = fs.lstatSync(path.join(directory, file));
let color = defaultColor
if(0o1000 & stats.mode){ // check sticky bit
color = '\x1b[40m\x1b[92m\x1b[7m'
} else if(stats.isDirectory()){
color = colorList.di ? `\x1b[${colorList.di[1]}m\x1b[${colorList.di[0]}m` : defaultColor
} else if (stats.isSymbolicLink()){
color = colorList.ln ? `\x1b[${colorList.ln[1]}m\x1b[${colorList.ln[0]}m` : defaultColor
}
result += color + file + ' ' + defaultColor;
}
console.log(result)
}else{
console.log(files.join(' '))
}
}
}
function usernameFromUID(uid: string | number){
if(uid == 0) return 'root'
if(uid != 0) return 'unknown user'
//TODO: add support for multiple users to the os
return uid
}
function groupnameFromGID(uid: string | number){
if(uid == 0) return 'root'
if(uid != 0) return 'unknown group'
//TODO: add support for multiple groups to the os
return uid
}
+2 -2
View File
@@ -1,3 +1,3 @@
const { lsmod } = require('/chibrax/kernel.js')
import { lsmod } from '../../core/kernel'
console.log(lsmod())
console.log(lsmod())
+3 -2
View File
@@ -1,6 +1,7 @@
const fs = require('fs')
import * as fs from 'fs'
if(process.argv.length >= 3){
fs.mkdir(process.argv[3], { recursive: true }, (err) => {
if (err) throw err;
});
}
}
+3 -3
View File
@@ -1,7 +1,7 @@
//@ts-check
const { finit_module, uname } = require('../../core/kernel.js')
const fs = require('fs')
const path = require('path')
import { finit_module, uname } from '../../core/kernel.js'
import * as fs from 'fs'
import * as path from 'path'
const name = uname()
const modulePath = path.join('/lib/modules', name, 'kernel')
+2 -2
View File
@@ -1,4 +1,4 @@
const fs = require('fs')
import * as fs from 'fs'
if(process.argv.length >= 3){
let filesToRemove = process.argv.slice(3).filter((arg) => !arg.startsWith('-'));
@@ -22,4 +22,4 @@ if(process.argv.length >= 3){
}
}
}
}
+28 -16
View File
@@ -1,10 +1,11 @@
//@ts-check
const { Lexer } = require('../lib/sheebr/lexer')
const { getline } = require('../lib/sheebr/utils')
const fs = require('fs')
let environment = require('../lib/sheebr/environment')
let aliases = require("../lib/sheebr/aliases")
const { startjs } = require('../../core/hook')
import { startjs } from '../../core/hook'
import Lexer from '../lib/sheebr/lexer'
import * as fs from 'fs'
import environment from '../lib/sheebr/environment'
import aliases from '../lib/sheebr/aliases'
import * as path from 'path'
let current_dir = process.cwd()
@@ -12,9 +13,13 @@ start()
async function start(){
while(true){
const input = await getline("sheebr> ");
const input = prompt("sheebr> ");
if(input === "exit") break;
if(!input) continue;
if(!input) {
//work around missing line break
console.log()
continue
}
else await evaluate(input);
}
}
@@ -61,23 +66,30 @@ async function evaluate(input){
* @param {string[]} args
*/
async function evaluateProgram(args){
let found = false;
for(let path of environment.path.split(':')){
for(const envPath of environment.path.split(':')){
let tobreak = false;
const files = fs.readdirSync(path);
if(files.includes(`${args[0]}.js`)){
if(!fs.existsSync(envPath)) continue
const jsPath = path.join(envPath, `${args[0]}.js`)
const tsPath = path.join(envPath, `${args[0]}.ts`)
console.log(jsPath, tsPath, envPath)
if(fs.existsSync(jsPath) || fs.existsSync(tsPath) ){
found = true;
console.log('found it: ' + path + args[0])
try {
const cmd = `${path + '/' + args[0]}.js`
const cmd = fs.existsSync(jsPath) ? jsPath : tsPath
const options = {cwd: current_dir, env: environment, shell: true}
console.log(args)
await startjs(cmd, args, options)
tobreak = true;
console.log('\x1b[0m')
tobreak = true
} catch(e) {
console.log("Program crashed")
}
}
if(tobreak) break;
}
if(!found){
@@ -114,4 +126,4 @@ function evaluateAliases(args){
return aliases[args[0]].concat(args.slice(1))
}
return args;
}
}
+3 -2
View File
@@ -1,4 +1,5 @@
const fs = require('fs')
import * as fs from 'fs'
if(process.argv.length >= 3){
try{
fs.openSync(process.argv[3], 'w');
@@ -6,4 +7,4 @@ if(process.argv.length >= 3){
catch(e){
console.error(e.code + '\n' + e.message);
}
}
}
+3 -3
View File
@@ -1,5 +1,5 @@
const fs = require('fs');
const { resolve } = require('path');
import * as fs from 'fs'
import { resolve } from 'path';
if(process.argv.length >= 3){
// console.log(process.env.path)
@@ -20,4 +20,4 @@ function recursiveSearch(dir, bin){
result = result.concat(recursiveSearch(dirent.name, bin))
}
return result;
}
}
+3 -2
View File
@@ -1,2 +1,3 @@
let os = require('os')
console.log(os.userInfo().username);
import { userInfo } from 'os'
console.log(userInfo().username);
+7 -10
View File
@@ -3,7 +3,7 @@
* DICKPICK is a image drawing library
*/
const graphics = require('../../core/graphics')
import * as graphics from '../../core/graphics'
/**
* @param { number } x
@@ -12,7 +12,7 @@ const graphics = require('../../core/graphics')
* @param { number } dy length on the y axis
* @param { string } color
*/
function drawRect(x, y, dx, dy, color) {
export function drawRect(x, y, dx, dy, color) {
const bitmap = {
data: Buffer.alloc(dx*dy*4, Buffer.from(graphics.parseHexColor(color))),
width: dx,
@@ -28,7 +28,7 @@ function drawRect(x, y, dx, dy, color) {
* @param { number[] } color
* @returns { Pencil }
*/
function pencilFromBitmap(Bitmap, color) {
export function pencilFromBitmap(Bitmap, color) {
return { ...Bitmap, color }
}
@@ -37,7 +37,7 @@ function pencilFromBitmap(Bitmap, color) {
* @param { number } height
* @returns
*/
function createBitmap(width, height) {
export function createBitmap(width, height) {
const data = Buffer.alloc(width * height * 4, Buffer.from([0, 0, 0, 0]));
return { width, height, data }
}
@@ -47,7 +47,7 @@ function createBitmap(width, height) {
* @param { number } x
* @param { number } y
*/
function setPixel(pencil, x, y) {
export function setPixel(pencil, x, y) {
pencil.data.set(pencil.color, y*pencil.width*4 + x*4)
}
@@ -60,7 +60,7 @@ function setPixel(pencil, x, y) {
* @param { number } yc
* @param { Pencil } pencil
*/
function symetrie8Axes(xc, yc, x, y, pencil) {
export function symetrie8Axes(xc, yc, x, y, pencil) {
setPixel(pencil, x+xc, y+yc)
setPixel(pencil, x+xc,-y+yc)
setPixel(pencil, -x+xc,-y+yc)
@@ -78,7 +78,7 @@ function symetrie8Axes(xc, yc, x, y, pencil) {
* @param { number } yc
* @param { number } r
*/
function drawCircle(pencil, xc, yc, r) {
export function drawCircle(pencil, xc, yc, r) {
let x = 0
let y = r
let d = 3 - (2 * r);
@@ -96,6 +96,3 @@ function drawCircle(pencil, xc, yc, r) {
symetrie8Axes(xc, yc, x, y, pencil);
}
}
module.exports = { drawRect, setPixel, pencilFromBitmap, createBitmap, drawCircle }
+1 -3
View File
@@ -2,8 +2,6 @@
/**
* @type {{ [key: string]: string[] }}
*/
const aliases = {
export default {
ls: ["ls", "--color"]
}
module.exports = aliases
@@ -11,4 +11,4 @@ let environment = {
}),
}
module.exports = environment
export default environment
+1 -8
View File
@@ -1,8 +1,6 @@
//@ts-check
const { isAlpha } = require('./utils')
class Lexer{
export default class Lexer{
/**
* @param { string } source
*/
@@ -55,8 +53,3 @@ class Lexer{
// this.tokens.push(Token(tokenType, value))
//}
}
module.exports = {
Lexer
}
@@ -8,6 +8,12 @@
'use strict';
import * as crypto from 'crypto'
import { tmpdir } from 'os';
import * as fs from 'fs'
import * as childProc from 'child_process'
import * as pathUtil from 'path'
var
IS_WIN = process.platform === 'win32',
@@ -15,10 +21,7 @@ var
ALGORITHM_HASH = 'sha256',
DEFAULT_ERR_MSG = 'The current environment doesn\'t support interactive reading from TTY.',
fs = require('fs'),
TTY = process.binding('tty_wrap').TTY,
childProc = require('child_process'),
pathUtil = require('path'),
defaultOptions = {
/* eslint-disable key-spacing */
@@ -91,7 +94,7 @@ function _execFileSync(options, execOptions) {
function getTempfile(name) {
var suffix = '',
filepath, fd;
tempdir = tempdir || require('os').tmpdir();
tempdir = tempdir || tmpdir();
while (true) {
filepath = pathUtil.join(tempdir, name + suffix);
@@ -116,7 +119,6 @@ function _execFileSync(options, execOptions) {
pathStderr = getTempfile('readline-sync.stderr'),
pathExit = getTempfile('readline-sync.exit'),
pathDone = getTempfile('readline-sync.done'),
crypto = require('crypto'),
hostArgs, shellPath, shellArgs, exitCode, extMessage, shasum, decipher, password;
shasum = crypto.createHash(ALGORITHM_HASH);
+1 -33
View File
@@ -1,41 +1,9 @@
//@ts-check
/**
* @param {string} str
* @returns { Promise<string> }
*/
async function getline(str) {
process.stdout.write(str)
process.stdin.resume()
process.stdin.setEncoding('utf8')
let line = ""
return new Promise((res, rej) => {
process.stdin.on('data', function(chunk) {
line += chunk
if (chunk.toString('utf-8').endsWith('\n')) {
process.stdin.pause()
res(line.substring(0, line.length -1))
}
})
process.stdin.on('error', function(err) {
rej(err)
})
})
}
/**
* @param { string } str
* @returns
*/
function isAlpha(str){
export function isAlpha(str){
return /^[a-zA-Z]*$/.test(str)
}
module.exports = {
isAlpha, getline
}