Skip to content

Commit 8d32d7b

Browse files
move profile creation to ash
1 parent 4945aea commit 8d32d7b

3 files changed

Lines changed: 37 additions & 19 deletions

File tree

src/initial_fs_setup.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ const setup_motd = async (fs: AbstractFileSystem) => {
5757
}
5858
};
5959

60-
const setup_rc_profile = async (fs: AbstractFileSystem) => {
61-
// create .ollie_profile file if it doesn't exist
62-
const profile_content = `# OllieOS configuration file${NEWLINE}# This file is run when the TTY starts.${NEWLINE}${NEWLINE}cat /etc/motd.txt${NEWLINE}echo "OllieOS v$VERSION ($ENV)"${NEWLINE}`;
63-
const absolute_profile = fs.absolute("~/.ollie_profile");
64-
if (!(await fs.exists(absolute_profile))) {
65-
await fs.write_file(absolute_profile, profile_content);
60+
const migrate_rc_profile = async (fs: AbstractFileSystem) => {
61+
// if .ollie_profile exists, and .ash_profile doesn't, rename it to .ash_profile
62+
const absolute_ollie_profile = fs.absolute("~/.ollie_profile");
63+
const absolute_ash_profile = fs.absolute("~/.ash_profile");
64+
if (await fs.exists(absolute_ollie_profile) && !(await fs.exists(absolute_ash_profile))) {
65+
await fs.move_file(absolute_ollie_profile, absolute_ash_profile);
6666
}
6767

68-
// create .ollierc file if it doesn't exist
69-
const rc_content = `# OllieOS configuration file${NEWLINE}# This file is run when a shell is created.${NEWLINE}${NEWLINE}`;
70-
const absolute_rc = fs.absolute("~/.ollierc");
71-
if (!(await fs.exists(absolute_rc))) {
72-
await fs.write_file(absolute_rc, rc_content);
68+
// if .ollierc exists, and .ashrc doesn't, rename it to .ashrc
69+
const absolute_ollierc = fs.absolute("~/.ollierc");
70+
const absolute_ashrc = fs.absolute("~/.ashrc");
71+
if (await fs.exists(absolute_ollierc) && !(await fs.exists(absolute_ashrc))) {
72+
await fs.move_file(absolute_ollierc, absolute_ashrc);
7373
}
7474
};
7575

@@ -422,7 +422,7 @@ const setup_projects = async (fs: AbstractFileSystem, data_rev: string | null) =
422422
export const initial_fs_setup = async (fs: AbstractFileSystem) => {
423423
await setup_boot(fs);
424424
await setup_motd(fs);
425-
await setup_rc_profile(fs);
425+
await migrate_rc_profile(fs);
426426
await setup_credits(fs);
427427

428428

src/programs/core/ash/index.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {Program} from "../../../types";
2+
import {NEWLINE} from "../../../term_ctl";
23

34
import {AshShell} from "./core";
45
import {make_read_line_key_handlers, make_read_line_printable_handler} from "./key_handlers";
@@ -24,20 +25,37 @@ export default {
2425

2526
const fs = kernel.get_fs();
2627

28+
const absolute_profile = fs.absolute("~/.ash_profile");
29+
const absolute_rc = fs.absolute("~/.ashrc");
30+
31+
// create .ash_profile file if it doesn't exist
32+
const profile_content = `# ash configuration file${NEWLINE}# This file is run at login.${NEWLINE}${NEWLINE}cat /etc/motd.txt${NEWLINE}echo "OllieOS v$VERSION ($ENV)"${NEWLINE}`;
33+
if (!(await fs.exists(absolute_profile))) {
34+
await fs.write_file(absolute_profile, profile_content);
35+
}
36+
37+
// create .ashrc file if it doesn't exist
38+
const rc_content = `# ash configuration file${NEWLINE}# This file is run when a shell is created.${NEWLINE}${NEWLINE}`;
39+
if (!(await fs.exists(absolute_rc))) {
40+
await fs.write_file(absolute_rc, rc_content);
41+
}
42+
2743
if (args.includes("--login")) {
2844
// enable screen reader mode if stored in local storage
2945
if (localStorage.getItem("reader") === "true") {
3046
await shell.execute("reader -s on");
3147
}
3248

33-
// run .ollie_profile if it exists
34-
const absolute_profile = fs.absolute("~/.ollie_profile");
35-
await shell.run_script(absolute_profile);
49+
// run .ash_profile, checking it exists again just in case (because why not)
50+
if (await fs.exists(absolute_profile)) {
51+
await shell.run_script(absolute_profile);
52+
}
3653
}
3754

38-
// run .ollierc if it exists
39-
const absolute_rc = fs.absolute("~/.ollierc");
40-
await shell.run_script(absolute_rc);
55+
// run .ashrc, checking it exists again just in case (could be deleted in profile)
56+
if (await fs.exists(absolute_rc)) {
57+
await shell.run_script(absolute_rc);
58+
}
4159

4260
let running = true;
4361
let final_code = 0;

src/programs/selfdestruct.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ export default {
5555
term.writeln(`${NEWLINE}Thank you for using OllieOS!${NEWLINE}`);
5656

5757
// TODO: talk to ignition instead of using shutdown command
58-
return await kernel.spawn("shutdown", ["r", "-t", "3000"], shell).completion;
58+
return await kernel.spawn("shutdown", ["-r", "-t", "3000"], shell).completion;
5959
}
6060
} as Program;

0 commit comments

Comments
 (0)