Compare commits

...

3 Commits

Author SHA1 Message Date
33c1a9c92b
init: Add a configurable service directory
All checks were successful
continuous-integration/drone/push Build is passing
2023-08-22 15:23:06 +02:00
65834ff491
edit: Make it more user-friendly 2023-08-22 15:17:13 +02:00
5c2718545f
base+tools: Add a welcome file and store the license inside the OS 2023-08-22 15:08:07 +02:00
6 changed files with 43 additions and 6 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@ initrd/boot/moon
env-local.sh
initrd/bin/**
base/usr/**
base/etc/skel/LICENSE
.fakeroot
kernel/config.cmake
ports/out/

View File

@ -1,6 +1,8 @@
#include <luna/String.h>
#include <os/ArgumentParser.h>
#include <os/File.h>
#include <os/FileSystem.h>
#include <os/Prompt.h>
using os::File;
@ -14,10 +16,20 @@ Result<int> luna_main(int argc, char** argv)
parser.add_positional_argument(pathname, "path"_sv, true);
parser.parse(argc, argv);
if (os::FileSystem::exists(pathname))
{
String prompt = TRY(String::format("File %s already exists. Overwrite?"_sv, pathname.chars()));
bool overwrite = os::conditional_prompt(prompt.chars(), os::DefaultNo);
if (!overwrite) return 0;
}
auto file = TRY(File::open_or_create(pathname, File::WriteOnly));
auto input = File::standard_input();
os::println("- Editing %s. Press Enter to start a new line, or Ctrl+D at the start of a line to save and exit. -",
pathname.chars());
while (1)
{
String line = TRY(input->read_line());

View File

@ -323,7 +323,7 @@ static void mount_shmfs()
if (chmod("/dev/shm", 01777) < 0) exit(255);
}
Result<int> sysinit()
Result<int> sysinit(StringView path)
{
if (getpid() != 1)
{
@ -358,7 +358,8 @@ Result<int> sysinit()
TRY(os::Security::pledge("stdio rpath wpath cpath proc exec id", nullptr));
start_services("/etc/init");
if (path.is_empty()) path = "/etc/init";
start_services(path);
while (1)
{
@ -394,7 +395,7 @@ Result<int> sysinit()
}
}
Result<int> user_init()
Result<int> user_init(StringView path)
{
setpgid(0, 0);
@ -405,7 +406,8 @@ Result<int> user_init()
TRY(os::Security::pledge("stdio rpath wpath cpath proc exec", nullptr));
start_services("/etc/user");
if (path.is_empty()) path = "/etc/user";
start_services(path);
TRY(os::Security::pledge("stdio rpath wpath proc exec", nullptr));
@ -446,13 +448,16 @@ Result<int> user_init()
Result<int> luna_main(int argc, char** argv)
{
bool user;
StringView service_path;
os::ArgumentParser parser;
parser.add_description("The init system for Luna.");
parser.add_system_program_info("init"_sv);
parser.add_switch_argument(user, 'u', "user"_sv, "initialize a user session instead of the system");
parser.add_value_argument(service_path, 's', "service-path"_sv,
"change the default service path (/etc/init or /etc/user)");
parser.parse(argc, argv);
if (user) return user_init();
return sysinit();
if (user) return user_init(service_path);
return sysinit(service_path);
}

14
base/etc/skel/welcome Normal file
View File

@ -0,0 +1,14 @@
Welcome to the Luna operating system!
You are running on the default user account, selene.
If you are familiar with Unix-style operating systems (like Linux or *BSD), you should be able to use the Luna terminal without much problems.
Following the traditional Unix filesystem structure, programs are installed in /usr/bin (/bin is a symlink to /usr/bin). The command `ls /bin` will show all commands available on your current Luna installation.
Currently, because of driver limitations, the root file system is mounted read-only. Your home folder is writable, but volatile; it is created and populated on boot, and its contents will vanish after a reboot.
The system is booted using the 'init' program. You can read its configuration files in the /etc/init directory to learn more about the boot process.
Luna is free software, released under the BSD-2-Clause license. The license is included in the LICENSE file in your home directory.
View the source code and read more about Luna at https://git.cloudapio.eu/apio/Luna.

View File

@ -1,3 +1,6 @@
#!/bin/sh
# Create and populate a volatile home directory.
mount -t tmpfs tmpfs /home/selene
chown selene:selene /home/selene
cp /etc/skel/welcome /home/selene/
cp /etc/skel/LICENSE /home/selene/

View File

@ -31,3 +31,5 @@ mkdir -p base/tmp
rm -f base/bin
ln -s usr/bin base/bin
cp $LUNA_ROOT/LICENSE base/etc/skel/LICENSE