1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/couchpotato_ynh.git synced 2024-09-03 18:16:22 +02:00

Switch to ynh_install_python

This commit is contained in:
yalh76 2020-06-22 05:35:15 +02:00
parent d8122a9fc8
commit 6bcbfb9dcc
10 changed files with 282 additions and 71 deletions

View file

@ -1,6 +0,0 @@
SOURCE_URL=https://github.com/YunoHost-Apps/yunohost.multimedia/archive/v1.2.tar.gz
SOURCE_SUM=7dfc07e32d7842f87274ef780cb9757a7679573cbbeb095c5f86ef76806f5d95
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=

View file

@ -1,6 +0,0 @@
SOURCE_URL=https://github.com/saghul/pythonz/archive/9067f35e0253b015eb51b8a4d60c0bd1a06dcc83.tar.gz
SOURCE_SUM=ce9eb5400fff81e4877e04dd7166c764d8adc999d9ca6b06ce933ee9375b8652
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=

View file

@ -3,10 +3,12 @@ Description=CouchPotato application instance
After=network.target After=network.target
[Service] [Service]
ExecStart=__FINALPATH__/ve2/bin/python __FINALPATH__/CouchPotato.py --quiet --pid_file=/var/run/__APP__/__APP__.pid --data_dir=__APP_DATA_DIR__ --config_file=__FINALPATH__/settings.conf
Type=simple Type=simple
User=__APP__ User=__APP__
Group=__APP__ Group=__APP__
WorkingDirectory=__FINALPATH__/
ExecStart=/opt/pyenv/versions/__APP__/bin/python __FINALPATH__/CouchPotato.py --quiet --pid_file=/var/run/__APP__/__APP__.pid --data_dir=__APP_DATA_DIR__ --config_file=__FINALPATH__/settings.conf
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -5,9 +5,10 @@
#================================================= #=================================================
# dependencies used by the app # dependencies used by the app
pkg_dependencies="python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python build-essential zlib1g-dev libbz2-dev libssl-dev libreadline-dev libncurses5-dev libsqlite3-dev libgdbm-dev libdb-dev libexpat-dev libpcap-dev liblzma-dev libpcre3-dev libffi-dev" pkg_dependencies=""
#python-pip python-virtualenv python-dev uwsgi uwsgi-plugin-python
python_version=2.7.2 PHYTON_VERSION=2.7.18
#================================================= #=================================================
# PERSONAL HELPERS # PERSONAL HELPERS

View file

