MightyPirates / OpenComputers

Home of the OpenComputers mod for Minecraft.
https://oc.cil.li
Other
1.59k stars 432 forks source link

Autorun a program (1.6.0.4) #2171

Closed ExDomino closed 6 years ago

ExDomino commented 7 years ago

Hello, I would like to have a program that is automaticaly executed at the computer startup, but autorun.lua (either placed in "/" or in "home/") doesn't work. My goal is to have a program that runs at the startup and shows every print and allow user interaction, like a normal program executed manually, and if the program only does something like print("test"), the "test" would be printed between the greetings frame and the prompt. Thank you in advance!

SaphireLattice commented 7 years ago

You can edit the motd program for your end goal. It's /etc/motd.lua iirc? Something like that

On Sat, Dec 10, 2016, 12:47 ExDomino notifications@github.com wrote:

Hello, I would like to have a program that is automaticaly executed at the computer startup, but autorun.lua (either placed in "/" or in "home/") doesn't work. My goal is to have a program that runs at the startup and shows every print and allow user interaction, like a normal program executed manually, and if the program only does something like print("test"), the "test" would be printed between the greetings frame and the prompt. Thank you in advance!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/MightyPirates/OpenComputers/issues/2171, or mute the thread https://github.com/notifications/unsubscribe-auth/AEFMuNPQKWNr1c878Bxd-mQm5fz5cmJDks5rGj0CgaJpZM4LJkU2 .

Vexatos commented 7 years ago

There is also .shrc

payonel commented 7 years ago

I think I should make a ocdoc page specifically talking about boot scripts and similar needs. But briefly here I'll list your options. I'll save the more detailed howto for each of these to an ocdoc page

  1. /bin/rc can be used to enable boot level scripts. Hopefully in the future of openos this feature is given a pretty nice upgrade; today it is basic.
  2. /autorun.lua (and not /home/autorun.lua) can be used for scripts to execute on drives that are automounted by the filesystem. This doesn't apply to the rootfs. This definitely could use more explanation, please note that this definitely is not what you're looking for.
  3. /etc/profile is "sourced" (as a list of shell commands) each time the shell loads, not just every boot. (e.g. if the user types 'exit' in the shell, the shell would reload but the machine is not rebooting)
    • /home/.shrc is "sourced" via /etc/profile
    • note that /etc/motd is actually run via /etc/profile
  4. You can also create "boot" scripts (these are generally intended for system library initialization). The existing boot scripts are found in /boot, and are numbered to support load order. This system is deprecated (at least in my mind) and I would like to eventually retire this system, fair warning.
ExDomino commented 7 years ago

You could make that "/autorun.lua" is executed after the prompt? ComputerCraft has an easy way to autorun a program, why not OpenComputers?

dgelessus commented 7 years ago

@ExDomino When OpenOS mounts a drive, it checks if there is an autorun.lua on it, and runs it if there is one. (There is also an option in OpenOS's configuration that needs to be enabled for autorun to work.) Making the shell run autorun.lua would be confusing and problematic - autorun scripts are supposed to run when a drive is attached, not when a shell is started.

If you want to run something every time the shell is started, use /etc/profile, as @payonel described in point 3.

payonel commented 7 years ago

I recommend editing /home/.shrc rather than /etc/profile purely for organizational purposes. Again, these files are "sourced" (as shell commands) and not "lua executed". I'll keep further detailed walkthroughs to a ocdoc update.

Joapfel commented 6 years ago

how can I write to.shrc or etc/profile..its all readonly

skyem123 commented 6 years ago

@Joapfel, you need to install OpenOS to a hard drive first. Then you should be able to write files...

payonel commented 6 years ago

a reasonable stub: http://ocdoc.cil.li/tutorial:autorun_options

ExDomino commented 6 years ago

Sadly there is no way to have an autorun program in OpenComputers, except if you are an expert! For simple users, after hours of searching, this is simply impossible.

I wanted a computer that is always on, always loaded (by a chunker loader) but it is simply impossible to do so. Only robots can chunk load, they has no screen to debug, and it is just too complicated because the lot of "DRM" in the mod to keep it complicated for no reason.

This mod only exists because the stupid decision of ComputerCraft's authors to make their computers too easy to craft and without any need of power.

Timsuper commented 6 years ago

No. Just change to root directory / and create a file autorun.lua . Worked for me. My question: does it run in /home/ too?

ExDomino commented 6 years ago

/autorun.lua is not executed for rootfs! autorun.lua is only executed when a floppy disk is inserted, and not when the computer starts with this floppy disk already inserted, of course, else it would be really too easy.

And we cannot put a chunkloader into a microcontroller... because of a DRM. We need a robot just to simply chunk load a simple chunk in the spawn area.

ExDomino commented 6 years ago

And just a question: someone is supposed to tell me how to run the main script of a robot, that is located on the floppy disk, if the robot cannot autorun the file autorun.lua? Humm? Nobody?

skyem123 commented 6 years ago

write a Lua program, call it /home/whatever.lua. then make a file called /home/.shrc and put the line /home/whatever.lua as the contents. That should autostart the program.

payonel commented 6 years ago

autorun on the rootfs is run, just like all the others. what code does your autorun have?

RubenWindels1 commented 6 years ago

I dont know nothing about this mod but I want to install and run this program. https://pastebin.com/aKjh5SZL What do I have to do? I searched the internet but couldn't find it.

skyem123 commented 6 years ago

@SlimeGenX, that is not directly related to the issue. For more direct help, consider asking for help in the IRC channel or Discord Group.