#!/bin/bash
#

# Cambiar por otra ruta si es necesario
#PREFIX=/tmp/fvwm95
PREFIX=/usr/local

echo ""
echo "Se instalará FVWM95 en $PREFIX"
echo "Si no estás de acuerdo con la ruta, aborta la instalación y cámbiala"
read -s -n 1

# Instalación (copiado de "make install")
for i in libs fvwm modules utils sample.fvwmrc xpmroot pixmaps mini-icons docs; do \
	echo Installing in $i
done
cd libs
mkdir -p $PREFIX/lib
install -c -m 644 libfvwm95.a $PREFIX/lib
cd ..
cd fvwm
mkdir -p $PREFIX/bin
install -c fvwm95 $PREFIX/bin
mkdir -p $PREFIX/man/man1
install -c -m 644 fvwm95.man $PREFIX/man/man1/fvwm95.1 
cd ..
cd modules
mkdir -p $PREFIX/lib/X11/fvwm95
for i in FvwmAudio FvwmAuto FvwmBacker FvwmBanner FvwmButtons FvwmConsole FvwmCpp FvwmDebug FvwmForm FvwmIconBox FvwmIconMan FvwmIdent FvwmM4 FvwmPager FvwmSave FvwmSaveDesk FvwmScript FvwmScroll FvwmTalk FvwmTaskBar FvwmWinList FvwmWharf; do \
	echo Installing in $i
done
cd FvwmAudio
install -c FvwmAudio $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmAudio.man $PREFIX/man/man1/FvwmAudio.1 
cd ..
cd FvwmAuto
install -c FvwmAuto $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmAuto.man $PREFIX/man/man1/FvwmAuto.1 
cd ..
cd FvwmBacker
install -c FvwmBacker $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmBacker.man $PREFIX/man/man1/FvwmBacker.1 
cd ..
cd FvwmBanner
install -c FvwmBanner $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmBanner.man $PREFIX/man/man1/FvwmBanner.1 
cd ..
cd FvwmButtons
install -c FvwmButtons $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmButtons.man $PREFIX/man/man1/FvwmButtons.1 
cd ..
cd FvwmConsole
install -c FvwmConsole $PREFIX/lib/X11/fvwm95
install -c FvwmConsoleC $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmConsole.man $PREFIX/man/man1/FvwmConsole.1 
cd ..
cd FvwmCpp
install -c FvwmCpp $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmCpp.man $PREFIX/man/man1/FvwmCpp.1 
cd ..
cd FvwmDebug
install -c FvwmDebug $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmDebug.man $PREFIX/man/man1/FvwmDebug.1 
cd ..
cd FvwmForm
install -c FvwmForm $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmForm.man $PREFIX/man/man1/FvwmForm.1 
cd ..
cd FvwmIconBox
install -c FvwmIconBox $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmIconBox.man $PREFIX/man/man1/FvwmIconBox.1 
cd ..
cd FvwmIconMan
install -c FvwmIconMan $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmIconMan.man $PREFIX/man/man1/FvwmIconMan.1 
cd ..
cd FvwmIdent
install -c FvwmIdent $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmIdent.man $PREFIX/man/man1/FvwmIdent.1 
cd ..
cd FvwmM4
install -c FvwmM4 $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmM4.man $PREFIX/man/man1/FvwmM4.1 
cd ..
cd FvwmPager
install -c FvwmPager $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmPager.man $PREFIX/man/man1/FvwmPager.1 
cd ..
cd FvwmSave
install -c FvwmSave $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmSave.man $PREFIX/man/man1/FvwmSave.1 
cd ..
cd FvwmSaveDesk
install -c FvwmSaveDesk $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmSaveDesk.man $PREFIX/man/man1/FvwmSaveDesk.1 
cd ..
cd FvwmScript
install -c FvwmScript $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmScript.man $PREFIX/man/man1/FvwmScript.1 
cd Scripts
mkdir -p $PREFIX/lib/X11/fvwm95/scripts
for i in BellSetup Buttons Date DeskSetup FileBrowser KeyboardSetup PointerSetup Quit ScreenDump ScreenSetup ; do \
	echo Installing $i ; \
	(install -c -m 644 $i $PREFIX/lib/X11/fvwm95/scripts) \
done
cd ..
cd ..
cd FvwmScroll
install -c FvwmScroll $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmScroll.man $PREFIX/man/man1/FvwmScroll.1 
cd ..
cd FvwmTalk
install -c FvwmTalk $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmTalk.man $PREFIX/man/man1/FvwmTalk.1 
cd ..
cd FvwmTaskBar
install -c FvwmTaskBar $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmTaskBar.man $PREFIX/man/man1/FvwmTaskBar.1 
mkdir -p $PREFIX/lib/X11/fvwm95/plugins
for i in CheckLockModule.so GoodyModule.so ShowDateModule.so MailCheckModule.so BatStatModule.so; do \
	echo Installing $i ; \
	(install -c $i  $PREFIX/lib/X11/fvwm95/plugins/ ) \
done
cd ..
cd FvwmWinList
install -c FvwmWinList $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmWinList.man $PREFIX/man/man1/FvwmWinList.1 
cd ..
cd FvwmWharf
install -c FvwmWharf $PREFIX/lib/X11/fvwm95
install -c -m 644 FvwmWharf.man $PREFIX/man/man1/FvwmWharf.1 
cd ..
cd ..
cd utils
for i in fvwmrc_convert quantize_pixmaps ; do \
	install -c ./$i $PREFIX/bin ; \