@ -7,6 +7,8 @@
#================================================= #=================================================
source _common.sh source _common.sh
source ynh_install_python
source ynh_multimedia_3
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -14,6 +16,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
read -p "key"
true true
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
@ -36,9 +39,6 @@ ynh_script_progression --message="Validating installation parameters..."
final_path=/opt/yunohost/$app final_path=/opt/yunohost/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder" test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
multimedia_final_path=/opt/yunohost/${app}_multimedia
test ! -e "$multimedia_final_path" || ynh_die --message="This path already contains a folder"
app_data_dir=/home/yunohost.app/$app app_data_dir=/home/yunohost.app/$app
test ! -e "$app_data_dir" || ynh_die --message="This path already contains a folder" test ! -e "$app_data_dir" || ynh_die --message="This path already contains a folder"
@ -52,7 +52,6 @@ ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=multimedia_final_path --value=$multimedia_final_path
ynh_app_setting_set --app=$app --key=app_data_dir --value=$app_data_dir ynh_app_setting_set --app=$app --key=app_data_dir --value=$app_data_dir
#================================================= #=================================================
@ -115,22 +114,6 @@ ynh_script_progression --message="Make data directory..."
# Make directories # Make directories
mkdir -p $app_data_dir mkdir -p $app_data_dir
#=================================================
# INSTALL PYTHONZ TO GET PYTHON
#=================================================
ynh_print_info --message="Installing Python..."
# Get pythonz
# curl -kL https://raw.githubusercontent.com/saghul/pythonz/master/pythonz-install
# ./pythonz-install
ynh_setup_source --dest_dir="$final_path/.pythonz" --source_id=pythonz
export PYTHONZ_ROOT="$final_path/.pythonz"
# Then install it
python $final_path/.pythonz/pythonz_install.py
# Install Python
$final_path/.pythonz/bin/pythonz install $python_version
#================================================= #=================================================
# BUILD COUCHPOTATO # BUILD COUCHPOTATO
#================================================= #=================================================
@ -139,10 +122,12 @@ ynh_script_progression --message="Building CouchPotato..."
# Set permissions to app files # Set permissions to app files
chown -R "$app": "$final_path" chown -R "$app": "$final_path"
pushd $final_path/ ynh_install_python --python_version=$PHYTON_VERSION
virtualenv -p $($final_path/.pythonz/bin/pythonz locate $python_version) ve2
ve2/bin/pip install --upgrade pyopenssl pushd $final_path
ve2/bin/pip install cheetah pyenv virtualenv $PHYTON_VERSION $app
/opt/pyenv/versions/$app/bin/pip install --upgrade pyopenssl
/opt/pyenv/versions/$app/bin/pip install cheetah
popd popd
#================================================= #=================================================
@ -150,17 +135,16 @@ popd
#================================================= #=================================================
ynh_script_progression --message="Install YunoHost multimedia..." ynh_script_progression --message="Install YunoHost multimedia..."
ynh_setup_source --dest_dir="$multimedia_final_path" -source_id=multimedia ynh_multimedia_build_main_dir
$multimedia_final_path/script/ynh_media_build.sh
# Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory # Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory
usermod -a -G multimedia $app ynh_multimedia_addaccess $app
# Creates the "Movies" subfolder in "Video" # Creates the "Movies" subfolder in "Video"
mkdir -p "/home/yunohost.multimedia/share/Video/Movies" mkdir -p "/home/yunohost.multimedia/share/Video/Movies"
# Fix permissions # Fix permissions
$multimedia_final_path/script/ynh_media_build.sh /home/yunohost.multimedia/ynh_media_build.sh
#================================================= #=================================================
# CONFIGURE TRANSMISSION # CONFIGURE TRANSMISSION
@ -219,8 +203,8 @@ ynh_replace_string --match_string="__RPCURL__" --replace_string="$transmission_r
ynh_replace_string --match_string="__RPCPASSWORD__" --replace_string="$transmission_rpcpassword" --target_file="../conf/couchpotato.conf" ynh_replace_string --match_string="__RPCPASSWORD__" --replace_string="$transmission_rpcpassword" --target_file="../conf/couchpotato.conf"
ynh_replace_string --match_string="__WATCHDIR__" --replace_string="$transmission_watchdir" --target_file="../conf/couchpotato.conf" ynh_replace_string --match_string="__WATCHDIR__" --replace_string="$transmission_watchdir" --target_file="../conf/couchpotato.conf"
ynh_replace_string --match_string="__PATH__" --replace_string="$path" --target_file="../conf/couchpotato.conf" ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="../conf/couchpotato.conf"
ynh_replace_string --match_string="__PORT__" --replace_string="$port@" --target_file="../conf/couchpotato.conf" ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/couchpotato.conf"
ynh_replace_string --match_string="__DATADIR__" --replace_string="$app_data_dir" --target_file="../conf/couchpotato.conf" ynh_replace_string --match_string="__DATADIR__" --replace_string="$app_data_dir" --target_file="../conf/couchpotato.conf"
cp -a ../conf/couchpotato.conf $app_config_file cp -a ../conf/couchpotato.conf $app_config_file

View file

@ -7,6 +7,7 @@
#================================================= #=================================================
source _common.sh source _common.sh
source ynh_install_python
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -48,6 +49,7 @@ ynh_remove_systemd_config
ynh_script_progression --message="Removing dependencies..." ynh_script_progression --message="Removing dependencies..."
# Remove metapackage and its dependencies # Remove metapackage and its dependencies
ynh_remove_python
ynh_remove_app_dependencies ynh_remove_app_dependencies
#================================================= #=================================================

View file

