The Testing Area :: April extensions



Thanks for your input and scripts.  I did not realize how many apps in base were linked to the gtk+-2.12.9 libs when the extension was loaded.  And nothing seems broken, except for /usr/bin/fc-cache that gives an error about scanning directories.  I will put a menu extension to automate the configuration.
Jason: in that setup script, which I didn't actually test until now, cp complains about overwriting a symlink with its target even with the force option, so I've:

- edited it to remove the target  before copying.
- only need a backup of the file if it isn't a symlink - changed.

So suggest using the updated version.

Ok, here is pretty much what i plan to include in the menu - a setup and a remove setup entry.  The setup:

Code Sample

#!/bin/bash
#Script to setup gtk+-2.12.9
#Idea and script by WDef, tweaked for dialog.

dialog --title "Setup GTK+-2.12.9" --yesno "This setup will cause the system to link programs to the newer libraries in /opt/gtk+-2.12.9/lib in priority over those in the system or other extensions.  This is basically harmless and shouldn't break anything.  Do you want to proceed?" 20 50 3


if [ $? = 1 ]; then
dialog --title "Setup GTK+-2.12.9" --msgbox "No changes were made.  Exiting.." 20 50 10

else

# Check for the existance of /etc/ld.so.conf
if [ ! -e /etc/ld.so.conf ]; then
dialog --title "Setup GTK+-2.12.9" --msgbox "You do not have an /etc/ld.so.conf.  Something is very wrong.  Exiting.." 20 50 3
exit 1;
fi
# Check for /etc/ld.so.conf entry.
if head -1 /etc/ld.so.conf | grep /opt/gtk+-2.12.9/lib > /dev/null 2>&1; then
sudo ldconfig
dialog --title "Setup GTK+-2.12.9" --msgbox "GTK+-2.12.9 is already set up on the system.  No changes were made.  Exiting..." 20 50 3    
      # already done
      exit 1;
       
   fi

# Get rid of symlink and copy file from KNOPPIX image if needed.
if [ -L /etc/ld.so.conf ]; then
       sudo rm -f /etc/ld.so.conf
       sudo cp /KNOPPIX/etc/ld.so.conf /etc/ld.so.conf
    else
       sudo cp -f /etc/ld.so.conf /etc/ld.so.conf.bak
fi

# Add entry to first line of /etc/ld.so.conf.

sudo sed -i '1 i\
/opt/gtk+-2.12.9/lib' /etc/ld.so.conf
sudo ldconfig
dialog --title "Setup GTK+-2.12.9" --msgbox "Finished setup.  GTK+-2.12.9 is ready for use." 20 50 10
fi



The unsetup:


Code Sample

#!/bin/bash
#Script to unsetup gtk+-2.12.9
#Idea and script by WDef, tweaked for dialog.

dialog --title "Deconfigure GTK+-2.12.9" --yesno "This setup will restore your /etc/ld.so.conf file and library linking to the state it was before running the setup menu for GTK+-2.12.9.  Do you want to proceed?" 20 50 3

if [ $? = 1 ]; then
dialog --title "Deconfigure GTK+-2.12.9" --msgbox "No changes were made.  Exiting.." 20 50 10

else

# Check for the existance of /etc/ld.so.conf
if [ ! -e /etc/ld.so.conf ]; then
dialog --title "Deconfigure GTK+-2.12.9" --msgbox "You do not have an /etc/ld.so.conf.  Something is very wrong.  Exiting.." 20 50 3
exit 1;
fi

# Check for /etc/ld.so.conf entry.
if head -1 /etc/ld.so.conf | grep /opt/gtk+-2.12.9/lib > /dev/null 2>&1; then
sudo sed -i 1d /etc/ld.so.conf
sudo ldconfig
dialog --title "Deconfigure GTK+-2.12.9" --msgbox "/opt/gtk+-2.12.9/lib was removed from the first line of /etc/ld.so.conf and ldconfig was run.  Exiting..." 20 50 3
else
dialog --title "Deconfigure GTK+-2.12.9" --msgbox "GTK+-2.12.9 is not setup on the system.  No changes were made.  Exiting..." 20 50 3    
      # already done
      exit 1;  
   fi
fi


Seems to work and make things easier.   Thanks again.

Quote (Jason W @ May 03 2008,00:58)
Ok, here is pretty much what i plan to include in the menu - a setup and a remove setup entry.

Some comments after a glance at the code:

- are you sure you want to only look at the first line? What if other extensions want to do something similar, etc.?
- the grep line may work, but it's actually checking wildcards.  You'd need to escape it, or use -F, etc. and use anchors.  A better way may be to use test (i.e. if [ `command` = "this" ]; then ) while (maybe) saving on some trivial resources

Good to use dialog to inform the user something's happened (see the loop-aes extension module setup script for something similar).

I'd probably just call it with sudo from the menu and save typing redundant sudos everywhere (less clutter is usually good practice).  If you are concerned non-X users might run it as ordinary user and wonder why it's broken, the usual thing is test if it's being run with root rights at the beginning:

Code Sample
if [ $EUID -ne 0 ];then
      echo "You're not root, exiting .."
      exit 1
fi


But it doesn't really matter much, whatever you' re happy with.

Next Page...
original here.