Hello openSUSE users!
I wrote a small script which can make installing software in openSUSE a bit easier.
It uses software.opensuse.org: Search Results to search for packages.
Here’s the code:
#!/bin/sh
#License: GPL
if -e /tmp/qinst ] ; then
rm -r /tmp/qinst
fi
mkdir /tmp/qinst
############ Display usage if run without arguments
usage()
{
echo "Usage: ${0##*/} package_to_install [OPTIONS]
This script helps you to install software that is not available in standard openSUSE repositories.
[OPTIONS]:
home - search also in user's home projects
factory - search in Factory repositories (be careful, it may harm your system!)
Examples:
${0##*/} gimp Search for gimp. If it won't be found, it will be searched in user's home projects.
${0##*/} gimp home Search for gimp also in user's home projects
${0##*/} gimp factory Search for gimp in openSUSE Factory
${0##*/} gimp home factory Search for gimp in openSUSE Factory & in user's home projects
" >&2
exit $1
}
if $# -eq 0 ]
then
usage 1
fi
######### Check openSUSE version
suse=$(cat /etc/SuSE-release | sed -n 1p|cut -d '(' -f1| sed -e 's/ *$//'|sed 's/ /%3A/g')
if "$2" = "factory" ] || "$3" = "factory" ] ; then
echo "Using Factory repositories"
suse="openSUSE%3AFactory"
fi
url="http://software.opensuse.org/search?q=$1&baseproject=$suse&exclude_debug=true"
######### Check if user's home projects should be enabled
if "$2" = "home" ] || "$3" = "home" ] ; then
echo "Using user's home projects"
url=$url"&include_home=true"
fi
echo ""
####### Download page, export links & repository names
wget -q -U "Mozilla/5.001" -O /tmp/qinst/w $url
if $(cat /tmp/qinst/w|grep -c '<div class="search_o_wrapper">') -ne 0 ]; then
cat /tmp/qinst/w|grep -A40 '<div class="search_o_wrapper">'|grep -A5 '"pkg_list"'|grep '.rpm</a>'|cut -d '>' -f2|cut -d '<' -f1 >> /tmp/qinst/rpm.txt
cat /tmp/qinst/w|grep -A40 '<div class="search_o_wrapper">'|grep ymp|cut -d '"' -f2 >> /tmp/qinst/links.txt
cat /tmp/qinst/w|grep -A40 '<div class="search_o_wrapper">'|grep "blue_over"|cut -d '>' -f2|cut -d '<' -f1 >> /tmp/qinst/repos.txt
#cat -n /tmp/qinst/rpm.txt
N=0
cat /tmp/qinst/rpm.txt | while read LINE ; do
N=$((N+1))
echo " $N = $LINE" " from repository "$(sed -n "$N p" /tmp/qinst/repos.txt)
done
echo "Type package number to install and press Enter (0 to abort):"
read which
if $which -eq 0 ]; then
exit 0
fi
if $which -gt $(cat /tmp/qinst/w|grep -c '<div class="search_o_wrapper">') ]; then
echo "Wrong package number, aborting..."
exit 0
fi
####### Download ymp and install
line=$(sed -n "$which p" /tmp/qinst/links.txt)
wget -q -O /tmp/qinst/inst.ymp http://software.opensuse.org$line
rm /tmp/qinst/links.txt
rm /tmp/qinst/rpm.txt
rm /tmp/qinst/repos.txt
rm /tmp/qinst/w
echo -e 'Now installing...'
sudo /sbin/OCICLI /tmp/qinst/inst.ymp
RETVAL=$?
$RETVAL -eq 0 ] && echo Installation successful
$RETVAL -ne 0 ] && echo Installation failed or aborted by user
rm /tmp/qinst/inst.ymp
rm -r /tmp/qinst
exit 0
############### If not found & home option not set, search in user's home projects
elif "$2" != "home" ] && "$3" != "home" ] ; then
echo "$1 not found. Searching again, with user's home projects enabled..."
if "$2" = "factory" ] || "$3" = "factory" ] ; then
exec $0 $1 home factory
else
exec $0 $1 home
fi
exit 0
############# If not found anywhere
else echo "$1 not found."
fi
Paste it to a text file (qinst for example) and remember to make it executable:
chmod +x ~/bin/qinst
Then you can use it like that:
qinst package_name
When a package isn’t available in standard openSUSE repositories, my script will search for it in other repositories. You can select a version to install. It is also possible to search in Factory repositories like that:
qinst package_name factory
After you select version to install, this script will download one-click installer and run it in YAST.
I hope somebody will find it useful.