@ -8,6 +8,8 @@
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source ../settings/scripts/ynh_install_pyhon
source ../settings/scripts/ynh_multimedia_3
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -31,7 +33,6 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path) path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
app_data_dir=$(ynh_app_setting_get --app=$app --key=app_data_dir) app_data_dir=$(ynh_app_setting_get --app=$app --key=app_data_dir)
multimedia_final_path=$(ynh_app_setting_get --app=$app --key=multimedia_final_path)
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
@ -88,6 +89,22 @@ ynh_script_progression --message="Reinstalling dependencies..."
# Define and install dependencies # Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies ynh_install_app_dependencies $pkg_dependencies
#=================================================
# BUILD COUCHPOTATO
#=================================================
ynh_script_progression --message="Building CouchPotato..."
# Set permissions to app files
chown -R "$app": "$final_path"
ynh_install_python --python_version=$PHYTON_VERSION
pushd $final_path
pyenv virtualenv $PHYTON_VERSION $app
/opt/pyenv/versions/$app/bin/pip install --upgrade pyopenssl
/opt/pyenv/versions/$app/bin/pip install cheetah
popd
#================================================= #=================================================
# RESTORE THE DATA DIRECTORY # RESTORE THE DATA DIRECTORY
#================================================= #=================================================
@ -100,17 +117,16 @@ ynh_restore_file --origin_path="$app_data_dir"
#================================================= #=================================================
ynh_script_progression --message="Install YunoHost multimedia..." ynh_script_progression --message="Install YunoHost multimedia..."
ynh_setup_source --dest_dir="$multimedia_final_path" -source_id=multimedia ynh_multimedia_build_main_dir
$multimedia_final_path/script/ynh_media_build.sh
# Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory # Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory
usermod -a -G multimedia $app ynh_multimedia_addaccess $app
# Creates the "Movies" subfolder in "Video" # Creates the "Movies" subfolder in "Video"
mkdir -p "/home/yunohost.multimedia/share/Video/Movies" mkdir -p "/home/yunohost.multimedia/share/Video/Movies"
# Fix permissions # Fix permissions
$multimedia_final_path/script/ynh_media_build.sh /home/yunohost.multimedia/ynh_media_build.sh
#================================================= #=================================================
# CONFIGURE LOGS # CONFIGURE LOGS

View file

@ -7,6 +7,8 @@
#================================================= #=================================================
source _common.sh source _common.sh
source ynh_install_python
source ynh_multimedia_3
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -139,24 +141,12 @@ ynh_script_progression --message="Building CouchPotato..."
# Set permissions to app files # Set permissions to app files
chown -R "$app": "$final_path" chown -R "$app": "$final_path"
pushd $final_path/ ynh_install_python --python_version=$PHYTON_VERSION
virtualenv -p $($final_path/.pythonz/bin/pythonz locate $python_version) ve2
ve2/bin/pip install --upgrade pyopenssl
ve2/bin/pip install cheetah
popd
#================================================= pushd $final_path
# BUILD COUCHPOTATO pyenv virtualenv $PHYTON_VERSION $app
#================================================= /opt/pyenv/versions/$app/bin/pip install --upgrade pyopenssl
ynh_script_progression --message="Building CouchPotato..." /opt/pyenv/versions/$app/bin/pip install cheetah
# Set permissions to app files
chown -R "$app": "$final_path"
pushd $final_path/
virtualenv -p $($final_path/.pythonz/bin/pythonz locate $python_version) ve2
ve2/bin/pip install --upgrade pyopenssl
ve2/bin/pip install cheetah
popd popd
#================================================= #=================================================
@ -164,17 +154,16 @@ popd
#================================================= #=================================================
ynh_script_progression --message="Install YunoHost multimedia..." ynh_script_progression --message="Install YunoHost multimedia..."
ynh_setup_source --dest_dir="$multimedia_final_path" -source_id=multimedia ynh_multimedia_build_main_dir
$multimedia_final_path/script/ynh_media_build.sh
# Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory # Give write access to the yunohost.multimedia directory so that Couchpotato can move Movies to the Movie directory
usermod -a -G multimedia $app ynh_multimedia_addaccess $app
# Creates the "Movies" subfolder in "Video" # Creates the "Movies" subfolder in "Video"
mkdir -p "/home/yunohost.multimedia/share/Video/Movies" mkdir -p "/home/yunohost.multimedia/share/Video/Movies"
# Fix permissions # Fix permissions
$multimedia_final_path/script/ynh_media_build.sh /home/yunohost.multimedia/ynh_media_build.sh
#================================================= #=================================================
# CONFIGURE LOGS # CONFIGURE LOGS

