#!/bin/sh

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

sudo ln -f -s "${CMAKE_INSTALL_PREFIX}/shiny-server/bin/shiny-server" /usr/bin/shiny-server
# See if "shiny" user exists
if id -u shiny >/dev/null 2>&1;
then
   echo User "shiny" already exists
else
   echo Creating user "shiny"
   sudo useradd -r -m shiny
fi

sudo mkdir -p /var/log/shiny-server
sudo mkdir -p /srv/shiny-server

# Log dir must be writable by "shiny" user
sudo chown shiny:shiny /var/log/shiny-server

# add upstart profile or init.d script and start the server
if test -d /etc/init/
then
   sudo cp ${CMAKE_INSTALL_PREFIX}/shiny-server/config/upstart/shiny-server.conf /etc/init/
   sudo initctl reload-configuration
   sudo initctl stop shiny-server 2>/dev/null
   sudo initctl start shiny-server
else
   sudo cp ${CMAKE_INSTALL_PREFIX}/shiny-server/config/init.d/redhat/shiny-server /etc/init.d/
   sudo chmod +x /etc/init.d/shiny-server
   sudo update-rc.d shiny-server defaults
   sudo /etc/init.d/shiny-server stop  2>/dev/null
   sudo /etc/init.d/shiny-server start
fi

# clear error termination state
set -e

#!/bin/sh

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

sudo ln -f -s "${CMAKE_INSTALL_PREFIX}/shiny-server/bin/shiny-server" /usr/bin/shiny-server
# See if "shiny" user exists
if id -u shiny >/dev/null 2>&1;
then
   echo User "shiny" already exists
else
   echo Creating user "shiny"
   sudo useradd -r -m shiny
fi

sudo mkdir -p /var/log/shiny-server
sudo mkdir -p /srv/shiny-server

# Log dir must be writable by "shiny" user
sudo chown shiny:shiny /var/log/shiny-server

# add upstart profile or init.d script and start the server
if test -d /etc/init/
then
   # remove any previously existing init.d based scheme
   service shiny-server stop 2>/dev/null
   rm -f /etc/init.d/shiny-server

   sudo cp ${CMAKE_INSTALL_PREFIX}/shiny-server/config/upstart/shiny-server.conf /etc/init/
   sudo initctl reload-configuration
   sudo initctl stop shiny-server 2>/dev/null
   sudo initctl start shiny-server
else
   cp ${CMAKE_INSTALL_PREFIX}/shiny-server/config/init.d/redhat/shiny-server /etc/init.d/
   chmod +x /etc/init.d/shiny-server
   chkconfig --add shiny-server
   service shiny-server stop 2>/dev/null
   service shiny-server start
fi

# clear error termination state
set -e

Fix post-install script for RedHat
Fix post-install script for RedHat
