155 lines
3.9 KiB
Plaintext
155 lines
3.9 KiB
Plaintext
|
#!/bin/bash
|
||
|
#
|
||
|
# netsrpm-install.sh - Build srpms that download sources from network
|
||
|
#
|
||
|
# Copyright (C) 2003-2011 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
|
||
|
kdialog \
|
||
|
--caption "$pckname" \
|
||
|
--msgbox "$pckname: "$"already installed."
|
||
|
else
|
||
|
kdialog \
|
||
|
--caption "$pckname" \
|
||
|
--sorry $"There was an error installing"" $pckname!"
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
|
||
|
for pckname in $PACKAGES; do
|
||
|
|
||
|
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
|
||
|
|
||
|
[ "$RPM_INSTALLED_VERSION" != "$SRPM_VERSION" ] && {
|
||
|
if [ "$RPM_INSTALLED_VERSION" ]; then
|
||
|
UPDATE_NEEDED=1
|
||
|
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
|
||
|
kdialog \
|
||
|
--caption "LICENSE" \
|
||
|
--textbox $tmpdir/LICENSE 600 400
|
||
|
[ $? -ne 0 ] && exit 1
|
||
|
fi
|
||
|
|
||
|
kdialog \
|
||
|
--title "$pckname" \
|
||
|
--passivepopup \
|
||
|
$"$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 rpm -hUv --force $RPM_PATH
|
||
|
if [ $? -gt 0 ]; then
|
||
|
echo "$me: "$"error installing \`$SRPM_PATH'."" "$"Aborting..." >&2
|
||
|
check_if_already_installed $pckname
|
||
|
exit 255
|
||
|
fi
|
||
|
|
||
|
rpm -q $pckname 2>/dev/null
|
||
|
if [ $? -eq 0 ]; then
|
||
|
kdialog \
|
||
|
--title "$pckname" \
|
||
|
--passivepopup \
|
||
|
$"Installation of $pckname successfully completed."
|
||
|
else
|
||
|
kdialog \
|
||
|
--caption "$pckname" \
|
||
|
--sorry $"There was an error installing $pckname!"
|
||
|
fi
|
||
|
rm -rf $tmpdir $tmpfile
|
||
|
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
[ "$UPDATE_NEEDED" ] && {
|
||
|
echo "Update needed."
|
||
|
exit 1
|
||
|
}
|
||
|
exit 0
|