I want to create simple .sh script which will include binary package with my program and will copy it to destination folders. During Installation I want to show gui messages to imform user that all is ok. Seems like zenity from this question is that I need How to show a GUI message box from a bash script in linux? But how to supply it with my single .sh script? (User should run installer from anywhere without any additional actions). Is there something universal for most common distributions of linux? Maybe "xmessage", but it looks very poor. Something else?
-
Why would one want to do that? This violates all good practices introduced with the software management systems on linux systems. Why wouldn't you use the package management instead of creating your own installer? No sane system administrator will trust it. Apart from that using the existing package management system in any linux distribution is much more comfortable and secure. – arkascha Apr 06 '15 at 13:47
-
Package management differs in different distributives, I have no idea what distrs will use my users, and creating all possible packages seems unjustified for my small program. And this program not for system administrators. Furthermore, for my embedded speciality I work alot with proprietary linux programs with universal installers (e.g. Xilinx ISE web pack and Quartus) and it all works good on Ubuntu and on my ArchLinux distributians. – Ivan Borshchov Apr 06 '15 at 13:55
-
1I never disputed that such custom installer work. I stated that no sane administrator with use them, since there is no way to tell what they do to a system. Why would one hand over full administrative rights over one's system to someone one does not know, have no idea about his motivation? There are not that many package formats, actually just 2 or 3 that are somewhat widespread. Take a look at opensuse's OpenBuildService. It allows you to create clean packages for many distributions and even offers download repositories. Can't get more comfortable... – arkascha Apr 06 '15 at 14:05
1 Answers
Anything like xmessage or zenity or gxmessage implies external dependencies that you cannot guarantee will be available (unless you can; you haven't said so in your question). To answer one of your questions, NO, there is nothing universal for Linux. Certainly not anything that depends on X, since so many Linux installations are headless.
For "something else", as a general principle, being self-contained is a good idea. That means using something that doesn't even depend on the X Window System. Shell based dialogs are readily available, whether you're in FreeBSD or Linux.
To be truly self-contained as well as portable (even between different distros of Linux, or different server configurations), I'd suggest writing your own dialog manager as a function within your shell script. Something along the lines of this:
#!/usr/bin/env bash
# A supporting function to see test a value against the contents of an array
is_in() {
value=$1; shift
for i in "$@"; do [[ $i == $value ]] && return 0; done
return 1
}
# Simple dialog implementation, no VT100 required,
dialog() {
# $options is an array of options
local i line max=0
# determine dialog width
for line in "${options[@]}"; do [[ ${#line} -gt $max ]] && max=${#line}; done
# draw a line
eval printf '%.s-' {1..$((max+8))}; echo
# print each option
for i in ${!options[@]}; do
printf "| %2d: %-${max}s |\n" "$i" "${options[i]}"
done
eval printf '%.s-' {1..$((max+8))}; echo
response=""
# only accept valid responses
while ! is_in "$response" "${!options[@]}"; do
read -p " Choose: " response
done
return "$response"
}
# Create our list, run the dialog, capture the result,
options=([1]="Hello world" [2]="This is a test")
dialog
result=$?
# And display the result.
echo "RESPONSE: $result / ${options[$result]}"

- 45,319
- 8
- 65
- 104