LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-24-2007, 04:58 PM   #1
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
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.
 
Old 06-24-2007, 05:42 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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.
 
Old 06-24-2007, 05:57 PM   #3
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Original Poster
Rep: Reputation: Disabled
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 )

Last edited by dive; 06-24-2007 at 06:19 PM.
 
Old 06-24-2007, 09:53 PM   #4
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Original Poster
Rep: Reputation: Disabled
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.

Last edited by dive; 06-24-2007 at 10:47 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
kdialog error pujansrt Linux - General 1 09-21-2006 10:27 AM
kdialog --menu command tardigrade Programming 2 01-17-2006 01:37 PM
Quick Challange for shell scripters! neocookie Programming 2 09-12-2005 10:13 AM
kdialog replacement Khabi Linux - Software 2 04-09-2005 01:10 AM
Variable info in kdialog? Klas Programming 1 01-08-2005 08:58 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration