3

I am making a search and install PPA script for Ubuntu. This script with zenity works 80%, the problem is when this script searches; displays only the first line. I need all lines

#!/bin/sh

# simple search and install PPA
# by David Vásquez


if [ $# -gt 0 ] ; then
    echo "$*"
else
    echo "No input"
exit
fi

code=$*

cat /dev/null > /tmp/ppa
cat /dev/null > /tmp/ppa-url-tmp


mojito=$(curl https://launchpad.net/ubuntu/+ppas?name_filter=$code | grep -e '+archive/' | grep "$code" | awk -F'<td><a href="/~' '{print $2}' | awk -F'">' '{print $1}' | uniq | tr -d '~')

echo $mojito | tr ' ' '\n' | tee -a /tmp/ppa-url-tmp




file="/tmp/ppa-url-tmp"
while IFS= read -r line; do
        # display $line or do somthing with $line
title=$(curl https://launchpad.net/~$line | grep -e '<title>'  | awk -F '<title>' '{print $2}' | awk -F '</title>' '{print $1}' | sed 's/^/"/' | sed 's/$/"/')


description=$(curl https://launchpad.net/~$line | grep -e 'content='  | awk -F 'content="' '{print $2}' | awk -F '.' '{print $1}' | tr -d '/>' | tr -d '"' | sed -e :a -e N -e 's/\n/ /' -e ta | sed 's/^/"/' | sed 's/$/"/') 


support=$(curl https://launchpad.net/~$line | grep -e '<option value='  | grep [0-9] | awk -F '(' '{print $2}' | awk -F ')' '{print $1}' | sed -e :a -e N -e 's/\n/ /' -e ta | awk '{print $1, $2, $3}' | sed 's/^/"/' | sed 's/$/"/' )


echo $title $description $support $line | uniq -u | tee -a /tmp/ppa

zenity --list --radiolist --title="Package installation." --text="Select package to be installed" --width=800 --height=500 --column=In --column=Name --column=Description --column=Compatible --column=PPA "in" "$title" "$description" "$support" "$line"

if [[ "$?" != 0 ]]; then
exit
else

CHECK_INST=$(echo $CHECK | awk -F'|' '{print $5}')

sudo apt-add-repository $CHECK_INST
sudo apt-get -y update
sudo apt-get install $code
fi

done <"$file"

My other attempt here (same results)

From terminal a example

myscript pipelight

enter image description here

5
  • @slm if you test: myscript pipeligth s28.postimg.org/47gop2p25/ppaserch.png Commented May 31, 2014 at 9:27
  • For all also You can see all lines in /tmp/ppa ;) Commented May 31, 2014 at 9:48
  • @slm I had the same result if I change zenity out the while loop :/ Commented May 31, 2014 at 9:53
  • @slm I need the entire list. In my 3 test dl.dropboxusercontent.com/u/76388877/ppa-installerf-zenity3 I had the same result :/ Commented May 31, 2014 at 10:06
  • @slm exactly! How did you do? What is wrong with my code? Commented May 31, 2014 at 16:52

1 Answer 1

3

From your description and code it sounds like you're looking for something like this:

    ss #1

To get a dialog that's constructed like this your original script needed to be augmented in a few key ways. For starters you need to move the call to construct the zenity dialog so that it's outside your while loop that's collecting all the data about the various PPAs.

The other thing lacking was a data structure to store all the bits about the PPAs that you were collecting. For this a Bash array makes the perfect "container" for this data.

lines=("${lines[@]}" "FALSE" "$title" "$description" "$support" "$line")

This will continue to append the results that you collect via the while loop to an array called lines. This array is then given to zenity, it contains the column data.

Complete script

Here's the whole thing put together, which produced the above screenshot of the dialog.

#!/bin/bash

file="ppa-url-tmp"

lines=()
while IFS= read -r line; do
        # display $line or do somthing with $line
title=$(curl https://launchpad.net/~$line | grep -e '<title>'  | awk -F '<title>' '{print $2}' | \
    awk -F '</title>' '{print $1}' | sed 's/^/"/' | sed 's/$/"/')


description=$(curl https://launchpad.net/~$line | grep -e 'content='  | awk -F 'content="' '{print $2}' | \
    awk -F '.' '{print $1}' | tr -d '/>' | tr -d '"' | sed -e :a -e N -e 's/\n/ /' -e ta | sed 's/^/"/' | sed 's/$/"/') 


support=$(curl https://launchpad.net/~$line | grep -e '<option value='  | grep [0-9] | awk -F '(' '{print $2}' | \
    awk -F ')' '{print $1}' | sed -e :a -e N -e 's/\n/ /' -e ta | awk '{print $1, $2, $3}' | sed 's/^/"/' | sed 's/$/"/' )

echo $title $description $support $line | uniq -u | tee -a /tmp/ppa
lines=("${lines[@]}" "FALSE" "$title" "$description" "$support" "$line")

done <"$file"

zenity --list --radiolist --title="Package installation." --text="Select package to be installed" \
    --width=800 --height=500 --column=In --column=Name --column=Description --column=Compatible --column=PPA "${lines[@]}"

if [[ "$?" != 0 ]]; then
  exit
else

  CHECK_INST=$(echo $CHECK | awk -F'|' '{print $5}')

  sudo apt-add-repository $CHECK_INST
  sudo apt-get -y update
  sudo apt-get install $code
fi

Additional debugging tip

When you're unclear what something is doing in a Bash script reach for the commands set -x and set +x. These will enable and disable Bash's verbosity which can really help shed light on what's going on. Here's my zenity command with just verbosity turned up for it:

set -x
zenity --list --radiolist --title="Package installation." --text="Select package to be installed" \
    --width=800 --height=500 --column=In --column=Name --column=Description --column=Compatible --column=PPA "${lines[@]}"
set +x

And here's what it looks like when I run ./myscript ...:

+ zenity --list --radiolist '--title=Package installation.' '--text=Select package to be installed' --width=800 --height=500 --column=In --column=Name --column=Description --column=Compatible --column=PPA FALSE '"pipelight-daily : Michael Müller"' '"This PPA provides daily builds of the Pipelight project pipelight-daily "' '"14.04 13.10 13.04"' mqchael/+archive/pipelight-daily FALSE '"Pipelight : Michael Müller"' '"Pipelight allows one to run Silverlight inside a Linux browser using Wine Pipelight "' '"14.04 13.10 13.04"' mqchael/+archive/pipelight FALSE '"pipelight-experimental : “Pipelight Dev Team” team"' '"Experimental packages for Pipelight  pipelight-experimental "' '"14.04 13.10 13.04"' pipelight/+archive/experimental FALSE '"pipelight-daily : “Pipelight Dev Team” team"' '"pipelight-daily "' '"14.10 14.04 13.10"' pipelight/+archive/daily FALSE '"pipelight-stable : “Pipelight Dev Team” team"' '"pipelight-stable "' '"14.10 14.04 13.10"' pipelight/+archive/stable FALSE '"libva : “Pipelight Dev Team” team"' '"libva "' '"13.10 12.10 12.04"' pipelight/+archive/libva
+ set +x

The above reveals how all the column components are expanded, properly quoted, by the use of "${lines[@]}".

4
  • Thanks my friend! it worked, thanks for explain. This script going to help to much people. Commented Jun 1, 2014 at 8:27
  • 1
    @davidva - glad to have been of help and thanks for the interesting Q. Good luck! Commented Jun 1, 2014 at 12:19
  • I attempted in Xubuntu doesn't read 'lines=("${lines[@]}" "FALSE" "$title" "$description" "$support" "$line")" . This is the output: 'Syntax error: "(" unexpected (expecting "done").' I do not understand. But in Fedora, Arch Linux works :/ Commented Jun 2, 2014 at 4:56
  • Solved! only change the first line #!/bin/sh to #!/bin/bash Commented Jun 2, 2014 at 5:30

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.