LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Any kdialog scripters here? (http://www.linuxquestions.org/questions/programming-9/any-kdialog-scripters-here-564215/)

dive 06-24-2007 05:58 PM

Any kdialog scripters here?
 
I'd like to find out why this doesn't work:

Code:

pname=urlview # this will come from an input box in the finished script
 slapt-get --search ${pname} > temp

 let n=4
 let pn=0

 for f in `cat temp`
    do
        let n=$n+1
        if  [[ $n == 5 ]]; then
            let pn=$pn+1
            let n=1
            pkg[$pn]=$f
            echo ${pn} ${pkg[${pn}]}
        fi
    done

 let n=0

 IFS=$'\n'
 for f in `cat temp`
    do
        let n=$n+1
        line[$n]=$f
        echo $n ${line[${n}]}
    done


 for (( f=1; f<=$pn; f++ ))
    do
        RESULTS+='"'${pkg[${f}]}'"'" "'"'${line[${f}]}'"'" "off" "
    done

 echo kdialog --radiolist "Search Results" ${RESULTS}
 DISPLAY=":0.0" kdialog --radiolist "Search Results" ${RESULTS}

It all works except the final kdialog. It works if I copy the echoed ouput into command line and run it, just not from within the script. There are no error messages - just says 'kbuildsycoca running...' and then exits.

unSpawn 06-24-2007 06:42 PM

I'd say verify your RESULTS var first (as in "sh -x scriptname"). If I run "DISPLAY=":0.0" kdialog --radiolist "Search Results" tag1 item1 status1 tag2 item2 status2" from a script in an xterm I do get the list.

dive 06-24-2007 06:57 PM

It seems to be adding extra single quotes around the tag/item/status line - ie

"search results" '"tag1" "items1" status1 "tag2"... '

At least that is the output of the -x switch. Running that on the command line breaks it so I need a way to take out those single quotes...

Or in other words it's treating it as a whole string and not in sets of 3 (I think :) )

dive 06-24-2007 10:53 PM

Ok. Result is that I've had to store info in temp files and then 'cat' them to kdialog. I don't like doing this but it was the only way I could get it to work. But it does have the bonus of being much faster than a=`kdialog ...` for some reason.

The code below allows you to search with slapt-get and install packages. I wrote it because I was a bit fed up with going to linuxpackages.net in a browser. It may be useful to some people.

Code:

#!/bin/bash

 DISPLAY=":0.0"
 rm slapt-results 2>/dev/null
 rm slapt-search 2>/dev/null
 rm slapt-temp 2>/dev/null
 rm slapt-output 2>/dev/null

 function quit
 {
    rm slapt-results 2>/dev/null
    rm slapt-search 2>/dev/null
    rm slapt-temp 2>/dev/null
    rm slapt-output 2>/dev/null
    exit 0
 }

 function not_found
 {
    kdialog --error "Not Found!"
    quit
 }
 kdialog --caption "Package Search" --inputbox "Slapt-Get Package Search" > slapt-search || quit
 sudo /usr/sbin/slapt-get --search `cat slapt-search` > slapt-temp

 let n=4
 let pn=1

 for f in `cat slapt-temp | awk {'print $1'}`
    do
        pkg[$pn]=${f}
        let pn+=1
    done
 [[ ${pkg[1]} == "" ]] && not_found

 let n=0

 IFS=$'\n'
 for f in `cat slapt-temp`
    do
        let n=$n+1
        line[$n]=$f
    done


 for (( f=1; f<$pn; f++ ))
    do
        echo ${pkg[$f]} >> slapt-results
        echo ${line[$f]} >> slapt-results
        echo off >> slapt-results
    done

 rm slapt-temp 2>/dev/null

 kdialog --caption "Search Results" --radiolist "Search Results" `cat slapt-results` --geometry 500x600 > slapt-temp || quit

 package=`cat slapt-temp`
 kdialog --title Installing --passivepopup "This may take some time." 30 &
 output=`sudo /usr/sbin/slapt-get --install ${package}`

 echo "${output}" | sed '/\[/d' > slapt-output
 installedmsg=`cat slapt-output | head -n 6`

 if [[ `cat slapt-output | grep "is up to date"` ]]
 then
    killall kdialog
    kdialog --caption "Package Up To Date" --msgbox "${output}"
    quit
 else
    killall kdialog
    kdialog --caption "Slapt-Get Output" --textbox slapt-output 500 400
 fi

 quit

P.S. It's probably buggy ;)

*Edit: all the code didn't paste - fixed now

Ah, it contains some 'sudo' lines. If you don't have ability to sudo without password remove the 'sudo's and run it as root. Should work if you do 'xhost +local:' as user.


All times are GMT -5. The time now is 04:59 AM.