You are not logged in.

#1 2005-10-09 12:42:07

Cam
Member
From: Brisbane, Aus
Registered: 2004-12-21
Posts: 658
Website

Xdialog pacman installer thing

I put this together while I'm waiting for some songs to upload to my ipod, I used the MIME editor from dibbles repo to create a MIME type for *.pkg.tar.gz files and associated them with this script in ROX. Works well from what I can see, does anyone else think it's a decent idea, see any glaring holes in my code, something I've missed, wants to punch me for doing something stupid? I'm pretty crap at bash scripting so there's probably something wrong with my code, but now I don't need to open up a terminal, cd around to install a local package. Just seems neat is all, feedback welcome.

#!/bin/bash

file=$1

usage() {
  echo "usage: $0 package"
  echo "    package should be a local *.pkg.tar.gz package for pacman to install"
  echo
  exit 0
}

test_stuff() {
  Xdialog --version &> /dev/null
  if [ $? -ne 0 ]; then
    echo "error: this script needs Xdialog installed and in your $PATH to work, quitting..."
    echo
    exit 0
  fi
  
  if [ -r $file ]; then
    pacman -Qpi $file &> /dev/null
    if [ $? -ne 0 ]; then
      Xdialog --title "Error" --msgbox "Supplied file is not a valid package for pacman, quitting..." 10 75
      exit 0
    fi
  else
    Xdialog --title "Error" --msgbox "File doesn't exist, quitting..." 10 75
    exit 0
  fi
}

if [ $# -eq 0 ] || [ $1 = "--help" ]; then
  usage
fi

test_stuff
pkg=`pacman -Qpi $1 | sed -e '2,20d' -e 's/Name.*: //'`
Xdialog --title "Warning" --msgbox "This will install $pkg, are you sure you want to continue?" 10 75
if [ $? -eq 0 ]; then
  pacman -U $1 | Xdialog --title "Installing" --smooth --tailbox - 10 75
  if [ $? -eq 0 ]; then
    Xdialog --title "Success" --msgbox "Installation successful!" 10 75
    exit 0
  else
    Xdialog --title "Failed" --msgbox "Installation failed!" 10 75
    exit 0
  fi
fi

exit 0

Offline

#2 2005-10-09 14:05:04

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: Xdialog pacman installer thing

Cam wrote:

[...].. see any glaring holes in my code, something I've missed...[...]

just a few suggestions:

  Xdialog --version &> /dev/null
  if [ $? -ne 0 ]; then
    echo "error: this script needs Xdialog installed and in your $PATH to work, quitting..."
    echo
    exit 0
  fi

"type -p" is a way of testing if a program exists and is in PATH:

if [ ! $(type -p Xdialog) ]; then
     echo error messages here and exit
fi

You probably should have it check for root user before doing anyting or exit with usage:

if [ $(-id -u) -ne 0 ]; then
       echo error message and exit
fi

[/code]

Offline

#3 2005-10-11 12:31:03

bogomipz
Member
From: Oslo, Norway
Registered: 2003-11-23
Posts: 169

Re: Xdialog pacman installer thing

Suggestions:

1) It could check if a version of the package is already installed and use -U if it is -A if it isn't, and inform the user of both the new and old version of the package.

2) As I don't suppose you run ROX as root, it should run pacman with either su or sudo. Preferably the latter, although this requires it to be installed and properly configured.

3) A simpler one; exit with a non-zero value on failure.

EDIT: #2 would also require a graphical password request.


All of your mips are belong to us!!

Offline

#4 2005-10-12 10:07:14

Cam
Member
From: Brisbane, Aus
Registered: 2004-12-21
Posts: 658
Website

Re: Xdialog pacman installer thing

2) As I don't suppose you run ROX as root, it should run pacman with either su or sudo. Preferably the latter, although this requires it to be installed and properly configured.

EDIT: #2 would also require a graphical password request.

Correct, I don't run ROX as root. I put sudo in front of it but I removed it before I posted here to allow a bit of imagination wink sudo, gksu, k* version of sksu, they'd all work, just left it blank so if anyone wanted to use it they could figure out their own way of handling that.

As for the other suggestions, all good. I'll implement them and update my original post big_smile

Offline

#5 2005-10-12 12:05:59

bogomipz
Member
From: Oslo, Norway
Registered: 2003-11-23
Posts: 169

Re: Xdialog pacman installer thing

I just spotted one more thing. Make sure you do file="$1" and also add quotes wherever you use the variable later (like [ -r "$file" ], pacman -A "$file"). Otherwise the user will get "Supplied file is not a valid package for pacman, quitting..." if the path to the file has whitespace in it (for instance the directory was called "downloaded packages").


All of your mips are belong to us!!

Offline

Board footer

Powered by FluxBB