Wizards should always be able to run from console without X

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#16 Post by jpeps »

This seems to work:

Code: Select all

#!/bin/sh
VAR="$(echo $(tty) | cut -d: -f1 )"
if [ "$VAR" = "not a tty" ]; then
yaf-splash -text "clicked"
else
yaf-splash -text "in console"
fi

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#17 Post by technosaurus »

Code: Select all

#!/bin/sh
[ ! $DISPLAY ] && echo NoX && exit || \
[ $(tty) ] && yaf-splash -text Terminal && exit || \
yaf-splash -text Gui
or if you don't care if it is in a terminal you can simply use

Code: Select all

#!/bin/sh
[ $DISPLAY ] && yaf-splash -text X && exit || echo NoX
the second will be part of bashbox as a function called message

Code: Select all

message() {
[ $DISPLAY ] && yaf-splash -text "$@" && exit || echo "$@"
}
I also use this to pick what dialog to use:

Code: Select all

[ $DISPLAY ] && DIALOG=Xdialog || DIALOG=dialog
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

goingnuts
Posts: 932
Joined: Sun 07 Dec 2008, 13:33
Contact:

#18 Post by goingnuts »

Maybe I am missing the point (and excuse me if I am) but:
jpeps: I cant get your code to work from console.
technosaurus: cli/dialog-scripts run from console wont be able to run with your switches - but it will tell me why...

jpeps code indicate that there can be different output from tty so I rephrase my code suggestion to:

Code: Select all

#!/bin/sh
[ -n $DISPLAY ] && [ "$(tty | grep not)" ] && exec rxvt -e sh -c $0
echo "I am forced to be spawned from a shell...
and I could call cli, dialog, Xdialog, yaf-splash,
GTK-dialog or xmessage-content, dependent on which
environment I am in - instead of just using echo..."
read DUMMY

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#19 Post by technosaurus »

Yes - they will be able to run in the console - I tested it
I was just simplifying the logic so that the code is more readable,

It simply echoes "NoX" from the console (that is the code)
In a terminal it displays "Terminal" using yaf-splash
From a gui it displays "Gui" using yaf-splash

feel free to insert whatever necessary code at those points
The only reason I can see bothering with tty is if you think that Xdialog
would not be available. Then you would set DIALOG="rxvt -e dialog"
or something like that.

I made an automatic gui generator in bashbox that just accepts a set of inputs - it would be fairly simple to build a cli interface to it.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

goingnuts
Posts: 932
Joined: Sun 07 Dec 2008, 13:33
Contact:

#20 Post by goingnuts »

technosaurus:
:oops: you are right :oops: it works of course in console.
The only reason I can see bothering with tty is if you think that Xdialog would not be available
That is what I am trying to say - quoting myself:
Setup-wizards should as a minimum be able to run from shell without any GUI wrapped around it
I will change thread title to:
Wizards should always be able to run from shell/console without X...

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#21 Post by big_bass »

goingnuts"

I will change thread title to:
Wizards should always be able to run from shell/console without
I agree with the end goal
everybody goes about it a different way :?
I prefer a standard linux way that would work for most distros
removing all puppy code

one that installs packages
runs all the important set up scripts

that was the motive for suggesting slackwares
approach using pkgtool
as a well developed and practical working example
to use or just get good ideas from

before posting here in your thread
I spent many months digging into and re writing the code
doing a complete re write of over a thousand lines of code

while converting pkgtool from dialog to xdialog
I discovered some of the snags between syntax

if you make it for only one special puppy version
which is the trend its dead before it can mature

if you to make it more linux compatible
I would help

Joe

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#22 Post by technosaurus »

@gn
Running in the X terminal should be a user choice though. Some console based UIs would take a series of screens instead of a single interface. Many users would prefer that the "easier" interface come up when they quickly open a terminal and type in the name of utility XYZ. Having this method as default except on low-ram systems or if the user changes the value of USEGUIAPPSINTERM (or whatever)

@bb
I have done similar work with {X}dialog and for the workarounds of mismatched syntax,I had set up variables and to do something like:
$DIALOG (common_code_here) $DIALOGA$XDIALOGA ... $DIALOGZ$XDIALOGZ (more_common_code) 0 0
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#23 Post by jpeps »

going nuts:

I was testing Joe's script, clicking on programs from an icon vs from within a terminal loading gtkdialog3 or bacon apps where X is loaded; so [-n $DIALOG ] will always be true. Sorry for the muddle. :)

goingnuts
Posts: 932
Joined: Sun 07 Dec 2008, 13:33
Contact:

#24 Post by goingnuts »

Thank you all for the feed back! 8)

This thread was started mainly to make a statement and if possible, make creators of wizards think: Will this wizard always work? What happens if I screw up my GTK/Xdialog/Xmessage/Yaf-splash etc.?
If X is broken only a few of Puppys setup-scripts will work.

Setup-scripts is an important content of an OS - why not make it robust and functional under the barest conditions?

