- s/sprintf/snprintf
[wmaker-crm.git] / util / wmaker.inst.in
blob91671ca9ba273a12e96a55259a6f221e6b289e27
1 #!/bin/sh
3 # Install Window Maker for the current user
6 # xx herbert
7 if test "x$1" = "x--batch" ; then
8 BATCH="1"
9 else
10 BATCH=""
12 # /xx herbert
14 # name of menu file we install (menu, plmenu)
15 inst_menu=""
17 LOCALE=$LANG
18 if [ -z "$LOCALE" ]; then
19 LOCALE=$LC_ALL
22 # directory where system wide configuration is stored
23 GLOBALDIR="#pkgdatadir#"
24 GLOBALDEFDIR="#sysconfdir#"
26 USERDIR=$HOME
28 VERSION="#version#"
30 BINDIR="#bindir#"
32 make_dir() {
33 mkdir $1
34 chmod +rwx $1
37 make_script() {
38 ISCRIPT=$1
40 cat << EOF >> $ISCRIPT
41 # Window Maker default X session startup script
43 PATH="\$PATH:$BINDIR"
45 # If you login from xdm, uncomment this to make error messages appear
46 # in the console window.
48 # tail -f $HOME/.xsession-errors > /dev/console &
50 exec wmaker
52 EOF
53 chmod +rx $ISCRIPT
58 # Copy files considering special cases
60 copy() {
61 source=$1
62 target=$2
63 file=`basename $source`
64 rm -f $target
65 if [ "$file" = "WindowMaker" ]; then
66 sed -e "s|~/GNUstep|$GSDIR|g" $source > $target
67 elif [ "$file" = "WMRootMenu" ]; then
68 if [ "$LOCALE" ]; then
69 if [ -f $GLOBALDIR/plmenu.${LOCALE%_*} ]; then
70 source=$GLOBALDIR/plmenu.${LOCALE%_*}
71 elif [ -f $GLOBALDIR/menu.${LOCALE%_*} ]; then
72 source=$GLOBALDIR/menu.${LOCALE%_*}
73 else
74 source=$GLOBALDIR/plmenu
76 else
77 source=$GLOBALDIR/plmenu
79 sed -e "s:#wmdatadir#:$GLOBALDIR:g" \
80 $source > $GSDIR/Defaults/WMRootMenu
81 else
82 if test "x$GNUSTEP_USER_ROOT" = "x"; then
83 sed -e "s:#wmdatadir#:$GLOBALDIR:g" \
84 $source > $target
85 else
86 sed -e "s|\$HOME/GNUstep|$GSDIR|g" \
87 -e "s:#wmdatadir#:$GLOBALDIR:g" \
88 $source > $target
95 echo "Installing WindowMaker $VERSION for current user..."
98 if [ ! -d $GLOBALDIR ]; then
99 echo "Could not find global data files"
100 echo "Make sure you have installed Window Maker correctly"
101 exit 1
104 if [ ! -d $GLOBALDEFDIR ]; then
105 echo "Could not find global configurations files"
106 echo "Make sure you have installed Window Maker correctly"
107 exit 1
110 if [ ! -d "$USERDIR" ]; then
111 echo "Could not find user directory $USERDIR"
112 exit 1
116 if test "x$GNUSTEP_USER_ROOT" = "x"; then
117 cd $USERDIR
118 GSDIR=$USERDIR/GNUstep
119 if [ ! -d $GSDIR ]; then
120 echo "Creating $GSDIR user directory"
121 make_dir $GSDIR
123 else
124 GSDIR=$GNUSTEP_USER_ROOT
125 if [ ! -d $GSDIR ]; then
126 echo "Directory specified in GNUSTEP_USER_ROOT environment variable does not exist"
127 exit 1
129 cd $GSDIR
130 cd ..
134 if [ ! -d "$GSDIR/.AppInfo" ]; then
135 make_dir $GSDIR/.AppInfo
138 if [ ! -d "$GSDIR/Defaults" ]; then
139 make_dir $GSDIR/Defaults
142 echo "Copying defaults database..."
144 FILES=`(cd $GLOBALDEFDIR;ls -d *)`
145 all=""
146 for i in $FILES; do
147 if [ ! -d $GLOBALDEFDIR/$i ]; then
148 if [ -f $GSDIR/Defaults/$i -a -z "$BATCH" ]; then
149 echo "The configuration file \"$i\" already exists in your defaults database."
150 echo "Do you wish to replace it? <y/n/a> [n] $all"
151 if [ "$all" != "a" ]; then
152 read foo
153 if [ "$foo" = "a" -o "$foo" = "A" ]; then
154 all="a"
157 if [ "$foo" = "y" -o "$foo" = "Y" -o "$all" = "a" ]; then
158 copy $GLOBALDEFDIR/$i $GSDIR/Defaults/$i
160 else
161 copy $GLOBALDEFDIR/$i $GSDIR/Defaults/$i
164 done
167 if [ ! -d "$GSDIR/Library/Icons/" ]; then
168 echo "Creating icon library directory $GSDIR/Library/Icons"
169 if [ ! -d $GSDIR/Library ]; then
170 make_dir $GSDIR/Library
172 make_dir $GSDIR/Library/Icons
176 if [ ! -d "$GSDIR/Library/WindowMaker/" ]; then
177 echo "Creating WindowMaker data library directory $GSDIR/Library/WindowMaker"
178 if [ ! -d $GSDIR/Library ]; then
179 make_dir $GSDIR/Library
181 make_dir $GSDIR/Library/WindowMaker
184 if [ ! -d "$GSDIR/Library/WindowMaker/Styles" ]; then
185 echo "Creating style library $GSDIR/Library/WindowMaker/Styles"
186 make_dir $GSDIR/Library/WindowMaker/Styles
190 if [ ! -d "$GSDIR/Library/WindowMaker/Themes" ]; then
191 echo "Creating theme library $GSDIR/Library/WindowMaker/Themes"
192 make_dir $GSDIR/Library/WindowMaker/Themes
197 if [ ! -d "$GSDIR/Library/WindowMaker/Backgrounds" ]; then
198 echo "Creating bg image library $GSDIR/Library/WindowMaker/Backgrounds"
199 make_dir $GSDIR/Library/WindowMaker/Backgrounds
200 else
201 echo "Default Backgrounds directory already exists. Skipping..."
205 if [ ! -d "$GSDIR/Library/WindowMaker/IconSets" ]; then
206 echo "Creating icon setup library $GSDIR/Library/WindowMaker/IconSets"
207 make_dir $GSDIR/Library/WindowMaker/IconSets
208 else
209 echo "Default IconSets directory already exists. Skipping..."
213 if [ ! -d "$GSDIR/Library/WindowMaker/Pixmaps" ]; then
214 echo "Creating pixmap library $GSDIR/Library/WindowMaker/Pixmaps"
215 make_dir $GSDIR/Library/WindowMaker/Pixmaps
216 else
217 echo "Default Pixmaps directory already exists. Skipping..."
221 if [ ! -d "$GSDIR/Library/WindowMaker/Sounds" ]; then
222 echo "Creating sound library $GSDIR/Library/WindowMaker/Sounds"
223 make_dir $GSDIR/Library/WindowMaker/Sounds
224 else
225 echo "Default Sounds directory already exists. Skipping..."
229 if [ ! -d "$GSDIR/Library/WindowMaker/SoundSets" ]; then
230 echo "Creating sound set library $GSDIR/Library/WindowMaker/SoundSets"
231 make_dir $GSDIR/Library/WindowMaker/SoundSets
232 else
233 echo "Default SoundSets directory already exists. Skipping..."
237 if test -z "#LITE#" ; then
238 FILES=`(cd $GLOBALDIR; ls menu menu.* plmenu plmenu.?? wmmacros)`
239 for i in $FILES; do
240 # xx herbert
241 if [ -f "$GSDIR/Library/WindowMaker/$i" -a -z "$BATCH" ]; then
242 # /xx herbert
243 echo "The file \"$i\" already exists in $GSDIR/Library/WindowMaker"
244 echo "Do you wish to replace it? <y/n/a> [n] $all"
245 if [ "$all" != "a" ]; then
246 read foo
247 if [ "$foo" = "a" -o "$foo" = "A" ]; then
248 all="a"
251 if [ "$foo" = "y" -o "$foo" = "Y" -o "$foo" = "a" ]; then
252 copy $GLOBALDIR/$i $GSDIR/Library/WindowMaker/$i
254 else
255 copy $GLOBALDIR/$i $GSDIR/Library/WindowMaker/$i
257 done
260 cp $GLOBALDIR/README.themes $GSDIR/Library/WindowMaker
261 cp $GLOBALDIR/README $GSDIR/Library/WindowMaker
263 test -f ~$GSDIR/Library/WindowMaker/autostart || \
264 cp $GLOBALDIR/autostart.sh $GSDIR/Library/WindowMaker/autostart
265 chmod +rx $GSDIR/Library/WindowMaker/autostart
267 test -f ~$GSDIR/Library/WindowMaker/exitscript || \
268 cp $GLOBALDIR/exitscript.sh $GSDIR/Library/WindowMaker/exitscript
269 chmod +rx $GSDIR/Library/WindowMaker/exitscript
271 # no need to call wmchlocale --auto, since national menu is already copied
272 wsetfont --auto
274 # xx herbert
275 if test -n "$BATCH" ; then
276 echo "Installation Finished"
277 exit 0
279 # /xx herbert
283 #######################
285 DATE=`date +%b%d.%T`
287 show_end_message() {
289 echo
290 echo "Installation Finished"
291 echo
292 if test -z "#LITE#" ; then
293 echo "There are menus in 2 different file formats. The plain text format and"
294 echo "the property list format. The plain text format is more flexible, but"
295 echo "the menu in the property list format can be edited graphically. The"
296 echo "menu that will be used by default is the property list one. Read"
297 echo " $GSDIR/Library/WindowMaker/README"
298 echo "for information on how to change it."
299 if [ "${inst_menu%.*}" = "menu" ]; then
300 echo "However, since you have locale set to $LOCALE and plmenu for such locale"
301 echo "was not found, your WMRootMenu contains path to text formated menu:"
302 echo " $GSDIR/Library/WindowMaker/$inst_menu"
304 else
305 echo "Your copy of Window Maker is configured especially for KDE."
306 echo "Window Maker application menus are not available."
310 wmaker_found=0
311 for xinit in .xinitrc .Xclients .xsession; do
312 test ! -f "$HOME/$xinit" && continue
313 res="`grep wmaker $HOME/$xinit`"
314 if test "x$res" != x; then
315 wmaker_found=1
316 break
318 done
319 if test $wmaker_found = 1; then
320 echo "Found Window Maker to already be your default window manager."
321 show_end_message
322 exit 0
326 trap "show_end_message;exit" 2
328 echo
329 echo "Now the .xinitrc, .Xclients or .xsession script must be updated so that"
330 echo "it calls wmaker when you start an X session."
331 echo "Type the name of the file that must be changed (normally .xinitrc)."
332 echo "If the file already exists, it will be backed up with a .old.$DATE "
333 echo "extension"
334 echo "If you want to edit it by hand, hit <Control>-C now."
335 read file
337 if test "x$file" = "x"; then
338 echo "Using .xinitrc as a default value"
339 file=.xinitrc
342 if [ -f $USERDIR/$file ]; then
343 mv $USERDIR/$file $USERDIR/$file.old.$DATE
346 make_script $USERDIR/$file
348 show_end_message