If you will take my advice you will think little of Socrates, and a great deal more of truthSocrates
1 | 2
6 - 8 [8]
Also relates to X11
Many of the applications I use on a daily basis come from the KDE toolkit or other X11 software most notably Konqueror, eSVN, Kompare, Karm, XEmacs and (of course) Amarok. If I am working extensively with KDE apps I will load up the K Desktop Environment as my window manager in full screen mode. However, sometimes I find I want to share X11 and native OS X applications. It is a little frustrating having to keep changing the initialisation file for X11 and switch to rootless mode in the Preferences pane. So I decided to concote a script to do this automatically.
By default my .xinitrc file will start up KDE with:
startkde >/tmp/kde.log 2>&1
Then I also have a start up file for the quartz window manager (.xinitrc.quartz) with:
exec quartz-wm
Then the startup script for X11 applications (based on the Xdroplets scripts) looks to see if X11 is already running by searching for display lock files in the tmp dir. If it is not another script is called which switches X11 to rootless mode and boots it with the Quartz window manager initialisation file. This allows me to start up X11 using its application link if I want to use KDE or to just open an X11 application if I want it to run in rootless mode seamlessly with native OSX applications.
The main challenge with achieveing this is switching the preference since this is stored in a binary plist file (~/Library/Preferences/com.apple.x11.plist). Fortunately the property list utility (plutil command) makes this task relatively simple:
if [ ! -z $1 ] && [ $1 == 'false' ] ; then
pattern='s/true/false/'
else
pattern='s/false/true/'
fi
plutil -convert xml1 -o /tmp/com.apple.x11.plist ~/Library/Preferences/com.apple.x11.plist
sed "/rootless/{ n; $pattern; }" /tmp/com.apple.x11.plist > /tmp/com.apple.x11-new.plist
plutil -convert binary1 -o ~/Library/Preferences/com.apple.x11.plist /tmp/com.apple.x11-new.plist
\rm /tmp/com.apple.x11{,-new}.plist
The property list utility converts the binary file to XML so that sed can then replace the state of the rootless property. So now I can open an X11 app or two without having to either boot a KDE session or reconfigure my .xinitrc or X11 preferences.
Posted on Aug 18, 2005 at 23:40:13. [Comments for Automating X11 Rootless Mode- 0]
Also relates to Apache and UNIX
Earlier I was setting up a couple of shell scripts to allow me to quickly switch between PHP versions on the Apache web server and enable/disable my unit testing environment in OS X. Along the lines of:
apachectl stop
httpd -f /usr/local/php5/httpd.conf
Since such scripts must be run as root user I wanted to concote a little script to check I had used sudo to run the commands (as I have a habit of forgetting!). Firstly I came up with the following:
#!/bin/sh
# verify-su
umask 222
touch /tmp/user-status
echo `whoami` 2> /dev/null >| /tmp/user-status
if [ $? -ne 0 ] ; then
if [ $# -eq 0 ] ; then
"This command must be run with root privileges!"
else
"$1 must be run with root privileges!"
fi
exit 1
fi
\rm /tmp/user-status
exit 0
A file is created with read only permissions (by temporarily changing umask) and then the script
attempts to write to it. The output redirection to file will only succeed if the script is run as root (the superuser).
In running this without the rm command I discovered that a script executed with sudo will return root from the whoami command instead of the user name I am currently logged in with. So this could actually be simplified considerably to:
if [ `whoami` != 'root' ] ; then
# etc …
exit 1
else
exit 0
fi
There is always a simpler way to do things!
Posted on Jun 20, 2005 at 19:12:51. [Comments for Verify Sudo in Script Execution- 1]
Also relates to X11
Not been much time to blog recently with all out of hours preoccupied with my newly acquired Apple Ibook. Only a week old, she has far and away exceeded all expectations. Within 48 hours I felt familiar with the OSX interface - considerably more user friendly than its PC counterpart and had filled up half a gigabyte with my favourite songs, plus a few nostalgic memories courtesy of the ITunes store. One frustration was the apparent absence of Apples X11 disk image anywhere on the hard drive or accompanying discs. But this probably was for the best, as I decided rather than downloading the installer from the Apple site to instead go with Fink and the somewhat purer XFree86 variant, XDarwin. So a few sleepless nights and longhaul downloads later, I now have GNOME set up and running smoothly (bar one or two glitches), giving me access to the Gimp, Nautilus (a great file explorer!), Bluefish editor and an Amaya release which actually includes the bookmarks feature to name just a few. Add the ability to run the Xserver rootless (actually using Xnest) I still have access to all those OSX applications - superb! And then there is my free OSX upgrade to Tiger still to come once it has stabilised.
This is just a quick summary really, and if I can find time to drag myself away from the captivating transit of Io in my RXVT shell - courtesy of Xplanet - I will post some extended blogs on my first experiences and the tools that assisted me in getting my Ibook development ready.
Posted on May 05, 2005 at 15:23:59. [Comments for AWOL Explained- 2]