1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mopidy_ynh.git synced 2024-09-03 19:46:21 +02:00
mopidy_ynh/scripts/install
2024-01-14 23:00:44 +01:00

141 lines
4.9 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# INITIALIZE AND STORE SETTINGS
#=================================================
mpd_state="${boolstr[mpd_ext]}"
ynh_app_setting_set --app="$app" --key=mpd_state --value="$mpd_state"
#=================================================
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
#=================================================
# INSTALL MOPIDY IN PYTHON ENVIRONMENT
#=================================================
ynh_script_progression --message="Install in Python environment..." --weight=30
_mopidy_install
# patch -u $install_dir/venv/lib/python$python_version/site-packages/mopidy/__main__.py -i ../sources/patches/__main__.patch --forward
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
chmod -R o-rwx "$data_dir"
chown -R "$app:www-data" "$data_dir"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..."
ynh_add_config --template="app.conf" --destination="$install_dir/$app.conf"
chmod 400 "$install_dir/$app.conf"
chown "$app:$app" "$install_dir/$app.conf"
#=================================================
# PROVIDE ADDITIONAL SHELL COMMAND
#=================================================
ynh_script_progression --message="Provide additional shell command..."
ynh_add_config --template="../sources/extra_files/mopidyctl" --destination="$cmd_file"
chmod +x "$cmd_file"
#=================================================
# SPECIFIC SETUP
#=================================================
# BUILD MULTIMEDIA
#=================================================
ynh_script_progression --message="Building multimedia directory..."
ynh_multimedia_build_main_dir # /home/yunohost.multimedia
#=================================================
# PROVIDE EXAMPLES
#=================================================
# provide example m3u-playlist
mkdir -p "$data_dir/data/m3u/"
cp -a ../sources/extra_files/radio_international.m3u "$data_dir/data/m3u/radio_international.m3u"
#provide example podcasts
mkdir -p "$data_dir/data/podcast"
cp -a ../sources/extra_files/bbc.opml "$data_dir/data/podcast/bbc.opml"
#provide example local music file
if [ "$(ls -A "$media_dir" 2> /dev/null)" == "" ]; then # copy example.mp3 to mediadir if empty (for test purpose)
cp -a ../sources/extra_files/Tryad_Beauty.mp3 "$media_dir"
fi
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config
if [ "$mpd_ext" -eq 1 ]; then
yunohost service add "$app" --description="Mopidy music server" --needs_exposed_ports="$port_mpd"
else
yunohost service add "$app" --description="Mopidy music server"
fi
#=================================================
# OPEN PORT
#=================================================
if [ "$mpd_ext" -eq 1 ]; then
ynh_script_progression --message="Opening MPD-port $port_mpd..." --weight=1
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP "$port_mpd"
fi
#=================================================
# SETUP SSOWAT
#=================================================
ynh_script_progression --message="Configuring domain-wide permissions..."
ynh_permission_url --permission="main" --add_url="$domain/mopidy/ws"
ynh_permission_url --permission="main" --add_url="$domain/musicbox_webclient"
ynh_permission_url --permission="main" --add_url="$domain/local"
#=================================================
# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...)
#=================================================
# SCAN LOCAL MEDIA DIRECTORY
#=================================================
ynh_script_progression --message="Running the initial local media directory..."
"$cmd_file" local scan 2>&1
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
# Start a systemd service
ynh_systemd_action --service_name="$app" --action="start"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last