wmaker.inst: quote shell variables
[wmaker-crm.git] / util / wmaker.inst.in
blob2acbbd613f2a984f7d349b8ba4716aec1d499ede
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="${LC_ALL-${LC_MESSAGES-$LANG}}"
19 # directory where system wide configuration is stored
20 GLOBALDIR="#pkgdatadir#"
21 GLOBALDEFDIR="#sysconfdir#"
23 USERDIR="$HOME"
25 VERSION="#version#"
27 BINDIR="#bindir#"
29 make_dir() {
30 mkdir "$1"
31 chmod +rwx "$1"
34 make_script() {
35 ISCRIPT="$1"
37 cat << EOF >> "$ISCRIPT"
38 # Window Maker default X session startup script
40 PATH="\$PATH:$BINDIR"
42 # If you login from xdm, uncomment this to make error messages appear
43 # in the console window.
45 # tail -f "$HOME"/.xsession-errors > /dev/console &
47 exec wmaker
49 EOF
50 chmod +rx "$ISCRIPT"
55 # Copy files considering special cases
57 copy() {
58 source="$1"
59 target="$2"
60 file="$(basename "$source")"
61 rm -f "$target"
62 if [ "$file" = "WindowMaker" ]; then
63 sed -e "s|~/GNUstep|$GSDIR|g" "$source" > "$target"
64 elif [ "$file" = "WMRootMenu" ]; then
65 if [ "$LOCALE" ]; then
66 if [ -f "$GLOBALDIR/plmenu.$LOCALE" ]; then
67 source="$GLOBALDIR/plmenu.$LOCALE"
68 elif [ -f "$GLOBALDIR/plmenu.${LOCALE%.*}" ]; then
69 source="$GLOBALDIR/plmenu.${LOCALE%.*}"
70 elif [ -f "$GLOBALDIR/plmenu.${LOCALE%_*}" ]; then
71 source="$GLOBALDIR/plmenu.${LOCALE%_*}"
72 elif [ -f "$GLOBALDIR/menu.${LOCALE%_*}" ]; then
73 source="$GLOBALDIR/menu.${LOCALE%_*}"
74 else
75 source="$GLOBALDIR/plmenu"
77 else
78 source="$GLOBALDIR/plmenu"
80 sed -e "s:#wmdatadir#:$GLOBALDIR:g" \
81 "$source" > "$GSDIR/Defaults/WMRootMenu"
82 else
83 if test "x$GNUSTEP_USER_ROOT" = "x"; then
84 sed -e "s:#wmdatadir#:$GLOBALDIR:g" \
85 "$source" > "$target"
86 else
87 sed -e "s|\$HOME/GNUstep|$GSDIR|g" \
88 -e "s:#wmdatadir#:$GLOBALDIR:g" \
89 "$source" > "$target"
96 echo "Installing WindowMaker $VERSION for current user..."
99 if [ ! -d "$GLOBALDIR" ]; then
100 echo "Could not find global data files"
101 echo "Make sure you have installed Window Maker correctly"
102 exit 1
105 if [ ! -d "$GLOBALDEFDIR" ]; then
106 echo "Could not find global configurations files"
107 echo "Make sure you have installed Window Maker correctly"
108 exit 1
111 if [ ! -d "$USERDIR" ]; then
112 echo "Could not find user directory $USERDIR"
113 exit 1
117 if test "x$GNUSTEP_USER_ROOT" = "x"; then
118 cd "$USERDIR"
119 GSDIR="$USERDIR/GNUstep"
120 if [ ! -d "$GSDIR" ]; then
121 echo "Creating $GSDIR user directory"
122 make_dir "$GSDIR"
124 else
125 GSDIR="$GNUSTEP_USER_ROOT"
126 if [ ! -d "$GSDIR" ]; then
127 echo "Directory specified in GNUSTEP_USER_ROOT environment variable does not exist"
128 exit 1
130 cd "$GSDIR"
131 cd ..
135 if [ ! -d "$GSDIR/Defaults" ]; then
136 make_dir "$GSDIR/Defaults"
139 echo "Copying defaults database..."
141 FILES="$(cd "$GLOBALDEFDIR" && ls -d *)"
142 all=""
143 for i in $FILES; do
144 if [ ! -d "$GLOBALDEFDIR/$i" ]; then
145 if [ -f "$GSDIR/Defaults/$i" -a -z "$BATCH" ]; then
146 echo "The configuration file \"$i\" already exists in your defaults database."
147 echo "Do you wish to replace it? <y/n/a> [n] $all"
148 if [ "$all" != "a" ]; then
149 read foo
150 if [ "$foo" = "a" -o "$foo" = "A" ]; then
151 all="a"
154 if [ "$foo" = "y" -o "$foo" = "Y" -o "$all" = "a" ]; then
155 copy "$GLOBALDEFDIR/$i" "$GSDIR/Defaults/$i"
157 else
158 copy "$GLOBALDEFDIR/$i" "$GSDIR/Defaults/$i"
161 done
164 if [ ! -d "$GSDIR/Library/Icons/" ]; then
165 echo "Creating icon library directory $GSDIR/Library/Icons"
166 if [ ! -d "$GSDIR/Library" ]; then
167 make_dir "$GSDIR/Library"
169 make_dir "$GSDIR/Library/Icons"
173 if [ ! -d "$GSDIR/Library/WindowMaker/" ]; then
174 echo "Creating WindowMaker data library directory $GSDIR/Library/WindowMaker"
175 if [ ! -d "$GSDIR/Library" ]; then
176 make_dir "$GSDIR/Library"
178 make_dir "$GSDIR/Library/WindowMaker"
181 if [ ! -d "$GSDIR/Library/WindowMaker/Styles" ]; then
182 echo "Creating style library $GSDIR/Library/WindowMaker/Styles"
183 make_dir "$GSDIR/Library/WindowMaker/Styles"
187 if [ ! -d "$GSDIR/Library/WindowMaker/Themes" ]; then
188 echo "Creating theme library $GSDIR/Library/WindowMaker/Themes"
189 make_dir "$GSDIR/Library/WindowMaker/Themes"
193 if [ ! -d "$GSDIR/Library/WindowMaker/Backgrounds" ]; then
194 echo "Creating bg image library $GSDIR/Library/WindowMaker/Backgrounds"
195 make_dir "$GSDIR/Library/WindowMaker/Backgrounds"
196 else
197 echo "Default Backgrounds directory already exists. Skipping..."
201 if [ ! -d "$GSDIR/Library/WindowMaker/IconSets" ]; then
202 echo "Creating icon setup library $GSDIR/Library/WindowMaker/IconSets"
203 make_dir "$GSDIR/Library/WindowMaker/IconSets"
204 else
205 echo "Default IconSets directory already exists. Skipping..."
209 if [ ! -d "$GSDIR/Library/WindowMaker/Pixmaps" ]; then
210 echo "Creating pixmap library $GSDIR/Library/WindowMaker/Pixmaps"
211 make_dir "$GSDIR/Library/WindowMaker/Pixmaps"
212 else
213 echo "Default Pixmaps directory already exists. Skipping..."
217 if [ ! -d "$GSDIR/Library/WindowMaker/CachedPixmaps" ]; then
218 make_dir "$GSDIR/Library/WindowMaker/CachedPixmaps"
221 if [ ! -d "$GSDIR/Library/WindowMaker/WPrefs" ]; then
222 make_dir "$GSDIR/Library/WindowMaker/WPrefs"
225 if test -z "#LITE#" ; then
226 FILES="$(cd "$GLOBALDIR" && ls menu menu.* plmenu plmenu.?? wmmacros)"
227 for i in $FILES; do
228 # xx herbert
229 if [ -f "$GSDIR/Library/WindowMaker/$i" -a -z "$BATCH" ]; then
230 # /xx herbert
231 echo "The file \"$i\" already exists in $GSDIR/Library/WindowMaker"
232 echo "Do you wish to replace it? <y/n/a> [n] $all"
233 if [ "$all" != "a" ]; then
234 read foo
235 if [ "$foo" = "a" -o "$foo" = "A" ]; then
236 all="a"
239 if [ "$foo" = "y" -o "$foo" = "Y" -o "$foo" = "a" ]; then
240 copy "$GLOBALDIR/$i" "$GSDIR/Library/WindowMaker/$i"
242 else
243 copy "$GLOBALDIR/$i" "$GSDIR/Library/WindowMaker/$i"
245 done
248 cp "$GLOBALDIR/README.themes" "$GSDIR/Library/WindowMaker"
249 cp "$GLOBALDIR/README" "$GSDIR/Library/WindowMaker"
251 test -f "$GSDIR/Library/WindowMaker/autostart" || \
252 cp "$GLOBALDIR/autostart.sh" "$GSDIR/Library/WindowMaker/autostart"
253 chmod +rx "$GSDIR/Library/WindowMaker/autostart"
255 test -f "$GSDIR/Library/WindowMaker/exitscript" || \
256 cp "$GLOBALDIR/exitscript.sh" "$GSDIR/Library/WindowMaker/exitscript"
257 chmod +rx "$GSDIR/Library/WindowMaker/exitscript"
259 # xx herbert
260 if test -n "$BATCH" ; then
261 echo "Installation Finished"
262 exit 0
264 # /xx herbert
268 #######################
270 DATE="$(date +%b%d.%T)"
272 show_end_message() {
274 echo
275 echo "Installation Finished"
276 echo
277 if test -z "#LITE#" ; then
278 echo "There are menus in 2 different file formats. The plain text format and"
279 echo "the property list format. The plain text format is more flexible, but"
280 echo "the menu in the property list format can be edited graphically. The"
281 echo "menu that will be used by default is the property list one. Read"
282 echo " $GSDIR/Library/WindowMaker/README"
283 echo "for information on how to change it."
284 if [ "${inst_menu%.*}" = "menu" ]; then
285 echo "However, since you have locale set to $LOCALE and plmenu for such locale"
286 echo "was not found, your WMRootMenu contains path to text formated menu:"
287 echo " $GSDIR/Library/WindowMaker/$inst_menu"
289 else
290 echo "Your copy of Window Maker is configured especially for KDE."
291 echo "Window Maker application menus are not available."
295 wmaker_found=0
296 for xinit in .xinitrc .Xclients .xsession; do
297 test ! -f "$HOME/$xinit" && continue
298 res="$(grep wmaker "$HOME/$xinit")"
299 if test "x$res" != x; then
300 wmaker_found=1
301 break
303 done
304 if test "$wmaker_found" = 1; then
305 echo "Found Window Maker to already be your default window manager."
306 show_end_message
307 exit 0
311 trap "show_end_message;exit" 2
313 echo
314 echo "Now the .xinitrc, .Xclients or .xsession script must be updated so that"
315 echo "it calls wmaker when you start an X session."
316 echo "Type the name of the file that must be changed (normally .xinitrc)."
317 echo "If the file already exists, it will be backed up with a .old.$DATE "
318 echo "extension"
319 echo "If you want to edit it by hand, hit <Control>-C now."
320 read file
322 if test "x$file" = "x"; then
323 echo "Using .xinitrc as a default value"
324 file=.xinitrc
327 if [ -f "$USERDIR/$file" ]; then
328 mv "$USERDIR/$file" "$USERDIR/$file.old.$DATE"
331 make_script "$USERDIR/$file"
333 show_end_message