#!/bin/sh

# errors shouldn't cause script to exit
set +e 

# only remove things if this is an uninstall
if [ "$1" = 0 ]
then
   # remove softlink to admin script
   rm -f /usr/sbin/rstudio-server

   # remove temporary streams
   rm -rf /tmp/rstudio-rsession
   rm -rf /tmp/rstudio-rserver

   # stop and remove service under systemd
   INIT_SYSTEM=`cat /proc/1/comm 2>/dev/null`
   if test "$INIT_SYSTEM" = "systemd"
   then
      systemctl stop rstudio-server.service 2>/dev/null
      systemctl disable rstudio-server.service 2>/dev/null
      rm -rf /etc/systemd/system/rstudio-server.service
      systemctl daemon-reload
   fi

   # remove openssl softlinks
   rm -rf ${CMAKE_INSTALL_PREFIX}/bin/libssl.so.6
   rm -rf ${CMAKE_INSTALL_PREFIX}/bin/libcrypto.so.6
fi

# clear error termination state
set -e
