#!/bin/sh # mkconsole - Setup Console Helper to run something with Super User Privileges # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Be warned that running anything as root is dangerous and could damage your system. # Script Name and Version MYNAME=mkconsole VERSION="$Id: mkconsole,v 1.4 2004/04/20 00:17:00 kg9ae Exp $" # Where to place consolehelper symlink. OUTBINDIR=${ROOTDIR}/usr/bin # You risk very bad mojo if you edit below here. PAMD=${ROOTDIR}/etc/pam.d CONSOLEAPPS=${ROOTDIR}/etc/security/console.apps DESKLAUNCHDIR=${ROOTDIR}/usr/share/applications function usage() { echo "${MYNAME} Copyright (c) 2004 David L Norris " echo "" echo "Usage: ${MYNAME} " echo " Ex: ${MYNAME} /usr/bin/nautilus nautilus-super" echo " " exit 1 } # this script must be run as root if [ ${UID} != 0 ]; then echo "${MYNAME}: Must be run as root." echo " Ex: sudo ${MYNAME} /usr/bin/nautilus nautilus-super" echo " " usage fi # we must have two arguments if [ "x${1}" = "x" ];then usage fi if [ "x${2}" = "x" ];then usage fi # source and target executables SOURCE="${1}" BINDIR=`dirname "${1}"` TARGET=`basename "${2}"` # We need this for PAM. if [ "x${BINDIR}" = "x." ]; then echo "${MYNAME}: Error: You must supply an absolute filename as the source." 1>&2 exit 2 fi # source must exist if [ ! -x "${SOURCE}" ]; then echo "${MYNAME}: Error: No executable named \"${SOURCE}\" was found." 1>&2 exit 3 fi # target must not exist if [ -e "${OUTBINDIR}/${TARGET}" ]; then echo "${MYNAME}: Error: Target \"${OUTBINDIR}/${TARGET}\" already exists!" 1>&2 exit 4 fi # PAM Authentication must not exist if [ -e "${PAMD}/${TARGET}" ]; then echo "${MYNAME}: Error: PAM Authentication data \"${PAMD}/${TARGET}\" already exists!" 1>&2 exit 5 fi # Console app must not exist if [ -e "${CONSOLEAPPS}/${TARGET}" ]; then echo "${MYNAME}: Error: Console App \"${CONSOLEAPPS}/${TARGET}\" already exists!" 1>&2 exit 6 fi # With some luck all is well in the universe beyond this point. ln -s consolehelper "${OUTBINDIR}/${TARGET}" # check for errors STATUS=$? if [ $STATUS -ne 0 ]; then echo "${MYNAME}: Error: Unable to create \"${OUTBINDIR}/${TARGET}\" symlink" 1>&2 exit 7 fi # Write our PAM authentication configuration echo "#%PAM-1.0 auth sufficient pam_rootok.so auth sufficient pam_timestamp.so auth required pam_stack.so service=system-auth session required pam_permit.so session optional pam_xauth.so session optional pam_timestamp.so account required pam_permit.so" > "${PAMD}/${TARGET}" # check for errors STATUS=$? if [ $STATUS -ne 0 ]; then echo "${MYNAME}: Error: Unable to create \"${PAMD}/${TARGET}\"" 1>&2 exit 7 fi # write console application config echo "USER=root PROGRAM=${SOURCE} SESSION=true" > "${CONSOLEAPPS}/${TARGET}" # check for errors STATUS=$? if [ $STATUS -ne 0 ]; then echo "${MYNAME}: Error: Unable to create \"${CONSOLEAPPS}/${TARGET}\"" 1>&2 exit 8 fi # Create Desktop Entry in System Tools - This is tricky so we'll try to err on the side of caution. # Find the desktop launcher if it exists FINDWHAT=`basename ${SOURCE}` DESKTOPLAUNCH=`grep "^Exec=${FINDWHAT}$" /usr/share/applications/* | cut -d: -f1` if [ "x${DESKTOPLAUNCH}" = "x" ]; then # No Launcher was found exit 10 fi # echo "${MYNAME}: INFO: Found desktop launcher at \"${DESKTOPLAUNCH}\"" # Give it a new name. FIXME: Only supports renaming C locale DESKTOPNAME="`grep "^Name=" "${DESKTOPLAUNCH}" | cut -d= -f2` (Super User)" # Get the original launcher file name. DESKFILEORIG=`basename "${DESKTOPLAUNCH}"` # Determine the new launcher file name DESKFILENEW="${DESKLAUNCHDIR}/${MYNAME}-${DESKFILEORIG}" # Install the new desktop launcher under the "System Tools" menu. desktop-file-install --vendor="${MYNAME}" --remove-key=Exec --remove-key=Name --remove-key=Categories "${DESKTOPLAUNCH}" "${DESKFILENEW}" # Was file created? if [ ! -e "${DESKFILENEW}" ]; then echo "${MYNAME}: ERROR: Desktop launcher was not created at \"${DESKFILENEW}\"." 1>&2 exit 11 fi # Wouldn't it be great if this could be done with desktop-file-install... echo "Exec=${TARGET} Name=${DESKTOPNAME} Categories=GNOME;Application;System;Utility;X-Red-Hat-Base; " >> "${DESKFILENEW}" echo "${MYNAME}: INFO: Created \"${DESKTOPNAME}\" launcher under the \"System Tools\" menu." # Yay, we have finished.