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
# Exit if an error occurs during the execution of the script # Build xmlrpc
ynh_abort_if_errors 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
#================================================= # Build libtorrent
# RETRIEVE ARGUMENTS FROM THE MANIFEST 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
domain=$YNH_APP_ARG_DOMAIN # Build rtorrent
path_url=$YNH_APP_ARG_PATH cd /tmp
admin=$YNH_APP_ARG_ADMIN sudo git clone https://github.com/rakshasa/rtorrent.git
is_public=$YNH_APP_ARG_IS_PUBLIC cd rtorrent
language=$YNH_APP_ARG_LANGUAGE sudo git checkout 0.9.6
sudo ./autogen.sh
sudo ./configure --with-xmlrpc-c
sudo make
sudo make install
# This is a multi-instance app, meaning it can be installed several times independently sudo ldconfig
# The id of the app as stated in the manifest is available as $YNH_APP_ID
# 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
#================================================= # Configure nginx
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/flood.conf
#=================================================
# Normalize the url path syntax # Create data dir
path_url=$(ynh_normalize_url_path $path_url) sudo mkdir $data_dir
sudo mkdir $data_dir/watch
sudo mkdir $data_dir/downloads
sudo mkdir $data_dir/.session
# Check web path availability # Create rtorrent user
ynh_webpath_available $domain $path_url sudo useradd -p -m flood
# Register (book) web path
ynh_webpath_register $app $domain $path_url
final_path=/var/www/$app # Add rtorrent config
test ! -e "$final_path" || ynh_die "This path already contains a folder" sudo sed -i "s@DATA_DIR@$data_dir@g" ../sources/rtorrent.rc
sudo cp ../sources/rtorrent.rc /home/flood/.rtorrent.rc
sudo chown -R flood:www-data /home/flood/.rtorrent.rc
#================================================= sudo chown -R flood:www-data $data_dir
# STORE SETTINGS FROM MANIFEST sudo chmod 755 $data_dir
#=================================================
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app language $language
#================================================= # Check port availability
# STANDARD MODIFICATIONS sudo yunohost app checkport 45069
#================================================= if [[ ! $? -eq 0 ]]; then
# FIND AND OPEN A PORT exit 1
#================================================= fi
# Find a free port # Open port in firewall
port=$(ynh_find_port 8095) sudo yunohost firewall allow TCP 45069 > /dev/null 2>&1
# Open this port
sudo yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port
#================================================= # Install nodejs for flood
# INSTALL DEPENDENCIES curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
#================================================= sudo apt-get install -y nodejs
ynh_install_app_dependencies deb1 deb2 # Clone flood
cd /home/flood
git clone https://github.com/jfurrow/flood.git
cp
#================================================= # Launch flood on boot
# CREATE A MYSQL DATABASE sudo cp ../sources/flood.service /etc/systemd/system/flood.service
#================================================= systemctl daemon-reload
# If your app uses a MySQL database, you can use these lines to bootstrap systemctl enable flood.service
# a database, an associated user and save the password in app settings
db_name=$(ynh_sanitize_dbid $app) # Launch rtorrent on boot
ynh_app_setting_set $app db_name $db_name sudo cp ../sources/rtorrent.service /etc/systemd/system/rtorrent.service
ynh_mysql_setup_db $db_name $db_name systemctl daemon-reload
systemctl enable rtorrent.service
#================================================= # Start rtorrent and flood
# DOWNLOAD, CHECK AND UNPACK SOURCE sudo service flood start
#================================================= sudo service rtorrent start
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