#!/bin/bash # # netsrpm-install.sh - Build srpms that download sources from network # # Copyright (C) 2003-2013 by Silvan Calarco # Copyright (C) 2005 by Massimo Pintore # Copyright (C) 2005-2007 by Davide Madrisan me="${0##*/}" DISTRO_SRPMS_DIR=/usr/share/openmamba/SRPMS rpmdir=$(rpm --eval=%{_rpmdir} 2>/dev/null) while [ "$1" ]; do case $1 in -c) CHECK_MODE=1 ;; -f) FORCE_MODE=1 ;; -u) UPGRADE_MODE=1 ;; -h|--help) PACKAGES= ; break ;; -*) echo "Error: invalid option $1; aborting."; exit 1 ;; *) PACKAGES="$PACKAGES $1" esac shift done if [ -z "$PACKAGES" ]; then echo "Usage: $me [options...] pkgname ... Options: -c: only check and exit (returns: 0: up-to-date; 1: needs update; 2: not installed) -f: force reinstallation if already installed -u: only upgrade if already installed " exit 255 fi function check_if_already_installed() { rpm -q $1 &>/dev/null if [ $? -eq 0 ]; then notify-send -a $"Network software installation" -i $icon "$pckname" "$pckname: "$"already installed." fi } for pckname in $PACKAGES; do icon=`grep Icon= /usr/share/applications/openmamba-$pckname.desktop | sed "s|Icon=||"` SRPM_NAME=`\ find $DISTRO_SRPMS_DIR \ -regex ".*/${pckname//+/\\+}-[^-]*-[^-]*" -printf "%f " 2>/dev/null` [ "$SRPM_NAME" ] || { echo "$me: $pckname is missing in $DISTRO_SRPMS_DIR; aborting." exit 255 } SRPM_VERSION=`\ echo $SRPM_NAME | \ sed "s|${pckname//+/\\+}-\([^-]*-[^-]*\).src.rpm|\1|" 2>/dev/null` RPM_INSTALLED=`rpm -q $pckname` [ $? -eq 0 ] || RPM_INSTALLED= RPM_INSTALLED_VERSION=`\ echo $RPM_INSTALLED | \ sed "s|${pckname//+/\\+}-\([^-]*-[^-]*\)\..*|\1|" 2>/dev/null` echo "Package name: $pckname" echo "Installed version: $RPM_INSTALLED_VERSION" echo "Last version: $SRPM_VERSION" echo if [ "$RPM_INSTALLED_VERSION" != "$SRPM_VERSION" ]; then if [ "$RPM_INSTALLED_VERSION" ]; then UPDATE_NEEDED=1 elif [ "$UPGRADE_MODE" ]; then continue fi elif [ "$UPGRADE_MODE" ]; then continue fi if [ ! "$CHECK_MODE" ]; then SRPM_PATH=${DISTRO_SRPMS_DIR}/${SRPM_NAME} if [ ! -f $SRPM_PATH ]; then echo "$me: "$"missing SRPM \`$SRPM_PATH'."" "$"Aborting..." >&2 exit 255 fi tmpfile=`mktemp -q -t $me.XXXXXXXX` || { echo "$me: error: cannot create temporary files; aborting." exit 255 } tmpdir=`mktemp -d -q -t $me.XXXXXXXX` || { echo "$me: error: cannot create temporary directory; aborting." exit 255 } # get license agreement ( rpm2cpio $SRPM_PATH > $tmpfile && cd $tmpdir && cpio --quiet --extract --make-directories < $tmpfile ) 2>/dev/null if [ -f $tmpdir/LICENSE ]; then if [ "$DISPLAY" ]; then license-dialog $tmpdir/LICENSE [ $? -ne 0 ] && exit 1 else echo "You must accept the following license terms:" echo more $tmpdir/LICENSE echo -n "Do you agree with the above license terms [y/N]? " read ans [ "$ans" = "Y" -o "$ans" = "y" ] || exit 1 fi fi notify-send -a $"Network software installation" -i $icon "$pckname" $"$pckname installation in progress..." # build rpm echo "$me: "$"rebuilding package \`$SRPM_PATH'..." rpmbuild --rebuild $SRPM_PATH --define="%_rpmdir $tmpdir" if [ $? -gt 0 ]; then echo "$me: "$"error rebuilding \`$SRPM_PATH'."" "$"Aborting..." >&2 notify-send -a $"Network software installation" -i $icon "$pckname" $"There was an error installing"" $pckname!" exit 255 fi RPM_PATH=`find $tmpdir -name \*.rpm` # install rpm if [ "$FORCE_MODE" = "1" ]; then sudo smart remove -y $pckname fi sudo smart install -y $RPM_PATH if [ $? -gt 0 ]; then echo "$me: "$"error installing \`$RPM_PATH'."" "$"Aborting..." >&2 check_if_already_installed $pckname exit 255 fi rpm -q $pckname 2>/dev/null if [ $? -eq 0 ]; then notify-send -a $"Network software installation" -i $icon "$pckname" $"Installation of $pckname successfully completed." else notify-send -a $"Network software installation" -i $icon "$pckname" $"There was an error installing $pckname!" fi rm -rf $tmpdir $tmpfile fi done if [ "$CHECK_MODE" -a "$UPDATE_NEEDED" ]; then echo "Update needed." fi exit 0