big_bass:
if you make it for only one special puppy version
which is the trend its dead before it can mature

if you to make it more linux compatible
I would help
I use the dialogfunctions.sh for my own purpose(=joy) - did not mean to create anything beyond that - only used it to make my point...but if it has any potential and the "more linux compatible" could be clarified for me...why not?

technosaurus
Running in the X terminal should be a user choice though
Fully agree! I see no contradiction between robust code and user choice (or coded best choice). The long series of dialogs is old school and should only be visible when needed - it should not exclude fancy one-shot setup GUIs.

jpeps:
Sorry for the muddle
I'm sorry - might have misused your example to promote my own statement... think [ -n $DISPLAY ] even might sometime give wrong result i console - maybe [ $DISPLAY ] is more secure?

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#25 Post by jpeps »

goingnuts wrote: .. think [ -n $DISPLAY ] even might sometime give wrong result i console - maybe [ $DISPLAY ] is more secure?
Both work the same on this end, as does [ "$(tty | grep not)" ]

goingnuts
Posts: 932
Joined: Sun 07 Dec 2008, 13:33
Contact:

#26 Post by goingnuts »

jpeps: After exit to prompt from X I get:
"Im in second part..."
"Im in first part..."
running the below script:

Code: Select all

#!/bin/sh
echo "Testing [ \$DISPLAY ]..."
if [ $DISPLAY ]; then
echo "Im in first part..."
else
echo "Im in second  part..."
fi

echo "Testing [ -n \$DISPLAY ]..."
if [ -n $DISPLAY ]; then
echo "Im in first part..."
else
echo "Im in second  part..."
fi
:?:
Its been a long day but below code (fragment to use in top of dialogfunctions.sh) seems to work clicking icon in rox, run from rxvt or run from console:

Code: Select all

TYPE="cli"		#dialog or cli
[ $(which dialog) ] && TYPE="dialog" && DIALOG=dialog
[ $(which Xdialog) ] && [ $DISPLAY ] && DIALOG=Xdialog
[ $DISPLAY ] && [ "$(tty | grep not)" ] && [ ! "${DIALOG}" = "Xdialog" ] && exec rxvt -e sh -c $0
where last line only there to take care of the rox-click...

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#27 Post by jpeps »

goingnuts wrote:jpeps: After exit to prompt from X I get:
"Im in second part..."
"Im in first part..."
running the below script:

Code: Select all

#!/bin/sh
echo "Testing [ \$DISPLAY ]..."
if [ $DISPLAY ]; then
echo "Im in first part..."
else
echo "Im in second  part..."
fi

echo "Testing [ -n \$DISPLAY ]..."
if [ -n $DISPLAY ]; then
echo "Im in first part..."
else
echo "Im in second  part..."
fi
:?:
try

Code: Select all

if [ -n "$DISPLAY" ]

goingnuts
Posts: 932
Joined: Sun 07 Dec 2008, 13:33
Contact:

#28 Post by goingnuts »

jpeps:
YES!
"$DISPLAY" seems to be the only reliable of the four possible
($DISPLAY, ${DISPLAY}, "$DISPLAY" and "${DISPLAY}") with or without the -n...

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#29 Post by 01micko »

Hi guys

I'm putting together a rescue pack, based on some of the work you guys have done here.

It will contain nothing more than a script that will download and install elinks and weechat, both a good browser and chat client outside of X respectively. The script will run inside of X too.

The idea is, that if a noob (or whoever) crashes X, they can just type 'help-NOX' at the prompt and a dialog will open asking if they want to download and install the packages. Once installed, another dialog will open up asking if they want to browse or chat.

Where i'm at now is the installation. I guess I should try this, but do any of you know if a pet will install at console level using petget? (ok, just tried, it was doomed to fail...) If not I guess I could tarball the package and expand and merge.

One thing I noticed .. when someone types 'help' at the prompt I think you end up with bash help, not real good for a noob. Any ideas on how to override this?

Cheers
Puppy Linux Blog - contact me for access

User avatar
upnorth
Posts: 287
Joined: Mon 11 Jan 2010, 19:32
Location: Wisconsin UTC-6 (-5 DST)
Contact:

installpkg.sh

#30 Post by upnorth »

Hi:
/usr/local/petget/installpkg.sh worked a couple months ago when i tried it.
I think it just takes an absolute path and package name as argument.

petget +package.pet may have worked at one time but now it demands gtk, but
petget -packagebasename worked for uninstalling.

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#31 Post by 01micko »

/usr/local/petget/installpkg.sh worked a couple months ago when i tried it.
I think it just takes an absolute path and package name as argument.
Thanks upnorth, I'll give that a try shortly.

Cheers
EDIT: that works upnorth, tho with errors, but I did manage to install elinks and am running outside of X right now, this is on a still warm burn of luci-240, latest woof

EDIT2: Ok, the app is up :D http://www.murga-linux.com/puppy/viewto ... 013#472013
Puppy Linux Blog - contact me for access

Post Reply