Suggestion: use "dialog" to create some nice menus

Suggestion: use "dialog" to create some nice menus

Postby hbuhrmester » 07.12.2013, 20:50

dialog can be used to create menus and input boxes in the shell. These dialogs can be navigated with the mouse and the cursor keys, the number keys, or by typing the first letter of each line.

I have prepared a sample skript of what it could look like:

Code: Select all
#!/bin/bash

# Sample skript for a possible usage of "dialog"

OS_sys=$(dialog --no-cancel --stdout --menu "Please select your OS" 0 0 0 \
"wxp-x86" "Windows XP" \
"wxp-x64" "Windows XP 64-bit" \
"w2k3-x86" "Windows Server 2003" \
"w2k3-x64" "Windows Server 2003 64-bit" \
"w60-x86" "Windows Vista / Server 2008" \
"w60-x64" "Windows Vista / Server 2008 64-bit" \
"w61-x86" "Windows 7" \
"w61-x64" "Windows 7 / Server 2008 R2 64-bit" \
"w62-x86" "Windows 8.0" \
"w62-x64" "Windows 8.0 / Server 2012 64 bit" \
"w63-x86" "Windows 8.1" \
"w63-x64" "Windows 8.1 64 bit" \
"all-x86" "All 32 bit" \
"all-x64" "All 64 bit" )

lang=$(dialog --no-cancel --stdout --menu "Please select your OS language" 0 0 0 \
"enu" "English" \
"deu" "German" \
"nld" "Dutch" \
"esn" "Spanish" \
"fra" "French" \
"ptg" "Portuguese" \
"ptb" "Portuguese (Brasil)" \
"ita" "Italian" \
"rus" "Russian" \
"plk" "Polish" \
"ell" "Greek" \
"csy" "Czech" \
"dan" "Danish" \
"nor" "Norwegian" \
"sve" "Swedish" \
"fin" "Finnish" \
"jpn" "Japanese" \
"kor" "Korean" \
"chs" "Chinese" \
"cht" "Chinese (Taiwan)" \
"hun" "Hungarian" \
"trk" "Turkish" \
"ara" "Arabic" \
"heb" "Hebrew" )

params=$(dialog --no-cancel --stdout --checklist "Select your download options" 0 0 0 \
"excludesp" "Exclude Service Packs" on \
"dotnet" "Download .Net framework" on \
"msse" "Download Microsoft Security Essentials files" off \
"wddefs" "Download Microsoft Windows Defender definition files" off \
"makeiso" "Create ISO-Image after download" on )

http_proxy=$(dialog --backtitle "WSUS Offline Update" --title "Proxy selection" --no-cancel --stdout --inputbox "Please specify your proxy (default: none, http://[username:password@]<server>:<port>])" 0 0)

dialog --backtitle "WSUS Offline Update" --title "Summary" --yesno "Your Choice \n\n\
  System: $OS_sys \n\
  Language: $lang \n\
  Parameter: $params \n\
  Proxy: $http_proxy \n\n\
Do you wish to download now?" 0 0

# Possible return status in $?
# 0 = OK-Button
# 1 = Cancel-Button
# 255 = Escape-Key

case $? in
  0)
    echo "OK";;
  1)
    echo "Cancel pressed.";;
  255)
    echo "ESC pressed.";;
esac


This could even make the maintenance easier, since dialog can return the needed variables.

Just make sure, that "dialog" is installed. Debian uses a replacement with a silly name instead (http://packages.debian.org/wheezy/whiptail).

Greetings,

Hartmut Buhrmester
hbuhrmester
 
Posts: 525
Joined: 11.10.2013, 20:59

Re: Suggestion: use "dialog" to create some nice menus

Postby oiaohm » 17.12.2013, 01:51

hbuhrmester I would not recommend do dialog the way you are.

whiptail is one of the dialog compadible relatiions but whiptail backend is completely different. The three to check for to cover most distrobutions is dialog, xdialog and whiptail.

dialog command be a varaible makes a lot of sense with a little bit of detection to choose what one to use so not forcing extra packages to be installed.
oiaohm
 

Re: Suggestion: use "dialog" to create some nice menus

Postby hhullen » 31.01.2014, 17:02

hbuhrmester wrote:dialog can be used to create menus and input boxes in the shell. These dialogs can be navigated with the mouse and the cursor keys, the number keys, or by typing the first letter of each line.
[...]

Greetings,

Hartmut Buhrmester


Sorry - that's no good idea.
I like to use "dialog" in other programs, but "wsusoffline" cannot expect that this program is available on the special machine where "wsusoffline" runs. And I prefer scripts which need only very few additional programs.
Viele Grüsse
Helmut
hhullen
 
Posts: 100
Joined: 23.04.2012, 10:43

Re: Suggestion: use "dialog" to create some nice menus

Postby aker » 31.01.2014, 23:42

@hhullen
What about just using "dialog" if it is installed?
Wer Rechtschreibfehler findet, darf sie behalten oder an den Meistbietenden versteigern. / Everybody finding a misspelling is allowed to keep or sell it.
aker

WSUS Offline Update „Community Edition“
https://gitlab.com/wsusoffline/wsusoffline/-/releases
aker
 
Posts: 3999
Joined: 02.03.2011, 15:32

Re: Suggestion: use "dialog" to create some nice menus

Postby hhullen » 01.02.2014, 11:43

aker wrote:@hhullen
What about just using "dialog" if it is installed?


Das möchte ich mindestens in diesem Jahr nicht ergänzen/umschreiben: da müsste einmal die bisherige ganz simple Abfrage der Parameter weiterbetreut werden und zusätzlich die (schöneren) "dialog"-Fenster.

Randproblem: Debuggen (bei der "bash": Anzeige der jeweiligen Operation) ist mit "dialog" erheblich umständlicher, und ich möchte auf die Debug-Möglichkeit nicht verzichten (und sie soll mir auch keine zusätzliche Arbeit bescheren).

Eher grundsätzlich: vermutlich wird die Linux-Version von "wsusoffline" überwiegend als Cronjob eingesetzt, und da ist "interaktiv" sowieso unnütz.
Viele Grüsse
Helmut
hhullen
 
Posts: 100
Joined: 23.04.2012, 10:43


Return to Linux

Who is online

Users browsing this forum: No registered users and 43 guests