1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/flood_ynh.git synced 2024-09-03 18:36:20 +02:00

Add sources + install

This commit is contained in:
Taker 2017-07-17 12:03:11 +02:00
parent edbac5e7b6
commit 62d9e84739
7 changed files with 144 additions and 183 deletions

View file

@ -43,6 +43,16 @@
"example": "/flood", "example": "/flood",
"default": "/flood" "default": "/flood"
}, },
{
"name": "data_dir",
"type": "path",
"ask": {
"en": "Choose a folder to store the downloads",
"fr": "Choisissez un dossier pour sauver les telechargements"
},
"example": "/mnt/disk1/torrents",
"default": "/home/rtorrent"
},
] ]
} }
} }

View file

@ -1,202 +1,114 @@
#!/bin/bash #!/bin/bash
#================================================= # Retrieve arguments
# GENERIC START domain=$1
#================================================= path=$2
# IMPORT GENERIC HELPERS data_dir=$3
#================================================= current_dir=${PWD}
debian_version=$(lsb_release -c -s)
source _common.sh # Check domain/path availability
source /usr/share/yunohost/helpers sudo yunohost app checkurl $domain$path -a flood
if [[ ! $? -eq 0 ]]; then
echo "Error: domain/path not available"
exit 1
fi
#================================================= # Install de dependencies
# MANAGE SCRIPT FAILURE sudo apt-get update
#================================================= apt install build-essential subversion autoconf g++ gcc curl comerr-dev pkg-config cfv libtool libssl-dev libncurses5-dev ncurses-term libsigc++-2.0-dev libcppunit-dev libcurl3 libcurl4-openssl-dev
cd /tmp
wget http://www.deb-multimedia.org/pool/main/d/deb-multimedia-keyring/deb-multimedia-keyring_2015.6.1_all.deb
sudo dpkg -i deb-multimedia-keyring_2015.6.1_all.deb
# Build xmlrpc
cd /tmp
sudo svn checkout http://svn.code.sf.net/p/xmlrpc-c/code/stable xmlrpc-c
cd xmlrpc-c/
sudo ./configure
sudo make
sudo make install
# Exit if an error occurs during the execution of the script # Build libtorrent
ynh_abort_if_errors cd /tmp
sudo git clone https://github.com/rakshasa/libtorrent.git
cd libtorrent
sudo git checkout 0.13.6
sudo ./autogen.sh
sudo ./configure
sudo make
sudo make install
#================================================= # Build rtorrent
# RETRIEVE ARGUMENTS FROM THE MANIFEST cd /tmp
#================================================= sudo git clone https://github.com/rakshasa/rtorrent.git
cd rtorrent
sudo git checkout 0.9.6
sudo ./autogen.sh
sudo ./configure --with-xmlrpc-c
sudo make
sudo make install
domain=$YNH_APP_ARG_DOMAIN sudo ldconfig
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
language=$YNH_APP_ARG_LANGUAGE
# This is a multi-instance app, meaning it can be installed several times independently # Configure nginx
# The id of the app as stated in the manifest is available as $YNH_APP_ID sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/flood.conf
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
# The app instance name is available as $YNH_APP_INSTANCE_NAME
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
# The app instance name is probably what you are interested the most, since this is
# guaranteed to be unique. This is a good unique identifier to define installation path,
# db names, ...
app=$YNH_APP_INSTANCE_NAME
#================================================= # Create data dir
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS sudo mkdir $data_dir
#================================================= sudo mkdir $data_dir/watch
sudo mkdir $data_dir/downloads
sudo mkdir $data_dir/.session
# Normalize the url path syntax # Create rtorrent user
path_url=$(ynh_normalize_url_path $path_url) sudo useradd -p -m flood
# Check web path availability # Add rtorrent config
ynh_webpath_available $domain $path_url sudo sed -i "s@DATA_DIR@$data_dir@g" ../sources/rtorrent.rc
# Register (book) web path sudo cp ../sources/rtorrent.rc /home/flood/.rtorrent.rc
ynh_webpath_register $app $domain $path_url sudo chown -R flood:www-data /home/flood/.rtorrent.rc
final_path=/var/www/$app sudo chown -R flood:www-data $data_dir
test ! -e "$final_path" || ynh_die "This path already contains a folder" sudo chmod 755 $data_dir
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set $app domain $domain # Check port availability
ynh_app_setting_set $app path $path_url sudo yunohost app checkport 45069
ynh_app_setting_set $app admin $admin if [[ ! $? -eq 0 ]]; then
ynh_app_setting_set $app is_public $is_public exit 1
ynh_app_setting_set $app language $language fi
#================================================= # Open port in firewall
# STANDARD MODIFICATIONS sudo yunohost firewall allow TCP 45069 > /dev/null 2>&1
#=================================================
# FIND AND OPEN A PORT
#=================================================
# Find a free port # Install nodejs for flood
port=$(ynh_find_port 8095) curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
# Open this port sudo apt-get install -y nodejs
sudo yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port
#================================================= # Clone flood
# INSTALL DEPENDENCIES cd /home/flood
#================================================= git clone https://github.com/jfurrow/flood.git
cp
ynh_install_app_dependencies deb1 deb2 # Launch flood on boot
sudo cp ../sources/flood.service /etc/systemd/system/flood.service
systemctl daemon-reload
systemctl enable flood.service
#================================================= # Launch rtorrent on boot
# CREATE A MYSQL DATABASE sudo cp ../sources/rtorrent.service /etc/systemd/system/rtorrent.service
#================================================= systemctl daemon-reload
# If your app uses a MySQL database, you can use these lines to bootstrap systemctl enable rtorrent.service
# a database, an associated user and save the password in app settings
db_name=$(ynh_sanitize_dbid $app) # Start rtorrent and flood
ynh_app_setting_set $app db_name $db_name sudo service flood start
ynh_mysql_setup_db $db_name $db_name sudo service rtorrent start
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_app_setting_set $app final_path $final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
# Create a dedicated php-fpm config
ynh_fpm_config
#=================================================
# SPECIFIC SETUP
#=================================================
# ...
#=================================================
#=================================================
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
ynh_systemd_config
#=================================================
# SETUP APPLICATION WITH CURL
#=================================================
# Set right permissions for curl install
sudo chown -R $app: $final_path
# Set the app as temporarily public for curl call
ynh_app_setting_set $app unprotected_uris "/"
# Reload SSOwat config
sudo yunohost app ssowatconf sudo yunohost app ssowatconf
sudo service nginx reload
# Reload Nginx # Save config
sudo systemctl reload nginx sudo yunohost app setting flood data_dir -v $data_dir
sudo yunohost app setting flood path -v $path
# Installation with curl # Register the service on yunohost
ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" sudo yunohost service add rtorrent
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/CONFIG_FILE"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
sudo chown -R root: $final_path
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
sudo yunohost service add NAME_INIT.D --log "/var/log/FILE.log"
#=================================================
# SETUP SSOWAT
#=================================================
if [ $is_public -eq 0 ]
then # Remove the public access
ynh_app_setting_delete $app skipped_uris
fi
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/"
fi
#=================================================
# RELOAD NGINX
#=================================================
sudo systemctl reload nginx