151
scripts/ynh_install_python Normal file
View file

@ -0,0 +1,151 @@
#!/bin/bash
# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args
pyenv_install_dir="/opt/pyenv"
# PYENV_ROOT is the directory of pyenv, it needs to be loaded as a environment variable.
export PYENV_ROOT="$pyenv_install_dir"
# Required dependencies
pyenv_dependencies="build-essential libssl1.0-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git"
# Install python version management
#
# [internal]
#
# usage: ynh_install_pyenv
ynh_install_pyenv () {
echo "Installation of pyenv - python version management" >&2
# Build an app.src for pyenv
mkdir -p "../conf"
echo "SOURCE_URL=https://github.com/pyenv/pyenv/archive/v1.2.19.tar.gz
SOURCE_SUM=e93466735ac9c34d68b7d5d71f32c16a2b4b1a6a1adffb85acc4126a3398b9d0" > "../conf/pyenv.src"
# Download and extract pyenv
ynh_setup_source "$pyenv_install_dir" pyenv
# Build an app.src for pyenv-virtualenv
mkdir -p "../conf"
echo "SOURCE_URL=https://github.com/pyenv/pyenv-virtualenv/archive/v1.1.5.tar.gz
SOURCE_SUM=27ae3de027a6f6dccdca4085225512e559c6b94b31625bd2b357a18890a1e618" > "../conf/pyenv-virtualenv.src"
# Download and extract pyenv-virtualenv
ynh_setup_source "$pyenv_install_dir/plugins/pyenv-virtualenv" pyenv-virtualenv
(cd $pyenv_install_dir
./src/configure && make -C src)
# Create shims directory if needed
if [ ! -d $pyenv_install_dir/shims ] ; then
mkdir $pyenv_install_dir/shims
fi
}
# Install a specific version of python
#
# ynh_install_python will install the version of python provided as argument by using pyenv.
#
# pyenv (python version management) stores the target python version in a .python_version file created in the target folder (using pyenv local <version>)
# It then uses that information for every python user that uses pyenv provided python command
#
# This helper creates a /etc/profile.d/pyenv.sh that configures PATH environment for pyenv
# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin)
#
# Don't forget to execute python-dependent command in a login environment
# (e.g. sudo --login option)
# When not possible (e.g. in systemd service definition), please use direct path
# to pyenv shims (e.g. $PYENV_ROOT/shims/bundle)
#
# usage: ynh_install_python python_version user
# | arg: -v, --python_version= - Version of python to install.
# If possible, prefer to use major version number (e.g. 8 instead of 8.10.0).
# The crontab will handle the update of minor versions when needed.
ynh_install_python () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [v]=python_version= )
# Use pyenv, https://github.com/pyenv/pyenv to manage the python versions
local python_version
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
# Create $pyenv_install_dir
mkdir -p "$pyenv_install_dir/plugins/pyenv-virtualenv"
# Load pyenv path in PATH
CLEAR_PATH="$pyenv_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of python prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Move an existing python binary, to avoid to block pyenv
#test -x /usr/bin/python && mv /usr/bin/python /usr/bin/python_pyenv
# If pyenv is not previously setup, install it
if ! type pyenv > /dev/null 2>&1
then
ynh_install_pyenv
elif dpkg --compare-versions "$($pyenv_install_dir/bin/pyenv --version | cut -d" " -f2)" lt "1.2.19"
then
ynh_install_pyenv
elif dpkg --compare-versions "$($pyenv_install_dir/plugins/pyenv-virtualenv/bin/pyenv-virtualenv --version | cut -d" " -f2)" lt "1.1.5"
then
ynh_install_pyenv
fi
# Restore /usr/local/bin in PATH (if needed)
PATH=$CLEAR_PATH
# And replace the old python binary
# test -x /usr/bin/python_pyenv && mv /usr/bin/python_pyenv /usr/bin/python
# Install required dependencies
ynh_add_app_dependencies --package="$pyenv_dependencies"
# Install the requested version of python
pyenv install --skip-existing $python_version
# Store the ID of this app and the version of python requested for it
echo "$YNH_APP_ID:$python_version" | tee --append "$pyenv_install_dir/ynh_app_version"
# Store python_version into the config of this app
ynh_app_setting_set --app=$app --key=python_version --value=$python_version
# Set environment for python users
echo "#pyenv
export PYENV_ROOT=$pyenv_install_dir
export PATH=\"$pyenv_install_dir/bin:$PATH\"
eval \"\$(pyenv init -)\"
#pyenv" > /etc/profile.d/pyenv.sh
# Load the right environment for the Installation
eval "$(pyenv init -)"
(cd $final_path
pyenv local $python_version)
}
# Remove the version of python used by the app.
#
# This helper will check if another app uses the same version of python,
# if not, this version of python will be removed.
# If no other app uses python, pyenv will be also removed.
#
# usage: ynh_remove_python
ynh_remove_python () {
python_version=$(ynh_app_setting_get --app=$app --key=python_version)
# Remove the line for this app
sed --in-place "/$YNH_APP_ID:$python_version/d" "$pyenv_install_dir/ynh_app_version"
# If no other app uses this version of python, remove it.
if ! grep --quiet "$python_version" "$pyenv_install_dir/ynh_app_version"
then
$pyenv_install_dir/bin/pyenv uninstall --force $python_version
fi
# Remove pyenv environment configuration
rm /etc/profile.d/pyenv.sh
# If no other app uses pyenv, remove pyenv and dedicated group
if [ ! -s "$pyenv_install_dir/ynh_app_version" ]
then
ynh_secure_remove --file="$pyenv_install_dir"
fi
}

