Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[autopatch] Automatic patch attempt for helpers 2.1 #40

Open
wants to merge 2 commits into
base: testing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*~
*.sw[op]
.DS_Store
3 changes: 2 additions & 1 deletion manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ admindoc = "https://wiki.bazarr.media"
code = "https://github.com/morpheus65535/bazarr"

[integration]
yunohost = ">= 11.2"
yunohost = ">= 11.2.30"
helpers_version = "2.1"
architectures = "all"
multi_instance = true
ldap = false
Expand Down
14 changes: 1 addition & 13 deletions scripts/_common.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

#=================================================
# COMMON VARIABLES
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================

python_version="3.7"
Expand All @@ -10,10 +10,6 @@ python_major_version=$(echo $python_version | cut -d. -f1)
pkg_dependencies+=" python${python_major_version}-libxml2 python${python_major_version}-lxml"
pkg_dependencies+=" python${python_major_version}-dev python${python_major_version}-venv"

#=================================================
# PERSONAL HELPERS
#=================================================

detect_and_read_radarr_and_sonarr_settings() {

if ls /etc/yunohost/apps | grep -q "radarr"; then
Expand Down Expand Up @@ -41,11 +37,3 @@ else
fi

}

#=================================================
# EXPERIMENTAL HELPERS
#=================================================

#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
32 changes: 6 additions & 26 deletions scripts/backup
Original file line number Diff line number Diff line change
@@ -1,48 +1,28 @@
#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers

#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
ynh_print_info "Declaring files to be backed up..."

#=================================================
# BACKUP THE APP MAIN DIR
#=================================================

ynh_backup --src_path="$install_dir"
ynh_backup "$install_dir"

#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================

ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"

#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================

ynh_backup --src_path="/etc/logrotate.d/$app"

#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup "/etc/logrotate.d/$app"

ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup "/etc/systemd/system/$app.service"

#=================================================
# END OF SCRIPT
#=================================================

ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
32 changes: 10 additions & 22 deletions scripts/change_url
Original file line number Diff line number Diff line change
@@ -1,55 +1,43 @@
#!/bin/bash

#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_script_progression "Stopping $app's systemd service..."

ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
ynh_systemctl --service=$app --action="stop"

#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
ynh_script_progression "Updating NGINX web server configuration..."

ynh_change_url_nginx_config
ynh_config_change_url_nginx

#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# MODIFY THE CONFIGURATION FILE
#=================================================
ynh_script_progression --message="Updating the configuration file..." --weight=1
ynh_script_progression "Updating the configuration file..."

if [ $change_path -eq 1 ]
then
ynh_replace_string --match_string="base_url: .*" --replace_string="base_url: ${new_path:-/}" --target_file="$install_dir/data/config/config.yaml"
ynh_replace --match="base_url: .*" --replace="base_url: ${new_path:-/}" --file="$install_dir/data/config/config.yaml"

ynh_store_file_checksum --file="$install_dir/data/config/config.yaml"
ynh_store_file_checksum "$install_dir/data/config/config.yaml"
fi

#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."

ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="BAZARR is started" --timeout 30
ynh_systemctl --service=$app --action="start" --wait_until="BAZARR is started" --timeout 30

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Change of URL completed for $app" --last
ynh_script_progression "Change of URL completed for $app"
55 changes: 23 additions & 32 deletions scripts/install
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=2
ynh_script_progression "Setting up source files..."

# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"

chmod -R o-rwx "$install_dir"
chown -R $app: "$install_dir"

#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app: "$install_dir"
# Prepare log path
log_path="/var/log/$app"
mkdir -p "$log_path"
Expand All @@ -30,95 +23,93 @@ chown -R $app: "$log_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
ynh_script_progression "Configuring NGINX web server..."

# Create a dedicated NGINX config
ynh_add_nginx_config
ynh_config_add_nginx

#=================================================
# SPECIFIC SETUP
#=================================================
# PREPARE PYTHON ENVIRONMENT AND INSTALL
#=================================================
ynh_script_progression --message="Installing Bazarr and its dependencies..." --weight=5
ynh_script_progression "Installing Bazarr and its dependencies..."

pushd $install_dir
# Initialize virtual environment
ynh_exec_as $app python${python_major_version} -m venv venv
ynh_exec_as_app python${python_major_version} -m venv venv

ynh_exec_as $app $install_dir/venv/bin/pip install -r "$install_dir/requirements.txt"
ynh_exec_as_app $install_dir/venv/bin/pip install -r "$install_dir/requirements.txt"
popd

#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1
ynh_script_progression "Configuring $app's systemd service..."

env_path="$install_dir/venv/bin:$PATH"

# Create a dedicated systemd config
ynh_add_systemd_config
ynh_config_add_systemd

#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
ynh_script_progression "Adding $app's configuration..."

# Letting Bazarr deploy itself
ynh_systemd_action --service_name=$app --action="start" --line_match="BAZARR is started" --log_path="/var/log/$app/$app.log" --timeout=60
ynh_systemctl --service=$app --action="start" --wait_until="BAZARR is started" --timeout=60
sleep 3
ynh_systemd_action --service_name=$app --action="stop" --line_match="Bazarr exited" --log_path="/var/log/$app/$app.log" --timeout=20
ynh_systemctl --service=$app --action="stop" --wait_until="Bazarr exited" --timeout=20

detect_and_read_radarr_and_sonarr_settings

flask_key=$(ynh_string_random --length=32)
ynh_app_setting_set --app=$app --key=flask_key --value=$flask_key
ynh_app_setting_set --key=flask_key --value=$flask_key

api_key=$(ynh_string_random --length=32)
ynh_app_setting_set --app=$app --key=api_key --value=$api_key
ynh_app_setting_set --key=api_key --value=$api_key

ynh_add_config --template="config.yaml" --destination="$install_dir/data/config/config.yaml"
ynh_config_add --template="config.yaml" --destination="$install_dir/data/config/config.yaml"

chmod 660 "$install_dir/data/config/config.yaml"
chown $app: "$install_dir/data/config/config.yaml"

#=================================================
# YUNOHOST MULTIMEDIA INTEGRATION
#=================================================
ynh_script_progression --message="Adding multimedia directories..." --weight=1
ynh_script_progression "Adding multimedia directories..."

# Build YunoHost multimedia directories
ynh_multimedia_build_main_dir
# Enable writing into these directories
ynh_multimedia_addaccess $app

#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1
ynh_script_progression "Configuring log rotation..."

# Use logrotate to manage application logfile(s)
ynh_use_logrotate
ynh_config_add_logrotate

#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
ynh_script_progression "Integrating service in YunoHost..."

yunohost service add $app --description="Subtitle downloader for Radarr and Sonarr" --log="/var/log/$app/$app.log"

#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."

# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemctl --service=$app --action="start"

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"
24 changes: 5 additions & 19 deletions scripts/remove
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================

# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service integration..." --weight=1
if ynh_hide_warnings yunohost service status $app >/dev/null; then
yunohost service remove $app
fi

# Remove the dedicated systemd config
ynh_remove_systemd_config
ynh_config_remove_systemd

# Remove the app-specific logrotate config
ynh_remove_logrotate
ynh_config_remove_logrotate

# Remove the dedicated NGINX config
ynh_remove_nginx_config
ynh_config_remove_nginx

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"
Loading