File indexing completed on 2024-04-28 16:44:10

0001 #!/bin/sh
0002 #
0003 # SPDX-FileCopyrightText: 2009 George Kiagiadakis <kiagiadakis.george@gmail.com>
0004 #
0005 # SPDX-License-Identifier: GPL-2.0-or-later
0006 
0007 
0008 # This function runs a command in a terminal
0009 # The first argument ($1) must be the full command to run.
0010 # It returns 0 if the command finished or 1 if the user closed
0011 # the terminal without waiting for the command to finish.
0012 # The return value of the command is saved in the $exit_status variable.
0013 run_in_terminal()
0014 {
0015     local fifo=/tmp/drkonqi-fifo-$$
0016     mkfifo $fifo
0017 
0018     # start terminal
0019     konsole -e sh -c "echo \$\$ > $fifo; $1; exit_status=\$?; sleep 1; rm $fifo; echo \$exit_status > $fifo" &
0020 
0021     # wait for it to finish
0022     local pid=`cat $fifo`
0023     while [ "$?" = "0" ]; do
0024         sleep 1
0025         kill -0 $pid 2>/dev/null
0026     done
0027 
0028     # check if terminal has finished succesfully and return the command's exit status
0029     local canceled=0
0030     if [ -p $fifo ]; then
0031         # terminal was closed before finishing execution
0032         canceled=1
0033     else
0034         exit_status=`cat $fifo`
0035         #echo "\"$1\" returned: $exit_status"
0036     fi
0037     rm $fifo
0038     return $canceled
0039 }
0040 
0041 # check misc script dependencies
0042 check_dep()
0043 {
0044     which $1 >/dev/null
0045     if [ "$?" != "0" ]; then
0046         # check for availability of kdialog
0047         which kdialog >/dev/null
0048         if [ "$?" != "0" ]; then
0049             xmessage -center "$1 was not found on your system. Please install $1 and try again."
0050         else
0051             kdialog --sorry "$1 was not found on your system. Please install $1 and try again."
0052         fi
0053         exit 1
0054     fi
0055 }
0056 
0057 check_dep debuginfo-install
0058 check_dep konsole
0059 
0060 # start searching for packages
0061 packages=""
0062 while [ "$1" != "" ];
0063 do
0064     package=`rpm -q --whatprovides "$1" --queryformat "%{NAME}"`
0065     packages="$packages $package"
0066     shift
0067 done
0068 
0069 # filter out duplicates
0070 packages=`echo "$packages" | tr " " "\n" | sort | uniq | tr "\n" " "`
0071 
0072 run_in_terminal "su -c \"debuginfo-install $packages\""
0073 
0074 if [ "$?" = "1" ]; then
0075     exit 3
0076 elif [ "$exit_status" = "0" ]; then
0077     exit 0
0078 else
0079     exit 1
0080 fi