#!/bin/sh
# 26-10-2018 JvW Add mc-home-dfsee to chmod; removed dfsquery from symlinks
# 01-08-2017 JvW Split up linux and mac scripts, each their own setup as well
# 27-07-2017 JvW Add dfspalet to show 88/256 colors and dfswget to run wget in an xterm
# 24-07-2017 JvW Add dfshexedit and dfsbrwsimz scripts for dfspuppy start in xterm
# 25-06-2017 JvW Add dfseesmall and dfseelarge scripts for dfspuppy start in xterm
# 21-08-2016 JvW Use filemode 755 to allow execution by anyone (like from /opt)
# 19-08-2016 JvW Made symlink creation optional, and configurable with linkdir parameter
# 14-08-2016 JvW Added dfs startup script using sudo, make symlinks in /usr/local/bin
# 08-05-2010 JvW Set attributes to 744 (root only) on each script spcecifically
# 05-05-2005 JvW Set workable attributes for the standard distribution (7.04)
# 13-11-2004 JvW Install check by Erik P. Olsen (6.16)
# 
# Resolve installation directory, MUST be the current directory, where dfsee lives

echo

if [ "$1" = "-?" ] || [ "$1" = "-h" ]  || [ "$1" = "--help" ] ; then

  echo Usage: $0  [ symlink-directory \| "-" \| none \| "-?" \| "-h" \| "--help" ]
  echo
  echo Setup DFSee scripts to be executable, mode 755
  echo
  echo Create symbolic links in a specified symlink-directory, when that exists
  echo Default when not specified is '/usr/local/bin'. It should be in the PATH
  echo Specifying any non-existing value/directory, skips the symlink creation. 

else

  if [ -f "dfsee" ]; then

    dfs_dir="`pwd`"

    chmod 755 $dfs_dir/dfsee
    chmod 755 $dfs_dir/dfseesmall
    chmod 755 $dfs_dir/dfseelarge
    chmod 755 $dfs_dir/dfseepup32
    chmod 755 $dfs_dir/dfshexedit
    chmod 755 $dfs_dir/dfsbrwsimz
    chmod 755 $dfs_dir/mc-home-dfsee
    chmod 755 $dfs_dir/dfslwget
    chmod 755 $dfs_dir/dfspalet
    chmod 755 $dfs_dir/dfscheck
    chmod 755 $dfs_dir/dfsdisk
    chmod 755 $dfs_dir/dfsedit
    chmod 755 $dfs_dir/dfsquery
    chmod 755 $dfs_dir/dfsquick
    chmod 755 $dfs_dir/dfstart
    chmod 755 $dfs_dir/dfs

    echo Exectable mode 755 set for executable and scripts in the DFSee distrution
    echo

    if [ $# -eq 0 ]; then
        linkdir="/usr/local/bin"
    else
        linkdir="$1"
    fi

    if [ -d "$linkdir" ]; then
        echo Creating symbolic links to the dfsee scripts in "$linkdir", this needs 
        echo administrative privileges, so you may need to supply the SUDO password:
        echo
        sudo ln -s -f -v $dfs_dir/dfsedit  $linkdir/dfsedit
        sudo ln -s -f -v $dfs_dir/dfs      $linkdir/dfs
    else
        echo "$linkdir" is not an existing directory, symlinks are NOT created
    fi
    echo
    echo DFSee setup done ...
  else
    echo DFSee executable file 'dfsee' was not found in the current directory!
    echo This setup script MUST be run from the directory where dfsee was installed,
    echo which could be '~/dfsee/linux/' when the standard procedure was followed,
    echo or any other place like '/opt/dfsee/bin/' if you moved/unpacked it there.
  fi
fi
echo