Last active
December 17, 2015 07:38
-
-
Save jerrykan/5573888 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Loosely based on the manual steps outlined at: | |
# https://kb.berkeley.edu/page.php?id=27401 | |
# and: | |
# http://hodza.net/2011/06/15/howto-install-tsm-backup-client-in-debian-squeeze-ubuntu-64bit/ | |
# | |
# This script assumes it is being run on a Debian host that has the alien | |
# package installed. | |
# | |
# This script will process all the RPMs in the current working directory, so | |
# copy the RPMs you wish to have processed into the current directory and run | |
# the script. The final DEBs can then be found in the 'debs/' directory. | |
# | |
# While the script will attempt to convert all RPMs in the current working | |
# directory to DEB packages, it has only been tested against the following | |
# RPMs: | |
# gskcrypt64-8.0.14.28.linux.x86_64.rpm (v7.1.0) | |
# gskssl64-8.0.14.28.linux.x86_64.rpm (v7.1.0) | |
# TIVsm-API64.x86_64.rpm (v7.1.0) | |
# TIVsm-BA.x86_64.rpm (v7.1.0) | |
# | |
# YOU USE THIS SCRIPT AT YOUR OWN RISK | |
# | |
DEBDIR=debs | |
TMPDIR=debtemp | |
PKG_VERS="package_versions.ignore" | |
# create temp directory | |
mkdir $TMPDIR | |
cd $TMPDIR | |
# extraced the RPMs and packager version information | |
for RPM in ../*.rpm; do | |
alien -g -c $RPM | |
PNAME=$(rpm -qip $RPM | grep Name | cut -d ':' -f 2 | sed 's/ //g') | |
PVERSION=$(rpm -qip $RPM | grep Version | cut -d ':' -f 2 | sed 's/ //g') | |
echo "$PNAME (=$PVERSION)" >> $PKG_VERS | |
done | |
# rename the directories we don't want to package up | |
for DIR in *.orig; do | |
mv $DIR $DIR.ignore | |
done | |
# build the DEBs | |
for DIR in $(ls | grep -v \.ignore); do | |
# fix Debian metadata files | |
mv $DIR/debian $DIR/DEBIAN | |
chmod 755 $DIR/DEBIAN/{postinst,prerm} 2> /dev/null | |
# update Debian control file | |
VERSION=$(expr match "$DIR" '.*-\([0-9.]\+\)') | |
# remove blank links, 'Depends:', and "non-tagged" lines | |
sed -i -r '/^(Depends:|[^:]* |$)/d' $DIR/DEBIAN/control | |
echo "Version: $VERSION" >> $DIR/DEBIAN/control | |
if [[ $DIR == "gsk"* ]]; then | |
if [[ $DIR == "gskssl64-"* ]]; then | |
# set the correct dependencies | |
echo "Depends: $(grep ^gskcrypt64 $PKG_VERS)" >> $DIR/DEBIAN/control | |
fi | |
# don't create symlinks in /usr/lib64 (no longer exists in Debian) | |
# these libraries hand included as part of the BA wrapper script | |
sed -i '/^ln.*\/usr\/lib64/d' $DIR/DEBIAN/postinst | |
sed -i '/^\s*rm.*\/usr\/lib64/d' $DIR/DEBIAN/prerm | |
# delete the prerm file if then in nothing in the if block to delete | |
if [[ $(awk '/if.*then$/,/^fi/' $DIR/DEBIAN/prerm | wc -l) -eq 2 ]]; then | |
rm $DIR/DEBIAN/prerm | |
fi | |
elif [[ $DIR == "TIVsm-API64-"* ]]; then | |
# set the correct dependencies | |
echo "Depends: $(grep ^gsk $PKG_VERS | paste -d ', ' -s | sed 's/,/, /g')" >> $DIR/DEBIAN/control | |
# don't create symlinks in /usr/lib64 (no longer exists in Debian) | |
# create them in /opt/tivoli/tsm/client/api/bin64/ if required | |
LIB64="/usr/lib64/" | |
BIN64="/opt/tivoli/tsm/client/api/bin64/" | |
for LINK in $DIR/$LIB64/*; do | |
TARGET=$(readlink $LINK | xargs basename) | |
NAME=$(basename $LINK) | |
if [ ! -f $DIR/$BIN64/$NAME ]; then | |
ln -s ./$TARGET $DIR/$BIN64/$NAME | |
fi | |
done | |
# delete lib64 symlinks | |
rm -rf $DIR/usr/lib64 | |
elif [[ $DIR == "TIVsm-BA-"* ]]; then | |
# set the correct dependencies | |
echo "Depends: $(grep ^TIVsm-API64 $PKG_VERS)" >> $DIR/DEBIAN/control | |
# provide a wrapper for dsm commands to load the libraries | |
WRAPPER=$DIR/usr/bin/dsm.wrapper | |
for LINK in $DIR/usr/bin/* ; do | |
ln -sf ./$(basename $WRAPPER) $LINK | |
done | |
echo "#!/bin/sh" > $WRAPPER | |
echo >> $WRAPPER | |
echo "export LD_LIBRARY_PATH=/opt/tivoli/tsm/client/api/bin64:/usr/local/ibm/gsk8_64/lib64" >> $WRAPPER | |
echo "/opt/tivoli/tsm/client/ba/bin/\$(basename \$0) \$@" >> $WRAPPER | |
chmod 755 $WRAPPER | |
fi | |
# build DEB package | |
dpkg -b $DIR | |
done | |
# mv to DEBs into their own folder | |
mkdir ../$DEBDIR | |
mv *.deb ../$DEBDIR | |
# delete the temp directory | |
cd .. | |
rm -rf $TMPDIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment