#!/bin/sh
#
# install script
#
# SYNOPSIS
# ./jslaunch-install [install-dir]
#
# installs jslaunch into /usr/local/bin, and makes rc[2-5].d script and links.
# the install-dir is the directory where your rc[0-6].d and init.d directories
# reside. 
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
   
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
   
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

if [ ! $1 ]; then
    echo "jslaunch install script"
    echo 
    echo "Usage:"
    echo "./jslaunch-install [install-dir]"
    echo
    echo "Installs jslaunch into /usr/local/bin, and makes rc[2-5].d links"
    echo "and script for boottime. Works only if you hava a sys V init script"
    echo "system (Red Hat, Debian, ...)."
    echo "the 'install-dir' option should be the directory where your"
    echo "rc[0-6].d and init.d directories reside. On Red Hat it is /etc/rc.d."
    echo "Of course you need to have root permissions to do this"
    echo 
    echo "The jslaunch.init script is automatically set up for polling every 3"
    echo "seconds, and do a reboot ("/sbin/shutdown -r now") when button"
    echo "1 and 2 are pressed simultaneously. To change this, edit the"
    echo "jslaunch.init script."
    echo 
    echo "WARNING: this install script will install jslaunch setuid root"
    echo "While this is normally safe, if you feel bad about other users"
    echo "on your system being able to see what joystick buttons are being"
    echo "pressed, you should remove the line 'make suid-install' from this"
    echo "script and replace it with 'make install'"
    exit
fi

echo make clean
make clean

echo make all
make all

# Comment these lines to not have jslaunch & jstest setuid root
# and uncomment the 'make install' lines
echo "make suid-install"
make suid-install

# echo make install
# make install


echo cp jslaunch.init $1/init.d/jslaunch.init
cp jslaunch.init $1/init.d/jslaunch.init


echo ln -s $1/init.d/jslaunch.init $1/rc2.d/S02jslaunch
ln -s $1/init.d/jslaunch.init $1/rc2.d/S02jslaunch
echo ln -s $1/init.d/jslaunch.init $1/rc3.d/S02jslaunch
ln -s $1/init.d/jslaunch.init $1/rc3.d/S02jslaunch
echo ln -s $1/init.d/jslaunch.init $1/rc4.d/S02jslaunch
ln -s $1/init.d/jslaunch.init $1/rc4.d/S02jslaunch
echo ln -s $1/init.d/jslaunch.init $1/rc5.d/S02jslaunch
ln -s $1/init.d/jslaunch.init $1/rc5.d/S02jslaunch

echo ln -s $1/init.d/jslaunch.init $1/rc0.d/K99jslaunch
ln -s $1/init.d/jslaunch.init $1/rc0.d/K99jslaunch
echo ln -s $1/init.d/jslaunch.init $1/rc6.d/K99jslaunch
ln -s $1/init.d/jslaunch.init $1/rc6.d/K99jslaunch

echo
echo
echo "Installation done... now do: "
echo
echo "$1/init.d/jslaunch.init start"
echo
echo "Installation done... now do: "
echo
echo "jslaunchd start"
echo
echo "to start the daemon. "
echo "If you want to change the settings you can edit /etc/jslaunchd.conf"
echo "before you run it. Run jstest to determine which button numbers"
echo "correspond to which buttons."
echo "To remove the installation, do: "
echo
echo "rm /usr/local/bin/jslaunch"
echo "rm /usr/local/bin/jstest"
echo "rm /usr/local/bin/jslaunchd"
echo "rm /usr/local/man/man1/jslaunch"
echo "rm /usr/local/man/man1/jslaunchd"
echo "rm /usr/local/man/man1/jstest"
echo "rm /etc/jslaunchd.conf"
echo "rm $1/init.d/jslaunch.init"
echo "rm $1/rc?.d/*jslaunch*"