From 6e871990318d962c59666f342f66a1bdd04caff6 Mon Sep 17 00:00:00 2001 From: Snipees Date: Sat, 5 Sep 2015 15:24:46 +0200 Subject: [PATCH] :package: rewrite --- conf/{config.ini => couchpotato.conf} | 0 conf/{couchpotato => couchpotato.defaults} | 2 +- conf/couchpotato.init | 135 +++++++++++++++++++++ conf/nginx.conf | 2 +- manifest.json | 49 ++++++-- scripts/backup | 18 +-- scripts/install | 126 ++++++++++--------- scripts/remove | 34 ++++-- scripts/restore | 23 ++-- scripts/upgrade | 56 +++++++-- 10 files changed, 335 insertions(+), 110 deletions(-) rename conf/{config.ini => couchpotato.conf} (100%) rename conf/{couchpotato => couchpotato.defaults} (82%) create mode 100644 conf/couchpotato.init diff --git a/conf/config.ini b/conf/couchpotato.conf similarity index 100% rename from conf/config.ini rename to conf/couchpotato.conf diff --git a/conf/couchpotato b/conf/couchpotato.defaults similarity index 82% rename from conf/couchpotato rename to conf/couchpotato.defaults index cf57cc2..59650e7 100644 --- a/conf/couchpotato +++ b/conf/couchpotato.defaults @@ -10,6 +10,6 @@ CP_HOME=APPDIRTOCHANGE #$APP_PATH, the location of couchpotato.py, the defau CP_DATA=DATADIRTOCHANGE #$DATA_DIR, the location of couchpotato.db, cache, logs, the default is /opt/couchpotato CP_PIDFILE=PIDFILETOCHANGE #$PID_FILE, the location of couchpotato.pid, the default is /var/run/couchpotato/couchpotato.pid PYTHON_BIN=PYTBINTOCHANGE #$DAEMON, the location of the python binary, the default is /usr/bin/python -CP_OPTS=" --config=OPTSTOCHANGE" #$EXTRA_DAEMON_OPTS, extra cli option for couchpotato, i.e. " --config_file=/home/couchpotato/couchpotato.ini" +CP_OPTS=" --config_file=OPTSTOCHANGE" #$EXTRA_DAEMON_OPTS, extra cli option for couchpotato, i.e. " --config_file=/home/couchpotato/couchpotato.ini" #SSD_OPTS=SSDTOCHANGE #$EXTRA_SSD_OPTS, extra start-stop-daemon option like " --group=users" #CP_PORT=PORTTOCHANGE #$PORT_OPTS, hardcoded port for the webserver, overrides value in couchpotato.ini \ No newline at end of file diff --git a/conf/couchpotato.init b/conf/couchpotato.init new file mode 100644 index 0000000..5336182 --- /dev/null +++ b/conf/couchpotato.init @@ -0,0 +1,135 @@ +#! /bin/sh + +### BEGIN INIT INFO +# Provides: couchpotato +# Required-Start: $local_fs $network $remote_fs +# Required-Stop: $local_fs $network $remote_fs +# Should-Start: $NetworkManager +# Should-Stop: $NetworkManager +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts instance of CouchPotato +# Description: starts instance of CouchPotato using start-stop-daemon +### END INIT INFO + +# Check for existance of defaults file +# and utilze if available +if [ -f /etc/default/couchpotato ]; then + . /etc/default/couchpotato +else + echo "/etc/default/couchpotato not found using default settings."; +fi + +. /lib/lsb/init-functions + +# Script name +NAME=couchpotato + +# App name +DESC=CouchPotato + +## Don't edit this file +## Edit user configuation in /etc/default/couchpotato to change +## +## CP_USER= #$RUN_AS, username to run couchpotato under, the default is couchpotato +## CP_HOME= #$APP_PATH, the location of couchpotato.py, the default is /opt/couchpotato +## CP_DATA= #$DATA_DIR, the location of couchpotato.db, cache, logs, the default is /var/opt/couchpotato +## CP_PIDFILE= #$PID_FILE, the location of couchpotato.pid, the default is /var/run/couchpotato/couchpotato.pid +## PYTHON_BIN= #$DAEMON, the location of the python binary, the default is /usr/bin/python +## CP_OPTS= #$EXTRA_DAEMON_OPTS, extra cli option for couchpotato, i.e. " --config_file=/home/couchpotato/couchpotato.ini" +## SSD_OPTS= #$EXTRA_SSD_OPTS, extra start-stop-daemon option like " --group=users" +## +## EXAMPLE if want to run as different user +## add CP_USER=username to /etc/default/couchpotato +## otherwise default couchpotato is used + +# Run CP as username +RUN_AS=${CP_USER-couchpotato} + +# Path to app +# CP_HOME=path_to_app_CouchPotato.py +APP_PATH=${CP_HOME-/opt/couchpotato/} + +# Data directory where couchpotato.db, cache and logs are stored +DATA_DIR=${CP_DATA-/var/opt/couchpotato} + +# Path to store PID file +PID_FILE=${CP_PIDFILE-/var/run/couchpotato/couchpotato.pid} + +# path to python bin +DAEMON=${PYTHON_BIN-/usr/bin/python} + +# Extra daemon option like: CP_OPTS=" --config=/home/couchpotato/couchpotato.ini" +EXTRA_DAEMON_OPTS=${CP_OPTS-} + +# Extra start-stop-daemon option like START_OPTS=" --group=users" +EXTRA_SSD_OPTS=${SSD_OPTS-} + + +## Parameter | Description +## ————————————— | ———————————————————————————————————— +## data_dir | Absolute or ~/ path of the data dir +## config_file | Absolute or ~/ path of the settings file (default DATA_DIR/settings.conf) +## debug | Debug mode +## console_log | Log to console +## quiet | No console logging +## daemon | Daemonize the app +## pid_file | Path to pidfile needed for daemon + + +PID_PATH=`dirname $PID_FILE` +DAEMON_OPTS="CouchPotato.py --quiet --daemon --pid_file=${PID_FILE} --data_dir=${DATA_DIR} ${EXTRA_DAEMON_OPTS}" + + +test -x $DAEMON || exit 0 + +set -e + +# Create PID directory if not exist and ensure the CouchPotato user can write to it +if [ ! -d $PID_PATH ]; then + mkdir -p $PID_PATH + chown $RUN_AS $PID_PATH +fi + +if [ ! -d $DATA_DIR ]; then + mkdir -p $DATA_DIR + chown $RUN_AS $DATA_DIR +fi + +if [ -e $PID_FILE ]; then + PID=`cat $PID_FILE` + if ! kill -0 $PID > /dev/null 2>&1; then + echo "Removing stale $PID_FILE" + rm $PID_FILE + fi +fi + +case "$1" in + start) + touch $PID_FILE + chown $RUN_AS $PID_FILE + echo "Starting $DESC" + start-stop-daemon -d $APP_PATH -c $RUN_AS $EXTRA_SSD_OPTS --start --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS + ;; + stop) + echo "Stopping $DESC" + start-stop-daemon --stop --pidfile $PID_FILE --retry 15 --oknodo + ;; + + restart|force-reload) + echo "Restarting $DESC" + start-stop-daemon --stop --pidfile $PID_FILE --retry 15 --oknodo + start-stop-daemon -d $APP_PATH -c $RUN_AS $EXTRA_SSD_OPTS --start --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS + ;; + + status) + status_of_proc -p $PID_FILE "$DAEMON" "$NAME" + ;; + *) + N=/etc/init.d/$NAME + echo "Usage: $N {start|stop|restart|force-reload|status}" >&2 + exit 1 + ;; +esac + +exit 0 \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf index 29ac99e..da6ed2f 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,7 +1,7 @@ location PATHTOCHANGE { proxy_http_version 1.1; proxy_pass_header Server; - proxy_pass http://IPTOCHANGE:PORTTOCHANGEPATHTOCHANGE; + proxy_pass HOSTTOCHANGE; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; diff --git a/manifest.json b/manifest.json index 12c2578..62ffda1 100644 --- a/manifest.json +++ b/manifest.json @@ -32,19 +32,28 @@ "default": "/couchpotato" }, { - "name": "host", + "name": "public", + "ask": { + "en": "Is it a public application ?", + "fr": "Est-ce une application publique ?" + }, + "choices": ["Yes", "No"], + "default": "No" + }, + { + "name": "method", "ask": { - "en": "Choose host for app (keep 127.0.0.1 for localhost installation)", - "fr": "Choisissez un hôte pour l'application (laissez 127.0.0.1 pour une installation locale)" + "en": "Choose installation method", + "fr": "Choisissez le type d'installation" }, - "example": "192.168.1.100", - "default": "127.0.0.1" + "choices": ["LOCAL", "REMOTE"], + "default": "LOCAL" }, { "name": "port", "ask": { - "en": "Choose the listening port of the app (not used for localhost installation)", - "fr": "Choisissez le port d'écoute de l'application (non utilisé pour une installation locale)" + "en": "LOCAL: Choose the listening port of the app", + "fr": "LOCAL: Choisissez le port d'écoute de l'application" }, "example": "5050", "default": "5050" @@ -52,12 +61,32 @@ { "name": "fork", "ask": { - "en": "Source URL of GIT to use (used only for localhost installation)", - "fr": "URL du GIT source à utiliser (uniquement pour une installation locale)" + "en": "LOCAL: Source URL of GIT to use", + "fr": "LOCAL: URL du GIT source à utiliser" }, "example": "https://github.com/Adelscott/CouchPotatoServer", "default": "https://github.com/RuudBurger/CouchPotatoServer" + }, + { + "name": "host", + "ask": { + "en": "REMOTE: Specify URL for the host", + "fr": "REMOTE: Indiquez l'URL de l'hôte" + }, + "example": "http://192.168.1.100:8888/myapp", + "default": "http://" + } + ], + "remove": [ + { + "name": "data", + "ask": { + "en": "Would you like to keep data files ?", + "fr": "Souhaitez-vous conserver les données ?" + }, + "choices": ["Yes", "No"], + "default": "Yes" } ] } -} +} \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index 8b1020b..4e8373a 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,21 +1,23 @@ #!/bin/bash -# Set variables +# Common variable declaration app_id=couchpotato app_user=couchpotato -app_install_dir=/opt/yunohost/$app_id -app_data_dir=/home/yunohost.app/$app_id -app_host=$(sudo yunohost app setting $app_id host) -app_domain=$(sudo yunohost app setting $app_id domain) +app_install_dir="/opt/yunohost/${app_id}" +app_data_dir="/home/yunohost.app/${app_id}" + +# Retrieve arguments +app_method="$(sudo yunohost app setting ${app_id} method)" +app_domain="$(sudo yunohost app setting ${app_id} domain)" # The parameter $1 is the backup directory location # which will be compressed afterward -app_backup_dir=$1/apps/$app_id -mkdir -p $app_backup_dir +app_backup_dir="$1/apps/${app_id}" +sudo mkdir -p $app_backup_dir # Backup files if localhost installation -if [[ $app_host == "127.0.0.1" ]]; then +if [[ $app_method == "LOCAL"* ]]; then # Backup sources sudo cp -a $app_install_dir/. $app_backup_dir/sources diff --git a/scripts/install b/scripts/install index 9b750ae..1717aa0 100644 --- a/scripts/install +++ b/scripts/install @@ -7,21 +7,31 @@ # Retrieve arguments app_domain=$1 app_path=$2 -app_host=$3 -app_port=$4 -app_fork=$5 -#app_opts=$6 +app_public=$3 +app_method=$4 +app_port=$5 +app_fork=$6 +app_host=$7 -# Set variables +# Basic variable declaration +BASEDIR="$(dirname "$(pwd)")" + +# Common variable declaration app_id=couchpotato app_user=couchpotato -app_install_dir=/opt/yunohost/$app_id -app_data_dir=/home/yunohost.app/$app_id -app_logs_dir=$app_data_dir/logs -app_pid_file=/var/run/$app_id/$app_id.pid -app_config_file=$app_data_dir/config.ini -app_init_file=$app_install_dir/init/ubuntu -app_python_bin=/usr/bin/python +app_local_host="127.0.0.1" +app_python_bin="/usr/bin/python" +## Destinations definitions +app_install_dir="/opt/yunohost/${app_id}" +app_data_dir="/home/yunohost.app/${app_id}" +app_logs_dir="/var/log/${app_id}" +app_config_file="${app_data_dir}/settings.conf" +app_pid_file="/var/run/${app_id}/${app_id}.pid" +## Sources definitions +app_src_conf="$BASEDIR/conf/${app_id}.conf" +app_src_dfts="$BASEDIR/conf/${app_id}.defaults" +app_src_init="$BASEDIR/conf/${app_id}.init" +app_src_nginx_conf="$BASEDIR/conf/nginx.conf" # Check domain/path availability @@ -30,21 +40,21 @@ if [[ ! $? -eq 0 ]]; then exit 1 fi -# Check port availability -sudo yunohost app checkport $app_port -if [[ ! $? -eq 0 ]]; then - exit 1 -fi - # Make install if localhost installation -if [[ $app_host == "127.0.0.1" ]]; then +if [[ $app_method == "LOCAL"* ]]; then + + # Check port availability + sudo yunohost app checkport $app_port + if [[ ! $? -eq 0 ]]; then + exit 1 + fi # Make directories sudo mkdir -p $app_data_dir sudo mkdir -p $app_install_dir - # Install the latest version of App using the fork + # Install latest version of app using the fork sudo apt-get install -y git-core sudo git clone $app_fork $app_install_dir @@ -56,43 +66,32 @@ if [[ $app_host == "127.0.0.1" ]]; then sudo bash -c "source $app_install_dir/bin/activate && pip install cheetah" fi - # Create App user + # Create app user id -u $app_user &>/dev/null || sudo useradd --home-dir $app_install_dir --shell /bin/false $app_user # Configure daemon - sudo sed -i "s@USERTOCHANGE@$app_user@g" ../conf/$app_id - sudo sed -i "s@APPDIRTOCHANGE@$app_install_dir@g" ../conf/$app_id - sudo sed -i "s@DATADIRTOCHANGE@$app_data_dir@g" ../conf/$app_id - sudo sed -i "s@PIDFILETOCHANGE@$app_pid_file@g" ../conf/$app_id - sudo sed -i "s@PYTBINTOCHANGE@$app_python_bin@g" ../conf/$app_id - sudo sed -i "s@OPTSTOCHANGE@$app_config_file@g" ../conf/$app_id - sudo cp -a ../conf/$app_id /etc/default/$app_id - sudo cp -a $app_init_file /etc/init.d/$app_id + sudo sed -i "s@USERTOCHANGE@$app_user@g" $app_src_dfts + sudo sed -i "s@APPDIRTOCHANGE@$app_install_dir@g" $app_src_dfts + sudo sed -i "s@DATADIRTOCHANGE@$app_data_dir@g" $app_src_dfts + sudo sed -i "s@PIDFILETOCHANGE@$app_pid_file@g" $app_src_dfts + sudo sed -i "s@PYTBINTOCHANGE@$app_python_bin@g" $app_src_dfts + sudo sed -i "s@OPTSTOCHANGE@$app_config_file@g" $app_src_dfts + sudo cp -a $app_src_dfts /etc/default/$app_id + sudo cp -a $app_src_init /etc/init.d/$app_id # Configure App - sudo sed -i "s@PATHTOCHANGE@$app_path@g" ../conf/config.ini - sudo sed -i "s@PORTTOCHANGE@$app_port@g" ../conf/config.ini - sudo sed -i "s@DATADIRTOCHANGE@$app_data_dir@g" ../conf/config.ini - sudo cp -a ../conf/config.ini $app_config_file + sudo sed -i "s@PATHTOCHANGE@$app_path@g" $app_src_conf + sudo sed -i "s@PORTTOCHANGE@$app_port@g" $app_src_conf + sudo sed -i "s@DATADIRTOCHANGE@$app_data_dir@g" $app_src_conf + sudo cp -a $app_src_conf $app_config_file - ## Configure specifics options - #case "$app_opts" in - #*"Transmission"*) - # ref_file=$(sudo sed -n -e '/^CONFIG_DIR/ s/.*\= *//p' $(find /etc/default -name '*transmission*') | sed 's/["* ]//g')/settings.json - # ref_field=(download-dir rpc-bind-address rpc-port rpc-url rpc-username rpc-password) - # for i in ${ref_field[*]}; do ref_value+=$(sudo sed -n -e "/$i/ s/.*\: *//p" $ref_file | sed 's/["*,]//g'); done - # ref_value=($ref_value) - # sudo sed -i "s@torrent_download_dir =.*@torrent_download_dir = ${ref_value[0]}@g" ../conf/config.ini - # sudo sed -i "s@torrent_path =.*@torrent_path = ${ref_value[0]}@g" ../conf/config.ini - # sudo sed -i "s@torrent_host =.*@torrent_host = http://${ref_value[1]}:${ref_value[2]}${ref_value[3]}@g" ../conf/config.ini - # sudo sed -i "s@torrent_username =.*@torrent_username = ${ref_value[4]}@g" ../conf/config.ini - # sudo sed -i "s@torrent_password =.*@torrent_password = ${ref_value[5]}@g" ../conf/config.ini - # sudo sed -i "s@torrent_method =.*@torrent_method = transmission@g" ../conf/config.ini - # sudo sed -i "s@torrent_custom_url =.*@torrent_custom_url = 1@g" ../conf/config.ini - # sudo sed -i "s@use_torrents =.*@use_torrents = 1@g" ../conf/config.ini - # sudo cp -a ../conf/config.ini $app_config_file - # ;; - #esac + # Redirect logs directory + if [[ $app_logs_dir != "$app_data_dir"* ]]; then + sudo mkdir -p $app_logs_dir + sudo chown -R $app_user $app_logs_dir + sudo chmod +x -R $app_logs_dir + sudo sed -i "s@self.log_dir =.*@self.log_dir = '$app_logs_dir'@g" $app_install_dir/CouchPotato.py + fi # Set rights sudo chown -R $app_user $app_install_dir @@ -102,7 +101,7 @@ if [[ $app_host == "127.0.0.1" ]]; then sudo chmod +x -R $app_data_dir # Add service to YunoHost's monitoring - sudo yunohost service add $app_id --log $app_logs_dir/ --status "ps aux | grep $app_id | grep -v grep" + sudo yunohost service add $app_id --log $app_logs_dir --status "ps aux | grep $app_id | grep -v grep" # Start daemon at boot sudo update-rc.d $app_id defaults @@ -110,6 +109,9 @@ if [[ $app_host == "127.0.0.1" ]]; then # Reload daemon sudo service $app_id restart + # Set proxy host variable + app_host="http://${app_local_host}:${app_port}${app_path%/}" + fi @@ -117,15 +119,21 @@ fi app_path=${app_path%/} # Configure Nginx -sudo sed -i "s@IPTOCHANGE@$app_host@g" ../conf/nginx.conf -sudo sed -i "s@PORTTOCHANGE@$app_port@g" ../conf/nginx.conf -sudo sed -i "s@PATHTOCHANGE@$app_path@g" ../conf/nginx.conf -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$app_domain.d/$app_id.conf +sudo sed -i "s@PATHTOCHANGE@$app_path@g" $app_src_nginx_conf +sudo sed -i "s@HOSTTOCHANGE@$app_host@g" $app_src_nginx_conf +sudo cp $app_src_nginx_conf /etc/nginx/conf.d/$app_domain.d/$app_id.conf + +# If app is public, add url to SSOWat conf as skipped_uris +if [[ $app_public == "Yes" ]]; then + # unprotected_uris allows SSO credentials to be passed anyway. + sudo yunohost app setting $app_id unprotected_uris -v "/" +fi -# Store used IP for upgrades -sudo yunohost app setting $app_id host -v $app_host +# Save app settings +sudo yunohost app setting $app_id public -v "$app_public" +sudo yunohost app setting $app_id method -v "$app_method" +sudo yunohost app setting $app_id host -v "$app_host" # Reload Nginx and regenerate SSOwat conf sudo service nginx reload -echo $? sudo yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove index 0eb5abb..ef59734 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,30 +1,41 @@ #!/bin/bash -# Set variables +# Common variable declaration app_id=couchpotato app_user=couchpotato -app_install_dir=/opt/yunohost/$app_id -app_data_dir=/home/yunohost.app/$app_id -app_host=$(sudo yunohost app setting $app_id host) -app_domain=$(sudo yunohost app setting $app_id domain) +app_install_dir="/opt/yunohost/${app_id}" +app_data_dir="/home/yunohost.app/${app_id}" +app_logs_dir="/var/log/${app_id}" + +# Retrieve arguments +app_method="$(sudo yunohost app setting ${app_id} method)" +app_domain="$(sudo yunohost app setting ${app_id} domain)" +keep_data=$1 # Remove files if localhost installation -if [[ $app_host == "127.0.0.1" ]]; then +if [[ $app_method == "LOCAL"* ]]; then - # Kill App and remove from boot + # Kill app and remove from boot sudo service $app_id stop sudo killall $app_id sudo update-rc.d $app_id remove - # Delete App user + # Delete app user sudo deluser $app_user # Remove sources sudo rm -rf $app_install_dir + # Remove logs + if [[ $app_logs_dir != "$app_data_dir"* ]]; then + sudo rm -rf $app_logs_dir + fi + # Remove data - sudo rm -rf $app_data_dir + if [[ $keep_data == "No" ]]; then + sudo rm -rf $app_data_dir + fi # Remove daemon config sudo rm -f /etc/init.d/$app_id @@ -37,6 +48,9 @@ fi # Remove Nginx parameters sudo rm -f /etc/nginx/conf.d/$app_domain.d/$app_id.conf +# Remove Yunohost service +sudo yunohost service remove $app_id + # Reload Nginx and update Yunohost sudo service nginx reload -sudo yunohost service remove $app_id \ No newline at end of file +sudo yunohost app ssowatconf \ No newline at end of file diff --git a/scripts/restore b/scripts/restore index 4db4383..23162fb 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,21 +1,23 @@ #!/bin/bash -# Set variables -app_id=couchpotato -app_user=couchpotato -app_install_dir=/opt/yunohost/$app_id -app_data_dir=/home/yunohost.app/$app_id -app_host=$(sudo yunohost app setting $app_id host) -app_domain=$(sudo yunohost app setting $app_id domain) +# Common variable declaration +app_id=htpc-manager +app_user=htpc-manager +app_install_dir="/opt/yunohost/${app_id}" +app_data_dir="/home/yunohost.app/${app_id}" + +# Retrieve arguments +app_method="$(sudo yunohost app setting ${app_id} method)" +app_domain="$(sudo yunohost app setting ${app_id} domain)" # The parameter $1 is the uncompressed restore directory location -app_backup_dir=$1/apps/$app_id +app_backup_dir="$1/apps/${app_id}" # Restore files if localhost installation -if [[ $app_host == "127.0.0.1" ]]; then +if [[ $app_method == "LOCAL"* ]]; then - # Kill App + # Kill app sudo service $app_id stop sudo killall $app_id @@ -51,5 +53,4 @@ sudo cp -a $app_backup_dir/nginx.conf /etc/nginx/conf.d/$app_domain.d/$app_id.co # Reload Nginx and regenerate SSOwat conf sudo service nginx reload -echo $? sudo yunohost app ssowatconf \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade index 345c43e..07e3570 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,27 +1,46 @@ #!/bin/bash -# Set variables +# Basic variable declaration +BASEDIR="$(dirname "$(pwd)")" + +# Common variable declaration app_id=couchpotato app_user=couchpotato -app_install_dir=/opt/yunohost/$app_id -app_init_file=$app_install_dir/init/ubuntu -app_host=$(sudo yunohost app setting $app_id host) +app_install_dir="/opt/yunohost/${app_id}" +app_data_dir="/home/yunohost.app/${app_id}" +app_logs_dir="/var/log/${app_id}" +## Sources definitions +app_src_init="$BASEDIR/conf/${app_id}.init" +app_src_nginx_conf="$BASEDIR/conf/nginx.conf" + +# Retrieve arguments +app_public="$(sudo yunohost app setting ${app_id} public)" +app_method="$(sudo yunohost app setting ${app_id} method)" +app_domain="$(sudo yunohost app setting ${app_id} domain)" +app_path="$(sudo yunohost app setting ${app_id} path)" +app_host="$(sudo yunohost app setting ${app_id} host)" + # Make upgrade if localhost installation -if [[ $app_host == "127.0.0.1" ]]; then +if [[ $app_method == "LOCAL"* ]]; then # Kill App sudo service $app_id stop sudo killall $app_id - # Upgrade to the latest version of App using the fork + # Upgrade to the latest version of app using the fork cd $app_install_dir && sudo git pull cd - # Upgrade dependencies + # Redirect logs directory + if [[ $app_logs_dir != $app_data_dir ]]; then + sudo sed -i "s@self.log_dir =.*@self.log_dir = '$app_logs_dir'@g" $app_install_dir/CouchPotato.py + fi + # Update init file - sudo cp -a $app_init_file /etc/init.d/$app_id + sudo cp -a $app_src_init /etc/init.d/$app_id # Set rights sudo chown -R $app_user $app_install_dir @@ -29,11 +48,28 @@ if [[ $app_host == "127.0.0.1" ]]; then sudo chmod +x -R $app_install_dir # Reload daemon - sudo service $app_id restart + sudo service $app_id start fi -# Reload Nginx -sudo service nginx reload +# Remove trailing "/" for next commands +app_path=${app_path%/} +# Configure Nginx +sudo sed -i "s@PATHTOCHANGE@$app_path@g" $app_src_nginx_conf +sudo sed -i "s@HOSTTOCHANGE@$app_host@g" $app_src_nginx_conf +sudo cp $app_src_nginx_conf /etc/nginx/conf.d/$app_domain.d/$app_id.conf + +# If app is public, add url to SSOWat conf as skipped_uris +if [[ $app_public = "Yes" ]]; +then + # See install script + sudo yunohost app setting $app_id unprotected_uris -v "/" + # Remove old settings + sudo yunohost app setting $app_id skipped_uris -d +fi + +# Reload Nginx and regenerate SSOwat conf +sudo service nginx reload +sudo yunohost app ssowatconf