Skip to content

Instantly share code, notes, and snippets.

@h2onda
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h2onda/9c73da8ddaa0f8dacc41 to your computer and use it in GitHub Desktop.
Save h2onda/9c73da8ddaa0f8dacc41 to your computer and use it in GitHub Desktop.
create driver disk from specified rpm package
#!/bin/bash
usage() {
echo "Usage: $(basename $0) [ -o filename.iso ] [driver.rpm ...]"
}
create_disk_template() {
rv=1
echo "Driver Update Disk version 3" > $workspace/rhdd3
for i in "$@"
do
filetype=$(file -b --mime-type "$i" 2>/dev/null)
if [ "$filetype" != "application/x-rpm" ] ; then
continue
fi
arch=$(rpm -q -p "$i" --qf "%{ARCH}\n" 2>/dev/null)
if [ -z "$arch" ] ; then
continue
fi
dest="$workspace/rpms/$arch"
if [ ! -d "$dest" ]; then
mkdir -p "$dest"
fi
cp -p $i $dest
done
for i in $(ls $workspace/rpms 2>/dev/null)
do
pushd $workspace/rpms/$i > /dev/null
$CREATEREPO -p -d ./
if [ $? -eq 0 ]; then
rv=0
fi
popd > /dev/null
done
return $rv
}
CREATEREPO=$(which createrepo 2>/dev/null)
if [ -z "$CREATEREPO" ] ; then
echo "createrepo command is not found!" > /dev/stderr
echo "you should run \"yum install createrepo\" !" > /dev/stderr
exit 1
fi
MKISOFS=$(which mkisofs 2>/dev/null)
if [ -z "$MKISOFS" ] ; then
echo "mkisofs command is not found!" > /dev/stderr
echo "you should run \"yum install '*/mkisofs'\" !" > /dev/stderr
exit 1
fi
while getopts 'o:h' args "$@"
do
case $args in
o)
ofile=$OPTARG
;;
h|?)
usage
exit 1
;;
esac
done
shift $(($OPTIND - 1))
ofile=${ofile:-driverdisk_$(date +"%F_%T").iso}
workspace=$(mktemp -t -d $(basename $0).XXXXXX)
trap "rm -rf $workspace" exit
create_disk_template "$@"
if [ $? -ne 0 ] ; then
echo "valid rpm file is not found!" > /dev/stderr
exit 1
fi
$MKISOFS -J -r -o $ofile -V "OEMDRV" -input-charset "utf-8" $workspace
if [ $? -ne 0 ] ; then
echo "create driver disk is failed!" > /dev/stderr
exit 1
fi
echo "create driver disk to $ofile is done!" > /dev/stderr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment