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
View File
@@ -8,3 +8,5 @@ diskoffset
package-lock.json package-lock.json
build build
node_modules node_modules
ovmf_vars.fd
bun.lockb
+5 -1
View File
@@ -2,6 +2,9 @@
"python.linting.enabled": false, "python.linting.enabled": false,
"files.associations": { "files.associations": {
"*.ejs": "html", "*.ejs": "html",
"*.rmd": "markdown",
"*.vue": "vue",
"*.h": "c",
"*.inc": "cpp", "*.inc": "cpp",
"internet": "cpp", "internet": "cpp",
"socket": "cpp", "socket": "cpp",
@@ -93,6 +96,7 @@
"ios": "cpp", "ios": "cpp",
"locale": "cpp", "locale": "cpp",
"queue": "cpp", "queue": "cpp",
"stack": "cpp" "stack": "cpp",
"export": "c"
}, },
} }
-32
View File
@@ -1,32 +0,0 @@
{
"targets": [
{
"target_name": "syscall",
'cflags': [ '-Wall' ],
"sources": [
"clibs/syscall.cc"
]
},
{
"target_name": "ioctl",
'cflags': [ '-Wall' ],
"sources": [
"clibs/ioctl.cc"
]
},
{
"target_name": "mount",
'cflags': [ '-Wall' ],
"sources": [
"clibs/mount.cc"
]
},
{
"target_name": "ip",
'cflags': [ '-Wall', '-Wextra' ],
"sources": [
"clibs/ip.cc"
]
}
]
}
+13 -46
View File
@@ -1,4 +1,4 @@
#!./bash-static #!/bin/bash
if [ "$EUID" = 0 ] if [ "$EUID" = 0 ]
then echo "Please don't run this as root" then echo "Please don't run this as root"
@@ -64,8 +64,6 @@ sudo rm chibrax.tar.gz 2> /dev/null
makeroot libfs || exit 1 makeroot libfs || exit 1
makeroot rootfs || exit 1 makeroot rootfs || exit 1
npm i
cd rootfs/usr cd rootfs/usr
ln -s lib lib64 ln -s lib lib64
cd - cd -
@@ -77,40 +75,17 @@ chmod +x ./libc/build.sh
cd libc && ./build.sh > /dev/null || exit 1 && cd - cd libc && ./build.sh > /dev/null || exit 1 && cd -
echo "done" echo "done"
echo "construction de gcc" echo "Téléchargement de Bun"
chmod +x ./libgcc/build.sh cd bun && ./build.sh && cd -
cd libgcc && ./build.sh > /dev/null || exit 1 && cd - cp bun/bun-linux-x64/bun rootfs/usr/bin/bun
echo "done" echo "done"
echo "construction de eudev" bun/bun-linux-x64/bun install
chmod +x ./libudev/build.sh
cd libudev && ./build.sh > /dev/null || exit 1 && cd -
echo "done"
echo "construction de lvm2(libdemapper)"
chmod +x ./lvm2/build.sh
cd lvm2 && ./build.sh > /dev/null || exit 1 && cd -
echo "done"
echo "construction de liblzma"
chmod +x ./liblzma/build.sh
cd liblzma && ./build.sh > /dev/null || exit 1 && cd -
echo "done"
echo "construction de grub"
chmod +x ./grub/build.sh
cd grub && ./build.sh > /dev/null || exit 1 && cd -
echo "done"
echo "construction de Nodejs"
chmod +x ./nodejs/build.sh
cd nodejs && ./build.sh || exit 1 && cd -
echo "done"
echo "construction du loader" echo "construction du loader"
chmod +x ./osLoader/build.sh chmod +x ./osLoader/build.sh
cd osLoader && ./build.sh && cd - cd osLoader && ./build.sh && cd -
sudo cp osLoader/init rootfs/usr/sbin/ || exit 1 cp osLoader/init rootfs/usr/sbin/ || exit 1
echo "done" echo "done"
echo "construction du bypass de sh" echo "construction du bypass de sh"
@@ -119,7 +94,7 @@ cd fakesh && ./build.sh && cd -
echo "done" echo "done"
echo "construction du kernel" echo "construction du kernel"
cd kernel && ./from_current.sh > /dev/null && cd - cd kernel && ./from_current.sh && cd -
echo "done" echo "done"
echo "Cloning the firmware" echo "Cloning the firmware"
@@ -130,24 +105,16 @@ sudo mkdir -p rootfs/usr/lib/firmware || exit 1
sudo cp linux-firmware/* rootfs/usr/lib/firmware/ -r || exit 1 sudo cp linux-firmware/* rootfs/usr/lib/firmware/ -r || exit 1
echo "done" echo "done"
echo "rebuilding C++ hooks" cp libfs/usr/lib/libc.so.6 rootfs/usr/lib/
./clibs.sh > /dev/null || exit 1 cp libfs/usr/lib/libdl.so.2 rootfs/usr/lib/
echo "done"
cp libfs/usr/lib64/libstdc++.so.6.0.29 rootfs/usr/lib/
cd rootfs/usr/lib/ && ln -s libstdc++.so.6.0.29 libstdc++.so.6 && ln -s libstdc++.so.6.0.29 libstdc++.so && cd -
cp libfs/usr/lib/libm.so.6 rootfs/usr/lib/ cp libfs/usr/lib/libm.so.6 rootfs/usr/lib/
cp libfs/usr/lib/ld-linux-x86-64.so.2 rootfs/usr/lib cp libfs/usr/lib/libpthread.so.0 rootfs/usr/lib/
cp libfs/usr/lib/libgcc_s.so* rootfs/usr/lib cp libfs/usr/lib64/ld-linux-x86-64.so.2 rootfs/usr/lib64/
cp libfs/usr/lib/libc.so.6 rootfs/usr/lib
cp libfs/usr/lib/liblzma.so.5.0.4 rootfs/usr/lib
cd rootfs/usr/lib/ && ln -s liblzma.so.5.0.4 liblzma.so.5 && ln -s liblzma.so.5.0.4 liblzma.so && cd -
cp libfs/usr/lib/libdevmapper.so.1.02 rootfs/usr/lib
cd rootfs/usr/lib/ && ln -s libdevmapper.so.1.02 libdevmapper.so && cd -
cp libfs/sbin/ldconfig rootfs/sbin
sudo cp rootfs\ overrides/* rootfs/ -r || exit 1 sudo cp rootfs\ overrides/* rootfs/ -r || exit 1
unset LD_LIBRARY_PATH unset LD_LIBRARY_PATH
sudo chown root rootfs -R
#`libtool --finish /usr/lib #`libtool --finish /usr/lib
+2
View File
@@ -0,0 +1,2 @@
bun-linux-x64
*.zip
Executable
+12
View File
@@ -0,0 +1,12 @@
# bun compilation is still very iffy so we use the precompiled binaries for now
VER=0.2.1
if [ ! -f bun-linux-x64-baseline$VER.zip ]
then
wget https://github.com/oven-sh/bun/releases/download/bun-v$VER/bun-linux-x64-baseline.zip
unzip bun-linux-x64-baseline.zip
mv bun-linux-x64-baseline.zip bun-linux-x64-baseline$VER.zip
mv bun-linux-x64-baseline bun-linux-x64
fi
-16
View File
@@ -1,16 +0,0 @@
#!/bin/bash
echo "building node-c hooks"
node node_modules/node-gyp/bin/node-gyp.js configure
node node_modules/node-gyp/bin/node-gyp.js build
echo " syscall"
cp build/Release/syscall.node rootfs\ overrides/core/syscall.node
echo " ioctl"
cp build/Release/ioctl.node rootfs\ overrides/core/ioctl.node
echo " mount"
cp build/Release/mount.node rootfs\ overrides/core/mount.node
echo " ip"
cp build/Release/ip.node rootfs\ overrides/core/ip.node
echo "done"
-40
View File
@@ -1,40 +0,0 @@
#include <sys/ioctl.h>
#include <unistd.h>
#include <node.h>
#include <fcntl.h>
#include <string>
#define nodeparam v8::FunctionCallbackInfo<v8::Value>
namespace ioctlNode {
void nodeIoctl(const nodeparam& args) {
v8::Isolate* isolate = args.GetIsolate();
if (args.Length() < 2 || !args[0]->IsUint32() || !args[1]->IsUint32()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Argument 1& 2 must be a number").ToLocalChecked()));
return;
}
u_int32_t fd = args[0].As<v8::Number>()->Value();
unsigned long request = args[1].As<v8::Number>()->Value();
int params[args.Length() - 2];
for(int i = 1 ; i < args.Length(); i++ ) {
if (!args[i]->IsNumber()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Argument must be a number").ToLocalChecked()));
return;
}
params[i - 1] = args[i].As<v8::Number>()->Value();
}
args.GetReturnValue().Set(ioctl(fd, request, &params));
close(fd);
}
void Initialize(v8::Local<v8::Object> exports) {
NODE_SET_METHOD(exports, "ioctl", nodeIoctl);
}
NODE_MODULE(ioctl_api, Initialize)
}
-112
View File
@@ -1,112 +0,0 @@
#include "nodeparams.hpp"
#include <iostream>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/route.h>
#include <linux/sockios.h>
#include <unistd.h>
#include <node.h>
#include <errno.h>
const int inet_sock_fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0);
namespace ipNode {
int setflags(const char* iface, short flags) {
struct ifreq ifr;
ifr.ifr_flags = flags;
strncpy(ifr.ifr_name, iface, IFNAMSIZ);
return ioctl(inet_sock_fd, SIOCSIFFLAGS, &ifr);
}
int getIfreq(struct ifreq *ifr ) {
return ioctl(inet_sock_fd, SIOCGIFFLAGS, ifr);
}
void nodeGetFlags(const nodeparam& args) {
v8::Isolate* isolate = args.GetIsolate();
if (args.Length() < 1 || !args[0]->IsString()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Invalid arguments ip.getflags").ToLocalChecked()));
return;
}
std::string iface = argToString(args[0]);
struct ifreq ifr;
strncpy(ifr.ifr_name, iface.c_str(), IFNAMSIZ);
int err = getIfreq(&ifr);
if(err != 0) {
char errstr[36];
sprintf(errstr, "Error while getting flags %d", errno);
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, errstr).ToLocalChecked()));
}
args.GetReturnValue().Set(ifr.ifr_flags);
}
void nodeSetIpv4(const nodeparam& args) {
v8::Isolate* isolate = args.GetIsolate();
if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsString()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Invalid arguments ip.setIpv4").ToLocalChecked()));
return;
}
const std::string iface = argToString(args[0]);;
const std::string ip = argToString(args[1]);
struct ifreq ifr;
struct sockaddr_in sai;
strncpy(ifr.ifr_name, iface.c_str(), IFNAMSIZ);
memset(&sai, 0, sizeof(struct sockaddr));
sai.sin_family = AF_INET;
sai.sin_port = 0;
sai.sin_addr.s_addr = inet_addr(ip.c_str());
memcpy( &ifr.ifr_ifru, &sai, sizeof(struct sockaddr));
int err = ioctl(inet_sock_fd, SIOCSIFADDR, &ifr);
if(err != 0) {
char errstr[36];
sprintf(errstr, "Error while getting flags %d", errno);
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, errstr).ToLocalChecked()));
}
args.GetReturnValue().Set(ifr.ifr_flags);
}
void nodeSetFlags(const nodeparam& args) {
v8::Isolate* isolate = args.GetIsolate();
if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsUint32()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Invalid arguments ip.srtFlags").ToLocalChecked()));
return;
}
short flags = (short) argToInt(args[1]);
std::string path = argToString(args[0]);
args.GetReturnValue().Set(setflags(path.c_str(), flags));
}
void Initialize(v8::Local<v8::Object> exports) {
NODE_SET_METHOD(exports, "setFlags", nodeSetFlags);
NODE_SET_METHOD(exports, "getFlags", nodeGetFlags);
NODE_SET_METHOD(exports, "setIpv4", nodeSetIpv4);
}
NODE_MODULE(ip_api, Initialize)
}
-64
View File
@@ -1,64 +0,0 @@
#include <sys/mount.h>
#include <unistd.h>
#include <node.h>
namespace mountNode {
void nodemount(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
if (!args[0]->IsString()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "First argument must be a string pointing to a device").ToLocalChecked()));
return;
}
if (!args[1]->IsString()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Argument must be a string pointing to a folder").ToLocalChecked()));
return;
}
if (!args[2]->IsString()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Argument must be a filesystem name").ToLocalChecked()));
return;
}
if (!args[3]->IsNumber()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Argument must be a number made from the mount flags").ToLocalChecked()));
return;
}
if (!args[4]->IsString()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Argument must be a string").ToLocalChecked()));
return;
}
v8::String::Utf8Value devpathV8(isolate, args[0]);
std::string devpath(*devpathV8);
v8::String::Utf8Value mountPointV8(isolate, args[1]);
std::string mountPoint(*mountPointV8);
v8::String::Utf8Value fsTypeV8(isolate, args[2]);
std::string fsType(*fsTypeV8);
unsigned long rwFlags = args[3].As<v8::Number>()->Value();
//comma separated parameters passed directly into the fs driver
v8::String::Utf8Value fsFlagsV8(isolate, args[4]);
std::string fsFlags(*fsFlagsV8);
const int returnValue = mount(devpath.c_str(), mountPoint.c_str(), fsType.c_str(), rwFlags, fsFlags.c_str());
args.GetReturnValue().Set(returnValue);
}
void Initialize(v8::Local<v8::Object> exports) {
NODE_SET_METHOD(exports, "mount", nodemount);
}
NODE_MODULE(mount_api, Initialize)
}
-7
View File
@@ -1,7 +0,0 @@
#include <string>
#include <v8.h>
#define nodeparam v8::FunctionCallbackInfo<v8::Value>
#define argToInt(arg) arg.As<v8::Number>()->Value()
#define argToString(arg) std::string(*v8::String::Utf8Value(isolate, arg))
-91
View File
@@ -1,91 +0,0 @@
#include <sys/syscall.h> /* Definition of SYS_* constants */
#include <sys/reboot.h>
#include <unistd.h>
#include <node.h>
#include <errno.h>
#include <list>
#define returnjs(val) args.GetReturnValue().Set(val);
namespace syscallNode {
void freeList(std::list<std::string *> &list) {
std::list<std::string *>::iterator it = list.begin();
for(; it != list.end(); it++) {
delete *it;
}
}
void nodeSyscall(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
std::list<std::string *> memoryToClean;
//les registres rdi, rsi, rdx ...
long int registers[args.Length()];
for(int i=0; i < args.Length(); i++) {
if(args[i]->IsNumber()) {
registers[i] = args[i].As<v8::Number>()->Value();
} else if(args[i]->IsString()) {
v8::String::Utf8Value argv8(isolate, args[i]);
std::string *argStr = new std::string(*argv8);
//un pointer c'est un u_int32_t donc sa deverais passer
registers[i] = (long int)argStr->c_str();
memoryToClean.push_front(argStr);
} else {
freeList(memoryToClean);
//respond -1 is something went wrong
returnjs(-1);
return;
}
}
long int syscallReturnValue;
switch(memoryToClean.size()) {
case 1:
syscallReturnValue = syscall(registers[0]);
return;
case 2:
syscallReturnValue = syscall(registers[0], registers[1]);
return;
case 3:
syscallReturnValue = syscall(registers[0], registers[1], registers[2]);
return;
case 4:
syscallReturnValue = syscall(registers[0], registers[1], registers[2], registers[3]);
return;
case 5:
syscallReturnValue = syscall(registers[0], registers[1], registers[2], registers[3], registers[4]);
return;
default:
//unsuported length
returnjs(-2);
return;
}
freeList(memoryToClean);
if(syscallReturnValue == -1) {
returnjs(errno);
}
}
void nodeReboot(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
if (!args[0]->IsNumber()) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Argument must be a number").ToLocalChecked()));
return;
}
long argsValue = args[0].As<v8::Number>()->Value();
reboot(argsValue);
}
void Initialize(v8::Local<v8::Object> exports) {
NODE_SET_METHOD(exports, "reboot", nodeReboot);
NODE_SET_METHOD(exports, "syscall", nodeSyscall);
}
NODE_MODULE(syscall_api, Initialize)
}
+34 -41
View File
@@ -12,6 +12,7 @@ then
fi fi
CHIBRAX_MOUNT_POINT="/tmp/core" CHIBRAX_MOUNT_POINT="/tmp/core"
EFI_MOUNT_POINT="/tmp/efi"
rm -f disk.img rm -f disk.img
@@ -21,63 +22,55 @@ do
done done
#create a 8Gb iso #create a 8Gb iso
dd if=/dev/zero of=disk.img bs=1024k seek=$((1000 * 2)) count=0 dd if=/dev/zero of=disk.img bs=1024k seek=$((1000 * 8)) count=0
HEADER_SIZE=2048
EFI_SIZE=512
EFI_SECTOR_LIMIT=997376
ROOT_SECTOR_LIMIT=15382528
SECTOR_SIZE=512
HEADER_OFFSET=$(($HEADER_SIZE * $SECTOR_SIZE))
ROOT_OFFSET=$(( ($EFI_SECTOR_LIMIT + $HEADER_SIZE ) * $SECTOR_SIZE ))
#creating a msdos image for mbr boot #creating a msdos image for mbr boot
parted disk.img mklabel msdos parted disk.img mklabel gpt
parted disk.img mkpart primary ext4 0% 100% echo "parted disk.img mkpart ext4 0% ${EFI_SIZE}M"
parted disk.img mkpart efi 0% ${EFI_SIZE}MB
parted disk.img mkpart root ${EFI_SIZE}MB 100%
##EFI
#parted disk.img name 1 root #parted disk.img name 1 root
START_SECTOR=$(file disk.img | cut -d',' -f 8 | cut -d' ' -f3) START_SECTOR=$(file disk.img | cut -d',' -f 8 | cut -d' ' -f3)
echo "Start sector :" $START_SECTOR echo "Start sector :" $START_SECTOR
OFFSET=$((512*$START_SECTOR))
echo $OFFSET > diskoffset losetup --offset $HEADER_OFFSET -f disk.img
EFI_LOOP=$(losetup -a | grep -v deleted | grep disk.img | grep $HEADER_OFFSET | cut -d':' -f 1)
mkfs.fat -F 32 ${EFI_LOOP}
losetup --offset $OFFSET -f disk.img echo "EFI LOOP: $EFI_LOOP"
LOOP=$(losetup -a | grep -v deleted | grep disk.img | cut -d':' -f 1)
losetup -f disk.img mkdir -p $EFI_MOUNT_POINT
LOOP_ROOT=$(losetup -a | grep -v deleted | grep -v ${LOOP} | cut -d':' -f 1) mount ${EFI_LOOP} $EFI_MOUNT_POINT
echo $ROOT_SECTOR_LIMIT
losetup --offset $ROOT_OFFSET -f disk.img --sizelimit $(($ROOT_SECTOR_LIMIT * 512))
ROOT_LOOP=$(losetup -a | grep -v deleted | grep disk.img | grep $ROOT_OFFSET | grep -v $EFI_LOOP | cut -d':' -f 1)
mkfs.ext4 ${ROOT_LOOP}
echo "ROOT LOOP: $ROOT_LOOP"
mkdir $CHIBRAX_MOUNT_POINT -p mkdir $CHIBRAX_MOUNT_POINT -p
mount ${ROOT_LOOP} $CHIBRAX_MOUNT_POINT
mkfs.ext4 ${LOOP}
mount ${LOOP} $CHIBRAX_MOUNT_POINT
echo "rebuilding C++ hooks"
./clibs.sh > /dev/null 2> /dev/null
echo "done"
echo "coping rootfs" echo "coping rootfs"
cp rootfs/* $CHIBRAX_MOUNT_POINT -r cp rootfs/* $CHIBRAX_MOUNT_POINT -r
echo "done" echo "done"
echo "installing grub" cp kernel/src/arch/x86/boot/bzImage $EFI_MOUNT_POINT/bzImage.efi
mount --rbind /dev $CHIBRAX_MOUNT_POINT/dev
mount --make-rslave $CHIBRAX_MOUNT_POINT/dev
mount -t proc /proc $CHIBRAX_MOUNT_POINT/proc
mount --rbind /sys $CHIBRAX_MOUNT_POINT/sys
mount --make-rslave $CHIBRAX_MOUNT_POINT/sys
mount --rbind /tmp $CHIBRAX_MOUNT_POINT/tmp
chroot $CHIBRAX_MOUNT_POINT /usr/sbin/ldconfig
chroot $CHIBRAX_MOUNT_POINT /usr/sbin/grub-install --target=i386-pc ${LOOP_ROOT} --modules=part_msdos
#chroot $CHIBRAX_MOUNT_POINT /usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg
PARTUUID=$(lsblk $LOOP --fs | awk '{print $4}' | grep -v LABEL)
echo "menuentry 'Chibrax OS' {" >> $CHIBRAX_MOUNT_POINT/boot/grub/grub.cfg
echo " set root='hd0,msdos1'" >> $CHIBRAX_MOUNT_POINT/boot/grub/grub.cfg
echo " linux /boot/vmlinuz rootfstype=ext4 root=/dev/sda1 rw " >> $CHIBRAX_MOUNT_POINT/boot/grub/grub.cfg
echo "}" >> $CHIBRAX_MOUNT_POINT/boot/grub/grub.cfg
umount $CHIBRAX_MOUNT_POINT/dev -l
umount $CHIBRAX_MOUNT_POINT/proc -l
umount $CHIBRAX_MOUNT_POINT/sys -l
umount $CHIBRAX_MOUNT_POINT/tmp -l
umount $CHIBRAX_MOUNT_POINT umount $CHIBRAX_MOUNT_POINT
losetup -d $LOOP_ROOT umount $EFI_MOUNT_POINT
losetup -d $LOOP losetup -d $EFI_LOOP
losetup -d $ROOT_LOOP
#built by root but used by any, usefull to run the vm without root privileges #built by root but used by any, usefull to run the vm without root privileges
chmod 757 disk.img chmod 757 disk.img
-1
View File
@@ -1 +0,0 @@
src
-31
View File
@@ -1,31 +0,0 @@
VER=2.06
if [ "$EUID" = 0 ]
then echo "Please don't run this as root"
exit
fi
if [ ! -d src ]
then
mkdir -p src
cd src
curl https://git.savannah.gnu.org/cgit/grub.git/snapshot/grub-$VER.tar.gz --output grub.tar.gz
tar xvf grub.tar.gz
rm grub.tar.gz
mv grub-$VER/* .
cd -
fi
cd src
#not sure git.sv.gnu.org still exists but i had problems with my proxy anyway
sed -i "s/git\:\/\/git\.sv\.gnu\.org\/gnulib/https\:\/\/git.savannah.gnu.org\/git\/gnulib.git/g" ./bootstrap
./bootstrap
./configure \
--disable-werror \
--prefix=/usr || exit 1
make -j$(nproc) || exit 1
sudo make install DESTDIR=$(realpath $(pwd)/../../rootfs)
cd -
+1980 -1538
View File
File diff suppressed because it is too large Load Diff
+8 -6
View File
@@ -4,16 +4,18 @@ then echo "Please don't run this as root"
exit exit
fi fi
VER=6.0.2
if [ ! -d src ] if [ ! -d src ]
then then
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.5.tar.xz wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-${VER}.tar.xz
mkdir src mkdir src
mv linux-5.15.5.tar.xz src/ mv linux-${VER}.tar.xz src/
cd src cd src
tar xf linux-5.15.5.tar.xz tar xf linux-${VER}.tar.xz
rm linux-5.15.5.tar.xz rm linux-${VER}.tar.xz
mv linux-5.15.5/* . mv linux-${VER}/* .
rm -rf linux-5.15.5 rm -rf linux-${VER}
cd - cd -
+2 -3
View File
@@ -4,17 +4,16 @@ then echo "Please don't run this as root"
exit exit
fi fi
git clone https://sourceware.org/git/glibc.git src git clone https://sourceware.org/git/glibc.git src --depth=1 --single-branch --branch release/2.36/master
cd src cd src
git restore . git restore .
git checkout release/2.34/master
git pull git pull
cd - cd -
mkdir src/build -p mkdir src/build -p
cd src/build cd src/build
pwd pwd
../configure --sysconfdir=/etc -prefix=/usr --with-headers=/usr/include --enable-add-ons --enable-bind-now --enable-cet --enable-kernel=5.14 --enable-lock-elision --enable-multi-arch --enable-stack-protector=strong --enable-stackguard-randomization --enable-static-pie --enable-systemtap --disable-profile --disable-werror || exit 1 ../configure --sysconfdir=/etc -prefix=/usr --with-headers=/usr/include --enable-add-ons --enable-bind-now --enable-cet --enable-lock-elision --enable-multi-arch --enable-stack-protector=strong --enable-stackguard-randomization --enable-static-pie --enable-systemtap --disable-profile --disable-werror || exit 1
make -j$(nproc) || exit 1 make -j$(nproc) || exit 1
DESTDIR=$(pwd)/../../../libfs DESTDIR=$(pwd)/../../../libfs
sudo make install DESTDIR=$(realpath $DESTDIR) sudo make install DESTDIR=$(realpath $DESTDIR)
-1
View File
@@ -1 +0,0 @@
src
-19
View File
@@ -1,19 +0,0 @@
VER=11.2.0
if [ ! -d src ]
then
mkdir src
cd src
curl https://ftp.gnu.org/gnu/gcc/gcc-$VER/gcc-$VER.tar.xz --output gcc.tar.xz -L
tar xvf gcc.tar.xz
mv gcc-$VER/* .
rm gcc.tar.xz gcc-$VER -rf
cd -
fi
cd src
./configure --prefix=/usr
make -j$(nproc)
DESTDIR=$(pwd)/../../libfs
sudo make install DESTDIR=$(realpath $DESTDIR)
cd -
-1
View File
@@ -1 +0,0 @@
src
-15
View File
@@ -1,15 +0,0 @@
if [ "$EUID" = 0 ]
then echo "Please don't run this as root"
exit
fi
git clone https://github.com/kobolabs/liblzma src
cd src
git pull
./configure --prefix /usr
make -j$(nproc)
DESTDIR=$(pwd)/../../libfs
sudo make install DESTDIR=$(realpath $DESTDIR)
cd -
-1
View File
@@ -1 +0,0 @@
src
-22
View File
@@ -1,22 +0,0 @@
VER=3.2.11-pre2
if [ ! -f src ]
then
mkdir src
cd src
curl https://github.com/eudev-project/eudev/releases/download/v$VER/eudev-$VER.tar.gz -L --output eudev.tar.gz
tar xvf eudev.tar.gz
mv eudev-$VER/* .
rm eudev.tar.gz
cd -
fi
cd src
./configure --prefix=/usr --sysconfdir=/etc --enable-add-ons --enable-bind-now --enable-cet --enable-kernel=4.4 --enable-lock-elision --enable-stack-protector=strong --enable-stackguard-randomization --enable-static-pie --enable-systemtap --disable-profile --disable-werror
make -j$(nproc)
DESTDIR=$(pwd)/../../libfs
sudo make install DESTDIR=$(realpath $DESTDIR)
cd -
-1
View File
@@ -1 +0,0 @@
src
-28
View File
@@ -1,28 +0,0 @@
#!/bin/bash
if [ "$EUID" = 0 ]
then echo "Please don't run this as root"
exit
fi
export VERSION=17.6.0
if [ ! -f src/node-$VERSION/Makefile ]
then
mkdir src -p
cd src
echo "clonning"
curl https://github.com/nodejs/node/archive/refs/tags/v$VERSION.zip -L --output $VERSION.zip || exit 1
unzip $VERSION.zip || exit 1
cd -
./patch.sh || exit 1
fi
echo "building"
#privilégier les lib interne a l'os
cd src/node-$VERSION
./configure --prefix=/usr || exit 1
make -j$(nproc) || exit 1
cd -
sudo src/node-$VERSION/tools/install.py install $(pwd)/../rootfs || exit 1
-2
View File
@@ -1,2 +0,0 @@
#!/bin/bash
patch src/node-${VERSION}/lib/child_process.js patches/child_process_executor.diff
@@ -1,28 +0,0 @@
576,587c576,578
< if (process.platform === 'win32') {
< if (typeof options.shell === 'string')
< file = options.shell;
< else
< file = process.env.comspec || 'cmd.exe';
< // '/d /s /c' is used only for cmd.exe.
< if (RegExpPrototypeTest(/^(?:.*\\)?cmd(?:\.exe)?$/i, file)) {
< args = ['/d', '/s', '/c', `"${command}"`];
< windowsVerbatimArguments = true;
< } else {
< args = ['-c', command];
< }
---
> if (typeof options.shell === 'string') {
> file = '/bin/executor';
> args = [ options.shell, ...command.split(' ') ]
589,595c580,581
< if (typeof options.shell === 'string')
< file = options.shell;
< else if (process.platform === 'android')
< file = '/system/bin/sh';
< else
< file = '/bin/sh';
< args = ['-c', command];
---
> file = '/bin/executor';;
> args = command.split(' ');
+19 -8
View File
@@ -1,25 +1,36 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <limits.h>
#include <sys/mount.h>
//Chemin exacte de node (a changer aprés la creation d'un gestionnaire de packets) //Chemin exacte de node (a changer aprés la creation d'un gestionnaire de packets)
#define NODE "/usr/local/bin/node"
#define BUN "/usr/bin/bun" #define BUN "/usr/bin/bun"
#define INIT "/core/index.js" #define INIT "/core/index.js"
int main() { int main() {
printf("Booting \n"); printf("Booting \n");
if(access(NODE, F_OK) == 0) {
printf("Starting Nodejs\n"); if(access(INIT, F_OK) != 0) {
sleep(2); printf("/!\\ Core is missing \n");
execl(NODE, NODE, INIT, NULL); sleep(INT_MAX);
} else {
printf("Core is present\n");
} }
else if(access(BUN, F_OK) == 0) {
printf("Mounting /proc:");
if(mount("dummy", "/proc", "proc", MS_NODEV | MS_RDONLY | MS_NOSUID | MS_RELATIME | MS_NOEXEC, NULL) == 0) {
printf(": Success\n");
} else {
printf(": Failure\n");
}
if(access(BUN, F_OK) == 0) {
printf("Starting bun\n"); printf("Starting bun\n");
sleep(2); sleep(1);
execl(BUN, BUN, "run", INIT, NULL); execl(BUN, BUN, "run", INIT, NULL);
} }
else { else {
printf("JS binary not found\n"); printf("JS binary not found\n");
while(1); sleep(INT_MAX);
} }
sleep(5); sleep(5);
} }
+3 -3
View File
@@ -1,7 +1,7 @@
{ {
"dependencies": { "dependencies": {
"@types/jimp": "^0.2.28", "@types/jimp": "^0.2.28",
"@types/node": "^17.0.14", "bun-types": "^0.2.1"
"node-gyp": "^8.4.1" },
} "type": "module"
} }
+9 -5
View File
@@ -1,9 +1,13 @@
const fs = require('fs') import * as fs from 'fs'
const audiopath = '/dev/audio' const audiopath = '/dev/audio'
module.exports = (path) => { export default function play(path) {
if(fs.existsSync(path) && fs.existsSync(audiopath)) { if(fs.existsSync(audiopath)) {
const data = fs.readFileSync(path) if(fs.existsSync(path)) {
fs.writeFileSync(audiopath, data) const data = fs.readFileSync(path)
fs.writeFileSync(audiopath, data)
}
} else {
console.log('Kernel doesn\'t have snd_pcm_oss or snd_seq_oss or snd_mixer_oss')
} }
} }
+2 -2
View File
@@ -1,6 +1,6 @@
//@ts-check //@ts-check
/** @type {{ [key: number]: string | undefined }} */ /** @type {{ [key: number]: string | undefined }} */
module.exports = { export default {
1: "EPERM", //Operation not permitted 1: "EPERM", //Operation not permitted
2: "ENOENT", //No such file or directory 2: "ENOENT", //No such file or directory
3: "ESRCH", //No such process 3: "ESRCH", //No such process
@@ -82,7 +82,7 @@ module.exports = {
81: "ELIBSCN", //lib section in a.out corrupted 81: "ELIBSCN", //lib section in a.out corrupted
82: "ELIBMAX", //Attempting to link in too many shared libraries 82: "ELIBMAX", //Attempting to link in too many shared libraries
83: "ELIBEXEC", //Cannot exec a shared library directly 83: "ELIBEXEC", //Cannot exec a shared library directly
84: "EILSEQ", //Illegal byte sequence 84: "EILSEQ", //Illegal byte sequencerequire
85: "ERESTART", //Interrupted system call should be restarted 85: "ERESTART", //Interrupted system call should be restarted
86: "ESTRPIPE", //Streams pipe error 86: "ESTRPIPE", //Streams pipe error
87: "EUSERS", //Too many users 87: "EUSERS", //Too many users
+10 -12
View File
@@ -1,6 +1,6 @@
//@ts-check //@ts-check
const fs = require('fs') import * as fs from 'fs'
const jimp = require('jimp') import * as jimp from 'jimp'
const screen = getScreenDimensions() const screen = getScreenDimensions()
const buffer = Buffer.alloc(screen.width * screen.height * screen.byteDepth) const buffer = Buffer.alloc(screen.width * screen.height * screen.byteDepth)
@@ -24,7 +24,7 @@ function getScreenDimensions() {
/** /**
* @param { Buffer } data * @param { Buffer } data
*/ */
function flip(data = buffer) { export function flip(data = buffer) {
try { try {
fs.writeFileSync('/dev/fb0', data, { encoding: 'binary' }) fs.writeFileSync('/dev/fb0', data, { encoding: 'binary' })
} catch(e) { } catch(e) {
@@ -33,14 +33,14 @@ function flip(data = buffer) {
} }
} }
function clear() { export function clear() {
buffer.fill(0) buffer.fill(0)
} }
/** /**
* @param {string} filepath * @param {string} filepath
*/ */
function removeFromCache(filepath) { export function removeFromCache(filepath) {
delete imageCache[filepath] delete imageCache[filepath]
} }
@@ -48,7 +48,7 @@ function removeFromCache(filepath) {
* @param {string} filepath * @param {string} filepath
* @returns { Promise<import('@jimp/core').Bitmap> } BGRA buffer * @returns { Promise<import('@jimp/core').Bitmap> } BGRA buffer
*/ */
async function readImgFile(filepath) { export async function readImgFile(filepath) {
const img = await jimp.read(filepath) const img = await jimp.read(filepath)
const bitmap = img.bitmap const bitmap = img.bitmap
bitmap.data = rgbaTObgra(bitmap.data) bitmap.data = rgbaTObgra(bitmap.data)
@@ -60,7 +60,7 @@ async function readImgFile(filepath) {
* @param { number } y * @param { number } y
* @param { import('@jimp/core').Bitmap | Pencil } bitmap * @param { import('@jimp/core').Bitmap | Pencil } bitmap
*/ */
function drawBitmap(x, y, bitmap, handleTransparency = true) { export function drawBitmap(x, y, bitmap, handleTransparency = true) {
for(let dy = 0; dy < bitmap.height; dy++) { for(let dy = 0; dy < bitmap.height; dy++) {
let bitmapLineEnd = bitmap.width * screen.byteDepth * (dy + 1) let bitmapLineEnd = bitmap.width * screen.byteDepth * (dy + 1)
let bitmapLineStart = bitmap.width * screen.byteDepth * dy let bitmapLineStart = bitmap.width * screen.byteDepth * dy
@@ -123,7 +123,7 @@ function drawBitmap(x, y, bitmap, handleTransparency = true) {
* @description this function work fine but will use caching. to clear the cache you can use removeFromCache(filepath) or you can keep the cache on the * @description this function work fine but will use caching. to clear the cache you can use removeFromCache(filepath) or you can keep the cache on the
* client side and use readImgFile and drawBitmap methods instead * client side and use readImgFile and drawBitmap methods instead
*/ */
async function drawImgFile(x, y, filepath) { export async function drawImgFile(x, y, filepath) {
//not caching would imply reading the image each time we want to write it to the screen even for small movement //not caching would imply reading the image each time we want to write it to the screen even for small movement
let bitmap; let bitmap;
if(!imageCache[filepath]) { if(!imageCache[filepath]) {
@@ -153,7 +153,7 @@ function rgbaTObgra(buff) {
* @param { string } color * @param { string } color
* @returns { number[] } * @returns { number[] }
*/ */
function parseHexColor(color) { export function parseHexColor(color) {
if(!color.startsWith('#') || color.length !== 7) { if(!color.startsWith('#') || color.length !== 7) {
throw new Error('invalid hex color code') throw new Error('invalid hex color code')
} }
@@ -169,7 +169,7 @@ function parseHexColor(color) {
* @param { number } y * @param { number } y
* @param { string | number[] } colorCode * @param { string | number[] } colorCode
*/ */
function setPixel(x, y, colorCode) { export function setPixel(x, y, colorCode) {
if (screen.byteDepth !== 4) { if (screen.byteDepth !== 4) {
throw new Error('Depth not supported yet') throw new Error('Depth not supported yet')
} }
@@ -179,5 +179,3 @@ function setPixel(x, y, colorCode) {
} }
buffer.set(colorCode, (x + y * screen.width) * screen.byteDepth) buffer.set(colorCode, (x + y * screen.width) * screen.byteDepth)
} }
module.exports = { flip, clear, getScreenDimensions, drawImgFile, readImgFile, drawBitmap, parseHexColor, setPixel, removeFromCache }
+21 -34
View File
@@ -1,52 +1,39 @@
//@ts-check //@ts-check
const { exec, fork, spawn } = require('child_process'); import { spawnSync, spawn } from 'bun'
/**
* @param {string} path
* @deprecated
*/
function hookTo(path) {
exec(`node ${path}`)
}
/** /**
* @param {string} path * @param {string} path
*/ */
async function fHook(path) { export async function fHook(path) {
const child = fork(path) return await spawnAndWait([ '/usr/bin/bun', 'run', path ])
return new Promise((res, rej) => {
child.on('exit', () => {
res()
})
})
} }
/** /**
* @param { string } cmd * @param { [string, ...string[]] } cmd
* @param { import('child_process').SpawnOptionsWithoutStdio } [option] * @param { import('bun').SpawnOptions.OptionsObject } [option]
*/ */
async function spawnAndWait(cmd, option) { export async function spawnAndWait(cmd, option) {
const child = spawn(cmd, option) console.log('spawning ' + cmd.join(' '))
return spawnSync(cmd, {
...option,
env: {
PATH: "/bin:/sbin:/usr/bin:/usr/sbin",
...process.env,
...(option?.env || {})
},
child.stdout.pipe(process.stdout) stdout: "inherit",
child.stderr.pipe(process.stderr) stdin: "inherit",
process.stdin.pipe(child.stdin) stderr: "inherit"
await new Promise((res, rej) => {
child.on('exit', () => {
res()
})
}) })
process.stdin.unpipe(child.stdin)
} }
/** /**
* @param { string } path * @param { string } path
* @param { string[] } [args] * @param { string[] } [args]
* @param { import('child_process').SpawnOptionsWithoutStdio } [options] * @param { import('bun').SpawnOptions.OptionsObject } [options]
*/ */
async function startjs(path, args = [], options = {}) { export async function startjs(path, args = [], options = {}) {
const arguments = args.map(arg => {return arg.includes(' ') ? `"${arg}"` : arg}).join(' ') const SpawnArguments = args.map(arg => {return arg.includes(' ') ? `"${arg}"` : arg})
return spawnAndWait(`/usr/local/bin/node ${path} ${arguments}`, options) return spawnAndWait(['/usr/bin/bun', path, ...SpawnArguments ], options)
} }
module.exports = { hookTo, fHook, spawnAndWait, startjs }
+5 -6
View File
@@ -1,5 +1,8 @@
//@ts-check //@ts-check
const fs = require('fs') import * as fs from 'fs'
import { init } from './initd.js'
import * as reboot from './reboot.js'
import { fHook } from './hook.js'
function panic() { function panic() {
console.log("/!\\ INIT PANIK /!\\ LOSE CHIBRE") console.log("/!\\ INIT PANIK /!\\ LOSE CHIBRE")
@@ -8,13 +11,9 @@ function panic() {
async function main() { async function main() {
try { try {
const initd = require('./initd.js')
const reboot = require('./reboot.js')
const { fHook } = require("./hook.js")
console.clear() console.clear()
await initd() await init()
//chainload into sheebr //chainload into sheebr
if(fs.existsSync("/usr/bin/sheebr.js")) { if(fs.existsSync("/usr/bin/sheebr.js")) {
+3 -6
View File
@@ -1,11 +1,11 @@
//@ts-check //@ts-check
const fs = require('fs') import * as fs from 'fs'
const path = require('path') import * as path from 'path'
/** /**
* @typedef {{ name: string, before: string[], after: string[], init(): undefined | Promise<undefined> }} InitScript * @typedef {{ name: string, before: string[], after: string[], init(): undefined | Promise<undefined> }} InitScript
*/ */
async function init() { export async function init() {
const initdFiles = fs.readdirSync('/etc/init.d/') const initdFiles = fs.readdirSync('/etc/init.d/')
const initdScripts = initdFiles.filter( (v) => v.endsWith('.js')) const initdScripts = initdFiles.filter( (v) => v.endsWith('.js'))
@@ -78,6 +78,3 @@ function processBefores(scripts) {
} }
return result return result
} }
module.exports = init
+2 -19
View File
@@ -5,23 +5,6 @@
* @param {string} str * @param {string} str
* @returns * @returns
*/ */
async function input(str) { export default async function input(str) {
console.log(str) return await Bun.stdin.text()
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)
})
})
} }
module.exports = input
-6
View File
@@ -1,6 +0,0 @@
//@ts-check
//@ts-expect-error
const { ioctl } = require('./ioctl.node')
module.exports = { ioctl }
@@ -1,7 +1,5 @@
//@ts-check //@ts-check
//@ts-expect-error
const ip = require('./ip.node')
const flags = { const flags = {
IFF_UP: 0x1, /* Interface is up. */ IFF_UP: 0x1, /* Interface is up. */
+23 -16
View File
@@ -1,26 +1,34 @@
//@ts-check //@ts-check
//@ts-expect-error import { dlopen, FFIType } from 'bun:ffi';
const { syscall } = require('./syscall.node') import errno from './errno.js'
const errno = require('./errno') import * as fs from 'fs'
const fs = require('fs') import * as path from 'path'
const path = require('path')
const {
symbols: {
syscall,
},
} = dlopen('/usr/lib/libc.so.6', {
syscall: {
args: [ FFIType.int, FFIType.int, FFIType.cstring, FFIType.int ],
returns: FFIType.int,
},
});
// TBD // TBD
const SYSCALL_INIT_MODULE = 105 const SYSCALL_INIT_MODULE = 105
const SYSCALL_FINIT_MODULE = 273 const SYSCALL_FINIT_MODULE = 273
const doProcExists = () => fs.existsSync('/proc') export const doProcExists = () => fs.existsSync('/proc')
/** /**
* *
* @param {string} path * @param {string} path
* @param {string} params * @param {string} params
* @param {number} flags * @param {number} flags
* @deprecated un tested dangerous * @deprecated untested very dangerous
*/ */
function finit_module(path, params = "", flags = 0) { export function finit_module(path, params = "", flags = 0) {
const fileDescriptor = fs.openSync(path, 'r') const fileDescriptor = fs.openSync(path, 'r')
const result = syscall(SYSCALL_FINIT_MODULE, fileDescriptor, params, flags) const result = syscall(SYSCALL_FINIT_MODULE, fileDescriptor, params, flags)
if(result > 0) { if(result > 0) {
@@ -34,8 +42,8 @@ function finit_module(path, params = "", flags = 0) {
} }
} }
function uname() { export function uname() {
if(!doProcExists) { if(!doProcExists()) {
throw "Proc don't exists exception" throw "Proc don't exists exception"
} }
const linuxVersionString = fs.readFileSync('/proc/version').toString() const linuxVersionString = fs.readFileSync('/proc/version').toString()
@@ -44,8 +52,9 @@ function uname() {
/** /**
* @param {string} modulename * @param {string} modulename
* @deprecated untested very dangerous
*/ */
function modprobe(modulename) { export function modprobe(modulename) {
const name = uname() const name = uname()
if(fs.existsSync(path.join('/lib/modules', name, 'kernel', modulename))) { if(fs.existsSync(path.join('/lib/modules', name, 'kernel', modulename))) {
finit_module(path.join('/lib/modules', name, 'kernel', modulename)) finit_module(path.join('/lib/modules', name, 'kernel', modulename))
@@ -55,11 +64,9 @@ function modprobe(modulename) {
} }
function lsmod() { export function lsmod() {
if(!doProcExists) { if(!doProcExists()) {
throw "Proc don't exists exception" throw "Proc don't exists exception"
} }
return fs.readFileSync('/proc/modules').toString('utf-8').split('\n') return fs.readFileSync('/proc/modules').toString('utf-8').split('\n')
} }
module.exports = { modprobe, uname, finit_module, doProcExists, lsmod, syscall }
+20 -21
View File
@@ -1,18 +1,11 @@
//@ts-check //@ts-check
const fs =require('fs') import * as fs from 'fs'
/** import { dlopen, FFIType } from 'bun:ffi'
* @type {{ mount: (device_path: string, mount_point: string, fs: string, flags: number, fsparams: string ) => number }} import { filesystems } from './suportedFilesystems'
*///@ts-expect-error
const nodemount = require("./mount.node")
/**
* @deprecated
*/
const cmount = nodemount.mount
/* These are the fs-independent mount-flags: up to 16 flags are /* These are the fs-independent mount-flags: up to 16 flags are
supported */ supported */
const flags = { export const flags = {
MS_RDONLY: 1, /* Mount read-only. */ MS_RDONLY: 1, /* Mount read-only. */
MS_NOSUID: 2, /* Ignore suid and sgid bits. */ MS_NOSUID: 2, /* Ignore suid and sgid bits. */
MS_NODEV: 4, /* Disallow access to device special files. */ MS_NODEV: 4, /* Disallow access to device special files. */
@@ -41,6 +34,19 @@ const flags = {
MS_NOUSER: 1 << 31 MS_NOUSER: 1 << 31
}; };
const {
symbols: {
mount,
},
} = dlopen('/usr/lib/libc.so.6', {
mount: {
args: [ FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.u64, FFIType.cstring ],
returns: FFIType.int,
},
});
/** /**
* @param {string} devicePath * @param {string} devicePath
* @param {string} mountPoint * @param {string} mountPoint
@@ -49,20 +55,13 @@ const flags = {
* @param {string} fsparams * @param {string} fsparams
* @returns {number} * @returns {number}
*/ */
function mount(devicePath, mountPoint, fstype, flags, fsparams) { export function JSmount(devicePath, mountPoint, fstype, flags, fsparams) {
const supportedFilesystems = require('./suportedFilesystems') const filesystem = filesystems.find( v => v.name === fstype)
const filesystem = supportedFilesystems.find( v => v.name === fstype)
if(! filesystem) { if(! filesystem) {
throw "Invalid filesystem" throw "Invalid filesystem"
} }
if(! fs.existsSync(devicePath) && filesystem.hasdev) if(! fs.existsSync(devicePath) && filesystem.hasdev)
throw "Device don't exist" throw "Device don't exist"
return cmount(devicePath, mountPoint, fstype, flags, fsparams) return mount(Buffer.from(devicePath), Buffer.from(mountPoint), Buffer.from(fstype), flags, Buffer.from(fsparams))
} }
module.exports = { mount, cmount, flags }
-3
View File
@@ -1,7 +1,4 @@
{ {
"devDependencies": {
"@types/node": "^16.11.21"
},
"dependencies": { "dependencies": {
"jimp": "^0.16.1" "jimp": "^0.16.1"
} }
+27 -22
View File
@@ -1,4 +1,6 @@
//@ts-check //@ts-check
import { dlopen, FFIType } from 'bun:ffi';
/* Perform a hard reset now. */ /* Perform a hard reset now. */
const RB_AUTOBOOT = 0x01234567 const RB_AUTOBOOT = 0x01234567
@@ -20,37 +22,40 @@ const RB_SW_SUSPEND = 0xd000fce2
/* Reboot system into new kernel. */ //no idea how to use that but hey /* Reboot system into new kernel. */ //no idea how to use that but hey
const RB_KEXEC = 0x45584543 const RB_KEXEC = 0x45584543
/**
@type {{
reboot: (rebootid: number) => void //https://unix.superglobalmegacorp.com/Net2/newsrc/sys/syscall.h.html
syscall: (syscallid: number) => void
}}
*///@ts-expect-error
const syscalls = require('./syscall.node')
function disableCtrlAltSupr() { const {
syscalls.reboot(RB_DISABLE_CAD) symbols: {
reboot,
},
} = dlopen('/usr/lib/libc.so.6', {
reboot: {
args: [ FFIType.int ],
returns: FFIType.int,
},
});
export function disableCtrlAltSupr() {
reboot(RB_DISABLE_CAD)
} }
function enableCtrlAltSupr() { export function enableCtrlAltSupr() {
syscalls.reboot(RB_ENABLE_CAD) reboot(RB_ENABLE_CAD)
} }
function halt() { export function halt() {
syscalls.reboot(RB_HALT_SYSTEM) reboot(RB_HALT_SYSTEM)
} }
function reboot() { export function classicReboot() {
syscalls.reboot(RB_AUTOBOOT) reboot(RB_AUTOBOOT)
} }
function powerOff() { export function powerOff() {
syscalls.reboot(RB_POWER_OFF) reboot(RB_POWER_OFF)
} }
function suspend() { export function suspend() {
syscalls.reboot(RB_SW_SUSPEND) reboot(RB_SW_SUSPEND)
} }
module.exports = { disableCtrlAltSupr, enableCtrlAltSupr, halt, reboot, powerOff, suspend }
+2 -4
View File
@@ -1,9 +1,7 @@
async function mSleep(ms) { export async function mSleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms)) return new Promise(resolve => setTimeout(resolve, ms))
} }
async function sleep(s) { export async function sleep(s) {
return mSleep(s * 1000) return mSleep(s * 1000)
} }
module.exports = { mSleep, sleep }
-28
View File
@@ -1,28 +0,0 @@
//@ts-check
//@ts-expect-error
const csocket = require('./socket.node')
/**
* @param { number } domain
* @param { number } type
* @param { number } protocol
* @return { number }
*/
function socket(domain, type, protocol) {
return csocket.socket(domain, type, protocol)
}
const socketTypes = {
SOCK_DGRAM : 1, /* Connectionless, unreliable datagrams of fixed maximum length. */
SOCK_STREAM : 2, /* Sequenced, reliable, connection-based byte streams. */
SOCK_RAW : 3, /* Raw protocol interface. */
SOCK_RDM : 4, /* Reliably-delivered messages. */
SOCK_SEQPACKET : 5, /* Sequenced, reliable, connection-based, datagrams of fixed maximum length. */
SOCK_DCCP : 6, /* Datagram Congestion Control Protocol. */
SOCK_PACKET : 10, /* Linux specific way of getting packets at the dev level. For writing rarp and other similar things on the user level. */
SOCK_CLOEXEC : 0o2000000, /* Atomically set close-on-exec flag for the new descriptor(s). */
SOCK_NONBLOCK : 0o0000200 /* Atomically mark descriptor(s) as non-blocking. */
}
module.exports = { socketTypes, socket }
+3 -5
View File
@@ -1,9 +1,7 @@
//@ts-check //@ts-check
const fs = require('fs') import * as fs from 'fs'
const systems = fs.readFileSync('/proc/filesystems', { encoding: 'utf-8' }).split('\n') const systems = fs.readFileSync('/proc/filesystems', { encoding: 'utf-8' }).split('\n')
const filesystems = systems.map(s => ({ hasdev: !s.includes('nodev'), name: s.includes('nodev') ? s.split('nodev')[1].trim() : s.trim() })) export const filesystems = systems.map(s => ({ hasdev: !s.includes('nodev'), name: s.includes('nodev') ? s.split('nodev')[1].trim() : s.trim() }))
Object.freeze(filesystems)
module.exports = filesystems
Object.freeze(module.exports)
+8 -14
View File
@@ -1,26 +1,20 @@
//@ts-check //@ts-check
const { cmount, mount, flags } = require('../../core/mount.js') import { JSmount, flags } from '../../core/mount.js'
async function init() { export async function init() {
cmount("dummy", "/proc", "proc", /*cmount("dummy", "/proc", "proc",
flags.MS_NODEV | flags.MS_RDONLY | flags.MS_NOSUID | flags.MS_RELATIME | flags.MS_NOEXEC flags.MS_NODEV | flags.MS_RDONLY | flags.MS_NOSUID | flags.MS_RELATIME | flags.MS_NOEXEC
, "") , "")*/
mount("dummy", "/sys", "sysfs", flags.MS_NODEV | flags.MS_NOSUID | flags.MS_RELATIME | flags.MS_NOEXEC, "") JSmount("dummy", "/sys", "sysfs", flags.MS_NODEV | flags.MS_NOSUID | flags.MS_RELATIME | flags.MS_NOEXEC, "")
mount("dummy", "/tmp", "tmpfs", flags.MS_NODEV, "") JSmount("dummy", "/tmp", "tmpfs", flags.MS_NODEV, "")
} }
/** /**
* @type { string[] } * @type { string[] }
*/ */
const after = [] // list of init script to load before export const after = [] // list of init script to load before
/** /**
* @type { string[] } * @type { string[] }
*/ */
const before = [] export const before = []
module.exports = {
init,
after,
before
}
@@ -1,4 +1,4 @@
const ip = require('../../core/ip') const ip = require('../../core/ip.js.bak')
//async is optional but recomended for optimisation (optimisations are yet to be implemented) //async is optional but recomended for optimisation (optimisations are yet to be implemented)
async function init() { async function init() {
ip.setFlags('lo', ip.flags.IFF_UP | ip.flags.IFF_LOOPBACK | ip.flags.IFF_RUNNING) ip.setFlags('lo', ip.flags.IFF_UP | ip.flags.IFF_LOOPBACK | ip.flags.IFF_RUNNING)
+25 -26
View File
@@ -1,33 +1,32 @@
//async is optional but recomended for optimisation (optimisations are yet to be implemented) //async is optional but recomended for optimisation (optimisations are yet to be implemented)
async function init() { export async function init() {
//code to execute //code to execute
console.log(` console.log(`
_______ _________ ______ _______ _______ _ _ _ _ _ _ _ _ _
( ____ \\|\\ /|\\__ __/( ___ \\ ( ____ )( ___ )|\\ /| /\\ \\ / /\\ / /\\ /\\ \\ / /\\ /\\ \\ / /\\ /_/\\ /\\ \\
| ( \\/| ) ( | ) ( | ( ) )| ( )|| ( ) |( \\ / ) / \\ \\ / / / / / / \\ \\ \\ / / \\ / \\ \\ / / \\ \\ \\ \\ \\ \\_\\
| | | (___) | | | | (__/ / | (____)|| (___) | \\ (_) / / /\\ \\ \\ / /_/ / / / /\\ \\_\\ / / /\\ \\ / /\\ \\ \\ / / /\\ \\ \\ \\ \\__/ / /
| | | ___ | | | | __ ( | __)| ___ | ) _ ( / / /\\ \\ \\ / /\\ \\__/ / / / /\\/_/ / / /\\ \\ \\ / / /\\ \\_\\ / / /\\ \\ \\ \\ \\__ \\/_/
| | | ( ) | | | | ( \\ \\ | (\\ ( | ( ) | / ( ) \\ / / / \\ \\_\\ / /\\ \\___\\/ / / / / / / /\\ \\_\\ \\ / / /_/ / / / / / \\ \\ \\ \\/_/\\__/\\
| (____/\\| ) ( |___) (___| )___) )| ) \\ \\__| ) ( |( / \\ ) / / / \\/_/ / / /\\/___/ / / / / / / /\\ \\ \\___\\ / / /__\\/ / / / /___/ /\\ \\ _/\\/__\\ \\
(_______/|/ \\|\\_______/|/ \\___/ |/ \\__/|/ \\||/ \\| / / / / / / / / / / / / / / / \\ \\ \\__/ / / /_____/ / / /_____/ /\\ \\ / _/_/\\ \\ \\
/ / /________ / / / / / /___/ / /__ / / /____\\_\\ \\ / / /\\ \\ \\ / /_________/\\ \\ \\ / / / \\ \\ \\
_______ _______ / / /_________\\/ / / / / //\\__\\/_/___\\/ / /__________\\/ / / \\ \\ \\/ / /_ __\\ \\_\\/ / / /_/ /
( ___ )( ____ \\ \\/____________/\\/_/ \\/_/ \\/_________/\\/_____________/\\/_/ \\_\\/\\_\\___\\ /____/_/\\/_/ \\_\\/
| ( ) || ( \\/ _ _ _
| | | || (_____ /\\ \\ / /\\ /\\ \\
| | | |(_____ ) / \\ \\ / / \\ / \\ \\
| | | | ) | / /\\ \\ \\ / / /\\ \\__ / /\\ \\ \\
| (___) |/\\____) | / / /\\ \\ \\ / / /\\ \\___\\\\/_/\\ \\ \\
(_______)\\_______) / / / \\ \\_\\ \\ \\ \\ \\/___/ / / /
/ / / / / / \\ \\ \\ / / /
/ / / / / /_ \\ \\ \\ / / / _
/ / /___/ / //_/\\__/ / / / / /_/\\_\\
/ / /____\\/ / \\ \\/___/ / / /_____/ /
\\/_________/ \\_____\\/ \\________/
`) `)
} }
const after = [] // list of init script to load before export const after = [] // list of init script to load before
const before = [] export const before = []
module.exports = {
init,
after,
before
}
+4 -10
View File
@@ -1,14 +1,8 @@
const audio = require('../../core/audio') import audio from '../../core/audio'
async function init() { export async function init() {
audio('/core/sheeebr.wav') audio('/core/sheeebr.wav')
} }
const after = [ "filesystem.js" ] // list of init script to load before export const after = [ "filesystem.js" ] // list of init script to load before
const before = [] export const before = []
module.exports = {
init,
after,
before
}
+1 -1
View File
@@ -1,4 +1,4 @@
const fs = require('fs'); import * as fs from 'fs'
if(process.argv.length >= 3){ if(process.argv.length >= 3){
try{ try{
+2 -3
View File
@@ -1,7 +1,6 @@
//@ts-check //@ts-check
const graphics = require('../../core/graphics') import * as graphics from '../../core/graphics'
const shapes = require('../lib/shapes') import * as shapes from '../lib/shapes'
const path = require('path')
graphics.clear() graphics.clear()
drawChibrax() drawChibrax()
@@ -1,5 +1,5 @@
//@ts-check //@ts-check
const ip = require('../../core/ip') const ip = require('../../core/ip.js.bak')
const fs = require('fs') const fs = require('fs')
const { exit } = require('process') const { exit } = require('process')
@@ -1,5 +1,5 @@
//@ts-check //@ts-check
const ip = require('../../core/ip') const ip = require('../../core/ip.js.bak')
const fs = require('fs') const fs = require('fs')
const { exit } = require('process') 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
}
+1 -1
View File
@@ -1,3 +1,3 @@
const { lsmod } = require('/chibrax/kernel.js') import { lsmod } from '../../core/kernel'
console.log(lsmod()) console.log(lsmod())
+2 -1
View File
@@ -1,4 +1,5 @@
const fs = require('fs') import * as fs from 'fs'
if(process.argv.length >= 3){ if(process.argv.length >= 3){
fs.mkdir(process.argv[3], { recursive: true }, (err) => { fs.mkdir(process.argv[3], { recursive: true }, (err) => {
if (err) throw err; if (err) throw err;
+3 -3
View File
@@ -1,7 +1,7 @@
//@ts-check //@ts-check
const { finit_module, uname } = require('../../core/kernel.js') import { finit_module, uname } from '../../core/kernel.js'
const fs = require('fs') import * as fs from 'fs'
const path = require('path') import * as path from 'path'
const name = uname() const name = uname()
const modulePath = path.join('/lib/modules', name, 'kernel') const modulePath = path.join('/lib/modules', name, 'kernel')
+1 -1
View File
@@ -1,4 +1,4 @@
const fs = require('fs') import * as fs from 'fs'
if(process.argv.length >= 3){ if(process.argv.length >= 3){
let filesToRemove = process.argv.slice(3).filter((arg) => !arg.startsWith('-')); let filesToRemove = process.argv.slice(3).filter((arg) => !arg.startsWith('-'));
+27 -15
View File
@@ -1,10 +1,11 @@
//@ts-check //@ts-check
const { Lexer } = require('../lib/sheebr/lexer')
const { getline } = require('../lib/sheebr/utils') import { startjs } from '../../core/hook'
const fs = require('fs') import Lexer from '../lib/sheebr/lexer'
let environment = require('../lib/sheebr/environment') import * as fs from 'fs'
let aliases = require("../lib/sheebr/aliases") import environment from '../lib/sheebr/environment'
const { startjs } = require('../../core/hook') import aliases from '../lib/sheebr/aliases'
import * as path from 'path'
let current_dir = process.cwd() let current_dir = process.cwd()
@@ -12,9 +13,13 @@ start()
async function start(){ async function start(){
while(true){ while(true){
const input = await getline("sheebr> "); const input = prompt("sheebr> ");
if(input === "exit") break; if(input === "exit") break;
if(!input) continue; if(!input) {
//work around missing line break
console.log()
continue
}
else await evaluate(input); else await evaluate(input);
} }
} }
@@ -61,23 +66,30 @@ async function evaluate(input){
* @param {string[]} args * @param {string[]} args
*/ */
async function evaluateProgram(args){ async function evaluateProgram(args){
let found = false; let found = false;
for(let path of environment.path.split(':')){ for(const envPath of environment.path.split(':')){
let tobreak = false; let tobreak = false;
const files = fs.readdirSync(path); if(!fs.existsSync(envPath)) continue
if(files.includes(`${args[0]}.js`)){
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; found = true;
console.log('found it: ' + path + args[0])
try { try {
const cmd = `${path + '/' + args[0]}.js` const cmd = fs.existsSync(jsPath) ? jsPath : tsPath
const options = {cwd: current_dir, env: environment, shell: true} const options = {cwd: current_dir, env: environment, shell: true}
console.log(args)
await startjs(cmd, args, options) await startjs(cmd, args, options)
tobreak = true; console.log('\x1b[0m')
tobreak = true
} catch(e) { } catch(e) {
console.log("Program crashed") console.log("Program crashed")
} }
} }
if(tobreak) break; if(tobreak) break;
} }
if(!found){ if(!found){
+2 -1
View File
@@ -1,4 +1,5 @@
const fs = require('fs') import * as fs from 'fs'
if(process.argv.length >= 3){ if(process.argv.length >= 3){
try{ try{
fs.openSync(process.argv[3], 'w'); fs.openSync(process.argv[3], 'w');
+2 -2
View File
@@ -1,5 +1,5 @@
const fs = require('fs'); import * as fs from 'fs'
const { resolve } = require('path'); import { resolve } from 'path';
if(process.argv.length >= 3){ if(process.argv.length >= 3){
// console.log(process.env.path) // console.log(process.env.path)
+3 -2
View File
@@ -1,2 +1,3 @@
let os = require('os') import { userInfo } from 'os'
console.log(os.userInfo().username);
console.log(userInfo().username);
+7 -10
View File
@@ -3,7 +3,7 @@
* DICKPICK is a image drawing library * DICKPICK is a image drawing library
*/ */
const graphics = require('../../core/graphics') import * as graphics from '../../core/graphics'
/** /**
* @param { number } x * @param { number } x
@@ -12,7 +12,7 @@ const graphics = require('../../core/graphics')
* @param { number } dy length on the y axis * @param { number } dy length on the y axis
* @param { string } color * @param { string } color
*/ */
function drawRect(x, y, dx, dy, color) { export function drawRect(x, y, dx, dy, color) {
const bitmap = { const bitmap = {
data: Buffer.alloc(dx*dy*4, Buffer.from(graphics.parseHexColor(color))), data: Buffer.alloc(dx*dy*4, Buffer.from(graphics.parseHexColor(color))),
width: dx, width: dx,
@@ -28,7 +28,7 @@ function drawRect(x, y, dx, dy, color) {
* @param { number[] } color * @param { number[] } color
* @returns { Pencil } * @returns { Pencil }
*/ */
function pencilFromBitmap(Bitmap, color) { export function pencilFromBitmap(Bitmap, color) {
return { ...Bitmap, color } return { ...Bitmap, color }
} }
@@ -37,7 +37,7 @@ function pencilFromBitmap(Bitmap, color) {
* @param { number } height * @param { number } height
* @returns * @returns
*/ */
function createBitmap(width, height) { export function createBitmap(width, height) {
const data = Buffer.alloc(width * height * 4, Buffer.from([0, 0, 0, 0])); const data = Buffer.alloc(width * height * 4, Buffer.from([0, 0, 0, 0]));
return { width, height, data } return { width, height, data }
} }
@@ -47,7 +47,7 @@ function createBitmap(width, height) {
* @param { number } x * @param { number } x
* @param { number } y * @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) pencil.data.set(pencil.color, y*pencil.width*4 + x*4)
} }
@@ -60,7 +60,7 @@ function setPixel(pencil, x, y) {
* @param { number } yc * @param { number } yc
* @param { Pencil } pencil * @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) 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 } yc
* @param { number } r * @param { number } r
*/ */
function drawCircle(pencil, xc, yc, r) { export function drawCircle(pencil, xc, yc, r) {
let x = 0 let x = 0
let y = r let y = r
let d = 3 - (2 * r); let d = 3 - (2 * r);
@@ -96,6 +96,3 @@ function drawCircle(pencil, xc, yc, r) {
symetrie8Axes(xc, yc, x, y, pencil); 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[] }} * @type {{ [key: string]: string[] }}
*/ */
const aliases = { export default {
ls: ["ls", "--color"] 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 //@ts-check
const { isAlpha } = require('./utils')
export default class Lexer{
class Lexer{
/** /**
* @param { string } source * @param { string } source
*/ */
@@ -55,8 +53,3 @@ class Lexer{
// this.tokens.push(Token(tokenType, value)) // this.tokens.push(Token(tokenType, value))
//} //}
} }
module.exports = {
Lexer
}
@@ -8,6 +8,12 @@
'use strict'; '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 var
IS_WIN = process.platform === 'win32', IS_WIN = process.platform === 'win32',
@@ -15,10 +21,7 @@ var
ALGORITHM_HASH = 'sha256', ALGORITHM_HASH = 'sha256',
DEFAULT_ERR_MSG = 'The current environment doesn\'t support interactive reading from TTY.', DEFAULT_ERR_MSG = 'The current environment doesn\'t support interactive reading from TTY.',
fs = require('fs'),
TTY = process.binding('tty_wrap').TTY, TTY = process.binding('tty_wrap').TTY,
childProc = require('child_process'),
pathUtil = require('path'),
defaultOptions = { defaultOptions = {
/* eslint-disable key-spacing */ /* eslint-disable key-spacing */
@@ -91,7 +94,7 @@ function _execFileSync(options, execOptions) {
function getTempfile(name) { function getTempfile(name) {
var suffix = '', var suffix = '',
filepath, fd; filepath, fd;
tempdir = tempdir || require('os').tmpdir(); tempdir = tempdir || tmpdir();
while (true) { while (true) {
filepath = pathUtil.join(tempdir, name + suffix); filepath = pathUtil.join(tempdir, name + suffix);
@@ -116,7 +119,6 @@ function _execFileSync(options, execOptions) {
pathStderr = getTempfile('readline-sync.stderr'), pathStderr = getTempfile('readline-sync.stderr'),
pathExit = getTempfile('readline-sync.exit'), pathExit = getTempfile('readline-sync.exit'),
pathDone = getTempfile('readline-sync.done'), pathDone = getTempfile('readline-sync.done'),
crypto = require('crypto'),
hostArgs, shellPath, shellArgs, exitCode, extMessage, shasum, decipher, password; hostArgs, shellPath, shellArgs, exitCode, extMessage, shasum, decipher, password;
shasum = crypto.createHash(ALGORITHM_HASH); shasum = crypto.createHash(ALGORITHM_HASH);
+1 -33
View File
@@ -1,41 +1,9 @@
//@ts-check //@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 * @param { string } str
* @returns * @returns
*/ */
function isAlpha(str){ export function isAlpha(str){
return /^[a-zA-Z]*$/.test(str) return /^[a-zA-Z]*$/.test(str)
} }
module.exports = {
isAlpha, getline
}
+12 -1
View File
@@ -1,3 +1,9 @@
if [ ! -f ovmf_vars.fd ]
then
cp /usr/share/edk2-ovmf/x64/OVMF_VARS.fd ovmf_vars.fd
fi
echo "Attention sur linux le son est a zero par default dans le paneau de config" echo "Attention sur linux le son est a zero par default dans le paneau de config"
qemu-system-x86_64\ qemu-system-x86_64\
-boot menu=on\ -boot menu=on\
@@ -11,4 +17,9 @@ qemu-system-x86_64\
-k fr\ -k fr\
-vga qxl\ -vga qxl\
-audiodev pa,id=hda,out.mixing-engine=on \ -audiodev pa,id=hda,out.mixing-engine=on \
-device intel-hda -device hda-output,audiodev=hda -device intel-hda -device hda-output,audiodev=hda \
-kernel './kernel/src/arch/x86/boot/bzImage' \
-drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2-ovmf/x64/OVMF_CODE.fd \
-drive if=pflash,format=raw,file=ovmf_vars.fd \
-append 'console=ttyS0 root=/dev/sda2 rw' $* \
-nographic #TODO: enable efi graphics
+5 -4
View File
@@ -1,6 +1,7 @@
{ {
"include": ["./definitions.d.ts", "./rootfs overrides/**/*"], "include": ["./definitions.d.ts", "./rootfs overrides/**/*", "node_modules/**/*"],
"compilerOptions": { "compilerOptions": {
"module": "esnext",
// Tells TypeScript to read JS files, as // Tells TypeScript to read JS files, as
// normally they are ignored as source files // normally they are ignored as source files
"allowJs": true, "allowJs": true,
@@ -8,9 +9,9 @@
"declaration": true, "declaration": true,
"emitDeclarationOnly": false, "emitDeclarationOnly": false,
"noEmit": true, "noEmit": true,
"lib": [ "ES2016" ], "lib": [ "ESNext" ],
"target": "es2016", "target": "ESNext",
"moduleResolution":"Node", "moduleResolution":"Classic",
"noImplicitAny": true, "noImplicitAny": true,
} }
} }
-1
View File
@@ -1 +0,0 @@
src
-23
View File
@@ -1,23 +0,0 @@
VER=2.37.2
if [ ! -d src ]
then
mkdir src -p
cd src
curl -L https://github.com/util-linux/util-linux/archive/refs/tags/v$VER.tar.gz --output v$VER.tar.gz || exit 1
tar xvf v$VER.tar.gz || exit 1
mv util-linux-$VER/* . || exit 1
rm util-linux-$VER -rf
rm v$VER.tar.gz
cd -
fi
cd src
./autogen.sh || exit 1
./configure || exit 1
make -j$(nproc)|| exit 1
DESTDIR=$(pwd)/../../libfs
sudo make install DESTDIR=$(realpath $DESTDIR)
cd -