#!/bin/ksh

#
# This file is a part of the NsCDE - Not so Common Desktop Environment
# Author: Hegel3DReloaded
# Licence: GPLv3
#

VERBOSE=0

if [ -z $HOME ]; then
   echo "Error: HOME is not set cannot continue."
   exit 3
fi

if [ -z $NSCDE_ROOT ]; then
   echo "Error: NSCDE_ROOT is not set cannot continue."
   exit 4
fi

if [ ! -e "$NSCDE_ROOT" ]; then
   echo "Error: NSCDE_ROOT does not exist. Cannot continue."
   exit 5
fi

if [ -z $FVWM_USERDIR ]; then
   echo "Error: FVWM_USERDIR is not set cannot continue."
   exit 6
fi

function setup_nscde
{
   if (($VERBOSE == 1)); then
      echo ""
      echo "#####################################################################"
      echo "#"
      echo "# NsCDE First Run Setup"
      echo "#"
      echo "#####################################################################"
      echo ""
   fi

   if [ -z $NSCDE_PALETTE ]; then
      NSCDE_PALETTE="Broica"
   fi

   if [ -z $NSCDE_PALETTE_NCOLORS ]; then
      NSCDE_PALETTE_NCOLORS=8
   fi

   if (($INTERACTIVE == 1)); then
      echo "Enter RETURN to run this script"
      read RET
   fi

   if [ ! -e "${FVWM_USERDIR}/NsCDE-Colorset.conf" ]; then
      if (($VERBOSE == 1)); then
         echo "Generating NsCDE fvwm Colorset ..."
      fi
      $NSCDE_ROOT/libexec/nscde_palette_colorgen.py -p $NSCDE_ROOT/share/palettes/${NSCDE_PALETTE}.dp \
       -n $NSCDE_PALETTE_NCOLORS -f > "$FVWM_USERDIR/NsCDE-Colorset.conf"
   else
      if (($VERBOSE == 1)); then
         echo "${FVWM_USERDIR}/NsCDE-Colorset.conf already exists."
      fi
   fi

   if (($VERBOSE == 1)); then
      echo "Setting up X resources in $HOME/.NsCDE - pieces that do not exist:"
      echo "(Xdefaults, Xdefaults.local, Xdefaults.fontdefs, app-defaults) ..."
   fi

   # Xdefaults includes
   if [ ! -e "${FVWM_USERDIR}/Xdefaults" ]; then
      $NSCDE_ROOT/libexec/nscde_palette_colorgen.py -p $NSCDE_ROOT/share/palettes/${NSCDE_PALETTE}.dp \
       -n $NSCDE_PALETTE_NCOLORS -i $NSCDE_ROOT/share/templates/Xdefaults -c > "$FVWM_USERDIR/Xdefaults"
   else
      if (($VERBOSE == 1)); then
         echo "${FVWM_USERDIR}/Xdefaults already exists."
      fi
   fi

   if [ ! -e "${FVWM_USERDIR}/Xdefaults.local" ]; then
      touch "${FVWM_USERDIR}/Xdefaults.local"
   else
      if (($VERBOSE == 1)); then
         echo "${FVWM_USERDIR}/Xdefaults.local already exists."
      fi
   fi

   if [ ! -e "${FVWM_USERDIR}/Xdefaults.fontdefs" ]; then
      cp "${NSCDE_ROOT}/share/templates/Xdefaults.fontdefs" "${FVWM_USERDIR}/Xdefaults.fontdefs"
   else
      if (($VERBOSE == 1)); then
         echo "${FVWM_USERDIR}/Xdefaults.fontdefs already exists."
      fi
   fi

   if [ ! -e "${FVWM_USERDIR}/Xdefaults.mouse" ]; then
      cp "${NSCDE_ROOT}/share/templates/Xdefaults.mouse" "${FVWM_USERDIR}/Xdefaults.mouse"
   else
      if (($VERBOSE == 1)); then
         echo "${FVWM_USERDIR}/Xdefaults.mouse already exists."
      fi
   fi

   # Xdefaults pieces dir (XAPPLRESDIR)
   if [ ! -e "${FVWM_USERDIR}/app-defaults" ]; then
      mkdir -p "${FVWM_USERDIR}/app-defaults"
      for appres in $NSCDE_ROOT/share/templates/app-defaults/*.tmpl
      do
         appres="${appres%.tmpl}"
         $NSCDE_ROOT/libexec/nscde_palette_colorgen.py -p $NSCDE_ROOT/share/palettes/${NSCDE_PALETTE}.dp \
          -n $NSCDE_PALETTE_NCOLORS -i ${appres}.tmpl -c > $FVWM_USERDIR/app-defaults/${appres##*/}
      done
   else
      if (($VERBOSE == 1)); then
         echo "${FVWM_USERDIR}/app-defaults already exists."
      fi
   fi

   # Xsettingsd daemon configuration
   if [ ! -e "${FVWM_USERDIR}/Xsettingsd.conf" ]; then
      cp "${NSCDE_ROOT}/share/templates/Xsettingsd.conf" "${FVWM_USERDIR}/Xsettingsd.conf"
   else
      if (($VERBOSE == 1)); then
         echo "${FVWM_USERDIR}/Xsettingsd.conf already exists."
      fi
   fi

   # Bare background before backer setup
   if [ ! -e "${FVWM_USERDIR}/.BGdefault" ]; then
      if (($VERBOSE == 1)); then
         echo "Writing default background pixel ${FVWM_USERDIR}/.BGdefault ..."
      fi
      cp ${NSCDE_ROOT}/share/templates/BGdefault "${FVWM_USERDIR}/.BGdefault"
   else
      if (($VERBOSE == 1)); then
         echo "${FVWM_USERDIR}/.BGdefault already exists."
      fi
   fi

   # Initial NsCDE.conf after InitFunction is run
   if [ ! -e "${FVWM_USERDIR}/NsCDE.conf" ]; then
      if (($VERBOSE == 1)); then
         echo "Initializing default ${FVWM_USERDIR}/NsCDE.conf ..."
      fi
      cp ${NSCDE_ROOT}/config/NsCDE.conf ${FVWM_USERDIR}/NsCDE.conf
   else
      if (($VERBOSE == 1)); then
         echo "${FVWM_USERDIR}/NsCDE.conf already exists."
      fi
   fi

   # Initial NsCDE-Init.conf for user session customizations
   if [ ! -e "${FVWM_USERDIR}/NsCDE-Init.conf" ]; then
      if (($VERBOSE == 1)); then
         echo "Initializing default ${FVWM_USERDIR}/NsCDE-Init.conf ..."
      fi
      cp ${NSCDE_ROOT}/config/NsCDE-Init.conf ${FVWM_USERDIR}/NsCDE-Init.conf
   else
      if (($VERBOSE == 1)); then
         echo "${FVWM_USERDIR}/NsCDE-Init.conf already exists."
      fi
   fi

   # Initial NsCDE-Functions.local example for user function customizations
   if [ ! -e "${FVWM_USERDIR}/NsCDE-Functions.local" ]; then
      if (($VERBOSE == 1)); then
         echo "Initializing default ${FVWM_USERDIR}/NsCDE-Functions.local ..."
      fi
      cp ${NSCDE_ROOT}/share/templates/NsCDE-Functions.local ${FVWM_USERDIR}/NsCDE-Fucntions.local
   else
      if (($VERBOSE == 1)); then
         echo "${FVWM_USERDIR}/NsCDE-Functions.local already exists."
      fi
   fi

   # GeometryDB ini
   if [ ! -e "${FVWM_USERDIR}/GeoDB.ini" ]; then
      if (($VERBOSE == 1)); then
         echo "Initializing default ${FVWM_USERDIR}/GeoDB.ini ..."
      fi
      cp ${NSCDE_ROOT}/share/templates/GeoDB.ini ${FVWM_USERDIR}/GeoDB.ini
   else
      if (($VERBOSE == 1)); then
         echo "${FVWM_USERDIR}/GeoDB.ini already exists."
      fi
   fi

   # Misc paths
   if (($VERBOSE == 1)); then
      echo "Making additional subdirectories in ${FVWM_USERDIR} ..."
   fi
   mkdir -p ${FVWM_USERDIR}/{palettes,templates,fontsets,backdrops,photos}

   # Disable "fancy" curors
   if [ ! -e "$HOME/.icons/default/index.theme" ]; then
      if (($VERBOSE == 1)); then
         echo "Writing $HOME/.icons/default/index.theme ..."
      fi
      mkdir -p "$HOME/.icons/default"
      echo -ne '[Icon Theme]\nInherits=dmz-aa\n' > "$HOME/.icons/default/index.theme"
   else
      if (($VERBOSE == 1)); then
         echo "${HOME}/.icons/default/index.theme already exists. Setting default cursor theme."
         $NSCDE_ROOT/bin/confset.py -t ini -c settingz.ini -s "Icon Theme" -k Inherits -v dmz-aa
      fi
   fi

   # Make sure $HOME/.gtkrc-2.0 and $HOME/.config/gtk-3.0/settings.ini exists,
   # if not, set it up with defaults and generate theme with starting or environment palette.

   # Gtk2
   if [ ! -e "$HOME/.gtkrc-2.0" ]; then
      if (($VERBOSE == 1)); then
         echo "Writing $HOME/.gtkrc-2.0 ..."
      fi
      echo -ne 'gtk-key-theme-name = "Emacs"\ngtk-theme-name = "NsCDE"\ngtk-font-name =  "DejaVu Serif Book 10"\n' > "$HOME/.gtkrc-2.0"
      echo -ne 'gtk-icon-theme-name = "NsCDE"\ngtk-button-images = 0\ngtk-menu-images = 0\ngtk-cursor-blink = 0\n' >> "$HOME/.gtkrc-2.0"
   else
      if (($VERBOSE == 1)); then
         echo "${HOME}/.gtkrc-2.0 already exists. Setting NsCDE theme options."
         $NSCDE_ROOT/bin/confset.py -t properties -c "$HOME/.gtkrc-2.0" -k gtk-key-theme-name -v '"Emacs"'
         $NSCDE_ROOT/bin/confset.py -t properties -c "$HOME/.gtkrc-2.0" -k gtk-theme-name -v '"NsCDE"'
         $NSCDE_ROOT/bin/confset.py -t properties -c "$HOME/.gtkrc-2.0" -k gtk-font-name -v '"DejaVu Serif Book 10"'
         $NSCDE_ROOT/bin/confset.py -t properties -c "$HOME/.gtkrc-2.0" -k gtk-icon-theme-name -v '"NsCDE"'
         $NSCDE_ROOT/bin/confset.py -t properties -c "$HOME/.gtkrc-2.0" -k gtk-button-images -v 0
         $NSCDE_ROOT/bin/confset.py -t properties -c "$HOME/.gtkrc-2.0" -k gtk-menu-images -v 0
         $NSCDE_ROOT/bin/confset.py -t properties -c "$HOME/.gtkrc-2.0" -k gtk-cursor-blink -v 0
      fi
   fi

   # Gtk3
   if [ ! -e "$HOME/.config/gtk-3.0/settings.ini" ]; then
      if (($VERBOSE == 1)); then
         echo "Writing $HOME/.config/gtk-3.0/settings.ini ..."
      fi
      mkdir -p "$HOME/.config/gtk-3.0"
      echo -ne "[Settings]\ngtk-theme-name = NsCDE\ngtk-cursor-theme-name = dmz-aa\ngtk-button-images = 0\n" > "$HOME/.config/gtk-3.0/settings.ini"
      echo -ne "gtk-menu-images = 0\ngtk-application-prefer-dark-theme = 1\ngtk-font-name = DejaVu Serif Book 10\n" >> "$HOME/.config/gtk-3.0/settings.ini"
      echo -ne "gtk-icon-theme-name = NsCDE\ngtk-cursor-blink = 0\n" >> "$HOME/.config/gtk-3.0/settings.ini"
   else
      if (($VERBOSE == 1)); then
         echo "${HOME}/.config/gtk-3.0/settings.ini already exists. Setting NsCDE theme options."
         $NSCDE_ROOT/bin/confset.py -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-theme-name -v NsCDE
         $NSCDE_ROOT/bin/confset.py -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-cursor-theme-name -v dmz-aa
         $NSCDE_ROOT/bin/confset.py -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-button-images -v 0
         $NSCDE_ROOT/bin/confset.py -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-menu-images -v 0
         $NSCDE_ROOT/bin/confset.py -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-application-prefer-dark-theme -v 1
         $NSCDE_ROOT/bin/confset.py -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-font-name -v "DejaVu Serif Book 10"
         $NSCDE_ROOT/bin/confset.py -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-icon-theme-name -v NsCDE
         $NSCDE_ROOT/bin/confset.py -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-cursor-blink -v 0
      fi
   fi

   # Gtk2 and Gtk3 themes
   if [ ! -e "$HOME/.themes/NsCDE" ]; then
      if (($VERBOSE == 1)); then
         echo "Generating default theme for Gtk2/Gtk3 in $HOME/.themes/NsCDE ..."
      fi
      mkdir -p "$HOME/.themes"
      $NSCDE_ROOT/libexec/themegen.py $NSCDE_ROOT/share/palettes/${NSCDE_PALETTE}.dp $NSCDE_PALETTE_NCOLORS gtk2 gtk3
   else
      if (($VERBOSE == 1)); then
         echo "${HOME}/.themes/NsCDE already exists."
      fi
   fi

   # Qt4 and Qt5
   if [ ! -r "$HOME/.config/Trolltech.conf" ]; then
      if (($VERBOSE == 1)); then
         echo "Integrating Qt4 with generated Gtk2 theme ..."
      fi
      mkdir -p "$HOME/.config"
      echo -ne '[Qt]\nstyle=GTK+\n' > "$HOME/.config/Trolltech.conf"
   else
      if (($VERBOSE == 1)); then
         echo "${HOME}/.config/Trolltech.conf already exists. Setting NsCDE style."
         $NSCDE_ROOT/bin/confset.py -t ini -c "$HOME/.config/Trolltech.conf" -s Qt -k style -v GTK+
      fi
   fi

   if [ ! -e "$HOME/.config/qt5ct/qt5ct.conf" ]; then
      if (($VERBOSE == 1)); then
         echo "Integrating Qt5 with generated Gtk2 theme ..."
      fi
      mkdir -p "$HOME/.config/qt5ct"
      echo -ne '[Appearance]\nstandard_dialogs=gtk2\nstyle=gtk2\n' > "$HOME/.config/qt5ct/qt5ct.conf"
   else
      if (($VERBOSE == 1)); then
         echo "${HOME}/.config/qt5ct/qt5ct.conf already exists. Setting NsCDE style."
         $NSCDE_ROOT/bin/confset.py -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Appearance -k icon_theme -v NsCDE
         $NSCDE_ROOT/bin/confset.py -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Appearance -k standard_dialogs -v gtk2
         $NSCDE_ROOT/bin/confset.py -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Appearance -k style -v gtk2
      fi
   fi

   # Stalonetray - if it doesn't have configuration yet ready.
   if [ ! -e "${FVWM_USERDIR}/Stalonetray.conf" ]; then
      if (($VERBOSE == 1)); then
         echo "Setting default ${FVWM_USERDIR}/Stalonetray.conf ..."
      fi
      cp ${NSCDE_ROOT}/share/templates/Stalonetray.conf "${FVWM_USERDIR}/Stalonetray.conf"
   else
      if (($VERBOSE == 1)); then
         echo "${FVWM_USERDIR}/Stalonetray.conf already exists."
      fi
   fi

   # Color Manager local hooks
   if [ ! -e "${FVWM_USERDIR}/libexec/colormgr.local" ]; then
      if (($VERBOSE == 1)); then
         echo "Setting default ${FVWM_USERDIR}/libexec/colormgr.local ..."
      fi
      mkdir -p "${FVWM_USERDIR}/libexec"
      cp ${NSCDE_ROOT}/share/templates/colormgr.local "${FVWM_USERDIR}/libexec/colormgr.local"
      chmod +x "${FVWM_USERDIR}/libexec/colormgr.local"
   else
      if (($VERBOSE == 1)); then
         echo "${FVWM_USERDIR}/libexec/colormgr.local already exists."
      fi
   fi

   if (($INTERACTIVE == 1)); then
      echo -ne "Do you want to enable NsCDE-specific visual pager preview on page/desk change? (y|n)[y] \c"
      read ans
      if [ "x$ans" == "x" ]; then
         ans="y"
      fi
      if [ "x$ans" == "xy" ]; then
         echo "Enabling: pageshowrootpager --> 1"
         $NSCDE_ROOT/bin/ised -c 's/InfoStoreAdd pageshowrootpager 0/InfoStoreAdd pageshowrootpager 1/g' -f "$FVWM_USERDIR/NsCDE.conf"
      elif [ "x$ans" == "xn" ]; then
         echo "Not enabling: pageshowrootpager --> 0"
      else
         echo "Answer not understood."
         echo "Not enabling: pageshowrootpager --> 0"
      fi

      echo -ne "Do you want to enable X Screen Saver? (y|n)[y] \c"
      read ans
      if [ "x$ans" == "x" ]; then
         ans="y"
      fi
      if [ "x$ans" == "xy" ]; then
         echo "Enabled by default: nscde_use_xscreensaver --> 1"
      elif [ "x$ans" == "xn" ]; then
         echo "Disabling: nscde_use_xscreensaver --> 0"
         $NSCDE_ROOT/bin/ised -c 's/InfoStoreAdd nscde_use_xscreensaver 1/InfoStoreAdd nscde_use_xscreensaver 0/g' -f "$FVWM_USERDIR/NsCDE.conf"
      else
         echo "Answer not understood."
         echo "Enabled by default: nscde_use_xscreensaver --> 1"
      fi

      echo -ne "Do you want to enable Stalonetray Tray? (y|n)[y] \c"
      read ans
      if [ "x$ans" == "x" ]; then
         ans="y"
      fi
      if [ "x$ans" == "xy" ]; then
         echo "Enabled by default: nscde_use_stalonetray --> 1"
      elif [ "x$ans" == "xn" ]; then
         echo "Disabling: nscde_use_stalonetray --> 0"
         $NSCDE_ROOT/bin/ised -c 's/InfoStoreAdd nscde_use_stalonetray 1/InfoStoreAdd nscde_use_stalonetray 0/g' -f "$FVWM_USERDIR/NsCDE.conf"
      else
         echo "Answer not understood."
         echo "Enabled by default: nscde_use_stalonetray --> 1"
      fi

      whence -q xsettingsd
      if (($? == 0)); then
         echo -ne "Do you want to enable color scheme integration with XSETTINGS daemon xsettingsd? (y|n)[y] \c"
         read ans
         if [ "x$ans" == "x" ]; then
            ans="y"
         fi
         if [ "x$ans" == "xy" ]; then
            echo "Enabling: nscde_use_xsettingsd --> 1"
            $NSCDE_ROOT/bin/ised -c 's/InfoStoreAdd nscde_use_xsettingsd 0/InfoStoreAdd nscde_use_xsettingsd 1/g' -f "$FVWM_USERDIR/NsCDE.conf"
         elif [ "x$ans" == "xn" ]; then
            echo "Not enabling: nscde_use_xsettingsd --> 0"
         else
            echo "Answer not understood."
            echo "Not enabling: nscde_use_xsettingsd --> 0"
         fi
      fi

      echo -ne "Do you want to remember last page on workspace when changing back to it? (y|n)[y] \c"
      read ans
      if [ "x$ans" == "x" ]; then
         ans="y"
      fi
      if [ "x$ans" == "xy" ]; then
         echo "Enabling: desklastpage --> 1"
         $NSCDE_ROOT/bin/ised -c 's/InfoStoreAdd desklastpage 0/InfoStoreAdd desklastpage 1/g' -f "$FVWM_USERDIR/NsCDE.conf"
      elif [ "x$ans" == "xn" ]; then
         echo "Not enabling: desklastpage --> 0"
         $NSCDE_ROOT/bin/ised -c 's/InfoStoreAdd desklastpage 1/InfoStoreAdd desklastpage 0/g' -f "$FVWM_USERDIR/NsCDE.conf"
      else
         echo "Answer not understood."
         echo "Not enabling: desklastpage --> 0"
         $NSCDE_ROOT/bin/ised -c 's/InfoStoreAdd desklastpage 1/InfoStoreAdd desklastpage 0/g' -f "$FVWM_USERDIR/NsCDE.conf"
      fi

      for filemgr in pcmanfm krusader caja nemo thunar dolphin nautilus
      do
         whence -q $filemgr
         if (($? == 0)); then
            fmsugestion=$filemgr
            break
         fi
      done

      echo -ne "Your favorite X File Manager (command)? [${fmsugestion}] \c"
      read ans
      if [ "x$ans" != "x" ]; then
         echo "Setting X File Manager: filemgr --> ${ans}"
         $NSCDE_ROOT/bin/ised -c "s/InfoStoreAdd filemgr true/InfoStoreAdd filemgr ${ans}/g" -f "$FVWM_USERDIR/NsCDE.conf"
      elif [ "x${fmsugestion}" != "x" ]; then
         echo "Setting Proposed X File Manager: filemgr --> ${fmsugestion}"
         $NSCDE_ROOT/bin/ised -c "s/InfoStoreAdd filemgr true/InfoStoreAdd filemgr ${fmsugestion}/g" -f "$FVWM_USERDIR/NsCDE.conf"
      else
         echo "Skipping File Manager selection. You can set it in $FVWM_USERDIR/NsCDE.conf later."
      fi

      for xeditor in gvim emacs xemacs nedit
      do
         whence -q $xeditor
         if (($? == 0)); then
            xedit_suggest="$xeditor"
            break
         fi
      done

      echo -ne "Your favorite X Text Editor (command)? [$xedit_suggest] \c"
      read ans
      if [ "x$ans" != "x" ]; then
         echo "Setting X Text Editor: xeditor --> ${ans}"
         if [ "x$ans" != "gvim" ]; then
            $NSCDE_ROOT/bin/ised -c "s/InfoStoreAdd xeditor gvim/InfoStoreAdd xeditor ${ans}/g" -f "$FVWM_USERDIR/NsCDE.conf"
         fi
      elif [ "x${xedit_suggest}" != "x" ]; then
         echo "Setting Proposed X Text Editor: xeditor --> ${xedit_suggest}"
         if [ "x$ans" != "gvim" ]; then
            $NSCDE_ROOT/bin/ised -c "s/InfoStoreAdd filemgr true/InfoStoreAdd xeditor ${xedit_suggest}/g" -f "$FVWM_USERDIR/NsCDE.conf"
         fi
      else
         echo "Skipping X Editor selection. You can set it in $FVWM_USERDIR/NsCDE.conf later."
      fi
   fi

   if (($VERBOSE == 1)); then
      sleep 1
      echo '... done!'
      echo ""
      echo "Please select a color palette (default: Broica) and GUI widgets integrations"
      echo "that you want to apply and confirm with OK in Color Style Manager"
      sleep 2
      echo ""
      FvwmCommand 'Module FvwmScript ColorMgr $[desk.n] $[NSCDE_PALETTE_NCOLORS]'
      echo "Logout and login again for the full changes to take effect."
      echo ""
      echo "You can set \$[infostore.terminal] variable to your favorite"
      echo "terminal program in \$HOME/.NsCDE/NsCDE.conf or leave autodiscovery."
      echo ""
      echo "Hint: See $NSCDE_ROOT/share/doc/examples for Gkrellm, X session and"
      echo "other integration options you may want to apply."
      sleep 1
      echo ""
   fi

   if (($INTERACTIVE == 1)); then
      echo "Press RETURN to exit setup and use Color Style Manager now."
      read RET
      FvwmCommand 'EdgeThickness 1'
      FvwmCommand 'All ("ColorMgr", CirculateHit) AnimatedMove 50-50w 50-50w ewmhiwa'
      exit 0
   fi
}

if [ ! -d "$FVWM_USERDIR" ]; then
   INTERACTIVE=0
   VERBOSE=1
   setup_nscde > $HOME/NsCDE-Setup.log
fi

while getopts fivh Option
do
   case $Option in
   f)
      unset IVF
      setup_nscde
   ;;  
   i)
      unset IVF
      INTERACTIVE=1
   ;;
   v)
      unset IVF
      VERBOSE=1
   ;;
   h)
      echo "Usage: ${0##*/} [ -f ] [ -i ] [ -v ] [ -h ]"
   ;;
   esac
done

if [ -n $IVF ]; then
   if [[ "$IVF" == "1" ]]; then
      VERBOSE=1
      INTERACTIVE=1
      setup_nscde
   fi
fi