done
cd ..
echo "Installing in sample.fvwmrc"
cd sample.fvwmrc
install -c -m 644 system.fvwm95rc $PREFIX/lib/X11/fvwm95 
ln -s $PREFIX/lib/X11/fvwm95/system.fvwm95rc $PREFIX/lib/X11/fvwm95/.fvwm95rc  
cd ..
cd xpmroot
install -c xpmroot $PREFIX/bin
install -c -m 644 xpmroot.man $PREFIX/man/man1/xpmroot.1 
cd ..
cd pixmaps
echo Installing pixmaps in $PREFIX/lib/X11/pixmaps  
mkdir -p $PREFIX/lib/X11/pixmaps
for i in Calculator.xpm Jxlock.xpm MailEmpty.xpm MailFull.xpm Mosaic.xpm N.xpm Pinky.xpm Terminal.xpm Xfm.xpm arrdown2.xpm arrows.xpm arrows2.xpm arrup2.xpm atom.xpm bckgnd1.xpm bckgnd3.xpm bell.xpm bomb.xpm bomb_3d.xpm book_index.xpm book_library.xpm clamp.xpm color_chart.xpm colormap.xpm colours.xpm communicatora1616.xpm communicatora3232.xpm communicatorb1616.xpm communicatorb3232.xpm communicatorc1616.xpm communicatorc3232.xpm communicatord1616.xpm communicatord3232.xpm communicatore1616.xpm communicatore3232.xpm communicatorf1616.xpm communicatorf3232.xpm communicatorg1616.xpm communicatorg3232.xpm communicatorh1616.xpm communicatorh3232.xpm communicatori1616.xpm communicatori3232.xpm communicatorj1616.xpm communicatorj3232.xpm communicatork1616.xpm communicatork3232.xpm communicatorl1616.xpm communicatorl3232.xpm date.xpm datebook.xpm desk.xpm desktop.xpm dialog_box.xpm disk.xpm disk_3D.xpm disk_run.xpm display.xpm documents.xpm dont_panic.xpm doombig.xpm doomface.xpm editres.xpm eps.xpm exit.xpm explorer.xpm find1.xpm flow_chart.xpm folder2.xpm folders.xpm fonts.xpm fruit.xpm fv.xpm fvwm.xpm fvwm2.xpm fvwm3.xpm fvwm95_big.xpm globe.xpm gnu-animal.xpm graphs.xpm gv.xpm help.xpm index.xpm info.xpm jewelbig.xpm keyboard.xpm label1.xpm label2.xpm label3.xpm lemacs.xpm mag_glass.xpm magnify.xpm mail.xpm mail1.xpm mail2.xpm map.xpm math4.xpm netscape_3d.xpm network.xpm new.xpm news2.xpm next.xpm notepad.xpm nscape.xpm onyx1616.xpm onyx3232.xpm owl.xpm page.xpm page2.xpm palette2.xpm pointer.xpm prev.xpm programs.xpm ps.xpm quake.xpm question.xpm rbomb.xpm rcalc.xpm recycler.xpm rterm.xpm run.xpm scilab-color.xpm scilab.xpm settings.xpm shutdown.xpm small.Paint2.xpm small.Shell2.xpm small.exit.xpm small.lock.xpm small.man.next.xpm small.note.next.xpm small.tools2_3d.xpm smallx.xpm snail.xpm snoopy.xpm sysedi.xpm tas.xpm term.xpm textedit.xpm tiff2.xpm toolbox.xpm toolbox_3d.xpm uk.xpm unknown1.xpm wierd_page3.xpm wilber.xpm window.xpm word_processor.xpm world.xpm write.next.xpm wterm.xpm x.xpm x_server.xpm xblast.xpm xboingbig.xpm xcalc.xpm xedit.xpm xedit_w.xpm xemacs-icon.xpm xemacs.xpm xgl.xpm xgrab.xpm xhelp.backward.xpm xhelp.exclaim.xpm xhelp.forward.xpm xhelp.index.xpm xhelp.search.xpm xlab.xpm xlock.xpm xmag.xpm xmail.xpm xman.xpm xmosaic.xpm xmosaic_w.xpm xnomail.xpm xoldmail.xpm xpaint.xpm xpovicon.xpm xscrabble.xpm xterm-axp.xpm xterm-blank.xpm xterm-dec.xpm xterm-sgi.xpm xterm-sol.xpm xterm-sun.xpm xterm.xpm xterm2.xpm xv.color.xpm xv.xpm xview.xpm ; do \
(install -c -m 644 $i $PREFIX/lib/X11/pixmaps) \
done
cd ..
cd mini-icons
echo Installing mini-icons in $PREFIX/lib/X11/mini-icons  
mkdir -p $PREFIX/lib/X11/mini-icons
for i in apm-alert.xpm apm-empty.xpm apm-full.xpm apm-half.xpm apm-loading.xpm apm-online.xpm apm-unknown.xpm bckgnd1.xpm bckgnd3.xpm documents.xpm find1.xpm folder.xpm freebsd-menu.xpm fvwm-menu.xpm help.xpm linux-menu.xpm menu.xpm mini-arch.xpm mini-asmail.xpm mini-audiovol.xpm mini-ball.xpm mini-bball.xpm mini-bomb.xpm mini-book1.xpm mini-book2.xpm mini-books.xpm mini-briefcase.xpm mini-bug1.xpm mini-bug2.xpm mini-bx2.xpm mini-calc.xpm mini-camera.xpm mini-cat.xpm mini-cave.xpm mini-cd.xpm mini-cdlabel.xpm mini-chinese.xpm mini-clipboard.xpm mini-clock.xpm mini-colors.xpm mini-connect.xpm mini-crosbone.xpm mini-cross.xpm mini-desktop.xpm mini-dfolder.xpm mini-diff.xpm mini-diskette.xpm mini-display.xpm mini-doc.xpm mini-doc1.xpm mini-dog.xpm mini-edit.xpm mini-espada.xpm mini-exclam.xpm mini-exp.xpm mini-eye.xpm mini-eyes.xpm mini-fax.xpm mini-fdisk.xpm mini-filemgr.xpm mini-folder.xpm mini-font.xpm mini-fractal.xpm mini-frame.xpm mini-ftp.xpm mini-gball.xpm mini-go.xpm mini-gopher.xpm mini-graph.xpm mini-gv.xpm mini-hammer.xpm mini-happy.xpm mini-hdisk.xpm mini-heart.xpm mini-hex.xpm mini-hextris.xpm mini-iconify.xpm mini-icons.xpm mini-keyboard.xpm mini-lightbolt-full.xpm mini-lock.xpm mini-lower.xpm mini-mail.xpm mini-manual.xpm mini-max1.xpm mini-maxtall.xpm mini-maxwide.xpm mini-maze.xpm mini-modules.xpm mini-monitor.xpm mini-mouse.xpm mini-move.xpm mini-move1.xpm mini-mwm.xpm mini-newmail.xpm mini-news.xpm mini-nscape.xpm mini-ofolder.xpm mini-olwm.xpm mini-pager.xpm mini-paint.xpm mini-palette.xpm mini-pdf.xpm mini-pencil.xpm mini-penguin.xpm mini-perf.xpm mini-question.xpm mini-raise.xpm mini-ray.xpm mini-rball.xpm mini-redhat.xpm mini-resize.xpm mini-roach.xpm mini-run.xpm mini-sh.xpm mini-sh1.xpm mini-slon.xpm mini-sound.xpm mini-speaker-off.xpm mini-speaker.xpm mini-start.xpm mini-stop.xpm mini-telnet.xpm mini-term.xpm mini-tetris.xpm mini-trebol.xpm mini-turn.xpm mini-twm.xpm mini-unreadmail.xpm mini-wilber.xpm mini-window.xpm mini-windows.xpm mini-x.xpm mini-x2.xpm mini-xfig.xpm mini-xjewel.xpm mini-xkeycaps.xpm mini-xlander.xpm mini-xmahjongg.xpm mini-xsnow.xpm mini-xv.xpm mini-zoom.xpm mini.FileManager.xpm mini.audiovol.xpm mini.blah.xpm mini.checkmark.xpm mini.cut.xpm mini.destroy.xpm mini.excl.xpm mini.exit.xpm mini.fvwm.xpm mini.install_3d.xpm mini.key_3d.xpm mini.letter.xpm mini.lower.xpm mini.move.xpm mini.netscape.xpm mini.rainbow.xpm mini.raise.xpm mini.resize.xpm mini.stick.xpm mini.stick2.xpm mini.text.xpm mini.win95.xpm mini.window3d.xpm mini.xarchie.xpm mini.xboing.xpm mini.xlock.xpm mini.xpm mini.xterm.xpm mini.zircon.xpm onyx1616.xpm onyx3232.xpm programs.xpm run.xpm run1616.xpm settings.xpm shutdown.xpm solaris95.xpm sun-menu.xpm utilities-menu.xpm ; do \
(install -c -m 644 $i $PREFIX/lib/X11/mini-icons) \
done
cd ..
cd docs
echo Installing documentation in $PREFIX/lib/X11/fvwm95/html  
mkdir -p $PREFIX/lib/X11/fvwm95/html
install -c -m 644 index.html $PREFIX/lib/X11/fvwm95
install -c -m 644 GPL.html $PREFIX/lib/X11/fvwm95
install -c -m 644 html/*.html $PREFIX/lib/X11/fvwm95/html  
cd ..

# Enlaces simbolicos en /usr/local
if [[ $PREFIX != "/usr/local" ]]; then
  echo "No es en /usr/local"
  if [[ ! -e /usr/local/lib/X11 ]]; then
    mkdir -vp /usr/local/lib/X11
  fi
  ln -v -s $PREFIX/lib/X11/fvwm95 /usr/local/lib/X11/
  ln -v -s $PREFIX/lib/X11/pixmaps /usr/local/lib/X11/
  ln -v -s $PREFIX/lib/X11/mini-icons /usr/local/lib/X11/
  ln -v -s $PREFIX/bin/* /usr/local/bin/
fi
