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);