78
scripts/ynh_multimedia_3 Normal file
View file

@ -0,0 +1,78 @@
#!/bin/bash
# Install or update the main directory yunohost.multimedia
#
# usage: ynh_multimedia_build_main_dir
ynh_multimedia_build_main_dir () {
local ynh_media_release="v1.2"
local checksum="806a827ba1902d6911095602a9221181"
# Download yunohost.multimedia scripts
wget -nv https://github.com/YunoHost-Apps/yunohost.multimedia/archive/${ynh_media_release}.tar.gz
# Check the control sum
echo "${checksum} ${ynh_media_release}.tar.gz" | md5sum -c --status \
|| ynh_die "Corrupt source"
# Check if the package acl is installed. Or install it.
ynh_package_is_installed 'acl' \
|| ynh_package_install acl
# Extract
mkdir yunohost.multimedia-master
tar -xf ${ynh_media_release}.tar.gz -C yunohost.multimedia-master --strip-components 1
./yunohost.multimedia-master/script/ynh_media_build.sh
}
# Add a directory in yunohost.multimedia
# This "directory" will be a symbolic link to a existing directory.
#
# usage: ynh_multimedia_addfolder "Source directory" "Destination directory"
#
# | arg: -s, --source_dir= - Source directory - The real directory which contains your medias.
# | arg: -d, --dest_dir= - Destination directory - The name and the place of the symbolic link, relative to "/home/yunohost.multimedia"
ynh_multimedia_addfolder () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [s]=source_dir= [d]=dest_dir= )
local source_dir
local dest_dir
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
./yunohost.multimedia-master/script/ynh_media_addfolder.sh --source="$source_dir" --dest="$dest_dir"
}
# Move a directory in yunohost.multimedia, and replace by a symbolic link
#
# usage: ynh_multimedia_movefolder "Source directory" "Destination directory"
#
# | arg: -s, --source_dir= - Source directory - The real directory which contains your medias.
# It will be moved to "Destination directory"
# A symbolic link will replace it.
# | arg: -d, --dest_dir= - Destination directory - The new name and place of the directory, relative to "/home/yunohost.multimedia"
ynh_multimedia_movefolder () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [s]=source_dir= [d]=dest_dir= )
local source_dir
local dest_dir
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
./yunohost.multimedia-master/script/ynh_media_addfolder.sh --inv --source="$source_dir" --dest="$dest_dir"
}
# Allow an user to have an write authorisation in multimedia directories
#
# usage: ynh_multimedia_addaccess user_name
#
# | arg: -u, --user_name= - The name of the user which gain this access.
ynh_multimedia_addaccess () {
# Declare an array to define the options of this helper.
declare -Ar args_array=( [u]=user_name=)
local user_name
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
groupadd -f multimedia
usermod -a -G multimedia $user_name
}