From 80b8d3875ed0dbbc40d296527879896fd2feab8b Mon Sep 17 00:00:00 2001 From: zamentur Date: Tue, 26 Aug 2014 00:49:46 +0200 Subject: [PATCH] Install script (support only one instance) --- README.md | 8 +++++ conf/ethercalc | 79 +++++++++++++++++++++++++++++++++++++++++++ conf/nginx.conf | 6 ++++ conf/nginx.conf-nosub | 6 ++++ manifest.json | 44 ++++++++++++++++++++++++ scripts/install | 51 ++++++++++++++++++++++++++++ scripts/remove | 13 +++++++ scripts/upgrade | 3 ++ 8 files changed, 210 insertions(+) create mode 100644 README.md create mode 100644 conf/ethercalc create mode 100644 conf/nginx.conf create mode 100644 conf/nginx.conf-nosub create mode 100644 manifest.json create mode 100644 scripts/install create mode 100644 scripts/remove create mode 100644 scripts/upgrade diff --git a/README.md b/README.md new file mode 100644 index 0000000..025d5e4 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +ethercalc_ynh +=============== + +EtherCalc for YunoHost + +LimeSurvey is an online web spreadsheet. + +https://ethercalc.net/ diff --git a/conf/ethercalc b/conf/ethercalc new file mode 100644 index 0000000..08cb33a --- /dev/null +++ b/conf/ethercalc @@ -0,0 +1,79 @@ +#!/bin/sh + +### BEGIN INIT INFO +# Provides: ethercalc +# Required-Start: $local_fs $remote_fs $network $syslog +# Required-Stop: $local_fs $remote_fs $network $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts ethercalc +# Description: starts ethercalc using start-stop-daemon +### END INIT INFO +app="ethercalc" +PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/node/bin" +LOGFILE="/var/log/$app/$app.log" +EPLITE_DIR="/usr/local/bin" +EPLITE_BIN="ethercalc" +USER="www-data" +GROUP="www-data" +DESC="EtherCalc" +NAME="$app" + +set -e + +. /lib/lsb/init-functions + +start() { + echo "Starting $DESC... " + + start-stop-daemon --start --chuid "$USER:$GROUP" --background --make-pidfile --pidfile /var/run/$NAME.pid --exec $EPLITE_DIR/$EPLITE_BIN -- $LOGFILE || true + echo "done" +} + +#We need this function to ensure the whole process tree will be killed +killtree() { + local _pid=$1 + local _sig=${2-TERM} + for _child in $(ps -o pid --no-headers --ppid ${_pid}); do + killtree ${_child} ${_sig} + done + kill -${_sig} ${_pid} +} + +stop() { + echo "Stopping $DESC... " + if test -f /var/run/$NAME.pid; then + while test -d /proc/$(cat /var/run/$NAME.pid); do + killtree $(cat /var/run/$NAME.pid) 15 + sleep 0.5 + done + rm /var/run/$NAME.pid + fi + echo "done" +} + +status() { + status_of_proc -p /var/run/$NAME.pid "" "$app" && exit 0 || exit $? +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; + status) + status + ;; + *) + echo "Usage: $NAME {start|stop|restart|status}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..d6bd37a --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,6 @@ +location PATHTOCHANGE/ { + rewrite ^PATHTOCHANGE$ PATHTOCHANGE/ permanent; + proxy_pass http://localhost:8000/; + proxy_set_header Host $host; + proxy_buffering off; +} diff --git a/conf/nginx.conf-nosub b/conf/nginx.conf-nosub new file mode 100644 index 0000000..6271ca9 --- /dev/null +++ b/conf/nginx.conf-nosub @@ -0,0 +1,6 @@ +location / { + proxy_pass http://localhost:8000/; + proxy_set_header Host $host; + # be careful, this line doesn't override any proxy_buffering on set in a conf.d/file.conf + proxy_buffering off; +} diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..e9fab7b --- /dev/null +++ b/manifest.json @@ -0,0 +1,44 @@ +{ + "name": "EtherCalc", + "id": "ethercalc", + "description": { + "en": "online web spreadsheet editor providing collaborative editing in really real-time" + }, + "developer": { + "name": "zamentur", + "email": "valentin@grimaud.me", + "url": "https://ethercalc.net/" + }, + "multi_instance": "false", + "arguments": { + "install" : [ + { + "name": "domain", + "ask": { + "en": "Choose a domain for EtherCalc" + }, + "example": "domain.org" + }, + { + "name": "path", + "ask": { + "en": "Choose a path for EtherCalc" + }, + "example": "/calc", + "default": "/calc" + }, + { + "name": "public_site", + "ask": { + "en": "Is it a public EtherCalc ?" + }, + "choices": ["Yes", "No"], + "default": "Yes" + } + + + ] + } +} + + diff --git a/scripts/install b/scripts/install new file mode 100644 index 0000000..f594684 --- /dev/null +++ b/scripts/install @@ -0,0 +1,51 @@ +#!/bin/bash + +app="ethercalc" + +# Retrieve arguments +domain=$1 +path=$2 +is_public=$3 + +# Check domain/path availability +sudo yunohost app checkurl $domain$path -a $app +if [[ ! $? -eq 0 ]]; then +exit 1 +fi + +# Save specific settings +sudo yunohost app setting $app is_public -v $is_public + +# Remove trailing "/" for next commands +path=${path%/} + +# Install dependances +sudo apt-get install nodejs-legacy npm redis-server -y +sudo npm i -g ethercalc + +# Copy files to the right place +sudo cp ../conf/$app /etc/init.d/ +sudo chmod +x /etc/init.d/$app +sudo update-rc.d $app defaults +sudo mkdir /var/log/$app/ +sudo touch /var/log/$app/$app.log +sudo chown www-data /var/log/$app/$app.log + +# Modify Nginx configuration file and copy it to Nginx conf directory +sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf* +sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf* +if [ "$path" = "" ]; +then + sudo cp ../conf/nginx.conf-nosub /etc/nginx/conf.d/$domain.d/$app.conf +else + sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf +fi + +# Reload Nginx and regenerate SSOwat conf +sudo service nginx reload +if [ "$is_public" = "Yes" ]; +then + sudo yunohost app setting $app skipped_uris -v "/" +fi +sudo yunohost app ssowatconf +sudo service $app start diff --git a/scripts/remove b/scripts/remove new file mode 100644 index 0000000..4f2bed2 --- /dev/null +++ b/scripts/remove @@ -0,0 +1,13 @@ +#!/bin/bash + +app="ethercalc" + +domain=$(sudo yunohost app setting $app domain) + +sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf +sudo rm -Rf /var/log/$app/ +sudo update-rc.d $app remove +sudo service $app stop +sudo rm /etc/init.d/$app + + diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..9549643 --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,3 @@ +#!/bin/bash + +#TODO