View file

@ -1,2 +0,0 @@
*~
*.sw[op]

11
sources/flood.service Normal file
View file

@ -0,0 +1,11 @@
[Unit]
Description=Flood rTorrent Web UI
After=network.target
[Service]
WorkingDirectory=/home/flood
ExecStart=/usr/bin/npm start --production /home/flood
User=flood
[Install]
WantedBy=multi-user.target

View file

@ -1,2 +0,0 @@
*~
*.sw[op]

18
sources/rtorrent.rc Normal file
View file

@ -0,0 +1,18 @@
scgi_port = 127.0.0.1:5000
encoding_list = UTF-8
port_range = 45069-45069
port_random = no
check_hash = no
directory = DATA_DIR/downloads
session = DATA_DIR/.session
encryption = allow_incoming, try_outgoing, enable_retry
schedule = watch_directory,1,1,"load_start=DATA_DIR/watch/*.torrent"
schedule = untied_directory,5,5,"stop_untied=DATA_DIR/watch/*.torrent"
use_udp_trackers = yes
dht = off
peer_exchange = no
min_peers = 40
max_peers = 100
min_peers_seed = 10
max_peers_seed = 50
max_uploads = 15

14
sources/rtorrent.service Normal file
View file

@ -0,0 +1,14 @@
[Unit]
Description=rTorrent
After=network.target
[Service]
User=flood
Type=forking
KillMode=none
ExecStart=/usr/bin/screen -d -m -fa -S rtorrent /usr/local/bin/rtorrent
ExecStop=/usr/bin/killall -w -s 2 /usr/local/bin/rtorrent
WorkingDirectory=%h
[Install]
WantedBy=default.target