1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo "You must be root to run this script."
exit 1
fi
if [ $# -gt 0 ]; then
CONF=$1
if [ $CONF == "shiny-server-rules" ]; then
echo "shiny-server-rules is not a valid configuration."
exit 1
fi
else
# No arguments passed. Use the default.
CONF="default"
fi
echo "Attempting to deploy configuration named: $CONF"
FILE="${CMAKE_INSTALL_PREFIX}/shiny-server/config/$CONF.config"
if [ ! -f $FILE ]; then
echo "ERROR: There is no configuration named: $CONF"
exit 1
fi
SSCONF="/etc/shiny-server/shiny-server.conf"
# Restart
restart_shiny () {
echo "Restarting Shiny Server..."
INIT_SYSTEM=`cat /proc/1/comm`
if test $INIT_SYSTEM = "systemd"
then
systemctl stop shiny-server.service 2>/dev/null
echo "Waiting..."
systemctl start shiny-server.service
elif test -d /etc/init/
then
initctl stop shiny-server 2>/dev/null
echo "Waiting..."
initctl start shiny-server
else
/sbin/service shiny-server stop 2>/dev/null
echo "Waiting..."
sleep 5
/sbin/service shiny-server start
fi
echo
echo "The $CONF config is all setup now. Enjoy!"
}
copy_config () {
/bin/cp -f $1 $SSCONF
echo "Copied $1 to $SSCONF."
echo "Installing sample apps..."
if [ ! -e /srv/shiny-server/index.html ]; then
ln -s ${CMAKE_INSTALL_PREFIX}/shiny-server/samples/welcome.html /srv/shiny-server/index.html
echo "Created /srv/shiny-server/index.html"
else
echo "/srv/shiny-server/index.html already exists. Not overwriting."
fi
if [ ! -e /srv/shiny-server/sample-apps ]; then
ln -s ${CMAKE_INSTALL_PREFIX}/shiny-server/samples/sample-apps /srv/shiny-server/sample-apps
echo "Created /srv/shiny-server/sample-apps/"
else
echo "/srv/shiny-server/sample-apps already exists. Not overwriting."
fi
echo "Done installing samples."
restart_shiny
}
if [ -f $SSCONF ]; then
read -p "Configuration file already exists at /etc/shiny-server/shiny-server.conf. Are you sure you want to overwrite it? [yN]" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
copy_config $FILE
else
echo "Not overwriting existing file. Exiting."
exit 1
fi
else
copy_config $FILE
fi
|