Yep - SuSE makes sure that only the Superuser has programs in the Path that would actually require the rights of the Superuser. As an added bonus, SuSE, Fedora, and a few others use a fork of mkisofs, genisoimage, which handles arguments differently, and complicates things a bit; that is, mkisofs only accepts -Jr, while genisoimage only accepts -J -r.
I've made some adjustments, and I can say that this does work with *buntu, including installing additional packages, it works with Fedora, which happens to already have all the packages it needs, and it'll at least let someone with SuSE or another Distro that behaves in a similar manner as far as the Path is concerned know what they need to do to make it work (run as the Superuser, su -). The only thing the user would have to do would be to download the file, change it's permissions to allow it to be executable (chmod a+x (file)), and answer the questions or follow any further instructions.
If there are any improvements, adjustments or extra features you think should be added to this, let me know :) .
The next version of the Shell Script:
#!/bin/bash
# This script will attempt to remove VLC from an OpenDisc ISO.
# Arguments to this script are optional.
# Should you decide to use arguments:
# Argument 1: 'local' or 'remote'
# Argument 2: If 'local', the relative or absolute path for the ISO on the disk.
# Argument 2: If 'remote', the name of the file on the OpenDisc SourceForge project.
# Anything after Argument 2 gets passed to mkisofs or genisoimage.
if [ $(whoami) = 'root' ] ; then
runAsRoot=1
else
runAsRoot=0
fi
checkProgramInPath()
{
# If the argument passed would be executable, return 0.
# Otherwise, return 1.
cmdChk=$1
# Check to make sure an argument was given.
if [ "$cmdChk" != '' ] ; then
# First, we say we want to find everything after a match.
# The pattern to match is '?', which is a single character.
# So, we've found everything after the first match, or, in
# this case, everything after the first character.
# Then we say find everything that doesn't match.
# Since the pattern to match is everything except the first
# character, the only thing that doesn't match is the first
# character.
# If the first character is '/', then we have an absolute path.
if [ "${cmdChk%${cmdChk#?}}" = '/' ] ; then
# Since we have an absolute path, check to see if the path is
# executable. If so, return 0; if not, return 1.
if [ -x $cmdChk ] ; then
return 0
else
return 1
fi
else
# We don't have an absolute path, which means checking each
# directory in the Path is necessary.
pth="$PATH"
nexc=1
# Since we're going to muck around with shell settings, make a
# backup so they can be restored.
oldIFSpath="$IFS"
IFS=':'
for directory in $pth
do
if [[ $nexc -eq 1 && -x $directory/$cmdChk ]] ; then
nexc=0
fi
done
# Restore the proper settings and return the result.
IFS="$oldIFSpath"
return $nexc
fi
else
return 1
fi
}
checkProgramInstalled()
{
# Check to see if a program is installed, and, if not,
# try to install it.
cmd="$1"
checkProgramInPath "$cmd"
if [ $? -ne 0 ] ; then
# Unless it happens that the command not found is mkisofs,
# and genisoimage is findable, try to install.
checkProgramInPath 'genisoimage'
if [[ $? -ne 0 || "$cmd" != 'mkisofs' ]] ; then
echo "It appears that the program $cmd is not in your Path."
echo "Either $cmd is not installed, or it is not in your Path."
echo 'In some Linux Distributions, you must run this script'
echo 'while logged in as the Superuser, modify your Path, or'
echo 'run su - before running this script for programs that'
echo 'require Superuser rights, including package managers.'
echo ''
install=0
answer=''
pkgmgr=0
checkProgramInPath 'sudo'
if [[ $? -eq 0 || $runAsRoot -eq 1 ]] ; then
echo -n "Would you like me to try and install $cmd? (y/n): "
read answer
answer="${answer%${answer#?}}"
if [[ "$answer" = 'y' || "$answer" = 'Y' ]] ; then
echo "I will now try to install $cmd."
instlrs="apt-get yum yast urpmi emerge up2date smart"
packages=$*
oldIFSinst="$IFS"
IFS=' '
# First, we need to loop by package managers.
for pkgmgrApp in $instlrs
do
# We don't need to do anything else if it's been installed.
if [ $install -ne 1 ] ; then
checkProgramInPath "$pkgmgrApp"
if [ $? -eq 0 ] ; then
pkgmgr=1
case "$pkgmgrApp" in
'apt-get')
pkgmgrAppPrm='install' ;;
'yum')
pkgmgrAppPrm='install' ;;
'yast')
pkgmgrAppPrm='-i' ;;
'urpmi')
pkgmgrAppPrm='' ;;
'emerge')
pkgmgrAppPrm='' ;;
'up2date')
pkgmgrAppPrm='--install' ;;
'smart')
pkgmgrAppPrm='install' ;;
esac
# Since we've found a package manager, we have to try
# and install the package by any known name.
for package in $packages
do
if [ $install -ne 1 ] ; then
if [ $runAsRoot -eq 1 ] ; then
if [ "$pkgmgrAppPrm" != '' ] ; then
$pkgmgrApp $pkgmgrAppPrm $package
else
$pkgmgrApp $package
fi
else
if [ "$pkgmgrAppPrm" != '' ] ; then
sudo $pkgmgrApp $pkgmgrAppPrm $package
else
sudo $pkgmgrApp $package
fi
fi
checkProgramInPath "$cmd"
if [ $? -eq 0 ] ; then
install=1
else
if [ "$cmd" = 'mkisofs' ] ; then
checkProgramInPath 'genisoimage'
if [ $? -eq 0 ] ; then
install=1
fi
fi
fi
fi
done
fi
fi
done
IFS="$oldIFSinst"
fi
else
echo "I cannot install $cmd, as I am neither running as root,"
echo 'nor can I find sudo. Try exiting this script, and, before'
echo 'relaunching, log in as the Superuser, or run su - .'
fi
if [ $install -eq 1 ] ; then
echo "$cmd was successfully installed."
elif [[ "$answer" = 'y' || "$answer" = 'Y' ]] ; then
if [ $pkgmgr -eq 1 ] ; then
echo "Attempting to install $cmd failed to add it to the Path."
echo "$cmd is either installed but not in your Path, or I don't"
echo "know what package contains $cmd for your Distribution."
else
echo "I could not find a package manager to install $cmd."
echo 'In some Linux Distributions, package managers will'
echo 'only be in the Path of the Superuser.'
fi
echo 'Try exiting this script, and, before relaunching, log'
echo 'in as the Superuser, modify your path to include the'
echo 'necessary programs, or run su - .'
fi
if [ $install -ne 1 ] ; then
echo -n 'Would you like to continue, or abort? (c/a): '
read answer
answer="${answer%${answer#?}}"
if [[ "$answer" != 'c' && "$answer" != 'C' ]] ; then
exit
fi
fi
fi
fi
}
checkForError()
{
errorNum="$1"
if [ $errorNum -ne 0 ] ; then
echo 'It seems that the last command I ran encountered a problem.'
echo "The exit code was $errorNum. You may also reference the output above."
echo -n 'Would you like to continue, or abort? (c/a): '
read answer
answer="${answer%${answer#?}}"
if [[ "$answer" != 'c' && "$answer" != 'C' ]] ; then
exit
fi
fi
}
sys="$1"
loc="$2"
shift
shift
# If we have more than 2 arguments, the first two go to us.
# Anything afterwards goes to mkisofs.
arg=''
while [ $# -ge 1 ] ;
do
if [ "$arg" != '' ] ; then
arg="$arg $1"
else
arg="$1"
fi
shift
done
echo 'I will attempt to remove VLC from an OpenDisc ISO.'
echo 'But first, I need to ask some questions.'
echo ''
echo 'Checking for required packages...'
# If you can't find it on the Path in the base install
# of either LinuxFromScratch or SuSE, check for it.
# We only need sudo if the current user isn't root.
if [ $runAsRoot -ne 1 ] ; then
checkProgramInstalled 'sudo'
fi
checkProgramInstalled 'mount' 'util-linux'
checkProgramInstalled 'patch'
checkProgramInstalled 'mkisofs' 'cdrkit-cdrtools-compat' 'genisoimage'
checkProgramInstalled 'umount' 'util-linux'
# We'll only check for wget if it turns out that the user
# hasn't already downloaded the OpenDisc ISO.
echo ''
# We need to find out if we're dealing with the
# original mkisofs or the fork, genisoimage.
origmki=1
mkifound=0
checkProgramInPath 'mkisofs'
if [ $? -eq 0 ] ; then
mkifound=1
mkivrsn=<code>mkisofs -version</code>
# If mkisofs' version mentions genisoimage, it's part of the fork.
if [[ "$mkivrsn" =~ .*genisoimage.* ]] ; then
origmki=0
fi
# Also, the installed version might be aged. If it's too old, it'll use
# the old method of accepting arguments.
# The following versions are considered old:
# 0, 1, 2.00, 2.01, 2.01.01a0 - 2.01.01a8
if [[ "$mkivrsn" =~ .*[[:space:]](2\.0*1\.0*1(a0*[0-8])?|((2(\.0*1)?(\.0+)+|[0-1])(\.[[:digit:]]+)*|2(\.0*1)?)(a[[:digit:]]+)?)[[:space:]].* ]] ; then
origmki=0
fi
fi
echo 'Insuring proper umask...'
# Get and save the current umask.
let "svumask = 8#<code>umask</code>"
# We should have full permissions to any file or folder created.
# 7077 in octal = 3647.
# The zero in 7077 eliminates any restrictions for the current
# user for newly created files and folders.
nwumask=$[ svumask & 3647 ]
# Convert the (possibly) new umask back to octal and set it.
umask <code>printf %o $nwumask</code>
echo ''
echo 'Creating required files...'
mkdir -p opendisc
checkForError $?
mkdir -p opendisc/new
checkForError $?
mkdir -p opendisc/old
checkForError $?
echo -e '*** disctree/en/home.html.old\t2007-11-08 21:19:15.000000000 -0500' > opendisc/menu.patch
checkForError $?
echo -e '--- disctree/en/home.html\t2007-11-08 21:20:09.000000000 -0500' >> opendisc/menu.patch
checkForError $?
echo -e '***************' >> opendisc/menu.patch
checkForError $?
echo -e '*** 384,401 ****' >> opendisc/menu.patch
checkForError $?
echo -e ' href="sumatra_install.lch"> <img src="../incl/img/install-s.png" /><span>Install</span></a>\r' >> opendisc/menu.patch
checkForError $?
echo -e ' </td>\r' >> opendisc/menu.patch
checkForError $?
echo -e ' </tr>\r' >> opendisc/menu.patch
checkForError $?
echo -e '- <tr>\r' >> opendisc/menu.patch
checkForError $?
echo -e '- <td class="logocell"><a class="info" href="vlc.html"><img\r' >> opendisc/menu.patch
checkForError $?
echo -e '- alt="VLC" src="../incl/img/vlc.png" /> <span><img\r' >> opendisc/menu.patch
checkForError $?
echo -e '- src="../incl/img/info-i.png" /></span></a></td>\r' >> opendisc/menu.patch
checkForError $?
echo -e '- <td>\r' >> opendisc/menu.patch
checkForError $?
echo -e '- <h3>VLC</h3>\r' >> opendisc/menu.patch
checkForError $?
echo -e '- <p>Video and audio player</p>\r' >> opendisc/menu.patch
checkForError $?
echo -e '- </td>\r' >> opendisc/menu.patch
checkForError $?
echo -e '- <td class="installcell"> <a class="install"\r' >> opendisc/menu.patch
checkForError $?
echo -e '- href="vlc_install.lch"> <img src="../incl/img/install-s.png" /><span>Install</span></a>\r' >> opendisc/menu.patch
checkForError $?
echo -e '- </td>\r' >> opendisc/menu.patch
checkForError $?
echo -e '- </tr>\r' >> opendisc/menu.patch
checkForError $?
echo -e ' </tbody>\r' >> opendisc/menu.patch
checkForError $?
echo -e ' </table>\r' >> opendisc/menu.patch
checkForError $?
echo -e ' <table class="categoryTable" id="productivity">\r' >> opendisc/menu.patch
checkForError $?
echo -e '--- 384,389 ----' >> opendisc/menu.patch
checkForError $?
echo ''
isoPath=''
while [ "$isoPath" = '' ] ;
do
case "$sys" in
'local')
answer='y' ;;
'remote')
answer='n' ;;
*)
echo -n 'Have you already downloaded the OpenDisc ISO? (y/n): '
read answer
answer="${answer%${answer#?}}" ;;
esac
if [[ "$answer" = 'y' || "$answer" = 'Y' ]] ; then
if [ "$loc" = '' ] ; then
echo -n 'Where is the OpenDisc ISO? (relative or absolute path): '
read answer
else
answer="$loc"
fi
if [ -r $answer ] ; then
echo 'OK, I can read the OpenDisc ISO.'
isoPath="$answer"
else
if [ -f $answer ] ; then
echo 'The OpenDisc ISO exists, but I cannot read it.'
else
echo 'The OpenDisc ISO does not appear to exist.'
fi
fi
else
echo 'OK, I will attempt to download it for you.'
checkProgramInstalled 'wget'
if [ "$loc" = '' ] ; then
echo -n 'What file would you like to download from the OpenDisc SourceForge Project?: '
read answer
else
answer="$loc"
fi
if [ "$answer" != '' ] ; then
echo 'I will now try and download the OpenDisc ISO.'
cd opendisc
wget "http://downloads.sourceforge.net/opendisc/$answer"
if [[ $? -eq 0 && -r $answer ]] ; then
echo 'OK, I have successfully downloaded the OpenDisc ISO.'
isoPath="opendisc/$answer"
else
echo 'There was a problem downloading the ISO from the OpenDisc SourceForge Project.'
fi
cd ..
else
echo 'You must supply a file name.'
fi
fi
# We don't need to get caught in an endless loop.
# If the supplied arguments worked, we've acted upon them.
# If they didn't work, all the more reason to discard them.
sys=''
loc=''
done
echo ''
echo -n 'If you would like to pass additional arguments to mkisofs, enter them now: '
read argAdd
if [ "$arg" != '' ] ; then
arg="$arg $argAdd"
else
arg="$argAdd"
fi
echo ''
echo 'I will now attempt to remove VLC from the OpenDisc ISO.'
if [ $runAsRoot -ne 1 ] ; then
echo 'You may be asked to authenticate yourself to sudo.'
fi
echo 'Mounting the OpenDisc ISO...'
if [ $runAsRoot -eq 1 ] ; then
mount -o loop $isoPath opendisc/old
checkForError $?
else
sudo mount -o loop $isoPath opendisc/old
checkForError $?
fi
cd opendisc
checkForError $?
echo 'Copying the contents of the OpenDisc ISO...'
cp -r old/* new/
checkForError $?
if [ $runAsRoot -eq 1 ] ; then
chmod u+rw -R new
checkForError $?
else
sudo chmod u+rw -R new
checkForError $?
fi
cd new
checkForError $?
echo 'Removing VLC files...'
rm -fr programs/vlc disctree/app_img/vlc* disctree/incl/img/vlc.png disctree/en/vlc*
checkForError $?
echo 'Removing VLC from the Disc Menu...'
patch -p0 < ../menu.patch
checkForError $?
echo 'Creating a new ISO...'
if [[ $mkifound -eq 1 && $origmki -eq 1 ]] ; then
if [ "$arg" != '' ] ; then
mkisofs -Jr $arg -o ../OpenDisc-NoVLC.iso ./
checkForError $?
else
mkisofs -Jr -o ../OpenDisc-NoVLC.iso ./
checkForError $?
fi
else
isoCtr='mkisofs'
if [ $mkifound -ne 1 ] ; then
isoCtr='genisoimage'
fi
if [ "$arg" != '' ] ; then
$isoCtr -J -r $arg -o ../OpenDisc-NoVLC.iso ./
checkForError $?
else
$isoCtr -J -r -o ../OpenDisc-NoVLC.iso ./
checkForError $?
fi
fi
cd ..
checkForError $?
echo 'Cleaning up...'
if [ $runAsRoot -eq 1 ] ; then
umount old
checkForError $?
else
sudo umount old
checkForError $?
fi
rm -r old new menu.patch
checkForError $?
# Don't forget to restore the saved umask.
umask <code>printf %o $svumask</code>
echo ''
echo 'I have finished removing VLC from the OpenDisc ISO.'