desktop-base-openmamba/openmamba-update/openmamba-netsrpms

144 lines
4.0 KiB
Bash
Executable File

#!/bin/bash
#
# netsrpm-install.sh - Build srpms that download sources from network
#
# Copyright (C) 2003-2012 by Silvan Calarco <silvan.calarco@mambasoft.it>
# Copyright (C) 2005 by Massimo Pintore <massimo.pintore@qilinux.it>
# Copyright (C) 2005-2007 by Davide Madrisan <davide.madrisan@qilinux.it>
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 ;;
-u) UPGRADE_MODE=1 ;;
*) PACKAGES="$PACKAGES $1"
esac
shift
done
if [ -z "$PACKAGES" ]; then
echo "Usage:
$me [-c] pkgname ...
-c: only check and exit (returns: 0: up-to-date; 1: needs update; 2: not 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."
else
notify-send -a $"Network software installation" -i $icon "$pckname" $"There was an error installing"" $pckname!"
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
license-dialog $tmpdir/LICENSE
[ $? -ne 0 ] && exit 1
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
check_if_already_installed $pckname
exit 255
fi
RPM_PATH=`find $tmpdir -name \*.rpm`
# install rpm
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
[ "$UPDATE_NEEDED" ] && {
echo "Update needed."
exit 1
}
exit 0