From d6f696ead08e250427030d8c6f10d70e3044a77f Mon Sep 17 00:00:00 2001 From: scith Date: Thu, 29 Dec 2016 18:34:33 +0100 Subject: [PATCH] Major upgrade - YunoHost 2.4 - Remove method, port, host and fork (remote installs should be done with direct_ynh) for simplicity - YunoHost multimedia folder structure - Integrates with transmission (RPC or watchdir, if available) - Systemd instead of init - Backup/restore - Automatic port finding Because these are major changes, I was not able to manage upgrade from previous versions. You must remove the app and reinstall. --- README.md | 12 +- check_process | 22 ++ conf/couchpotato.conf | 434 ++++++++++++++++++++++++++------------ conf/couchpotato.defaults | 15 -- conf/couchpotato.init | 135 ------------ conf/nginx.conf | 6 +- conf/systemd.service | 12 ++ manifest.json | 70 +----- scripts/backup | 44 ++-- scripts/install | 227 +++++++++++--------- scripts/remove | 63 +++--- scripts/restore | 122 +++++++---- scripts/upgrade | 131 +++++++----- 13 files changed, 674 insertions(+), 619 deletions(-) create mode 100644 check_process delete mode 100644 conf/couchpotato.defaults delete mode 100644 conf/couchpotato.init create mode 100644 conf/systemd.service diff --git a/README.md b/README.md index 22400b2..fa03fba 100644 --- a/README.md +++ b/README.md @@ -4,20 +4,19 @@ [![Status](https://img.shields.io/badge/status-in_progress-yellow.svg?style=flat)](https://github.com/Snipees/couchpotato_ynh/milestones) [![Dependencies](https://img.shields.io/badge/dependencies-includes-lightgrey.svg?style=flat)](https://github.com/Snipees/couchpotato_ynh#dependencies) [![GitHub license](https://img.shields.io/badge/license-GPLv3-blue.svg?style=flat)](https://raw.githubusercontent.com/Snipees/couchpotato_ynh/master/LICENSE) -[![Yunohost version](https://img.shields.io/badge/yunohost-2.2.0_tested-orange.svg?style=flat)](https://github.com/YunoHost/yunohost) -[![GitHub issues](https://img.shields.io/github/issues/Snipees/couchpotato_ynh.svg?style=flat)](https://github.com/Snipees/couchpotato_ynh/issues) +[![Yunohost version](https://img.shields.io/badge/yunohost-2.4.2_tested-orange.svg?style=flat)](https://github.com/YunoHost/yunohost) +[![GitHub issues](https://img.shields.io/github/issues/YunoHost-Apps/couchpotato_ynh.svg?style=flat)](https://github.com/YunoHost-Apps/couchpotato_ynh/issues) [ **CouchPotato Integration for Yunohost** ] -This install script uses a Git-fork as sources for a local installation. -Otherwise the script sets a reverse-proxy to a remote instance. +Download movies automatically, easily and in the best quality as soon as they are available. +- Integrates automatically with [transmission_ynh](https://github.com/YunoHost-Apps/transmission_ynh) (or tries to...), +- Integrates [YunoHost multimedia](https://github.com/YunoHost-Apps/yunohost.multimedia) folder structure ### How to install: - Use **Install software** option from Yunohost admin panel - Find textbox tagged as **Install custom App from github** - Copy and paste: https://github.com/YunoHost-Apps/couchpotato_ynh -- Choose the method installation: *local* or *remote* (as described above) -- Answer the required questions to the selected method ### More information about: @@ -26,6 +25,7 @@ Otherwise the script sets a reverse-proxy to a remote instance. #### Special Thanks to the Yunohost Community: +[Snipees](https://github.com/Snipees) [anaqreon](https://github.com/anaqreon), [aymhce](https://github.com/aymhce), [beudbeud](https://github.com/abeudin), diff --git a/check_process b/check_process new file mode 100644 index 0000000..f8bbf06 --- /dev/null +++ b/check_process @@ -0,0 +1,22 @@ +;; Test CouchPotato + auto_remove=1 + ; Manifest + domain="domain.tld" (DOMAIN) + path="/couchpotato" (PATH)" + ; Checks + pkg_linter=1 + setup_sub_dir=1 + setup_root=1 + setup_nourl=0 + setup_private=0 + setup_public=0 + upgrade=1 + backup_restore=1 + multi_instance=0 + wrong_user=0 + wrong_path=1 + incorrect_path=1 + corrupt_source=0 + fail_download_source=0 + port_already_use=1 (5050) + final_path_already_use=0 diff --git a/conf/couchpotato.conf b/conf/couchpotato.conf index 388a7b5..a1fac0d 100644 --- a/conf/couchpotato.conf +++ b/conf/couchpotato.conf @@ -1,18 +1,28 @@ [core] -api_key = -username = -ssl_key = -ssl_cert = -data_dir = DATADIRTOCHANGE +api_key = +username = +ssl_key = +ssl_cert = +data_dir = __DATADIR__ permission_folder = 0755 development = 0 -url_base = PATHTOCHANGE +url_base = __PATH__ debug = 0 launch_browser = False -password = -port = PORTTOCHANGE +password = +port = __PORT__ permission_file = 0755 -show_wizard = 1 +show_wizard = 0 +username_internal_meta = rw +proxy_server = +use_proxy = 0 +proxy_password = +bookmarklet_host = +dereferer = http://www.nullrefer.com/? +dark_theme = False +api_key_internal_meta = ro +proxy_username = +ipv6 = 0 [download_providers] @@ -26,38 +36,44 @@ automatic = False rating = 7.0 votes = 1000 hour = 12 -required_genres = +required_genres = year = 2011 -ignored_genres = +ignored_genres = [manage] startup_scan = True library_refresh_interval = 0 cleanup = True enabled = False -library = +library = [renamer] nfo_name = .orig. -from = +from = /home/yunohost.transmission/completed force_every = 2 move_leftover = False -to = +to = /home/yunohost.multimedia/share/Video/Movies file_name = . -enabled = False +enabled = __RENAMER__ next_on_failed = True unrar = False rename_nfo = True -cleanup = False -separator = +cleanup = 1 +separator = folder_name = () run_every = 1 -foldersep = +foldersep = file_action = link ntfs_permission = False +default_file_action = move +check_space = True +unrar_modify_date = False +replace_doubles = True +unrar_path = +remove_lower_quality_copies = True [subtitle] -languages = +languages = force = False enabled = False @@ -67,25 +83,26 @@ enabled = False name = -trailer [blackhole] -directory = +directory = __WATCHDIR__ manual = 0 -enabled = 0 +enabled = __BLACKHOLE__ create_subdir = 0 -use_for = both +use_for = torrent +magnet_file = 0 [deluge] -username = +username = delete_failed = True -completed_directory = +completed_directory = manual = 0 enabled = 0 -label = +label = paused = False host = localhost:58846 delete_files = True -directory = +directory = remove_complete = True -password = +password = [nzbget] username = nzbget @@ -96,7 +113,7 @@ enabled = 0 priority = 0 ssl = 0 host = localhost:6789 -password = +password = [nzbvortex] delete_failed = True @@ -104,39 +121,44 @@ manual = False enabled = 0 ssl = 1 host = localhost:4321 -api_key = +api_key = +group = [pneumatic] -directory = +directory = manual = 0 enabled = 0 [qbittorrent] -username = +username = manual = 0 enabled = 0 paused = False host = http://localhost:8080/ delete_files = True remove_complete = False -password = +password = +label = couchpotato [rtorrent] -username = +username = rpc_url = RPC2 manual = 0 enabled = 0 -label = +label = paused = False ssl = 0 host = localhost:80 delete_files = True -directory = +directory = remove_complete = False -password = +password = +authentication = basic +ssl_verify = 1 +ssl_ca_bundle = [sabnzbd] -category = +category = delete_failed = True manual = False enabled = 0 @@ -144,103 +166,106 @@ priority = 0 ssl = 0 host = localhost:8080 remove_complete = False -api_key = +api_key = [synology] -username = +username = manual = 0 -destination = +destination = enabled = 0 host = localhost:5000 -password = +password = use_for = both [transmission] -username = +username = transmission stalled_as_failed = True delete_failed = True -rpc_url = transmission +rpc_url = __RPCURL__ manual = 0 -enabled = 0 +enabled = __RPC__ paused = False -host = localhost:9091 +host = 127.0.0.1:9091 delete_files = True -directory = +directory = remove_complete = True -password = +password = __RPCPASSWORD__ [utorrent] -username = +username = delete_failed = True manual = 0 enabled = 0 -label = +label = paused = False host = localhost:8000 delete_files = True remove_complete = True -password = +password = [notification_providers] [boxcar2] -token = +token = enabled = 0 on_snatch = 0 [email] starttls = 0 -smtp_pass = +smtp_pass = on_snatch = 0 -from = -to = +from = +to = smtp_port = 25 enabled = 0 -smtp_server = -smtp_user = +smtp_server = +smtp_user = ssl = 0 [growl] -password = +password = on_snatch = False -hostname = +hostname = enabled = 0 -port = +port = [nmj] host = localhost enabled = 0 -mount = -database = +mount = +database = [notifymyandroid] priority = 0 -dev_key = -api_key = +dev_key = +api_key = enabled = 0 on_snatch = 0 [notifymywp] priority = 0 -dev_key = -api_key = +dev_key = +api_key = enabled = 0 on_snatch = 0 [plex] on_snatch = 0 -clients = +clients = enabled = 0 media_server = localhost +username = +auth_token = +password = [prowl] priority = 0 on_snatch = 0 -api_key = +api_key = enabled = 0 [pushalot] -auth_token = +auth_token = important = 0 enabled = 0 silent = 0 @@ -248,14 +273,15 @@ on_snatch = 0 [pushbullet] on_snatch = 0 -api_key = +api_key = enabled = 0 -devices = +devices = +channels = [pushover] -sound = +sound = on_snatch = 0 -user_key = +user_key = enabled = 0 priority = 0 api_token = YkxHMYDZp285L265L3IwH3LmzkTaCy @@ -265,24 +291,26 @@ enabled = 0 [toasty] on_snatch = 0 -api_key = +api_key = enabled = 0 [trakt] remove_watchlist_enabled = False notification_enabled = False -automation_password = +automation_password = automation_enabled = False -automation_username = -automation_api_key = +automation_username = +automation_api_key = +automation_oauth_refresh = +automation_oauth_token = [twitter] on_snatch = 0 -screen_name = +screen_name = enabled = 0 -access_token_key = -mention = -access_token_secret = +access_token_key = +mention = +access_token_secret = direct_message = 0 [xbmc] @@ -293,7 +321,7 @@ only_first = 0 enabled = 0 remote_dir_scan = 0 host = localhost:8080 -password = +password = meta_disc_art_name = disc.png meta_extra_thumbs_name = extrathumbs/thumb.jpg meta_thumbnail = True @@ -318,18 +346,18 @@ meta_extra_thumbs = False meta_disc_art = False [xmpp] -username = +username = on_snatch = 0 hostname = talk.google.com enabled = 0 -to = -password = +to = +password = port = 5222 [nzb_providers] [binsearch] -enabled = +enabled = extra_score = 0 [newznab] @@ -341,7 +369,7 @@ custom_tag = ,,,,, api_key = ,,,,, [nzbclub] -enabled = +enabled = extra_score = 0 [nzbindex] @@ -349,10 +377,11 @@ enabled = True extra_score = 0 [omgwtfnzbs] -username = -api_key = -enabled = +username = +api_key = +enabled = extra_score = 20 +custom_tag = [torrent_providers] @@ -360,55 +389,56 @@ extra_score = 20 seed_time = 40 extra_score = 20 only_internal = 1 -passkey = +passkey = enabled = False favor = both prefer_internal = 1 seed_ratio = 1 [bithdtv] -username = +username = seed_time = 40 extra_score = 20 enabled = False -password = +password = seed_ratio = 1 [bitsoup] -username = +username = seed_time = 40 extra_score = 20 enabled = False -password = +password = seed_ratio = 1 [hdbits] -username = +username = seed_time = 40 extra_score = 0 -passkey = +passkey = enabled = False seed_ratio = 1 +internal_only = False [ilovetorrents] -username = +username = seed_time = 40 extra_score = 0 enabled = False -password = +password = seed_ratio = 1 [iptorrents] -username = +username = freeleech = 0 extra_score = 0 enabled = False seed_time = 40 -password = +password = seed_ratio = 1 [kickasstorrents] -domain = +domain = seed_time = 40 extra_score = 0 enabled = True @@ -416,74 +446,77 @@ only_verified = False seed_ratio = 1 [passthepopcorn] -username = -domain = +username = +domain = seed_time = 40 extra_score = 20 -passkey = +passkey = prefer_scene = 0 enabled = False prefer_golden = 1 require_approval = 0 -password = +password = seed_ratio = 1 +prefer_freeleech = 1 [sceneaccess] -username = +username = seed_time = 40 extra_score = 20 enabled = False -password = +password = seed_ratio = 1 [thepiratebay] seed_time = 40 -domain = +domain = enabled = False seed_ratio = 1 extra_score = 0 +trusted_only = False [torrentbytes] -username = +username = seed_time = 40 extra_score = 20 enabled = False -password = +password = seed_ratio = 1 [torrentday] -username = +username = seed_time = 40 extra_score = 0 enabled = False -password = +password = seed_ratio = 1 +cookiesetting = [torrentleech] -username = +username = seed_time = 40 extra_score = 20 enabled = False -password = +password = seed_ratio = 1 [torrentpotato] -use = +use = seed_time = 40 -name = +name = extra_score = 0 enabled = False -host = +host = pass_key = , seed_ratio = 1 [torrentshack] -username = +username = seed_time = 40 extra_score = 0 enabled = False scene_only = False -password = +password = seed_ratio = 1 [torrentz] @@ -496,16 +529,16 @@ seed_ratio = 1 [yify] seed_time = 40 -domain = +domain = enabled = False seed_ratio = 1 extra_score = 0 [searcher] preferred_method = both -required_words = +required_words = ignored_words = german, dutch, french, truefrench, danish, swedish, spanish, italian, korean, dubbed, swesub, korsub, dksubs, vain -preferred_words = +preferred_words = [nzb] retention = 1500 @@ -524,13 +557,13 @@ chart_display_enabled = True backlog = False [flixster] -automation_ids_use = +automation_ids_use = automation_enabled = False -automation_ids = +automation_ids = [goodfilms] automation_enabled = False -automation_username = +automation_username = [imdb] automation_charts_top250 = False @@ -538,8 +571,8 @@ chart_display_boxoffice = True chart_display_top250 = False automation_enabled = False chart_display_rentals = True -automation_urls_use = -automation_urls = +automation_urls_use = +automation_urls = automation_providers_enabled = False automation_charts_rentals = True chart_display_theater = False @@ -557,16 +590,16 @@ automation_enabled = False [letterboxd] automation_enabled = False -automation_urls_use = -automation_urls = +automation_urls_use = +automation_urls = [moviemeter] automation_enabled = False [moviesio] automation_enabled = False -automation_urls_use = -automation_urls = +automation_urls_use = +automation_urls = [popularmovies] automation_enabled = False @@ -578,7 +611,7 @@ automation_urls_use = 1 automation_urls = http://www.rottentomatoes.com/syndication/rss/in_theaters.xml [themoviedb] -api_key = 9b939aee0aaafc12a65bf448e4af9543 +api_key = [mediabrowser] meta_enabled = False @@ -595,4 +628,139 @@ cron_hour = 12 cron_minute = 42 always_search = False run_on_launch = 0 -search_on_add = 1 \ No newline at end of file +search_on_add = 1 + +[hadouken] +auth_type = api_key +auth_pass = +enabled = 0 +label = +host = localhost:7890 +version = v4 +auth_user = +api_key = + +[putio] +delete_file = 0 +callback_host = +download_dir = +manual = 0 +enabled = 0 +oauth_token = +download = 0 +folder = 0 + +[androidpn] +broadcast = 1 +username = +on_snatch = 0 +enabled = 0 +url = + +[emby] +host = localhost:8096 +apikey = +enabled = 0 + +[homey] +url = +enabled = 0 + +[slack] +on_snatch = 0 +as_user = False +enabled = 0 +bot_name = CouchPotato +channels = +token = +icon_emoji = +icon_url = +include_imdb = True + +[telegrambot] +bot_token = +on_snatch = 0 +enabled = 0 +receiver_user_id = + +[webhook] +url = +on_snatch = 0 +enabled = 0 + +[alpharatio] +username = +seed_time = 40 +extra_score = 0 +enabled = False +scene_only = False +password = +seed_ratio = 1 + +[hd4free] +username = +apikey = +seed_time = 0 +extra_score = 0 +enabled = False +internal_only = False +prefer_internal = 1 +seed_ratio = 0 + +[magnetdl] +seed_time = 40 +max_pages = 3 +enabled = False +seed_ratio = 1 +extra_score = 0 + +[morethantv] +username = +seed_time = 40 +extra_score = 0 +enabled = False +scene_only = False +password = +seed_ratio = 1 + +[rarbg] +min_leechers = 0 +enabled = False +ranked_only = 1 +extra_score = 0 +min_seeders = 10 + +[scenetime] +username = +seed_time = 40 +extra_score = 20 +enabled = False +password = +seed_ratio = 1 + +[torrent] +minimum_seeders = 1 + +[crowdai] +automation_enabled = False +number_grabs = 500 +automation_urls_use = 1 +automation_urls = http://YOUR_PROVIDER/rss?t=THE_MOVIE_CATEGORY&i=YOUR_USER_ID&r=YOUR_API_KEY&res=2&rls=2&num=100 + +[hummingbird] +automation_list_dropped = False +automation_enabled = False +automation_username = +automation_list_hold = False +automation_list_completed = False +automation_list_plan = True +automation_list_current = False + +[wdtvlive] +meta_thumbnail = True +meta_enabled = False +meta_nfo = True + +[suggestion] +enabled = True + diff --git a/conf/couchpotato.defaults b/conf/couchpotato.defaults deleted file mode 100644 index 59650e7..0000000 --- a/conf/couchpotato.defaults +++ /dev/null @@ -1,15 +0,0 @@ -# COPY THIS FILE TO /etc/default/couchpotato -# OPTIONS: CP_HOME, CP_USER, CP_DATA, CP_PIDFILE, PYTHON_BIN, CP_OPTS, SSD_OPTS, CP_PORT - -## EXAMPLE if want to run as different user -## add CP_USER=username to /etc/default/couchpotato -## otherwise default couchpotato is used - -CP_USER=USERTOCHANGE #$RUN_AS, username to run couchpotato under, the default is couchpotato -CP_HOME=APPDIRTOCHANGE #$APP_PATH, the location of couchpotato.py, the default is /opt/couchpotato -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_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 deleted file mode 100644 index 5336182..0000000 --- a/conf/couchpotato.init +++ /dev/null @@ -1,135 +0,0 @@ -#! /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 da6ed2f..664df0e 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,7 +1,7 @@ -location PATHTOCHANGE { +location __PATH__ { proxy_http_version 1.1; proxy_pass_header Server; - proxy_pass HOSTTOCHANGE; + proxy_pass http://127.0.0.1:__PORT__; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; @@ -12,4 +12,4 @@ location PATHTOCHANGE { # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; more_clear_input_headers 'Accept-Encoding'; -} \ No newline at end of file +} diff --git a/conf/systemd.service b/conf/systemd.service new file mode 100644 index 0000000..e0ae36c --- /dev/null +++ b/conf/systemd.service @@ -0,0 +1,12 @@ +[Unit] +Description=CouchPotato application instance +After=network.target + +[Service] +ExecStart=__PYTHON__ __APPDIR__/CouchPotato.py --quiet --pid_file=__PIDFILE__ --data_dir=__DATADIR__ --config_file=__CONFIGFILE__ +Type=simple +User=__USER__ +Group=__USER__ + +[Install] +WantedBy=multi-user.target diff --git a/manifest.json b/manifest.json index 62ffda1..d46f55a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,17 +1,25 @@ { + "packaging_format": 1, "name": "CouchPotato", "id": "couchpotato", "description": { "en": "Automatic movie downloader", "fr": "Téléchargement automatisé de film" }, - "license": "GPL-3", + "url": "https://couchpota.to/", + "license": "free", "maintainer": { "name": "Snipees", "email": "snipees@wareziens.net", "url": "https://github.com/Snipees" }, - "multi_instance": "false", + "multi_instance": false, + "services": [ + "nginx" + ], + "requirements": { + "yunohost": ">= 2.4.0" + }, "arguments": { "install": [ { @@ -30,63 +38,7 @@ }, "example": "/couchpotato", "default": "/couchpotato" - }, - { - "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 installation method", - "fr": "Choisissez le type d'installation" - }, - "choices": ["LOCAL", "REMOTE"], - "default": "LOCAL" - }, - { - "name": "port", - "ask": { - "en": "LOCAL: Choose the listening port of the app", - "fr": "LOCAL: Choisissez le port d'écoute de l'application" - }, - "example": "5050", - "default": "5050" - }, - { - "name": "fork", - "ask": { - "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 4e8373a..0c20a6d 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,37 +1,25 @@ #!/bin/bash + set -eu + app=$YNH_APP_INSTANCE_NAME + +# Source app helpers +. /usr/share/yunohost/helpers # 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_install_dir="/opt/yunohost/$app" + app_data_dir="/home/yunohost.app/$app" # Retrieve arguments -app_method="$(sudo yunohost app setting ${app_id} method)" -app_domain="$(sudo yunohost app setting ${app_id} domain)" + domain=$(ynh_app_setting_get "$app" domain) -# The parameter $1 is the backup directory location -# which will be compressed afterward -app_backup_dir="$1/apps/${app_id}" -sudo mkdir -p $app_backup_dir +# Backup sources + ynh_backup "$app_install_dir" "sources" - -# Backup files if localhost installation -if [[ $app_method == "LOCAL"* ]]; then - - # Backup sources - sudo cp -a $app_install_dir/. $app_backup_dir/sources - - # Backup data - sudo cp -a $app_data_dir/. $app_backup_dir/data +# Backup data + ynh_backup "$app_data_dir" "data" - # Backup daemon config - sudo cp -a /etc/default/$app_id $app_backup_dir/conf/$app_id.default - sudo cp -a /etc/init.d/$app_id $app_backup_dir/conf/$app_id.init - -fi +# Backup daemon + ynh_backup "/etc/systemd/system/$app.service" "$app.service" - -# Copy Nginx and YunoHost parameters to make the script "standalone" -sudo cp -a /etc/yunohost/apps/$app_id/. $app_backup_dir/yunohost -sudo cp -a /etc/nginx/conf.d/$app_domain.d/$app_id.conf $app_backup_dir/nginx.conf \ No newline at end of file +# Copy the conf files + ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" diff --git a/scripts/install b/scripts/install index 79bd3c3..c38eb56 100644 --- a/scripts/install +++ b/scripts/install @@ -1,62 +1,54 @@ #!/bin/bash -#debug commands -#exec > >(tee /tmp/debug-install.log) -#exec 2>&1 + set -eu + app=$YNH_APP_INSTANCE_NAME + source="https://github.com/CouchPotato/CouchPotatoServer" + + +# Source app helpers +. /usr/share/yunohost/helpers # Retrieve arguments -app_domain=$1 -app_path=$2 -app_public=$3 -app_method=$4 -app_port=$5 -app_fork=$6 -app_host=$7 - -# Basic variable declaration -BASEDIR="$(dirname "$(pwd)")" - -# Common variable declaration -app_id=couchpotato -app_user=couchpotato -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" + domain=$YNH_APP_ARG_DOMAIN + path=$YNH_APP_ARG_PATH +# Correct path: puts a / at the start and nothing at the end + if [ "${path:0:1}" != "/" ]; then + path="/$path" + fi + if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then + path="${path:0:${#path}-1}" + fi # Check domain/path availability -sudo yunohost app checkurl $app_domain$app_path -a $app_id -if [[ ! $? -eq 0 ]]; then - exit 1 -fi + sudo yunohost app checkurl "${domain}${path}" -a "$app" \ + || ynh_die "Path not available: ${domain}${path}" +# Destinations definitions + app_install_dir="/opt/yunohost/$app" + app_data_dir="/home/yunohost.app/$app" + app_logs_dir="/var/log/$app" + app_config_file="${app_data_dir}/settings.conf" + app_pid_file="/var/run/$app/$app.pid" + app_python_bin="/usr/bin/python" -# Make install if localhost installation -if [[ $app_method == "LOCAL"* ]]; then +# Install Couchpotato - # Check port availability - sudo yunohost app checkport $app_port - if [[ ! $? -eq 0 ]]; then - exit 1 - fi + # Get first available port + port=5050 + sudo yunohost app checkport $port + while [[ ! $? -eq 0 ]]; do + port=$((port+1)) + sudo yunohost app checkport $port + done + ynh_app_setting_set "$app" port "$port" # Make directories sudo mkdir -p $app_data_dir sudo mkdir -p $app_install_dir # Install latest version of app using the fork - sudo apt-get install -y git-core - sudo git clone $app_fork $app_install_dir + sudo git clone $source $app_install_dir # Install dependencies (using virtualenv) if [[ $(python --version 2>&1) != Python\ 2* ]]; then @@ -67,73 +59,98 @@ if [[ $app_method == "LOCAL"* ]]; then fi # 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" $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 - + id -u $app &>/dev/null || sudo useradd --home-dir $app_install_dir --shell /bin/false $app + + # YunoHost multimedia + # Add yunohost.multimedia directory + wget -qq https://github.com/YunoHost-Apps/yunohost.multimedia/archive/master.zip + unzip -qq master.zip + sudo ./yunohost.multimedia-master/script/ynh_media_build.sh + # Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory + sudo usermod -a -G multimedia $app + # Creates the "Movies" subfolder in "Video" + sudo mkdir -p "/home/yunohost.multimedia/share/Video/Movies" + # Fix permissions + sudo ./yunohost.multimedia-master/script/ynh_media_build.sh + + # Transmission link: Preferred method is direct RPC link. If not available, switch to watchdir. + transmission_rpcurl="" + transmission_rpcpassword="" + transmission_watchdir="" + # Check if Transmission is installed + if [[ -z $(sudo yunohost app list -i -f transmission | grep -v 'apps:') ]]; then + sudo sed -i "s@__RPC__@0@g" ../conf/couchpotato.conf # Disable Transmission RPC + sudo sed -i "s@__BLACKHOLE__@0@g" ../conf/couchpotato.conf # Disable Transmission Watchdir + sudo sed -i "s@__RENAMER__@0@g" ../conf/couchpotato.conf # Disable Renamer + else + echo "Transmission is installed. Trying to link it to CouchPotato..." + # Check if the transmission password is in settings + if [[ -n $(ynh_app_setting_get transmission rpcpassword || true) ]]; then + echo "Transmission will be linked to CouchPotato directly" + transmission_rpcurl="$(ynh_app_setting_get transmission path)transmission" + transmission_rpcpassword=$(ynh_app_setting_get transmission rpcpassword) + sudo sed -i "s@__RPC__@1@g" ../conf/couchpotato.conf # Enable Transmission RPC + sudo sed -i "s@__BLACKHOLE__@0@g" ../conf/couchpotato.conf # Disable Transmission Watchdir + sudo sed -i "s@__RENAMER__@1@g" ../conf/couchpotato.conf # Enable Renamer + # If transmission uses YunoHost multimedia, use its folder for the renamer + else + # Check if transmission has watchdir enabled + if [[ -n $(ynh_app_setting_get transmission watchdir || true) ]]; then + echo "Transmission will be linked to CouchPotato with watchdir" + transmission_watchdir=$(ynh_app_setting_get transmission watchdir) + sudo sed -i "s@__RPC__@0@g" ../conf/couchpotato.conf # Disable Transmission RPC + sudo sed -i "s@__BLACKHOLE__@1@g" ../conf/couchpotato.conf # Enable Transmission Watchdir + sudo sed -i "s@__RENAMER__@1@g" ../conf/couchpotato.conf # Enable Renamer + # If transmission uses YunoHost multimedia, use its folder for the renamer + else + echo "Cannot link Couchpotato to Transmission because Transmission has no RPC password or watchdir available." + sudo sed -i "s@__RPC__@0@g" ../conf/couchpotato.conf # Disable Transmission RPC + sudo sed -i "s@__BLACKHOLE__@0@g" ../conf/couchpotato.conf # Disable Transmission Watchdir + sudo sed -i "s@__RENAMER__@0@g" ../conf/couchpotato.conf # Disable Renamer + fi + fi + fi + # Configure App - 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 + sudo sed -i "s@__RPCURL__@$transmission_rpcurl@g" ../conf/couchpotato.conf + sudo sed -i "s@__RPCPASSWORD__@$transmission_rpcpassword@g" ../conf/couchpotato.conf + sudo sed -i "s@__WATCHDIR__@$transmission_watchdir@g" ../conf/couchpotato.conf + + sudo sed -i "s@__PATH__@$path@g" ../conf/couchpotato.conf + sudo sed -i "s@__PORT__@$port@g" ../conf/couchpotato.conf + sudo sed -i "s@__DATADIR__@$app_data_dir@g" ../conf/couchpotato.conf + + sudo cp -a ../conf/couchpotato.conf $app_config_file # 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 - sudo chown -R $app_user $app_data_dir - sudo chmod +x /etc/init.d/$app_id - sudo chmod +x -R $app_install_dir - 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" - - # Start daemon at boot - sudo update-rc.d $app_id defaults + sudo mkdir -p $app_logs_dir + sudo chown -R $app $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 + + # Permissions + sudo chown -R $app:$app $app_install_dir + sudo chown -R $app:$app $app_data_dir + # Configure service + sed -i "s@__PYTHON__@$app_python_bin@g" ../conf/systemd.service + sed -i "s@__APPDIR__@$app_install_dir@g" ../conf/systemd.service + sed -i "s@__DATADIR__@$app_data_dir@g" ../conf/systemd.service + sed -i "s@__PIDFILE__@$app_pid_file@g" ../conf/systemd.service + sed -i "s@__CONFIGFILE__@$app_config_file@g" ../conf/systemd.service + sed -i "s@__USER__@$app@g" ../conf/systemd.service + sudo cp ../conf/systemd.service /etc/systemd/system/$app.service + sudo systemctl daemon-reload + sudo systemctl enable $app + sudo yunohost service add $app + # Start service - sudo service $app_id start - - # Set proxy host variable - app_host="http://${app_local_host}:${app_port}${app_path%/}" - -fi + sudo yunohost service start $app - -# 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 - # unprotected_uris allows SSO credentials to be passed anyway. - sudo yunohost app setting $app_id unprotected_uris -v "/" -fi - -# 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" +# Configure Nginx and reload + sed -i "s@__PATH__@$path@g" ../conf/nginx.conf + sed -i "s@__PORT__@$port@g" ../conf/nginx.conf + sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf # Reload Nginx and regenerate SSOwat conf -sudo service nginx reload -sudo yunohost app ssowatconf + sudo service nginx reload diff --git a/scripts/remove b/scripts/remove index ef59734..475ba83 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,56 +1,41 @@ #!/bin/bash + #set -eu + app=$YNH_APP_INSTANCE_NAME + +# Source app helpers +. /usr/share/yunohost/helpers # 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="/var/log/${app_id}" + app_install_dir="/opt/yunohost/$app" + app_data_dir="/home/yunohost.app/$app" + app_logs_dir="/var/log/$app" # 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_method == "LOCAL"* ]]; then + domain=$(ynh_app_setting_get "$app" domain) +# Remove files # Kill app and remove from boot - sudo service $app_id stop - sudo killall $app_id - sudo update-rc.d $app_id remove + sudo service $app stop # Delete app user - sudo deluser $app_user + sudo deluser $app # 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 + sudo rm -rf $app_data_dir + sudo rm -rf $app_logs_dir # Remove data - if [[ $keep_data == "No" ]]; then - sudo rm -rf $app_data_dir - fi + sudo rm -rf $app_data_dir - # Remove daemon config - sudo rm -f /etc/init.d/$app_id - sudo rm -f /etc/default/$app_id - sudo rm -rf /var/run/$app_id +# Remove service + sudo systemctl disable $app.service + sudo rm -f /etc/systemd/system/$app.service + sudo systemctl daemon-reload + sudo yunohost service remove $app -fi +# Remove nginx configuration file + sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf - -# 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 app ssowatconf \ No newline at end of file +# Restart services + sudo service nginx reload diff --git a/scripts/restore b/scripts/restore index ace4123..3e2a516 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,56 +1,92 @@ #!/bin/bash + app=$YNH_APP_INSTANCE_NAME + +# Source app helpers +. /usr/share/yunohost/helpers # 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_install_dir="/opt/yunohost/$app" + app_data_dir="/home/yunohost.app/$app" + app_logs_dir="/var/log/$app" + app_python_bin="/usr/bin/python" # Retrieve arguments -app_method="$(sudo yunohost app setting ${app_id} method)" -app_domain="$(sudo yunohost app setting ${app_id} domain)" + domain=$(ynh_app_setting_get "$app" domain) + path=$(ynh_app_setting_get "$app" path) -# The parameter $1 is the uncompressed restore directory location -app_backup_dir="$1/apps/${app_id}" +# Check destination directories + [[ -d $app_install_dir ]] && ynh_die \ + "The destination directory '$app_install_dir' already exists.\ + You should safely delete it before restoring this app." + [[ -d $app_data_dir ]] && ynh_die \ + "The destination directory '$app_data_dir' already exists.\ + You should safely delete it before restoring this app." -# Restore files if localhost installation -if [[ $app_method == "LOCAL"* ]]; then + nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" + [[ -f $nginx_conf ]] && ynh_die \ + "The NGINX configuration already exists at '${nginx_conf}'. + You should safely delete it before restoring this app." - # Kill app - sudo service $app_id stop - sudo killall $app_id + systemd_conf="/etc/systemd/system/${app}.service" + [[ -f $systemd_conf ]] && ynh_die \ + "The Systemd configuration already exists at '${systemd_conf}'. + You should safely delete it before restoring this app." - # Restore sources - sudo cp -a $app_backup_dir/sources/. $app_install_dir +# Kill app if running + sudo systemctl stop $app - # Restore data - sudo cp -a $app_backup_dir/data/. $app_data_dir +# Restore sources + sudo mkdir -p $app_install_dir + sudo cp -a ./sources/. $app_install_dir + +# Restore data + sudo mkdir -p $app_data_dir + sudo cp -a ./data/. $app_data_dir + +# Reinstall dependencies (using virtualenv) + if [[ $(python --version 2>&1) != Python\ 2* ]]; then + sudo apt-get install -y python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python + sudo virtualenv $app_install_dir + sudo bash -c "source $app_install_dir/bin/activate && pip install cheetah" + fi + +# Recreate app user + id -u $app &>/dev/null || sudo useradd --home-dir $app_install_dir --shell /bin/false $app + +# YunoHost multimedia + # Add yunohost.multimedia directory + wget -qq https://github.com/YunoHost-Apps/yunohost.multimedia/archive/master.zip + unzip -qq master.zip + sudo ./yunohost.multimedia-master/script/ynh_media_build.sh + # Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory + sudo usermod -a -G multimedia $app + # Creates the "Movies" subfolder in "Video" + sudo mkdir -p "/home/yunohost.multimedia/share/Video/Movies" + # Fix permissions + sudo ./yunohost.multimedia-master/script/ynh_media_build.sh + +# Redirect logs directory + sudo mkdir -p $app_logs_dir + sudo chown -R $app $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 + +# Permissions + sudo chown -R $app:$app $app_install_dir + sudo chown -R $app:$app $app_data_dir + +# Restore daemon config + sudo cp -a ./$app.service $systemd_conf + sudo systemctl daemon-reload + sudo systemctl enable $app + sudo yunohost service add $app + +# Start service + sudo yunohost service start $app - # Restore daemon config - sudo cp -a $app_backup_dir/conf/$app_id.default /etc/default/$app_id - sudo cp -a $app_backup_dir/conf/$app_id.init /etc/init.d/$app_id - - # Set rights - sudo chown -R $app_user $app_install_dir - sudo chown -R $app_user $app_data_dir - sudo chmod +x /etc/init.d/$app_id - sudo chmod +x -R $app_install_dir - sudo chmod +x -R $app_data_dir - - # Start daemon at boot - sudo update-rc.d $app_id defaults - - # Reload daemon - sudo service $app_id restart - -fi +# Restore Nginx conf + sudo cp -a ./nginx.conf "$nginx_conf" - -# Restore Nginx and YunoHost parameters -sudo cp -a $app_backup_dir/yunohost/. /etc/yunohost/apps/$app_id -sudo cp -a $app_backup_dir/nginx.conf /etc/nginx/conf.d/$app_domain.d/$app_id.conf - -# Reload Nginx and regenerate SSOwat conf -sudo service nginx reload -sudo yunohost app ssowatconf \ No newline at end of file +# Reload Nginx + sudo service nginx reload diff --git a/scripts/upgrade b/scripts/upgrade index e771821..b359c6b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,75 +1,100 @@ #!/bin/bash + app=$YNH_APP_INSTANCE_NAME + source="https://github.com/CouchPotato/CouchPotatoServer" -# Basic variable declaration -BASEDIR="$(dirname "$(pwd)")" +# Backup the current version of the app, restore it if the upgrade fails + EXIT_PROPERLY () { + trap '' EXIT + set +e + sudo yunohost backup restore --ignore-hooks $app-before-upgrade --apps $app --force --quiet # Restore the backup if upgrade failed + ynh_die "Upgrade failed. The app was restored to the way it was before the failed upgrade." + } + if [[ -n $(sudo yunohost backup info $app-before-upgrade || true) ]]; then + sudo yunohost backup delete $app-before-upgrade + fi + sudo yunohost backup create --ignore-hooks --apps $app --name $app-before-upgrade --quiet + set -e + trap EXIT_PROPERLY ERR -# 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="/var/log/${app_id}" -## Sources definitions -app_src_init="$BASEDIR/conf/${app_id}.init" -app_src_nginx_conf="$BASEDIR/conf/nginx.conf" +# Source app helpers +. /usr/share/yunohost/helpers # 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)" + domain=$(ynh_app_setting_get "$app" domain) + path=$(ynh_app_setting_get "$app" path) + port=$(ynh_app_setting_get "$app" port) +# Cancel upgrade if the version is too old + if [[ -n $(ynh_app_setting_get $app method) ]]; then + ynh_die "Your current version is too old and cannot be upgraded.\ + If you had a local install, please remove the app and reinstall it.\ + If you had a remote install, please remove the app and install redirect_ynh for this purpose instead." + fi -# Make upgrade if localhost installation -if [[ $app_method == "LOCAL"* ]]; then +# Destinations definitions + app_install_dir="/opt/yunohost/$app" + app_data_dir="/home/yunohost.app/$app" + app_logs_dir="/var/log/$app" + app_config_file="${app_data_dir}/settings.conf" + app_pid_file="/var/run/$app/$app.pid" + app_python_bin="/usr/bin/python" + +# Upgrade Couchpotato # Kill app - sudo service $app_id stop - sudo killall $app_id - + sudo service $app stop || true + # Upgrade to the latest version of app using the fork cd $app_install_dir && sudo git pull cd - - - # Upgrade dependencies + # Upgrade dependencies + if [[ $(python --version 2>&1) != Python\ 2* ]]; then + app_python_bin=$app_install_dir/bin/python + sudo apt-get install -y python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python + fi + + # YunoHost multimedia + # Add yunohost.multimedia directory + wget -qq https://github.com/YunoHost-Apps/yunohost.multimedia/archive/master.zip + unzip -qq master.zip + sudo ./yunohost.multimedia-master/script/ynh_media_build.sh + # Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory + sudo usermod -a -G multimedia $app + # Creates the "Movies" subfolder in "Video" + sudo mkdir -p "/home/yunohost.multimedia/share/Video/Movies" + # Fix permissions + sudo ./yunohost.multimedia-master/script/ynh_media_build.sh + + # 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 + + # Permissions + sudo chown -R $app:$app $app_install_dir + sudo chown -R $app:$app $app_data_dir - # Update init file - sudo cp -a $app_src_init /etc/init.d/$app_id - - # Set rights - sudo chown -R $app_user $app_install_dir - sudo chmod +x /etc/init.d/$app_id - sudo chmod +x -R $app_install_dir - + # Configure service + sed -i "s@__PYTHON__@$app_python_bin@g" ../conf/systemd.service + sed -i "s@__APPDIR__@$app_install_dir@g" ../conf/systemd.service + sed -i "s@__DATADIR__@$app_data_dir@g" ../conf/systemd.service + sed -i "s@__PIDFILE__@$app_pid_file@g" ../conf/systemd.service + sed -i "s@__CONFIGFILE__@$app_config_file@g" ../conf/systemd.service + sed -i "s@__USER__@$app@g" ../conf/systemd.service + sudo cp ../conf/systemd.service /etc/systemd/system/$app.service + sudo systemctl daemon-reload + sudo systemctl enable $app + sudo yunohost service add $app + # Start service - sudo service $app_id start - -fi + sudo yunohost service start $app - -# 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 +# Configure Nginx and reload + sed -i "s@__PATH__@$path@g" ../conf/nginx.conf + sed -i "s@__PORT__@$port@g" ../conf/nginx.conf + sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf # Reload Nginx and regenerate SSOwat conf -sudo service nginx reload -sudo yunohost app ssowatconf + sudo service nginx reload