From 72b0911421fbbdcfe4ce5937c9b7758ae085de42 Mon Sep 17 00:00:00 2001 From: Todd Naugle Date: Wed, 6 Apr 2011 19:02:11 +0000 Subject: [PATCH] install and uninstall can now be run as root (ie su -c) although this is not preferred. Also check for free disk space before installing git-svn-id: svn://localhost/ardour2/branches/3.0@9308 d708f5d6-7413-0410-9779-e7cbd77b26cf --- tools/linux_packaging/build | 3 + tools/linux_packaging/package | 40 +++++--- tools/linux_packaging/stage2.run | 126 ++++++++++++++++++++------ tools/linux_packaging/uninstall.sh.in | 56 ++++++++++-- 4 files changed, 175 insertions(+), 50 deletions(-) diff --git a/tools/linux_packaging/build b/tools/linux_packaging/build index 8c09767cce..0120cf39fe 100755 --- a/tools/linux_packaging/build +++ b/tools/linux_packaging/build @@ -607,6 +607,9 @@ echo "Building tarball ..." rm -f $APPDIR.tar.bz2 tar -cjf $APPDIR.tar.bz2 $APPDIR +echo "Calculating bundle size" +du -sb $APPDIR/ | awk '{print $1}' > $APPDIR.size + rm -rf $APPDIR/ echo "Done." diff --git a/tools/linux_packaging/package b/tools/linux_packaging/package index 9dec97b064..8a8b111c34 100755 --- a/tools/linux_packaging/package +++ b/tools/linux_packaging/package @@ -52,8 +52,6 @@ while [ $# -gt 0 ] ; do esac done -release_version=`grep -m 1 '^VERSION' ../../wscript | awk '{print $3}' | sed "s/'//g"` -svn_version=`grep -m 1 'svn_revision =' ../../libs/ardour/svn_revision.cc | cut -d"'" -f 2` # Figure out the Build Type if grep -q "DEBUG = True" ../../build/c4che/default.cache.py; then @@ -70,27 +68,37 @@ if [ x$DEBUG != x ]; then fi fi +release_version=`grep -m 1 '^VERSION' ../../wscript | awk '{print $3}' | sed "s/'//g"` +svn_version=`grep -m 1 'svn_revision =' ../../libs/ardour/svn_revision.cc | cut -d"'" -f 2` -if [ -z ${BUILDTYPE} ]; then - X86_BUILD="${APPNAME}_x86-${release_version}_${svn_version}.tar.bz2" - X86_64_BUILD="${APPNAME}_x86_64-${release_version}_${svn_version}.tar.bz2" -else - X86_BUILD="${APPNAME}_x86-${release_version}_${svn_version}-${BUILDTYPE}.tar.bz2" - X86_64_BUILD="${APPNAME}_x86_64-${release_version}_${svn_version}-${BUILDTYPE}.tar.bz2" +X86_BUNDLE="${APPNAME}_x86-${release_version}_${svn_version}" +X86_64_BUNDLE="${APPNAME}_x86_64-${release_version}_${svn_version}" + +if [ ! -z ${BUILDTYPE} ]; then + X86_BUNDLE="${X86_BUNDLE}-${BUILDTYPE}" + X86_64_BUNDLE="${X86_64_BUNDLE}-${BUILDTYPE}" fi -if [ ! -e ${X86_BUILD} ]; then +if [ ! -e ${X86_BUNDLE}.tar.bz2 ] ; then echo "" - echo "Can't locate x86 bundle file ${X86_BUILD}" + echo "Can't locate x86 bundle file ${X86_BUNDLE}.tar.bz2" + echo "" +elif [ ! -e ${X86_BUNDLE}.size ] ; then + echo "" + echo "Can't locate x86 bundle size file ${X86_BUNDLE}.size" echo "" else X86_BUNDLE_OK="T" fi -if [ ! -e ${X86_64_BUILD} ]; then +if [ ! -e ${X86_64_BUNDLE}.tar.bz2 ]; then echo "" - echo "Can't locate x86_64 bundle file ${X86_64_BUILD}" + echo "Can't locate x86_64 bundle file ${X86_64_BUNDLE}.tar.bz2" + echo "" +elif [ ! -e ${X86_64_BUNDLE}.size ]; then + echo "" + echo "Can't locate x86 bundle size file ${X86_BUNDLE}.size" echo "" else X86_64_BUNDLE_OK="T" @@ -100,7 +108,7 @@ fi if [ "${X86_BUNDLE_OK}" = "F" ] || [ "${X86_64_BUNDLE_OK}" = "F" ]; then if [ "${X86_BUNDLE_OK}" = "${X86_64_BUNDLE_OK}" ]; then echo "" - echo "!!! ERROR !!! - Can't locate bundle files ${X86_BUILD} or ${X86_64_BUILD}" + echo "!!! ERROR !!! - Can't locate bundle files ${X86_BUNDLE} or ${X86_64_BUNDLE}" echo "" exit 1 elif [ "${SINGLE_ARCH}" = "T" ]; then @@ -150,11 +158,13 @@ echo "Creating new package dir..." mkdir ${PACKAGE} if [ "${X86_BUNDLE_OK}" = "T" ]; then - mv ${X86_BUILD} ${PACKAGE} + mv ${X86_BUNDLE}.tar.bz2 ${PACKAGE} + mv ${X86_BUNDLE}.size ${PACKAGE}/.${X86_BUNDLE}.size fi if [ "${X86_64_BUNDLE_OK}" = "T" ]; then - mv ${X86_64_BUILD} ${PACKAGE} + mv ${X86_64_BUNDLE}.tar.bz2 ${PACKAGE} + mv ${X86_64_BUNDLE}.size ${PACKAGE}/.${X86_64_BUNDLE}.size fi cp install.sh ${PACKAGE} diff --git a/tools/linux_packaging/stage2.run b/tools/linux_packaging/stage2.run index 207df675c8..7075e52c35 100755 --- a/tools/linux_packaging/stage2.run +++ b/tools/linux_packaging/stage2.run @@ -59,7 +59,7 @@ SystemInstall () if which yum > /dev/null; then - sudo yum -y install $1 + ${SUPER} yum -y install $1 rtrn=$? if [ $rtrn -ne 0 ]; @@ -72,7 +72,7 @@ SystemInstall () elif which apt-get > /dev/null; then - sudo apt-get -y install $1 + ${SUPER} apt-get -y install $1 rtrn=$? if [ $rtrn -ne 0 ]; @@ -108,20 +108,53 @@ echo "" echo "Welcome to the ${PGM_NAME} installer" echo "" -############## -# Check sudo -############## +############################# +# Check for root privileges +############################# -if ! sudo date; -then +SUPER="" + +if [ "$(id -u)" != "0" ]; then + + if ! which sudo > /dev/null; + then + echo "" + echo "!!! ERROR !!!" + echo "" + echo "The installer requires root privileges. It is currently not" + echo "running as root AND the program sudo is missing from this system." + echo "" + echo "Please correct this by installing and configuring sudo or running" + echo "the installer as root." + echo "" + read -p "Press ENTER to exit installer:" BLAH + exit 1 + fi + + if ! sudo date; + then + echo "" + echo "!!! ERROR !!!" + echo "" + echo "Either you don't know the root password or the user is not allowed to sudo" + echo "Please correct this and run the installer again" + echo "(hint: use visudo to edit sudoers file)" + echo "" + read -p "Press ENTER to exit installer:" BLAH + exit 1 + fi + SUPER="sudo" +else echo "" - echo "!!! ERROR !!!" + echo "!!! Warning !!!" echo "" - echo "Either you don't know the root password or the user is not allowed to sudo" - echo "Please correct this and run the installer again (hint: use visudo to edit sudoers file)" + echo "The installer is running as the root user which is not the prefered method." + echo "There are checks run at the end of the installer to help ensure proper operation" + echo "of ${PGM_NAME} (realtime priviledges, memory locking, frequency scaling)." + echo "Running as root will invalidate these tests." echo "" - read -p "Press ENTER to exit installer:" BLAH - exit 1 + read -p "Press ENTER to continue:" BLAH + fi ############################ @@ -146,6 +179,47 @@ case `uname -m` in ;; esac +#################### +# Check disk space +#################### + +# We have to check the current folder and the INSTALL_DEST_BASE just +# in case they are on different devices +echo "Checking for required disk space" + +if [ ! -e .${PGM_NAME}_${ARCH}-*.size ]; then + echo "" + echo "!!! ERROR !!! Can't locate .size file for ${ARCH} bundle." + echo "" + exit 1 +else + REQUIRED_BYTES=$(cat .${PGM_NAME}_${ARCH}-*.size) + + #Check space in current folder + FREE_BYTES=$(df -B 1 ${PKG_PATH} | grep / | awk '{print $4}') + + if [ ${FREE_BYTES} -le ${REQUIRED_BYTES} ] ; then + echo "" + echo "!!! ERROR !!! - Insufficient disk space in ${PKG_PATH}" + echo "" + exit 1 + fi + + #Check space in INSTALL_DEST_BASE + FREE_BYTES=$(df -B 1 ${INSTALL_DEST_BASE} | grep / | awk '{print $4}') + + if [ ${FREE_BYTES} -le ${REQUIRED_BYTES} ] ; then + echo "" + echo "!!! ERROR !!! - Insufficient disk space in ${INSTALL_DEST_BASE}" + echo "" + exit 1 + fi +fi + +##################### +# Unpack the bundle +##################### + # untar the correct bundle for us to install echo "Unpacking bundle for $ARCH" @@ -278,7 +352,7 @@ then echo "Running uninstaller $i" ${i} - sudo rm -f ${i} + ${SUPER} rm -f ${i} fi done fi @@ -291,8 +365,8 @@ echo "Installing ${PGM_NAME} ${PGM_VERSION} built from ${PGM_BUILD} in ${INSTALL echo "" # Copy the new version in the install directory -sudo mkdir ${INSTALL_DEST_BASE}/${PGM_FULL_NAME} -sudo cp -Rf ${BUNDLE_DIR}/* ${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/ +${SUPER} mkdir ${INSTALL_DEST_BASE}/${PGM_FULL_NAME} +${SUPER} cp -Rf ${BUNDLE_DIR}/* ${INSTALL_DEST_BASE}/${PGM_FULL_NAME}/ # write the desktop/menu file echo "[Desktop Entry]" > /tmp/${MENU_FILE} @@ -312,24 +386,24 @@ echo "Comment=Digital Audio Workstation" >> /tmp/${MENU_FILE} echo "Categories=AudioVideo;AudioEditing;Audio;Recorder;" >> /tmp/${MENU_FILE} chmod ugo+rx /tmp/${MENU_FILE} -sudo mv /tmp/${MENU_FILE} ${MENU_FILE_PATH}/. +${SUPER} mv /tmp/${MENU_FILE} ${MENU_FILE_PATH}/. # install the Menu, Link, and Icon(s) if [ "T" = ${HAS_XDG} ]; then echo "Adding ${PGM_NAME} to the applications menu" - sudo xdg-icon-resource install --context apps --size 16 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_16px.png ${ICON_NAME} - sudo xdg-icon-resource install --context apps --size 22 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_22px.png ${ICON_NAME} - sudo xdg-icon-resource install --context apps --size 32 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_32px.png ${ICON_NAME} - sudo xdg-icon-resource install --context apps --size 48 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_48px.png ${ICON_NAME} + ${SUPER} xdg-icon-resource install --context apps --size 16 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_16px.png ${ICON_NAME} + ${SUPER} xdg-icon-resource install --context apps --size 22 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_22px.png ${ICON_NAME} + ${SUPER} xdg-icon-resource install --context apps --size 32 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_32px.png ${ICON_NAME} + ${SUPER} xdg-icon-resource install --context apps --size 48 ${ICON_PATH}/${PGM_NAME_LOWER}_icon_48px.png ${ICON_NAME} if [ -e ${ICON_PATH}/${PGM_NAME_LOWER}_icon.svg -a -d /usr/share/icons/hicolor/scalable/apps ]; then - sudo cp -f ${ICON_PATH}/${PGM_NAME_LOWER}_icon.svg /usr/share/icons/hicolor/scalable/apps/${ICON_NAME}.svg + ${SUPER} cp -f ${ICON_PATH}/${PGM_NAME_LOWER}_icon.svg /usr/share/icons/hicolor/scalable/apps/${ICON_NAME}.svg fi - sudo xdg-desktop-menu install ${MENU_FILE_PATH}/${MENU_FILE} - sudo xdg-desktop-menu forceupdate --mode system # Some systems need an extra kick + ${SUPER} xdg-desktop-menu install ${MENU_FILE_PATH}/${MENU_FILE} + ${SUPER} xdg-desktop-menu forceupdate --mode system # Some systems need an extra kick echo "" echo "Creating a desktop link for ${PGM_NAME}" @@ -346,7 +420,7 @@ echo "" echo "Copying uninstall script to ${INSTALL_DEST_BASE}" echo "" -sudo cp -f ${BUNDLE_DIR}/bin/*.uninstall.sh ${INSTALL_DEST_BASE}/. +${SUPER} cp -f ${BUNDLE_DIR}/bin/*.uninstall.sh ${INSTALL_DEST_BASE}/. ########################### # Check Jack and qjackctl @@ -448,7 +522,7 @@ then read -p "Press ENTER to continue:" BLAH user=`whoami` - if sudo usermod -a -G audio $user; + if ${SUPER} usermod -a -G audio $user; then USER_GROUP_ADJUSTED="t" else @@ -470,7 +544,7 @@ then read -p "Press ENTER to continue:" BLAH user=`whoami` - if sudo usermod -a -G jackuser $user; + if ${SUPER} usermod -a -G jackuser $user; then USER_GROUP_ADJUSTED="t" else diff --git a/tools/linux_packaging/uninstall.sh.in b/tools/linux_packaging/uninstall.sh.in index 468a4035fa..7e86b2bc11 100644 --- a/tools/linux_packaging/uninstall.sh.in +++ b/tools/linux_packaging/uninstall.sh.in @@ -33,6 +33,44 @@ fi MENU_FILE_PATH="${PGM_PATH}/share/${MENU_FILE}" +############################# +# Check for root privileges +############################# + +SUPER="" + +if [ "$(id -u)" != "0" ]; then + + if ! which sudo > /dev/null; + then + echo "" + echo "!!! ERROR !!!" + echo "" + echo "The uninstaller requires root privileges. It is currently not" + echo "running as root AND the program sudo is missing from this system." + echo "" + echo "Please correct this by running the uninstaller as root or" + echo "installing and configuring sudo." + echo "" + read -p "Press ENTER to exit uninstaller:" BLAH + exit 1 + fi + + if ! sudo date; + then + echo "" + echo "!!! ERROR !!!" + echo "" + echo "Either you don't know the root password or the user is not allowed to sudo" + echo "Please correct this and run the uninstaller again" + echo "(hint: use visudo to edit sudoers file or run the installer as root)" + echo "" + read -p "Press ENTER to exit uninstaller:" BLAH + exit 1 + fi + SUPER="sudo" +fi + ####################### # Check for xdg utils ####################### @@ -65,26 +103,26 @@ then if [ "T" = ${HAS_XDG} ]; then - sudo xdg-desktop-menu uninstall ${MENU_FILE_PATH} - sudo xdg-icon-resource uninstall --size 16 ${ICON_NAME} - sudo xdg-icon-resource uninstall --size 22 ${ICON_NAME} - sudo xdg-icon-resource uninstall --size 32 ${ICON_NAME} - sudo xdg-icon-resource uninstall --size 48 ${ICON_NAME} + ${SUPER} xdg-desktop-menu uninstall ${MENU_FILE_PATH} + ${SUPER} xdg-icon-resource uninstall --size 16 ${ICON_NAME} + ${SUPER} xdg-icon-resource uninstall --size 22 ${ICON_NAME} + ${SUPER} xdg-icon-resource uninstall --size 32 ${ICON_NAME} + ${SUPER} xdg-icon-resource uninstall --size 48 ${ICON_NAME} if [ -e /usr/share/icons/hicolor/scalable/apps/${ICON_NAME}.svg ]; then - sudo rm -f /usr/share/icons/hicolor/scalable/apps/${ICON_NAME}.svg + ${SUPER} rm -f /usr/share/icons/hicolor/scalable/apps/${ICON_NAME}.svg fi fi if [ -e ~/Desktop/${DESKTOP_LINK_FILE} ]; then - sudo rm -f ~/Desktop/${DESKTOP_LINK_FILE} + ${SUPER} rm -f ~/Desktop/${DESKTOP_LINK_FILE} fi # delete the old package - sudo rm -rf ${PGM_PATH} - sudo rm -f $0 + ${SUPER} rm -rf ${PGM_PATH} + ${SUPER} rm -f $0 else echo "" echo "!!! FAILURE !!! - install path ${PGM_PATH} does not exist."