util: create custom GNUSTEP dir if needed
[wmaker-crm.git] / util / wmaker.inst.in
blobad2a9a8448c1f9bf52facd12609c605e008aaf2c
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 else
65 if test "x$GNUSTEP_USER_ROOT" = "x"; then
66 sed -e "s:#wmdatadir#:$GLOBALDIR:g" \
67 "$source" > "$target"
68 else
69 sed -e "s|\$HOME/GNUstep|$GSDIR|g" \
70 -e "s:#wmdatadir#:$GLOBALDIR:g" \
71 "$source" > "$target"
77 # Generate WMRootmenu
79 GenerateMenu() {
80 wmgenmenu > $GSDIR/Defaults/WMRootMenu
83 echo "Installing WindowMaker $VERSION for current user..."
86 if [ ! -d "$GLOBALDIR" ]; then
87 echo "Could not find global data files"
88 echo "Make sure you have installed Window Maker correctly"
89 exit 1
92 if [ ! -d "$GLOBALDEFDIR" ]; then
93 echo "Could not find global configurations files"
94 echo "Make sure you have installed Window Maker correctly"
95 exit 1
98 if [ ! -d "$USERDIR" ]; then
99 echo "Could not find user directory $USERDIR"
100 exit 1
104 if test "x$GNUSTEP_USER_ROOT" = "x"; then
105 cd "$USERDIR"
106 GSDIR="$USERDIR/GNUstep"
107 if [ ! -d "$GSDIR" ]; then
108 echo "Creating $GSDIR user directory"
109 make_dir "$GSDIR"
111 else
112 GSDIR="$GNUSTEP_USER_ROOT"
113 if [ ! -d "$GSDIR" ]; then
114 # in this case, and in this case only, mkdir needs -p option
115 mkdir -p $GSDIR || {
116 echo "Directory specified in GNUSTEP_USER_ROOT environment variable does not exist"
117 exit 1
119 chmod +rwx $GSDIR || exit 1
121 cd "$GSDIR"
122 cd ..
126 if [ ! -d "$GSDIR/Defaults" ]; then
127 make_dir "$GSDIR/Defaults"
130 echo "Copying defaults database..."
132 FILES="$(cd "$GLOBALDEFDIR" && ls -d *)"
133 all=""
134 for i in $FILES; do
135 if [ ! -d "$GLOBALDEFDIR/$i" ]; then
136 if [ -f "$GSDIR/Defaults/$i" -a -z "$BATCH" ]; then
137 echo "The configuration file \"$i\" already exists in your defaults database."
138 echo "Do you wish to replace it? <y/n/a> [n] $all"
139 if [ "$all" != "a" ]; then
140 read foo
141 if [ "$foo" = "a" -o "$foo" = "A" ]; then
142 all="a"
145 if [ "$foo" = "y" -o "$foo" = "Y" -o "$all" = "a" ]; then
146 copy "$GLOBALDEFDIR/$i" "$GSDIR/Defaults/$i"
148 else
149 copy "$GLOBALDEFDIR/$i" "$GSDIR/Defaults/$i"
152 done
154 GenerateMenu
156 if [ ! -d "$GSDIR/Library/Icons/" ]; then
157 echo "Creating icon library directory $GSDIR/Library/Icons"
158 if [ ! -d "$GSDIR/Library" ]; then
159 make_dir "$GSDIR/Library"
161 make_dir "$GSDIR/Library/Icons"
165 if [ ! -d "$GSDIR/Library/WindowMaker/" ]; then
166 echo "Creating WindowMaker data library directory $GSDIR/Library/WindowMaker"
167 if [ ! -d "$GSDIR/Library" ]; then
168 make_dir "$GSDIR/Library"
170 make_dir "$GSDIR/Library/WindowMaker"
173 if [ ! -d "$GSDIR/Library/WindowMaker/Styles" ]; then
174 echo "Creating style library $GSDIR/Library/WindowMaker/Styles"
175 make_dir "$GSDIR/Library/WindowMaker/Styles"
179 if [ ! -d "$GSDIR/Library/WindowMaker/Themes" ]; then
180 echo "Creating theme library $GSDIR/Library/WindowMaker/Themes"
181 make_dir "$GSDIR/Library/WindowMaker/Themes"
185 if [ ! -d "$GSDIR/Library/WindowMaker/Backgrounds" ]; then
186 echo "Creating bg image library $GSDIR/Library/WindowMaker/Backgrounds"
187 make_dir "$GSDIR/Library/WindowMaker/Backgrounds"
188 else
189 echo "Default Backgrounds directory already exists. Skipping..."
193 if [ ! -d "$GSDIR/Library/WindowMaker/IconSets" ]; then
194 echo "Creating icon setup library $GSDIR/Library/WindowMaker/IconSets"
195 make_dir "$GSDIR/Library/WindowMaker/IconSets"
196 else
197 echo "Default IconSets directory already exists. Skipping..."
201 if [ ! -d "$GSDIR/Library/WindowMaker/Pixmaps" ]; then
202 echo "Creating pixmap library $GSDIR/Library/WindowMaker/Pixmaps"
203 make_dir "$GSDIR/Library/WindowMaker/Pixmaps"
204 else
205 echo "Default Pixmaps directory already exists. Skipping..."
209 if [ ! -d "$GSDIR/Library/WindowMaker/CachedPixmaps" ]; then
210 make_dir "$GSDIR/Library/WindowMaker/CachedPixmaps"
213 if [ ! -d "$GSDIR/Library/WindowMaker/WPrefs" ]; then
214 make_dir "$GSDIR/Library/WindowMaker/WPrefs"
217 if test -z "#LITE#" ; then
218 FILES="$(cd "$GLOBALDIR" && ls menu menu.* plmenu plmenu.?? wmmacros)"
219 for i in $FILES; do
220 # xx herbert
221 if [ -f "$GSDIR/Library/WindowMaker/$i" -a -z "$BATCH" ]; then
222 # /xx herbert
223 echo "The file \"$i\" already exists in $GSDIR/Library/WindowMaker"
224 echo "Do you wish to replace it? <y/n/a> [n] $all"
225 if [ "$all" != "a" ]; then
226 read foo
227 if [ "$foo" = "a" -o "$foo" = "A" ]; then
228 all="a"
231 if [ "$foo" = "y" -o "$foo" = "Y" -o "$foo" = "a" ]; then
232 copy "$GLOBALDIR/$i" "$GSDIR/Library/WindowMaker/$i"
234 else
235 copy "$GLOBALDIR/$i" "$GSDIR/Library/WindowMaker/$i"
237 done
240 cp "$GLOBALDIR/README.themes" "$GSDIR/Library/WindowMaker"
241 cp "$GLOBALDIR/README" "$GSDIR/Library/WindowMaker"
243 test -f "$GSDIR/Library/WindowMaker/autostart" || \
244 cp "$GLOBALDIR/autostart.sh" "$GSDIR/Library/WindowMaker/autostart"
245 chmod +rx "$GSDIR/Library/WindowMaker/autostart"
247 test -f "$GSDIR/Library/WindowMaker/exitscript" || \
248 cp "$GLOBALDIR/exitscript.sh" "$GSDIR/Library/WindowMaker/exitscript"
249 chmod +rx "$GSDIR/Library/WindowMaker/exitscript"
251 # xx herbert
252 if test -n "$BATCH" ; then
253 echo "Installation Finished"
254 exit 0
256 # /xx herbert
260 #######################
262 DATE="$(date +%b%d.%T)"
264 show_end_message() {
266 echo
267 echo "Installation Finished"
268 echo
269 echo "There are menus in 2 different file formats. The plain text format and"
270 echo "the property list format. The plain text format is more flexible, but"
271 echo "the menu in the property list format can be edited graphically. The"
272 echo "menu that will be used by default is the property list one. Read"
273 echo " $GSDIR/Library/WindowMaker/README"
274 echo "for information on how to change it."
275 if [ "${inst_menu%.*}" = "menu" ]; then
276 echo "However, since you have locale set to $LOCALE and plmenu for such locale"
277 echo "was not found, your WMRootMenu contains path to text formated menu:"
278 echo " $GSDIR/Library/WindowMaker/$inst_menu"
282 wmaker_found=0
283 for xinit in .xinitrc .Xclients .xsession; do
284 test ! -f "$HOME/$xinit" && continue
285 res="$(grep wmaker "$HOME/$xinit")"
286 if test "x$res" != x; then
287 wmaker_found=1
288 break
290 done
291 if test "$wmaker_found" = 1; then
292 echo "Found Window Maker to already be your default window manager."
293 show_end_message
294 exit 0
298 trap "show_end_message;exit" 2
300 echo
301 echo "Now the .xinitrc, .Xclients or .xsession script must be updated so that"
302 echo "it calls wmaker when you start an X session."
303 echo "Type the name of the file that must be changed (normally .xinitrc)."
304 echo "If the file already exists, it will be backed up with a .old.$DATE "
305 echo "extension"
306 echo "If you want to edit it by hand, hit <Control>-C now."
307 read file
309 if test "x$file" = "x"; then
310 echo "Using .xinitrc as a default value"
311 file=.xinitrc
314 if [ -f "$USERDIR/$file" ]; then
315 mv "$USERDIR/$file" "$USERDIR/$file.old.$DATE"
318 make_script "$USERDIR/$file"
320 show_end_message