#!/bin/sh

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

# remove softlink to admin script 
sudo rm -f /usr/sbin/rstudio-server

# remove temporary streams
sudo rm -rf /tmp/rstudio-rsession
sudo 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
   sudo systemctl stop rstudio-server.service 2>/dev/null
   sudo systemctl disable rstudio-server.service 2>/dev/null
   sudo rm -rf /etc/systemd/system/rstudio-server.service
   sudo systemctl daemon-reload
fi

# clear error termination state
set -e
