How to auto shutdown under BlitzMax app?

Archives Forums/Linux Discussion/How to auto shutdown under BlitzMax app?

Space Fractal(Posted 2007) [#1]
On Windows, this is a plain easy task (Here for me, I was using a external app for that), but it seen it can't been done in Linux, because restrictions: You are not in root in Ubuntu (but did have enabled it), and you need to insert the password manual and I cant auto send the password in some way.

Here is what I trying and it wont work (but it find the command):

Local proc3:TProcess=TProcess.Create("sudo shutdown -h now",1)
If proc=Null 
	Print "Command Not Found"
Else
	Print "Command Found"
EndIf


Since I need it, because Im are converting a full screen jukebox application (running in a arcade or jukebox cabinet), and not a game.


D4NM4N(Posted 2007) [#2]
Not an expert but this is what id try:

First get rid of the need for sudo and 'users' alltogether (NOT RECOMMENDED NORMALLY! - but doesnt matter as its going to be an embeded, specialised & isolated system)

#sudo passwd root
enter a new UNIX password:

This will activate the superuser account.

You should then be able to LOGIN as root/su rather than a user so it runs the app with root permissions. You then shouldnt be prompted for password when the shutdown is called.

If tprocess still fails, What about this: (it might work)
create a file called 'shutdownscript' with execute permissions containing:
#!/bin/bash
shutdown -h now
then in your tprocess call:
Local proc3:TProcess=TProcess.Create("./shutdown",1)
another thing that might work if you cannot log in as root is to somehow give the default user root permissions (add to root group mabe?)

If all my semi-adept ranting above still doesnt work then ask on the ubuntu forums. In theory you can get linux to do practically anything you want with a bit of tweaking and what you are trying to do seems pretty straightforward. There should somehow also be a way of automatically booting straight in as root without the need for a login too.

Thinking about it, does linux even need to be 'shut down' if the entire file system is made 100% read only, with no swap? You had better ask someone that knows more, but i suspect it can be simply powered off as there is no possibility of any disk write.

On Windows, this is a plain easy task
LOL, They must be so proud of the fact ;P


Space Fractal(Posted 2007) [#3]
It still ask the password when I trying to run it as terminal application with the above "batch" file (it even I have enabled the root user).

When you first have typed it in, it does the job....

It just have a major problem:
MultiJuke (a jukebox application) which I have created, is designed to run in a arcade/jukebox cabinets without having a keyboard.

Typical it only have a joystick/trackball and few buttons.

That is why I trying to due that, so I can put in shutdown features back in MultiŽJuke. There are 2 methods to shutdown in MultiJuke (directly when pressed the quit key (ESC) or when the last song is played finished).


D4NM4N(Posted 2007) [#4]
It still ask the password when I trying to run it as terminal application with the above "batch" file (it even I have enabled the root user).

But are you logging in as root? If its asking for a password then the it is not running with root permission. (simply enabling the root account does not give your account extra permission)

In a terminal type 'su' and enter a root terminal, try shutdown, it shuts down immediately. Try running your app from a root terminal and it should run with the permissions of the user (root).
ie:
bring up terminal (note, when you switch to root u get a # not a $)
you@youpc:-$ su
password:
you@youpc:/home/you/yourprog# ./programname

This should run it as root so no passwords needed
(it works, i just tried it on the ./shutdownscript :)

I dunno if SU has a time out like sudo does :/ Ubuntu by default does not let you log in as 'root' from the main actual login screen, but this should be possible to dissable the login completely so it boots straight in as root. Ask on the UB forum, if no joy then try a different linux. Ive used several that let you log in directly as root.
PS: ive changed the name of my original script idea, calling it shutdown was dumb. Ive renamed it to shutdownscript!

LoL, i too have been working on an embedded dukebox program for a long time, but its far from finished. Good luck with it :)


D4NM4N(Posted 2007) [#5]
.


Space Fractal(Posted 2007) [#6]
It works when I login as root user first on the login screen (not tested from BlitzMax, but dobble click works directly without password).

I just like If I could do the same when using my normal username, since not all might like that (and some way got auto yped the password).

It could even been when running MultiJuke first, to do that done with a another script?

I guess I need to check and start a tread at Ubuntu Forums, but thanks for the answers :-).


Winni(Posted 2007) [#7]
I don't know how they do it on Linux, but on OS X there is a special authorization API for such purposes that you have to call first to obtain the necessary privileges. But even that OS X API will show an authorization dialog before it grants you the requested privileges; there is no way to pass the root password as an argument to the function call. And I think this is how it has to be.

I presume that GNU/Linux has a similar security API; you probably have to write a BlitzMax wrapper for it to use it properly.


Space Fractal(Posted 2007) [#8]
It would been nice, if there are any documentaion or some can make that wrapper.

I have a form for user input screen in my App, so I could let User input thier password on that way (MultiJuke do have such a password proctection itself when quit, which prettly would act the same as the security API would do).

The only problem is so, it on a fullscreen OpenGL, and not the desktop dialog I would like to the user type in the password.


jamesmintram(Posted 2007) [#9]
Hi, have a look at this site:

http://www.suphp.org/Home.html

That will allow you to write a very simple php script that should allow you to shut the computer down from any user account, simply call the script from your program. You need to set the owner of the script to root though, there may be other solutions for other scripting languages out there but I dont know any of them!