# -- perl --

$Action = @ARGV[0];
$Prefix = @ARGV[1];

if ($Action eq "add")
{
   if (index($Prefix,"/usr/local") eq -1)
   {
      $HOMEDIR = $ENV{"HOME"};
      print "--> Installing files in $HOMEDIR\n";

      `mv -f $HOMEDIR/.toprc $HOMEDIR/.toprc.glinaccess`;
      `mv -f $HOMEDIR/.fvwm2rc $HOMEDIR/.fvwm2rc.glinaccess`;
      `mv -f $HOMEDIR/.fvwmrc $HOMEDIR/.fvwmrc.glinaccess`;
      `mv -f $HOMEDIR/.twmrc $HOMEDIR/.twmrc.glinaccess`;
      `mv -f $HOMEDIR/.xinitrc $HOMEDIR/.xinitrc.glinaccess`;
      `mv -f .toprc $HOMEDIR/.toprc`; 
      `mv -f .fvwm2rc $HOMEDIR/.fvwm2rc`; 
      `mv -f .fvwmrc $HOMEDIR/.fvwmrc`; 
      `mv -f .twmrc $HOMEDIR/.twmrc`; 
      `mv -f .xinitrc $HOMEDIR/.xinitrc`;
      `mv -f .glinaccess.sourceme $HOMEDIR/.glinaccess.sourceme`;
      `rm -f x.bashrc`;
      `echo "source $HOMEDIR/.glinaccess.sourceme" > x.bashrc`;
      `cat x.bashrc >> $HOMEDIR/.bashrc`;
      `rm -f x.bashrc`;
      `rm -f x.cshrc`;
      `echo "source $HOMEDIR/.glinaccess.sourceme" > x.cshrc`;
      `cat x.cshrc >>  $HOMEDIR/.cshrc`;
      `rm -f x.cshrc`;
   }
   else
   {
      print "--> Installing files in /etc/skel\n";

      `mv -f .toprc /etc/skel/.toprc`;
      `mv -f .fvwm2rc /etc/skel/.fvwm2rc`;
      `mv -f .fvwmrc /etc/skel/.fvwmrc`;
      `mv -f .twmrc /etc/skel/.twmrc`;
      `mv -f .xinitrc /etc/skel/.xinitrc`;
      `mv -f .glinaccess.sourceme /etc/skel/.glinaccess.sourceme`;
      `rm -f x.bashrc`;
      `echo "source /etc/skel/.glinaccess.sourceme" > x.bashrc`;
      `cat x.bashrc >> /etc/skel/.bashrc`;
      `rm -f x.bashrc`;
      `rm -f x.cshrc`;
      `echo "source /etc/skel/.glinaccess.sourceme" > x.cshrc`;
      `cat x.cshrc >>  /etc/skel/.cshrc`;
      `rm -f x.cshrc`;
   }
}
else
{
   if (index($Prefix,"/usr/local") eq -1)
   {
      $HOMEDIR = $ENV{"HOME"};
      print "--> Uninstalling files in $HOMEDIR\n";

      `rm -R -f $HOMEDIR/.toprc $HOMEDIR/.fvwm2rc $HOMEDIR/.fvwmrc $HOMEDIR/.twmrc $HOMEDIR/.xinitrc`;
      `rm -f $HOMEDIR/.glinaccess.sourceme`;
      `mv -f $HOMEDIR/.toprc.glinaccess $HOMEDIR/.toprc`;
      `mv -f $HOMEDIR/.fvwm2rc.glinaccess $HOMEDIR/.fvwm2rc`;
      `mv -f $HOMEDIR/.fvwmrc.glinaccess $HOMEDIR/.fvwmrc`;
      `mv -f $HOMEDIR/.twmrc.glinaccess $HOMEDIR/.twmrc`;
      `mv -f $HOMEDIR/.xinitrc.glinaccess $HOMEDIR/.xinitrc`;
      `sed -e '/.glinaccess.sourceme/d' $HOMEDIR/.bashrc > $HOMEDIR/bashrc`;
      `mv $HOMEDIR/bashrc $HOMEDIR/.bashrc`;
      `sed -e '/.glinaccess.sourceme/d' $HOMEDIR/.cshrc > $HOMEDIR/cshrc`;
      `mv $HOMEDIR/cshrc $HOMEDIR/.cshrc`;
   }
   else
   {
      print "--> Uninstalling files in /etc/skel\n";
      
      `rm -f /etc/skel/.toprc`;
      `rm -f /etc/skel/.fvwm2rc`;
      `rm -f /etc/skel/.fvwmrc`;
      `rm -f /etc/skel/.twmrc`;
      `rm -f /etc/skel/.xinitrc`;
      `rm -f /etc/skel/.glinaccess.sourceme`;
      `sed -e '/.glinaccess.sourceme/d' /etc/skel/.bashrc > /etc/skel/bashrc`;
      `mv /etc/skel/bashrc /etc/skel/.bashrc`;
      `sed -e '/.glinaccess.sourceme/d' /etc/skel/.cshrc > /etc/skel/cshrc`;
      `mv /etc/skel/cshrc /etc/skel/.cshrc`;
   }
}

